|
56 | 56 | #pragma GCC optimize (3) |
57 | 57 |
|
58 | 58 | typedef uint8_t (*pfnSpiTransfer)(uint8_t b); |
59 | | - typedef void (*pfnSpiRxBlock)(uint8_t* buf, uint32_t nbyte); |
60 | | - typedef void (*pfnSpiTxBlock)(const uint8_t* buf, uint32_t nbyte); |
| 59 | + typedef void (*pfnSpiRxBlock)(uint8_t *buf, uint32_t nbyte); |
| 60 | + typedef void (*pfnSpiTxBlock)(const uint8_t *buf, uint32_t nbyte); |
61 | 61 |
|
62 | 62 | /* ---------------- Macros to be able to access definitions from asm */ |
63 | 63 | #define _PORT(IO) DIO ## IO ## _WPORT |
|
270 | 270 | static pfnSpiTransfer spiTransferTx = (pfnSpiTransfer)spiTransferX; |
271 | 271 |
|
272 | 272 | // Block transfers run at ~8 .. ~10Mhz - Tx version (Rx data discarded) |
273 | | - static void spiTxBlock0(const uint8_t* ptr, uint32_t todo) { |
| 273 | + static void spiTxBlock0(const uint8_t *ptr, uint32_t todo) { |
274 | 274 | uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(SD_MOSI_PIN)) + 0x30; /* SODR of port */ |
275 | 275 | uint32_t MOSI_MASK = PIN_MASK(SD_MOSI_PIN); |
276 | 276 | uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */ |
|
349 | 349 | ); |
350 | 350 | } |
351 | 351 |
|
352 | | - static void spiRxBlock0(uint8_t* ptr, uint32_t todo) { |
| 352 | + static void spiRxBlock0(uint8_t *ptr, uint32_t todo) { |
353 | 353 | uint32_t bin = 0; |
354 | 354 | uint32_t work = 0; |
355 | 355 | uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(SD_MISO_PIN))+0x3C, PIN_SHIFT(SD_MISO_PIN)); /* PDSR of port in bitband area */ |
|
425 | 425 | ); |
426 | 426 | } |
427 | 427 |
|
428 | | - static void spiTxBlockX(const uint8_t* buf, uint32_t todo) { |
| 428 | + static void spiTxBlockX(const uint8_t *buf, uint32_t todo) { |
429 | 429 | do { |
430 | 430 | (void)spiTransferTx(*buf++); |
431 | 431 | } while (--todo); |
432 | 432 | } |
433 | 433 |
|
434 | | - static void spiRxBlockX(uint8_t* buf, uint32_t todo) { |
| 434 | + static void spiRxBlockX(uint8_t *buf, uint32_t todo) { |
435 | 435 | do { |
436 | 436 | *buf++ = spiTransferRx(0xFF); |
437 | 437 | } while (--todo); |
|
463 | 463 | return b; |
464 | 464 | } |
465 | 465 |
|
466 | | - void spiRead(uint8_t* buf, uint16_t nbyte) { |
| 466 | + void spiRead(uint8_t *buf, uint16_t nbyte) { |
467 | 467 | if (nbyte) { |
468 | 468 | _SS_WRITE(LOW); |
469 | 469 | WRITE(SD_MOSI_PIN, HIGH); // Output 1s 1 |
|
478 | 478 | _SS_WRITE(HIGH); |
479 | 479 | } |
480 | 480 |
|
481 | | - void spiSendBlock(uint8_t token, const uint8_t* buf) { |
| 481 | + void spiSendBlock(uint8_t token, const uint8_t *buf) { |
482 | 482 | _SS_WRITE(LOW); |
483 | 483 | (void)spiTransferTx(token); |
484 | 484 | spiTxBlock(buf, 512); |
|
645 | 645 | } |
646 | 646 |
|
647 | 647 | // Read from SPI into buffer |
648 | | - void spiRead(uint8_t* buf, uint16_t nbyte) { |
| 648 | + void spiRead(uint8_t *buf, uint16_t nbyte) { |
649 | 649 | if (!nbyte) return; |
650 | 650 | --nbyte; |
651 | 651 | for (int i = 0; i < nbyte; i++) { |
|
668 | 668 | //DELAY_US(1U); |
669 | 669 | } |
670 | 670 |
|
671 | | - void spiSend(const uint8_t* buf, size_t nbyte) { |
| 671 | + void spiSend(const uint8_t *buf, size_t nbyte) { |
672 | 672 | if (!nbyte) return; |
673 | 673 | --nbyte; |
674 | 674 | for (size_t i = 0; i < nbyte; i++) { |
|
689 | 689 | FLUSH_RX(); |
690 | 690 | } |
691 | 691 |
|
692 | | - void spiSend(uint32_t chan, const uint8_t* buf, size_t nbyte) { |
| 692 | + void spiSend(uint32_t chan, const uint8_t *buf, size_t nbyte) { |
693 | 693 | if (!nbyte) return; |
694 | 694 | --nbyte; |
695 | 695 | for (size_t i = 0; i < nbyte; i++) { |
|
702 | 702 | } |
703 | 703 |
|
704 | 704 | // Write from buffer to SPI |
705 | | - void spiSendBlock(uint8_t token, const uint8_t* buf) { |
| 705 | + void spiSendBlock(uint8_t token, const uint8_t *buf) { |
706 | 706 | SPI0->SPI_TDR = (uint32_t)token | SPI_PCS(SPI_CHAN); |
707 | 707 | WHILE_TX(0); |
708 | 708 | //WHILE_RX(0); |
|
801 | 801 |
|
802 | 802 | uint8_t spiRec() { return (uint8_t)spiTransfer(0xFF); } |
803 | 803 |
|
804 | | - void spiRead(uint8_t* buf, uint16_t nbyte) { |
| 804 | + void spiRead(uint8_t *buf, uint16_t nbyte) { |
805 | 805 | for (int i = 0; i < nbyte; i++) |
806 | 806 | buf[i] = spiTransfer(0xFF); |
807 | 807 | } |
808 | 808 |
|
809 | 809 | void spiSend(uint8_t data) { spiTransfer(data); } |
810 | 810 |
|
811 | | - void spiSend(const uint8_t* buf, size_t nbyte) { |
| 811 | + void spiSend(const uint8_t *buf, size_t nbyte) { |
812 | 812 | for (uint16_t i = 0; i < nbyte; i++) |
813 | 813 | spiTransfer(buf[i]); |
814 | 814 | } |
815 | 815 |
|
816 | | - void spiSendBlock(uint8_t token, const uint8_t* buf) { |
| 816 | + void spiSendBlock(uint8_t token, const uint8_t *buf) { |
817 | 817 | spiTransfer(token); |
818 | 818 | for (uint16_t i = 0; i < 512; i++) |
819 | 819 | spiTransfer(buf[i]); |
|
0 commit comments