Class for making communication easier from code to i2c connected Rohm/Kionix sensors. Maybe could be used later also for abstracting Arduino/mbed os. Code ported from 'C'-library rohm-sensor-hal.
Dependents: kionix-kx123-hello rohm-bh1790glc-hello simple-sensor-client rohm-SensorShield-example
Fork of rohm-sensor-hal by
RegisterWriter Class Reference
RegisterWriter class for writing sensor registers via I2C object. More...
#include <RegisterWriter.h>
Public Member Functions | |
RegisterWriter (I2C &i2c_obj) | |
Use pre-instantiated I2C instance for HAL. | |
RegisterWriter (PinName sda=I2C_SDA, PinName scl=I2C_SCL) | |
Create a i2c instance which is connected to specified I2C pins. | |
uint8_t | read_register (uint8_t sad, uint8_t reg, uint8_t *buf, uint8_t buf_len=1) |
General read value(s) to @*buf from sensor in address . | |
uint8_t | read_fifo_register (uint8_t sad, uint8_t reg, uint8_t *buf, uint8_t buf_len) |
FIFO Read value(s) to @*buf from sensor in address . | |
uint8_t | hs_read_register (uint8_t sad, uint8_t reg, uint8_t *buf, uint8_t buf_len) |
Read value(s) in high speed to @*buf from sensor in address . | |
bool | write_register (uint8_t sad, uint8_t reg, uint8_t *data, uint8_t data_len) |
Write value(s) from @*data to sensor in address . | |
bool | write_register_single (uint8_t sad, uint8_t reg, uint8_t *data, uint8_t data_len) |
Write register with single write. | |
bool | write_register_separate (uint8_t sad, uint8_t reg, uint8_t *data, uint8_t data_len) |
Write register with two separate writes. | |
bool | write_register (uint8_t sad, uint8_t reg, uint8_t data) |
Write 1 value from to sensor in address . | |
bool | hs_write_register (uint8_t sad, uint8_t reg, uint8_t *data, uint8_t data_len) |
Write value(s) in high speed from @*data to sensor in address . | |
bool | change_bits (uint8_t sad, uint8_t reg, uint8_t mask, uint8_t bits) |
Read-change-write register (/) |
Detailed Description
RegisterWriter class for writing sensor registers via I2C object.
Definition at line 33 of file RegisterWriter.h.
Constructor & Destructor Documentation
RegisterWriter | ( | I2C & | i2c_obj ) |
Use pre-instantiated I2C instance for HAL.
- Parameters:
-
i2c_obj pre-instantiated i2c object.
Definition at line 33 of file RegisterWriter.cpp.
RegisterWriter | ( | PinName | sda = I2C_SDA , |
PinName | scl = I2C_SCL |
||
) |
Create a i2c instance which is connected to specified I2C pins.
- Parameters:
-
sda SDA pin sdl SCL pin
Definition at line 38 of file RegisterWriter.cpp.
Member Function Documentation
bool change_bits | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t | mask, | ||
uint8_t | bits | ||
) |
Read-change-write register (/)
- Parameters:
-
sad Slave address of sensor reg Register of sensor mask bits to clear before applying new bits value to write
- Returns:
- true on error, false on ok
Definition at line 128 of file RegisterWriter.cpp.
uint8_t hs_read_register | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | buf, | ||
uint8_t | buf_len | ||
) |
Read value(s) in high speed to @*buf from sensor in address .
Reference to kx123 specification page 24, hs 3.4mhZ mode.
- Parameters:
-
sad Slave address of sensor reg Register of sensor *buf uint8_t[] for read data buf_len amount of data to read from
Definition at line 74 of file RegisterWriter.cpp.
bool hs_write_register | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | data, | ||
uint8_t | data_len | ||
) |
Write value(s) in high speed from @*data to sensor in address .
- Parameters:
-
sad Slave address of sensor reg Register of sensor *data uint8_t[] for written data data_len amount of data to written to
uint8_t read_fifo_register | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | buf, | ||
uint8_t | buf_len | ||
) |
FIFO Read value(s) to @*buf from sensor in address .
Difference is the usage of stop-bit between commands.
- Parameters:
-
sad Slave address of sensor reg Register of sensor *buf uint8_t[] for read data buf_len amount of data to read from
Definition at line 58 of file RegisterWriter.cpp.
uint8_t read_register | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | buf, | ||
uint8_t | buf_len = 1 |
||
) |
General read value(s) to @*buf from sensor in address .
- Parameters:
-
sad Slave address of sensor reg Register of sensor *buf uint8_t[] for read data buf_len amount of data to read from
Definition at line 50 of file RegisterWriter.cpp.
bool write_register | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | data, | ||
uint8_t | data_len | ||
) |
Write value(s) from @*data to sensor in address .
Write data to register.
- Parameters:
-
sad Slave address of sensor reg Register of sensor *data uint8_t[] for written data data_len amount of data to written to
Definition at line 81 of file RegisterWriter.cpp.
bool write_register | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t | data | ||
) |
Write 1 value from to sensor in address .
- Parameters:
-
sad Slave address of sensor reg Register of sensor data to be written
Definition at line 116 of file RegisterWriter.cpp.
bool write_register_separate | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | data, | ||
uint8_t | data_len | ||
) |
Write register with two separate writes.
First write register address and then continue with data. Send stop only after second write.
Definition at line 107 of file RegisterWriter.cpp.
bool write_register_single | ( | uint8_t | sad, |
uint8_t | reg, | ||
uint8_t * | data, | ||
uint8_t | data_len | ||
) |
Write register with single write.
Definition at line 88 of file RegisterWriter.cpp.
Generated on Thu Jul 14 2022 05:54:55 by 1.7.2