added missing files, working on extruder module ( not finished, removing
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / .svn / text-base / SPIHalfDuplex.h.svn-base
1 /* mbed Microcontroller Library - SPI
2 * Copyright (c) 2010 ARM Limited. All rights reserved.
3 * jward
4 */
5
6 #ifndef MBED_SPIHALFDUPLEX_H
7 #define MBED_SPIHALFDUPLEX_H
8
9 #include "SPI.h"
10
11 namespace mbed {
12
13 /* Class: SPIHalfDuplex
14 * A SPI half-duplex master, used for communicating with SPI slave devices
15 * over a shared data line.
16 *
17 * The default format is set to 8-bits for both master and slave, and a
18 * clock frequency of 1MHz
19 *
20 * Most SPI devies will also require Chip Select and Reset signals. These
21 * can be controlled using <DigitalOut> pins.
22 *
23 * Although this is for a shared data line, both MISO and MOSI are defined,
24 * and should be tied together externally to the mbed. This class handles
25 * the tri-stating of the MOSI pin.
26 *
27 * Example:
28 * > // Send a byte to a SPI half-duplex slave, and record the response
29 * >
30 * > #include "mbed.h"
31 * >
32 * > SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
33 * >
34 * > int main() {
35 * > int respone = device.write(0xAA);
36 * > }
37 */
38
39 class SPIHalfDuplex : public SPI {
40
41 public:
42
43 /* Constructor: SPIHalfDuplex
44 * Create a SPI half-duplex master connected to the specified pins
45 *
46 * Variables:
47 * mosi - SPI Master Out, Slave In pin
48 * miso - SPI Master In, Slave Out pin
49 * sclk - SPI Clock pin
50 * name - (optional) A string to identify the object
51 *
52 * Pin Options:
53 * (5, 6, 7) or (11, 12, 13)
54 *
55 * mosi or miso can be specfied as NC if not used
56 */
57 SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk,
58 const char *name = NULL);
59
60 #if 0 // Inherited from SPI - documentation only
61 /* Function: format
62 * Configure the data transmission format
63 *
64 * Variables:
65 * bits - Number of bits per SPI frame (4 - 16)
66 * mode - Clock polarity and phase mode (0 - 3)
67 *
68 * > mode | POL PHA
69 * > -----+--------
70 * > 0 | 0 0
71 * > 1 | 0 1
72 * > 2 | 1 0
73 * > 3 | 1 1
74 */
75 void format(int bits, int mode = 0);
76
77 /* Function: frequency
78 * Set the spi bus clock frequency
79 *
80 * Variables:
81 * hz - SCLK frequency in hz (default = 1MHz)
82 */
83 void frequency(int hz = 1000000);
84 #endif
85
86 /* Function: write
87 * Write to the SPI Slave and return the response
88 *
89 * Variables:
90 * value - Data to be sent to the SPI slave
91 * returns - Response from the SPI slave
92 */
93 virtual int write(int value);
94
95 /* Function: slave_format
96 * Set the number of databits expected from the slave, from 4-16
97 *
98 * Variables:
99 * sbits - Number of expected bits in the slave response
100 */
101 void slave_format(int sbits);
102
103 protected:
104
105 PinName _mosi;
106 PinName _miso;
107 int _sbits;
108
109 }; // End of class
110
111 } // End of namespace mbed
112
113 #endif