Rework _all_ of the I2C
This moves all of the I2C code to IRQ based (not DMA _yet_). But it does drastically improve reliability, especially of reads.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include <BMA223.hpp>
|
||||
#include "BMA223_defines.h"
|
||||
#include <array>
|
||||
#define BMA223_ADDRESS 0b00110000
|
||||
#define BMA223_ADDRESS 0x18<<1
|
||||
|
||||
bool BMA223::detect() {
|
||||
return FRToSI2C::probe(BMA223_ADDRESS);
|
||||
@@ -16,16 +16,17 @@ bool BMA223::detect() {
|
||||
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
//
|
||||
{ BMA223_PMU_RANGE, 0b0011, 0 }, //2G range
|
||||
{ BMA223_PMU_BW, 0b1101, 0 }, //250Hz filter
|
||||
{ BMA223_PMU_LPW, 0x00, 0 }, //Full power
|
||||
{ BMA223_ACCD_HBW, 0b01000000, 0 }, //filtered data out
|
||||
{ BMA223_INT_OUT_CTRL, 0b1111, 0 }, //interrupt active high and OD to get it hi-z
|
||||
{ BMA223_OFC_CTRL, 0b00000111, 0 }, //High pass en
|
||||
{ BMA223_PMU_RANGE, 0b00000011, 0 }, //2G range
|
||||
{ BMA223_PMU_BW, 0b00001101, 0 }, //250Hz filter
|
||||
{ BMA223_PMU_LPW, 0b00000000, 0 }, //Full power
|
||||
{ BMA223_ACCD_HBW, 0b00000000, 0 }, //filtered data out
|
||||
{ BMA223_INT_OUT_CTRL, 0b00001010, 0 }, //interrupt active low and OD to get it hi-z
|
||||
{ BMA223_INT_RST_LATCH, 0b10000000, 0 }, //interrupt active low and OD to get it hi-z
|
||||
// { BMA223_OFC_CTRL, 0b00000111, 0 }, //High pass en
|
||||
|
||||
//
|
||||
};
|
||||
void BMA223::initalize() {
|
||||
bool BMA223::initalize() {
|
||||
//Setup acceleration readings
|
||||
//2G range
|
||||
//bandwidth = 250Hz
|
||||
@@ -35,19 +36,22 @@ void BMA223::initalize() {
|
||||
// Hysteresis is set to ~ 16 counts
|
||||
//Theta blocking is set to 0b10
|
||||
|
||||
FRToSI2C::writeRegistersBulk(BMA223_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
return FRToSI2C::writeRegistersBulk(BMA223_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
|
||||
}
|
||||
|
||||
void BMA223::getAxisReadings(int16_t& x, int16_t& y, int16_t& z) {
|
||||
//The BMA is odd in that its output data width is only 8 bits
|
||||
//And yet there are MSB and LSB registers _sigh_.
|
||||
uint8_t sensorData[6];
|
||||
uint8_t sensorData[6] = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
FRToSI2C::Mem_Read(BMA223_ADDRESS, BMA223_ACCD_X_LSB, sensorData, 6);
|
||||
if (FRToSI2C::Mem_Read(BMA223_ADDRESS, BMA223_ACCD_X_LSB, sensorData, 6) == false) {
|
||||
x = 0xAAFF;
|
||||
return;
|
||||
}
|
||||
|
||||
x = sensorData[1] << 2;
|
||||
y = sensorData[3] << 2;
|
||||
z = sensorData[5] << 2;
|
||||
x = sensorData[1] << 4;
|
||||
y = sensorData[3] << 4;
|
||||
z = sensorData[5] << 4;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
class BMA223 {
|
||||
public:
|
||||
static bool detect();
|
||||
static void initalize();
|
||||
static bool initalize();
|
||||
//1 = rh, 2,=lh, 8=flat
|
||||
static Orientation getOrientation() {
|
||||
#ifdef ACCEL_ORI_FLIP
|
||||
|
||||
@@ -24,8 +24,8 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { { LIS_CTRL_REG1, 0x17, 0 }, /
|
||||
{ LIS_INT1_THS, 0x28, 0 }, //
|
||||
{ LIS_INT1_DURATION, 64, 0 } };
|
||||
|
||||
void LIS2DH12::initalize() {
|
||||
FRToSI2C::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
bool LIS2DH12::initalize() {
|
||||
return FRToSI2C::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
}
|
||||
|
||||
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
class LIS2DH12 {
|
||||
public:
|
||||
static bool detect();
|
||||
static void initalize();
|
||||
static bool initalize();
|
||||
//1 = rh, 2,=lh, 8=flat
|
||||
static Orientation getOrientation() {
|
||||
#ifdef LIS_ORI_FLIP
|
||||
|
||||
@@ -26,8 +26,8 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { { CTRL_REG2, 0, 0 }, //Nor
|
||||
{ CTRL_REG1, 0x19, 0 } // ODR=12 Hz, Active mode
|
||||
};
|
||||
|
||||
void MMA8652FC::initalize() {
|
||||
FRToSI2C::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
bool MMA8652FC::initalize() {
|
||||
return FRToSI2C::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
//Returns true if this accelerometer is detected
|
||||
static bool detect();
|
||||
//Init any internal state
|
||||
static void initalize();
|
||||
static bool initalize();
|
||||
static Orientation getOrientation(); // Reads the I2C register and returns the orientation (true == left)
|
||||
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user