Soletta™ Framework
|
I²C (Inter-Integrated Circuit) API for Soletta. More...
Typedefs | |
typedef struct sol_i2c | sol_i2c |
I2C handle structure. More... | |
typedef struct sol_i2c_pending | sol_i2c_pending |
I2C pending operation handle structure. More... | |
Enumerations | |
enum | sol_i2c_speed { SOL_I2C_SPEED_10KBIT = 0, SOL_I2C_SPEED_100KBIT, SOL_I2C_SPEED_400KBIT, SOL_I2C_SPEED_1MBIT, SOL_I2C_SPEED_3MBIT_400KBIT } |
Enum for I2C bus speed. More... | |
Functions | |
void | sol_i2c_close (struct sol_i2c *i2c) |
Close an I2C bus. More... | |
uint8_t | sol_i2c_get_bus (const struct sol_i2c *i2c) |
Get the I2C bus ID. More... | |
uint8_t | sol_i2c_get_slave_address (struct sol_i2c *i2c) |
Get the (slave) device address set on an I2C bus (to deliver I2C commands to) More... | |
struct sol_i2c * | sol_i2c_open (uint8_t bus, enum sol_i2c_speed speed) |
Open an I2C bus. More... | |
struct sol_i2c * | sol_i2c_open_raw (uint8_t bus, enum sol_i2c_speed speed) |
Open an I2C bus. More... | |
void | sol_i2c_pending_cancel (struct sol_i2c *i2c, struct sol_i2c_pending *pending) |
Cancel a pending operation. More... | |
struct sol_i2c_pending * | sol_i2c_read (struct sol_i2c *i2c, uint8_t *data, size_t count, void(*read_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status), const void *cb_data) |
Perform successive asynchronous I2C byte read operations, with no specified register. More... | |
struct sol_i2c_pending * | sol_i2c_read_register (struct sol_i2c *i2c, uint8_t reg, uint8_t *data, size_t count, void(*read_reg_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data) |
Perform an asynchronous I2C read operation on a given device register. More... | |
struct sol_i2c_pending * | sol_i2c_read_register_multiple (struct sol_i2c *i2c, uint8_t reg, uint8_t *values, size_t count, uint8_t times, void(*read_reg_multiple_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data) |
Asynchronous read of an arbitrary number of bytes from a register in repeated bursts of a given length (that start always on the provided register address) More... | |
int | sol_i2c_set_slave_address (struct sol_i2c *i2c, uint8_t slave_address) |
Set a (slave) device address on a I2C bus to deliver commands to. More... | |
enum sol_i2c_speed | sol_i2c_speed_from_str (const char *speed) |
Converts a string I2C speed to sol_i2c_speed. More... | |
const char * | sol_i2c_speed_to_str (enum sol_i2c_speed speed) |
Converts sol_i2c_speed to a string name. More... | |
struct sol_i2c_pending * | sol_i2c_write (struct sol_i2c *i2c, uint8_t *data, size_t count, void(*write_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status), const void *cb_data) |
Perform successive asynchronous I2C byte write operations, with no specified register. More... | |
struct sol_i2c_pending * | sol_i2c_write_quick (struct sol_i2c *i2c, bool rw, void(*write_quick_cb)(void *cb_data, struct sol_i2c *i2c, ssize_t status), const void *cb_data) |
Perform a I2C write quick operation. More... | |
struct sol_i2c_pending * | sol_i2c_write_register (struct sol_i2c *i2c, uint8_t reg, const uint8_t *data, size_t count, void(*write_reg_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data) |
Perform an asynchronous I2C write operation on a given device register. More... | |
enum | sol_i2c_op_type { SOL_I2C_READ, SOL_I2C_WRITE } |
I²C operation dispatcher. More... | |
typedef struct sol_i2c_op_set_pending | sol_i2c_op_set_pending |
I2C Dispatcher pending operation set handle structure. More... | |
struct sol_i2c_op_set_pending * | sol_i2c_dispatcher_add_op_set (struct sol_i2c *i2c, uint8_t addr, struct sol_vector *set, void(*cb)(void *cb_data, ssize_t status), void *cb_data, uint32_t delay) |
Add an operation set in the dispatcher's queue of a given I2C bus. More... | |
void | sol_i2c_dispatcher_remove_op_set (struct sol_i2c *i2c, struct sol_i2c_op_set_pending *pending) |
Cancel the execution of the pending operation set. More... | |
I²C (Inter-Integrated Circuit) API for Soletta.
I2C handle structure.
I2C Dispatcher pending operation set handle structure.
I2C pending operation handle structure.
enum sol_i2c_op_type |
enum sol_i2c_speed |
Enum for I2C bus speed.
Must be chosen when opening a bus with sol_i2c_open() and sol_i2c_open_raw().
void sol_i2c_close | ( | struct sol_i2c * | i2c | ) |
Close an I2C bus.
i2c | The I2C bus handle to close |
struct sol_i2c_op_set_pending* sol_i2c_dispatcher_add_op_set | ( | struct sol_i2c * | i2c, |
uint8_t | addr, | ||
struct sol_vector * | set, | ||
void(*)(void *cb_data, ssize_t status) | cb, | ||
void * | cb_data, | ||
uint32_t | delay | ||
) |
Add an operation set in the dispatcher's queue of a given I2C bus.
It adds an operation set scheduling it for execution by the dispatcher handling i2c opeations at bus i2c.
i2c | The i2c bus handle |
addr | The slave device address |
set | Operation set to be added |
cb | Callback to be called after the operation set is executed |
cb_data | Callback context data |
delay | Time, in milliseconds, to wait between two consecutive operations of this set |
void sol_i2c_dispatcher_remove_op_set | ( | struct sol_i2c * | i2c, |
struct sol_i2c_op_set_pending * | pending | ||
) |
Cancel the execution of the pending operation set.
i2c | The I2C bus handle |
pending | The operation set pending handle |
uint8_t sol_i2c_get_bus | ( | const struct sol_i2c * | i2c | ) |
Get the I2C bus ID.
i2c | The I2C bus handle |
uint8_t sol_i2c_get_slave_address | ( | struct sol_i2c * | i2c | ) |
Get the (slave) device address set on an I2C bus (to deliver I2C commands to)
i2c | The I2C bus handle |
0x0
means bus was not set to any device yet struct sol_i2c* sol_i2c_open | ( | uint8_t | bus, |
enum sol_i2c_speed | speed | ||
) |
Open an I2C bus.
bus | The I2C bus number to open |
speed | The speed to open I2C bus bus at |
struct sol_i2c* sol_i2c_open_raw | ( | uint8_t | bus, |
enum sol_i2c_speed | speed | ||
) |
Open an I2C bus.
bus | The I2C bus number to open |
speed | The speed to open I2C bus bus at |
void sol_i2c_pending_cancel | ( | struct sol_i2c * | i2c, |
struct sol_i2c_pending * | pending | ||
) |
Cancel a pending operation.
i2c | the I2C bus handle |
pending | the operation handle |
struct sol_i2c_pending* sol_i2c_read | ( | struct sol_i2c * | i2c, |
uint8_t * | data, | ||
size_t | count, | ||
void(*)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status) | read_cb, | ||
const void * | cb_data | ||
) |
Perform successive asynchronous I2C byte read operations, with no specified register.
This makes count read byte I2C operations on the device bus is set to operate on, at no specific register. Some devices are so simple that this interface is enough. For others, it is a shorthand if you want to read the same register as in the previous I2C command.
i2c | The I2C bus handle |
data | The output buffer for the read operation |
count | The bytes count for the read operation |
read_cb | The callback to be called when operation finish, the status parameter should be equal to count in case of success (or a negative error code, on failure) |
cb_data | The first parameter of callback |
NULL
. It's only valid before read_cb is called. It may be used before that to cancel the read operation. If NULL
is returned, the errno variable will be set with the correct error value. In case that the I2C device is in use, the errno variable is set to EBUSY. struct sol_i2c_pending* sol_i2c_read_register | ( | struct sol_i2c * | i2c, |
uint8_t | reg, | ||
uint8_t * | data, | ||
size_t | count, | ||
void(*)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status) | read_reg_cb, | ||
const void * | cb_data | ||
) |
Perform an asynchronous I2C read operation on a given device register.
i2c | The I2C bus handle |
reg | The I2C register for the read operation |
data | The output buffer for the read operation |
count | The bytes count for the read operation |
read_reg_cb | The callback to be called when operation finish, the status parameter should be equal to count in case of success (or a negative error code, on failure) |
cb_data | The first parameter of callback |
NULL
. It's only valid before read_reg_cb is called. It may be used before that to cancel the read operation. If NULL
is returned, the errno variable will be set with the correct error value. In case that the I2C device is in use, the errno variable is set to EBUSY. struct sol_i2c_pending* sol_i2c_read_register_multiple | ( | struct sol_i2c * | i2c, |
uint8_t | reg, | ||
uint8_t * | values, | ||
size_t | count, | ||
uint8_t | times, | ||
void(*)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status) | read_reg_multiple_cb, | ||
const void * | cb_data | ||
) |
Asynchronous read of an arbitrary number of bytes from a register in repeated bursts of a given length (that start always on the provided register address)
This is so because a lot of devices will, after a read operation, update its register values with new data to be read on subsequent operations, until the total data length the user requested is read. If the device has the auto-increment feature, sol_i2c_read_register() might be a better call than this function.
This will issue multiple I2C read/write transactions with the first (write) message specifying the register to operate on and the second (read) message specifying the length (always len per read) and the destination of the read operation.
i2c | The I2C bus handle |
reg | The register to start reading from |
values | Where to store the read bytes |
count | The size of a single read block |
times | How many reads of size len to perform (on success, len * times bytes will be read) |
read_reg_multiple_cb | The callback to be called when the operation finishes. The status parameter should be equal to count in case of success (or a negative error code, on failure) |
cb_data | The first parameter of callback |
NULL
. It's only valid before read_reg_multiple_cb is called. It may be used before that to cancel the read operation. If NULL
is returned, the errno variable will be set with the correct error value. In case that the I2C device is in use, the errno variable is set to EBUSY. int sol_i2c_set_slave_address | ( | struct sol_i2c * | i2c, |
uint8_t | slave_address | ||
) |
Set a (slave) device address on a I2C bus to deliver commands to.
All other I2C functions, after this call, will act on the given slave_address device address. Since other I2C calls might happen in between your own ones, though, it's highly advisable that you issue this call before using any of the I2C read/write functions.
i2c | The I2C bus handle |
slave_address | The slave device address to deliver commands to |
0
on success, -EBUSY
if the device is busy or -errno on error. enum sol_i2c_speed sol_i2c_speed_from_str | ( | const char * | speed | ) |
Converts a string I2C speed to sol_i2c_speed.
This function converts a string I2C speed to enumeration sol_i2c_speed.
speed | Valid values are "10kbps", "100kbps", "400kbps", "1000kbps", "3400kbps". |
const char* sol_i2c_speed_to_str | ( | enum sol_i2c_speed | speed | ) |
Converts sol_i2c_speed to a string name.
This function converts sol_i2c_speed enumeration to a string I2C speed name.
speed | sol_i2c_speed. |
struct sol_i2c_pending* sol_i2c_write | ( | struct sol_i2c * | i2c, |
uint8_t * | data, | ||
size_t | count, | ||
void(*)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status) | write_cb, | ||
const void * | cb_data | ||
) |
Perform successive asynchronous I2C byte write operations, with no specified register.
This makes count write byte I2C operations on the device bus is set to operate on, at no specific register. Some devices are so simple that this interface is enough. For others, it is a shorthand if you want to write the same register as in the previous I2C command.
i2c | The I2C bus handle |
data | The output buffer for the write operation |
count | The bytes count for the write operation |
write_cb | The callback to be called when operation finish, the status parameter should be equal to count in case of success (or a negative error code, on failure) |
cb_data | The first parameter of callback |
NULL
. It's only valid before write_cb is called. It may be used before that to cancel the read operation. If NULL
is returned, the errno variable will be set with the correct error value. In case that the I2C device is in use, the errno variable is set to EBUSY. struct sol_i2c_pending* sol_i2c_write_quick | ( | struct sol_i2c * | i2c, |
bool | rw, | ||
void(*)(void *cb_data, struct sol_i2c *i2c, ssize_t status) | write_quick_cb, | ||
const void * | cb_data | ||
) |
Perform a I2C write quick operation.
This sends a single bit to a device (command designed to turn on and off simple devices)
i2c | The I2C bus handle |
rw | The value to write |
write_quick_cb | The callback to be issued when the operation finishes. The status parameter should be equal to one in case of success (or a negative error code, on failure) |
cb_data | Data to be passed to write_quick_cb |
NULL
. It's only valid before write_quick_cb is called. It may be used before that to cancel the read operation. If NULL
is returned, the errno variable will be set with the correct error value. In case that the I2C device is in use, the errno variable is set to EBUSY. struct sol_i2c_pending* sol_i2c_write_register | ( | struct sol_i2c * | i2c, |
uint8_t | reg, | ||
const uint8_t * | data, | ||
size_t | count, | ||
void(*)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status) | write_reg_cb, | ||
const void * | cb_data | ||
) |
Perform an asynchronous I2C write operation on a given device register.
i2c | The I2C bus handle |
reg | The I2C register for the write operation |
data | The output buffer for the write operation |
count | The bytes count for the write operation |
write_reg_cb | The callback to be called when operation finish, the status parameter should be equal to count in case of success (or a negative error code, on failure) |
cb_data | The first parameter of callback |
NULL
. It's only valid before write_reg_cb is called. It may be used before that to cancel the read operation. If NULL
is returned, the errno variable will be set with the correct error value. In case that the I2C device is in use, the errno variable is set to EBUSY.