Skip to content

File syn_soft_spi.h

FileList > drivers > syn_soft_spi.h

Go to the source code of this file

Software SPI (bit-banging) driver. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_SoftSPI
Software SPI instance.

Public Types

Type Name
enum SYN_SPIMode
SPI Clock Mode.

Public Functions

Type Name
void syn_soft_spi_deselect (SYN_SoftSPI * spi)
Deassert chip select (drive inactive).
void syn_soft_spi_init (SYN_SoftSPI * spi, SYN_GPIO_Pin sck, SYN_GPIO_Pin mosi, SYN_GPIO_Pin miso, SYN_SPIMode mode, uint32_t delay_loops)
Initialize the soft SPI pins.
void syn_soft_spi_select (SYN_SoftSPI * spi)
Assert chip select (drive active).
void syn_soft_spi_set_cs (SYN_SoftSPI * spi, SYN_GPIO_Pin cs_pin, bool active_low)
Set an optional chip select pin.
uint8_t syn_soft_spi_transfer (const SYN_SoftSPI * spi, uint8_t data)
Transfer a single byte (read and write simultaneously).
void syn_soft_spi_transfer_bulk (SYN_SoftSPI * spi, const uint8_t * tx, uint8_t * rx, size_t len)
Transfer multiple bytes.

Detailed Description

Implements SPI master functionality using any GPIO pins. Relies on syn_port_gpio.h for pin manipulation.

Public Types Documentation

enum SYN_SPIMode

SPI Clock Mode.

enum SYN_SPIMode {
    SYN_SPI_MODE_0 = 0,
    SYN_SPI_MODE_1 = 1,
    SYN_SPI_MODE_2 = 2,
    SYN_SPI_MODE_3 = 3
};


Public Functions Documentation

function syn_soft_spi_deselect

Deassert chip select (drive inactive).

void syn_soft_spi_deselect (
    SYN_SoftSPI * spi
) 

Parameters:

  • spi Soft SPI instance.

function syn_soft_spi_init

Initialize the soft SPI pins.

void syn_soft_spi_init (
    SYN_SoftSPI * spi,
    SYN_GPIO_Pin sck,
    SYN_GPIO_Pin mosi,
    SYN_GPIO_Pin miso,
    SYN_SPIMode mode,
    uint32_t delay_loops
) 

Parameters:

  • spi Pointer to SPI instance.
  • sck SCK pin.
  • mosi MOSI pin.
  • miso MISO pin.
  • mode SPI Mode (0-3).
  • delay_loops Number of iterations for a half-clock delay.

function syn_soft_spi_select

Assert chip select (drive active).

void syn_soft_spi_select (
    SYN_SoftSPI * spi
) 

Parameters:

  • spi Soft SPI instance.

function syn_soft_spi_set_cs

Set an optional chip select pin.

void syn_soft_spi_set_cs (
    SYN_SoftSPI * spi,
    SYN_GPIO_Pin cs_pin,
    bool active_low
) 

When set, syn_soft_spi_select/deselect can be used to assert/deassert CS.

Parameters:

  • spi SPI instance.
  • cs_pin Chip select GPIO pin.
  • active_low true if CS is active-low (most common).

function syn_soft_spi_transfer

Transfer a single byte (read and write simultaneously).

uint8_t syn_soft_spi_transfer (
    const SYN_SoftSPI * spi,
    uint8_t data
) 

Parameters:

  • spi Pointer to SPI instance.
  • data Byte to write out on MOSI.

Returns:

Byte read in from MISO.


function syn_soft_spi_transfer_bulk

Transfer multiple bytes.

void syn_soft_spi_transfer_bulk (
    SYN_SoftSPI * spi,
    const uint8_t * tx,
    uint8_t * rx,
    size_t len
) 

Parameters:

  • spi Pointer to SPI instance.
  • tx Buffer to transmit (can be NULL if rx-only).
  • rx Buffer to receive into (can be NULL if tx-only).
  • len Number of bytes to transfer.


The documentation for this class was generated from the following file src/syntropic/drivers/syn_soft_spi.h