10 typedef enum [[clang::flag_enum]] : uint32_t
18 InterruptTransmitWatermark = 1 << 3,
25 InterruptReceiveWatermark = 1 << 1,
45 ConfigurationMSBFirst = 1u << 29,
53 ConfigurationClockPhase = 1u << 30,
59 ConfigurationClockPolarity = 1u << 31,
146 template<
size_t NumChipSelects = 4>
227 void init(
const bool ClockPolarity,
228 const bool ClockPhase,
230 const uint16_t HalfClockPeriod)
volatile
233 (ClockPolarity ? ConfigurationClockPolarity : 0) |
234 (ClockPhase ? ConfigurationClockPhase : 0) |
235 (MsbFirst ? ConfigurationMSBFirst : 0) |
236 (HalfClockPeriod & ConfigurationHalfClockPeriodMask);
248 ControlTransmitClear | ControlSoftwareReset | ControlReceiveClear;
255 while ((
status & StatusIdle) == 0)
267 len <= StartByteCountMask,
268 "You can't transfer more than 0x7ff bytes at a time.");
269 len &= StartByteCountMask;
276 control = ControlTransmitEnable;
279 uint32_t transmitAvailable = 0;
280 for (uint32_t i = 0; i < len; ++i)
282 while (!transmitAvailable)
286 transmitAvailable = 8 - (
status & StatusTxFifoLevel);
301 void blocking_read(uint8_t data[], uint16_t len)
volatile
304 "You can't receive more than 0x7ff bytes at a time.");
314 for (uint32_t i = 0; i < len; ++i)
335 template<u
int8_t Index,
bool DeassertOthers = true>
338 static_assert(Index < NumChipSelects,
339 "SPI chip select index out of bounds");
341 const uint32_t State =
342 DeassertOthers ? (1 << NumChipSelects) - 1 :
chipSelects;
344 const uint32_t Bit = (1 << Index);
A specialised driver for the SPI device connected to the Ethernet MAC.
void reset_assert(const bool Assert=true) volatile
Assert the reset line.
void chip_select_assert(const bool Assert) volatile
Assert the chip select line.
A specialised driver for the SPI device connected to the LCD screen.
void data_command_set(const bool High) volatile
Set the data/command line.
void chip_select_assert(const bool Assert) volatile
Assert the chip select line.
void reset_assert(const bool Assert=true) volatile
Assert the chip select line.
Utility class to delete copy and move contructors.
C++ APIs for assertions, invariants, and writing formatted debug messages to a UART.
A driver for the Sonata's SPI device block.
uint32_t interruptEnable
Controls which interrupts are enabled.
uint32_t chipSelects
Chip Select lines; each bit controls a chip select line.
uint32_t transmitFifo
Bytes written here are pushed to the transmit FIFO.
uint32_t start
Writes to this begin an SPI operation.
uint32_t control
Controls the operation of the SPI block.
uint32_t interruptState
The current state of the SPI interrupts.
void interrupt_disable(Interrupt interrupt) volatile
Disable the given interrupt(s).
void init(const bool ClockPolarity, const bool ClockPhase, const bool MsbFirst, const uint16_t HalfClockPeriod) volatile
Initialises the SPI block.
uint32_t configuration
Configuration register.
uint32_t interruptTest
Allows one to manually trigger an interrupt for testing.
void interrupt_enable(Interrupt interrupt) volatile
Enable the given interrupt(s).
uint32_t status
Status information about the SPI block.
void chip_select_assert(const bool Assert=true) volatile
Asserts/de-asserts a given chip select.
uint32_t receiveFifo
Data from the receive FIFO.
ConditionalDebug< DebugSonataSpi, "Sonata SPI"> Debug
Helper for conditional debug logs and assertions.
uint32_t info
Information about the SPI controller.
static constexpr bool DebugSonataSpi
Flag set when we're debugging this driver.
void blocking_write(const uint8_t data[], uint16_t len) volatile
Sends len bytes from the given data buffer, where len is at most 0x7ff.
void wait_idle() volatile
Waits for the SPI device to become idle.
@ StartByteCountMask
Number of bytes to receive/transmit in the SPI operation.
@ InfoRxFifoDepth
Maximum number of items in the receive FIFO.
@ InfoTxFifoDepth
Maximum number of items in the transmit FIFO.
@ StatusTxFifoLevel
Number of items in the transmit FIFO.
@ StatusRxFifoEmpty
When set the receive FIFO is empty and any data read from it will be undefined.
@ StatusRxFifoLevel
Number of items in the receive FIFO.
@ StatusIdle
When set the SPI block is idle and can accept a new start command.
@ StatusTxFifoFull
When set the transmit FIFO is full and any data written to it will be ignored.
@ ControlReceiveEnable
When set incoming bits are written to the receive FIFO.
@ ControlReceiveClear
Write 1 to clear the receive FIFO.
@ ControlTransmitEnable
When set bytes from the transmit FIFO are sent.
@ ControlReceiveWatermarkMask
The watermark level for the receive FIFO, depending on the value the interrupt will trigger at differ...
@ ControlTransmitClear
Write 1 to clear the transmit FIFO.
@ ControlTransmitWatermarkMask
The watermark level for the transmit FIFO, depending on the value the interrupt will trigger at diffe...
@ InterruptComplete
Raised when a SPI operation completes and the block has become idle.
@ InterruptTransmitEmpty
Asserted whilst the transmit FIFO is empty.
@ InterruptReceiveFull
Asserted whilst the receive FIFO is full.
@ ConfigurationHalfClockPeriodMask
The length of a half period (i.e.
@ ControlSoftwareReset
Software reset performed when written as 1.
@ ControlInternalLoopback
Internal loopback function enabled when set to 1.
Miscellaneous utility functions and classes.