APM:Libraries
Macros | Functions | Variables
spi.c File Reference
#include <spi.h>
#include <hal.h>
Include dependency graph for spi.c:

Go to the source code of this file.

Macros

#define BR_CLEAR_MASK   0xFFC7
 

Functions

void spi_init (const spi_dev *dev)
 Initialize and reset a SPI device. More...
 
void spi_foreach (void(*fn)(const spi_dev *))
 Call a function on each SPI port. More...
 
void spi_gpio_master_cfg (const spi_dev *dev, const gpio_dev *comm_dev, uint8_t sck_bit, uint8_t miso_bit, uint8_t mosi_bit)
 Configure and enable a SPI device as bus master. More...
 
void spi_gpio_slave_cfg (const spi_dev *dev, const gpio_dev *comm_dev, uint8_t sck_bit, uint8_t miso_bit, uint8_t mosi_bit)
 
void spi_reconfigure (const spi_dev *dev, uint8_t ismaster, uint16_t baudPrescaler, uint16_t bitorder, uint8_t mode)
 
void spi_set_speed (const spi_dev *dev, uint16_t baudPrescaler)
 
int spimaster_transfer (const spi_dev *dev, const uint8_t *txbuf, uint16_t txcount, uint8_t *rxbuf, uint16_t rxcount)
 
static void isr_handler (const spi_dev *dev)
 
void SPI1_IRQHandler ()
 
void SPI2_IRQHandler ()
 
void SPI3_IRQHandler ()
 

Variables

static spi_state spi1_state IN_CCM
 
static const spi_dev spi1
 
const spi_dev *const _SPI1 = &spi1
 
static const spi_dev spi2
 
const spi_dev *const _SPI2 = &spi2
 
static const spi_dev spi3
 
const spi_dev *const _SPI3 = &spi3
 

Macro Definition Documentation

◆ BR_CLEAR_MASK

#define BR_CLEAR_MASK   0xFFC7

Referenced by spi_set_speed().

Function Documentation

◆ isr_handler()

static void isr_handler ( const spi_dev dev)
static

Definition at line 265 of file spi.c.

Referenced by SPI1_IRQHandler(), SPI2_IRQHandler(), and SPI3_IRQHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPI1_IRQHandler()

void SPI1_IRQHandler ( )

Definition at line 277 of file spi.c.

Referenced by isr_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPI2_IRQHandler()

void SPI2_IRQHandler ( )

Definition at line 281 of file spi.c.

Referenced by isr_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPI3_IRQHandler()

void SPI3_IRQHandler ( )

Definition at line 285 of file spi.c.

Referenced by isr_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spi_foreach()

void spi_foreach ( void(*)(const spi_dev *)  fn)

Call a function on each SPI port.

Parameters
fnFunction to call.

Definition at line 84 of file spi.c.

Referenced by spi_master_enable(), and spi_peripheral_disable_all().

Here is the caller graph for this function:

◆ spi_gpio_master_cfg()

void spi_gpio_master_cfg ( const spi_dev dev,
const gpio_dev comm_dev,
uint8_t  sck_bit,
uint8_t  miso_bit,
uint8_t  mosi_bit 
)

Configure and enable a SPI device as bus master.

The device's peripheral will be disabled before being reconfigured.

Parameters
devDevice to configure as bus master
baudBus baud rate
modeSPI mode
flagsLogical OR of spi_cfg_flag values.
See also
spi_cfg_flag

Definition at line 92 of file spi.c.

Referenced by F4Light::SPIDevice::init(), and spi_master_enable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spi_gpio_slave_cfg()

void spi_gpio_slave_cfg ( const spi_dev dev,
const gpio_dev comm_dev,
uint8_t  sck_bit,
uint8_t  miso_bit,
uint8_t  mosi_bit 
)

Definition at line 115 of file spi.c.

Referenced by spi_master_enable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spi_init()

void spi_init ( const spi_dev dev)

Initialize and reset a SPI device.

Parameters
devDevice to initialize and reset.

Definition at line 57 of file spi.c.

Referenced by F4Light::SPIDevice::init(), setup(), spi_peripheral_disable(), and spi_reconfigure().

Here is the caller graph for this function:

◆ spi_reconfigure()

void spi_reconfigure ( const spi_dev dev,
uint8_t  ismaster,
uint16_t  baudPrescaler,
uint16_t  bitorder,
uint8_t  mode 
)

Definition at line 132 of file spi.c.

Referenced by spi_master_enable(), and spi_peripheral_disable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spi_set_speed()

void spi_set_speed ( const spi_dev dev,
uint16_t  baudPrescaler 
)

Definition at line 205 of file spi.c.

Referenced by F4Light::SPIDevice::apply_speed(), spi_master_enable(), F4Light::SPIDevice::transfer(), and F4Light::SPIDevice::transfer_fullduplex().

Here is the caller graph for this function:

◆ spimaster_transfer()

int spimaster_transfer ( const spi_dev dev,
const uint8_t *  txbuf,
uint16_t  txcount,
uint8_t *  rxbuf,
uint16_t  rxcount 
)

Definition at line 219 of file spi.c.

Referenced by spi_master_enable(), and F4Light::SPIDevice::transfer().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _SPI1

const spi_dev* const _SPI1 = &spi1

SPI device 1

Definition at line 32 of file spi.c.

◆ _SPI2

const spi_dev* const _SPI2 = &spi2

SPI device 2

Definition at line 43 of file spi.c.

◆ _SPI3

const spi_dev* const _SPI3 = &spi3

SPI device 3

Definition at line 54 of file spi.c.

◆ IN_CCM

spi_state spi3_state IN_CCM
static

Definition at line 19 of file spi.c.

◆ spi1

const spi_dev spi1
static
Initial value:
= {
.SPIx = SPI1,
.afio = GPIO_AF_SPI1,
.irq = SPI1_IRQn,
.clock = RCC_APB2Periph_SPI1,
.state = &spi1_state,
}
#define DMA_CR_CH3
Definition: dma.h:101

Definition at line 23 of file spi.c.

◆ spi2

const spi_dev spi2
static
Initial value:
= {
.SPIx = SPI2,
.afio = GPIO_AF_SPI2,
.irq = SPI2_IRQn,
.clock = RCC_APB1Periph_SPI2,
.state = &spi2_state,
}
#define DMA_CR_CH0
Definition: dma.h:98

Definition at line 34 of file spi.c.

◆ spi3

const spi_dev spi3
static
Initial value:
= {
.SPIx = SPI3,
.afio = GPIO_AF_SPI3,
.irq = SPI3_IRQn,
.clock = RCC_APB1Periph_SPI3,
.state = &spi3_state,
}
#define DMA_CR_CH0
Definition: dma.h:98

Definition at line 45 of file spi.c.