Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
spi.h File Reference

Go to the source code of this file.

Data Structures

struct  _SPI_PROPERTIES
struct  _SPI_CHIP_SELECT
struct  _SPI_DEVICE

Macros

#define SPI_NAME_PREFIX   "SPI"
 Name prefix for SPI Devices.
#define SPISLAVE_NAME_PREFIX   "SPISlave"
 Name prefix for SPI Slave Devices.
#define SPI_TYPE_NONE   0
#define SPI_TYPE_MASTER   1
#define SPI_TYPE_SLAVE   2
#define SPI_TYPE_MAX   2
#define SPI_STATE_DISABLED   0
#define SPI_STATE_ENABLED   1
#define SPI_STATE_MAX   1
#define SPI_FLAG_NONE   0x00000000
#define SPI_FLAG_SLAVE   0x00000001
 Device is a slave not a master.
#define SPI_FLAG_4WIRE   0x00000002
 Device supports 4 wire operation (CS/MISO/MOSI/SCLK).
#define SPI_FLAG_3WIRE   0x00000004
 Device supports 3 wire operation (CS/MIMO/SCLK).
#define SPI_FLAG_LOSSI   0x00000008
 Device supports LoSSI (Low Speed Serial) mode (CS/SCL/SDA).
#define SPI_FLAG_CPOL   0x00000010
 Device supports Clock Polarity setting.
#define SPI_FLAG_CPHA   0x00000020
 Device supports Clock Phase setting.
#define SPI_FLAG_CSPOL   0x00000040
 Device supports Chip Select Polarity setting.
#define SPI_FLAG_NO_CS   0x00000080
 Device supports Chip Select None (CS handled externally).
#define SPI_FLAG_DMA   0x00000100
 Device supports DMA transfers.
#define SPI_TRANSFER_NONE   0x00000000
#define SPI_TRANSFER_DMA   0x00000001
 Use DMA for transfer (Write/Read) (If supported) (Note: Buffers must be DMA compatible).
#define SPI_TRANSFER_PIO   0x00000002
 Use PIO (Polling) for transfer (Write/Read).
#define SPI_TRANSFER_DELAY   0x00000004
 Add a delay after each byte written (Write/Read) (Note: Only available with PIO transfer unless provided directly by hardware).

Typedefs

typedef struct _SPI_PROPERTIES SPI_PROPERTIES
typedef struct _SPI_CHIP_SELECT SPI_CHIP_SELECT
typedef struct _SPI_DEVICE SPI_DEVICE
typedef uint32_t STDCALL(* spi_enumerate_cb) (SPI_DEVICE *spi, void *data)
typedef uint32_t STDCALL(* spi_notification_cb) (DEVICE *device, void *data, uint32_t notification)
typedef uint32_t STDCALL(* spi_device_start_proc) (SPI_DEVICE *spi, uint32_t mode, uint32_t clockrate, uint32_t clockphase, uint32_t clockpolarity)
typedef uint32_t STDCALL(* spi_device_stop_proc) (SPI_DEVICE *spi)
typedef uint32_t STDCALL(* spi_device_read_proc) (SPI_DEVICE *spi, uint16_t chipselect, void *dest, uint32_t size, uint32_t flags, uint32_t *count)
typedef uint32_t STDCALL(* spi_device_write_proc) (SPI_DEVICE *spi, uint16_t chipselect, void *source, uint32_t size, uint32_t flags, uint32_t *count)
typedef uint32_t STDCALL(* spi_device_write_read_proc) (SPI_DEVICE *spi, uint16_t chipselect, void *source, void *dest, uint32_t size, uint32_t flags, uint32_t *count)
typedef uint32_t STDCALL(* spi_device_get_mode_proc) (SPI_DEVICE *spi)
typedef uint32_t STDCALL(* spi_device_set_mode_proc) (SPI_DEVICE *spi, uint32_t mode)
typedef uint32_t STDCALL(* spi_device_get_clock_rate_proc) (SPI_DEVICE *spi, uint16_t chipselect)
typedef uint32_t STDCALL(* spi_device_set_clock_rate_proc) (SPI_DEVICE *spi, uint16_t chipselect, uint32_t clockrate)
typedef uint32_t STDCALL(* spi_device_get_clock_phase_proc) (SPI_DEVICE *spi)
typedef uint32_t STDCALL(* spi_device_set_clock_phase_proc) (SPI_DEVICE *spi, uint32_t clockphase)
typedef uint32_t STDCALL(* spi_device_get_clock_polarity_proc) (SPI_DEVICE *spi)
typedef uint32_t STDCALL(* spi_device_set_clock_polarity_proc) (SPI_DEVICE *spi, uint32_t clockpolarity)
typedef uint32_t STDCALL(* spi_device_get_select_polarity_proc) (SPI_DEVICE *spi, uint16_t chipselect)
typedef uint32_t STDCALL(* spi_device_set_select_polarity_proc) (SPI_DEVICE *spi, uint16_t chipselect, uint32_t selectpolarity)
typedef uint32_t STDCALL(* spi_device_get_byte_delay_proc) (SPI_DEVICE *spi)
typedef uint32_t STDCALL(* spi_device_set_byte_delay_proc) (SPI_DEVICE *spi, uint32_t delay)
typedef uint32_t STDCALL(* spi_device_get_properties_proc) (SPI_DEVICE *spi, SPI_PROPERTIES *properties)

