Difference between revisions of "Unit SPI"

From Ultibo.org
Jump to: navigation, search
 
(35 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
=== Description ===
 
=== Description ===
 
----
 
----
 +
 +
'''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.
 
   
 
   
The SPI protocol is not defined by any actual standard but some psuedo standards exist with all of the available devices. SPI is a master-slave protocol where the master asserts the chip selectline (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.
+
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.
 
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.
Line 16: Line 18:
 
----
 
----
  
''To be documented''
+
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''SPI specific constants''' <code> SPI_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SPI_NAME_PREFIX = 'SPI';</code>
 +
| Name prefix for SPI Devices
 +
|-
 +
| <code>SPISLAVE_NAME_PREFIX = 'SPISlave';</code>
 +
| Name prefix for SPI Slave Devices
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''SPI device type''' <code> SPI_TYPE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SPI_TYPE_NONE = 0;</code>
 +
| 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>
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''SPI device state''' <code> SPI_STATE_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SPI_STATE_DISABLED = 0;</code>
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
| <code>SPI_STATE_ENABLED = 1;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SPI_STATE_MAX = 1;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''SPI device flag''' <code> SPI_FLAG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SPI_FLAG_NONE = $00000000;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SPI_FLAG_SLAVE = $00000001;</code>
 +
| Device is a slave not a master
 +
|-
 +
| <code>SPI_FLAG_4WIRE = $00000002;</code>
 +
| Device supports 4 wire operation (CS/MISO/MOSI/SCLK)
 +
|-
 +
| <code>SPI_FLAG_3WIRE = $00000004;</code>
 +
| Device supports 3 wire operation (CS/MIMO/SCLK)
 +
|-
 +
| <code>SPI_FLAG_LOSSI = $00000008;</code>
 +
| Device supports LoSSI (Low Speed Serial) mode (CS/SCL/SDA)
 +
|-
 +
| <code>SPI_FLAG_CPOL = $00000010;</code>
 +
| Device supports Clock Polarity setting
 +
|-
 +
| <code>SPI_FLAG_CPHA = $00000020;</code>
 +
| Device supports Clock Phase setting
 +
|-
 +
| <code>SPI_FLAG_CSPOL = $00000040;</code>
 +
| Device supports Chip Select Polarity setting
 +
|-
 +
| <code>SPI_FLAG_NO_CS = $00000080;</code>
 +
| Device supports Chip Select None (CS handled externally)
 +
|-
 +
| <code>SPI_FLAG_DMA = $00000100;</code>
 +
| Device supports DMA transfers
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''SPI transfer flag''' <code> SPI_TRANSFER_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SPI_TRANSFER_NONE = $00000000;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SPI_TRANSFER_DMA = $00000001;</code>
 +
| 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
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''SPI logging''' <code> SPI_LOG_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SPI_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;</code>
 +
| SPI debugging messages
 +
|-
 +
| <code>SPI_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code>
 +
| SPI informational messages, such as a device being attached or detached
 +
|-
 +
| <code>SPI_LOG_LEVEL_WARN = LOG_LEVEL_WARN;</code>
 +
| SPI warning messages
 +
|-
 +
| <code>SPI_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code>
 +
| SPI error messages
 +
|-
 +
| <code>SPI_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code>
 +
| No SPI messages
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Type definitions ===
 
=== Type definitions ===
 
----
 
----
  
''To be documented''
+
 
 +
'''SPI properties'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PSPIProperties = ^TSPIProperties;</code>
 +
 
 +
<code>TSPIProperties = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Flags:LongWord;</code>
 +
| Device flags (eg SPI_FLAG_SLAVE)
 +
|-
 +
| <code>MaxSize:LongWord;</code>
 +
| Maximum supported data transfer size
 +
|-
 +
| <code>MinClock:LongWord;</code>
 +
| Minimum supported clock rate
 +
|-
 +
| <code>MaxClock:LongWord;</code>
 +
| Maximum supported clock rate
 +
|-
 +
| <code>SelectCount:LongWord;</code>
 +
| Number of chip selects supported
 +
|-
 +
| <code>Mode:LongWord;</code>
 +
| Current mode (eg SPI_MODE_4WIRE)
 +
|-
 +
| <code>ClockRate:LongWord;</code>
 +
| Current clock rate
 +
|-
 +
| <code>ClockPhase:LongWord;</code>
 +
| Current clock phase (CPHA) (eg SPI_CLOCK_PHASE_LOW)
 +
|-
 +
| <code>ClockPolarity:LongWord;</code>
 +
| Current clock polarity (CPOL) (eg SPI_CLOCK_POLARITY_LOW)
 +
|-
 +
| <code>SelectPolarity:LongWord;</code>
 +
| Default chip select polarity (eg SPI_CS_POLARITY_LOW)
 +
|-
 +
| <code>ByteDelay:LongWord;</code>
 +
| Delay between bytes written (Microseconds)
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''SPI chip select'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PSPIChipSelect = ^TSPIChipSelect;</code>
 +
 
 +
<code>TSPIChipSelect = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Pin:LongWord;</code>
 +
| The GPIO pin for this chip select (eg GPIO_PIN_46)(GPIO_PIN_UNKNOWN for internal)
 +
|-
 +
| <code>Mode:LongWord;</code>
 +
| The mode for this chip select (eg SPI_MODE_0)
 +
|-
 +
| <code>Divider:LongWord;</code>
 +
| The clock divider for this chip select (Used internally by drivers)
 +
|-
 +
| <code>ClockRate:LongWord;</code>
 +
| The clock rate for this chip select
 +
|-
 +
| <code>ClockPhase:LongWord;</code>
 +
| The clock phase (CPHA) for this chip select (eg SPI_CLOCK_PHASE_LOW)
 +
|-
 +
| <code>ClockPolarity:LongWord;</code>
 +
| The clock polarity (CPOL) for this chip select (eg SPI_CLOCK_POLARITY_LOW)
 +
|-
 +
| <code>SelectPolarity:LongWord;</code>
 +
| 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)
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''SPI enumeration callback'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIEnumerate = function(SPI:PSPIDevice; Data:Pointer):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI notification callback'''
 +
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPINotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device start'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceStart = function(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device stop'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceStop = function(SPI:PSPIDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device read'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceRead = function(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device write'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceWrite = function(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device write read'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceWriteRead = function(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device get mode'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetMode = function(SPI:PSPIDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device set mode'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceSetMode = function(SPI:PSPIDevice; Mode:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device get clock rate'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetClockRate = function(SPI:PSPIDevice; ChipSelect:Word):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device set clock rate'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceSetClockRate = function(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device get clock phase'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetClockPhase = function(SPI:PSPIDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device set clock phase'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceSetClockPhase = function(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device get clock polarity'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetClockPolarity = function(SPI:PSPIDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device set clock polarity'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceSetClockPolarity = function(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device get select polarity'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetSelectPolarity = function(SPI:PSPIDevice; ChipSelect:Word):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device set select polarity'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <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%;"|
 +
|-
 +
|}
 +
 
 +
'''SPI device get properties'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSPIDeviceGetProperties = function(SPI:PSPIDevice; Properties:PSPIProperties):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''SPI device'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PSPIDevice = ^TSPIDevice;</code>
 +
 
 +
<code>TSPIDevice = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''Device Properties''
 +
|-
 +
| <code>Device:TDevice;</code>
 +
| The Device entry for this SPI
 +
|-
 +
|colspan="2"|''SPI Properties''
 +
|-
 +
| <code>SPIId:LongWord;</code>
 +
| Unique Id of this SPI in the SPI table
 +
|-
 +
| <code>SPIState:LongWord;</code>
 +
| SPI state (eg SPI_STATE_ENABLED)
 +
|-
 +
| <code>SPIMode:LongWord;</code>
 +
| SPI mode (eg SPI_MODE_4WIRE)
 +
|-
 +
| <code>DeviceStart:TSPIDeviceStart;</code>
 +
| A Device specific DeviceStart method implementing the standard SPI device interface (Mandatory)
 +
|-
 +
| <code>DeviceStop:TSPIDeviceStop;</code>
 +
| A Device specific DeviceStop method implementing the standard SPI device interface (Mandatory)
 +
|-
 +
| <code>DeviceRead:TSPIDeviceRead;</code>
 +
| A Device specific DeviceRead method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceWrite:TSPIDeviceWrite;</code>
 +
| A Device specific DeviceWrite method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceWriteRead:TSPIDeviceWriteRead;</code>
 +
| A Device specific DeviceWriteRead method implementing the standard SPI device interface (Mandatory)
 +
|-
 +
| <code>DeviceGetMode:TSPIDeviceGetMode;</code>
 +
| A Device specific DeviceGetMode method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetMode:TSPIDeviceSetMode;</code>
 +
| A Device specific DeviceSetMode method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetClockRate:TSPIDeviceGetClockRate;</code>
 +
| A Device specific DeviceGetClockRate method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetClockRate:TSPIDeviceSetClockRate;</code>
 +
| A Device specific DeviceSetClockRate method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetClockPhase:TSPIDeviceGetClockPhase;</code>
 +
| A Device specific DeviceGetClockPhase method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetClockPhase:TSPIDeviceSetClockPhase;</code>
 +
| A Device specific DeviceSetClockPhase method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetClockPolarity:TSPIDeviceGetClockPolarity;</code>
 +
| A Device specific DeviceGetClockPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetClockPolarity:TSPIDeviceSetClockPolarity;</code>
 +
| A Device specific DeviceSetClockPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetSelectPolarity:TSPIDeviceGetSelectPolarity;</code>
 +
| A Device specific DeviceGetSelectPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetSelectPolarity:TSPIDeviceSetSelectPolarity;</code>
 +
| 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>
 +
| A Device specific DeviceGetProperties method implementing the standard SPI device interface (Or nil if the default method is suitable)
 +
|-
 +
|colspan="2"|''Statistics Properties''
 +
|-
 +
| <code>TransferCount:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>TransferErrors:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''Driver Properties''
 +
|-
 +
| <code>Lock:TMutexHandle;</code>
 +
| Device lock
 +
|-
 +
| <code>Wait:TSemaphoreHandle;</code>
 +
| Write/Read wait event
 +
|-
 +
| <code>Divider:LongWord;</code>
 +
| Clock divider (Used internally by drivers)
 +
|-
 +
| <code>ClockRate:LongWord;</code>
 +
| Clock rate (Hz)
 +
|-
 +
| <code>ClockPhase:LongWord;</code>
 +
| Clock Phase (eg SPI_CLOCK_PHASE_LOW)
 +
|-
 +
| <code>ClockPolarity:LongWord;</code>
 +
| Clock Polarity (eg SPI_CLOCK_POLARITY_LOW)
 +
|-
 +
| <code>SelectPolarity:LongWord;</code>
 +
| Default Chip Select Polarity (eg SPI_CS_POLARITY_LOW)
 +
|-
 +
| <code>Properties:TSPIProperties;</code>
 +
|  Device properties
 +
|-
 +
| <code>ChipSelects:array[0..SPI_CS_MAX] of TSPIChipSelect;</code>
 +
| Chip selects
 +
|-
 +
|colspan="2"|''Internal Properties''
 +
|-
 +
| <code>Prev:PSPIDevice;</code>
 +
| Previous entry in SPI table
 +
|-
 +
| <code>Next:PSPIDevice;</code>
 +
| Next entry in SPI table
 +
|-
 +
|}
 +
</div></div> 
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
 
----
 
----
  
''To be documented''
+
 
 +
'''SPI logging'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>SPI_DEFAULT_LOG_LEVEL:LongWord = SPI_LOG_LEVEL_DEBUG;</code>
 +
| style="width: 40%;"|Minimum level for SPI messages. Only messages with level greater than or equal to this will be printed.
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>SPI_LOG_ENABLED:Boolean;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
<br />
  
 
=== Function declarations ===
 
=== Function declarations ===
Line 40: 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 55: 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 82: 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
 +
|-
 +
|}
 +
</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 SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from 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 read from
 +
|-
 +
! ChipSelect
 +
| The chip select for the slave to read from (eg SPI_CS_0)
 +
|-
 +
! Dest
 +
| Pointer to a buffer to receive the data
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Flags
 +
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 +
|-
 +
! Count
 +
| The number of bytes read on return
 +
|-
 +
! Return
 +
| 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.
 
|-
 
|-
 
|}
 
|}
Line 97: 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.
 +
|-
 +
|}
 +
