Difference between revisions of "Unit SPI"
Line 195: | Line 195: | ||
! '''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 ?rom | ||
+ | |- | ||
+ | ! '''ChipSelect''' | ||
+ | | The chip select number to get polarity ?rom (SPI_CS_NONE for default) | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure | ||
|- | |- | ||
|} | |} |
Revision as of 01:31, 7 October 2016
Return to Unit Reference
Description
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.
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
To be documented
Type definitions
To be documented
Public variables
To be documented
Function declarations
Initialization functions
procedure SPIInit;
Note | Called only during system startup |
---|
SPI functions
function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
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;
SPI | The SPI device to stop |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SPIDeviceWrite(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
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 by written |
function SPIDeviceSetMode(SPI:PSPIDevice; Mode:LongWord):LongWord;
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 SPIDeviceSetClockRate(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;
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 SPIDeviceSetClockPhase(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;
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 SPIDeviceSetClockPolarity(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;
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;
SPI | The SPI device to get chip select polarity ?rom |
---|---|
ChipSelect | The chip select number to get polarity ?rom (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;
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 SPIDeviceProperties(SPI:PSPIDevice; Properties:PSPIProperties):LongWord;
SPI | The SPI device to get properties ?rom |
---|---|
Properties | Pointer to a TSPIProperties structure to fill in |
Return | ERROR_SUCCESS if completed or another error code on failure |
function SPIDeviceCreate:PSPIDevice;
Return | Pointer to new SPI entry or nil if SPI could not be created |
---|
function SPIDeviceCreateEx(Size:LongWord):PSPIDevice;
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;
Note | None documented |
---|
function SPIDeviceRegister(SPI:PSPIDevice):LongWord;
Note | None documented |
---|
function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;
Note | None documented |
---|
function SPIDeviceFind(SPIId:LongWord):PSPIDevice;
Note | None documented |
---|
function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;
Note | None documented |
---|
function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;
Note | None documented |
---|
function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;
Note | None documented |
---|
function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Note | None documented |
---|
RTL SPI functions
function SysSPIAvailable:Boolean;
Note | None documented |
---|
function SysSPIStart(Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
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;
Return | ERROR_SUCCESS if completed or another error code on failure |
---|
function SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
ChipSet | The chip select for the slave to read ?rom (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;
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 by written |
function SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
ChipSet | The chip select for the slave to write to and read ?rom (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;
Return | The device mode or SPI_MODE_UNKNOWN on failure |
---|
function SysSPISetMode(Mode:LongWord):LongWord;
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;
ChipSelect | The chip select number to get clock rate ?rom (SPI_CS_NONE for default) |
---|---|
Return | The clock rate in Hz or 0 on failure |
function SysSPISetClockRate(ChipSelect:Word; ClockRate:LongWord):LongWord;
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;
Return | The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure |
---|
function SysSPISetClockPhase(ClockPhase:LongWord):LongWord;
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;
Return | The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure |
---|
function SysSPISetClockPolarity(ClockPolarity:LongWord):LongWord;
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;
ChipSet | The chip select number to get polarity ?rom (SPI_CS_NONE for default) |
---|---|
Return | The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure |
</div></div>
function SysSPISetSelectPolarity(ChipSelect:Word; SelectPolarity:LongWord):LongWord;
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; inline;
Note | None documented |
---|
function SPIDeviceGetDefault:PSPIDevice; inline;
Note | None documented |
---|
function SPIDeviceSetDefault(SPI:PSPIDevice):LongWord;
Note | None documented |
---|
function SPIDeviceCheck(SPI:PSPIDevice):PSPIDevice;
Note | None documented |
---|
procedure SPILog(Level:LongWord; SPI:PSPIDevice; const AText:String);
Note | None documented |
---|
procedure SPILogInfo(SPI:PSPIDevice; const AText:String); inline;
Note | None documented |
---|
procedure SPILogError(SPI:PSPIDevice; const AText:String); inline;
Note | None documented |
---|
procedure SPILogDebug(SPI:PSPIDevice; const AText:String); inline;
Note | None documented |
---|
function SPIChipSelectToString(ChipSelect:Word):String;
Note | None documented |
---|
function SPIModeToString(Mode:LongWord):String;
Note | None documented |
---|
function SPIClockPhaseToString(Phase:LongWord):String;
Note | None documented |
---|
function SPIClockPolarityToString(Polarity:LongWord):String;
Note | None documented |
---|
function SPISelectPolarityToString(Polarity:LongWord):String;
Note | None documented |
---|
Return to Unit Reference