|
@@ -62,7 +62,7 @@ class TWIBus {
|
62
|
62
|
|
63
|
63
|
/**
|
64
|
64
|
* @brief Number of bytes on buffer
|
65
|
|
- * @description Number of bytes in the buffer waiting to be flushed to the bus.
|
|
65
|
+ * @description Number of bytes in the buffer waiting to be flushed to the bus
|
66
|
66
|
*/
|
67
|
67
|
uint8_t buffer_s = 0;
|
68
|
68
|
|
|
@@ -94,7 +94,7 @@ class TWIBus {
|
94
|
94
|
|
95
|
95
|
/**
|
96
|
96
|
* @brief Send the buffer data to the bus
|
97
|
|
- * @details Flush the buffer to the bus at the target address.
|
|
97
|
+ * @details Flush the buffer to the target address
|
98
|
98
|
*/
|
99
|
99
|
void send();
|
100
|
100
|
|
|
@@ -108,44 +108,56 @@ class TWIBus {
|
108
|
108
|
void addbyte(const char c);
|
109
|
109
|
|
110
|
110
|
/**
|
|
111
|
+ * @brief Add some bytes to the buffer
|
|
112
|
+ * @details Add bytes to the end of the buffer.
|
|
113
|
+ * Concatenates at the buffer size.
|
|
114
|
+ *
|
|
115
|
+ * @param src source data address
|
|
116
|
+ * @param bytes the number of bytes to add
|
|
117
|
+ */
|
|
118
|
+ void addbytes(char src[], uint8_t bytes);
|
|
119
|
+
|
|
120
|
+ /**
|
|
121
|
+ * @brief Add a null-terminated string to the buffer
|
|
122
|
+ * @details Add bytes to the end of the buffer up to a nul.
|
|
123
|
+ * Concatenates at the buffer size.
|
|
124
|
+ *
|
|
125
|
+ * @param str source string address
|
|
126
|
+ */
|
|
127
|
+ void addstring(char str[]);
|
|
128
|
+
|
|
129
|
+ /**
|
111
|
130
|
* @brief Set the target slave address
|
112
|
|
- * @details The target slave address for sending the full packet.
|
|
131
|
+ * @details The target slave address for sending the full packet
|
113
|
132
|
*
|
114
|
|
- * @param addr 7-bit integer address
|
|
133
|
+ * @param adr 7-bit integer address
|
115
|
134
|
*/
|
116
|
|
- void address(const uint8_t addr);
|
|
135
|
+ void address(const uint8_t adr);
|
117
|
136
|
|
118
|
137
|
/**
|
119
|
|
- * @brief Request data from the slave device
|
120
|
|
- * @details Request a number of bytes from a slave device.
|
121
|
|
- * This implementation simply sends the data to serial
|
122
|
|
- * in a parser-friendly format.
|
|
138
|
+ * @brief Echo data on the bus to serial
|
|
139
|
+ * @details Echo some number of bytes from the bus
|
|
140
|
+ * to serial in a parser-friendly format.
|
123
|
141
|
*
|
124
|
142
|
* @param bytes the number of bytes to request
|
125
|
143
|
*/
|
126
|
|
- void reqbytes(const uint8_t bytes);
|
|
144
|
+ static void echodata(uint8_t bytes, const char prefix[], uint8_t adr);
|
127
|
145
|
|
128
|
146
|
/**
|
129
|
|
- * @brief Relay data from the slave device to serial
|
130
|
|
- * @details Relay a number of bytes from the bus to
|
131
|
|
- * serial in a parser-friendly format.
|
|
147
|
+ * @brief Request data from the slave device
|
|
148
|
+ * @details Request a number of bytes from a slave device.
|
|
149
|
+ * This implementation simply sends the data to serial
|
|
150
|
+ * in a parser-friendly format.
|
132
|
151
|
*
|
133
|
152
|
* @param bytes the number of bytes to request
|
134
|
153
|
*/
|
135
|
|
- void relaydata(uint8_t bytes);
|
|
154
|
+ void reqbytes(const uint8_t bytes);
|
136
|
155
|
|
137
|
156
|
#if I2C_SLAVE_ADDRESS > 0
|
138
|
157
|
|
139
|
158
|
/**
|
140
|
|
- * @brief Receive bytes (passively)
|
141
|
|
- * @details Receive bytes sent to our slave address.
|
142
|
|
- * and simply echo them to serial.
|
143
|
|
- */
|
144
|
|
- inline void receive(uint8_t bytes) { relaydata(bytes); }
|
145
|
|
-
|
146
|
|
- /**
|
147
|
159
|
* @brief Register a slave receive handler
|
148
|
|
- * @details Set a handler to receive data addressed to us.
|
|
160
|
+ * @details Set a handler to receive data addressed to us
|
149
|
161
|
*
|
150
|
162
|
* @param handler A function to handle receiving bytes
|
151
|
163
|
*/
|
|
@@ -153,12 +165,25 @@ class TWIBus {
|
153
|
165
|
|
154
|
166
|
/**
|
155
|
167
|
* @brief Register a slave request handler
|
156
|
|
- * @details Set a handler to send data requested from us.
|
|
168
|
+ * @details Set a handler to send data requested from us
|
157
|
169
|
*
|
158
|
170
|
* @param handler A function to handle receiving bytes
|
159
|
171
|
*/
|
160
|
172
|
inline void onRequest(const twiRequestFunc_t handler) { Wire.onRequest(handler); }
|
161
|
173
|
|
|
174
|
+ /**
|
|
175
|
+ * @brief Default handler to receive
|
|
176
|
+ * @details Receive bytes sent to our slave address
|
|
177
|
+ * and simply echo them to serial.
|
|
178
|
+ */
|
|
179
|
+ void receive(uint8_t bytes);
|
|
180
|
+
|
|
181
|
+ /**
|
|
182
|
+ * @brief Send a reply to the bus
|
|
183
|
+ * @details Send the buffer and clear it.
|
|
184
|
+ */
|
|
185
|
+ void reply(char str[]=NULL);
|
|
186
|
+
|
162
|
187
|
#endif
|
163
|
188
|
|
164
|
189
|
#if ENABLED(DEBUG_TWIBUS)
|
|
@@ -167,7 +192,11 @@ class TWIBus {
|
167
|
192
|
* @brief Prints a debug message
|
168
|
193
|
* @details Prints a simple debug message "TWIBus::function: value"
|
169
|
194
|
*/
|
170
|
|
- static void debug(const char func[], int32_t val = -1);
|
|
195
|
+ static void prefix(const char func[]);
|
|
196
|
+ static void debug(const char func[], uint32_t adr);
|
|
197
|
+ static void debug(const char func[], char c);
|
|
198
|
+ static void debug(const char func[], char adr[]);
|
|
199
|
+ static inline void debug(const char func[], uint8_t v) { debug(func, (uint32_t)v); }
|
171
|
200
|
|
172
|
201
|
#endif
|
173
|
202
|
};
|