</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 SPIDeviceWriteRead(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to and Read data from the specified SPI device in one operation</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 write to and read from
 +
|-
 +
! ChipSelect
 +
| 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
 +
|-
 +
! Dest
 +
| Pointer to a buffer to receive the data
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Flags
 +
| The flags for this transfer (eg SPI_TRANSFER_DMA)
 +
|-
 +
! Count
 +
| The number of bytes written and read on return
 +
|-
 +
! Return
 +
| 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.
 +
|-
 +
|}
 +
</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 SPIDeviceGetMode(SPI:PSPIDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the device mode of 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 device mode from
 +
|-
 +
! Return
 +
| The device mode or SPI_MODE_UNKNOWN on failure
 
|-
 
|-
 
|}
 
|}
Line 130: 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
 +
|-
 +
|}
 +
</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 SPIDeviceGetClockRate(SPI:PSPIDevice; ChipSelect:Word):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the clock rate of 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 clock rate from
 +
|-
 +
! ChipSelect
 +
| The chip select number to get clock rate from (SPI_CS_NONE for default)
 +
|-
 +
! Return
 +
| The clock rate in Hz or 0 on failure
 
|-
 
|-
 
|}
 
|}
Line 148: 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
 +
|-
 +
|}
 +
</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 SPIDeviceGetClockPhase(SPI:PSPIDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the clock phase of 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 clock phase from
 +
|-
 +
! Return
 +
| The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure
 
|-
 
|-
 
|}
 
