|
@@ -178,8 +178,7 @@ void SPIClass::end() {
|
178
|
178
|
// FIXME [0.1.0] remove this once you have an interrupt based driver
|
179
|
179
|
volatile uint16_t rx __attribute__((unused)) = spi_rx_reg(_currentSetting->spi_d);
|
180
|
180
|
}
|
181
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ }
|
182
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ }
|
|
181
|
+ waitSpiTxEnd(_currentSetting->spi_d);
|
183
|
182
|
|
184
|
183
|
spi_peripheral_disable(_currentSetting->spi_d);
|
185
|
184
|
// added for DMA callbacks.
|
|
@@ -297,8 +296,7 @@ void SPIClass::write(uint16_t data) {
|
297
|
296
|
* This almost doubles the speed of this function.
|
298
|
297
|
*/
|
299
|
298
|
spi_tx_reg(_currentSetting->spi_d, data); // write the data to be transmitted into the SPI_DR register (this clears the TXE flag)
|
300
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
301
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ } // "... and then wait until BSY=0 before disabling the SPI."
|
|
299
|
+ waitSpiTxEnd(_currentSetting->spi_d);
|
302
|
300
|
}
|
303
|
301
|
|
304
|
302
|
void SPIClass::write16(uint16_t data) {
|
|
@@ -306,8 +304,7 @@ void SPIClass::write16(uint16_t data) {
|
306
|
304
|
spi_tx_reg(_currentSetting->spi_d, data>>8); // write high byte
|
307
|
305
|
while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // Wait until TXE=1
|
308
|
306
|
spi_tx_reg(_currentSetting->spi_d, data); // write low byte
|
309
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // Wait until TXE=1
|
310
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ } // wait until BSY=0
|
|
307
|
+ waitSpiTxEnd(_currentSetting->spi_d);
|
311
|
308
|
}
|
312
|
309
|
|
313
|
310
|
void SPIClass::write(uint16_t data, uint32_t n) {
|
|
@@ -323,16 +320,14 @@ void SPIClass::write(uint16_t data, uint32_t n) {
|
323
|
320
|
void SPIClass::write(const void *data, uint32_t length) {
|
324
|
321
|
spi_dev * spi_d = _currentSetting->spi_d;
|
325
|
322
|
spi_tx(spi_d, data, length); // data can be array of bytes or words
|
326
|
|
- while (!spi_is_tx_empty(spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
327
|
|
- while (spi_is_busy(spi_d)) { /* nada */ } // "... and then wait until BSY=0 before disabling the SPI."
|
|
323
|
+ waitSpiTxEnd(spi_d);
|
328
|
324
|
}
|
329
|
325
|
|
330
|
326
|
uint8_t SPIClass::transfer(uint8_t byte) const {
|
331
|
327
|
spi_dev * spi_d = _currentSetting->spi_d;
|
332
|
328
|
spi_rx_reg(spi_d); // read any previous data
|
333
|
329
|
spi_tx_reg(spi_d, byte); // Write the data item to be transmitted into the SPI_DR register
|
334
|
|
- while (!spi_is_tx_empty(spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
335
|
|
- while (spi_is_busy(spi_d)) { /* nada */ } // "... and then wait until BSY=0 before disabling the SPI."
|
|
330
|
+ waitSpiTxEnd(spi_d);
|
336
|
331
|
return (uint8)spi_rx_reg(spi_d); // "... and read the last received data."
|
337
|
332
|
}
|
338
|
333
|
|
|
@@ -342,12 +337,10 @@ uint16_t SPIClass::transfer16(uint16_t data) const {
|
342
|
337
|
spi_dev * spi_d = _currentSetting->spi_d;
|
343
|
338
|
spi_rx_reg(spi_d); // read any previous data
|
344
|
339
|
spi_tx_reg(spi_d, data>>8); // write high byte
|
345
|
|
- while (!spi_is_tx_empty(spi_d)) { /* nada */ } // wait until TXE=1
|
346
|
|
- while (spi_is_busy(spi_d)) { /* nada */ } // wait until BSY=0
|
|
340
|
+ waitSpiTxEnd(spi_d); // wait until TXE=1 and then wait until BSY=0
|
347
|
341
|
uint16_t ret = spi_rx_reg(spi_d)<<8; // read and shift high byte
|
348
|
342
|
spi_tx_reg(spi_d, data); // write low byte
|
349
|
|
- while (!spi_is_tx_empty(spi_d)) { /* nada */ } // wait until TXE=1
|
350
|
|
- while (spi_is_busy(spi_d)) { /* nada */ } // wait until BSY=0
|
|
343
|
+ waitSpiTxEnd(spi_d); // wait until TXE=1 and then wait until BSY=0
|
351
|
344
|
ret += spi_rx_reg(spi_d); // read low byte
|
352
|
345
|
return ret;
|
353
|
346
|
}
|
|
@@ -400,8 +393,7 @@ uint8_t SPIClass::dmaTransferRepeat(uint16_t length) {
|
400
|
393
|
if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
|
401
|
394
|
}
|
402
|
395
|
|
403
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
404
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ } // "... and then wait until BSY=0 before disabling the SPI."
|
|
396
|
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
|
405
|
397
|
spi_tx_dma_disable(_currentSetting->spi_d);
|
406
|
398
|
spi_rx_dma_disable(_currentSetting->spi_d);
|
407
|
399
|
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
|
@@ -456,8 +448,7 @@ uint8_t SPIClass::dmaSendRepeat(uint16_t length) {
|
456
|
448
|
// Avoid interrupts and just loop waiting for the flag to be set.
|
457
|
449
|
if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
|
458
|
450
|
}
|
459
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
460
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ } // "... and then wait until BSY=0 before disabling the SPI."
|
|
451
|
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
|
461
|
452
|
spi_tx_dma_disable(_currentSetting->spi_d);
|
462
|
453
|
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
463
|
454
|
dma_clear_isr_bits(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
|
@@ -480,9 +471,7 @@ uint8_t SPIClass::dmaSendAsync(const void * transmitBuf, uint16_t length, bool m
|
480
|
471
|
//delayMicroseconds(10);
|
481
|
472
|
if ((millis() - m) > DMA_TIMEOUT) { b = 2; break; }
|
482
|
473
|
}
|
483
|
|
-
|
484
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
485
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ } // "... and then wait until BSY=0 before disabling the SPI."
|
|
474
|
+ waitSpiTxEnd(_currentSetting->spi_d); // until TXE=1 and BSY=0
|
486
|
475
|
spi_tx_dma_disable(_currentSetting->spi_d);
|
487
|
476
|
dma_disable(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel);
|
488
|
477
|
_currentSetting->state = SPI_STATE_READY;
|
|
@@ -572,8 +561,7 @@ void SPIClass::onTransmit(void(*callback)(void)) {
|
572
|
561
|
* during the initial setup and only set the callback to EventCallback if they are set.
|
573
|
562
|
*/
|
574
|
563
|
void SPIClass::EventCallback() {
|
575
|
|
- while (!spi_is_tx_empty(_currentSetting->spi_d)) { /* nada */ } // "5. Wait until TXE=1 ..."
|
576
|
|
- while (spi_is_busy(_currentSetting->spi_d)) { /* nada */ } // "... and then wait until BSY=0"
|
|
564
|
+ waitSpiTxEnd(_currentSetting->spi_d);
|
577
|
565
|
switch (_currentSetting->state) {
|
578
|
566
|
case SPI_STATE_TRANSFER:
|
579
|
567
|
while (spi_is_rx_nonempty(_currentSetting->spi_d)) { /* nada */ }
|