void SPIClass::setClockDivider(uint8_t _pin, uint8_t _divider) { uint32_t ch = BOARD_PIN_TO_SPI_CHANNEL(_pin); divider[ch] = _divider; // SPI_CSR_DLYBCT(1) keeps CS enabled for 32 MCLK after a completed // transfer. Some device needs that for working properly. SPI_ConfigureNPCS(spi, ch, mode[ch] | SPI_CSR_SCBR(divider[ch]) | SPI_CSR_DLYBCT(1)); }
void SPIClass::setDataMode(uint8_t _pin, uint8_t _mode) { uint32_t ch = BOARD_PIN_TO_SPI_CHANNEL(_pin); mode[ch] = _mode | SPI_CSR_CSAAT; // SPI_CSR_DLYBCT(1) keeps CS enabled for 32 MCLK after a completed // transfer. Some device needs that for working properly. //TODO: See if this is needed for Flutter SPI_ConfigureNPCS(spi, ch, mode[ch] | SPI_CSR_SCBR(divider[ch]) | SPI_CSR_DLYBCT(1)); }
byte SPIClass::transfer(byte _pin, uint8_t _data, SPITransferMode _mode) { uint32_t ch = BOARD_PIN_TO_SPI_CHANNEL(_pin); // Reverse bit order if (bitOrder[ch] == LSBFIRST) _data = __REV(__RBIT(_data)); uint32_t d = _data | SPI_PCS(ch); if (_mode == SPI_LAST) d |= SPI_TDR_LASTXFER; // SPI_Write(spi, _channel, _data); while ((spi->SPI_SR & SPI_SR_TDRE) == 0) ; spi->SPI_TDR = d; // return SPI_Read(spi); while ((spi->SPI_SR & SPI_SR_RDRF) == 0) ; d = spi->SPI_RDR; // Reverse bit order if (bitOrder[ch] == LSBFIRST) d = __REV(__RBIT(d)); return d & 0xFF; }
void SPIClass::setBitOrder(uint8_t _pin, BitOrder _bitOrder) { uint32_t ch = BOARD_PIN_TO_SPI_CHANNEL(_pin); bitOrder[ch] = _bitOrder; }