Difference between revisions of "Unit SPI"

From Ultibo.org
Jump to: navigation, search
 
(10 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
'''Ultibo SPI interface unit'''
+
'''Ultibo SPI Interface unit'''
  
 
SPI (Serial Peripheral Interface) is a synchronous serial bus for communication with peripheral components.
 
SPI (Serial Peripheral Interface) is a synchronous serial bus for communication with peripheral components.
Line 26: Line 26:
 
| <code>SPI_NAME_PREFIX = 'SPI';</code>
 
| <code>SPI_NAME_PREFIX = 'SPI';</code>
 
| Name prefix for SPI Devices
 
| Name prefix for SPI Devices
 +
|-
 +
| <code>SPISLAVE_NAME_PREFIX = 'SPISlave';</code>
 +
| Name prefix for SPI Slave Devices
 
|-
 
|-
 
|}
 
|}
Line 37: Line 40:
 
| <code>SPI_TYPE_NONE = 0;</code>
 
| <code>SPI_TYPE_NONE = 0;</code>
 
| style="width: 50%;"|&nbsp;
 
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>SPI_TYPE_MASTER = 1;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SPI_TYPE_SLAVE = 2;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SPI_TYPE_MAX = 2;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
|colspan="2"|SPI Type Names
 +
|-
 +
|colspan="2"|<code>SPI_TYPE_NAMES:array[SPI_TYPE_NONE..SPI_TYPE_MAX] of String = ('SPI_TYPE_NONE', 'SPI_TYPE_MASTER', 'SPI_TYPE_SLAVE');</code>
 
|-
 
|-
 
|}
 
|}
Line 50: Line 70:
 
|-
 
|-
 
| <code>SPI_STATE_ENABLED = 1;</code>
 
| <code>SPI_STATE_ENABLED = 1;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SPI_STATE_MAX = 1;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 103: Line 128:
 
| <code>SPI_TRANSFER_DMA = $00000001;</code>
 
| <code>SPI_TRANSFER_DMA = $00000001;</code>
 
| Use DMA for transfer (Write/Read) (Note: Buffers must be DMA compatible)
 
| Use DMA for transfer (Write/Read) (Note: Buffers must be DMA compatible)
 +
|-
 +
| <code>SPI_TRANSFER_PIO = $00000002;</code>
 +
| Use PIO (Polling) for transfer (Write/Read)
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SPI_TRANSFER_DELAY = $00000004;</code>
 +
| Add a delay after each byte written (Write/Read) Note: Only available with PIO transfer unless provided directly by hardware
 
|-
 
|-
 
|}
 
|}
Line 173: Line 206:
 
| <code>SelectPolarity:LongWord;</code>
 
| <code>SelectPolarity:LongWord;</code>
 
| Default chip select polarity (eg SPI_CS_POLARITY_LOW)
 
| Default chip select polarity (eg SPI_CS_POLARITY_LOW)
 +
|-
 +
| <code>ByteDelay:LongWord;</code>
 +
| Delay between bytes written (Microseconds)
 
|-
 
|-
 
|}
 
|}
Line 206: Line 242:
 
| <code>SelectPolarity:LongWord;</code>
 
| <code>SelectPolarity:LongWord;</code>
 
| The chip select polarity for this chip select (eg SPI_CS_POLARITY_LOW)
 
| The chip select polarity for this chip select (eg SPI_CS_POLARITY_LOW)
 +
|-
 +
| <code>ByteDelay:LongWord;</code>
 +
| Delay between bytes written for this chip select (Microseconds)
 
|-
 
|-
 
|}
 
|}
Line 359: Line 398:
 
|-
 
|-
 
