mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
SC7A20 handle address
This commit is contained in:
@@ -9,15 +9,29 @@
|
|||||||
#include <SC7A20_defines.h>
|
#include <SC7A20_defines.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
uint8_t SC7A20::activeAddress;
|
||||||
|
|
||||||
bool SC7A20::detect() {
|
bool SC7A20::detect() {
|
||||||
if (FRToSI2C::probe(SC7A20_ADDRESS)) {
|
if (FRToSI2C::probe(SC7A20_ADDRESS)) {
|
||||||
// Read chip id to ensure its not an address collision
|
// Read chip id to ensure its not an address collision
|
||||||
uint8_t id = 0;
|
uint8_t id = 0;
|
||||||
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_WHO_AMI_I, &id, 1)) {
|
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_WHO_AMI_I, &id, 1)) {
|
||||||
return id == 0b00010001;
|
if (id == SC7A20_WHO_AM_I_VALUE) {
|
||||||
|
activeAddress = SC7A20_ADDRESS;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FRToSI2C::probe(SC7A20_ADDRESS2)) {
|
||||||
|
// Read chip id to ensure its not an address collision
|
||||||
|
uint8_t id = 0;
|
||||||
|
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS2, SC7A20_WHO_AMI_I, &id, 1)) {
|
||||||
|
if (id == SC7A20_WHO_AM_I_VALUE) {
|
||||||
|
activeAddress = SC7A20_ADDRESS2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +64,7 @@ bool SC7A20::initalize() {
|
|||||||
// Hysteresis is set to ~ 16 counts
|
// Hysteresis is set to ~ 16 counts
|
||||||
// Theta blocking is set to 0b10
|
// Theta blocking is set to 0b10
|
||||||
|
|
||||||
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
return FRToSI2C::writeRegistersBulk(activeAddress, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ 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() {
|
||||||
uint8_t val = ((FRToSI2C::I2C_RegisterRead(SC7A20_ADDRESS, SC7A20_INT2_SOURCE) >> 2) - 1);
|
uint8_t val = ((FRToSI2C::I2C_RegisterRead(activeAddress, SC7A20_INT2_SOURCE) >> 2) - 1);
|
||||||
if (val == 1)
|
if (val == 1)
|
||||||
return Orientation::ORIENTATION_LEFT_HAND;
|
return Orientation::ORIENTATION_LEFT_HAND;
|
||||||
else if (val == 4 || val == 0)
|
else if (val == 4 || val == 0)
|
||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static uint8_t activeAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CORE_DRIVERS_BMA223_HPP_ */
|
#endif /* CORE_DRIVERS_BMA223_HPP_ */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* BMA223_defines.h
|
* SC7A20_defines.h
|
||||||
*
|
*
|
||||||
* Created on: 18 Sep. 2020
|
* Created on: 18 Sep. 2020
|
||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
@@ -9,6 +9,10 @@
|
|||||||
#define CORE_DRIVERS_SC7A20_DEFINES_H_
|
#define CORE_DRIVERS_SC7A20_DEFINES_H_
|
||||||
|
|
||||||
#define SC7A20_ADDRESS 0x18 << 1
|
#define SC7A20_ADDRESS 0x18 << 1
|
||||||
|
// Sometimes the SC7A20 turns up programmed to impersonate the LIS2DH12
|
||||||
|
#define SC7A20_ADDRESS2 (25 << 1)
|
||||||
|
|
||||||
|
#define SC7A20_WHO_AM_I_VALUE (0b00010001)
|
||||||
#define SC7A20_WHO_AMI_I 0x0F
|
#define SC7A20_WHO_AMI_I 0x0F
|
||||||
#define SC7A20_CTRL_REG1 0x20
|
#define SC7A20_CTRL_REG1 0x20
|
||||||
#define SC7A20_CTRL_REG2 0x21
|
#define SC7A20_CTRL_REG2 0x21
|
||||||
|
|||||||
Reference in New Issue
Block a user