@@ -147,6 +147,7 @@ void ArduinoSPI::begin()
147
147
148
148
configSpiSettings (DEFAULT_SPI_SETTINGS);
149
149
150
+ #if 0
150
151
/* Configure the Interrupt Controller. */
151
152
if (_is_sci)
152
153
{
@@ -180,6 +181,7 @@ void ArduinoSPI::begin()
180
181
init_ok = false;
181
182
}
182
183
}
184
+ #endif
183
185
184
186
_is_initialized = init_ok;
185
187
}
@@ -197,7 +199,8 @@ void ArduinoSPI::end()
197
199
uint8_t ArduinoSPI::transfer (uint8_t data)
198
200
{
199
201
uint8_t rxbuf;
200
- _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
202
+ #if 0
203
+ _spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
201
204
if (_is_sci) {
202
205
_write_then_read(&_spi_sci_ctrl, &data, &rxbuf, 1, SPI_BIT_WIDTH_8_BITS);
203
206
} else {
@@ -214,6 +217,16 @@ uint8_t ArduinoSPI::transfer(uint8_t data)
214
217
end();
215
218
return 0;
216
219
}
220
+ #endif
221
+
222
+ #if 1
223
+ _spi_ctrl.p_regs ->SPDR_BY = data;
224
+ // while (0 == _spi_ctrl.p_regs->SPSR_b.SPTEF) {}
225
+ // while (_spi_ctrl.p_regs->SPSR_b.IDLNF) {}
226
+ while (0 == _spi_ctrl.p_regs ->SPSR_b .SPRF ) {}
227
+ rxbuf = _spi_ctrl.p_regs ->SPDR_BY ;
228
+ #endif
229
+
217
230
return rxbuf;
218
231
}
219
232
@@ -234,6 +247,7 @@ uint16_t ArduinoSPI::transfer16(uint16_t data)
234
247
235
248
void ArduinoSPI::transfer (void *buf, size_t count)
236
249
{
250
+ #if 0
237
251
_spi_cb_event[_cb_event_idx] = SPI_EVENT_TRANSFER_ABORTED;
238
252
239
253
if (_is_sci) {
@@ -251,6 +265,19 @@ void ArduinoSPI::transfer(void *buf, size_t count)
251
265
{
252
266
end();
253
267
}
268
+ #endif
269
+
270
+ #if 1
271
+ uint8_t *buffer = (uint8_t *) buf;
272
+
273
+ for (size_t index = 0 ; index < count; index++)
274
+ {
275
+ _spi_ctrl.p_regs ->SPDR_BY = buffer[index];
276
+ while (0 == _spi_ctrl.p_regs ->SPSR_b .SPRF ) {}
277
+ buffer[index] = _spi_ctrl.p_regs ->SPDR_BY ;
278
+ }
279
+ while (_spi_ctrl.p_regs ->SPSR_b .IDLNF ) {}
280
+ #endif
254
281
}
255
282
256
283
void ArduinoSPI::beginTransaction (arduino::SPISettings settings)
@@ -366,6 +393,7 @@ void ArduinoSPI::configSpiSettings(arduino::SPISettings const & settings)
366
393
367
394
void ArduinoSPI::configSpi (arduino::SPISettings const & settings)
368
395
{
396
+ #if 0
369
397
auto [clk_phase, clk_polarity, bit_order] = toFspSpiConfig(settings);
370
398
371
399
rspck_div_setting_t spck_div = _spi_ext_cfg.spck_div;
@@ -383,12 +411,84 @@ void ArduinoSPI::configSpi(arduino::SPISettings const & settings)
383
411
spcmd0 |= (uint32_t) bit_order << 12;
384
412
385
413
/* Configure the Bit Rate Division Setting */
386
- spcmd0 &= ~ (((uint32_t ) 3 ) << 2 );
414
+ spcmd0 &= ! (((uint32_t)0xFF ) << 2);
387
415
spcmd0 |= (uint32_t) spck_div.brdv << 2;
388
416
389
417
/* Update settings. */
390
418
_spi_ctrl.p_regs->SPCMD[0] = (uint16_t) spcmd0;
391
419
_spi_ctrl.p_regs->SPBR = (uint8_t) spck_div.spbr;
420
+ #endif
421
+
422
+ #if 1
423
+ /* * SPI base register access macro. */
424
+ #define SPI_REG (channel ) ((R_SPI0_Type *) ((uint32_t ) R_SPI0 + \
425
+ ((uint32_t ) R_SPI1 - (uint32_t ) R_SPI0) * \
426
+ (channel)))
427
+
428
+ _spi_ctrl.p_cfg = &_spi_cfg;
429
+ _spi_ctrl.p_callback = _spi_cfg.p_callback ;
430
+ _spi_ctrl.p_context = _spi_cfg.p_context ;
431
+ _spi_ctrl.p_callback_memory = NULL ;
432
+ _spi_ctrl.p_regs = SPI_REG (_spi_ctrl.p_cfg ->channel );
433
+
434
+ auto [clk_phase, clk_polarity, bit_order] = toFspSpiConfig (settings);
435
+
436
+ rspck_div_setting_t spck_div = _spi_ext_cfg.spck_div ;
437
+ R_SPI_CalculateBitrate (settings.getClockFreq (), &spck_div);
438
+
439
+ uint32_t spcmd0 = 0 ;
440
+ uint32_t spcr = 0 ;
441
+ uint32_t sslp = 0 ;
442
+ uint32_t sppcr = 0 ;
443
+ uint32_t spcr2 = 0 ;
444
+ uint32_t spckd = 0 ;
445
+ uint32_t sslnd = 0 ;
446
+ uint32_t spnd = 0 ;
447
+
448
+ spcmd0 |= (uint32_t ) clk_phase; /* Configure CPHA setting. */
449
+ spcmd0 |= (uint32_t ) clk_polarity << 1 ; /* Configure CPOL setting. */
450
+ spcmd0 |= (uint32_t ) spck_div.brdv << 2 ; /* Configure the Bit Rate Division Setting */
451
+ spcmd0 |= (uint32_t ) SPI_BIT_WIDTH_8_BITS << 8 ; /* Configure 8 bit data width */
452
+ spcmd0 |= (uint32_t ) bit_order << 12 ; /* Configure Bit Order (MSB,LSB) */
453
+
454
+ /* TXMD = 0 -> full duplex, SPxIE = 0 -> no interrupts */
455
+ spcr |= R_SPI0_SPCR_SPMS_Msk; /* configure 3-Wire Mode */
456
+ if (SPI_MODE_MASTER == _spi_cfg.operating_mode )
457
+ {
458
+ spcr |= R_SPI0_SPCR_MSTR_Msk;
459
+ spcr2 |= R_SPI0_SPCR2_SCKASE_Msk;
460
+ }
461
+
462
+ /* Configure SSLn polarity setting. */
463
+ sslp |= (uint32_t ) _spi_ext_cfg.ssl_polarity << _spi_ext_cfg.ssl_select ;
464
+
465
+ /* set MOSI idle value to low */
466
+ sppcr |= R_SPI0_SPPCR_MOIFE_Msk;
467
+
468
+ /* Power up the SPI module. */
469
+ R_BSP_MODULE_START (FSP_IP_SPI, _spi_cfg.channel );
470
+
471
+ /* Write registers */
472
+ _spi_ctrl.p_regs ->SPCR = (uint8_t ) spcr;
473
+ _spi_ctrl.p_regs ->SSLP = (uint8_t ) sslp;
474
+ _spi_ctrl.p_regs ->SPPCR = (uint8_t ) sppcr;
475
+ _spi_ctrl.p_regs ->SPCKD = (uint8_t ) spckd;
476
+ _spi_ctrl.p_regs ->SSLND = (uint8_t ) sslnd;
477
+ _spi_ctrl.p_regs ->SPND = (uint8_t ) spnd;
478
+ _spi_ctrl.p_regs ->SPCR2 = (uint8_t ) spcr2;
479
+
480
+ _spi_ctrl.p_regs ->SPCMD [0 ] = (uint16_t ) spcmd0;
481
+ _spi_ctrl.p_regs ->SPBR = (uint8_t ) spck_div.spbr ;
482
+
483
+ _spi_ctrl.p_regs ->SPDCR_b .SPBYT = 1 ; /* SPI byte access */
484
+
485
+ _spi_ctrl.p_regs ->SPSR ; /* read to clear OVRF */
486
+ _spi_ctrl.p_regs ->SPSR = 0 ; /* clear status register */
487
+
488
+ _spi_ctrl.p_regs ->SPCR_b .SPE = 1 ; /* enable SPI unit */
489
+
490
+ _spi_ctrl.open = (0x52535049ULL ); /* "SPI" in ASCII, used to determine if channel is open. */
491
+ #endif
392
492
}
393
493
394
494
void ArduinoSPI::configSpiSci (arduino::SPISettings const & settings)
0 commit comments