| <code>TSPIDeviceSetSelectPolarity = function(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;</code>
 
| <code>TSPIDeviceSetSelectPolarity = function(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''SPI device get byte delay'''
 +
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetByteDelay = function(SPI:PSPIDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''SPI device set byte delay'''
 +
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceSetByteDelay = function(SPI:PSPIDevice; Delay:LongWord):LongWord;</code>
 
| style="width: 40%;"|
 
| style="width: 40%;"|
 
|-
 
|-
Line 441: Line 498:
 
| <code>DeviceSetSelectPolarity:TSPIDeviceSetSelectPolarity;</code>
 
| <code>DeviceSetSelectPolarity:TSPIDeviceSetSelectPolarity;</code>
 
| A Device specific DeviceSetSelectPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
 
| A Device specific DeviceSetSelectPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetByteDelay:TSPIDeviceGetByteDelay;</code>
 +
| A Device specific DeviceGetByteDelay method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetByteDelay:TSPIDeviceSetByteDelay;</code>
 +
| A Device specific DeviceSetByteDelay method implementing the standard SPI device interface (Or nil if the default method is suitable)
 
|-
 
|-
 
| <code>DeviceGetProperties:TSPIDeviceGetProperties;</code>
 
| <code>DeviceGetProperties:TSPIDeviceGetProperties;</code>
Line 526: Line 589:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Called only during system startup
 
| Called only during system startup
 
|-
 
|-
Line 541: Line 604:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to start
 
| The SPI device to start
 
|-
 
|-
! '''Mode'''
+
! Mode
 
| The device mode to set (eg SPI_MODE_4WIRE)
 
| The device mode to set (eg SPI_MODE_4WIRE)
 
|-
 
|-
! '''ClockRate'''
+
! ClockRate
 
| The clock rate to set for the device
 
| The clock rate to set for the device
 
|-
 
|-
! '''ClockPhase'''
+
! ClockPhase
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
|-
 
|-
! '''ClockPolarity'''
+
! ClockPolarity
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 568: Line 631:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to stop
 
| The SPI device to stop
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 583: Line 646:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to read from
 
| The SPI device to read from
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! Dest
 
| Pointer to a buffer to receive the data
 
| Pointer to a buffer to receive the data
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Flags'''
+
! Flags
 
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes read on return
 
| The number of bytes read on return
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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 679:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to write to
 
| The SPI device to write to
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! Source
 
| Pointer to a buffer of data to transmit
 
| Pointer to a buffer of data to transmit
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Flags'''
+
! Flags
 
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes written on return
 
| The number of bytes written on return
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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 byte written.
 
|-
 
|-
 
|}
 
|}
Line 649: Line 712:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to write to and read from
 
| The SPI device to write to and read from
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! Source
 
| Pointer to a buffer of data to transmit
 
| Pointer to a buffer of data to transmit
 
|-
 
|-
! '''Dest'''
+
! Dest
 
| Pointer to a buffer to receive the data
 