Functions

uint32_t STDCALL spi_device_start (SPI_DEVICE *spi, uint32_t mode, uint32_t clockrate, uint32_t clockphase, uint32_t clockpolarity)
 Start the specified SPI device ready for writing and reading.
uint32_t STDCALL spi_device_stop (SPI_DEVICE *spi)
 Stop the specified SPI device and terminate writing and reading.
uint32_t STDCALL spi_device_read (SPI_DEVICE *spi, uint16_t chipselect, void *dest, uint32_t size, uint32_t flags, uint32_t *count)
 Read data from the specified SPI device Because SPI writes and then reads for each byte, dummy data will be written for each byte to be read.
uint32_t STDCALL spi_device_write (SPI_DEVICE *spi, uint16_t chipselect, void *source, uint32_t size, uint32_t flags, uint32_t *count)
 Write data to the specified SPI device Because SPI writes and then reads for each byte, received data will be discarded for each byte written.
uint32_t STDCALL spi_device_write_read (SPI_DEVICE *spi, uint16_t chipselect, void *source, void *dest, uint32_t size, uint32_t flags, uint32_t *count)
 Write data to and Read data from the specified SPI device in one operation Because SPI writes and then reads for each byte, both the source and dest buffers must be the same size.
uint32_t STDCALL spi_device_get_mode (SPI_DEVICE *spi)
 Get the device mode of the specified SPI device.
uint32_t STDCALL spi_device_set_mode (SPI_DEVICE *spi, uint32_t mode)
 Set the device mode for the specified SPI device.
uint32_t STDCALL spi_device_get_clock_rate (SPI_DEVICE *spi, uint16_t chipselect)
 Get the clock rate of the specified SPI device.
uint32_t STDCALL spi_device_set_clock_rate (SPI_DEVICE *spi, uint16_t chipselect, uint32_t clockrate)
 Set the clock rate for the specified SPI device.
uint32_t STDCALL spi_device_get_clock_phase (SPI_DEVICE *spi)
 Get the clock phase of the specified SPI device.
uint32_t STDCALL spi_device_set_clock_phase (SPI_DEVICE *spi, uint32_t clockphase)
 Set the clock phase for the specified SPI device.
uint32_t STDCALL spi_device_get_clock_polarity (SPI_DEVICE *spi)
 Get the clock polarity of the specified SPI device.
uint32_t STDCALL spi_device_set_clock_polarity (SPI_DEVICE *spi, uint32_t clockpolarity)
 Set the clock polarity for the specified SPI device.
uint32_t STDCALL spi_device_get_select_polarity (SPI_DEVICE *spi, uint16_t chipselect)
 Get the chip select polarity of the specified SPI device.
uint32_t STDCALL spi_device_set_select_polarity (SPI_DEVICE *spi, uint16_t chipselect, uint32_t selectpolarity)
 Set the chip select polarity for the specified SPI device.
uint32_t STDCALL spi_device_get_byte_delay (SPI_DEVICE *spi)
 Get the delay between bytes written for the specified SPI device.
uint32_t STDCALL spi_device_set_byte_delay (SPI_DEVICE *spi, uint32_t delay)
 Set the delay between bytes written for the specified SPI device.
uint32_t STDCALL spi_device_properties (SPI_DEVICE *spi, SPI_PROPERTIES *properties)
 Get the properties for the specified SPI device.
uint32_t STDCALL spi_device_get_properties (SPI_DEVICE *spi, SPI_PROPERTIES *properties)
 Get the properties for the specified SPI device.
