Difference between revisions of "Unit SPI"
Line 526: | Line 526: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| Called only during system startup | | Called only during system startup | ||
|- | |- | ||
Line 541: | Line 541: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to start | | The SPI device to start | ||
|- | |- | ||
− | ! | + | ! Mode |
| The device mode to set (eg SPI_MODE_4WIRE) | | The device mode to set (eg SPI_MODE_4WIRE) | ||
|- | |- | ||
− | ! | + | ! ClockRate |
| The clock rate to set for the device | | The clock rate to set for the device | ||
|- | |- | ||
− | ! | + | ! ClockPhase |
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | | The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | ||
|- | |- | ||
− | ! | + | ! ClockPolarity |
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | | The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 568: | Line 568: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to stop | | The SPI device to stop | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 583: | Line 583: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to read from | | The SPI device to read from | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select for the slave to read from (eg SPI_CS_0) | | The chip select for the slave to read from (eg SPI_CS_0) | ||
|- | |- | ||
− | ! | + | ! Dest |
| Pointer to a buffer to receive the data | | Pointer to a buffer to receive the data | ||
|- | |- | ||
− | ! | + | ! Size |
| The size of the buffer | | The size of the buffer | ||
|- | |- | ||
− | ! | + | ! Flags |
| The flags for this transfer (eg SPI_TRANSFER_DMA) | | The flags for this transfer (eg SPI_TRANSFER_DMA) | ||
|- | |- | ||
− | ! | + | ! Count |
| The number of bytes read on return | | The number of bytes read on return | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Because SPI writes and then reads for each byte, dummy data will be written for each byte to be read | + | | Because SPI writes and then reads for each byte, dummy data will be written for each byte to be read. |
|- | |- | ||
|} | |} | ||
Line 616: | Line 616: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to write to | | The SPI device to write to | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select for the slave to write to (eg SPI_CS_0) | | The chip select for the slave to write to (eg SPI_CS_0) | ||
|- | |- | ||
− | ! | + | ! Source |
| Pointer to a buffer of data to transmit | | Pointer to a buffer of data to transmit | ||
|- | |- | ||
− | ! | + | ! Size |
| The size of the buffer | | The size of the buffer | ||
|- | |- | ||
− | ! | + | ! Flags |
| The flags for this transfer (eg SPI_TRANSFER_DMA) | | The flags for this transfer (eg SPI_TRANSFER_DMA) | ||
|- | |- | ||
− | ! | + | ! Count |
| The number of bytes written on return | | The number of bytes written on return | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Because SPI writes and then reads for each byte, received data will be discarded for each by written | + | | Because SPI writes and then reads for each byte, received data will be discarded for each by written. |
|- | |- | ||
|} | |} | ||
Line 649: | Line 649: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to write to and read from | | The SPI device to write to and read from | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select for the slave to write to and read from (eg SPI_CS_0) | | The chip select for the slave to write to and read from (eg SPI_CS_0) | ||
|- | |- | ||
− | ! | + | ! Source |
| Pointer to a buffer of data to transmit | | Pointer to a buffer of data to transmit | ||
|- | |- | ||
− | ! | + | ! Dest |
| Pointer to a buffer to receive the data | | Pointer to a buffer to receive the data | ||
|- | |- | ||
− | ! | + | ! Size |
| The size of the buffer | | The size of the buffer | ||
|- | |- | ||
− | ! | + | ! Flags |
| The flags for this transfer (eg SPI_TRANSFER_DMA) | | The flags for this transfer (eg SPI_TRANSFER_DMA) | ||
|- | |- | ||
− | ! | + | ! Count |
| The number of bytes written and read on return | | The number of bytes written and read on return | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Because SPI writes and then reads for each byte, both the source and dest buffers must be the same size | + | | Because SPI writes and then reads for each byte, both the source and dest buffers must be the same size. |
|- | |- | ||
|} | |} | ||
Line 685: | Line 685: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get device mode from | | The SPI device to get device mode from | ||
|- | |- | ||
− | ! | + | ! Return |
| The device mode or SPI_MODE_UNKNOWN on failure | | The device mode or SPI_MODE_UNKNOWN on failure | ||
|- | |- | ||
Line 700: | Line 700: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to set device mode for | | The SPI device to set device mode for | ||
|- | |- | ||
− | ! | + | ! Mode |
| The device mode to set (eg SPI_MODE_4WIRE) | | The device mode to set (eg SPI_MODE_4WIRE) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 718: | Line 718: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get clock rate from | | The SPI device to get clock rate from | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select number to get clock rate from (SPI_CS_NONE for default) | | The chip select number to get clock rate from (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! Return |
| The clock rate in Hz or 0 on failure | | The clock rate in Hz or 0 on failure | ||
|- | |- | ||
Line 736: | Line 736: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to set clock rate for | | The SPI device to set clock rate for | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select number to set clock rate for (SPI_CS_NONE for default) | | The chip select number to set clock rate for (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! ClockRate |
| The clock rate to set in Hz | | The clock rate to set in Hz | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 757: | Line 757: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get clock phase from | | The SPI device to get clock phase from | ||
|- | |- | ||
− | ! | + | ! Return |
| The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure | | The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure | ||
|- | |- | ||
Line 772: | Line 772: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to set clock phase for | | The SPI device to set clock phase for | ||
|- | |- | ||
− | ! | + | ! ClockPhase |
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | | The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 790: | Line 790: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get clock polarity from | | The SPI device to get clock polarity from | ||
|- | |- | ||
− | ! | + | ! Return |
| The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure | | The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure | ||
|- | |- | ||
Line 805: | Line 805: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to set clock polarity for | | The SPI device to set clock polarity for | ||
|- | |- | ||
− | ! | + | ! ClockPolarity |
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | | The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 823: | Line 823: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get chip select polarity from | | The SPI device to get chip select polarity from | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select number to get polarity from (SPI_CS_NONE for default) | | The chip select number to get polarity from (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! Return |
| The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure | | The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure | ||
|- | |- | ||
Line 841: | Line 841: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to set chip select polarity for | | The SPI device to set chip select polarity for | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select number to set polarity for (SPI_CS_NONE for default) | | The chip select number to set polarity for (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! SelectPolarity |
| The chip select polarity to set (eg SPI_CS_POLARITY_LOW) | | The chip select polarity to set (eg SPI_CS_POLARITY_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 862: | Line 862: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get properties from | | The SPI device to get properties from | ||
|- | |- | ||
− | ! | + | ! Properties |
| Pointer to a TSPIProperties structure to fill in | | Pointer to a TSPIProperties structure to fill in | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
| Replaced by SPIDeviceGetProperties for consistency | | Replaced by SPIDeviceGetProperties for consistency | ||
|- | |- | ||
Line 883: | Line 883: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! SPI |
| The SPI device to get properties from | | The SPI device to get properties from | ||
|- | |- | ||
− | ! | + | ! Properties |
| Pointer to a TSPIProperties structure to fill in | | Pointer to a TSPIProperties structure to fill in | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 901: | Line 901: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Return |
| Pointer to new SPI entry or nil if SPI could not be created | | Pointer to new SPI entry or nil if SPI could not be created | ||
|- | |- | ||
Line 913: | Line 913: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Size |
| Size in bytes to allocate for new SPI (Including the SPI entry) | | Size in bytes to allocate for new SPI (Including the SPI entry) | ||
|- | |- | ||
− | ! | + | ! Return |
| Pointer to new SPI entry or nil if SPI could not be created | | Pointer to new SPI entry or nil if SPI could not be created | ||
|- | |- | ||
Line 928: | Line 928: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 940: | Line 940: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 952: | Line 952: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 964: | Line 964: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 976: | Line 976: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 988: | Line 988: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,000: | Line 1,000: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,012: | Line 1,012: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,027: | Line 1,027: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,039: | Line 1,039: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Mode |
− | | The device mode to set (eg SPI_MODE_4WIRE | + | | The device mode to set (eg SPI_MODE_4WIRE) |
|- | |- | ||
− | ! | + | ! ClockRate |
| The clock rate to set for the device | | The clock rate to set for the device | ||
|- | |- | ||
− | ! | + | ! ClockPhase |
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | | The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | ||
|- | |- | ||
− | ! | + | ! ClockPolarity |
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | | The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,063: | Line 1,063: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,075: | Line 1,075: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSet |
| The chip select for the slave to read from (eg SPI_CS_0) | | The chip select for the slave to read from (eg SPI_CS_0) | ||
|- | |- | ||
− | ! | + | ! Dest |
| Pointer to a buffer to receive the data | | Pointer to a buffer to receive the data | ||
|- | |- | ||
− | ! | + | ! Size |
| The size of the buffer | | The size of the buffer | ||
|- | |- | ||
− | ! | + | ! Count |
| The number of bytes read on return | | The number of bytes read on return | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Because SPI writes and then reads for each byte, dummy data will be written for each byte to be read | + | | Because SPI writes and then reads for each byte, dummy data will be written for each byte to be read. |
|- | |- | ||
|} | |} | ||
Line 1,102: | Line 1,102: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSet |
| The chip select for the slave to write to (eg SPI_CS_0) | | The chip select for the slave to write to (eg SPI_CS_0) | ||
|- | |- | ||
− | ! | + | ! Source |
| Pointer to a buffer of data to transmit | | Pointer to a buffer of data to transmit | ||
|- | |- | ||
− | ! | + | ! Size |
| The size of the buffer | | The size of the buffer | ||
|- | |- | ||
− | ! | + | ! Count |
| The number of bytes written on return | | The number of bytes written on return | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Because SPI writes and then reads for each byte, received data will be discarded for each by written | + | | Because SPI writes and then reads for each byte, received data will be discarded for each by written. |
|- | |- | ||
|} | |} | ||
Line 1,129: | Line 1,129: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSet |
| The chip select for the slave to write to and read from (eg SPI_CS_0) | | The chip select for the slave to write to and read from (eg SPI_CS_0) | ||
|- | |- | ||
− | ! | + | ! Source |
| Pointer to a buffer of data to transmit | | Pointer to a buffer of data to transmit | ||
|- | |- | ||
− | ! | + | ! Dest |
| Pointer to a buffer to receive the data | | Pointer to a buffer to receive the data | ||
|- | |- | ||
− | ! | + | ! Size |
| The size of the buffer | | The size of the buffer | ||
|- | |- | ||
− | ! | + | ! Count |
| The number of bytes written and read on return | | The number of bytes written and read on return | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
− | ! | + | ! Note |
− | | Because SPI writes and then reads for each byte, both the source and dest buffers must be the same size | + | | Because SPI writes and then reads for each byte, both the source and dest buffers must be the same size. |
|- | |- | ||
|} | |} | ||
Line 1,159: | Line 1,159: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Return |
| The device mode or SPI_MODE_UNKNOWN on failure | | The device mode or SPI_MODE_UNKNOWN on failure | ||
|- | |- | ||
Line 1,171: | Line 1,171: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Mode |
| The device mode to set (eg SPI_MODE_4WIRE) | | The device mode to set (eg SPI_MODE_4WIRE) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,186: | Line 1,186: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select number to get clock rate from (SPI_CS_NONE for default) | | The chip select number to get clock rate from (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! Return |
| The clock rate in Hz or 0 on failure | | The clock rate in Hz or 0 on failure | ||
|- | |- | ||
Line 1,201: | Line 1,201: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSelect |
| The chip select number to set clock rate for (SPI_CS_NONE for default) | | The chip select number to set clock rate for (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! ClockRate |
| The clock rate to set in Hz | | The clock rate to set in Hz | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,219: | Line 1,219: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Return |
| The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure | | The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure | ||
|- | |- | ||
Line 1,231: | Line 1,231: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ClockPhase |
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | | The clock phase to set (eg SPI_CLOCK_PHASE_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,246: | Line 1,246: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Return |
| The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure | | The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure | ||
|- | |- | ||
Line 1,258: | Line 1,258: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ClockPolarity |
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | | The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,273: | Line 1,273: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSet |
| The chip select number to get polarity from (SPI_CS_NONE for default) | | The chip select number to get polarity from (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! Return |
| The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure | | The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure | ||
|- | |- | ||
Line 1,288: | Line 1,288: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! ChipSet |
| The chip select number to set polarity for (SPI_CS_NONE for default) | | The chip select number to set polarity for (SPI_CS_NONE for default) | ||
|- | |- | ||
− | ! | + | ! SelectPolarity |
| The chip select polarity to set (eg SPI_CS_POLARITY_LOW) | | The chip select polarity to set (eg SPI_CS_POLARITY_LOW) | ||
|- | |- | ||
− | ! | + | ! Return |
| ERROR_SUCCESS if completed or another error code on failure | | ERROR_SUCCESS if completed or another error code on failure | ||
|- | |- | ||
Line 1,309: | Line 1,309: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,321: | Line 1,321: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,333: | Line 1,333: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,345: | Line 1,345: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,357: | Line 1,357: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,369: | Line 1,369: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,381: | Line 1,381: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,393: | Line 1,393: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,405: | Line 1,405: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,417: | Line 1,417: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,429: | Line 1,429: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,441: | Line 1,441: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,453: | Line 1,453: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 1,465: | Line 1,465: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- |
Revision as of 05:46, 20 April 2018
Return to Unit Reference
Contents
[hide]Description
Ultibo SPI interface unit
SPI (Serial Peripheral Interface) is a synchronous serial bus for communication with peripheral components.
The SPI protocol is not defined by any actual standard but some pseudo standards exist with all of the available devices. SPI is a master-slave protocol where the master asserts the chip select line (CS) to select the slave device before sending data one byte at a time. For every byte written to the bus by the master the selected slave returns a byte as well so for every write there is an equivalent read. SPI can also operate in either 4 wire (standard) or 3 wire(bidirectional) modes.
Due to the lack of formal standards and the range of devices that exist various options are provided to allow setting clock phase and polarity as well chip select polarity.
For the purpose of this interface a device is the SPI controller attached to the local system and may be either a master or a slave. Since the protocol does not include any form of enumeration or identification the interface does not attempt to represent the devices connected to the bus, any driver written to communicate with a connected SPI device should know (or allow configuration of) the chip select for the for the device and the specific message format required for that device.
Constants
SPI_*
SPI_TYPE_*
SPI_STATE_*
SPI_FLAG_*
SPI_TRANSFER_*
SPI_LOG_*
Type definitions
SPI properties
SPI chip select
SPI enumeration callback
TSPIEnumerate = function(SPI:PSPIDevice; Data:Pointer):LongWord;
|
SPI notification callback
TSPINotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
|
SPI device start
TSPIDeviceStart = function(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
|
SPI device stop
TSPIDeviceStop = function(SPI:PSPIDevice):LongWord;
|
SPI device read
TSPIDeviceRead = function(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
SPI device write
TSPIDeviceWrite = function(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
SPI device write read
TSPIDeviceWriteRead = function(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
SPI device get mode
TSPIDeviceGetMode = function(SPI:PSPIDevice):LongWord;
|
SPI device set mode
TSPIDeviceSetMode = function(SPI:PSPIDevice; Mode:LongWord):LongWord;
|
SPI device get clock rate
TSPIDeviceGetClockRate = function(SPI:PSPIDevice; ChipSelect:Word):LongWord;
|
SPI device set clock rate
TSPIDeviceSetClockRate = function(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;
|
SPI device get clock phase
TSPIDeviceGetClockPhase = function(SPI:PSPIDevice):LongWord;
|
SPI device set clock phase
TSPIDeviceSetClockPhase = function(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;
|
SPI device get clock polarity
TSPIDeviceGetClockPolarity = function(SPI:PSPIDevice):LongWord;
|
SPI device set clock polarity
TSPIDeviceSetClockPolarity = function(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;
|
SPI device get select polarity
TSPIDeviceGetSelectPolarity = function(SPI:PSPIDevice; ChipSelect:Word):LongWord;
|
SPI device set select polarity
TSPIDeviceSetSelectPolarity = function(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;
|
SPI device get properties
TSPIDeviceGetProperties = function(SPI:PSPIDevice; Properties:PSPIProperties):LongWord;
|
SPI device
Public variables
SPI logging
SPI_DEFAULT_LOG_LEVEL:LongWord = SPI_LOG_LEVEL_DEBUG;
|
Minimum level for SPI messages. Only messages with level greater than or equal to this will be printed. |
SPI_LOG_ENABLED:Boolean;
|
Function declarations
Initialization functions
SPI functions
function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
function SPIDeviceStop(SPI:PSPIDevice):LongWord;
function SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SPIDeviceWrite(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SPIDeviceWriteRead(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SPIDeviceGetMode(SPI:PSPIDevice):LongWord;
function SPIDeviceSetMode(SPI:PSPIDevice; Mode:LongWord):LongWord;
function SPIDeviceGetClockRate(SPI:PSPIDevice; ChipSelect:Word):LongWord;
function SPIDeviceSetClockRate(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;
function SPIDeviceGetClockPhase(SPI:PSPIDevice):LongWord;
function SPIDeviceSetClockPhase(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;
function SPIDeviceGetClockPolarity(SPI:PSPIDevice):LongWord;
function SPIDeviceSetClockPolarity(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;
function SPIDeviceGetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word):LongWord;
function SPIDeviceSetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;
function SPIDeviceProperties(SPI:PSPIDevice; Properties:PSPIProperties):LongWord; inline;
function SPIDeviceGetProperties(SPI:PSPIDevice;Properties:PSPIProperties):LongWord;
function SPIDeviceDestroy(SPI:PSPIDevice):LongWord;
function SPIDeviceRegister(SPI:PSPIDevice):LongWord;
function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;
function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;
function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;
function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;
function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
RTL SPI functions
function SysSPIStart(Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
function SysSPIStop:LongWord;
function SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSPIWrite(ChipSelect:Word; Source:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSPIGetMode:LongWord;
function SysSPISetMode(Mode:LongWord):LongWord;
function SysSPIGetClockRate(ChipSelect:Word):LongWord;
function SysSPISetClockRate(ChipSelect:Word; ClockRate:LongWord):LongWord;
function SysSPIGetClockPhase:LongWord;
function SysSPISetClockPhase(ClockPhase:LongWord):LongWord;
function SysSPIGetClockPolarity:LongWord;
function SysSPISetClockPolarity(ClockPolarity:LongWord):LongWord;
function SysSPIGetSelectPolarity(ChipSelect:Word):LongWord;
function SysSPISetSelectPolarity(ChipSelect:Word; SelectPolarity:LongWord):LongWord;
SPI helper functions
function SPIDeviceGetDefault:PSPIDevice; inline;
function SPIDeviceSetDefault(SPI:PSPIDevice):LongWord;
function SPIDeviceCheck(SPI:PSPIDevice):PSPIDevice;
procedure SPILog(Level:LongWord; SPI:PSPIDevice; const AText:String);
procedure SPILogInfo(SPI:PSPIDevice; const AText:String); inline;
procedure SPILogWarn(SPI:PSPIDevice; const AText:String); inline;
procedure SPILogError(SPI:PSPIDevice; const AText:String); inline;
procedure SPILogDebug(SPI:PSPIDevice; const AText:String); inline;
function SPISelectPolarityToString(Polarity:LongWord):String;
Return to Unit Reference