]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/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.
4 #ifndef MBED_SPIHALFDUPLEX_H
5 #define MBED_SPIHALFDUPLEX_H
15 /** A SPI half-duplex master, used for communicating with SPI slave devices
16 * over a shared data line.
18 * The default format is set to 8-bits for both master and slave, and a
19 * clock frequency of 1MHz
21 * Most SPI devies will also require Chip Select and Reset signals. These
22 * can be controlled using <DigitalOut> pins.
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.
30 * // Send a byte to a SPI half-duplex slave, and record the response
34 * SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
37 * int respone = device.write(0xAA);
42 class SPIHalfDuplex
: public SPI
{
46 /** Create a SPI half-duplex master connected to the specified pins
49 * (5, 6, 7) or (11, 12, 13)
51 * mosi or miso can be specfied as NC if not used
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
58 SPIHalfDuplex(PinName mosi
, PinName miso
, PinName sclk
);
60 /** Write to the SPI Slave and return the response
62 * @param value Data to be sent to the SPI slave
65 * Response from the SPI slave
67 virtual int write(int value
);
69 /** Set the number of databits expected from the slave, from 4-16
71 * @param sbits Number of expected bits in the slave response
73 void slave_format(int sbits
);
81 } // End of namespace mbed