SPI_DEVICE *STDCALL spi_device_create (void)
 Create a new SPI entry.
SPI_DEVICE *STDCALL spi_device_create_ex (uint32_t size)
 Create a new SPI entry.
uint32_t STDCALL spi_device_destroy (SPI_DEVICE *spi)
 Destroy an existing SPI entry.
uint32_t STDCALL spi_device_register (SPI_DEVICE *spi)
 Register a new SPI in the SPI table.
uint32_t STDCALL spi_device_deregister (SPI_DEVICE *spi)
 Deregister an SPI from the SPI table.
SPI_DEVICE *STDCALL spi_device_find (uint32_t spiid)
 Find an SPI device by ID in the SPI table.
SPI_DEVICE *STDCALL spi_device_find_by_name (const char *name)
 Find an SPI device by name in the device table.
SPI_DEVICE *STDCALL spi_device_find_by_description (const char *description)
 Find an SPI device by description in the device table.
uint32_t STDCALL spi_device_enumerate (spi_enumerate_cb callback, void *data)
 Enumerate all SPI devices in the SPI table.
uint32_t STDCALL spi_device_notification (SPI_DEVICE *spi, spi_notification_cb callback, void *data, uint32_t notification, uint32_t flags)
 Register a notification for SPI device changes.
uint32_t STDCALL spi_get_count (void)
 Get the current SPI count.
SPI_DEVICE *STDCALL spi_device_get_default (void)
 Get the current default SPI device.
uint32_t STDCALL spi_device_set_default (SPI_DEVICE *spi)
 Set the current default SPI device.
SPI_DEVICE *STDCALL spi_device_check (SPI_DEVICE *spi)
 Check if the supplied SPI is in the SPI table.
uint32_t STDCALL spi_type_to_string (uint32_t spitype, char *string, uint32_t len)
 Convert an SPI type value to a string.
uint32_t STDCALL spi_state_to_string (uint32_t spistate, char *string, uint32_t len)
 Convert an SPI state value to a string.
uint32_t STDCALL spi_chip_select_to_string (uint16_t chipselect, char *string, uint32_t len)
uint32_t STDCALL spi_mode_to_string (uint32_t mode, char *string, uint32_t len)
uint32_t STDCALL spi_clock_phase_to_string (uint32_t phase, char *string, uint32_t len)
uint32_t STDCALL spi_clock_polarity_to_string (uint32_t polarity, char *string, uint32_t len)
uint32_t STDCALL spi_select_polarity_to_string (uint32_t polarity, char *string, uint32_t len)

Macro Definition Documentation

◆ SPI_NAME_PREFIX

#define SPI_NAME_PREFIX   "SPI"

Name prefix for SPI Devices.

SPI specific constants

◆ SPISLAVE_NAME_PREFIX

#define SPISLAVE_NAME_PREFIX   "SPISlave"

Name prefix for SPI Slave Devices.

◆ SPI_TYPE_NONE

#define SPI_TYPE_NONE   0

SPI Device Types

◆ SPI_TYPE_MASTER

#define SPI_TYPE_MASTER   1

◆ SPI_TYPE_SLAVE

#define SPI_TYPE_SLAVE   2

◆ SPI_TYPE_MAX

#define SPI_TYPE_MAX   2

◆ SPI_STATE_DISABLED

#define SPI_STATE_DISABLED   0

SPI Device States

◆ SPI_STATE_ENABLED

#define SPI_STATE_ENABLED   1

◆ SPI_STATE_MAX

#define SPI_STATE_MAX   1

◆ SPI_FLAG_NONE

#define SPI_FLAG_NONE   0x00000000

SPI Device Flags

◆ SPI_FLAG_SLAVE

#define SPI_FLAG_SLAVE   0x00000001

Device is a slave not a master.

◆ SPI_FLAG_4WIRE

#define SPI_FLAG_4WIRE   0x00000002

Device supports 4 wire operation (CS/MISO/MOSI/SCLK).

◆ SPI_FLAG_3WIRE

#define SPI_FLAG_3WIRE   0x00000004

Device supports 3 wire operation (CS/MIMO/SCLK).

◆ SPI_FLAG_LOSSI

#define SPI_FLAG_LOSSI   0x00000008

Device supports LoSSI (Low Speed Serial) mode (CS/SCL/SDA).

◆ SPI_FLAG_CPOL

