To create an I2C device, first call i2c_init
, passing in an i2c_config_t
struct. This struct defines the SCL/SDA pins, the I2C device address, and the connect
/read
/write
/disconnect
callbacks.
Initializes an I2C device. The config
argument defines the pins, address, and callbacks for the I2C device. It contains the following fields:
All the callbacks (connect
, read
, write
, disconnect
) are optional. They all use the user_data
pointer as their first argument.
bool on_i2c_connect(void *user_data, uint32_t address, bool read) {
return true;
}
uint8_t on_i2c_read(void *user_data) {
return 0;
}
bool on_i2c_write(void *user_data, uint8_t data) {
return true;
}
void on_i2c_disconnect(void *user_data) {
}
static const i2c_config_t i2c1 {
.address = 0x22,
.scl = pin_init("SCL", INPUT_PULLUP),
.sda = pin_init("SDA", INPUT_PULLUP),
.connect = on_i2c_connect,
.read = on_i2c_read,
.write = on_i2c_write,
.disconnect = on_i2c_disconnect,
.user_data = chip,
};
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4