Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SPIHalfDuplex.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* mbed Microcontroller Library - SPIHalfDuplex
  2. * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
  3. */
  4. #ifndef MBED_SPIHALFDUPLEX_H
  5. #define MBED_SPIHALFDUPLEX_H
  6. #include "platform.h"
  7. #if DEVICE_SPI
  8. #include "SPI.h"
  9. namespace mbed {
  10. /** A SPI half-duplex master, used for communicating with SPI slave devices
  11. * over a shared data line.
  12. *
  13. * The default format is set to 8-bits for both master and slave, and a
  14. * clock frequency of 1MHz
  15. *
  16. * Most SPI devies will also require Chip Select and Reset signals. These
  17. * can be controlled using <DigitalOut> pins.
  18. *
  19. * Although this is for a shared data line, both MISO and MOSI are defined,
  20. * and should be tied together externally to the mbed. This class handles
  21. * the tri-stating of the MOSI pin.
  22. *
  23. * Example:
  24. * @code
  25. * // Send a byte to a SPI half-duplex slave, and record the response
  26. *
  27. * #include "mbed.h"
  28. *
  29. * SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
  30. *
  31. * int main() {
  32. * int respone = device.write(0xAA);
  33. * }
  34. * @endcode
  35. */
  36. class SPIHalfDuplex : public SPI {
  37. public:
  38. /** Create a SPI half-duplex master connected to the specified pins
  39. *
  40. * Pin Options:
  41. * (5, 6, 7) or (11, 12, 13)
  42. *
  43. * mosi or miso can be specfied as NC if not used
  44. *
  45. * @param mosi SPI Master Out, Slave In pin
  46. * @param miso SPI Master In, Slave Out pin
  47. * @param sclk SPI Clock pin
  48. * @param name (optional) A string to identify the object
  49. */
  50. SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk);
  51. /** Write to the SPI Slave and return the response
  52. *
  53. * @param value Data to be sent to the SPI slave
  54. *
  55. * @returns
  56. * Response from the SPI slave
  57. */
  58. virtual int write(int value);
  59. /** Set the number of databits expected from the slave, from 4-16
  60. *
  61. * @param sbits Number of expected bits in the slave response
  62. */
  63. void slave_format(int sbits);
  64. protected:
  65. PinName _mosi;
  66. PinName _miso;
  67. int _sbits;
  68. }; // End of class
  69. } // End of namespace mbed
  70. #endif
  71. #endif