#define SPI_FLAG_CPOL   0x00000010

Device supports Clock Polarity setting.

◆ SPI_FLAG_CPHA

#define SPI_FLAG_CPHA   0x00000020

Device supports Clock Phase setting.

◆ SPI_FLAG_CSPOL

#define SPI_FLAG_CSPOL   0x00000040

Device supports Chip Select Polarity setting.

◆ SPI_FLAG_NO_CS

#define SPI_FLAG_NO_CS   0x00000080

Device supports Chip Select None (CS handled externally).

◆ SPI_FLAG_DMA

#define SPI_FLAG_DMA   0x00000100

Device supports DMA transfers.

◆ SPI_TRANSFER_NONE

#define SPI_TRANSFER_NONE   0x00000000

SPI Transfer Flags

◆ SPI_TRANSFER_DMA

#define SPI_TRANSFER_DMA   0x00000001

Use DMA for transfer (Write/Read) (If supported) (Note: Buffers must be DMA compatible).

◆ SPI_TRANSFER_PIO

#define SPI_TRANSFER_PIO   0x00000002

Use PIO (Polling) for transfer (Write/Read).

◆ SPI_TRANSFER_DELAY

#define SPI_TRANSFER_DELAY   0x00000004

Add a delay after each byte written (Write/Read) (Note: Only available with PIO transfer unless provided directly by hardware).

Typedef Documentation

◆ SPI_PROPERTIES

SPI specific types SPI Properties

◆ SPI_CHIP_SELECT

SPI Chip Select

◆ SPI_DEVICE

typedef struct _SPI_DEVICE SPI_DEVICE

SPI Device

◆ spi_enumerate_cb

typedef uint32_t STDCALL(* spi_enumerate_cb) (SPI_DEVICE *spi, void *data)

SPI Enumeration Callback

◆ spi_notification_cb

typedef uint32_t STDCALL(* spi_notification_cb) (DEVICE *device, void *data, uint32_t notification)

SPI Notification Callback

◆ spi_device_start_proc

typedef uint32_t STDCALL(* spi_device_start_proc) (SPI_DEVICE *spi, uint32_t mode, uint32_t clockrate, uint32_t clockphase, uint32_t clockpolarity)

SPI Device Methods

◆ spi_device_stop_proc

typedef uint32_t STDCALL(* spi_device_stop_proc) (SPI_DEVICE *spi)

◆ spi_device_read_proc

typedef uint32_t STDCALL(* spi_device_read_proc) (SPI_DEVICE *spi, uint16_t chipselect, void *dest, uint32_t size, uint32_t flags, uint32_t *count)

◆ spi_device_write_proc

typedef uint32_t STDCALL(* spi_device_write_proc) (SPI_DEVICE *spi, uint16_t chipselect, void *source, uint32_t size, uint32_t flags, uint32_t *count)

◆ spi_device_write_read_proc

typedef uint32_t STDCALL(* spi_device_write_read_proc) (SPI_DEVICE *spi, uint16_t chipselect, void *source, void *dest, uint32_t size, uint32_t flags, uint32_t *count)

◆ spi_device_get_mode_proc

typedef uint32_t STDCALL(* spi_device_get_mode_proc) (SPI_DEVICE *spi)

◆ spi_device_set_mode_proc

typedef uint32_t STDCALL(* spi_device_set_mode_proc) (SPI_DEVICE *spi, uint32_t mode)

◆ spi_device_get_clock_rate_proc

typedef uint32_t STDCALL(* spi_device_get_clock_rate_proc) (SPI_DEVICE *spi, uint16_t chipselect)

◆ spi_device_set_clock_rate_proc

typedef uint32_t STDCALL(* spi_device_set_clock_rate_proc) (SPI_DEVICE *spi, uint16_t chipselect, uint32_t clockrate)

◆ spi_device_get_clock_phase_proc

typedef uint32_t STDCALL(* spi_device_get_clock_phase_proc) (SPI_DEVICE *spi)

◆ spi_device_set_clock_phase_proc

typedef uint32_t STDCALL(* spi_device_set_clock_phase_proc) (SPI_DEVICE *spi, uint32_t clockphase)

◆ spi_device_get_clock_polarity_proc

typedef uint32_t STDCALL(* spi_device_get_clock_polarity_proc) (SPI_DEVICE *spi)

◆ spi_device_set_clock_polarity_proc

