objc

i2c.h
Go to the documentation of this file.
1 
11 #pragma once
12 #include "gpio.h"
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 
18 // TYPES
19 
28 typedef struct hw_i2c_t {
29  uint8_t reserved[32];
30 } hw_i2c_t;
31 
33 // LIFECYCLE
34 
46 bool hw_i2c_init_default(hw_i2c_t *adapter, uint32_t baudrate);
47 
65 bool hw_i2c_init(hw_i2c_t *adapter, uint8_t index, uint8_t sda, uint8_t scl,
66  uint32_t baudrate);
67 
80 bool hw_i2c_init_device(hw_i2c_t *adapter, const char *device,
81  uint32_t baudrate);
82 
92 void hw_i2c_finalize(hw_i2c_t *i2c);
93 
95 // PROPERTIES
96 
106 uint8_t hw_i2c_count(void);
107 
117 bool hw_i2c_valid(hw_i2c_t *i2c);
118 
120 // METHODS
121 
134 bool hw_i2c_detect(hw_i2c_t *i2c, uint8_t addr);
135 
158 size_t hw_i2c_xfr(hw_i2c_t *i2c, uint8_t addr, void *data, size_t tx, size_t rx,
159  uint32_t timeout_ms);
160 
174 size_t hw_i2c_read(hw_i2c_t *i2c, uint8_t addr, uint8_t reg, void *data,
175  size_t len, uint32_t timeout_ms);
176 
190 size_t hw_i2c_write(hw_i2c_t *i2c, uint8_t addr, uint8_t reg, const void *data,
191  size_t len, uint32_t timeout_ms);
struct hw_i2c_t hw_i2c_t
I2C adapter.
GPIO (General Purpose Input/Output) interface.
bool hw_i2c_init_default(hw_i2c_t *adapter, uint32_t baudrate)
Initialize an I2C interface using default pins and adapter.
size_t hw_i2c_xfr(hw_i2c_t *i2c, uint8_t addr, void *data, size_t tx, size_t rx, uint32_t timeout_ms)
Perform an I2C transfer operation (read, write, or combined).
bool hw_i2c_detect(hw_i2c_t *i2c, uint8_t addr)
Detect if an I2C device is present at the specified address.
uint8_t reserved[32]
Reserved for platform-specific implementation.
Definition: i2c.h:29
bool hw_i2c_init_device(hw_i2c_t *adapter, const char *device, uint32_t baudrate)
Initialize an I2C interface with device path.
void hw_i2c_finalize(hw_i2c_t *i2c)
Finalize and release an I2C interface.
I2C adapter.
Definition: i2c.h:28
size_t hw_i2c_write(hw_i2c_t *i2c, uint8_t addr, uint8_t reg, const void *data, size_t len, uint32_t timeout_ms)
Write data to a specific register of an I2C device.
bool hw_i2c_valid(hw_i2c_t *i2c)
Get true if the I2C interface is valid.
size_t hw_i2c_read(hw_i2c_t *i2c, uint8_t addr, uint8_t reg, void *data, size_t len, uint32_t timeout_ms)
Read data from a specific register of an I2C device.
uint8_t hw_i2c_count(void)
Get the total number of available I2C adapters.
bool hw_i2c_init(hw_i2c_t *adapter, uint8_t index, uint8_t sda, uint8_t scl, uint32_t baudrate)
Initialize an I2C interface with specific adapter and pins.