|}
Line 169: 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
 +
|-
 +
|}
 +
</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 SPIDeviceGetClockPolarity(SPI:PSPIDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the clock polarity of 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 clock polarity from
 +
|-
 +
! Return
 +
| The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure
 
|-
 
|-
 
|}
 
|}
Line 187: 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
 +
|-
 +
|}
 +
</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 SPIDeviceGetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the chip select polarity of 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 chip select polarity from
 +
|-
 +
! ChipSelect
 +
| 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
 
|-
 
|-
 
|}
 
|}
Line 205: 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
 +
|-
 +
|}
 +
</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 SPIDeviceProperties(SPI:PSPIDevice; Properties:PSPIProperties):LongWord; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties 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 properties from
 +
|-
 +
! Properties
 +
| Pointer to a TSPIProperties structure to fill in
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
! Note
 +
| Replaced by SPIDeviceGetProperties for consistency
 +
|-
 +
|}
 +
</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 SPIDeviceGetProperties(SPI:PSPIDevice;Properties:PSPIProperties):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties 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 properties from
 +
|-
 +
! Properties
 +
| 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 226: 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 238: 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 253: 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 265: 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
 +
|-
 +
|}
 +
</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 SPIDeviceDeregister(SPI:PSPIDevice):LongWord;</pre>
 +