typedef uint32_t STDCALL(* spi_device_set_clock_polarity_proc) (SPI_DEVICE *spi, uint32_t clockpolarity)

◆ spi_device_get_select_polarity_proc

typedef uint32_t STDCALL(* spi_device_get_select_polarity_proc) (SPI_DEVICE *spi, uint16_t chipselect)

◆ spi_device_set_select_polarity_proc

typedef uint32_t STDCALL(* spi_device_set_select_polarity_proc) (SPI_DEVICE *spi, uint16_t chipselect, uint32_t selectpolarity)

◆ spi_device_get_byte_delay_proc

typedef uint32_t STDCALL(* spi_device_get_byte_delay_proc) (SPI_DEVICE *spi)

◆ spi_device_set_byte_delay_proc

typedef uint32_t STDCALL(* spi_device_set_byte_delay_proc) (SPI_DEVICE *spi, uint32_t delay)

◆ spi_device_get_properties_proc

typedef uint32_t STDCALL(* spi_device_get_properties_proc) (SPI_DEVICE *spi, SPI_PROPERTIES *properties)

Function Documentation

◆ spi_device_start()

uint32_t STDCALL spi_device_start ( SPI_DEVICE * spi,
uint32_t mode,
uint32_t clockrate,
uint32_t clockphase,
uint32_t clockpolarity )

Start the specified SPI device ready for writing and reading.

SPI Functions

Parameters
SPIThe SPI device to start
ModeThe device mode to set (eg SPI_MODE_4WIRE)
ClockRateThe clock rate to set for the device
ClockPhaseThe clock phase to set (eg SPI_CLOCK_PHASE_LOW)
ClockPolarityThe clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_stop()

uint32_t STDCALL spi_device_stop ( SPI_DEVICE * spi)

Stop the specified SPI device and terminate writing and reading.

Parameters
SPIThe SPI device to stop
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_read()

uint32_t STDCALL spi_device_read ( SPI_DEVICE * spi,
uint16_t chipselect,
void * dest,
uint32_t size,
uint32_t flags,
uint32_t * count )

Read data from the specified SPI device Because SPI writes and then reads for each byte, dummy data will be written for each byte to be read.

Parameters
SPIThe SPI device to read from
ChipSelectThe chip select for the slave to read from (eg SPI_CS_0)
DestPointer to a buffer to receive the data
SizeThe size of the buffer
FlagsThe flags for this transfer (eg SPI_TRANSFER_DMA)
CountThe number of bytes read on return
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_write()

uint32_t STDCALL spi_device_write ( SPI_DEVICE * spi,
uint16_t chipselect,
void * source,
uint32_t size,
uint32_t flags,
uint32_t * count )

Write data to the specified SPI device Because SPI writes and then reads for each byte, received data will be discarded for each byte written.

Parameters
SPIThe SPI device to write to
ChipSelectThe chip select for the slave to write to (eg SPI_CS_0)
SourcePointer to a buffer of data to transmit
SizeThe size of the buffer
FlagsThe flags for this transfer (eg SPI_TRANSFER_DMA)
CountThe number of bytes written on return
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_write_read()

uint32_t STDCALL spi_device_write_read ( SPI_DEVICE * spi,
uint16_t chipselect,
void * source,
void * dest,
uint32_t size,
uint32_t flags,
uint32_t * count )

Write data to and Read data from the specified SPI device in one operation Because SPI writes and then reads for each byte, both the source and dest buffers must be the same size.

Parameters
SPIThe SPI device to write to and read from
ChipSelectThe chip select for the slave to write to and read from (eg SPI_CS_0)
SourcePointer to a buffer of data to transmit
DestPointer to a buffer to receive the data
SizeThe size of the buffer
FlagsThe flags for this transfer (eg SPI_TRANSFER_DMA)
CountThe number of bytes written and read on return
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_get_mode()

uint32_t STDCALL spi_device_get_mode ( SPI_DEVICE * spi)

Get the device mode of the specified SPI device.

Parameters
SPIThe SPI device to get device mode from
Returns
The device mode or SPI_MODE_UNKNOWN on failure

◆ spi_device_set_mode()

uint32_t STDCALL spi_device_set_mode ( SPI_DEVICE * spi,
uint32_t mode )

Set the device mode for the specified SPI device.

Parameters
SPIThe SPI device to set device mode for
ModeThe device mode to set (eg SPI_MODE_4WIRE)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_get_clock_rate()