| Pointer to a buffer to receive the data
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Flags'''
+
! Flags
 
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes written and read on return
 
| The number of bytes written and read on return
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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 748:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get device mode from
 
| The SPI device to get device mode from
 
|-
 
|-
! '''Return'''
+
! Return
 
| The device mode or SPI_MODE_UNKNOWN on failure
 
| The device mode or SPI_MODE_UNKNOWN on failure
 
|-
 
|-
Line 700: Line 763:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to set device mode for
 
| The SPI device to set device mode for
 
|-
 
|-
! '''Mode'''
+
! Mode
 
| The device mode to set (eg SPI_MODE_4WIRE)
 
| The device mode to set (eg SPI_MODE_4WIRE)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 718: Line 781:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get clock rate from
 
| The SPI device to get clock rate from
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! Return
 
| The clock rate in Hz or 0 on failure
 
| The clock rate in Hz or 0 on failure
 
|-
 
|-
Line 736: Line 799:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to set clock rate for
 
| The SPI device to set clock rate for
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! ClockRate
 
| The clock rate to set in Hz
 
| The clock rate to set in Hz
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 757: Line 820:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get clock phase from
 
| The SPI device to get clock phase from
 
|-
 
|-
! '''Return'''
+
! Return
 
| The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure
 
| The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure
 
|-
 
|-
Line 772: Line 835:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to set clock phase for
 
| The SPI device to set clock phase for
 
|-
 
|-
! '''ClockPhase'''
+
! ClockPhase
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 790: Line 853:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get clock polarity from
 
| The SPI device to get clock polarity from
 
|-
 
|-
! '''Return'''
+
! Return
 
| The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure
 
| The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure
 
|-
 
|-
Line 805: Line 868:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to set clock polarity for
 
| The SPI device to set clock polarity for
 
|-
 
|-
! '''ClockPolarity'''
+
! ClockPolarity
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 823: Line 886:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get chip select polarity from
 
| The SPI device to get chip select polarity from
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! 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 904:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to set chip select polarity for
 
| The SPI device to set chip select polarity for
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! SelectPolarity
 
| The chip select polarity to set (eg SPI_CS_POLARITY_LOW)
 
| The chip select polarity to set (eg SPI_CS_POLARITY_LOW)
 
|-
 
|-
! '''Return'''
+
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceGetByteDelay(SPI:PSPIDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the delay between bytes written for the specified SPI device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! SPI
 +
| The SPI device to get the byte delay from
 +
|-
 +
! Return
 +
| The byte delay in microseconds, 0 if not set or on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceSetByteDelay(SPI:PSPIDevice; Delay:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the delay between bytes written for the specified SPI device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! SPI
 +
| The SPI device to set byte delay for
 +
|-
 +
! Delay
 +
| The byte delay to set in microseconds
 +
|-
 +
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 862: Line 958:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get properties from
 
| The SPI device to get properties from
 
|-
 
|-
! '''Properties'''
+
! Properties
 
| Pointer to a TSPIProperties structure to fill in
 
| Pointer to a TSPIProperties structure to fill in
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! Note
 
| Replaced by SPIDeviceGetProperties for consistency
 
| Replaced by SPIDeviceGetProperties for consistency
 
|-
 
|-
Line 883: Line 979:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''SPI'''
+
! SPI
 
| The SPI device to get properties from
 
| The SPI device to get properties from
 
|-
 
|-
! '''Properties'''
+
! Properties
 
| Pointer to a TSPIProperties structure to fill in
 
| Pointer to a TSPIProperties structure to fill in
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 901: Line 997:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! 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 1,009:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Size'''
+
! 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'''
+
! 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 1,024:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! SPI
| None documented
+
| The SPI device to destroy
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 940: Line 1,039:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! SPI
| None documented
+
| The SPI device to register
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 948: Line 1,050:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister a SPI from the SPI table</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister an SPI from the SPI table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! SPI
| None documented
+
| The SPI device to deregister
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 960: Line 1,065:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceFind(SPIId:LongWord):PSPIDevice;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceFind(SPIId:LongWord):PSPIDevice;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' ERROR_SUCCESS if completed or another error code on failure</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! SPIId
| None documented
+
| The ID number of the SPI device to find
 +
|-
 +
! Return
 +
| Pointer to SPI device entry or nil if not found
 
|-
 
|-
 
|}
 
|}
Line 972: Line 1,080:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an SPI device by name in the device table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Name
| None documented
+
| The name of the SPI device to find (eg SPI0)
 +
|-
 +
! Return
 +
| Pointer to SPI device entry or nil if not found
 
|-
 
|-
 
|}
 
|}
Line 984: Line 1,095:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find an SPI device by description in the device table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Description
| None documented
+
| The description of the SPI to find (eg BCM2837 SPI0 Master)
 +
|-
 +
! Return
 +
| Pointer to SPI device entry or nil if not found
 
|-
 
|-
 
|}
 
|}
Line 996: Line 1,110:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Enumerate all SPI devices in the SPI table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Callback
| None documented
+
| The callback function to call for each SPI device in the table
 +
|-
 +
! Data
 +
| A private data pointer to pass to callback for each SPI device in the table
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 1,008: Line 1,128:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Register a notification for SPI device changes</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Device
| None documented
+
| The SPI device to notify changes for (Optional, pass nil for all SPI devices)
 +
|-
 +
! Callback
 +
| The function to call when a notification event occurs
 +
|-
 +
! Data
 +
| A private data pointer to pass to callback when a notification event occurs
 +
