gos_spi_device_t Struct Reference

SPI slave context used by gos_spi_master_transfer() More...

Data Fields

gos_spi_t port
 SPI peripheral used.
 
gos_gpio_t chip_select
 GPIO of slave's chip select, set as GOS_GPIO_INVALID if unused.
 
gos_spi_cs_callback_t cs_callback
 gos_spi_cs_callback_t invoked when asserting/de-asserting CS signal, set as NULL if unused
 
void * cs_callback_arg
 Optional argument supplied to gos_spi_cs_callback_t.
 
uint32_t speed
 Master clock speed in hertz.
 
gos_spi_flag_t flags
 Bus flags, see gos_spi_flag_t.
 
uint8_t bits
 Number of bits per frame.
 
bool lcd_bit8
 Bit 8 setting in 9 bit LCD mode.
 

Detailed Description

SPI slave context used by gos_spi_master_transfer()

Note
Either the chip_select and/or cs_callback MUST be specified.

Gecko OS automatically locks the SPI peripheral based on:

  • Current thread
  • chip_select field
  • cs_callback field

This allows for multiple threads to safely access the same SPI peripheral.

If chip_select is GOS_GPIO_INVALID and the cs_callback function pointer is used to assert different SPI slave devices, then the function pointer should be different for each slave device. i.e.

void spi_slave1_cs_callback(void *arg, bool asserted)
{
io_expander_set(SPI_SLAVE1_GPIO, asserted);
}
void spi_slave2_cs_callback(void *arg, bool asserted)
{
io_expander_set(SPI_SLAVE2_GPIO, asserted);
}
gos_spi_device_t spi_slave1;
gos_spi_device_t spi_slave2;
spi_slave1.cs_callback = spi_slave1_cs_callback;
spi_slave2.cs_callback = spi_slave2_cs_callback;
Examples:
test/spi_loop_back/main.c.