uint32_t STDCALL spi_device_get_clock_rate ( SPI_DEVICE * spi,
uint16_t chipselect )

Get the clock rate of the specified SPI device.

Parameters
SPIThe SPI device to get clock rate from
ChipSelectThe chip select number to get clock rate from (SPI_CS_NONE for default)
Returns
The clock rate in Hz or 0 on failure

◆ spi_device_set_clock_rate()

uint32_t STDCALL spi_device_set_clock_rate ( SPI_DEVICE * spi,
uint16_t chipselect,
uint32_t clockrate )

Set the clock rate for the specified SPI device.

Parameters
SPIThe SPI device to set clock rate for
ChipSelectThe chip select number to set clock rate for (SPI_CS_NONE for default)
ClockRateThe clock rate to set in Hz
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_get_clock_phase()

uint32_t STDCALL spi_device_get_clock_phase ( SPI_DEVICE * spi)

Get the clock phase of the specified SPI device.

Parameters
SPIThe SPI device to get clock phase from
Returns
The clock phase or SPI_CLOCK_PHASE_UNKNOWN on failure

◆ spi_device_set_clock_phase()

uint32_t STDCALL spi_device_set_clock_phase ( SPI_DEVICE * spi,
uint32_t clockphase )

Set the clock phase for the specified SPI device.

Parameters
SPIThe SPI device to set clock phase for
ClockPhaseThe clock phase to set (eg SPI_CLOCK_PHASE_LOW)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_get_clock_polarity()

uint32_t STDCALL spi_device_get_clock_polarity ( SPI_DEVICE * spi)

Get the clock polarity of the specified SPI device.

Parameters
SPIThe SPI device to get clock polarity from
Returns
The clock polarity or SPI_CLOCK_POLARITY_UNKNOWN on failure

◆ spi_device_set_clock_polarity()

uint32_t STDCALL spi_device_set_clock_polarity ( SPI_DEVICE * spi,
uint32_t clockpolarity )

Set the clock polarity for the specified SPI device.

Parameters
SPIThe SPI device to set clock polarity for
ClockPolarityThe clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_get_select_polarity()

uint32_t STDCALL spi_device_get_select_polarity ( SPI_DEVICE * spi,
uint16_t chipselect )

Get the chip select polarity of the specified SPI device.

Parameters
SPIThe SPI device to get chip select polarity from
ChipSelectThe chip select number to get polarity from (SPI_CS_NONE for default)
Returns
The chip select polarity or SPI_CS_POLARITY_UNKNOWN on failure

◆ spi_device_set_select_polarity()

uint32_t STDCALL spi_device_set_select_polarity ( SPI_DEVICE * spi,
uint16_t chipselect,
uint32_t selectpolarity )

Set the chip select polarity for the specified SPI device.

Parameters
SPIThe SPI device to set chip select polarity for
ChipSelectThe chip select number to set polarity for (SPI_CS_NONE for default)
SelectPolarityThe chip select polarity to set (eg SPI_CS_POLARITY_LOW)
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_get_byte_delay()

uint32_t STDCALL spi_device_get_byte_delay ( SPI_DEVICE * spi)

Get the delay between bytes written for the specified SPI device.

Parameters
SPIThe SPI device to get the byte delay from
Returns
The byte delay in microseconds, 0 if not set or on failure

◆ spi_device_set_byte_delay()

uint32_t STDCALL spi_device_set_byte_delay ( SPI_DEVICE * spi,
uint32_t delay )

Set the delay between bytes written for the specified SPI device.

Parameters
SPIThe SPI device to set byte delay for
DelayThe byte delay to set in microseconds
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_properties()

uint32_t STDCALL spi_device_properties ( SPI_DEVICE * spi,
SPI_PROPERTIES * properties )

Get the properties for the specified SPI device.

Parameters
SPIThe SPI device to get properties from
PropertiesPointer to a TSPIProperties structure to fill in
Returns
ERROR_SUCCESS if completed or another error code on failure
Note
Replaced by SPIDeviceGetProperties for consistency

◆ spi_device_get_properties()

uint32_t STDCALL spi_device_get_properties ( SPI_DEVICE * spi,
SPI_PROPERTIES * properties )

Get the properties for the specified SPI device.

Parameters
SPIThe SPI device to get properties from
PropertiesPointer to a TSPIProperties structure to fill in
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_create()

SPI_DEVICE *STDCALL spi_device_create ( void )

Create a new SPI entry.

