@@ -156,6 +156,97 @@ void ArduinoSPI::setPins(bsp_io_port_pin_t miso, bsp_io_port_pin_t mosi,
156
156
pinPeripheral (sck, (uint32_t ) IOPORT_CFG_PERIPHERAL_PIN | peripheralCfg);
157
157
}
158
158
159
+ void ArduinoSPI::usingInterrupt (int interruptNumber)
160
+ {
161
+ }
162
+
163
+ void ArduinoSPI::notUsingInterrupt (int interruptNumber)
164
+ {
165
+ }
166
+
167
+ uint8_t ArduinoSPI::transfer (uint8_t data) {
168
+ uint8_t rxbuf;
169
+ _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
170
+ if (_is_sci) {
171
+ R_SCI_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_8_BITS);
172
+ } else {
173
+ R_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_8_BITS);
174
+ }
175
+
176
+ for (auto const start = millis ();
177
+ (SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis () - start < 1000 ); )
178
+ {
179
+ __NOP ();
180
+ }
181
+ if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
182
+ {
183
+ end ();
184
+ return 0 ;
185
+ }
186
+ return rxbuf;
187
+ }
188
+
189
+ uint16_t ArduinoSPI::transfer16 (uint16_t data) {
190
+ uint16_t rxbuf;
191
+ _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
192
+ if (_is_sci) {
193
+ R_SCI_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_16_BITS);
194
+ } else {
195
+ R_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_16_BITS);
196
+ }
197
+
198
+ for (auto const start = millis ();
199
+ (SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis () - start < 1000 ); )
200
+ {
201
+ __NOP ();
202
+ }
203
+ if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
204
+ {
205
+ end ();
206
+ return 0 ;
207
+ }
208
+ return rxbuf;
209
+ }
210
+
211
+ void ArduinoSPI::transfer (void *buf, size_t count) {
212
+ _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
213
+ if (_is_sci) {
214
+ R_SCI_SPI_WriteRead (_g_spi_ctrl, buf, buf, count, SPI_BIT_WIDTH_8_BITS);
215
+ } else {
216
+ R_SPI_WriteRead (_g_spi_ctrl, buf, buf, count, SPI_BIT_WIDTH_8_BITS);
217
+ }
218
+
219
+ for (auto const start = millis ();
220
+ (SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis () - start < 1000 ); )
221
+ {
222
+ __NOP ();
223
+ }
224
+ if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
225
+ {
226
+ end ();
227
+ }
228
+ }
229
+
230
+ void ArduinoSPI::beginTransaction (arduino::SPISettings settings)
231
+ {
232
+ if (_is_sci)
233
+ configSpiSci (settings);
234
+ else
235
+ configSpi (settings);
236
+ }
237
+
238
+ void ArduinoSPI::endTransaction (void ) {
239
+
240
+ }
241
+
242
+ void ArduinoSPI::attachInterrupt () {
243
+
244
+ }
245
+
246
+ void ArduinoSPI::detachInterrupt () {
247
+
248
+ }
249
+
159
250
void ArduinoSPI::configSpi (arduino::SPISettings const & settings)
160
251
{
161
252
auto [clk_phase, clk_polarity, bit_order] = toFspSpiConfig (settings);
@@ -260,97 +351,6 @@ std::tuple<spi_clk_phase_t, spi_clk_polarity_t, spi_bit_order_t> ArduinoSPI::toF
260
351
return std::make_tuple (clk_phase, clk_polarity, bit_order);
261
352
}
262
353
263
- void ArduinoSPI::usingInterrupt (int interruptNumber)
264
- {
265
- }
266
-
267
- void ArduinoSPI::notUsingInterrupt (int interruptNumber)
268
- {
269
- }
270
-
271
- uint8_t ArduinoSPI::transfer (uint8_t data) {
272
- uint8_t rxbuf;
273
- _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
274
- if (_is_sci) {
275
- R_SCI_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_8_BITS);
276
- } else {
277
- R_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_8_BITS);
278
- }
279
-
280
- for (auto const start = millis ();
281
- (SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis () - start < 1000 ); )
282
- {
283
- __NOP ();
284
- }
285
- if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
286
- {
287
- end ();
288
- return 0 ;
289
- }
290
- return rxbuf;
291
- }
292
-
293
- uint16_t ArduinoSPI::transfer16 (uint16_t data) {
294
- uint16_t rxbuf;
295
- _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
296
- if (_is_sci) {
297
- R_SCI_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_16_BITS);
298
- } else {
299
- R_SPI_WriteRead (_g_spi_ctrl, &data, &rxbuf, 1 , SPI_BIT_WIDTH_16_BITS);
300
- }
301
-
302
- for (auto const start = millis ();
303
- (SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis () - start < 1000 ); )
304
- {
305
- __NOP ();
306
- }
307
- if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
308
- {
309
- end ();
310
- return 0 ;
311
- }
312
- return rxbuf;
313
- }
314
-
315
- void ArduinoSPI::transfer (void *buf, size_t count) {
316
- _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
317
- if (_is_sci) {
318
- R_SCI_SPI_WriteRead (_g_spi_ctrl, buf, buf, count, SPI_BIT_WIDTH_8_BITS);
319
- } else {
320
- R_SPI_WriteRead (_g_spi_ctrl, buf, buf, count, SPI_BIT_WIDTH_8_BITS);
321
- }
322
-
323
- for (auto const start = millis ();
324
- (SPI_EVENT_TRANSFER_COMPLETE != _spi_cb_event[_cb_event_idx]) && (millis () - start < 1000 ); )
325
- {
326
- __NOP ();
327
- }
328
- if (SPI_EVENT_TRANSFER_ABORTED == _spi_cb_event[_cb_event_idx])
329
- {
330
- end ();
331
- }
332
- }
333
-
334
- void ArduinoSPI::beginTransaction (arduino::SPISettings settings)
335
- {
336
- if (_is_sci)
337
- configSpiSci (settings);
338
- else
339
- configSpi (settings);
340
- }
341
-
342
- void ArduinoSPI::endTransaction (void ) {
343
-
344
- }
345
-
346
- void ArduinoSPI::attachInterrupt () {
347
-
348
- }
349
-
350
- void ArduinoSPI::detachInterrupt () {
351
-
352
- }
353
-
354
354
void ArduinoSPI::enableSciSpiIrqs () {
355
355
356
356
switch (_channel)
0 commit comments