File syn_soft_i2c.h¶
FileList > drivers > syn_soft_i2c.h
Go to the source code of this file
Software I2C (bit-banging) driver. More...
#include "../common/syn_defs.h"#include <stdbool.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_SoftI2C Software I2C instance. |
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. |
Detailed Description¶
Implements I2C master functionality using any two GPIO pins. Relies on syn_port_gpio.h for pin manipulation. Uses a simple NOP loop for clock stretching/delays.
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:
i2cPointer to I2C instance.sclSCL pin.sdaSDA pin.delay_loopsNumber of iterations for a half-clock delay.
function syn_soft_i2c_read¶
Read a byte from the I2C bus.
Parameters:
i2cPointer to I2C instance.acktrue to ACK the byte, false to NACK (end of read).
Returns:
The byte read.
function syn_soft_i2c_start¶
Generate an I2C START condition.
Parameters:
i2cPointer to I2C instance.
function syn_soft_i2c_stop¶
Generate an I2C STOP condition.
Parameters:
i2cPointer to I2C instance.
function syn_soft_i2c_write¶
Write a byte to the I2C bus.
Parameters:
i2cPointer to I2C instance.dataByte 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:
i2cI2C instance.dev_addr7-bit device address (will be left-shifted internally).tx_dataData to write (e.g., register address). Can be NULL if tx_len is 0.tx_lenNumber of bytes to write.rx_dataBuffer to read into. Can be NULL if rx_len is 0.rx_lenNumber of bytes to read.
Returns:
true if all bytes were ACKed, false on NACK.
The documentation for this class was generated from the following file src/syntropic/drivers/syn_soft_i2c.h