Returns
Pointer to new SPI entry or nil if SPI could not be created

◆ spi_device_create_ex()

SPI_DEVICE *STDCALL spi_device_create_ex ( uint32_t size)

Create a new SPI entry.

Parameters
SizeSize in bytes to allocate for new SPI (Including the SPI entry)
Returns
Pointer to new SPI entry or nil if SPI could not be created

◆ spi_device_destroy()

uint32_t STDCALL spi_device_destroy ( SPI_DEVICE * spi)

Destroy an existing SPI entry.

Parameters
SPIThe SPI device to destroy
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_register()

uint32_t STDCALL spi_device_register ( SPI_DEVICE * spi)

Register a new SPI in the SPI table.

Parameters
SPIThe SPI device to register
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_deregister()

uint32_t STDCALL spi_device_deregister ( SPI_DEVICE * spi)

Deregister an SPI from the SPI table.

Parameters
SPIThe SPI device to deregister
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_find()

SPI_DEVICE *STDCALL spi_device_find ( uint32_t spiid)

Find an SPI device by ID in the SPI table.

Parameters
SPIIdThe ID number of the SPI device to find
Returns
Pointer to SPI device entry or nil if not found

◆ spi_device_find_by_name()

SPI_DEVICE *STDCALL spi_device_find_by_name ( const char * name)

Find an SPI device by name in the device table.

Parameters
NameThe name of the SPI device to find (eg SPI0)
Returns
Pointer to SPI device entry or nil if not found

◆ spi_device_find_by_description()

SPI_DEVICE *STDCALL spi_device_find_by_description ( const char * description)

Find an SPI device by description in the device table.

Parameters
DescriptionThe description of the SPI to find (eg BCM2837 SPI0 Master)
Returns
Pointer to SPI device entry or nil if not found

◆ spi_device_enumerate()

uint32_t STDCALL spi_device_enumerate ( spi_enumerate_cb callback,
void * data )

Enumerate all SPI devices in the SPI table.

Parameters
CallbackThe callback function to call for each SPI device in the table
DataA private data pointer to pass to callback for each SPI device in the table
Returns
ERROR_SUCCESS if completed or another error code on failure

◆ spi_device_notification()

uint32_t STDCALL spi_device_notification ( SPI_DEVICE * spi,
spi_notification_cb callback,
void * data,
uint32_t notification,
uint32_t flags )

Register a notification for SPI device changes.

Parameters
DeviceThe SPI device to notify changes for (Optional, pass nil for all SPI devices)
CallbackThe function to call when a notification event occurs
DataA private data pointer to pass to callback when a notification event occurs
NotificationThe events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
FlagsThe flags to control the notification (eg NOTIFIER_FLAG_WORKER)

◆ spi_get_count()

uint32_t STDCALL spi_get_count ( void )

Get the current SPI count.

SPI Helper Functions

◆ spi_device_get_default()

SPI_DEVICE *STDCALL spi_device_get_default ( void )

Get the current default SPI device.

◆ spi_device_set_default()

uint32_t STDCALL spi_device_set_default ( SPI_DEVICE * spi)

Set the current default SPI device.

◆ spi_device_check()

SPI_DEVICE *STDCALL spi_device_check ( SPI_DEVICE * spi)

Check if the supplied SPI is in the SPI table.

◆ spi_type_to_string()

uint32_t STDCALL spi_type_to_string ( uint32_t spitype,
char * string,
uint32_t len )

Convert an SPI type value to a string.

◆ spi_state_to_string()

uint32_t STDCALL spi_state_to_string ( uint32_t spistate,
char * string,
uint32_t len )

Convert an SPI state value to a string.

◆ spi_chip_select_to_string()

uint32_t STDCALL spi_chip_select_to_string ( uint16_t chipselect,
char * string,
uint32_t len )

◆ spi_mode_to_string()

uint32_t STDCALL spi_mode_to_string ( uint32_t mode,
char * string,
uint32_t len )

◆ spi_clock_phase_to_string()

uint32_t STDCALL spi_clock_phase_to_string ( uint32_t phase,
char * string,
uint32_t len )

◆ spi_clock_polarity_to_string()

uint32_t STDCALL spi_clock_polarity_to_string ( uint32_t polarity,
char * string,
uint32_t len )

◆ spi_select_polarity_to_string()

uint32_t STDCALL spi_select_polarity_to_string ( uint32_t polarity,
char * string,
uint32_t len )