<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;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! SPI
 +
| The SPI device to deregister
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 273: 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 285: 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 297: 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 309: 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 321: 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 340: 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 352: 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 376: 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
 +
|-
 +
|}
 +
</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 SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from the default SPI device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! ChipSet
 +
| The chip select for the slave to read from (eg SPI_CS_0)
 +
|-
 +
! Dest
 +
| Pointer to a buffer to receive the data
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Count
 +
| The number of bytes read on return
 +
|-
 +
! Return
 +
| 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.
 
|-
 
|-
 
|}
 
|}
Line 388: 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
 +
|-
 +
! Note
 +
| Because SPI writes and then reads for each byte, received data will be discarded for each byte written.
 +
|-
 +
|}
 +
</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 SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to and Read data from the default SPI device in one operation</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| 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)
 +
|-
 +
! Source
 +
| Pointer to a buffer of data to transmit
 +
|-
 +
! Dest
 +
| Pointer to a buffer to receive the data
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Count
 +
| 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'''
+
! 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, both the source and dest buffers must be the same size.
 
|-
 
|-
 
|}
 
|}
Line 415: 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 427: 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 442: 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 ?rom (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 457: 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 475: 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 487: 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 502: 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 514: 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
 +
|-
 +
|}
 +
</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 SysSPIGetSelectPolarity(ChipSelect:Word):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the chip select polarity of the default SPI device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! ChipSet
 +
| 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
 
|-
 
|-
 
|}
 
|}
Line 529: 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 545: 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 557: 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 574: 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 586: 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 598: 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 610: Line 1,525:
 
{| 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;">procedure SPILogWarn(SPI:PSPIDevice; const AText:String); inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</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 622: 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 634: 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 646: 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 658: 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 670: 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 682: 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 694: 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



SPI specific constants SPI_*
SPI_NAME_PREFIX = 'SPI'; Name prefix for SPI Devices
SPISLAVE_NAME_PREFIX = 'SPISlave'; Name prefix for SPI Slave Devices


SPI device type SPI_TYPE_*
SPI_TYPE_NONE = 0;  
SPI_TYPE_MASTER = 1;  
SPI_TYPE_SLAVE = 2;  
 
SPI_TYPE_MAX = 2;  
 
SPI Type Names
SPI_TYPE_NAMES:array[SPI_TYPE_NONE..SPI_TYPE_MAX] of String = ('SPI_TYPE_NONE', 'SPI_TYPE_MASTER', 'SPI_TYPE_SLAVE');


SPI device state SPI_STATE_*
SPI_STATE_DISABLED = 0;  
SPI_STATE_ENABLED = 1;  
 
SPI_STATE_MAX = 1;  


SPI device flag SPI_FLAG_*
SPI_FLAG_NONE = $00000000;  
SPI_FLAG_SLAVE = $00000001; Device is a slave not a master
SPI_FLAG_4WIRE = $00000002; Device supports 4 wire operation (CS/MISO/MOSI/SCLK)
SPI_FLAG_3WIRE = $00000004; Device supports 3 wire operation (CS/MIMO/SCLK)
SPI_FLAG_LOSSI = $00000008; Device supports LoSSI (Low Speed Serial) mode (CS/SCL/SDA)
SPI_FLAG_CPOL = $00000010; Device supports Clock Polarity setting
SPI_FLAG_CPHA = $00000020; Device supports Clock Phase setting
SPI_FLAG_CSPOL = $00000040; Device supports Chip Select Polarity setting
SPI_FLAG_NO_CS = $00000080; Device supports Chip Select None (CS handled externally)
SPI_FLAG_DMA = $00000100; Device supports DMA transfers


SPI transfer flag SPI_TRANSFER_*
SPI_TRANSFER_NONE = $00000000;  
SPI_TRANSFER_DMA = $00000001; Use DMA for transfer (Write/Read) (Note: Buffers must be DMA compatible)
SPI_TRANSFER_PIO = $00000002; Use PIO (Polling) for transfer (Write/Read)
 
SPI_TRANSFER_DELAY = $00000004; Add a delay after each byte written (Write/Read) Note: Only available with PIO transfer unless provided directly by hardware


SPI logging SPI_LOG_*
SPI_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; SPI debugging messages
SPI_LOG_LEVEL_INFO = LOG_LEVEL_INFO; SPI informational messages, such as a device being attached or detached
SPI_LOG_LEVEL_WARN = LOG_LEVEL_WARN; SPI warning messages
SPI_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; SPI error messages
SPI_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No SPI messages


Type definitions



SPI properties

PSPIProperties = ^TSPIProperties;

TSPIProperties = record

Flags:LongWord; Device flags (eg SPI_FLAG_SLAVE)
MaxSize:LongWord; Maximum supported data transfer size
MinClock:LongWord; Minimum supported clock rate
MaxClock:LongWord; Maximum supported clock rate
SelectCount:LongWord; Number of chip selects supported
Mode:LongWord; Current mode (eg SPI_MODE_4WIRE)
ClockRate:LongWord; Current clock rate
ClockPhase:LongWord; Current clock phase (CPHA) (eg SPI_CLOCK_PHASE_LOW)
ClockPolarity:LongWord; Current clock polarity (CPOL) (eg SPI_CLOCK_POLARITY_LOW)
SelectPolarity:LongWord; Default chip select polarity (eg SPI_CS_POLARITY_LOW)
ByteDelay:LongWord; Delay between bytes written (Microseconds)

SPI chip select

PSPIChipSelect = ^TSPIChipSelect;

TSPIChipSelect = record

Pin:LongWord; The GPIO pin for this chip select (eg GPIO_PIN_46)(GPIO_PIN_UNKNOWN for internal)
Mode:LongWord; The mode for this chip select (eg SPI_MODE_0)
Divider:LongWord; The clock divider for this chip select (Used internally by drivers)
ClockRate:LongWord; The clock rate for this chip select
ClockPhase:LongWord; The clock phase (CPHA) for this chip select (eg SPI_CLOCK_PHASE_LOW)
ClockPolarity:LongWord; The clock polarity (CPOL) for this chip select (eg SPI_CLOCK_POLARITY_LOW)
SelectPolarity:LongWord; The chip select polarity for this chip select (eg SPI_CS_POLARITY_LOW)
ByteDelay:LongWord; Delay between bytes written for this chip select (Microseconds)

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

PSPIDevice = ^TSPIDevice;

TSPIDevice = record

Device Properties
Device:TDevice; The Device entry for this SPI
SPI Properties
SPIId:LongWord; Unique Id of this SPI in the SPI table
SPIState:LongWord; SPI state (eg SPI_STATE_ENABLED)
SPIMode:LongWord; SPI mode (eg SPI_MODE_4WIRE)
DeviceStart:TSPIDeviceStart; A Device specific DeviceStart method implementing the standard SPI device interface (Mandatory)
DeviceStop:TSPIDeviceStop; A Device specific DeviceStop method implementing the standard SPI device interface (Mandatory)
DeviceRead:TSPIDeviceRead; A Device specific DeviceRead method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceWrite:TSPIDeviceWrite; A Device specific DeviceWrite method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceWriteRead:TSPIDeviceWriteRead; A Device specific DeviceWriteRead method implementing the standard SPI device interface (Mandatory)
DeviceGetMode:TSPIDeviceGetMode; A Device specific DeviceGetMode method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceSetMode:TSPIDeviceSetMode; A Device specific DeviceSetMode method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceGetClockRate:TSPIDeviceGetClockRate; A Device specific DeviceGetClockRate method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceSetClockRate:TSPIDeviceSetClockRate; A Device specific DeviceSetClockRate method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceGetClockPhase:TSPIDeviceGetClockPhase; A Device specific DeviceGetClockPhase method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceSetClockPhase:TSPIDeviceSetClockPhase; A Device specific DeviceSetClockPhase method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceGetClockPolarity:TSPIDeviceGetClockPolarity; A Device specific DeviceGetClockPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceSetClockPolarity:TSPIDeviceSetClockPolarity; A Device specific DeviceSetClockPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceGetSelectPolarity:TSPIDeviceGetSelectPolarity; A Device specific DeviceGetSelectPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceSetSelectPolarity:TSPIDeviceSetSelectPolarity; A Device specific DeviceSetSelectPolarity method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceGetByteDelay:TSPIDeviceGetByteDelay; A Device specific DeviceGetByteDelay method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceSetByteDelay:TSPIDeviceSetByteDelay; A Device specific DeviceSetByteDelay method implementing the standard SPI device interface (Or nil if the default method is suitable)
DeviceGetProperties:TSPIDeviceGetProperties; A Device specific DeviceGetProperties method implementing the standard SPI device interface (Or nil if the default method is suitable)
Statistics Properties
TransferCount:LongWord;  
TransferErrors:LongWord;  
Driver Properties
Lock:TMutexHandle; Device lock
Wait:TSemaphoreHandle; Write/Read wait event
Divider:LongWord; Clock divider (Used internally by drivers)
ClockRate:LongWord; Clock rate (Hz)
ClockPhase:LongWord; Clock Phase (eg SPI_CLOCK_PHASE_LOW)
ClockPolarity:LongWord; Clock Polarity (eg SPI_CLOCK_POLARITY_LOW)
SelectPolarity:LongWord; Default Chip Select Polarity (eg SPI_CS_POLARITY_LOW)
Properties:TSPIProperties; Device properties
ChipSelects:array[0..SPI_CS_MAX] of TSPIChipSelect; Chip selects
Internal Properties
Prev:PSPIDevice; Previous entry in SPI table
Next:PSPIDevice; Next entry in SPI table


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

procedure SPIInit;
Description: Initialize the SPI unit and SPI device table
Note Called only during system startup


SPI functions

function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
Description: Start the specified SPI device ready for writing and reading
SPI The SPI device to start
Mode The device mode to set (eg SPI_MODE_4WIRE)
ClockRate The clock rate to set for the device
ClockPhase The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
ClockPolarity The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceStop(SPI:PSPIDevice):LongWord;
Description: Stop the specified SPI device and terminate writing and reading
SPI The SPI device to stop
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read data from the specified SPI device
SPI The SPI device to read from
ChipSelect The chip select for the slave to read from (eg SPI_CS_0)
Dest Pointer to a buffer to receive the data
Size The size of the buffer
Flags The flags for this transfer (eg SPI_TRANSFER_DMA)
Count The number of bytes read on return
Return 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.


function SPIDeviceWrite(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Write data to the specified SPI device
SPI The SPI device to write to
ChipSelect The chip select for the slave to write to (eg SPI_CS_0)
Source Pointer to a buffer of data to transmit
Size The size of the buffer
Flags The flags for this transfer (eg SPI_TRANSFER_DMA)
Count The number of bytes written on return
Return 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 byte written.


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
SPI 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)
Source Pointer to a buffer of data to transmit
Dest Pointer to a buffer to receive the data
Size The size of the buffer
Flags The flags for this transfer (eg SPI_TRANSFER_DMA)
Count The number of bytes written and read on return
Return 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.


function SPIDeviceGetMode(SPI:PSPIDevice):LongWord;
Description: Get the device mode of the specified SPI device
SPI The SPI device to get device mode from
Return The device mode or SPI_MODE_UNKNOWN on failure


function SPIDeviceSetMode(SPI:PSPIDevice; Mode:LongWord):LongWord;
Description: Set the device mode for the specified SPI device
SPI The SPI device to set device mode for
Mode The device mode to set (eg SPI_MODE_4WIRE)
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceGetClockRate(SPI:PSPIDevice; ChipSelect:Word):LongWord;
Description: Get the clock rate of the specified SPI device
SPI The SPI device to get clock rate from
ChipSelect The chip select number to get clock rate from (SPI_CS_NONE for default)
Return The clock rate in Hz or 0 on failure


function SPIDeviceSetClockRate(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;
Description: Set the clock rate for the specified SPI device
SPI The SPI device to set clock rate for
ChipSelect The chip select number to set clock rate for (SPI_CS_NONE for default)
ClockRate The clock rate to set in Hz
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceGetClockPhase(SPI:PSPIDevice):LongWord;
Description: Get the clock phase of the specified SPI device
SPI The SPI device to get clock phase from
Return The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure


function SPIDeviceSetClockPhase(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;
Description: Set the clock phase for the specified SPI device
SPI The SPI device to set clock phase for
ClockPhase The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceGetClockPolarity(SPI:PSPIDevice):LongWord;
Description: Get the clock polarity of the specified SPI device
SPI The SPI device to get clock polarity from
Return The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure


function SPIDeviceSetClockPolarity(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;
Description: Set the clock polarity for the specified SPI device
SPI The SPI device to set clock polarity for
ClockPolarity The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceGetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word):LongWord;
Description: Get the chip select polarity of the specified SPI device
SPI The SPI device to get chip select polarity from
ChipSelect 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


function SPIDeviceSetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;
Description: Set the chip select polarity for the specified SPI device
SPI The SPI device to set chip select polarity for
ChipSelect 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)
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceGetByteDelay(SPI:PSPIDevice):LongWord;
Description: Get the delay between bytes written for the specified SPI device
SPI The SPI device to get the byte delay from
Return The byte delay in microseconds, 0 if not set or on failure


function SPIDeviceSetByteDelay(SPI:PSPIDevice; Delay:LongWord):LongWord;
Description: Set the delay between bytes written for the specified SPI device
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


function SPIDeviceProperties(SPI:PSPIDevice; Properties:PSPIProperties):LongWord; inline;
Description: Get the properties for the specified SPI device
SPI The SPI device to get properties from
Properties Pointer to a TSPIProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure
Note Replaced by SPIDeviceGetProperties for consistency


function SPIDeviceGetProperties(SPI:PSPIDevice;Properties:PSPIProperties):LongWord;
Description: Get the properties for the specified SPI device
SPI The SPI device to get properties from
Properties Pointer to a TSPIProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceCreate:PSPIDevice;
Description: Create a new SPI entry
Return Pointer to new SPI entry or nil if SPI could not be created


function SPIDeviceCreateEx(Size:LongWord):PSPIDevice;
Description: Create a new SPI entry
Size 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


function SPIDeviceDestroy(SPI:PSPIDevice):LongWord;
Description: Destroy an existing SPI entry
SPI The SPI device to destroy
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceRegister(SPI:PSPIDevice):LongWord;
Description: Register a new SPI in the SPI table
SPI The SPI device to register
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;
Description: Deregister an SPI from the SPI table
SPI The SPI device to deregister
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceFind(SPIId:LongWord):PSPIDevice;
Description: ERROR_SUCCESS if completed or another error code on failure
SPIId The ID number of the SPI device to find
Return Pointer to SPI device entry or nil if not found


function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;
Description: Find an SPI device by name in the device table
Name The name of the SPI device to find (eg SPI0)
Return Pointer to SPI device entry or nil if not found


function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;
Description: Find an SPI device by description in the device table
Description The description of the SPI to find (eg BCM2837 SPI0 Master)
Return Pointer to SPI device entry or nil if not found


function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;
Description: Enumerate all SPI devices in the SPI table
Callback 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


function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for SPI device changes
Device 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)


RTL SPI functions

function SysSPIAvailable:Boolean; 
Description: Check if an SPI device is available
Note None documented


function SysSPIStart(Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
Description: Start the default SPI device ready for writing and reading
Mode The device mode to set (eg SPI_MODE_4WIRE)
ClockRate The clock rate to set for the device
ClockPhase The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
ClockPolarity The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SysSPIStop:LongWord;
Description: Stop the default SPI device and terminate writing and reading
Return ERROR_SUCCESS if completed or another error code on failure


function SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Read data from the default SPI device
ChipSet The chip select for the slave to read from (eg SPI_CS_0)
Dest Pointer to a buffer to receive the data
Size The size of the buffer
Count The number of bytes read on return
Return 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.


function SysSPIWrite(ChipSelect:Word; Source:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Write data to the default SPI device
ChipSet The chip select for the slave to write to (eg SPI_CS_0)
Source Pointer to a buffer of data to transmit
Size The size of the buffer
Count The number of bytes written on return
Return 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 byte written.


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
ChipSet 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
Dest Pointer to a buffer to receive the data
Size The size of the buffer
Count The number of bytes written and read on return
Return 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.


function SysSPIGetMode:LongWord;
Description: Get the device mode of the default SPI device
Return The device mode or SPI_MODE_UNKNOWN on failure


function SysSPISetMode(Mode:LongWord):LongWord;
Description: Set the device mode for the default SPI device
Mode The device mode to set (eg SPI_MODE_4WIRE)
Return ERROR_SUCCESS if completed or another error code on failure


function SysSPIGetClockRate(ChipSelect:Word):LongWord;
Description: Get the clock rate of the default SPI device
ChipSelect The chip select number to get clock rate from (SPI_CS_NONE for default)
Return The clock rate in Hz or 0 on failure


function SysSPISetClockRate(ChipSelect:Word; ClockRate:LongWord):LongWord;
Description: Set the clock rate for the default SPI device
ChipSelect The chip select number to set clock rate for (SPI_CS_NONE for default)
ClockRate The clock rate to set in Hz
Return ERROR_SUCCESS if completed or another error code on failure


function SysSPIGetClockPhase:LongWord;
Description: Get the clock phase of the default SPI device
Return The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure


function SysSPISetClockPhase(ClockPhase:LongWord):LongWord;
Description: Set the clock phase for the default SPI device
ClockPhase The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SysSPIGetClockPolarity:LongWord;
Description: Get the clock polarity of the default SPI device
Return The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure


function SysSPISetClockPolarity(ClockPolarity:LongWord):LongWord;
Description: Set the clock polarity for the default SPI device
ClockPolarity The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SysSPIGetSelectPolarity(ChipSelect:Word):LongWord;
Description: Get the chip select polarity of the default SPI device
ChipSet 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


function SysSPISetSelectPolarity(ChipSelect:Word; SelectPolarity:LongWord):LongWord;
Description: Set the chip select polarity for the default SPI device
ChipSet 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)
Return ERROR_SUCCESS if completed or another error code on failure


SPI helper functions

function SPIGetCount:LongWord;
Description: Get the current SPI count
Note None documented


function SPIDeviceGetDefault:PSPIDevice;
Description: Get the current default SPI device
Note None documented


function SPIDeviceSetDefault(SPI:PSPIDevice):LongWord;
Description: Set the current default SPI device
Note None documented


function SPIDeviceCheck(SPI:PSPIDevice):PSPIDevice;
Description: Check if the supplied SPI is in the SPI table
Note None documented


function SPITypeToString(SPIType:LongWord):String;
Description: Convert an SPI type value to a string
Note None documented


function SPIStateToString(SPIState:LongWord):String;
Description: Convert an SPI state value to a string
Note None documented


procedure SPILog(Level:LongWord; SPI:PSPIDevice; const AText:String);
Description: To be documented
Note None documented


procedure SPILogInfo(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure SPILogWarn(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure SPILogError(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure SPILogDebug(SPI:PSPIDevice; const AText:String); inline;
Description: To be documented
Note None documented


function SPIChipSelectToString(ChipSelect:Word):String;
Description: To be documented
Note None documented


function SPIModeToString(Mode:LongWord):String;
Description: To be documented
Note None documented


function SPIClockPhaseToString(Phase:LongWord):String;
Description: To be documented
Note None documented


function SPIClockPolarityToString(Polarity:LongWord):String;
Description: To be documented
Note None documented


function SPISelectPolarityToString(Polarity:LongWord):String;
Description: To be documented
Note None documented


Return to Unit Reference