26
26
namespace mbed {
27
27
/* * \addtogroup drivers */
28
28
29
- /* * A SPI slave, used for communicating with a SPI Master device
29
+ /* * A SPI slave, used for communicating with a SPI master device.
30
30
*
31
- * The default format is set to 8- bits, mode 0, and a clock frequency of 1MHz
31
+ * The default format is set to 8 bits, mode 0 and a clock frequency of 1MHz.
32
32
*
33
33
* @note Synchronization level: Not protected
34
34
*
35
- * Example:
35
+ * Example of how to reply to a SPI master as slave :
36
36
* @code
37
- * // Reply to a SPI master as slave
38
37
*
39
38
* #include "mbed.h"
40
39
*
41
- * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
40
+ * SPISlave device(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS);
42
41
*
43
42
* int main() {
44
43
* device.reply(0x00); // Prime SPI with first reply
@@ -57,21 +56,21 @@ class SPISlave : private NonCopyable<SPISlave> {
57
56
58
57
public:
59
58
60
- /* * Create a SPI slave connected to the specified pins
59
+ /* * Create a SPI slave connected to the specified pins.
61
60
*
62
- * mosi or miso can be specified as NC if not used
61
+ * @note Either mosi or miso can be specified as NC if not used.
63
62
*
64
- * @param mosi SPI Master Out, Slave In pin
65
- * @param miso SPI Master In, Slave Out pin
66
- * @param sclk SPI Clock pin
67
- * @param ssel SPI chip select pin
63
+ * @param mosi SPI Master Out, Slave In pin.
64
+ * @param miso SPI Master In, Slave Out pin.
65
+ * @param sclk SPI Clock pin.
66
+ * @param ssel SPI Chip Select pin.
68
67
*/
69
68
SPISlave (PinName mosi, PinName miso, PinName sclk, PinName ssel);
70
69
71
- /* * Configure the data transmission format
70
+ /* * Configure the data transmission format.
72
71
*
73
- * @param bits Number of bits per SPI frame (4 - 16)
74
- * @param mode Clock polarity and phase mode (0 - 3)
72
+ * @param bits Number of bits per SPI frame (4 - 16).
73
+ * @param mode Clock polarity and phase mode (0 - 3).
75
74
*
76
75
* @code
77
76
* mode | POL PHA
@@ -84,40 +83,47 @@ class SPISlave : private NonCopyable<SPISlave> {
84
83
*/
85
84
void format (int bits, int mode = 0 );
86
85
87
- /* * Set the spi bus clock frequency
86
+ /* * Set the SPI bus clock frequency.
88
87
*
89
- * @param hz SCLK frequency in hz (default = 1MHz)
88
+ * @param hz Clock frequency in hz (default = 1MHz).
90
89
*/
91
90
void frequency (int hz = 1000000 );
92
91
93
- /* * Polls the SPI to see if data has been received
92
+ /* * Polls the SPI to see if data has been received.
94
93
*
95
- * @returns
96
- * 0 if no data,
97
- * 1 otherwise
94
+ * @return Presence of received data.
95
+ * @retval 0 No data waiting.
96
+ * @retval 1 Data waiting.
98
97
*/
99
98
int receive (void );
100
99
101
- /* * Retrieve data from receive buffer as slave
100
+ /* * Retrieve data from receive buffer as slave.
102
101
*
103
- * @returns
104
- * the data in the receive buffer
102
+ * @return The data in the receive buffer.
105
103
*/
106
104
int read (void );
107
105
108
106
/* * Fill the transmission buffer with the value to be written out
109
107
* as slave on the next received message from the master.
110
108
*
111
- * @param value the data to be transmitted next
109
+ * @param value The data to be transmitted next.
112
110
*/
113
111
void reply (int value);
114
112
113
+ #if !defined(DOXYGEN_ONLY)
114
+
115
115
protected:
116
+ /* Internal SPI object identifying the resources */
116
117
spi_t _spi;
117
118
119
+ /* How many bits in an SPI frame */
118
120
int _bits;
121
+ /* Clock phase and polarity */
119
122
int _mode;
123
+ /* Clock frequency */
120
124
int _hz;
125
+
126
+ #endif // !defined(DOXYGEN_ONLY)
121
127
};
122
128
123
129
} // namespace mbed
0 commit comments