I2C_device_Arduino 1.0.5
An I²C utility class for Arduino
|
#include <I2C_device.h>
Public Member Functions | |
I2C_device (uint8_t i2c_address, bool repeated_start_enable=true) | |
I2C_device (TwoWire &wire, uint8_t i2c_address, bool repeated_start_enable=true) | |
~I2C_device () | |
void | repeated_start_enable (bool en=true) |
bool | ping (void) |
int | tx (const uint8_t *data, uint16_t size, bool stop=true) |
int | rx (uint8_t *data, uint16_t size) |
int | reg_w (uint8_t reg_adr, const uint8_t *data, uint16_t size) |
int | reg_w (uint8_t reg_adr, uint8_t data) |
int | reg_r (uint8_t reg_adr, uint8_t *data, uint16_t size) |
uint8_t | reg_r (uint8_t reg_adr) |
void | write_r8 (uint8_t reg, uint8_t val) |
void | write_r16 (uint8_t reg, uint16_t val) |
uint8_t | read_r8 (uint8_t reg) |
uint16_t | read_r16 (uint8_t reg) |
void | bit_op8 (uint8_t reg, uint8_t mask, uint8_t value) |
void | bit_op16 (uint8_t reg, uint16_t mask, uint16_t value) |
Static Public Member Functions | |
static bool | ping (uint8_t addr) |
static void | scan (TwoWire &target_i2c=Wire, uint8_t stop=128) |
Private Attributes | |
TwoWire & | i2c |
uint8_t | i2c_addr |
bool | rs_dis |
I2C device abstracting class
This class provides common methods for all I2C devices
Released under the MIT license License
Definition at line 18 of file I2C_device.h.
I2C_device::I2C_device | ( | uint8_t | i2c_address, |
bool | repeated_start_enable = true ) |
Create a I2C_device instance with specified address
i2c_address | I2C-bus address |
repeated_start_enable | repeated-START-condition enable between write and read transaction for register reading. Default: true |
Definition at line 3 of file I2C_device.cpp.
I2C_device::I2C_device | ( | TwoWire & | wire, |
uint8_t | i2c_address, | ||
bool | repeated_start_enable = true ) |
Create a I2C_device instance with specified address
wire | TwoWire instance |
i2c_address | I2C-bus address |
repeated_start_enable | repeated-START-condition enable between write and read transaction for register reading. Default: true |
Definition at line 7 of file I2C_device.cpp.
I2C_device::~I2C_device | ( | ) |
Destructor of I2C_device
Definition at line 11 of file I2C_device.cpp.
void I2C_device::bit_op16 | ( | uint8_t | reg, |
uint16_t | mask, | ||
uint16_t | value ) |
Definition at line 165 of file I2C_device.cpp.
void I2C_device::bit_op8 | ( | uint8_t | reg, |
uint8_t | mask, | ||
uint8_t | value ) |
Register overwriting with bit-mask
Register can be updated by bit level
reg | register index/address/pointer |
mask | bit-mask to protect overwriting |
value | value to overwrite |
Definition at line 155 of file I2C_device.cpp.
|
static |
ping (class method)
target | address |
bool I2C_device::ping | ( | void | ) |
uint16_t I2C_device::read_r16 | ( | uint8_t | reg | ) |
Register read, 16 bit
This 16 bit access may ot be common but it's useful for sensor devices
reg | register index/address/pointer |
Definition at line 146 of file I2C_device.cpp.
Referenced by bit_op16(), and test_LM75B::read().
uint8_t I2C_device::read_r8 | ( | uint8_t | reg | ) |
Register read, 8 bit
reg | register index/address/pointer |
Definition at line 141 of file I2C_device.cpp.
Referenced by bit_op8(), and test_LM75B::os_mode().
uint8_t I2C_device::reg_r | ( | uint8_t | reg_adr | ) |
Single register read
reg | register index/address/pointer |
data | pointer to data buffer |
size | data size |
Definition at line 117 of file I2C_device.cpp.
int I2C_device::reg_r | ( | uint8_t | reg_adr, |
uint8_t * | data, | ||
uint16_t | size ) |
Multiple register read
reg | register index/address/pointer |
data | pointer to data buffer |
size | data size |
Definition at line 111 of file I2C_device.cpp.
Referenced by read_r16(), and read_r8().
int I2C_device::reg_w | ( | uint8_t | reg_adr, |
const uint8_t * | data, | ||
uint16_t | size ) |
Multiple register write
reg | register index/address/pointer |
data | pointer to data buffer |
size | data size |
Definition at line 90 of file I2C_device.cpp.
Referenced by write_r16(), and write_r8().
int I2C_device::reg_w | ( | uint8_t | reg_adr, |
uint8_t | data ) |
Single register write
reg | register index/address/pointer |
data | pointer to data buffer |
size | data size |
Definition at line 101 of file I2C_device.cpp.
void I2C_device::repeated_start_enable | ( | bool | en = true | ) |
repeated-START-condition enable
en | repeated-START-condition enable between write and read transaction for register reading. Default: true |
Definition at line 15 of file I2C_device.cpp.
int I2C_device::rx | ( | uint8_t * | data, |
uint16_t | size ) |
Receive data
data | pointer to data buffer |
size | data size |
Definition at line 75 of file I2C_device.cpp.
|
static |
scan (class method)
Definition at line 26 of file I2C_device.cpp.
int I2C_device::tx | ( | const uint8_t * | data, |
uint16_t | size, | ||
bool | stop = true ) |
Send data
data | pointer to data buffer |
size | data size |
stop | option: generating STOP-condition after transaction. Defailt: true |
Definition at line 63 of file I2C_device.cpp.
void I2C_device::write_r16 | ( | uint8_t | reg, |
uint16_t | val ) |
Register write, 16 bit
This 16 bit access may ot be common but it's useful for sensor devices
reg | register index/address/pointer |
val | data value |
Definition at line 131 of file I2C_device.cpp.
Referenced by bit_op16(), and test_LM75B::thresholds().
void I2C_device::write_r8 | ( | uint8_t | reg, |
uint8_t | val ) |
Register write, 8 bit
reg | register index/address/pointer |
Definition at line 126 of file I2C_device.cpp.
Referenced by bit_op8(), and test_LM75B::os_mode().
|
private |
Definition at line 160 of file I2C_device.h.
|
private |
Definition at line 161 of file I2C_device.h.
|
private |
Definition at line 162 of file I2C_device.h.
Referenced by reg_r(), reg_r(), and repeated_start_enable().