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