Base class for digital I2C Groves. More...
#include <sg_GroveI2CDigital.hpp>
Public Types | |
typedef uint8_t | I2CBus |
I2C bus. More... | |
typedef uint8_t | I2CAddress |
I2C addresses. More... | |
typedef uint8_t | I2CRegister |
I2C register. More... | |
typedef std::vector< uint8_t > | I2CBlock |
Block of sequential bytes to read or write. More... | |
Public Member Functions | |
GroveI2CDigital (const SG::EGroveType t=SG::EGroveType::kUnknown, const std::string &n="", const I2CAddress addr=0) | |
Constructor. More... | |
virtual | ~GroveI2CDigital (void) |
Destructor. More... | |
virtual bool | is_analog (void) const |
This is always false for GroveI2CDigital. More... | |
virtual bool | is_digital (void) const |
This is always true for GroveI2CDigital. More... | |
I2CAddress | get_address_from_type (void) const |
Get the address for this Grove type. More... | |
virtual uint8_t | read8 (const I2CRegister reg) |
Read a byte (8 bits) from the specificed register. More... | |
virtual uint16_t | read16 (const I2CRegister reg) |
Read a 16-bit word from the specified register. More... | |
virtual uint16_t | read12 (const I2CRegister reg) |
Read a 16-bit word from the specified register, but only keep the bottom 12 bits. More... | |
virtual I2CBlock | read_block (const I2CRegister reg) |
Read a consecutive block of bytes, anywhere between 1 and 32 bytes in length. More... | |
virtual GroveI2CDigital & | write_byte (const uint8_t value) |
Write a single byte to the I2C bus. More... | |
virtual GroveI2CDigital & | write_block (const I2CRegister reg, const I2CBlock &v) |
Write a consecutive block of bytes, anywhere between 1 and 32 bytes in length. More... | |
virtual GroveI2CDigital & | write_block (const I2CBlock &v) |
Write a consecutive block of bytes directly to the I2C file handle. More... | |
virtual bool | is_grove_uart (void) const |
This is always false for GroveI2C. More... | |
virtual bool | is_grove_i2c (void) const |
This is always true for GroveI2C. More... | |
virtual bool | is_grove_gpio (void) const |
This is always false for GroveI2C. More... | |
virtual uint32_t | get_sku (void) const |
Return a guess as to the Seeed SKU number based on the grove type. More... | |
virtual std::string | get_type_name (void) const |
Return a short text string representing the grove type. More... | |
virtual EGroveType | get_type (void) const |
Return the grove type. More... | |
virtual std::string | get_name (void) const |
Return the user-supplied name. More... | |
virtual std::string | get_description (void) const |
Return a multi-word 1-line description of this object. More... | |
virtual GroveI2CDigital & | write8 (const I2CRegister reg, const uint8_t value) |
Write the given value to the specified register. More... | |
virtual GroveI2CDigital & | write16 (const I2CRegister reg, const uint16_t value) |
bool | operator== (const GroveBase &rhs) const |
Test object equality. More... | |
bool | operator!= (const GroveBase &rhs) const |
Test object equality. More... | |
Static Public Member Functions | |
static I2CBus | detect_i2c_bus_number (const bool force_detect=false, const int force_bus_number=-1) |
Detect the I2C bus to use to talk to Grove I2C devices. More... | |
static I2CAddress | get_address_from_type (const EGroveType &type) |
Get the default I2C address for a given type. More... | |
Public Attributes | |
I2CBus | i2c_bus_number |
The bus number to use for I2C Grove twigs. More... | |
I2CAddress | i2c_address |
The I2C address used to communicate with the Grove device. More... | |
int | i2c_file_handle |
The file handle to /dev/i2c-* used to communicate with the Grove device. More... | |
EGroveType | grove_type |
Grove type. More... | |
std::string | grove_name |
User-supplied name. More... | |
Base class for digital I2C Groves.
The BeagleBone Green has two I2C buses. The first is /dev/i2c-0
and the second is /dev/i2c-1
or /dev/i2c-2
. The first one, i2c-0
, is not exposed and isn't of interest to the SG++ library. The second one is where I2C Grove twigs are connected.
When looking at the top of a BeagleBone Green with the network interface towards the top and the Grove interfaces at the bottom, i2c-1
(or i2c-2
) is the left-hand-side Grove interface labelled J4
. On the board, you'll also see the labels SCL
(serial clock line), SDA
(serial data line), 3V3
, and GND
.
Several parts of the BeagleBone Green are always connected to the I2C bus. It is important to note the addresses, because they can conflict with the address of Seeed twigs, such as Seeed's I2C ADC twig which defaults to address 0x55
.
Bus/Device | Address | Name | Description | Also See |
---|---|---|---|---|
/dev/i2c-0 | 0x24 | TPS65217 | PMU (power management unit) | /sys/bus/i2c/devices/0-0024 |
/dev/i2c-0 | 0x50 | AT24C256 | EEPROM | /sys/bus/i2c/devices/0-0050 |
/dev/i2c-1 | 0x54 | AT24C256 | EEPROM | /sys/bus/i2c/devices/1-0054 |
/dev/i2c-1 | 0x55 | AT24C256 | EEPROM | /sys/bus/i2c/devices/1-0055 |
/dev/i2c-1 | 0x56 | AT24C256 | EEPROM | /sys/bus/i2c/devices/1-0056 |
/dev/i2c-1 | 0x57 | AT24C256 | EEPROM | /sys/bus/i2c/devices/1-0057 |
The other interface labelled J5
on the bottom right side is the UART Grove interface.
typedef uint8_t SG::GroveI2CDigital::I2CAddress |
I2C addresses.
typedef std::vector<uint8_t> SG::GroveI2CDigital::I2CBlock |
Block of sequential bytes to read or write.
typedef uint8_t SG::GroveI2CDigital::I2CBus |
I2C bus.
typedef uint8_t SG::GroveI2CDigital::I2CRegister |
I2C register.
SG::GroveI2CDigital::GroveI2CDigital | ( | const SG::EGroveType | t = SG::EGroveType::kUnknown , |
const std::string & | n = "" , |
||
const I2CAddress | addr = 0 |
||
) |
Constructor.
std::system_error | if the I2C device cannot be opened. |
std::system_error | if the I2C slave address cannot be set. |
References get_address_from_type(), SG::GroveBase::get_description(), i2c_address, i2c_bus_number, i2c_file_handle, I2C_SLAVE, and SG::BeagleBone::Detect::to_string().
|
virtual |
Destructor.
References i2c_file_handle.
|
static |
Detect the I2C bus to use to talk to Grove I2C devices.
This is normally 1
or 2
. The detection consists of looking at /dev/i2c* devices.
[in] | force_detect | The detected bus number is usually remembered to prevent having to re-detect it every time a new GroveI2C object is instantiated. If force_detect is set to true , then this will force GroveI2C to ignore the previously cached bus number and re-detect the I2C bus. |
[in] | force_bus_number | If an explicit bus number should be used, then force_bus_number can be set to the correct bus value. This will prevent calls to detect_i2c_bus_number() from attempting to auto-detect the I2C bus. Setting the I2C bus number this way wont change existing GroveI2C objects that have already been instantiated. Only new objects will use the new bus number. The actual bus number used by specific objects is i2c_bus_number. |
std::system_error | if /dev cannot be opened. |
std::runtime_error | if the I2C bus cannot be found in /dev. |
Referenced by is_digital().
|
static |
Get the default I2C address for a given type.
Note that several Grove types have multiple addresses. This only returns the first address.
References SG::k3AxisDigitalAccelerometer16g, SG::k3AxisDigitalAccelerometer1_5g, SG::k3AxisDigitalAccelerometer400g, SG::k3AxisDigitalCompass, SG::k3AxisDigitalGyro, SG::k6AxisAccelerometerAndCompassV1, SG::k6AxisAccelerometerAndCompassV2, SG::kBarometerHighAccuracy, SG::kBarometerSensor, SG::kBarometerSensorBMP180, SG::kDigitalInfraredTemperatureSensor, SG::kDigitalLightSensor, SG::kGestureV1, SG::kI2CADC, SG::kI2CColorSensor, SG::kI2CFMReceiver, SG::kI2CMotorDriverV10, SG::kI2CMotorDriverV12, SG::kIMU10DOF, SG::kIMU9DOFV1, SG::kIMU9DOFV2, SG::kLCDRGBBacklight, SG::kMultichannelGasSensor, SG::kNFCTag, SG::kOLEDDisplay0_96, SG::kOLEDDisplay1_12, SG::kQTouchSensor, SG::kRTC, SG::kTemperatureAndHumiditySensor, and SG::kTouchSensor.
|
inline |
Get the address for this Grove type.
References get_address_from_type(), SG::GroveBase::get_type(), read16(), and read8().
Referenced by get_address_from_type(), GroveI2CDigital(), and is_digital().
|
virtualinherited |
Return a multi-word 1-line description of this object.
References SG::demangle(), SG::GroveBase::get_name(), SG::GroveBase::get_sku(), SG::GroveBase::get_type_name(), SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), SG::GroveBase::is_grove_uart(), and SG::BeagleBone::Detect::to_string().
Referenced by buzzer(), chainable_rgb_led(), common_oled(), SG::GroveBase::get_name(), GroveI2CDigital(), read16(), read8(), read_block(), SG::CommonOLED::set_display_bitmap(), SG::CommonOLED::set_orientation(), temperature(), variable_led(), write16(), write8(), write_block(), and write_byte().
|
inlinevirtualinherited |
Return the user-supplied name.
References SG::GroveBase::get_description(), SG::GroveBase::grove_name, SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), and SG::GroveBase::is_grove_uart().
Referenced by SG::GroveBase::get_description(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().
|
inlinevirtualinherited |
Return a guess as to the Seeed SKU number based on the grove type.
References SG::get_sku_from_grove_type(), and SG::GroveBase::grove_type.
Referenced by SG::GroveBase::get_description().
|
inlinevirtualinherited |
Return the grove type.
References SG::GroveBase::grove_type.
Referenced by get_address_from_type(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().
|
inlinevirtualinherited |
Return a short text string representing the grove type.
References SG::GroveBase::grove_type, and SG::to_string().
Referenced by SG::GroveBase::get_description().
|
inlinevirtual |
This is always false
for GroveI2CDigital.
Implements SG::GroveI2C.
|
inlinevirtual |
This is always true
for GroveI2CDigital.
Implements SG::GroveI2C.
References detect_i2c_bus_number(), and get_address_from_type().
|
inlinevirtualinherited |
This is always false
for GroveI2C.
Implements SG::GroveBase.
References SG::GroveI2C::is_analog(), and SG::GroveI2C::is_digital().
|
inlinevirtualinherited |
This is always true
for GroveI2C.
Implements SG::GroveBase.
|
inlinevirtualinherited |
This is always false
for GroveI2C.
Implements SG::GroveBase.
|
inlineinherited |
Test object equality.
References SG::GroveBase::operator==().
|
inherited |
Test object equality.
References SG::GroveBase::get_name(), and SG::GroveBase::get_type().
Referenced by SG::GroveBase::operator!=(), SG::Buzzer::operator==(), SG::TemperatureAndHumiditySensor::operator==(), SG::TemperatureSensor::operator==(), and SG::I2CADC::operator==().
|
inlinevirtual |
Read a 16-bit word from the specified register, but only keep the bottom 12 bits.
Some devices such as the I2CADC return 12-bit values.
References read16(), read_block(), write16(), write8(), write_block(), and write_byte().
Referenced by SG::I2CADC::read12().
|
virtual |
Read a 16-bit word from the specified register.
std::system_error | if the register cannot be read. |
References SG::GroveBase::get_description(), i2c_address, and i2c_file_handle.
Referenced by get_address_from_type(), and read12().
|
virtual |
Read a byte (8 bits) from the specificed register.
std::system_error | if the register cannot be read. |
References SG::GroveBase::get_description(), i2c_address, and i2c_file_handle.
Referenced by get_address_from_type(), SG::ThreeAxisDigitalCompass::get_config(), SG::ThreeAxisDigitalCompass::get_data(), SG::ThreeAxisDigitalCompass::get_mode(), SG::ThreeAxisDigitalCompass::get_status(), and SG::I2CADC::read8().
|
virtual |
Read a consecutive block of bytes, anywhere between 1 and 32 bytes in length.
std::system_error | if the register cannot be read. |
References SG::GroveBase::get_description(), i2c_address, and i2c_file_handle.
Referenced by read12().
|
virtual |
std::system_error | if the value cannot be written. |
References SG::GroveBase::get_description(), i2c_address, and i2c_file_handle.
Referenced by read12(), and SG::I2CADC::write16().
|
virtual |
Write the given value to the specified register.
std::system_error | if the value cannot be written. |
References SG::GroveBase::get_description(), i2c_address, and i2c_file_handle.
Referenced by read12(), SG::ThreeAxisDigitalCompass::set_config(), SG::ThreeAxisDigitalCompass::set_mode(), and SG::I2CADC::write8().
|
virtual |
Write a consecutive block of bytes, anywhere between 1 and 32 bytes in length.
std::length_error | if the block is too long to write. |
std::system_error | if the block failed to write. |
References SG::GroveBase::get_description(), i2c_address, i2c_file_handle, and SG::BeagleBone::Detect::to_string().
Referenced by SG::CommonOLED::flood(), read12(), SG::OLED096::reset(), SG::CommonOLED::send_command(), SG::CommonOLED::set_display_bitmap(), SG::CommonOLED::set_orientation(), and SG::CommonOLED::show().
|
virtual |
Write a consecutive block of bytes directly to the I2C file handle.
std::system_error | if the block failed to write. |
References SG::GroveBase::get_description(), i2c_address, i2c_file_handle, and SG::BeagleBone::Detect::to_string().
|
virtual |
Write a single byte to the I2C bus.
std::system_error | if the value cannot be writen. |
References SG::GroveBase::get_description(), i2c_address, and i2c_file_handle.
Referenced by SG::OLED096::all_off_display(), SG::OLED096::all_on_display(), SG::OLED096::invert_display(), SG::OLED096::normal_display(), read12(), and SG::CommonOLED::set_display_bitmap().
|
inherited |
User-supplied name.
Referenced by SG::GroveBase::get_name(), and SG::GroveBase::operator=().
|
inherited |
Grove type.
Referenced by SG::GroveBase::get_sku(), SG::GroveBase::get_type(), SG::GroveBase::get_type_name(), and SG::GroveBase::operator=().
I2CAddress SG::GroveI2CDigital::i2c_address |
The I2C address used to communicate with the Grove device.
Referenced by GroveI2CDigital(), SG::I2CADC::operator==(), read16(), read8(), read_block(), write16(), write8(), write_block(), and write_byte().
I2CBus SG::GroveI2CDigital::i2c_bus_number |
The bus number to use for I2C Grove twigs.
The exposed I2C bus is usually 1
or 2
. This is normally auto-detected by detect_i2c_bus_number() called by the constructor, and doesn't need to be manually set.
Referenced by GroveI2CDigital().
int SG::GroveI2CDigital::i2c_file_handle |
The file handle to /dev/i2c-* used to communicate with the Grove device.
Referenced by GroveI2CDigital(), read16(), read8(), read_block(), write16(), write8(), write_block(), write_byte(), and ~GroveI2CDigital().