mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Working auto orientation
This commit is contained in:
@@ -107,13 +107,17 @@ void I2C0_EV_IRQHandler(void) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case I2C_TRANSMIT_DATA:
|
case I2C_TRANSMIT_DATA:
|
||||||
if (i2c_interrupt_flag_get(I2C0, I2C_INT_FLAG_TBE)) {
|
if (i2c_nbytes) {
|
||||||
/* the master sends a data byte */
|
if (i2c_interrupt_flag_get(I2C0, I2C_INT_FLAG_TBE)) {
|
||||||
i2c_data_transmit(I2C0, *i2c_write++);
|
/* the master sends a data byte */
|
||||||
i2c_nbytes--;
|
i2c_data_transmit(I2C0, *i2c_write++);
|
||||||
if (RESET == i2c_nbytes) {
|
i2c_nbytes--;
|
||||||
i2c_write_process = I2C_STOP;
|
if (0 == i2c_nbytes) {
|
||||||
|
i2c_write_process = I2C_STOP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
i2c_write_process = I2C_STOP;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case I2C_STOP:
|
case I2C_STOP:
|
||||||
@@ -180,25 +184,27 @@ void I2C0_EV_IRQHandler(void) {
|
|||||||
break;
|
break;
|
||||||
case I2C_TRANSMIT_DATA:
|
case I2C_TRANSMIT_DATA:
|
||||||
if (i2c_nbytes > 0) {
|
if (i2c_nbytes > 0) {
|
||||||
/* read a byte from the EEPROM */
|
if (i2c_interrupt_flag_get(I2C0, I2C_INT_FLAG_RBNE)) {
|
||||||
if (i2c_nbytes == 2) {
|
/* read a byte from the EEPROM */
|
||||||
/* wait until BTC bit is set */
|
if (i2c_nbytes == 2) {
|
||||||
i2c_ackpos_config(I2C0, I2C_ACKPOS_CURRENT);
|
/* wait until BTC bit is set */
|
||||||
/* clear the ACKEN before the ADDSEND is cleared */
|
i2c_ackpos_config(I2C0, I2C_ACKPOS_CURRENT);
|
||||||
i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
/* clear the ACKEN before the ADDSEND is cleared */
|
||||||
}
|
i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
||||||
*i2c_read = i2c_data_receive(I2C0);
|
}
|
||||||
i2c_read++;
|
*i2c_read = i2c_data_receive(I2C0);
|
||||||
i2c_nbytes--;
|
i2c_read++;
|
||||||
if (i2c_nbytes == 0) {
|
i2c_nbytes--;
|
||||||
/* the master sends a stop condition to I2C bus */
|
if (i2c_nbytes == 0) {
|
||||||
i2c_stop_on_bus(I2C0);
|
/* the master sends a stop condition to I2C bus */
|
||||||
/* disable the I2C0 interrupt */
|
i2c_stop_on_bus(I2C0);
|
||||||
i2c_interrupt_disable(I2C0, I2C_INT_ERR);
|
/* disable the I2C0 interrupt */
|
||||||
i2c_interrupt_disable(I2C0, I2C_INT_BUF);
|
i2c_interrupt_disable(I2C0, I2C_INT_ERR);
|
||||||
i2c_interrupt_disable(I2C0, I2C_INT_EV);
|
i2c_interrupt_disable(I2C0, I2C_INT_BUF);
|
||||||
i2c_process_flag = RESET;
|
i2c_interrupt_disable(I2C0, I2C_INT_EV);
|
||||||
i2c_read_process = I2C_DONE;
|
i2c_process_flag = RESET;
|
||||||
|
i2c_read_process = I2C_DONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i2c_read_process = I2C_STOP;
|
i2c_read_process = I2C_STOP;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
//
|
//
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user