A compilation of some hardware sensors and their shared programming interfaces.
I2CSensor Class Reference
Base class from which digital sensors using I2C should be derived to simplify low-level communications with the device. More...
#include <I2CSensor.h>
Inherited by INA219, MAG3110, MAX17043, and MMA8451Q.
Public Member Functions | |
I2CSensor (PinName sda, PinName scl, int i2c_addr) | |
PinName | getSDAPin () |
PinName | getSCLPin () |
uint8_t | getDeviceI2CAddress () |
uint8_t | getRegister (const uint8_t reg_addr) |
Read an 8-bit register. | |
uint16_t | getRegister16b (const uint8_t reg_addr) |
Read a 16-bit register. | |
void | setRegister (const uint8_t reg_addr, const uint8_t data) |
Set an 8-bit register. | |
void | setRegister16b (const uint8_t reg_addr, const uint16_t data) |
Set a 16-bit register. | |
Protected Member Functions | |
int | __readReg (const uint8_t reg_addr, uint8_t *data, int len) |
int | __writeReg (const uint8_t *data, int total_len) |
Detailed Description
Base class from which digital sensors using I2C should be derived to simplify low-level communications with the device.
Definition at line 15 of file I2CSensor.h.
Constructor & Destructor Documentation
I2CSensor | ( | PinName | sda, |
PinName | scl, | ||
int | i2c_addr | ||
) |
- Parameters:
-
sda I2C SDA pin ID scl I2C SCL pin ID i2c_addr I2C 8-bit address (LSB is actually don't care)
Definition at line 14 of file I2CSensor.cpp.
Member Function Documentation
int __readReg | ( | const uint8_t | reg_addr, |
uint8_t * | data, | ||
int | len | ||
) | [protected] |
- Parameters:
-
reg_addr 8-bit register address inside the device data 8-bit data that will be read from the register. This pointer MUST be valid. This array MUST be at least as long as len. len total number of bytes to read. len must be >= 1.
- Returns:
- 0 on success, otherwise error code from I2C
Definition at line 57 of file I2CSensor.cpp.
int __writeReg | ( | const uint8_t * | data, |
int | total_len | ||
) | [protected] |
- Parameters:
-
data 8-bit data that will be written to the register. This pointer MUST be valid. This array MUST be at least as long as total_len. data[0] should be set to the 8-bit register address. The data payload should start at index 1. total_len total length of the data array, which is the length of the payload + 1 for the register address. total_len must be >= 2.
- Returns:
- 0 on success, otherwise error code from I2C
Definition at line 72 of file I2CSensor.cpp.
uint8_t getDeviceI2CAddress | ( | ) |
- Returns:
- Device I2C address (LSB always 0 in this case, it is don't care)
Definition at line 28 of file I2CSensor.cpp.
uint8_t getRegister | ( | const uint8_t | reg_addr ) |
Read an 8-bit register.
- Parameters:
-
reg_addr the register in the device
- Returns:
- The raw value from the register specified by reg_addr.
Definition at line 30 of file I2CSensor.cpp.
uint16_t getRegister16b | ( | const uint8_t | reg_addr ) |
Read a 16-bit register.
- Parameters:
-
reg_addr the register in the device
- Returns:
- The raw value from the register specified by reg_addr.
Definition at line 36 of file I2CSensor.cpp.
PinName getSCLPin | ( | ) |
- Returns:
- I2C SCL pin ID
Definition at line 26 of file I2CSensor.cpp.
PinName getSDAPin | ( | ) |
- Returns:
- I2C SDA pin ID
Definition at line 24 of file I2CSensor.cpp.
void setRegister | ( | const uint8_t | reg_addr, |
const uint8_t | data | ||
) |
Set an 8-bit register.
- Parameters:
-
reg_addr the register in the device data the byte to write to the register
Definition at line 43 of file I2CSensor.cpp.
void setRegister16b | ( | const uint8_t | reg_addr, |
const uint16_t | data | ||
) |
Set a 16-bit register.
- Parameters:
-
reg_addr the register in the device data the byte to write to the register
Definition at line 48 of file I2CSensor.cpp.
Generated on Wed Jul 13 2022 19:24:41 by 1.7.2