1
0
forked from me/IronOS

Working auto orientation

This commit is contained in:
Ben V. Brown
2020-09-24 18:06:20 +10:00
parent e38da13306
commit 088516acea
4 changed files with 48 additions and 45 deletions

View File

@@ -107,14 +107,18 @@ void I2C0_EV_IRQHandler(void) {
} }
break; break;
case I2C_TRANSMIT_DATA: case I2C_TRANSMIT_DATA:
if (i2c_nbytes) {
if (i2c_interrupt_flag_get(I2C0, I2C_INT_FLAG_TBE)) { if (i2c_interrupt_flag_get(I2C0, I2C_INT_FLAG_TBE)) {
/* the master sends a data byte */ /* the master sends a data byte */
i2c_data_transmit(I2C0, *i2c_write++); i2c_data_transmit(I2C0, *i2c_write++);
i2c_nbytes--; i2c_nbytes--;
if (RESET == i2c_nbytes) { if (0 == i2c_nbytes) {
i2c_write_process = I2C_STOP; i2c_write_process = I2C_STOP;
} }
} }
} else {
i2c_write_process = I2C_STOP;
}
break; break;
case I2C_STOP: case I2C_STOP:
/* the master sends a stop condition to I2C bus */ /* the master sends a stop condition to I2C bus */
@@ -180,6 +184,7 @@ void I2C0_EV_IRQHandler(void) {
break; break;
case I2C_TRANSMIT_DATA: case I2C_TRANSMIT_DATA:
if (i2c_nbytes > 0) { if (i2c_nbytes > 0) {
if (i2c_interrupt_flag_get(I2C0, I2C_INT_FLAG_RBNE)) {
/* read a byte from the EEPROM */ /* read a byte from the EEPROM */
if (i2c_nbytes == 2) { if (i2c_nbytes == 2) {
/* wait until BTC bit is set */ /* wait until BTC bit is set */
@@ -200,6 +205,7 @@ void I2C0_EV_IRQHandler(void) {
i2c_process_flag = RESET; i2c_process_flag = RESET;
i2c_read_process = I2C_DONE; i2c_read_process = I2C_DONE;
} }
}
} else { } else {
i2c_read_process = I2C_STOP; i2c_read_process = I2C_STOP;
/* the master sends a stop condition to I2C bus */ /* the master sends a stop condition to I2C bus */

View File

@@ -6,9 +6,7 @@
*/ */
#include <BMA223.hpp> #include <BMA223.hpp>
#include "BMA223_defines.h"
#include <array> #include <array>
#define BMA223_ADDRESS 0x18<<1
bool BMA223::detect() { bool BMA223::detect() {
return FRToSI2C::probe(BMA223_ADDRESS); return FRToSI2C::probe(BMA223_ADDRESS);
@@ -22,7 +20,8 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { //
{ BMA223_ACCD_HBW, 0b00000000, 0 }, //filtered data out { 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_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_INT_RST_LATCH, 0b10000000, 0 }, //interrupt active low and OD to get it hi-z
// { BMA223_OFC_CTRL, 0b00000111, 0 }, //High pass en { BMA223_INT_EN_0, 0b01000000, 0 }, //Enable orientation
{ BMA223_INT_A, 0b00100111, 0 }, //Setup orientation detection
// //
}; };

View File

@@ -8,9 +8,8 @@
#ifndef CORE_DRIVERS_BMA223_HPP_ #ifndef CORE_DRIVERS_BMA223_HPP_
#define CORE_DRIVERS_BMA223_HPP_ #define CORE_DRIVERS_BMA223_HPP_
#include "I2C_Wrapper.hpp" #include "I2C_Wrapper.hpp"
#include "LIS2DH12_defines.hpp"
#include "BSP.h" #include "BSP.h"
#include "BMA223_defines.h"
class BMA223 { class BMA223 {
public: public:
@@ -18,21 +17,19 @@ public:
static bool initalize(); static bool initalize();
//1 = rh, 2,=lh, 8=flat //1 = rh, 2,=lh, 8=flat
static Orientation getOrientation() { static Orientation getOrientation() {
#ifdef ACCEL_ORI_FLIP uint8_t val = FRToSI2C::I2C_RegisterRead(BMA223_ADDRESS,
uint8_t val = (FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS, BMA223_INT_STATUS_3);
LIS_INT2_SRC) >> 2); val >>= 4; //we dont need high values
if (val == 8) val &= 0b11;
val = 3; if(val &0b10){
else if (val == 1) return ORIENTATION_FLAT;
val = 1; }else{
else if (val == 2) return static_cast<Orientation>(!val);
val = 0; }
else //0 = rhs
val = 3; //1 =lhs
return static_cast<Orientation>(val); //2 & 3 == ignore
#else
return static_cast<Orientation>((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,LIS_INT2_SRC) >> 2) - 1);
#endif
} }
static void getAxisReadings(int16_t& x, int16_t& y, int16_t& z); static void getAxisReadings(int16_t& x, int16_t& y, int16_t& z);

View File

@@ -8,6 +8,7 @@
#ifndef CORE_DRIVERS_BMA223_DEFINES_H_ #ifndef CORE_DRIVERS_BMA223_DEFINES_H_
#define CORE_DRIVERS_BMA223_DEFINES_H_ #define CORE_DRIVERS_BMA223_DEFINES_H_
#define BMA223_ADDRESS 0x18<<1
#define BMA223_BGW_CHIPID 0x00 #define BMA223_BGW_CHIPID 0x00
#define BMA223_ACCD_X_LSB 0x02 #define BMA223_ACCD_X_LSB 0x02
#define BMA223_ACCD_X_MSB 0x03 #define BMA223_ACCD_X_MSB 0x03