SPI Master

Functions for using Serial Peripheral Interface (SPI) peripheral. More...

Modules

Types
Hardware SPI data types.
 
Macros
Hardware SPI macros.
 

Functions

gos_result_t gos_spi_stream_configure (gos_spi_t port, gos_gpio_t ss_gpio, gos_spi_flag_t flags, uint32_t clock_rate)
 Configure SPI stream for communication with SPI slave. More...
 
gos_result_t gos_spi_stream_open (gos_handle_t *handle_ptr, uint16_t rx_buffer_size)
 Open SPI stream to slave device. More...
 
gos_result_t gos_spi_stream_write (gos_handle_t handle, const void *data, uint32_t size)
 Write data to slave device. More...
 
gos_result_t gos_spi_stream_read (gos_handle_t handle, void *data, uint32_t max_size, uint32_t *bytes_read_ptr)
 Read data from slave device. More...
 
gos_result_t gos_spi_stream_read_with_buffer (gos_handle_t handle, gos_buffer_t *buffer)
 Read SPI stream data into buffer. More...
 
gos_result_t gos_spi_stream_close (gos_handle_t handle)
 Close SPI stream. More...
 
gos_result_t gos_spi_stream_set_slave_select (gos_handle_t handle, gos_gpio_t ss_gpio)
 Switch SPI stream's slave device. More...
 
gos_result_t gos_spi_transfer (const gos_spi_device_t *spi, const gos_spi_message_t *messages, uint16_t message_count)
 Transfer data messages to SPI slave. More...
 
gos_result_t gos_spi_master_lock_bus (const gos_spi_device_t *spi, uint32_t timeout)
 Lock the SPI bus's mutex. More...
 
gos_result_t gos_spi_master_unlock_bus (const gos_spi_device_t *spi)
 Unlock the SPI bus's mutex. More...
 
gos_result_t gos_spi_master_deassert (const gos_spi_device_t *spi)
 De-assert the SPI slave select GPIO. More...
 

Detailed Description

Functions for using Serial Peripheral Interface (SPI) peripheral.

Function Documentation

◆ gos_spi_master_deassert()

gos_result_t gos_spi_master_deassert ( const gos_spi_device_t spi)

De-assert the SPI slave select GPIO.

This de-selects the slave-select signal. The signal-select can remain asserted based on the supplied flags.

Parameters
[in]spiSPI bus to lock
Returns
gos_result_t result of api call

◆ gos_spi_master_lock_bus()

gos_result_t gos_spi_master_lock_bus ( const gos_spi_device_t spi,
uint32_t  timeout 
)

Lock the SPI bus's mutex.

If the SPI bus is shared with the extended flash, the mutex ensures exclusive access to the bus.

Note
Use gos_spi_master_unlock_bus() to release the lock.
Parameters
[in]spiSPI bus to lock
[in]timeoutMaximum amount of time to wait for the lock
Returns
gos_result_t result of api call

◆ gos_spi_master_unlock_bus()

gos_result_t gos_spi_master_unlock_bus ( const gos_spi_device_t spi)

Unlock the SPI bus's mutex.

See gos_spi_master_lock_bus() for more info.

Parameters
[in]spiSPI bus to lock
Returns
gos_result_t result of api call

◆ gos_spi_stream_close()

gos_result_t gos_spi_stream_close ( gos_handle_t  handle)

Close SPI stream.

See Gecko OS Command API documentation: stream_close.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in]handleHandle of stream to close
Returns
gos_result_t result of api call

◆ gos_spi_stream_configure()

gos_result_t gos_spi_stream_configure ( gos_spi_t  port,
gos_gpio_t  ss_gpio,
gos_spi_flag_t  flags,
uint32_t  clock_rate 
)

Configure SPI stream for communication with SPI slave.

See Gecko OS Command API documentation: spi_master_config.

Parameters
[in]portSPI peripheral port
[in]ss_gpioSlave-select gpio
[in]flagsConfiguration flags, see SPI_FLAG macros
[in]clock_rateSPI master clock
Returns
result of api call, see gos_result_t

◆ gos_spi_stream_open()

gos_result_t gos_spi_stream_open ( gos_handle_t handle_ptr,
uint16_t  rx_buffer_size 
)

Open SPI stream to slave device.

See Gecko OS Command API documentation: spi_master_open.

Parameters
[out]handle_ptrStream handle
[in]rx_buffer_sizeSize of RX buffer
Returns
result of api call, see gos_result_t

◆ gos_spi_stream_read()

gos_result_t gos_spi_stream_read ( gos_handle_t  handle,
void *  data,
uint32_t  max_size,
uint32_t *  bytes_read_ptr 
)

Read data from slave device.

See Gecko OS Command API documentation: spi_master_open, stream_read.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in]handleStream handle returned by API call
[out]dataBuffer to hold read data
[in]max_sizeMaximum amount of data to read
[out]bytes_read_ptrPointer to hold actual amount of data read (set NULL if not used)
Returns
gos_result_t result of api call

◆ gos_spi_stream_read_with_buffer()

gos_result_t gos_spi_stream_read_with_buffer ( gos_handle_t  handle,
gos_buffer_t buffer 
)

Read SPI stream data into buffer.

See gos_read_with_buffer() for more information.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
handleStream handle
bufferBuffer to specify how much data to read, then return how much data was read with pointer to data
Returns
gos_result_t result of api call

◆ gos_spi_stream_set_slave_select()

gos_result_t gos_spi_stream_set_slave_select ( gos_handle_t  handle,
gos_gpio_t  ss_gpio 
)

Switch SPI stream's slave device.

A SPI stream can be associated with multiple SPI slaves. A SPI slave is configured with gos_spi_stream_configure() The configured SPI slave is then selected with this API

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in]handleSPI stream handle
[in]ss_gpioGPIO of configured SPI slave
Returns
gos_result_t result of api call

◆ gos_spi_stream_write()

gos_result_t gos_spi_stream_write ( gos_handle_t  handle,
const void *  data,
uint32_t  size 
)

Write data to slave device.

See Gecko OS Command API documentation: spi_master_open, stream_write.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in]handleStream handle returned by API call
[in]dataData to write to stream
[in]sizeSize of data in bytes to write
Returns
gos_result_t result of api call

◆ gos_spi_transfer()

gos_result_t gos_spi_transfer ( const gos_spi_device_t spi,
const gos_spi_message_t messages,
uint16_t  message_count 
)

Transfer data messages to SPI slave.

This API is separate from the 'spi stream' APIs. This API directly writes the SPI master driver. The driver is automatically configured based on the settings in gos_spi_device_t upon calling this API.

Note
This API does NOT initialize the chip_select GPIO. gos_gpio_init() MUST be called first.
Parameters
[in]spiSPI driver configuration, see gos_spi_device_t
[in,out]messagesArray of messages to read/write data, see gos_spi_message_t
[in]message_countNumber of messages to transfer to SPI slave device
Returns
gos_result_t result of api call