Skip to content

File syn_soft_i2c.c

FileList > drivers > syn_soft_i2c.c

Go to the source code of this file

  • #include "../util/syn_assert.h"
  • #include "syn_gpio.h"
  • #include "syn_soft_i2c.h"

Public Functions

Type Name
void syn_soft_i2c_init (SYN_SoftI2C * i2c, SYN_GPIO_Pin scl, SYN_GPIO_Pin sda, uint32_t delay_loops)
Initialize the soft I2C pins.
uint8_t syn_soft_i2c_read (const SYN_SoftI2C * i2c, bool ack)
Read a byte from the I2C bus.
void syn_soft_i2c_start (const SYN_SoftI2C * i2c)
Generate an I2C START condition.
void syn_soft_i2c_stop (const SYN_SoftI2C * i2c)
Generate an I2C STOP condition.
bool syn_soft_i2c_write (const SYN_SoftI2C * i2c, uint8_t data)
Write a byte to the I2C bus.
bool syn_soft_i2c_write_read (SYN_SoftI2C * i2c, uint8_t dev_addr, const uint8_t * tx_data, size_t tx_len, uint8_t * rx_data, size_t rx_len)
Perform a write-then-read I2C transaction.

Public Static Functions

Type Name
void i2c_delay (const SYN_SoftI2C * i2c)
void scl_high (const SYN_SoftI2C * i2c)
void scl_low (const SYN_SoftI2C * i2c)
void sda_high (const SYN_SoftI2C * i2c)
void sda_low (const SYN_SoftI2C * i2c)

Public Functions Documentation

function syn_soft_i2c_init

Initialize the soft I2C pins.

void syn_soft_i2c_init (
    SYN_SoftI2C * i2c,
    SYN_GPIO_Pin scl,
    SYN_GPIO_Pin sda,
    uint32_t delay_loops
) 

Parameters:

  • i2c Pointer to I2C instance.
  • scl SCL pin.
  • sda SDA pin.
  • delay_loops Number of iterations for a half-clock delay.

function syn_soft_i2c_read

Read a byte from the I2C bus.

uint8_t syn_soft_i2c_read (
    const SYN_SoftI2C * i2c,
    bool ack
) 

Parameters:

  • i2c Pointer to I2C instance.
  • ack true to ACK the byte, false to NACK (end of read).

Returns:

The byte read.


function syn_soft_i2c_start

Generate an I2C START condition.

void syn_soft_i2c_start (
    const SYN_SoftI2C * i2c
) 

Parameters:

  • i2c Pointer to I2C instance.

function syn_soft_i2c_stop

Generate an I2C STOP condition.

void syn_soft_i2c_stop (
    const SYN_SoftI2C * i2c
) 

Parameters:

  • i2c Pointer to I2C instance.

function syn_soft_i2c_write

Write a byte to the I2C bus.

bool syn_soft_i2c_write (
    const SYN_SoftI2C * i2c,
    uint8_t data
) 

Parameters:

  • i2c Pointer to I2C instance.
  • data Byte to write.

Returns:

true if the slave ACKed, false if NACKed.


function syn_soft_i2c_write_read

Perform a write-then-read I2C transaction.

bool syn_soft_i2c_write_read (
    SYN_SoftI2C * i2c,
    uint8_t dev_addr,
    const uint8_t * tx_data,
    size_t tx_len,
    uint8_t * rx_data,
    size_t rx_len
) 

Sends a START, writes the device address + tx_data, then issues a repeated START, reads rx_len bytes into rx_data, and sends a STOP. This covers the common "write register address, read data" pattern.

Parameters:

  • i2c I2C instance.
  • dev_addr 7-bit device address (will be left-shifted internally).
  • tx_data Data to write (e.g., register address). Can be NULL if tx_len is 0.
  • tx_len Number of bytes to write.
  • rx_data Buffer to read into. Can be NULL if rx_len is 0.
  • rx_len Number of bytes to read.

Returns:

true if all bytes were ACKed, false on NACK.


Public Static Functions Documentation

function i2c_delay

static void i2c_delay (
    const SYN_SoftI2C * i2c
) 

function scl_high

static void scl_high (
    const SYN_SoftI2C * i2c
) 

function scl_low

static void scl_low (
    const SYN_SoftI2C * i2c
) 

function sda_high

static void sda_high (
    const SYN_SoftI2C * i2c
) 

function sda_low

static void sda_low (
    const SYN_SoftI2C * i2c
) 


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