|-
 +
! Notification
 +
| The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
 +
|-
 +
! Flags
 +
| The flags to control the notification (eg NOTIFIER_FLAG_WORKER)
 
|-
 
|-
 
|}
 
|}
Line 1,027: Line 1,159:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,039: Line 1,171:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Mode'''
+
! Mode
| The device mode to set (eg SPI_MODE_4WIRE")
+
| The device mode to set (eg SPI_MODE_4WIRE)
 
|-
 
|-
! '''ClockRate'''
+
! ClockRate
 
| The clock rate to set for the device
 
| The clock rate to set for the device
 
|-
 
|-
! '''ClockPhase'''
+
! ClockPhase
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
|-
 
|-
! '''ClockPolarity'''
+
! ClockPolarity
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
|-
 
|-
! '''Return'''
+
! 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,195:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! 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,207:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSet'''
+
! 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'''
+
! Dest
 
| Pointer to a buffer to receive the data
 
| Pointer to a buffer to receive the data
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes read on return
 
| The number of bytes read on return
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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,234:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSet'''
+
! 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'''
+
! Source
 
| Pointer to a buffer of data to transmit
 
| Pointer to a buffer of data to transmit
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes written on return
 
| The number of bytes written on return
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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 byte written.
 
|-
 
|-
 
|}
 
|}
Line 1,129: Line 1,261:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSet'''
+
! 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'''
+
! Source
 
| Pointer to a buffer of data to transmit
 
| Pointer to a buffer of data to transmit
 
|-
 
|-
! '''Dest'''
+
! Dest
 
| Pointer to a buffer to receive the data
 
| Pointer to a buffer to receive the data
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes written and read on return
 
| The number of bytes written and read on return
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
! '''Note'''
+
! 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,291:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
 
| The device mode or SPI_MODE_UNKNOWN on failure
 
| The device mode or SPI_MODE_UNKNOWN on failure
 
|-
 
|-
Line 1,171: Line 1,303:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Mode'''
+
! Mode
 
| The device mode to set (eg SPI_MODE_4WIRE)
 
| The device mode to set (eg SPI_MODE_4WIRE)
 
|-
 
|-
! '''Return'''
+
! 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,318:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! Return
 
| The clock rate in Hz or 0 on failure
 
| The clock rate in Hz or 0 on failure
 
|-
 
|-
Line 1,201: Line 1,333:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSelect'''
+
! 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'''
+
! ClockRate
 
| The clock rate to set in Hz
 
| The clock rate to set in Hz
 
|-
 
|-
! '''Return'''
+
! 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,351:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! 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,363:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ClockPhase'''
+
! ClockPhase
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 
|-
 
|-
! '''Return'''
+
! 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,378:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! 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,390:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ClockPolarity'''
+
! ClockPolarity
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 
|-
 
|-
! '''Return'''
+
! 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,405:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSet'''
+
! 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'''
+
! 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,420:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''ChipSet'''
+
! 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'''
+
! SelectPolarity
 
| The chip select polarity to set (eg SPI_CS_POLARITY_LOW)
 
| The chip select polarity to set (eg SPI_CS_POLARITY_LOW)
 
|-
 
|-
! '''Return'''
+
! Return
 
