diff options
Diffstat (limited to 'include/i2c.h')
-rw-r--r-- | include/i2c.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/include/i2c.h b/include/i2c.h index 1dcfe46332..9be4f19991 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -31,6 +31,16 @@ enum i2c_freq { I2C_FREQ_COUNT, }; +/* + * I2C mask update actions. + * MASK_SET will OR the mask into the old value + * MASK_CLR will AND the ~mask from the old value + */ +enum mask_update_action { + MASK_CLR, + MASK_SET +}; + /* Data structure to define I2C port configuration. */ struct i2c_port_t { const char *name; /* Port name */ @@ -265,6 +275,79 @@ int i2c_read8(int port, int slave_addr, int offset, int *data); int i2c_write8(int port, int slave_addr, int offset, int data); /** + * Read, modify, write an i2c register to the slave at 7-bit slave address + * <slave_addr_flags>, at the specified 8-bit <offset> in the slave's + * address space. The <action> will specify whether this is setting the + * <mask> bit value(s) or clearing them. If the value to be written is the + * same as the original value of the register, the write will not be + * performed. + */ +int i2c_update8(const int port, + const uint16_t slave_addr_flags, + const int offset, + const uint8_t mask, + const enum mask_update_action action); + +int i2c_update16(const int port, + const uint16_t slave_addr_flags, + const int offset, + const uint16_t mask, + const enum mask_update_action action); + +/** + * Read, modify, write field of an i2c register to the slave at 7-bit + * slave address <slave_addr_flags>, at the specified 8-bit <offset> in + * the slave's address space. The register will be read, the <field_mask> + * will be cleared and then the <set_value> will be set. The field mask + * and the set value do not have to be in the same bit locations. If the + * new value is not the same as the original value, the new value will be + * written back out to the device, otherwise no write will be performed. + */ +int i2c_field_update8(const int port, + const uint16_t slave_addr_flags, + const int offset, + const uint8_t field_mask, + const uint8_t set_value); + +int i2c_field_update16(const int port, + const uint16_t slave_addr_flags, + const int offset, + const uint16_t field_mask, + const uint16_t set_value); + +/** + * Read one or two bytes data from the slave at 7-bit slave address + * * <slaveaddr>, at 16-bit <offset> in the slave's address space. + */ +int i2c_read_offset16(const int port, + const uint16_t slave_addr_flags, + uint16_t offset, int *data, int len); + +/** + * Write one or two bytes data to the slave at 7-bit slave address + * <slaveaddr>, at 16-bit <offset> in the slave's address space. + */ +int i2c_write_offset16(const int port, + const uint16_t slave_addr_flags, + uint16_t offset, int data, int len); + +/** + * Read <len> bytes block data from the slave at 7-bit slave address + * * <slaveaddr>, at 16-bit <offset> in the slave's address space. + */ +int i2c_read_offset16_block(const int port, + const uint16_t slave_addr_flags, + uint16_t offset, uint8_t *data, int len); + +/** + * Write <len> bytes block data to the slave at 7-bit slave address + * <slaveaddr>, at 16-bit <offset> in the slave's address space. + */ +int i2c_write_offset16_block(const int port, + const uint16_t slave_addr_flags, + uint16_t offset, const uint8_t *data, int len); + +/** * @return non-zero if i2c bus is busy */ int i2c_is_busy(int port); |