| ERROR_SUCCESS if completed or another error code on failure
 
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
Line 1,304: Line 1,436:
  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function SPIGetCount:LongWord; inline;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function SPIGetCount:LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current SPI count</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current SPI count</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,316: Line 1,448:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceGetDefault:PSPIDevice; inline;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceGetDefault:PSPIDevice;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default SPI device</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default SPI device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,333: Line 1,465:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,345: Line 1,477:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SPITypeToString(SPIType:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert an SPI type value to a string</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SPIStateToString(SPIState:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert an SPI state value to a string</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,357: Line 1,513:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,369: Line 1,525:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,381: Line 1,537:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,393: Line 1,549:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,405: Line 1,561:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,417: Line 1,573:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,429: Line 1,585:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,441: Line 1,597:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,453: Line 1,609:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,465: Line 1,621:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-

Latest revision as of 04:41, 10 October 2023

Return to Unit Reference


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



[Expand]
SPI specific constants SPI_*


[Expand]
SPI device type SPI_TYPE_*


[Expand]
SPI device state SPI_STATE_*


[Expand]
SPI device flag SPI_FLAG_*


[Expand]
SPI transfer flag SPI_TRANSFER_*


[Expand]
SPI logging SPI_LOG_*


Type definitions



SPI properties

[Expand]

PSPIProperties = ^TSPIProperties;

TSPIProperties = record

SPI chip select

[Expand]

PSPIChipSelect = ^TSPIChipSelect;

TSPIChipSelect = record

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 byte delay

TSPIDeviceGetByteDelay = function(SPI:PSPIDevice):LongWord;

SPI device set byte delay

TSPIDeviceSetByteDelay = function(SPI:PSPIDevice; Delay:LongWord):LongWord;

SPI device get properties

TSPIDeviceGetProperties = function(SPI:PSPIDevice; Properties:PSPIProperties):LongWord;

SPI device

[Expand]

PSPIDevice = ^TSPIDevice;

TSPIDevice = record


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

[Expand]
procedure SPIInit;
Description: Initialize the SPI unit and SPI device table


SPI functions

[Expand]
function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
Description: Start the specified SPI device ready for writing and reading


[Expand]
function SPIDeviceStop(SPI:PSPIDevice):LongWord;
Description: Stop the specified SPI device and terminate writing and reading


[Expand]
function SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read data from the specified SPI device


[Expand]
function SPIDeviceWrite(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Write data to the specified SPI device


[Expand]
function SPIDeviceWriteRead(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Write data to and Read data from the specified SPI device in one operation


[Expand]
function SPIDeviceGetMode(SPI:PSPIDevice):LongWord;
Description: Get the device mode of the specified SPI device


[Expand]
function SPIDeviceSetMode(SPI:PSPIDevice; Mode:LongWord):LongWord;
Description: Set the device mode for the specified SPI device


[Expand]
function SPIDeviceGetClockRate(SPI:PSPIDevice; ChipSelect:Word):LongWord;
Description: Get the clock rate of the specified SPI device


[Expand]
function SPIDeviceSetClockRate(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;
Description: Set the clock rate for the specified SPI device


[Expand]
function SPIDeviceGetClockPhase(SPI:PSPIDevice):LongWord;
Description: Get the clock phase of the specified SPI device


[Expand]
function SPIDeviceSetClockPhase(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;
Description: Set the clock phase for the specified SPI device


[Expand]
function SPIDeviceGetClockPolarity(SPI:PSPIDevice):LongWord;
Description: Get the clock polarity of the specified SPI device


[Expand]
function SPIDeviceSetClockPolarity(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;
Description: Set the clock polarity for the specified SPI device


[Expand]
function SPIDeviceGetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word):LongWord;
Description: Get the chip select polarity of the specified SPI device


[Expand]
function SPIDeviceSetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;
Description: Set the chip select polarity for the specified SPI device


[Expand]
function SPIDeviceGetByteDelay(SPI:PSPIDevice):LongWord;
Description: Get the delay between bytes written for the specified SPI device


[Expand]
function SPIDeviceSetByteDelay(SPI:PSPIDevice; Delay:LongWord):LongWord;
Description: Set the delay between bytes written for the specified SPI device


[Expand]
function SPIDeviceProperties(SPI:PSPIDevice; Properties:PSPIProperties):LongWord; inline;
Description: Get the properties for the specified SPI device


[Expand]
function SPIDeviceGetProperties(SPI:PSPIDevice;Properties:PSPIProperties):LongWord;
Description: Get the properties for the specified SPI device


[Expand]
function SPIDeviceCreate:PSPIDevice;
Description: Create a new SPI entry


[Expand]
function SPIDeviceCreateEx(Size:LongWord):PSPIDevice;
Description: Create a new SPI entry


[Expand]
function SPIDeviceDestroy(SPI:PSPIDevice):LongWord;
Description: Destroy an existing SPI entry


[Expand]
function SPIDeviceRegister(SPI:PSPIDevice):LongWord;
Description: Register a new SPI in the SPI table


[Expand]
function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;
Description: Deregister an SPI from the SPI table


[Expand]
function SPIDeviceFind(SPIId:LongWord):PSPIDevice;
Description: ERROR_SUCCESS if completed or another error code on failure


[Expand]
function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;
Description: Find an SPI device by name in the device table


[Expand]
function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;
Description: Find an SPI device by description in the device table


[Expand]
function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;
Description: Enumerate all SPI devices in the SPI table


[Expand]
function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for SPI device changes


RTL SPI functions

[Expand]
function SysSPIAvailable:Boolean; 
Description: Check if an SPI device is available


[Expand]
function SysSPIStart(Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
Description: Start the default SPI device ready for writing and reading


[Expand]
function SysSPIStop:LongWord;
Description: Stop the default SPI device and terminate writing and reading


[Expand]
function SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Read data from the default SPI device


[Expand]
function SysSPIWrite(ChipSelect:Word; Source:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Write data to the default SPI device


[Expand]
function SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Write data to and Read data from the default SPI device in one operation


[Expand]
function SysSPIGetMode:LongWord;
Description: Get the device mode of the default SPI device


[Expand]
function SysSPISetMode(Mode:LongWord):LongWord;
Description: Set the device mode for the default SPI device


[Expand]
function SysSPIGetClockRate(ChipSelect:Word):LongWord;
Description: Get the clock rate of the default SPI device


[Expand]
function SysSPISetClockRate(ChipSelect:Word; ClockRate:LongWord):LongWord;
Description: Set the clock rate for the default SPI device


[Expand]
function SysSPIGetClockPhase:LongWord;
Description: Get the clock phase of the default SPI device


[Expand]
function SysSPISetClockPhase(ClockPhase:LongWord):LongWord;
Description: Set the clock phase for the default SPI device


[Expand]
function SysSPIGetClockPolarity:LongWord;
Description: Get the clock polarity of the default SPI device


[Expand]
function SysSPISetClockPolarity(ClockPolarity:LongWord):LongWord;
Description: Set the clock polarity for the default SPI device


[Expand]
function SysSPIGetSelectPolarity(ChipSelect:Word):LongWord;
Description: Get the chip select polarity of the default SPI device


[Expand]
function SysSPISetSelectPolarity(ChipSelect:Word; SelectPolarity:LongWord):LongWord;
Description: Set the chip select polarity for the default SPI device


SPI helper functions

[Expand]
function SPIGetCount:LongWord;
Description: Get the current SPI count


[Expand]
function SPIDeviceGetDefault:PSPIDevice;
Description: Get the current default SPI device


[Expand]
function SPIDeviceSetDefault(SPI:PSPIDevice):LongWord;
Description: Set the current default SPI device


[Expand]
function SPIDeviceCheck(SPI:PSPIDevice):PSPIDevice;
Description: Check if the supplied SPI is in the SPI table


[Expand]
function SPITypeToString(SPIType:LongWord):String;
Description: Convert an SPI type value to a string


[Expand]
function SPIStateToString(SPIState:LongWord):String;
Description: Convert an SPI state value to a string


[Expand]
procedure SPILog(Level:LongWord; SPI:PSPIDevice; const AText:String);
Description: To be documented


[Expand]
procedure SPILogInfo(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure SPILogWarn(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure SPILogError(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure SPILogDebug(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented


[Expand]
function SPIChipSelectToString(ChipSelect:Word):String;
Description: To be documented


[Expand]
function SPIModeToString(Mode:LongWord):String;
Description: To be documented


[Expand]
function SPIClockPhaseToString(Phase:LongWord):String;
Description: To be documented


[Expand]
function SPIClockPolarityToString(Polarity:LongWord):String;
Description: To be documented


[Expand]
function SPISelectPolarityToString(Polarity:LongWord):String;
Description: To be documented


Return to Unit Reference