update: added support for IMU and Lottie JSON

This commit is contained in:
2026-01-24 13:50:49 +05:30
parent ecf234efa5
commit 2c731c72e3
868 changed files with 318873 additions and 894 deletions

2
.gitignore vendored
View File

@@ -10,3 +10,5 @@ sdkconfig.old
/.vscode
/.cache
/managed_components
/03_QMI8658
/.github

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
set(src_dirs ./src
./src/touch
./src/platform)
set(include_dirs ./src
./src/REG
./src/touch
./src/platform)
idf_component_register(SRC_DIRS ${src_dirs}
INCLUDE_DIRS ${include_dirs}
REQUIRES esp_timer esp_driver_gpio driver)

View File

@@ -0,0 +1,95 @@
/**
* @file DevicesPins.h
* @author Lewis He (lewishe@outlook.com)
* @license MIT
* @copyright Copyright (c) 2024 ShenZhen XinYuan Electronic Technology Co., Ltd
* @date 2024-09-14
*
*/
#pragma once
#if defined(ARDUINO_T_DECK)
// T-Deck GT911
#define SENSOR_SDA 18
#define SENSOR_SCL 8
#define SENSOR_IRQ 16
#define SENSOR_RST -1
#elif defined(ARDUINO_T_AMOLED_191)
// T-Display-AMOLED 1.91 Inch CST816T✅
#define SENSOR_SDA 3
#define SENSOR_SCL 2
#define SENSOR_IRQ 21
#define SENSOR_RST -1
#elif defined(ARDUINO_T_AMOLED_191_QWIIC)
// T-Display-AMOLED 1.91 Inch QWIIC
#define SENSOR_SDA 3
#define SENSOR_SCL 2
#define SENSOR_IRQ TX
#define SENSOR_RST RX
#elif defined(ARDUINO_T_AMOLED_241)
// T4-S3 CST226SE ✅
#define SENSOR_SDA 6
#define SENSOR_SCL 7
#define SENSOR_IRQ 8
#define SENSOR_RST 17
#elif defined(ARDUINO_T_AMOLED_147)
// T-Display-Lite 1.47 Inch CHSC5816 ✅
#define SENSOR_SDA 1
#define SENSOR_SCL 2
#define SENSOR_IRQ 13
#define SENSOR_RST 14
#elif defined(ARDUINO_T_DISPLAY_S3_PRO)
// T-Display-S3-Pro CST226SE✅
#define SENSOR_SDA 5
#define SENSOR_SCL 6
#define SENSOR_IRQ 7
#define SENSOR_RST 13
#elif defined(ARDUINO_T_DISPLAY_S3)
// T-Display-S3 CST816T✅
#define SENSOR_SDA 18
#define SENSOR_SCL 17
#define SENSOR_IRQ 16
#define SENSOR_RST 21
#elif defined(ARDUINO_T_EPD47_S3)
// T-EPD47 S3 GT911 2 Point touch✅
#define SENSOR_SDA 6
#define SENSOR_SCL 5
#define SENSOR_IRQ 15
#define SENSOR_RST 41
#elif defined(ARDUINO_T_WATCH_S3_U)
// T-Watch-S3-U
#define SENSOR_SDA 2
#define SENSOR_SCL 3
#define SENSOR_IRQ 12
#define SENSOR_RST 16
#endif

View File

@@ -0,0 +1,291 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file ExtensionIOXL9555.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-12-27
*
*/
#pragma once
#include "REG/XL9555Constants.h"
#include "SensorCommon.tpp"
#include "ExtensionSPI.tpp"
typedef void (*gpio_event_t)(void *user_data);
typedef struct ioEvent {
uint8_t mode;
gpio_event_t cb;
void *user_data;
uint8_t last_state;
ioEvent() : mode(0), cb(NULL), user_data(NULL), last_state(LOW)
{
}
} ioEvent_t;
class ExtensionIOXL9555 :
public SensorCommon<ExtensionIOXL9555>,
public ExtensionSPI<ExtensionIOXL9555>
{
friend class SensorCommon<ExtensionIOXL9555>;
friend class ExtensionSPI<ExtensionIOXL9555>;
public:
enum {
PORT0,
PORT1,
};
enum ExtensionGPIO {
IO0,
IO1,
IO2,
IO3,
IO4,
IO5,
IO6,
IO7,
IO8,
IO9,
IO10,
IO11,
IO12,
IO13,
IO14,
IO15,
};
#if defined(ARDUINO)
ExtensionIOXL9555(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = XL9555_UNKOWN_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
ExtensionIOXL9555()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = XL9555_UNKOWN_ADDRESS;
}
~ExtensionIOXL9555()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = XL9555_UNKOWN_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t registers = 0;
if (pin >= IO8) {
pin -= IO8;
registers = XL9555_CTRL_CFG1;
} else {
registers = XL9555_CTRL_CFG0;
}
switch (mode) {
case INPUT:
setRegisterBit(registers, pin);
break;
case OUTPUT:
clrRegisterBit(registers, pin);
break;
default:
break;
}
}
int digitalRead(uint8_t pin)
{
uint8_t registers = 0;
if (pin >= IO8) {
pin -= IO8;
registers = XL9555_CTRL_INP1;
} else {
registers = XL9555_CTRL_INP0;
}
return getRegisterBit(registers, pin);
}
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t registers = 0;
if (pin >= IO8) {
pin -= IO8;
registers = XL9555_CTRL_OUTP1;
} else {
registers = XL9555_CTRL_OUTP0;
}
val ? setRegisterBit(registers, pin) : clrRegisterBit(registers, pin);
}
// Invert gpio
void digitalToggle(uint8_t pin)
{
int state = 1 - digitalRead(pin);
digitalWrite(pin, state);
}
// Read 8-bit gpio input status
int readPort(uint8_t port)
{
return readRegister(port == PORT0 ? XL9555_CTRL_INP0 : XL9555_CTRL_INP1);
}
// Write 8 bits of data to the specified port
int writePort(uint8_t port, uint8_t mask)
{
return writeRegister(port == PORT0 ? XL9555_CTRL_OUTP0 : XL9555_CTRL_OUTP1, mask);
}
// Read 16-bit gpio input status
uint16_t read()
{
uint16_t val = 0x0;
readRegister(XL9555_CTRL_INP0, (uint8_t *)&val, 2);
return val;
}
// Write 16-bit data to gpio, low bit port 0
void write(uint16_t value)
{
uint8_t buffer[2] = {highByte(value), lowByte(value)};
writeRegister(XL9555_CTRL_OUTP0, buffer, 2);
}
// Read the specified port configuration status
int readConfig(uint8_t port)
{
return readRegister(port == PORT0 ? XL9555_CTRL_CFG0 : XL9555_CTRL_CFG1);
}
// Configure the specified port as input or output , 0xFF = all pin input , 0x00 = all pin output
int configPort(uint8_t port, uint8_t mask)
{
return writeRegister(port == PORT0 ? XL9555_CTRL_CFG0 : XL9555_CTRL_CFG1, mask);
}
void setPinEvent(uint8_t pin, uint8_t mode, gpio_event_t event, void *user_data)
{
if (pin > XL9555_MAX_PIN) {
log_e("XL9555 Max use io pin is 0 ~ 15 .");
return;
}
this->event[pin].cb = event;
this->event[pin].mode = mode;
this->event[pin].user_data = user_data;
}
void removePinEvent(uint8_t pin)
{
if (pin > XL9555_MAX_PIN) {
log_e("XL9555 Max use io pin is 0 ~ 15 .");
return;
}
this->event[pin].cb = NULL;
}
void update()
{
uint16_t val = this->read();
int i = XL9555_MAX_PIN;
for (; i >= 0; i--) {
uint8_t _index = XL9555_MAX_PIN - i;
if (this->event[_index].cb != NULL) {
if (!(val & 1)) {
if (this->event[_index].mode == LOW) {
this->event[_index].cb(this->event[_index].user_data);
}
this->event[_index].last_state = LOW;
} else {
if (this->event[_index].mode == HIGH && this->event[_index].last_state == LOW) {
this->event[_index].cb(this->event[_index].user_data);
}
this->event[_index].last_state = HIGH;
}
}
val >>= 1;
}
}
private:
bool initImpl()
{
if (__addr == XL9555_UNKOWN_ADDRESS) {
for (uint8_t addr = XL9555_SLAVE_ADDRESS0; addr <= XL9555_SLAVE_ADDRESS7; ++addr) {
if (probe(addr)) {
log_e("Find the xl9555 chip address is 0x%X", addr);
__addr = addr;
return true;
}
}
log_e("No find the xl9555 chip ...");
return false;
}
return probe();
}
int getReadMaskImpl()
{
return -1;
}
ioEvent_t event[16];
protected:
};

View File

@@ -0,0 +1,124 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file ExtensionSPI.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2024-01-19
*
*/
#pragma once
#include "SensorLib.h"
template <class chipType>
class ExtensionSPI
{
public:
void beginSPI(int mosi,
int miso,
int sck,
int cs
)
{
_mosi = mosi;
_miso = miso;
_sck = sck;
_cs = cs;
thisChip().pinMode(_mosi, OUTPUT);
thisChip().pinMode(_sck, OUTPUT);
if (_cs != SENSOR_PIN_NONE) {
thisChip().pinMode(_cs, OUTPUT);
thisChip().digitalWrite(_cs, HIGH);
}
if (_miso != SENSOR_PIN_NONE) {
thisChip().pinMode(_miso, INPUT);
}
thisChip().digitalWrite(_mosi, HIGH);
thisChip().digitalWrite(_sck, HIGH);
}
void setBitOrder(uint8_t order)
{
_order = order & 1;
}
uint8_t transfer8(uint8_t val)
{
return transferDataBits(val, 8);
}
uint16_t transfer9(uint16_t val)
{
return transferDataBits(val, 9);
}
uint32_t transferDataBits(uint32_t val, uint32_t bits)
{
uint32_t mask = _BV(bits - 1);
uint8_t out = 0;
if (_cs != SENSOR_PIN_NONE) {
thisChip().digitalWrite(_cs, LOW);
}
for (int i = 0; i < bits ; i++) {
thisChip().digitalWrite(_sck, LOW);
out <<= 1;
if (_miso != SENSOR_PIN_NONE) {
if (thisChip().digitalRead(_miso)) {
out |= 0x01;
}
}
thisChip().digitalWrite(_mosi, val & mask ? HIGH : LOW);
val <<= 1;
thisChip().digitalWrite(_sck, HIGH);
}
if (_cs != SENSOR_PIN_NONE) {
thisChip().digitalWrite(_cs, HIGH);
}
return out;
}
protected:
inline const chipType &thisChip() const
{
return static_cast<const chipType &>(*this);
}
inline chipType &thisChip()
{
return static_cast<chipType &>(*this);
}
private:
int _mosi;
int _sck;
int _miso;
int _order;
int _cs;
};

View File

@@ -0,0 +1,726 @@
#pragma once
#define BMA423_SLAVE_ADDRESS (0x19)
#define BAM423_SENSOR_RESOLUTION (12)
#define BMA423_RESET_REG (0x7E)
/**\name CHIP ID ADDRESS*/
#define BMA4_CHIP_ID_ADDR (0x00)
/**\name Chip ID of BMA423 sensor */
#define BMA423_CHIP_ID (0x13)
/**\name POWER_CTRL REGISTER*/
#define BMA4_POWER_CONF_ADDR (0x7C)
#define BMA4_POWER_CTRL_ADDR (0x7D)
/**\name ADVANCE POWER SAVE POSITION AND MASK*/
#define BMA4_ADVANCE_POWER_SAVE_MSK (0x01)
/**\name MAP INTERRUPT 1 and 2 REGISTERS*/
#define BMA4_INT_MAP_1_ADDR (0X56)
#define BMA4_INT_MAP_2_ADDR (0X57)
#define BMA4_INT_MAP_DATA_ADDR (0x58)
#define BMA4_INIT_CTRL_ADDR (0x59)
/**\name FEATURE CONFIG RELATED */
#define BMA4_RESERVED_REG_5B_ADDR (0x5B)
#define BMA4_RESERVED_REG_5C_ADDR (0x5C)
#define BMA4_FEATURE_CONFIG_ADDR (0x5E)
#define BMA4_INTERNAL_ERROR (0x5F)
/**\name GPIO REGISTERS*/
#define BMA4_STEP_CNT_OUT_0_ADDR (0x1E)
#define BMA4_HIGH_G_OUT_ADDR (0x1F)
#define BMA4_ACTIVITY_OUT_ADDR (0x27)
#define BMA4_ORIENTATION_OUT_ADDR (0x28)
#define BMA4_INTERNAL_STAT (0x2A)
/**\name SENSOR TIME REGISTERS*/
#define BMA4_SENSORTIME_0_ADDR (0X18)
/**\name INTERRUPT/FEATURE STATUS REGISTERS*/
#define BMA4_INT_STAT_0_ADDR (0X1C)
/**\name INTERRUPT/FEATURE STATUS REGISTERS*/
#define BMA4_INT_STAT_1_ADDR (0X1D)
/**\name BUS READ AND WRITE LENGTH FOR MAG & ACCEL*/
#define BMA4_MAG_TRIM_DATA_SIZE (16)
#define BMA4_MAG_XYZ_DATA_LENGTH (6)
#define BMA4_MAG_XYZR_DATA_LENGTH (8)
#define BMA4_ACCEL_DATA_LENGTH (6)
#define BMA4_FIFO_DATA_LENGTH (2)
#define BMA4_TEMP_DATA_SIZE (1)
/**\name AUX/ACCEL DATA BASE ADDRESS REGISTERS*/
#define BMA4_DATA_0_ADDR (0X0A)
#define BMA4_DATA_8_ADDR (0X12)
/**\name Feature offset address */
#define BMA423_ANY_NO_MOTION_OFFSET (0x00)
#define BMA423_STEP_CNTR_OFFSET (0x36)
#define BMA423_STEP_CNTR_PARAM_OFFSET (0x04)
#define BMA423_WAKEUP_OFFSET (0x38)
#define BMA423_TILT_OFFSET (0x3A)
#define BMA423_CONFIG_ID_OFFSET (0x3C)
#define BMA423_AXES_REMAP_OFFSET (0x3E)
/**\name Sensor feature size */
#define BMA423_FEATURE_SIZE (64)
#define BMA423_ANYMOTION_EN_LEN (2)
#define BMA423_RD_WR_MIN_LEN (2)
/**************************************************************/
/**\name Remap Axes */
/**************************************************************/
#define BMA423_X_AXIS_MASK (0x03)
#define BMA423_X_AXIS_SIGN_MASK (0x04)
#define BMA423_Y_AXIS_MASK (0x18)
#define BMA423_Y_AXIS_SIGN_MASK (0x20)
#define BMA423_Z_AXIS_MASK (0xC0)
#define BMA423_Z_AXIS_SIGN_MASK (0x01)
/**\name ACCELEROMETER ENABLE POSITION AND MASK*/
#define BMA4_ACCEL_ENABLE_MSK (0x04)
#define BMA4_ASIC_INITIALIZED (0x01)
#define BMA4_CONFIG_STREAM_SIZE (6144)
/**\name Feature configuration file */
static const unsigned char bma423_config_file[] = {
0x80, 0x2e, 0xfc, 0x00, 0x80, 0x2e, 0xfe, 0x00, 0xc8, 0x2e, 0x00, 0x2e,
0x80, 0x2e, 0xfa, 0x00, 0x80, 0x2e, 0x23, 0xb1, 0x80, 0x2e, 0xfd, 0x00,
0x80, 0x2e, 0xfb, 0x00, 0x80, 0x2e, 0x5a, 0xb1, 0x50, 0x39, 0x21, 0x2e,
0xb0, 0xf0, 0x10, 0x30, 0x21, 0x2e, 0x16, 0xf0, 0x80, 0x2e, 0xfc, 0x01,
0x5d, 0x50, 0x45, 0x52, 0x01, 0x42, 0x3b, 0x80, 0x41, 0x30, 0x01, 0x42,
0x3c, 0x80, 0x00, 0x2e, 0x01, 0x40, 0x01, 0x42, 0x21, 0x2e, 0xff, 0xaf,
0xb8, 0x2e, 0xb6, 0xd6, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0xfd, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x24, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x2e,
0x99, 0x01, 0x20, 0x26, 0x98, 0x2e, 0xf6, 0x00, 0x98, 0x2e, 0xe9, 0x01,
0x10, 0x30, 0x21, 0x2e, 0x59, 0xf0, 0x98, 0x2e, 0xd8, 0x00, 0x00, 0x2e,
0x00, 0x2e, 0xd0, 0x2e, 0x98, 0x2e, 0xdd, 0x00, 0x01, 0x2e, 0x56, 0x00,
0x00, 0xb2, 0x11, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0x56, 0x00, 0x41, 0x50,
0x98, 0x2e, 0xcc, 0xb0, 0x41, 0x50, 0x98, 0x2e, 0x8f, 0xb4, 0x01, 0x2e,
0x03, 0xf0, 0x0d, 0xbc, 0x0f, 0xb8, 0x00, 0x90, 0x02, 0x2f, 0x45, 0x50,
0x21, 0x2e, 0xbc, 0xf0, 0x01, 0x2e, 0x55, 0x00, 0x00, 0xb2, 0x1a, 0x2f,
0x00, 0x30, 0x21, 0x2e, 0x55, 0x00, 0x43, 0x50, 0x98, 0x2e, 0xcc, 0xb0,
0x43, 0x50, 0x98, 0x2e, 0xdc, 0xb1, 0x43, 0x50, 0x98, 0x2e, 0x92, 0xb5,
0x43, 0x50, 0x98, 0x2e, 0x00, 0xb0, 0x01, 0x2e, 0x1c, 0x01, 0x0f, 0xbc,
0x0f, 0xb8, 0x00, 0x90, 0x45, 0x50, 0x02, 0x2f, 0x21, 0x2e, 0xbc, 0xf0,
0x02, 0x2d, 0x21, 0x2e, 0xba, 0xf0, 0x98, 0x2e, 0xd8, 0x00, 0xc3, 0x2d,
0x01, 0x2e, 0x55, 0xf0, 0xc0, 0x2e, 0x21, 0x2e, 0x55, 0xf0, 0x03, 0x2e,
0x00, 0xf0, 0x45, 0x54, 0x01, 0x2e, 0x59, 0xf0, 0x4a, 0x0e, 0x02, 0x2f,
0xf1, 0x33, 0x0d, 0x2c, 0x01, 0x08, 0xf2, 0x30, 0x4a, 0x08, 0x79, 0x84,
0x82, 0xa2, 0x04, 0x2f, 0x02, 0x34, 0x82, 0x0a, 0x47, 0xa2, 0x03, 0x2c,
0x10, 0x22, 0x45, 0x52, 0x01, 0x0a, 0xc0, 0x2e, 0x21, 0x2e, 0x59, 0xf0,
0x00, 0x31, 0xc0, 0x2e, 0x21, 0x2e, 0xba, 0xf0, 0xc8, 0x2e, 0xc8, 0x2e,
0xc8, 0x2e, 0xc8, 0x2e, 0xc8, 0x2e, 0x44, 0x47, 0xaa, 0x00, 0x05, 0x00,
0x2d, 0x01, 0xd4, 0x7b, 0x3b, 0x01, 0xdb, 0x7a, 0x04, 0x00, 0x3f, 0x7b,
0xcd, 0x6c, 0xc3, 0x04, 0x85, 0x09, 0xc3, 0x04, 0xec, 0xe6, 0x0c, 0x46,
0x01, 0x00, 0x27, 0x00, 0x19, 0x00, 0x96, 0x00, 0xa0, 0x00, 0x01, 0x00,
0x0c, 0x00, 0xf0, 0x3c, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00,
0x0e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x43, 0x28, 0x88, 0x00,
0x52, 0x00, 0x4f, 0x00, 0x80, 0x00, 0x5b, 0x00, 0x00, 0x40, 0xaf, 0x00,
0xff, 0x00, 0xff, 0xb7, 0x00, 0x02, 0x00, 0xb0, 0x05, 0x80, 0xb1, 0xf0,
0xc0, 0x00, 0x00, 0x01, 0x5e, 0xf0, 0x39, 0xf0, 0x89, 0xf0, 0x00, 0x20,
0xff, 0x7f, 0x7d, 0x00, 0x5e, 0x00, 0x62, 0x00, 0x7c, 0x00, 0xff, 0xfb,
0x52, 0xf0, 0x56, 0xf0, 0x33, 0x09, 0x33, 0x07, 0x00, 0x08, 0x90, 0x01,
0x00, 0xf8, 0x67, 0x00, 0x4c, 0x04, 0xa0, 0x00, 0xe8, 0x03, 0x81, 0x00,
0x82, 0x00, 0x6a, 0x00, 0x6d, 0x00, 0x6c, 0x00, 0xeb, 0x07, 0xae, 0x07,
0x72, 0x00, 0x6f, 0x00, 0xa1, 0x01, 0x1e, 0x05, 0x47, 0xfd, 0x73, 0x00,
0x77, 0x00, 0x79, 0x00, 0x76, 0x00, 0xcc, 0x00, 0x30, 0x50, 0x50, 0x40,
0x00, 0x18, 0x50, 0x40, 0x56, 0x25, 0x47, 0x25, 0x00, 0x18, 0x2e, 0x00,
0x41, 0x40, 0xa7, 0x02, 0x09, 0x18, 0xc6, 0x00, 0xfb, 0x7f, 0x00, 0x30,
0x49, 0x52, 0x05, 0x30, 0x05, 0x2c, 0x17, 0x03, 0x1e, 0xbd, 0xd2, 0xba,
0x92, 0xb8, 0x6a, 0x0b, 0x61, 0x0e, 0xf9, 0x2f, 0x61, 0x1a, 0x01, 0x2f,
0x5d, 0x0e, 0xf5, 0x2f, 0xd4, 0x7f, 0x02, 0x30, 0x1f, 0x2c, 0xe3, 0x7f,
0x85, 0x01, 0xd1, 0x03, 0x7c, 0x0e, 0x03, 0x2f, 0x7c, 0x1a, 0x0f, 0x2f,
0x73, 0x0f, 0x0d, 0x2f, 0xe3, 0x6f, 0xde, 0x04, 0x5f, 0xba, 0x11, 0xbf,
0xb4, 0x0b, 0xd4, 0x6f, 0x27, 0x07, 0xb3, 0x25, 0xd1, 0xbf, 0xeb, 0x7f,
0x07, 0x00, 0xb4, 0x25, 0x96, 0x02, 0xdb, 0x7f, 0x2f, 0xbf, 0x9e, 0xbf,
0x01, 0xb8, 0xd2, 0xba, 0x21, 0xb9, 0x92, 0xb8, 0x06, 0x0a, 0x6f, 0x0b,
0x40, 0x90, 0xdf, 0x2f, 0x40, 0x91, 0xdd, 0x2f, 0xfb, 0x6f, 0xd0, 0x5f,
0xb8, 0x2e, 0x57, 0x50, 0x41, 0x30, 0x02, 0x40, 0x51, 0x0a, 0x01, 0x42,
0x18, 0x82, 0x4b, 0x50, 0x60, 0x42, 0x70, 0x3c, 0x4d, 0x54, 0x42, 0x42,
0x69, 0x82, 0x82, 0x32, 0x43, 0x40, 0x18, 0x08, 0x02, 0x0a, 0x40, 0x42,
0x42, 0x80, 0x02, 0x3f, 0x01, 0x40, 0x10, 0x50, 0x4a, 0x08, 0xfb, 0x7f,
0x11, 0x42, 0x0b, 0x31, 0x0b, 0x42, 0x3e, 0x80, 0x01, 0x32, 0x01, 0x42,
0x00, 0x2e, 0x01, 0x2e, 0x40, 0xf0, 0x13, 0x90, 0x20, 0x2f, 0x03, 0x30,
0x51, 0x50, 0x4f, 0x54, 0xf4, 0x34, 0x06, 0x30, 0x55, 0x52, 0x55, 0x32,
0x1d, 0x1a, 0xe3, 0x22, 0x18, 0x1a, 0x53, 0x58, 0xe3, 0x22, 0x04, 0x30,
0xd5, 0x40, 0xb5, 0x0d, 0xe1, 0xbe, 0x6f, 0xbb, 0x80, 0x91, 0xa9, 0x0d,
0x01, 0x89, 0xb5, 0x23, 0x10, 0xa1, 0xf7, 0x2f, 0xda, 0x0e, 0xf4, 0x34,
0xeb, 0x2f, 0x01, 0x2e, 0x25, 0x00, 0x70, 0x1a, 0x00, 0x30, 0x21, 0x30,
0x02, 0x2c, 0x08, 0x22, 0x30, 0x30, 0x00, 0xb2, 0x06, 0x2f, 0x21, 0x2e,
0x59, 0xf0, 0x98, 0x2e, 0xd8, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e,
0xfb, 0x6f, 0xf0, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0xb1, 0xf0, 0x59, 0x52,
0x01, 0x0a, 0x21, 0x2e, 0xb1, 0xf0, 0x01, 0x2e, 0x1c, 0x01, 0x0f, 0xbc,
0x0f, 0xb8, 0x00, 0x90, 0x45, 0x50, 0x02, 0x2f, 0xc0, 0x2e, 0x21, 0x2e,
0xbc, 0xf0, 0xc0, 0x2e, 0x21, 0x2e, 0xba, 0xf0, 0x1a, 0x24, 0x26, 0x00,
0x80, 0x2e, 0x8f, 0x00, 0x03, 0x2e, 0x01, 0x01, 0x05, 0x2e, 0x01, 0x01,
0x92, 0xbd, 0x20, 0x50, 0x03, 0x2e, 0x01, 0x01, 0xbf, 0xba, 0x21, 0xbd,
0x2f, 0xbb, 0x1f, 0xba, 0x40, 0x91, 0xf0, 0x7f, 0x04, 0x2f, 0x80, 0x91,
0x02, 0x2f, 0x00, 0xb3, 0x90, 0x2e, 0xc7, 0xb0, 0x03, 0x2e, 0x7b, 0x00,
0x01, 0x80, 0x40, 0x90, 0x14, 0x2f, 0x41, 0x84, 0xf1, 0x6f, 0x25, 0x2e,
0x7b, 0x00, 0x41, 0x40, 0x23, 0x2e, 0x5a, 0x00, 0x47, 0x52, 0x12, 0x40,
0x52, 0x42, 0x02, 0x30, 0x00, 0x40, 0x40, 0x42, 0xe0, 0x5f, 0x25, 0x2e,
0x57, 0x00, 0x25, 0x2e, 0x58, 0x00, 0x25, 0x2e, 0x5d, 0x00, 0xb8, 0x2e,
0x07, 0x2e, 0x00, 0x01, 0x03, 0x2e, 0x01, 0x01, 0x05, 0x2e, 0x00, 0x01,
0x24, 0xbd, 0x0f, 0x2e, 0x59, 0x00, 0xb5, 0xbd, 0x93, 0xbc, 0x2f, 0xb9,
0xb5, 0xb9, 0x93, 0xb8, 0x3a, 0x1a, 0x06, 0x2f, 0x07, 0x30, 0x25, 0x2e,
0x59, 0x00, 0x2f, 0x2e, 0x57, 0x00, 0x2f, 0x2e, 0x58, 0x00, 0x40, 0xb3,
0x05, 0x30, 0x07, 0x30, 0x0a, 0x2f, 0xf7, 0x6f, 0xe6, 0x7f, 0x00, 0x2e,
0xc6, 0x41, 0x0f, 0x2e, 0x5a, 0x00, 0xb7, 0x05, 0x80, 0xa9, 0xee, 0x05,
0xf7, 0x23, 0xe6, 0x6f, 0x80, 0xb3, 0x06, 0x30, 0x09, 0x2f, 0xe7, 0x7f,
0x00, 0x2e, 0x06, 0x40, 0x0f, 0x2e, 0x5b, 0x00, 0xb7, 0x05, 0x80, 0xa9,
0xee, 0x05, 0xb7, 0x23, 0xe7, 0x6f, 0x00, 0xb3, 0x04, 0x30, 0x0b, 0x2f,
0xf4, 0x6f, 0x02, 0x89, 0xe7, 0x7f, 0x00, 0x2e, 0x04, 0x41, 0x0f, 0x2e,
0x5c, 0x00, 0x27, 0x05, 0x00, 0xa9, 0xec, 0x05, 0x27, 0x23, 0xe7, 0x6f,
0x7b, 0x0f, 0x17, 0x30, 0x0b, 0x2f, 0x73, 0x0f, 0x05, 0x30, 0x17, 0x30,
0x07, 0x2f, 0x63, 0x0f, 0x15, 0x30, 0x17, 0x30, 0x00, 0x2f, 0x07, 0x30,
0xe3, 0x0e, 0x00, 0x2f, 0x05, 0x30, 0x80, 0x90, 0x05, 0x2e, 0x57, 0x00,
0x13, 0x30, 0x13, 0x29, 0xf2, 0x6f, 0x47, 0x5c, 0x17, 0x2f, 0xc0, 0x91,
0x05, 0x30, 0x0b, 0x2f, 0x07, 0x2e, 0x58, 0x00, 0xc1, 0x86, 0x2b, 0x2e,
0x57, 0x00, 0x59, 0x0e, 0x27, 0x2e, 0x58, 0x00, 0x24, 0x2f, 0x2b, 0x2e,
0x5d, 0x00, 0x22, 0x2d, 0x61, 0x0e, 0x29, 0x2e, 0x57, 0x00, 0x2b, 0x2e,
0x58, 0x00, 0x1b, 0x2f, 0x27, 0x2e, 0x5d, 0x00, 0x19, 0x2d, 0x40, 0x91,
0x05, 0x2f, 0x01, 0x30, 0x23, 0x2e, 0x57, 0x00, 0x23, 0x2e, 0x5d, 0x00,
0x06, 0x2d, 0x29, 0x2e, 0x57, 0x00, 0x61, 0x0e, 0x01, 0x2f, 0x27, 0x2e,
0x5d, 0x00, 0x81, 0x40, 0x23, 0x2e, 0x5a, 0x00, 0x30, 0x25, 0x47, 0x52,
0xd4, 0x40, 0x54, 0x42, 0x00, 0x2e, 0xc3, 0x40, 0x43, 0x42, 0x00, 0x2e,
0x03, 0x2e, 0x5d, 0x00, 0x40, 0xb2, 0x0d, 0x2f, 0x81, 0x40, 0x23, 0x2e,
0x5a, 0x00, 0x11, 0x40, 0x91, 0x43, 0x01, 0x34, 0x00, 0x40, 0x80, 0x43,
0x23, 0x2e, 0x5e, 0xf0, 0x03, 0x2d, 0x00, 0x30, 0x21, 0x2e, 0x7b, 0x00,
0xe0, 0x5f, 0xb8, 0x2e, 0x50, 0x50, 0xf0, 0x7f, 0x1a, 0x25, 0x13, 0x40,
0x7b, 0x84, 0xe0, 0x7f, 0x83, 0x42, 0x35, 0x30, 0x11, 0x40, 0x04, 0x40,
0xc1, 0x7f, 0xd4, 0x7f, 0x86, 0x31, 0x07, 0x2e, 0x59, 0xf0, 0x03, 0x2e,
0x1f, 0x01, 0x0d, 0x09, 0x02, 0xab, 0x05, 0x30, 0x8e, 0x09, 0x2c, 0x23,
0xe3, 0xba, 0x42, 0xab, 0x16, 0x30, 0x75, 0x23, 0x59, 0x5c, 0x8e, 0x09,
0x66, 0xbb, 0x82, 0xab, 0x27, 0x30, 0xbe, 0x23, 0x3e, 0x80, 0x25, 0x1a,
0x06, 0x2f, 0x2e, 0x1a, 0x04, 0x2f, 0x26, 0x1a, 0x02, 0x2f, 0xf7, 0x3d,
0x03, 0x2c, 0xdf, 0x08, 0x07, 0x32, 0xdf, 0x0a, 0x14, 0x01, 0x55, 0x01,
0x04, 0x41, 0x14, 0x42, 0x16, 0x01, 0x42, 0x41, 0x45, 0x30, 0x4d, 0x09,
0x04, 0x41, 0x12, 0x42, 0x04, 0x42, 0x40, 0xb3, 0x04, 0x2f, 0xf0, 0x6f,
0x02, 0x30, 0x04, 0x40, 0x94, 0x04, 0x02, 0x42, 0x00, 0x32, 0x08, 0x08,
0x00, 0xb2, 0x00, 0x30, 0x05, 0x2f, 0xe2, 0x6f, 0x00, 0x2e, 0x84, 0x40,
0x04, 0x05, 0x84, 0x42, 0x00, 0x2e, 0x5b, 0x54, 0x4a, 0x08, 0x40, 0xb2,
0xf1, 0x6f, 0x04, 0x2f, 0x42, 0x82, 0x00, 0x2e, 0x42, 0x40, 0x02, 0x04,
0x40, 0x42, 0xb0, 0x5f, 0x27, 0x2e, 0x59, 0xf0, 0xb8, 0x2e, 0x50, 0x50,
0xf7, 0x7f, 0x00, 0x2e, 0x0f, 0x2e, 0xb8, 0xf0, 0xf8, 0xbf, 0xff, 0xbb,
0xc0, 0xb3, 0x2a, 0x2f, 0x0f, 0x2e, 0x01, 0xf0, 0xfe, 0xbf, 0xe6, 0x7f,
0x7e, 0xbb, 0xd5, 0x7f, 0x37, 0x30, 0x5f, 0x5a, 0xbe, 0x05, 0x67, 0x41,
0xc4, 0x7f, 0x78, 0xbe, 0x47, 0x41, 0x27, 0x0b, 0xb3, 0x7f, 0xe6, 0x11,
0x41, 0x56, 0x43, 0x89, 0xd7, 0x42, 0x00, 0x2e, 0x27, 0x41, 0x05, 0x41,
0xf8, 0xbf, 0x7d, 0x0b, 0x6e, 0x11, 0x03, 0x8f, 0xd5, 0x42, 0x14, 0x30,
0xe5, 0x41, 0xc7, 0x41, 0xd8, 0xbe, 0x6f, 0x0b, 0x6e, 0x11, 0xc5, 0x42,
0x29, 0x2e, 0x56, 0x00, 0x45, 0x56, 0x27, 0x2e, 0xb8, 0xf0, 0xe6, 0x6f,
0xd5, 0x6f, 0xc4, 0x6f, 0xb3, 0x6f, 0xf7, 0x6f, 0xb0, 0x5f, 0xc8, 0x2e,
0x50, 0x50, 0xe5, 0x7f, 0xd7, 0x7f, 0xf6, 0x7f, 0x36, 0x30, 0x0b, 0x2e,
0x01, 0xf0, 0xde, 0xbe, 0xde, 0xbb, 0x61, 0x5a, 0xb7, 0x05, 0x67, 0x41,
0xc4, 0x7f, 0x78, 0xbe, 0x47, 0x41, 0x27, 0x0b, 0xb3, 0x7f, 0xe6, 0x11,
0x43, 0x56, 0x43, 0x89, 0xd7, 0x42, 0x00, 0x2e, 0x27, 0x41, 0x05, 0x41,
0xf8, 0xbf, 0x7d, 0x0b, 0x6e, 0x11, 0x03, 0x8f, 0xd5, 0x42, 0x14, 0x30,
0xe5, 0x41, 0xc7, 0x41, 0xd8, 0xbe, 0x6f, 0x0b, 0x6e, 0x11, 0xc5, 0x42,
0x29, 0x2e, 0x55, 0x00, 0x03, 0x31, 0x27, 0x2e, 0xb8, 0xf0, 0xf6, 0x6f,
0xe5, 0x6f, 0xd7, 0x6f, 0xc4, 0x6f, 0xb3, 0x6f, 0xb0, 0x5f, 0xc8, 0x2e,
0x40, 0x50, 0xf6, 0x7f, 0x1a, 0x18, 0x63, 0x56, 0x33, 0x00, 0x06, 0x30,
0xfe, 0x03, 0x0e, 0xb8, 0xf2, 0xbf, 0x07, 0x0a, 0x2a, 0x18, 0x63, 0x5a,
0xb5, 0x01, 0x03, 0x30, 0xfb, 0x03, 0x6e, 0xbb, 0xf2, 0xbf, 0xe1, 0x7f,
0xf7, 0x0b, 0x56, 0x40, 0x36, 0x25, 0x46, 0x40, 0x06, 0x28, 0xc7, 0x7f,
0x22, 0x18, 0xd1, 0x7f, 0xb5, 0x00, 0x01, 0x30, 0x39, 0x03, 0x2e, 0xb9,
0x42, 0xbe, 0x14, 0x0b, 0xf2, 0x6f, 0x10, 0x18, 0xb5, 0x00, 0xb9, 0x03,
0x2e, 0xb9, 0x62, 0xbf, 0x96, 0x0a, 0xb6, 0x6f, 0x30, 0x18, 0x75, 0x01,
0xb9, 0x03, 0x5c, 0x28, 0xe2, 0xbf, 0xde, 0xb9, 0xd6, 0x6f, 0xdf, 0x0a,
0x8a, 0x28, 0xc4, 0x6f, 0x82, 0x43, 0x23, 0x29, 0xe5, 0x6f, 0xc0, 0x2e,
0x44, 0x43, 0xc0, 0x5f, 0x40, 0x50, 0xd0, 0x7f, 0x4a, 0x17, 0x00, 0x40,
0x01, 0x18, 0x46, 0x25, 0x07, 0x25, 0x65, 0x56, 0xd9, 0x04, 0x53, 0x18,
0xeb, 0x18, 0x05, 0x30, 0x49, 0x16, 0x69, 0x06, 0xca, 0x18, 0xa6, 0x00,
0xc7, 0x02, 0x65, 0x58, 0xcb, 0x7f, 0x98, 0x2e, 0x7f, 0xb6, 0xcb, 0x6f,
0xd2, 0x6f, 0xc0, 0x2e, 0x80, 0x42, 0xc0, 0x5f, 0x09, 0x2e, 0x1b, 0x01,
0x05, 0x2e, 0x1b, 0x01, 0xa3, 0xbc, 0x44, 0xbe, 0x90, 0x50, 0x4f, 0xb9,
0x07, 0x2e, 0x1b, 0x01, 0x4a, 0x25, 0x9f, 0xb8, 0x39, 0x8f, 0xb2, 0xbd,
0xf2, 0x7f, 0xbf, 0xb9, 0xeb, 0x7f, 0x8a, 0x0a, 0x37, 0x89, 0x0b, 0x30,
0x93, 0x0a, 0x8b, 0x7f, 0xcb, 0x43, 0x0b, 0x43, 0x80, 0xb2, 0xd3, 0x7f,
0xc1, 0x7f, 0x90, 0x2e, 0x87, 0xb2, 0x20, 0x25, 0x01, 0x2e, 0x64, 0x00,
0x01, 0x90, 0x0e, 0x2f, 0x67, 0x52, 0x01, 0x2e, 0x61, 0x00, 0xb4, 0x7f,
0xa2, 0x7f, 0x98, 0x2e, 0x8d, 0xb2, 0x00, 0x30, 0x21, 0x2e, 0x64, 0x00,
0xc1, 0x6f, 0xd3, 0x6f, 0xa2, 0x6f, 0xb4, 0x6f, 0x0b, 0x30, 0x01, 0x2e,
0x1b, 0x01, 0x06, 0xbc, 0x06, 0xbb, 0x57, 0x25, 0x01, 0x2e, 0x1b, 0x01,
0x94, 0xb1, 0x05, 0xbc, 0xb6, 0x7f, 0x0f, 0xbb, 0x6b, 0x50, 0x80, 0xb3,
0x0f, 0x2f, 0x0d, 0x2e, 0x1b, 0x01, 0x6f, 0x5e, 0xb7, 0x09, 0x2d, 0x2e,
0x1b, 0x01, 0x71, 0x5c, 0x69, 0x5e, 0x9b, 0x43, 0x9b, 0x43, 0xdb, 0x43,
0x9b, 0x43, 0x1b, 0x42, 0xcb, 0x43, 0x0b, 0x42, 0x8b, 0x43, 0x40, 0xb2,
0x05, 0x2f, 0x69, 0x50, 0x00, 0x2e, 0x16, 0x40, 0x0b, 0x40, 0x76, 0x7f,
0x8b, 0x7f, 0xcb, 0x0a, 0x01, 0x2e, 0x61, 0x00, 0x67, 0x52, 0x6d, 0x5c,
0x98, 0x2e, 0xd3, 0xb2, 0x90, 0x6f, 0x00, 0xb2, 0x0b, 0x2f, 0xf0, 0x6f,
0x00, 0xb2, 0x08, 0x2f, 0x69, 0x58, 0x6b, 0x50, 0x12, 0x41, 0x12, 0x42,
0x21, 0x30, 0x04, 0x41, 0x04, 0x42, 0x23, 0x2e, 0x5e, 0xf0, 0xc0, 0x6f,
0x00, 0xb2, 0x26, 0x2f, 0x74, 0x6f, 0x80, 0x6f, 0x71, 0x54, 0x88, 0xbd,
0xc8, 0xb8, 0x4b, 0x0a, 0x94, 0x42, 0x91, 0x42, 0x90, 0x42, 0x88, 0xba,
0x69, 0x52, 0xf3, 0x6f, 0x54, 0x42, 0x85, 0x42, 0xc0, 0x90, 0x40, 0x42,
0x15, 0x2f, 0x6b, 0x52, 0x00, 0x2e, 0x52, 0x40, 0x41, 0x40, 0xa2, 0x04,
0x41, 0x06, 0x40, 0xaa, 0x04, 0x2f, 0x40, 0x90, 0x0b, 0x2f, 0xb1, 0x6f,
0x4a, 0x0f, 0x08, 0x2f, 0xb2, 0x6f, 0x80, 0xb2, 0x05, 0x2f, 0x6b, 0x54,
0x21, 0x30, 0x94, 0x42, 0x80, 0x42, 0x23, 0x2e, 0x5e, 0xf0, 0xd0, 0x6f,
0x00, 0xb2, 0x13, 0x2f, 0x01, 0x2e, 0x60, 0x00, 0x09, 0x2e, 0x7c, 0x00,
0x04, 0x1a, 0x0d, 0x2f, 0x73, 0x50, 0x29, 0x2e, 0x60, 0x00, 0x24, 0x42,
0x44, 0x30, 0x02, 0x40, 0x02, 0x42, 0x09, 0x80, 0x00, 0x2e, 0x04, 0x42,
0x03, 0x2d, 0x10, 0x30, 0x21, 0x2e, 0x64, 0x00, 0xeb, 0x6f, 0x70, 0x5f,
0xb8, 0x2e, 0x09, 0x86, 0x49, 0x54, 0xe4, 0x40, 0xc3, 0x80, 0x94, 0x04,
0xc3, 0x40, 0x13, 0x05, 0x05, 0x40, 0x25, 0x05, 0x8a, 0x17, 0x73, 0x30,
0x73, 0x09, 0x8c, 0x17, 0xf3, 0x08, 0xe3, 0x00, 0x4c, 0x82, 0x95, 0x00,
0xb3, 0xb5, 0x23, 0xb5, 0x53, 0x42, 0x52, 0x42, 0x53, 0x42, 0x42, 0x42,
0x71, 0x82, 0x75, 0x54, 0x52, 0x42, 0x10, 0x50, 0x77, 0x54, 0x52, 0x42,
0xfb, 0x7f, 0x22, 0x30, 0x79, 0x56, 0x43, 0x42, 0x44, 0x82, 0x0b, 0x30,
0x52, 0x42, 0x5b, 0x42, 0x7c, 0x84, 0x4b, 0x42, 0x35, 0x82, 0x8c, 0x80,
0x8b, 0x42, 0x0b, 0x42, 0x39, 0x80, 0x04, 0x30, 0x0b, 0x42, 0x37, 0x80,
0x15, 0x30, 0x60, 0x25, 0x98, 0x2e, 0xc6, 0xb2, 0x8b, 0x83, 0xfb, 0x6f,
0x65, 0x42, 0xc0, 0x2e, 0x44, 0x42, 0xf0, 0x5f, 0x05, 0x80, 0x02, 0x30,
0x51, 0x82, 0x02, 0x42, 0x13, 0x30, 0x41, 0x40, 0x4b, 0x08, 0x7b, 0x54,
0x3e, 0x80, 0x51, 0x14, 0xc0, 0x2e, 0x01, 0x42, 0x00, 0x2e, 0x40, 0x51,
0xd1, 0x7f, 0x12, 0x25, 0x02, 0x30, 0x42, 0x43, 0x32, 0x30, 0x82, 0x43,
0xc6, 0x7f, 0xe5, 0x7f, 0xb4, 0x7f, 0xa3, 0x7f, 0x90, 0x7f, 0x8b, 0x7f,
0x98, 0x2e, 0x54, 0x01, 0xc0, 0x7e, 0x00, 0xac, 0x01, 0x2f, 0x65, 0x50,
0xc0, 0x7e, 0x00, 0x2e, 0x90, 0x6f, 0x09, 0x8a, 0xd1, 0x6f, 0x75, 0x7f,
0x4c, 0x82, 0x63, 0x41, 0x65, 0x7f, 0x11, 0x7f, 0x00, 0x2e, 0x64, 0x41,
0x44, 0x85, 0x52, 0x7f, 0x45, 0x7f, 0x00, 0x2e, 0xa6, 0x40, 0x80, 0x40,
0x32, 0x7f, 0x82, 0x8e, 0xc2, 0x6e, 0x45, 0x41, 0xf0, 0x7f, 0x27, 0x7f,
0x02, 0x7f, 0x98, 0x2e, 0x8a, 0xb1, 0x23, 0x6f, 0xd1, 0x6f, 0xc2, 0x40,
0xf9, 0x86, 0x23, 0x7f, 0x80, 0xb2, 0xe0, 0x7e, 0x0f, 0x2f, 0x32, 0x6f,
0x64, 0x6f, 0x82, 0x40, 0xf2, 0x7f, 0x4e, 0x82, 0x42, 0x6f, 0x50, 0x6f,
0x73, 0x6f, 0x85, 0x40, 0xc3, 0x40, 0x04, 0x41, 0x06, 0x40, 0xe2, 0x6e,
0x98, 0x2e, 0x8a, 0xb1, 0xe0, 0x7e, 0xf3, 0x31, 0x10, 0x6f, 0x36, 0x80,
0xe1, 0x6e, 0x02, 0x40, 0x71, 0x7f, 0x51, 0x04, 0x02, 0x30, 0x40, 0xa8,
0x91, 0x04, 0x4a, 0x22, 0x89, 0x16, 0x93, 0x08, 0x4a, 0x00, 0x95, 0xb4,
0x09, 0x18, 0x8e, 0x16, 0x13, 0x30, 0x93, 0x08, 0x21, 0x6f, 0x60, 0x7f,
0x4d, 0x86, 0x02, 0x80, 0xb2, 0x00, 0x41, 0x40, 0x21, 0xb5, 0x50, 0x7f,
0x43, 0x7f, 0x98, 0x2e, 0xc2, 0xb1, 0x40, 0x6f, 0x62, 0x6f, 0x55, 0x6f,
0x13, 0x40, 0x84, 0x40, 0x01, 0x40, 0x45, 0x41, 0x42, 0xbe, 0x1d, 0x18,
0x4c, 0x04, 0x31, 0x0f, 0x04, 0x8a, 0xc0, 0x6f, 0x11, 0x30, 0x02, 0x2f,
0x00, 0x2e, 0x03, 0x2c, 0x01, 0x42, 0x23, 0x30, 0x03, 0x42, 0x00, 0x2e,
0xd6, 0x6f, 0x44, 0x41, 0x8a, 0x87, 0x76, 0x8b, 0x00, 0xb3, 0x53, 0x7f,
0x15, 0x2f, 0x04, 0x6f, 0x7d, 0x5e, 0x8b, 0x8d, 0xe7, 0x01, 0xc0, 0xa5,
0x84, 0x41, 0x01, 0x2f, 0x00, 0xa1, 0x03, 0x2f, 0xc0, 0xad, 0x08, 0x2f,
0x00, 0xa5, 0x06, 0x2f, 0xc6, 0x40, 0x81, 0x8d, 0x07, 0x30, 0x3c, 0x05,
0xd6, 0x42, 0x04, 0x2c, 0xc4, 0x42, 0x02, 0x2c, 0x07, 0x30, 0x07, 0x30,
0x86, 0x86, 0x94, 0x6f, 0xd7, 0x7e, 0x0e, 0x8d, 0x00, 0x40, 0x74, 0x89,
0xc7, 0x40, 0x02, 0xb2, 0xf9, 0x29, 0x45, 0x41, 0x86, 0x41, 0xbe, 0x80,
0x21, 0x41, 0x75, 0x23, 0x82, 0x40, 0xc7, 0x42, 0x45, 0x7f, 0x34, 0x7f,
0x20, 0x7f, 0x98, 0x2e, 0xc2, 0xb1, 0x31, 0x6f, 0x60, 0x6f, 0x24, 0x6f,
0x22, 0x40, 0x05, 0x41, 0x43, 0x40, 0x13, 0x01, 0x43, 0x86, 0xac, 0x0f,
0xd1, 0x6f, 0x30, 0x7f, 0x00, 0x2f, 0x44, 0x42, 0x48, 0x8a, 0x41, 0x88,
0xe1, 0x40, 0x13, 0x7f, 0x04, 0x7f, 0xf5, 0x7e, 0x98, 0x2e, 0xc2, 0xb1,
0x11, 0x6f, 0x60, 0x6f, 0x34, 0x6f, 0x42, 0x40, 0x03, 0x40, 0x9a, 0x04,
0x04, 0x41, 0x43, 0x82, 0xa2, 0x0e, 0x03, 0x6f, 0x00, 0x2f, 0xc2, 0x42,
0x00, 0x2e, 0x41, 0x40, 0x72, 0x6f, 0x98, 0x2e, 0xc2, 0xb1, 0x25, 0x6f,
0x72, 0x6f, 0x53, 0x41, 0x93, 0x0e, 0xd1, 0x6f, 0x46, 0x80, 0x1b, 0x30,
0x03, 0x30, 0x0c, 0x2f, 0x04, 0x40, 0x00, 0x91, 0x42, 0x42, 0x08, 0x2f,
0xf6, 0x6e, 0x44, 0x6f, 0x86, 0x41, 0xb4, 0x0e, 0x03, 0x2f, 0x02, 0x88,
0xdb, 0x7e, 0x03, 0x43, 0x0b, 0x42, 0x46, 0x8d, 0x44, 0x41, 0x47, 0x80,
0x05, 0x6f, 0x94, 0x0f, 0x76, 0x7f, 0x60, 0x7f, 0x02, 0x2f, 0x45, 0x89,
0x42, 0x43, 0x03, 0x43, 0x49, 0x88, 0xa5, 0x6f, 0x40, 0x91, 0xa4, 0x7f,
0x15, 0x30, 0xe2, 0x6f, 0xd3, 0x6e, 0x03, 0x2f, 0x04, 0x30, 0x83, 0x42,
0x80, 0x2e, 0x77, 0xb4, 0x04, 0x40, 0x25, 0x29, 0x04, 0x42, 0x83, 0x42,
0x45, 0x82, 0x94, 0x6f, 0x04, 0x85, 0xc0, 0xb2, 0x90, 0x2e, 0x63, 0xb4,
0x15, 0x87, 0x3c, 0x8c, 0xc4, 0x40, 0x46, 0x7f, 0xc2, 0x86, 0x07, 0x40,
0x86, 0x41, 0xf4, 0xbf, 0x00, 0xb3, 0x0c, 0x2f, 0x90, 0x6f, 0x16, 0x80,
0x46, 0x25, 0x00, 0x40, 0x57, 0x25, 0x04, 0x18, 0xae, 0x0e, 0x10, 0x30,
0x06, 0x30, 0x75, 0x25, 0x46, 0x23, 0x60, 0x6f, 0x64, 0x25, 0xc4, 0x40,
0xfa, 0x86, 0x00, 0xb3, 0x33, 0x7f, 0x09, 0x2f, 0x93, 0x6f, 0xd8, 0x88,
0x53, 0x6f, 0x04, 0x41, 0xc3, 0x40, 0xdc, 0x0e, 0x13, 0x30, 0x04, 0x30,
0xdc, 0x22, 0xb3, 0x25, 0x40, 0xb3, 0x02, 0x2f, 0x3b, 0x25, 0xc0, 0x90,
0x05, 0x2f, 0x91, 0x6f, 0xd0, 0x6f, 0x98, 0x2e, 0xc6, 0xb2, 0x4d, 0x2c,
0x04, 0x30, 0x8d, 0x88, 0x43, 0x40, 0x82, 0x40, 0x54, 0x7f, 0xda, 0x0f,
0x04, 0x30, 0x08, 0x2f, 0xc1, 0x80, 0x40, 0x42, 0xc2, 0x0f, 0x02, 0x2f,
0x00, 0x30, 0xc0, 0x7e, 0x1b, 0x2d, 0xc0, 0x7e, 0x19, 0x2d, 0xe1, 0xbc,
0x92, 0x6f, 0x4f, 0x04, 0x90, 0x84, 0x40, 0xa8, 0x21, 0x05, 0x83, 0x40,
0x4c, 0x22, 0x4b, 0x0e, 0xb6, 0x84, 0x21, 0x30, 0x02, 0x2f, 0x11, 0x30,
0x04, 0x2c, 0xc1, 0x7e, 0xe3, 0x6f, 0xc1, 0x7e, 0xc1, 0x42, 0x00, 0x2e,
0x00, 0x40, 0x81, 0x40, 0x04, 0xbd, 0x40, 0x6f, 0x98, 0x2e, 0xc2, 0xb1,
0x50, 0x6f, 0x11, 0x30, 0x02, 0x40, 0x51, 0x08, 0xc3, 0x6e, 0x03, 0x80,
0x99, 0x15, 0x0b, 0x40, 0xb1, 0x6f, 0xd0, 0x6f, 0xb6, 0x7f, 0x5b, 0x7f,
0x04, 0x30, 0x4d, 0x54, 0x03, 0x30, 0x11, 0x2c, 0x10, 0x80, 0x55, 0x6f,
0x06, 0x40, 0x75, 0x01, 0x58, 0xbb, 0x6a, 0x09, 0x05, 0x42, 0xc1, 0x86,
0x47, 0x40, 0x51, 0x25, 0xbe, 0x01, 0x56, 0x43, 0x00, 0x2e, 0x46, 0x41,
0xf4, 0x03, 0xb6, 0x6f, 0x47, 0x43, 0x5e, 0x0e, 0xed, 0x2f, 0x31, 0x6f,
0x60, 0x6f, 0x42, 0x40, 0x15, 0x30, 0x02, 0x82, 0x95, 0x08, 0x04, 0x42,
0x52, 0x42, 0x02, 0x2c, 0x44, 0x42, 0x04, 0x30, 0x3e, 0x8e, 0x91, 0x6f,
0x4f, 0x8c, 0x02, 0x40, 0x83, 0x41, 0xb5, 0x8d, 0x93, 0x0e, 0xd0, 0x6f,
0x01, 0x2f, 0x98, 0x2e, 0xc6, 0xb2, 0x00, 0x2e, 0xc0, 0x41, 0x81, 0x41,
0xc1, 0x0f, 0xc0, 0x6f, 0x01, 0x2f, 0x04, 0x42, 0x00, 0x2e, 0x70, 0x6f,
0x3c, 0x82, 0x00, 0x40, 0x41, 0x40, 0x89, 0x16, 0x95, 0x08, 0x4a, 0x00,
0x04, 0xbc, 0x91, 0xb4, 0x01, 0x0e, 0xe0, 0x6f, 0x07, 0x2f, 0xa1, 0x6f,
0x00, 0x2e, 0x41, 0x40, 0x40, 0xb2, 0x02, 0x2f, 0xa1, 0x6f, 0x05, 0x42,
0x44, 0x42, 0x00, 0x2e, 0x8b, 0x6f, 0xc0, 0x5e, 0xb8, 0x2e, 0x03, 0x2e,
0x1c, 0x01, 0x9c, 0xbc, 0x1d, 0xb9, 0x02, 0x82, 0x25, 0x2e, 0x8e, 0x00,
0x83, 0x56, 0x13, 0x18, 0x01, 0x2e, 0x66, 0x00, 0x43, 0x40, 0xd8, 0x04,
0x05, 0x2e, 0x65, 0x00, 0x40, 0x50, 0x27, 0x2e, 0x65, 0x00, 0xfb, 0x7f,
0xda, 0x05, 0x8b, 0x50, 0x4b, 0x40, 0x02, 0x40, 0x81, 0x82, 0x01, 0x42,
0x03, 0x80, 0x81, 0x52, 0xb1, 0x00, 0x03, 0x40, 0x3b, 0x82, 0x85, 0x58,
0x14, 0x01, 0xc0, 0xb2, 0x37, 0x2e, 0x66, 0x00, 0xd1, 0x7f, 0xe2, 0x7f,
0x04, 0x2f, 0x05, 0x2e, 0x6b, 0x00, 0x81, 0x84, 0x25, 0x2e, 0x6b, 0x00,
0x62, 0x40, 0x3a, 0x0f, 0x45, 0x40, 0xc1, 0x7f, 0x21, 0x30, 0x12, 0x30,
0x42, 0x2f, 0x0d, 0x2e, 0x69, 0x00, 0x3e, 0x0e, 0x33, 0x2f, 0x05, 0x2e,
0x6a, 0x00, 0x01, 0x35, 0x91, 0x0e, 0x01, 0x30, 0x03, 0x2f, 0x09, 0x2e,
0x6e, 0x00, 0x00, 0xb3, 0x24, 0x2f, 0xc0, 0x35, 0x90, 0x0e, 0x39, 0x2f,
0x8f, 0x50, 0x02, 0x30, 0x01, 0x40, 0x7f, 0x82, 0x43, 0xa2, 0x02, 0x2f,
0x00, 0x2e, 0x0c, 0x2c, 0x01, 0x30, 0xc0, 0xb2, 0x11, 0x30, 0x02, 0x2f,
0x25, 0x2e, 0x6d, 0x00, 0x03, 0x2d, 0x23, 0x2e, 0x6d, 0x00, 0x21, 0x30,
0x25, 0x2e, 0x6b, 0x00, 0x42, 0xb2, 0x04, 0x2f, 0x41, 0xb2, 0x02, 0x2f,
0x25, 0x2e, 0x6d, 0x00, 0x31, 0x30, 0x3e, 0x80, 0x04, 0x86, 0x25, 0x2e,
0x6c, 0x00, 0x02, 0x42, 0xc2, 0x42, 0x18, 0x2d, 0x02, 0x35, 0x01, 0x42,
0x25, 0x2e, 0x6a, 0x00, 0x13, 0x2d, 0x2c, 0x04, 0x38, 0x1e, 0x21, 0x2e,
0x69, 0x00, 0x7f, 0x50, 0x11, 0x30, 0x22, 0x30, 0x98, 0x2e, 0x66, 0xb5,
0x09, 0x2c, 0x01, 0x30, 0x2c, 0x00, 0x38, 0x1c, 0x21, 0x2e, 0x68, 0x00,
0x7f, 0x50, 0x98, 0x2e, 0x66, 0xb5, 0x01, 0x30, 0xc0, 0x6f, 0xd4, 0xb1,
0xf5, 0xbd, 0x6b, 0xba, 0x91, 0x5a, 0x02, 0x40, 0x15, 0x18, 0xf5, 0xbe,
0xeb, 0xbb, 0xe3, 0x0a, 0x3d, 0x0b, 0xd2, 0x6f, 0xe3, 0x00, 0x84, 0x40,
0x63, 0x05, 0x93, 0x58, 0x2c, 0x18, 0xf5, 0xbe, 0x03, 0x42, 0xeb, 0xbb,
0xfd, 0x0b, 0xe0, 0x6f, 0x58, 0x01, 0xdf, 0x01, 0x7d, 0x1f, 0x95, 0x42,
0x18, 0x04, 0x85, 0x40, 0x5d, 0x05, 0x2c, 0x18, 0x75, 0xbe, 0xeb, 0xba,
0x2c, 0x0b, 0xdc, 0x04, 0x18, 0x1c, 0x80, 0x42, 0x84, 0x80, 0x02, 0x30,
0x00, 0x40, 0x00, 0xb2, 0x0c, 0x2f, 0x01, 0x2e, 0x6b, 0x00, 0x03, 0x35,
0x83, 0x0e, 0x07, 0x2f, 0x8d, 0x50, 0x3e, 0x80, 0x25, 0x2e, 0x6d, 0x00,
0x02, 0x42, 0x03, 0x80, 0x00, 0x2e, 0x02, 0x42, 0x40, 0xb2, 0x04, 0x2f,
0x8b, 0x50, 0x04, 0x80, 0x25, 0x2e, 0x6a, 0x00, 0x02, 0x42, 0x42, 0xb2,
0x89, 0x56, 0x9a, 0x22, 0x41, 0xb2, 0x01, 0x2e, 0x1c, 0x01, 0x87, 0x52,
0x0b, 0xbc, 0x8a, 0x22, 0x0f, 0xb8, 0x00, 0x90, 0x01, 0x32, 0x06, 0x2f,
0x10, 0x30, 0x90, 0x08, 0x80, 0xb2, 0x08, 0x2f, 0x23, 0x2e, 0x5e, 0xf0,
0x06, 0x2d, 0x20, 0x30, 0x90, 0x08, 0x80, 0xb2, 0x01, 0x2f, 0x23, 0x2e,
0x5e, 0xf0, 0xfb, 0x6f, 0xc0, 0x5f, 0xb8, 0x2e, 0x07, 0x86, 0xfc, 0x88,
0xc6, 0x40, 0x05, 0x41, 0x31, 0x1a, 0x12, 0x2f, 0x80, 0x91, 0x22, 0x2f,
0x01, 0x35, 0x29, 0x0f, 0x0a, 0x2f, 0x06, 0x80, 0x00, 0x2e, 0x00, 0x40,
0x00, 0xb2, 0x01, 0x2f, 0x44, 0xa9, 0x03, 0x2f, 0x00, 0x30, 0xc0, 0x42,
0x00, 0x43, 0xb8, 0x2e, 0xc2, 0x42, 0x01, 0x43, 0xb8, 0x2e, 0x01, 0x35,
0xa9, 0x0e, 0x0e, 0x2f, 0x03, 0x3b, 0xeb, 0x00, 0xcc, 0xa8, 0x0a, 0x2f,
0x05, 0x86, 0xc2, 0x80, 0xc3, 0x40, 0x02, 0x42, 0x3c, 0x84, 0xc1, 0x80,
0x81, 0x42, 0x82, 0x84, 0xc0, 0x2e, 0x80, 0x42, 0x00, 0x2e, 0xb8, 0x2e,
0x03, 0x2e, 0x1d, 0x01, 0x9f, 0xbc, 0x9f, 0xb8, 0x90, 0x50, 0x40, 0xb2,
0x90, 0x2e, 0x71, 0xb6, 0x12, 0x40, 0x03, 0x30, 0x11, 0x40, 0x80, 0xa8,
0x5a, 0x05, 0x9f, 0x58, 0x55, 0x23, 0x00, 0x40, 0x75, 0x7f, 0x40, 0xa8,
0x16, 0x41, 0xd9, 0x05, 0xcf, 0x23, 0x56, 0x05, 0x40, 0xa9, 0x9d, 0x05,
0x87, 0x7f, 0x6e, 0x23, 0x17, 0x41, 0xa5, 0x7f, 0x3e, 0x8b, 0x04, 0x41,
0x52, 0x43, 0x00, 0xa8, 0x98, 0x05, 0xf2, 0x7f, 0x86, 0x22, 0xcf, 0x05,
0xc0, 0xa9, 0x9f, 0x05, 0xbe, 0x23, 0x04, 0x05, 0x92, 0x7f, 0x00, 0xa9,
0xdc, 0x05, 0x51, 0x43, 0xb6, 0x7f, 0x27, 0x23, 0xa7, 0x54, 0xe1, 0x7f,
0x02, 0x18, 0x7d, 0x83, 0x40, 0x43, 0xeb, 0xba, 0x75, 0xbd, 0xaa, 0x0a,
0x0b, 0x2e, 0x71, 0x00, 0x77, 0x5c, 0x2e, 0x18, 0xf5, 0xbe, 0x6b, 0xbb,
0x75, 0x0b, 0xaa, 0x00, 0xc4, 0x7f, 0x25, 0x2e, 0x71, 0x00, 0xb2, 0x6f,
0xa5, 0x6f, 0xaa, 0x00, 0x54, 0x01, 0x84, 0x6f, 0x72, 0x6f, 0x94, 0x05,
0x80, 0xa9, 0xde, 0x05, 0xb7, 0x23, 0x99, 0x5e, 0x77, 0x0e, 0x41, 0x40,
0x97, 0x5c, 0xb1, 0x01, 0xd5, 0x7f, 0x00, 0x2e, 0x85, 0x41, 0x0e, 0x2f,
0x00, 0xa0, 0x0c, 0x2f, 0x14, 0x0f, 0x04, 0x2f, 0xe0, 0x6f, 0x00, 0xac,
0x10, 0x30, 0x08, 0x2c, 0x18, 0x22, 0xf0, 0x6f, 0x00, 0xac, 0x30, 0x30,
0x24, 0x30, 0x02, 0x2c, 0x20, 0x22, 0x40, 0x30, 0x0d, 0x2e, 0x71, 0x00,
0x80, 0xa1, 0x1e, 0x23, 0x79, 0x5e, 0x37, 0x0f, 0xbc, 0x23, 0x00, 0x90,
0x14, 0x30, 0x10, 0x30, 0x18, 0x2f, 0x9d, 0x50, 0x30, 0x00, 0x9b, 0x56,
0x43, 0x0e, 0x02, 0x2f, 0x10, 0x30, 0x0a, 0x2c, 0x03, 0x30, 0x99, 0x50,
0x10, 0x0e, 0x13, 0x30, 0x00, 0x2f, 0x03, 0x30, 0x90, 0x0f, 0x10, 0x30,
0x00, 0x2f, 0x00, 0x30, 0x00, 0x90, 0x10, 0x30, 0x00, 0x2f, 0x00, 0x30,
0xc0, 0x90, 0x13, 0x30, 0x00, 0x2f, 0x03, 0x30, 0x40, 0xb2, 0x87, 0x5c,
0x22, 0x2f, 0x41, 0x90, 0x4a, 0x2f, 0xa5, 0x50, 0x00, 0x2e, 0x01, 0x40,
0x41, 0x82, 0x01, 0x42, 0x02, 0x80, 0x4a, 0xa8, 0x01, 0x40, 0x06, 0x2f,
0xd0, 0x6f, 0x85, 0x0e, 0x3e, 0x2f, 0x41, 0x80, 0x21, 0x2e, 0x78, 0x00,
0x3b, 0x2d, 0x95, 0x50, 0xfb, 0x7f, 0x4a, 0xa8, 0x06, 0x2f, 0x98, 0x2e,
0x73, 0xb6, 0xc0, 0x90, 0xfb, 0x6f, 0x32, 0x2f, 0x00, 0x2e, 0x30, 0x2d,
0x98, 0x2e, 0x73, 0xb6, 0x29, 0x2e, 0x7a, 0x00, 0x2b, 0x2c, 0xfb, 0x6f,
0xa1, 0x52, 0xd2, 0x6f, 0x95, 0x0e, 0x41, 0x40, 0x05, 0x2f, 0x00, 0x90,
0x17, 0x2f, 0x05, 0x2e, 0x7a, 0x00, 0x80, 0x90, 0x13, 0x2f, 0x7f, 0x82,
0x40, 0xac, 0x23, 0x2e, 0x77, 0x00, 0x01, 0x30, 0x18, 0x2f, 0xa1, 0x54,
0x82, 0x84, 0x23, 0x2e, 0x77, 0x00, 0x82, 0x40, 0x80, 0xb2, 0x11, 0x2f,
0x00, 0x90, 0x23, 0x2e, 0x79, 0x00, 0x0d, 0x2f, 0x29, 0x2e, 0x72, 0x00,
0x0b, 0x2d, 0x41, 0x80, 0x21, 0x2e, 0x77, 0x00, 0x0f, 0xa4, 0x05, 0x2f,
0xa3, 0x50, 0x3e, 0x80, 0xf1, 0x30, 0x29, 0x2e, 0x79, 0x00, 0x01, 0x42,
0x06, 0x30, 0x34, 0x08, 0x00, 0xb2, 0x02, 0x2f, 0x80, 0x30, 0x21, 0x2e,
0x5e, 0xf0, 0x70, 0x5f, 0xb8, 0x2e, 0x04, 0x84, 0x01, 0x30, 0x81, 0x42,
0x82, 0x84, 0x01, 0x42, 0xa1, 0x42, 0x81, 0x42, 0x82, 0x84, 0x00, 0x2e,
0x91, 0x42, 0x81, 0x42, 0xb8, 0x2e, 0x30, 0x50, 0xf3, 0x7f, 0xc0, 0xac,
0xe4, 0x7f, 0xd5, 0x7f, 0x03, 0x2f, 0x00, 0x30, 0x82, 0x04, 0xf3, 0x6f,
0xc3, 0x06, 0x40, 0xad, 0x05, 0x2f, 0xe0, 0x6f, 0x05, 0x30, 0x28, 0x04,
0xd1, 0x6f, 0x69, 0x07, 0xe0, 0x7f, 0x40, 0xa1, 0x01, 0x30, 0x20, 0x2f,
0x13, 0x25, 0x02, 0x25, 0x04, 0x32, 0x06, 0x30, 0x02, 0x30, 0x03, 0x30,
0xaf, 0xbb, 0xb1, 0xbd, 0xdf, 0x0a, 0x9f, 0xbb, 0x21, 0xbd, 0x97, 0x0a,
0x8f, 0xbb, 0x91, 0xbc, 0x01, 0xbc, 0x4f, 0x0a, 0x6b, 0x0e, 0x04, 0x2f,
0x6b, 0x1a, 0x07, 0x2f, 0xe7, 0x6f, 0x7a, 0x0f, 0x04, 0x2f, 0xe7, 0x6f,
0x97, 0x04, 0x17, 0x30, 0x07, 0x0a, 0xdd, 0x06, 0x81, 0x8d, 0x34, 0x0e,
0xe6, 0x2f, 0x00, 0x2e, 0x0d, 0x2d, 0x6b, 0x0e, 0x00, 0x30, 0x05, 0x2f,
0x6b, 0x1a, 0x07, 0x2f, 0xe0, 0x6f, 0x42, 0x0f, 0x00, 0x30, 0x03, 0x2f,
0xe0, 0x6f, 0x90, 0x04, 0xdd, 0x06, 0x10, 0x30, 0xf5, 0x6f, 0xc3, 0x7f,
0xb2, 0x7f, 0x40, 0xad, 0x06, 0x2f, 0x03, 0x30, 0xb2, 0x6f, 0x9a, 0x04,
0xc4, 0x6f, 0xdc, 0x06, 0xb2, 0x7f, 0xc3, 0x7f, 0x00, 0x2e, 0xd2, 0x6f,
0xaa, 0x0c, 0x80, 0xac, 0x02, 0x30, 0x01, 0x2f, 0x10, 0x04, 0x51, 0x06,
0xd0, 0x5f, 0xb8, 0x2e, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00
};
#define BMA4_ACCEL_CONFIG_ADDR (0X40)
#define BMA4_TEMPERATURE_ADDR (0X22)
/**************************************************************/
/**\name Step Counter & Detector */
/**************************************************************/
/**\name Step counter enable macros */
#define BMA423_STEP_CNTR_EN_POS (4)
#define BMA423_STEP_CNTR_EN_MSK (0x10)
#define BMA423_ACTIVITY_EN_MSK (0x20)
/**\name Step counter watermark macros */
#define BMA423_STEP_CNTR_WM_MSK (0x03FF)
/**\name Step counter reset macros */
#define BMA423_STEP_CNTR_RST_POS (2)
#define BMA423_STEP_CNTR_RST_MSK (0x04)
/**\name Step detector enable macros */
#define BMA423_STEP_DETECTOR_EN_POS (3)
#define BMA423_STEP_DETECTOR_EN_MSK (0x08)
/**\name Tilt enable macros */
#define BMA423_TILT_EN_MSK (0x01)
/**\name Step count output length*/
#define BMA423_STEP_CNTR_DATA_SIZE (4)
/**\name Wakeup enable macros */
#define BMA423_WAKEUP_EN_MSK (0x01)
/**\name Wake up sensitivity macros */
#define BMA423_WAKEUP_SENS_POS (1)
#define BMA423_WAKEUP_SENS_MSK (0x0E)
/**\name Tap selection macro */
#define BMA423_TAP_SEL_POS (4)
#define BMA423_TAP_SEL_MSK (0x10)
/**************************************************************/
/**\name Any Motion */
/**************************************************************/
/**\name Any motion threshold macros */
#define BMA423_ANY_NO_MOTION_THRES_POS (0)
#define BMA423_ANY_NO_MOTION_THRES_MSK (0x07FF)
/**\name Any motion selection macros */
#define BMA423_ANY_NO_MOTION_SEL_POS (3)
#define BMA423_ANY_NO_MOTION_SEL_MSK (0x08)
/**\name Any motion enable macros */
#define BMA423_ANY_NO_MOTION_AXIS_EN_POS (5)
#define BMA423_ANY_NO_MOTION_AXIS_EN_MSK (0xE0)
/**\name Any motion duration macros */
#define BMA423_ANY_NO_MOTION_DUR_MSK (0x1FFF)
/**\name INTERRUPT MAPS */
#define BMA4_INTR1_MAP (0)
#define BMA4_INTR2_MAP (1)
/**\name INTERRUPT ENABLE REGISTERS*/
#define BMA4_INT1_IO_CTRL_ADDR (0X53)
#define BMA4_INT2_IO_CTRL_ADDR (0X54)
/**\name LATCH DURATION REGISTERS*/
#define BMA4_INTR_LATCH_ADDR (0X55)
/**\name CONSTANTS */
#define BMA4_FIFO_CONFIG_LENGTH (2)
#define BMA4_ACCEL_CONFIG_LENGTH (2)
#define BMA4_FIFO_WM_LENGTH (2)
#define BMA4_CONFIG_STREAM_SIZE (6144)
#define BMA4_NON_LATCH_MODE (0)
#define BMA4_LATCH_MODE (1)
#define BMA4_OPEN_DRAIN (1)
#define BMA4_PUSH_PULL (0)
#define BMA4_ACTIVE_HIGH (1)
#define BMA4_ACTIVE_LOW (0)
#define BMA4_EDGE_TRIGGER (1)
#define BMA4_LEVEL_TRIGGER (0)
#define BMA4_OUTPUT_ENABLE (1)
#define BMA4_OUTPUT_DISABLE (0)
#define BMA4_INPUT_ENABLE (1)
#define BMA4_INPUT_DISABLE (0)
/**\name OUTPUT TYPE ENABLE POSITION AND MASK*/
#define BMA4_INT_EDGE_CTRL_MASK (0x01)
#define BMA4_INT_EDGE_CTRL_POS (0x00)
#define BMA4_INT_LEVEL_MASK (0x02)
#define BMA4_INT_LEVEL_POS (0x01)
#define BMA4_INT_OPEN_DRAIN_MASK (0x04)
#define BMA4_INT_OPEN_DRAIN_POS (0x02)
#define BMA4_INT_OUTPUT_EN_MASK (0x08)
#define BMA4_INT_OUTPUT_EN_POS (0x03)
#define BMA4_INT_INPUT_EN_MASK (0x10)
#define BMA4_INT_INPUT_EN_POS (0x04)
/**\name Interrupt status macros */
#define BMA423_STEP_CNTR_INT (0x02)
#define BMA423_ACTIVITY_INT (0x04)
#define BMA423_TILT_INT (0x08)
#define BMA423_WAKEUP_INT (0x20)
#define BMA423_ANY_NO_MOTION_INT (0x40)
#define BMA423_ERROR_INT (0x80)

View File

@@ -0,0 +1,66 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file CHSC5816Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-17
*
*/
#pragma once
#define CHSC5816_SLAVE_ADDRESS (0x2E)
#define CHSC5816_REG_CMD_BUFF (0x20000000U)
#define CHSC5816_REG_RSP_BUFF (0x20000000U)
#define CHSC5816_REG_IMG_HEAD (0x20000014U)
#define CHSC5816_REG_POINT (0x2000002CU)
#define CHSC5816_REG_WR_BUFF (0x20002000U)
#define CHSC5816_REG_RD_BUFF (0x20002400U)
#define CHSC5816_REG_HOLD_MCU (0x40007000U)
#define CHSC5816_REG_AUTO_FEED (0x40007010U)
#define CHSC5816_REG_REMAP_MCU (0x40007000U)
#define CHSC5816_REG_RELEASE_MCU (0x40007000U)
#define CHSC5816_REG_BOOT_STATE (0x20000018U)
#define CHSC5816_HOLD_MCU_VAL (0x12044000U)
#define CHSC5816_AUTO_FEED_VAL (0x0000925aU)
#define CHSC5816_REMAP_MCU_VAL (0x12044002U)
#define CHSC5816_RELEASE_MCU_VAL (0x12044003U)
#define CHSC5816_REG_VID_PID_BACKUP (40 * 1024 + 0x10U)
#define CHSC5816_SIG_VALUE (0x43534843U)
/*ctp work staus*/
#define CHSC5816_POINTING_WORK (0x00000000U)
#define CHSC5816_READY_UPGRADE (1 << 1)
#define CHSC5816_UPGRAD_RUNING (1 << 2)
#define CHSC5816_SLFTEST_RUNING (1 << 3)
#define CHSC5816_SUSPEND_GATE (1 << 16)
#define CHSC5816_GUESTURE_GATE (1 << 17)
#define CHSC5816_PROXIMITY_GATE (1 << 18)
#define CHSC5816_GLOVE_GATE (1 << 19)
#define CHSC5816_ORIENTATION_GATE (1 << 20)

View File

@@ -0,0 +1,62 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file CM32181Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-14
*
*/
#pragma once
#define CM32181_SLAVE_ADDRESS (0x10)
// CM32181 slave address can be 0x10 or 0x48, determined by pin ADDR configuration
#define CM32181_ADDR_ALS (0x10) // 7-bit
#define CM32181_ADDR_ALS1 (0x48) // 7-bit
// CM32181 registers
#define CM32181_REG_ALS_CONF (uint8_t)(0x00)
#define CM32181_REG_ALS_THDH (uint8_t)(0x01)
#define CM32181_REG_ALS_THDL (uint8_t)(0x02)
#define CM32181_REG_ALS_PSM (uint8_t)(0x03)
#define CM32181_REG_ALS_DATA (uint8_t)(0x04)
#define CM32181_REG_ALS_STATUS (uint8_t)(0x06)
#define CM32181_REG_ID (uint8_t)(0x07)
#define CM32181_CHIP_ID (0x81)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,46 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file CSTxxxConstants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-24
*
*/
#pragma once
#define CSTXXX_SLAVE_ADDRESS (0x15)
#define CST816_SLAVE_ADDRESS (0x15)
#define CST328_SLAVE_ADDRESS (0x1A)
#define CST226SE_SLAVE_ADDRESS (0x5A)
#define CST816S_CHIP_ID (0xB4)
#define CST816T_CHIP_ID (0xB5)
#define CST716_CHIP_ID (0x20)
#define CST226SE_CHIP_ID (0xA8)

View File

@@ -0,0 +1,80 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file DRV2605Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-03
*
*/
#pragma once
#define DRV2605_SLAVE_ADDRESS (0x5A)
#define DRV2604_CHIP_ID (0x04) //* DRV2604 (contains RAM, does not contain licensed ROM library)
#define DRV2605_CHIP_ID (0x03) //* DRV2605 (contains licensed ROM library, does not contain RAM)
#define DRV2604L_CHIP_ID (0x06) //* DRV2604L (low-voltage version of the DRV2604 device)
#define DRV2605L_CHIP_ID (0x07) //* DRV2605L (low-voltage version of the DRV2605 device)
#define DRV2605_REG_STATUS (0x00) //* Status register
#define DRV2605_REG_MODE (0x01) //* Mode register
#define DRV2605_MODE_INTTRIG (0x00) //* Internal trigger mode
#define DRV2605_MODE_EXTTRIGEDGE (0x01) //* External edge trigger mode
#define DRV2605_MODE_EXTTRIGLVL (0x02) //* External level trigger mode
#define DRV2605_MODE_PWMANALOG (0x03) //* PWM/Analog input mode
#define DRV2605_MODE_AUDIOVIBE (0x04) //* Audio-to-vibe mode
#define DRV2605_MODE_REALTIME (0x05) //* Real-time playback (RTP) mode
#define DRV2605_MODE_DIAGNOS (0x06) //* Diagnostics mode
#define DRV2605_MODE_AUTOCAL (0x07) //* Auto calibration mode
#define DRV2605_REG_RTPIN (0x02) //* Real-time playback input register
#define DRV2605_REG_LIBRARY (0x03) //* Waveform library selection register
#define DRV2605_REG_WAVESEQ1 (0x04) //* Waveform sequence register 1
#define DRV2605_REG_WAVESEQ2 (0x05) //* Waveform sequence register 2
#define DRV2605_REG_WAVESEQ3 (0x06) //* Waveform sequence register 3
#define DRV2605_REG_WAVESEQ4 (0x07) //* Waveform sequence register 4
#define DRV2605_REG_WAVESEQ5 (0x08) //* Waveform sequence register 5
#define DRV2605_REG_WAVESEQ6 (0x09) //* Waveform sequence register 6
#define DRV2605_REG_WAVESEQ7 (0x0A) //* Waveform sequence register 7
#define DRV2605_REG_WAVESEQ8 (0x0B) //* Waveform sequence register 8
#define DRV2605_REG_GO (0x0C) //* Go register
#define DRV2605_REG_OVERDRIVE (0x0D) //* Overdrive time offset register
#define DRV2605_REG_SUSTAINPOS (0x0E) //* Sustain time offset, positive register
#define DRV2605_REG_SUSTAINNEG (0x0F) //* Sustain time offset, negative register
#define DRV2605_REG_BREAK (0x10) //* Brake time offset register
#define DRV2605_REG_AUDIOCTRL (0x11) //* Audio-to-vibe control register
#define DRV2605_REG_AUDIOLVL (0x12) //* Audio-to-vibe minimum input level register
#define DRV2605_REG_AUDIOMAX (0x13) //* Audio-to-vibe maximum input level register
#define DRV2605_REG_AUDIOOUTMIN (0x14) //* Audio-to-vibe minimum output drive register
#define DRV2605_REG_AUDIOOUTMAX (0x15) //* Audio-to-vibe maximum output drive register
#define DRV2605_REG_RATEDV (0x16) //* Rated voltage register
#define DRV2605_REG_CLAMPV (0x17) //* Overdrive clamp voltage register
#define DRV2605_REG_AUTOCALCOMP (0x18) //* Auto-calibration compensation result register
#define DRV2605_REG_AUTOCALEMP (0x19) //* Auto-calibration back-EMF result register
#define DRV2605_REG_FEEDBACK (0x1A) //* Feedback control register
#define DRV2605_REG_CONTROL1 (0x1B) //* Control1 Register
#define DRV2605_REG_CONTROL2 (0x1C) //* Control2 Register
#define DRV2605_REG_CONTROL3 (0x1D) //* Control3 Register
#define DRV2605_REG_CONTROL4 (0x1E) //* Control4 Register
#define DRV2605_REG_VBAT (0x21) //* Vbat voltage-monitor register
#define DRV2605_REG_LRARESON (0x22) //* LRA resonance-period register

View File

@@ -0,0 +1,65 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file FT6X36Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-01
*
*/
#pragma once
#define FT3267_SLAVE_ADDRESS (0x38)
#define FT5206_SLAVE_ADDRESS (0x38)
#define FT6X36_SLAVE_ADDRESS (0x38)
#define FT6X36_VEND_ID (0x11)
#define FT3267_CHIP_ID (0x33)
#define FT6206_CHIP_ID (0x06)
#define FT6236_CHIP_ID (0x36)
#define FT6236U_CHIP_ID (0x64)
#define FT5206U_CHIP_ID (0x64)
#define FT6X36_REG_MODE (0x00)
#define FT6X36_REG_GEST (0x01)
#define FT6X36_REG_STATUS (0x02)
#define FT6X36_REG_TOUCH1_XH (0x03)
#define FT6X36_REG_TOUCH1_XL (0x04)
#define FT6X36_REG_TOUCH1_YH (0x05)
#define FT6X36_REG_TOUCH1_YL (0x06)
#define FT6X36_REG_THRESHOLD (0x80)
#define FT6X36_REG_MONITOR_TIME (0x87)
#define FT6X36_REG_PERIOD_ACTIVE (0x88)
#define FT6X36_REG_PERIOD_MONITOR (0x89)
#define FT6X36_REG_AUTO_CLB_MODE (0xA0)
#define FT6X36_REG_LIB_VERSION_H (0xA1)
#define FT6X36_REG_LIB_VERSION_L (0xA2)
#define FT6X36_REG_INT_STATUS (0xA4)
#define FT6X36_REG_POWER_MODE (0xA5)
#define FT6X36_REG_FIRM_VERS (0xA6)
#define FT6X36_REG_CHIP_ID (0xA3)
#define FT6X36_REG_VENDOR1_ID (0xA8)
#define FT6X36_REG_ERROR_STATUS (0xA9)

View File

@@ -0,0 +1,166 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file GT911Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-12
*
*/
#pragma once
#define GT911_SLAVE_ADDRESS_H (0x14)
#define GT911_SLAVE_ADDRESS_L (0x5D)
#define GT911_DEV_ID (911)
#define GT911_BASE_REF_RATE (5)
#define GT911_REG_LENGTH (186)
// Real-time command (Write only)
#define GT911_COMMAND (0x8040)
#define GT911_ESD_CHECK (0x8041)
#define GT911_COMMAND_CHECK (0x8046)
// Configuration information (R/W)
#define GT911_CONFIG_START (0x8047)
#define GT911_CONFIG_VERSION (0x8047)
#define GT911_X_OUTPUT_MAX_LOW (0x8048)
#define GT911_X_OUTPUT_MAX_HIGH (0x8049)
#define GT911_Y_OUTPUT_MAX_LOW (0x804A)
#define GT911_Y_OUTPUT_MAX_HIGH (0x804B)
#define GT911_TOUCH_NUMBER (0x804C)
#define GT911_MODULE_SWITCH_1 (0x804D)
#define GT911_MODULE_SWITCH_2 (0x804E)
#define GT911_SHAKE_COUNT (0x804F)
#define GT911_FILTER (0x8050)
#define GT911_LARGE_TOUCH (0x8051)
#define GT911_NOISE_REDUCTION (0x8052)
#define GT911_SCREEN_TOUCH_LEVEL (0x8053)
#define GT911_SCREEN_RELEASE_LEVEL (0x8054)
#define GT911_LOW_POWER_CONTROL (0x8055)
#define GT911_REFRESH_RATE (0x8056)
#define GT911_X_THRESHOLD (0x8057)
#define GT911_Y_THRESHOLD (0x8058)
#define GT911_X_SPEED_LIMIT (0x8059) // Reserve
#define GT911_Y_SPEED_LIMIT (0x805A) // Reserve
#define GT911_SPACE_TOP_BOTTOM (0x805B)
#define GT911_SPACE_LEFT_RIGHT (0x805C)
#define GT911_MINI_FILTER (0x805D)
#define GT911_STRETCH_R0 (0x805E)
#define GT911_STRETCH_R1 (0x805F)
#define GT911_STRETCH_R2 (0x8060)
#define GT911_STRETCH_RM (0x8061)
#define GT911_DRV_GROUPA_NUM (0x8062)
#define GT911_DRV_GROUPB_NUM (0x8063)
#define GT911_SENSOR_NUM (0x8064)
#define GT911_FREQ_A_FACTOR (0x8065)
#define GT911_FREQ_B_FACTOR (0x8066)
#define GT911_PANEL_BIT_FREQ_L (0x8067)
#define GT911_PANEL_BIT_FREQ_H (0x8068)
#define GT911_PANEL_SENSOR_TIME_L (0x8069) // Reserve
#define GT911_PANEL_SENSOR_TIME_H (0x806A)
#define GT911_PANEL_TX_GAIN (0x806B)
#define GT911_PANEL_RX_GAIN (0x806C)
#define GT911_PANEL_DUMP_SHIFT (0x806D)
#define GT911_DRV_FRAME_CONTROL (0x806E)
#define GT911_CHARGING_LEVEL_UP (0x806F)
#define GT911_MODULE_SWITCH3 (0x8070)
#define GT911_GESTURE_DIS (0X8071)
#define GT911_GESTURE_LONG_PRESS_TIME (0x8072)
#define GT911_X_Y_SLOPE_ADJUST (0X8073)
#define GT911_GESTURE_CONTROL (0X8074)
#define GT911_GESTURE_SWITCH1 (0X8075)
#define GT911_GESTURE_SWITCH2 (0X8076)
#define GT911_GESTURE_REFRESH_RATE (0x8077)
#define GT911_GESTURE_TOUCH_LEVEL (0x8078)
#define GT911_NEWGREENWAKEUPLEVEL (0x8079)
#define GT911_FREQ_HOPPING_START (0x807A)
#define GT911_FREQ_HOPPING_END (0X807B)
#define GT911_NOISE_DETECT_TIMES (0x807C)
#define GT911_HOPPING_FLAG (0X807D)
#define GT911_HOPPING_THRESHOLD (0X807E)
#define GT911_NOISE_THRESHOLD (0X807F) // Reserve
#define GT911_NOISE_MIN_THRESHOLD (0X8080)
#define GT911_HOPPING_SENSOR_GROUP (0X8082)
#define GT911_HOPPING_SEG1_NORMALIZE (0X8083)
#define GT911_HOPPING_SEG1_FACTOR (0X8084)
#define GT911_MAIN_CLOCK_AJDUST (0X8085)
#define GT911_HOPPING_SEG2_NORMALIZE (0X8086)
#define GT911_HOPPING_SEG2_FACTOR (0X8087)
#define GT911_HOPPING_SEG3_NORMALIZE (0X8089)
#define GT911_HOPPING_SEG3_FACTOR (0X808A)
#define GT911_HOPPING_SEG4_NORMALIZE (0X808C)
#define GT911_HOPPING_SEG4_FACTOR (0X808D)
#define GT911_HOPPING_SEG5_NORMALIZE (0X808F)
#define GT911_HOPPING_SEG5_FACTOR (0X8090)
#define GT911_HOPPING_SEG6_NORMALIZE (0X8092)
#define GT911_KEY_1 (0X8093)
#define GT911_KEY_2 (0X8094)
#define GT911_KEY_3 (0X8095)
#define GT911_KEY_4 (0X8096)
#define GT911_KEY_AREA (0X8097)
#define GT911_KEY_TOUCH_LEVEL (0X8098)
#define GT911_KEY_LEAVE_LEVEL (0X8099)
#define GT911_KEY_SENS_1_2 (0X809A)
#define GT911_KEY_SENS_3_4 (0X809B)
#define GT911_KEY_RESTRAIN (0X809C)
#define GT911_KEY_RESTRAIN_TIME (0X809D)
#define GT911_GESTURE_LARGE_TOUCH (0X809E)
#define GT911_HOTKNOT_NOISE_MAP (0X80A1)
#define GT911_LINK_THRESHOLD (0X80A2)
#define GT911_PXY_THRESHOLD (0X80A3)
#define GT911_GHOT_DUMP_SHIFT (0X80A4)
#define GT911_GHOT_RX_GAIN (0X80A5)
#define GT911_FREQ_GAIN0 (0X80A6)
#define GT911_FREQ_GAIN1 (0X80A7)
#define GT911_FREQ_GAIN2 (0X80A8)
#define GT911_FREQ_GAIN3 (0X80A9)
#define GT911_COMBINE_DIS (0X80B3)
#define GT911_SPLIT_SET (0X80B4)
#define GT911_SENSOR_CH0 (0X80B7)
#define GT911_DRIVER_CH0 (0X80D5)
#define GT911_CONFIG_CHKSUM (0X80FF)
#define GT911_CONFIG_FRESH (0X8100)
#define GT911_CONFIG_SIZE (0xFF - 0x46)
// Coordinate information
#define GT911_PRODUCT_ID (0x8140)
#define GT911_FIRMWARE_VERSION (0x8144)
#define GT911_X_RESOLUTION (0x8146)
#define GT911_Y_RESOLUTION (0x8148)
#define GT911_VENDOR_ID (0X8140)
#define GT911_IMFORMATION (0X8140)
#define GT911_POINT_INFO (0X814E)
#define GT911_POINT_1 (0X814F)
#define GT911_POINT_2 (0X8157)
#define GT911_POINT_3 (0X815F)
#define GT911_POINT_4 (0X8167)
#define GT911_POINT_5 (0X816F)
#define GT911_GET_POINT(x) (x & 0x0F)
#define GT911_GET_BUFFER_STATUS(x) (x & 0x80)
#define GT911_GET_HAVE_KEY(x) (x & 0x10)

View File

@@ -0,0 +1,63 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file LTR533Constants.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-09
*/
#pragma once
#define LTR553_SLAVE_ADDRESS (0x23)
#define LTR553_REG_ALS_CONTR (0x80)
#define LTR553_REG_PS_CONTR (0x81)
#define LTR553_REG_PS_LED (0x82)
#define LTR553_REG_PS_N_PULSES (0x83)
#define LTR553_REG_PS_MEAS_RATE (0x84)
#define LTR553_REG_ALS_MEAS_RATE (0x85)
#define LTR553_REG_PART_ID (0x86)
#define LTR553_REG_MANUFAC_ID (0x87)
#define LTR553_REG_ALS_DATA_CH1_0 (0x88)
#define LTR553_REG_ALS_DATA_CH1_1 (0x89)
#define LTR553_REG_ALS_DATA_CH0_0 (0x8A)
#define LTR553_REG_ALS_DATA_CH0_1 (0x8B)
#define LTR553_REG_ALS_PS_STATUS (0x8C)
#define LTR553_REG_PS_DATA_0 (0x8D)
#define LTR553_REG_PS_DATA_1 (0x8E)
#define LTR553_REG_INTERRUPT (0x8F)
#define LTR553_REG_PS_THRES_UP_0 (0x90)
#define LTR553_REG_PS_THRES_UP_1 (0x91)
#define LTR553_REG_PS_THRES_LOW_0 (0x92)
#define LTR553_REG_PS_THRES_LOW_1 (0x93)
#define LTR553_REG_PS_OFFSET_1 (0x94)
#define LTR553_REG_PS_OFFSET_0 (0x95)
#define LTR553_REG_ALS_THRES_UP_0 (0x97)
#define LTR553_REG_ALS_THRES_UP_1 (0x98)
#define LTR553_REG_ALS_THRES_LOW_0 (0x99)
#define LTR553_REG_ALS_THRES_LOW_1 (0x9A)
#define LTR553_REG_INTERRUPT_PERSIST (0x9E)
#define LTR553_DEFAULT_MAN_ID (0x05)

View File

@@ -0,0 +1,115 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file MPU6886Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2022-10-16
*
*/
#pragma once
#define MPU6886_SLAVE_ADDRESS (0x68)
#define MPU6886_REG_XG_OFFS_TC_H (0x04)
#define MPU6886_REG_XG_OFFS_TC_L (0x05)
#define MPU6886_REG_YG_OFFS_TC_H (0x07)
#define MPU6886_REG_YG_OFFS_TC_L (0x08)
#define MPU6886_REG_ZG_OFFS_TC_H (0x0A)
#define MPU6886_REG_ZG_OFFS_TC_L (0x0B)
#define MPU6886_REG_SELF_TEST_X_ACCEL (0x0D)
#define MPU6886_REG_SELF_TEST_Y_ACCEL (0x0E)
#define MPU6886_REG_SELF_TEST_Z_ACCEL (0x0F)
#define MPU6886_REG_XG_OFFS_USRH (0x13)
#define MPU6886_REG_XG_OFFS_USRL (0x14)
#define MPU6886_REG_YG_OFFS_USRH (0x15)
#define MPU6886_REG_YG_OFFS_USRL (0x16)
#define MPU6886_REG_ZG_OFFS_USRH (0x17)
#define MPU6886_REG_ZG_OFFS_USRL (0x18)
#define MPU6886_REG_SMPLRT_DIV (0x19)
#define MPU6886_REG_CONFIG (0x1A)
#define MPU6886_REG_GYRO_CONFIG (0x1B)
#define MPU6886_REG_ACCEL_CONFIG (0x1C)
#define MPU6886_REG_ACCEL_CONFIG_2 (0x1D)
#define MPU6886_REG_LP_MODE_CFG (0x1E)
#define MPU6886_REG_ACCEL_WOM_X_THR (0x20)
#define MPU6886_REG_ACCEL_WOM_Y_THR (0x21)
#define MPU6886_REG_ACCEL_WOM_Z_THR (0x22)
#define MPU6886_REG_FIFO_EN (0x23)
#define MPU6886_REG_FSYNC_INT (0x36)
#define MPU6886_REG_INT_PIN_CFG (0x37)
#define MPU6886_REG_INT_ENABLE (0x38)
#define MPU6886_REG_FIFO_WM_INT_STATUS (0x39)
#define MPU6886_REG_INT_STATUS (0x3A)
#define MPU6886_REG_ACCEL_XOUT_H (0x3B)
#define MPU6886_REG_ACCEL_XOUT_L (0x3C)
#define MPU6886_REG_ACCEL_YOUT_H (0x3D)
#define MPU6886_REG_ACCEL_YOUT_L (0x3E)
#define MPU6886_REG_ACCEL_ZOUT_H (0x3F)
#define MPU6886_REG_ACCEL_ZOUT_L (0x40)
#define MPU6886_REG_TEMP_OUT_H (0x41)
#define MPU6886_REG_TEMP_OUT_L (0x42)
#define MPU6886_REG_GYRO_XOUT_H (0x43)
#define MPU6886_REG_GYRO_XOUT_L (0x44)
#define MPU6886_REG_GYRO_YOUT_H (0x45)
#define MPU6886_REG_GYRO_YOUT_L (0x46)
#define MPU6886_REG_GYRO_ZOUT_H (0x47)
#define MPU6886_REG_GYRO_ZOUT_L (0x48)
#define MPU6886_REG_SELF_TEST_X_GYRO (0x50)
#define MPU6886_REG_SELF_TEST_Y_GYRO (0x51)
#define MPU6886_REG_SELF_TEST_Z_GYRO (0x52)
#define MPU6886_REG_E_ID0 (0x53)
#define MPU6886_REG_E_ID1 (0x54)
#define MPU6886_REG_E_ID2 (0x55)
#define MPU6886_REG_E_ID3 (0x56)
#define MPU6886_REG_E_ID4 (0x57)
#define MPU6886_REG_E_ID5 (0x58)
#define MPU6886_REG_E_ID6 (0x59)
#define MPU6886_REG_FIFO_WM_TH1 (0x60)
#define MPU6886_REG_FIFO_WM_TH2 (0x61)
#define MPU6886_REG_SIGNAL_PATH_RESET (0x68)
#define MPU6886_REG_ACCEL_INTEL_CTRL (0x69)
#define MPU6886_REG_USER_CTRL (0x6A)
#define MPU6886_REG_PWR_MGMT_1 (0x6B)
#define MPU6886_REG_PWR_MGMT_2 (0x6C)
#define MPU6886_REG_I2C_IF (0x70)
#define MPU6886_REG_FIFO_COUNTH (0x72)
#define MPU6886_REG_FIFO_COUNTL (0x73)
#define MPU6886_REG_FIFO_R_W (0x74)
#define MPU6886_REG_WHO_AM_I (0x75)
#define MPU6886_REG_XA_OFFSET_H (0x77)
#define MPU6886_REG_XA_OFFSET_L (0x78)
#define MPU6886_REG_YA_OFFSET_H (0x7A)
#define MPU6886_REG_YA_OFFSET_L (0x7B)
#define MPU6886_REG_ZA_OFFSET_H (0x7D)
#define MPU6886_REG_ZA_OFFSET_L (0x7E)
#define MPU6886_WHO_AM_I_RES (0x19)

View File

@@ -0,0 +1,63 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file PCF85063Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-07
*
*/
#pragma once
#define PCF85063_SLAVE_ADDRESS (0x51)
#define PCF85063_CTRL1_REG (0x00)
#define PCF85063_CTRL2_REG (0x01)
#define PCF85063_OFFSET_REG (0x02)
#define PCF85063_RAM_REG (0x03)
#define PCF85063_SEC_REG (0x04)
#define PCF85063_MIN_REG (0x05)
#define PCF85063_HR_REG (0x06)
#define PCF85063_DAY_REG (0x07)
#define PCF85063_WEEKDAY_REG (0x08)
#define PCF85063_MONTH_REG (0x09)
#define PCF85063_YEAR_REG (0x0A)
#define PCF85063_ALRM_SEC_REG (0x0B)
#define PCF85063_ALRM_MIN_REG (0x0C)
#define PCF85063_ALRM_HR_REG (0x0D)
#define PCF85063_ALRM_DAY_REG (0x0E)
#define PCF85063_ALRM_WEEK_REG (0x0F)
#define PCF85063_TIMER_VAL_REG (0x10)
#define PCF85063_TIMER_MD_REG (0x11)
#define PCF85063_CTRL1_TEST_EN_MASK (1<<7u)
#define PCF85063_CTRL1_CLOCK_EN_MASK (1<<5u)
#define PCF85063_CTRL1_SOFTRST_EN_MASK (1<<4u)
#define PCF85063_CTRL1_CIE_EN_MASK (1<<2u)
#define PCF85063_CTRL1_HOUR_FORMAT_12H_MASK (1<<1u)
#define PCF85063_NO_ALARM (0xFF)
#define PCF85063_ALARM_ENABLE (0x80)

View File

@@ -0,0 +1,70 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file PCF8563Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2022-12-09
*
*/
#pragma once
#define PCF8563_SLAVE_ADDRESS (0x51)
#define PCF8563_STAT1_REG (0x00)
#define PCF8563_STAT2_REG (0x01)
#define PCF8563_SEC_REG (0x02)
#define PCF8563_MIN_REG (0x03)
#define PCF8563_HR_REG (0x04)
#define PCF8563_DAY_REG (0x05)
#define PCF8563_WEEKDAY_REG (0x06)
#define PCF8563_MONTH_REG (0x07)
#define PCF8563_YEAR_REG (0x08)
#define PCF8563_ALRM_MIN_REG (0x09)
#define PCF8563_SQW_REG (0x0D)
#define PCF8563_TIMER1_REG (0x0E)
#define PCF8563_TIMER2_REG (0x0F)
#define PCF8563_VOL_LOW_MASK (0x80)
#define PCF8563_MINUTES_MASK (0x7F)
#define PCF8563_HOUR_MASK (0x3F)
#define PCF8563_WEEKDAY_MASK (0x07)
#define PCF8563_CENTURY_MASK (0x80)
#define PCF8563_DAY_MASK (0x3F)
#define PCF8563_MONTH_MASK (0x1F)
#define PCF8563_TIMER_CTL_MASK (0x03)
#define PCF8563_ALARM_AF (0x08)
#define PCF8563_TIMER_TF (0x04)
#define PCF8563_ALARM_AIE (0x02)
#define PCF8563_TIMER_TIE (0x01)
#define PCF8563_TIMER_TE (0x80)
#define PCF8563_TIMER_TD10 (0x03)
#define PCF8563_NO_ALARM (0xFF)
#define PCF8563_ALARM_ENABLE (0x80)
#define PCF8563_CLK_ENABLE (0x80)

View File

@@ -0,0 +1,53 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file QMC6310Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2022-10-16
*
*/
#pragma once
// @brief device address
#define QMC6310_SLAVE_ADDRESS (0x1C)
#define QMC6310_DEFAULT_ID (0x80)
#define QMC6310_REG_CHIP_ID (0x00)
#define QMC6310_REG_LSB_DX (0X01)
#define QMC6310_REG_MSB_DX (0X02)
#define QMC6310_REG_LSB_DY (0X03)
#define QMC6310_REG_MSB_DY (0X04)
#define QMC6310_REG_LSB_DZ (0X05)
#define QMC6310_REG_MSB_DZ (0X06)
#define QMC6310_REG_STAT (0X09)
#define QMC6310_REG_CMD1 (0x0A)
#define QMC6310_REG_CMD2 (0x0B)
#define QMC6310_REG_SIGN (0x29)

View File

@@ -0,0 +1,133 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file QMI8658Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2022-10-16
*
*/
#pragma once
// @brief device address
#define QMI8658_L_SLAVE_ADDRESS (0x6B)
#define QMI8658_H_SLAVE_ADDRESS (0x6A)
// @brief registers default value
#define QMI8658_REG_WHOAMI_DEFAULT (0x05)
#define QMI8658_REG_STATUS_DEFAULT (0x03)
#define QMI8658_REG_RESET_DEFAULT (0xB0)
// @brief registers list
#define QMI8658_REG_WHOAMI (0x00)
#define QMI8658_REG_REVISION (0x01)
#define QMI8658_REG_CTRL1 (0x02)
#define QMI8658_REG_CTRL2 (0x03)
#define QMI8658_REG_CTRL3 (0x04)
// #define QMI8658_REG_CTRL4 (0x05)
#define QMI8658_REG_CTRL5 (0x06)
// #define QMI8658_REG_CTRL6 (0x07)
#define QMI8658_REG_CTRL7 (0x08)
#define QMI8658_REG_CTRL8 (0x09)
#define QMI8658_REG_CTRL9 (0x0A)
#define QMI8658_REG_CAL1_L (0x0B)
#define QMI8658_REG_CAL1_H (0x0C)
#define QMI8658_REG_CAL2_L (0x0D)
#define QMI8658_REG_CAL2_H (0x0E)
#define QMI8658_REG_CAL3_L (0x0F)
#define QMI8658_REG_CAL3_H (0x10)
#define QMI8658_REG_CAL4_L (0x11)
#define QMI8658_REG_CAL4_H (0x12)
#define QMI8658_REG_FIFOWMKTH (0x13)
#define QMI8658_REG_FIFOCTRL (0x14)
#define QMI8658_REG_FIFOCOUNT (0x15)
#define QMI8658_REG_FIFOSTATUS (0x16)
#define QMI8658_REG_FIFODATA (0x17)
// #define QMI8658_REG_STATUSI2CM (0x2C)
#define QMI8658_REG_STATUSINT (0x2D)
#define QMI8658_REG_STATUS0 (0x2E)
#define QMI8658_REG_STATUS1 (0x2F)
#define QMI8658_REG_TIMESTAMP_L (0x30)
#define QMI8658_REG_TIMESTAMP_M (0x31)
#define QMI8658_REG_TIMESTAMP_H (0x32)
#define QMI8658_REG_TEMPEARTURE_L (0x33)
#define QMI8658_REG_TEMPEARTURE_H (0x34)
#define QMI8658_REG_AX_L (0x35)
#define QMI8658_REG_AX_H (0x36)
#define QMI8658_REG_AY_L (0x37)
#define QMI8658_REG_AY_H (0x38)
#define QMI8658_REG_AZ_L (0x39)
#define QMI8658_REG_AZ_H (0x3A)
#define QMI8658_REG_GX_L (0x3B)
#define QMI8658_REG_GX_H (0x3C)
#define QMI8658_REG_GY_L (0x3D)
#define QMI8658_REG_GY_H (0x3E)
#define QMI8658_REG_GZ_L (0x3F)
#define QMI8658_REG_GZ_H (0x40)
#define QMI8658_REG_COD_STATUS (0x46)
#define QMI8658_REG_DQW_L (0x49)
#define QMI8658_REG_DQW_H (0x4A)
#define QMI8658_REG_DQX_L (0x4B)
#define QMI8658_REG_DQX_H (0x4C)
#define QMI8658_REG_DQY_L (0x4D)
#define QMI8658_REG_DQY_H (0x4E)
#define QMI8658_REG_DQZ_L (0x4F)
#define QMI8658_REG_DQZ_H (0x50)
#define QMI8658_REG_DVX_L (0x51)
#define QMI8658_REG_DVX_H (0x52)
#define QMI8658_REG_DVY_L (0x53)
#define QMI8658_REG_DVY_H (0x54)
#define QMI8658_REG_DVZ_L (0x55)
#define QMI8658_REG_DVZ_H (0x56)
#define QMI8658_REG_TAP_STATUS (0x59)
#define QMI8658_REG_PEDO_L (0x5A)
#define QMI8658_REG_PEDO_M (0x5B)
#define QMI8658_REG_PEDO_H (0x5C)
#define QMI8658_REG_RESET (0x60)
#define QMI8658_REG_RST_RESULT (0x4D)
#define QMI8658_REG_RST_RESULT_VAL (0x80)
#define STATUS0_ACCE_AVAIL (0x01)
#define STATUS0_GYRO_AVAIL (0x02)
#define QMI8658_ACCEL_LPF_MASK (0xF9)
#define QMI8658_GYRO_LPF_MASK (0x9F)
#define QMI8658_ACCEL_EN_MASK (0x01)
#define QMI8658_GYRO_EN_MASK (0x02)
#define QMI8658_ACCEL_GYRO_EN_MASK (0x03)
#define QMI8658_FIFO_MAP_INT1 0x04 // ctrl1

View File

@@ -0,0 +1,33 @@
#pragma once
// A0, A1, A2 connect to GND
#define XL9555_UNKOWN_ADDRESS (0xFF)
#define XL9555_SLAVE_ADDRESS0 (0x20)
#define XL9555_SLAVE_ADDRESS1 (0x21)
#define XL9555_SLAVE_ADDRESS2 (0x22)
#define XL9555_SLAVE_ADDRESS3 (0x23)
#define XL9555_SLAVE_ADDRESS4 (0x24)
#define XL9555_SLAVE_ADDRESS5 (0x25)
#define XL9555_SLAVE_ADDRESS6 (0x26)
#define XL9555_SLAVE_ADDRESS7 (0x27)
// Input Port 0 /R
#define XL9555_CTRL_INP0 (0x00)
// Input Port 1 /R
#define XL9555_CTRL_INP1 (0x01)
// Output Port 0 /RW
#define XL9555_CTRL_OUTP0 (0x02)
// Output Port 1 /RW
#define XL9555_CTRL_OUTP1 (0x03)
// Polarity Inversion Port 0 /RW
#define XL9555_CTRL_PIP0 (0x04)
// Polarity Inversion Port 1 /RW
#define XL9555_CTRL_PIP1 (0x05)
// Configuration Port 0 /RW
#define XL9555_CTRL_CFG0 (0x06)
// Configuration Port 1 /RW
#define XL9555_CTRL_CFG1 (0x07)
#define XL9555_MAX_PIN (15)

View File

@@ -0,0 +1,36 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorBHI260AP.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2024-05-27
*
*/
#include "SensorBHI260AP.hpp"
#if defined(ARDUINO)
volatile bool SensorBHI260AP::__data_available;
#endif

View File

@@ -0,0 +1,802 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorBHI260AP.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-06
* @note Most source code references come from the https://github.com/boschsensortec/BHY2-Sensor-API
* Simplification for Arduino
*/
#pragma once
#if defined(ARDUINO)
#include "bosch/BoschParse.h"
#include "bosch/SensorBhy2Define.h"
#include "bosch/firmware/BHI260AP.fw.h"
class SensorBHI260AP
{
friend class BoschParse;
public:
SensorBHI260AP(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BHI260AP_SLAVE_ADDRESS_L)
{
__handler.u.i2c_dev.scl = scl;
__handler.u.i2c_dev.sda = sda;
__handler.u.i2c_dev.addr = addr;
__handler.u.i2c_dev.wire = &w;
__handler.intf = SENSORLIB_I2C_INTERFACE;
}
SensorBHI260AP(int cs, int mosi = -1, int miso = -1, int sck = -1,
PLATFORM_SPI_TYPE &spi = SPI
)
{
__handler.u.spi_dev.cs = cs;
__handler.u.spi_dev.miso = miso;
__handler.u.spi_dev.mosi = mosi;
__handler.u.spi_dev.sck = sck;
__handler.u.spi_dev.spi = &spi;
__handler.intf = SENSORLIB_SPI_INTERFACE;
}
~SensorBHI260AP()
{
deinit();
}
SensorBHI260AP()
{
memset(&__handler, 0, sizeof(__handler));
}
void setPins(int rst, int irq)
{
__handler.irq = irq;
__handler.rst = rst;
}
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BHI260AP_SLAVE_ADDRESS_L)
{
__handler.u.i2c_dev.scl = scl;
__handler.u.i2c_dev.sda = sda;
__handler.u.i2c_dev.addr = addr;
__handler.u.i2c_dev.wire = &w;
__handler.intf = SENSORLIB_I2C_INTERFACE;
return initImpl();
}
bool init(
PLATFORM_SPI_TYPE &spi,
int cs, int mosi = MOSI, int miso = MISO, int sck = SCK)
{
__handler.u.spi_dev.cs = cs;
__handler.u.spi_dev.miso = miso;
__handler.u.spi_dev.mosi = mosi;
__handler.u.spi_dev.sck = sck;
__handler.u.spi_dev.spi = &spi;
__handler.intf = SENSORLIB_SPI_INTERFACE;
return initImpl();
}
bool init()
{
return initImpl();
}
void deinit()
{
if (__pro_buf) {
free(__pro_buf);
}
__pro_buf = NULL;
if (bhy2) {
free(bhy2);
bhy2 = NULL;
}
if (__handler.irq != SENSOR_PIN_NONE) {
detachInterrupt(__handler.irq);
}
// end();
}
void reset()
{
if (__handler.rst != SENSOR_PIN_NONE) {
digitalWrite(__handler.rst, HIGH);
delay(5);
digitalWrite(__handler.rst, LOW);
delay(10);
digitalWrite(__handler.rst, HIGH);
delay(5);
}
}
void update()
{
if (!__pro_buf) {
return;
}
if (__handler.irq != SENSOR_PIN_NONE) {
if (__data_available) {
bhy2_get_and_process_fifo(__pro_buf, __pro_buf_size, bhy2);
}
} else {
bhy2_get_and_process_fifo(__pro_buf, __pro_buf_size, bhy2);
}
}
void setBootFormFlash(bool boot_from_flash)
{
__boot_from_flash = boot_from_flash;
}
bhy2_dev *getHandler()
{
return bhy2;
}
void printSensors(Stream &port)
{
uint8_t cnt = 0;
bool presentBuff[256];
for (uint16_t i = 0; i < sizeof(bhy2->present_buff); i++) {
for (uint8_t j = 0; j < 8; j++) {
presentBuff[i * 8 + j] = ((bhy2->present_buff[i] >> j) & 0x01);
}
}
port.println("Present sensors: ");
for (int i = 0; i < (int)sizeof(presentBuff); i++) {
if (presentBuff[i]) {
cnt++;
port.print(i);
port.print(" - ");
port.print(get_sensor_name(i));
port.println();
}
}
port.printf("Total %u Sensor online .\n", cnt);
}
bool printInfo(Stream &stream)
{
uint16_t kernel_version = 0, user_version = 0;
uint16_t rom_version = 0;
uint8_t product_id = 0;
uint8_t host_status = 0, feat_status = 0;
uint8_t boot_status = 0;
uint8_t sensor_error;
struct bhy2_sensor_info info;
/* Get product_id */
__error_code = (bhy2_get_product_id(&product_id, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_product_id failed!", false);
/* Get Kernel version */
__error_code = (bhy2_get_kernel_version(&kernel_version, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_kernel_version failed!", false);
/* Get User version */
__error_code = (bhy2_get_user_version(&user_version, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_user_version failed!", false);
/* Get ROM version */
__error_code = (bhy2_get_rom_version(&rom_version, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_rom_version failed!", false);
__error_code = (bhy2_get_host_status(&host_status, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_host_status failed!", false);
__error_code = (bhy2_get_feature_status(&feat_status, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_feature_status failed!", false);
stream.printf("Product ID : %02x\n", product_id);
stream.printf("Kernel version : %04u\n", kernel_version);
stream.printf("User version : %04u\n", user_version);
stream.printf("ROM version : %04u\n", rom_version);
stream.printf("Power state : %s\n", (host_status & BHY2_HST_POWER_STATE) ? "sleeping" : "active");
stream.printf("Host interface : %s\n", (host_status & BHY2_HST_HOST_PROTOCOL) ? "SPI" : "I2C");
stream.printf("Feature status : 0x%02x\n", feat_status);
/* Read boot status */
__error_code = (bhy2_get_boot_status(&boot_status, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false);
stream.printf("Boot Status : 0x%02x: ", boot_status);
if (boot_status & BHY2_BST_FLASH_DETECTED) {
stream.println("\tFlash detected. ");
}
if (boot_status & BHY2_BST_FLASH_VERIFY_DONE) {
stream.println("\tFlash verify done. ");
}
if (boot_status & BHY2_BST_FLASH_VERIFY_ERROR) {
stream.println("Flash verification failed. ");
}
if (boot_status & BHY2_BST_NO_FLASH) {
stream.println("\tNo flash installed. ");
}
if (boot_status & BHY2_BST_HOST_INTERFACE_READY) {
stream.println("\tHost interface ready. ");
}
if (boot_status & BHY2_BST_HOST_FW_VERIFY_DONE) {
stream.println("\tFirmware verification done. ");
}
if (boot_status & BHY2_BST_HOST_FW_VERIFY_ERROR) {
stream.println("\tFirmware verification error. ");
}
if (boot_status & BHY2_BST_HOST_FW_IDLE) {
stream.println("\tFirmware halted. ");
}
/* Read error value */
__error_code = (bhy2_get_error_value(&sensor_error, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_error_value failed!", false);
if (sensor_error) {
log_e("%s", get_sensor_error_text(sensor_error));
}
if (feat_status & BHY2_FEAT_STATUS_OPEN_RTOS_MSK) {
bhy2_update_virtual_sensor_list(bhy2);
/* Get present virtual sensor */
bhy2_get_virt_sensor_list(bhy2);
stream.printf("Virtual sensor list.\r\n");
stream.printf("Sensor ID | Sensor Name | ID | Ver | Min rate | Max rate |\r\n");
stream.printf("----------+--------------------------------------+-----+-----+-----------+-----------|\r\n");
for (uint8_t i = 0; i < BHY2_SENSOR_ID_MAX; i++) {
if (bhy2_is_sensor_available(i, bhy2)) {
if (i < BHY2_SENSOR_ID_CUSTOM_START) {
stream.printf(" %8u | %36s ", i, get_sensor_name(i));
}
__error_code = (bhy2_get_sensor_info(i, &info, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_sensor_info failed!", false);
stream.printf("| %3u | %3u | %9.4f | %9.4f |\r\n",
info.driver_id,
info.driver_version,
info.min_rate.f_val,
info.max_rate.f_val);
}
}
}
return true;
}
bool setInterruptCtrl(uint8_t data)
{
__error_code = bhy2_set_host_interrupt_ctrl(data, bhy2);
if (__error_code != BHY2_OK) {
return false;
}
}
uint8_t getInterruptCtrl()
{
uint8_t data;
__error_code = bhy2_get_host_interrupt_ctrl(&data, bhy2);
if (__error_code != BHY2_OK) {
return 0;
}
return data;
}
void printInterruptCtrl(Stream &stream)
{
uint8_t data;
__error_code = bhy2_get_host_interrupt_ctrl(&data, bhy2);
if (__error_code != BHY2_OK) {
return ;
}
stream.printf("Host interrupt control\r\n");
stream.printf("-- Wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_W) ? "disabled" : "enabled");
stream.printf("-- Non wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_NW) ? "disabled" : "enabled");
stream.printf("-- Status FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_STATUS_FIFO) ? "disabled" : "enabled");
stream.printf("-- Debugging %s.\r\n", (data & BHY2_ICTL_DISABLE_DEBUG) ? "disabled" : "enabled");
stream.printf("-- Fault %s.\r\n", (data & BHY2_ICTL_DISABLE_FAULT) ? "disabled" : "enabled");
stream.printf("-- Interrupt is %s.\r\n", (data & BHY2_ICTL_ACTIVE_LOW) ? "active low" : "active high");
stream.printf("-- Interrupt is %s triggered.\r\n", (data & BHY2_ICTL_EDGE) ? "pulse" : "level");
stream.printf("-- Interrupt pin drive is %s.\r\n", (data & BHY2_ICTL_OPEN_DRAIN) ? "open drain" : "push-pull");
}
bool isReady()
{
uint8_t boot_status = 0;
__error_code = bhy2_get_boot_status(&boot_status, bhy2);
log_i("boot_status:0x%x", boot_status);
if (__error_code != BHY2_OK) {
return false;
}
return (boot_status & BHY2_BST_HOST_INTERFACE_READY);
}
uint16_t getKernelVersion()
{
uint16_t version = 0;
__error_code = bhy2_get_kernel_version(&version, bhy2);
if ((__error_code != BHY2_OK) && (version == 0)) {
return 0;
}
log_d("Boot successful. Kernel version %u.", version);
return version;
}
void onEvent(BhySensorEvent event_id, BhyEventCb callback)
{
SensorEventCbList_t newEventHandler;
newEventHandler.cb = callback;
newEventHandler.event = event_id;
BoschParse::bhyEventVector.push_back(newEventHandler);
}
void removeEvent(BhySensorEvent event_id, BhyEventCb callback)
{
if (!callback) {
return;
}
for (uint32_t i = 0; i < BoschParse::bhyEventVector.size(); i++) {
SensorEventCbList_t entry = BoschParse::bhyEventVector[i];
if (entry.cb == callback && entry.event == event_id) {
BoschParse::bhyEventVector.erase(BoschParse::bhyEventVector.begin() + i);
}
}
}
void onResultEvent(BhySensorID sensor_id, BhyParseDataCallback callback)
{
ParseCallBackList_t newEventHandler;
newEventHandler.cb = callback;
newEventHandler.id = sensor_id;
BoschParse::bhyParseEventVector.push_back(newEventHandler);
}
void removeResultEvent(BhySensorID sensor_id, BhyParseDataCallback callback)
{
if (!callback) {
return;
}
for (uint32_t i = 0; i < BoschParse::bhyParseEventVector.size(); i++) {
ParseCallBackList_t entry = BoschParse::bhyParseEventVector[i];
if (entry.cb == callback && entry.id == sensor_id) {
BoschParse::bhyParseEventVector.erase(BoschParse::bhyParseEventVector.begin() + i);
}
}
}
void setProcessBufferSize(uint32_t size)
{
__pro_buf_size = size;
}
bool uploadFirmware(const uint8_t *firmware, uint32_t length, bool write2Flash = false)
{
uint8_t sensor_error;
uint8_t boot_status;
log_i("Upload Firmware ...");
__error_code = bhy2_get_boot_status(&boot_status, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false);
if (write2Flash) {
if (boot_status & BHY2_BST_FLASH_DETECTED) {
uint32_t start_addr = BHY2_FLASH_SECTOR_START_ADDR;
uint32_t end_addr = start_addr + length;
log_i("Flash detected. Erasing flash to upload firmware");
__error_code = bhy2_erase_flash(start_addr, end_addr, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_erase_flash failed!", false);
} else {
log_e("Flash not detected");
return false;
}
printf("Loading firmware into FLASH.");
__error_code = bhy2_upload_firmware_to_flash(firmware, length, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_upload_firmware_to_flash failed!", false);
} else {
log_i("Loading firmware into RAM.");
log_i("upload size = %lu", length);
__error_code = bhy2_upload_firmware_to_ram(firmware, length, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_upload_firmware_to_ram failed!", false);
}
log_i("Loading firmware into RAM Done");
__error_code = bhy2_get_error_value(&sensor_error, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_error_value failed!", false);
if (sensor_error != BHY2_OK) {
__error_code = bhy2_get_error_value(&sensor_error, bhy2);
log_e("%s", get_sensor_error_text(sensor_error));
return false;
}
if (write2Flash) {
log_i("Booting from FLASH.");
__error_code = bhy2_boot_from_flash(bhy2);
} else {
log_i("Booting from RAM.");
__error_code = bhy2_boot_from_ram(bhy2);
}
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2 boot failed!", false);
__error_code = bhy2_get_error_value(&sensor_error, bhy2);
if (sensor_error) {
log_e("%s", get_sensor_error_text(sensor_error));
return false;
}
return sensor_error == BHY2_OK;
}
String getError()
{
String err = get_api_error(__error_code);
err += " Code:" + String(__error_code);
return err;
}
bool configure(uint8_t sensor_id, float sample_rate, uint32_t report_latency_ms)
{
if (!bhy2_is_sensor_available(sensor_id, bhy2)) {
log_e("Sensor not present"); return false;
}
__error_code = bhy2_set_virt_sensor_cfg(sensor_id, sample_rate, report_latency_ms, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_virt_sensor_cfg failed!", false);
log_i("Enable %s at %.2fHz.", get_sensor_name(sensor_id), sample_rate);
return true;
}
struct bhy2_virt_sensor_conf getConfigure(uint8_t sensor_id)
{
bhy2_virt_sensor_conf conf;
bhy2_get_virt_sensor_cfg(sensor_id, &conf, bhy2);
log_i("range:%u sample_rate:%f latency:%lu sensitivity:%u\n", conf.range, conf.sample_rate, conf.latency, conf.sensitivity);
return conf;
}
float getScaling(uint8_t sensor_id)
{
return get_sensor_default_scaling(sensor_id);
}
void setFirmware(const uint8_t *image, size_t image_len, bool write_flash)
{
__firmware = image;
__firmware_size = image_len;
__write_flash = write_flash;
}
static const char *getSensorName(uint8_t sensor_id)
{
return get_sensor_name(sensor_id);
}
// Get an accuracy report
uint8_t getAccuracy()
{
return __accuracy;
}
private:
bool bootFromFlash()
{
int8_t rslt;
uint8_t boot_status, feat_status;
uint8_t error_val = 0;
uint16_t tries = 300; /* Wait for up to little over 3s */
log_d("Waiting for firmware verification to complete");
do {
__error_code = bhy2_get_boot_status(&boot_status, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false);
if (boot_status & BHY2_BST_FLASH_VERIFY_DONE) {
break;
}
delay(10);
} while (tries--);
__error_code = bhy2_get_boot_status(&boot_status, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false);
print_boot_status(boot_status);
if (boot_status & BHY2_BST_HOST_INTERFACE_READY) {
if (boot_status & BHY2_BST_FLASH_DETECTED) {
/* If no firmware is running, boot from Flash */
log_d("Booting from flash");
rslt = bhy2_boot_from_flash(bhy2);
if (rslt != BHY2_OK) {
log_e("%s. Booting from flash failed.\r\n", get_api_error(rslt));
__error_code = bhy2_get_regs(BHY2_REG_ERROR_VALUE, &error_val, 1, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_regs failed!", false);
if (error_val) {
log_e("%s\r\n", get_sensor_error_text(error_val));
}
return false;
}
__error_code = bhy2_get_boot_status(&boot_status, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_boot_status failed!", false);
print_boot_status(boot_status);
if (!(boot_status & BHY2_BST_HOST_INTERFACE_READY)) {
/* hub is not ready, need reset hub */
log_d("Host interface is not ready, triggering a reset");
__error_code = bhy2_soft_reset(bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_soft_reset failed!", false);
}
__error_code = (bhy2_get_feature_status(&feat_status, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "Reading Feature status failed, booting from flash failed!", false);
} else {
log_e("Can't detect external flash");
return false;
}
} else {
log_e("Host interface is not ready");
return false;
}
log_d("Booting from flash successful");
return true;
}
void print_boot_status(uint8_t boot_status)
{
log_d("Boot Status : 0x%02x: ", boot_status);
if (boot_status & BHY2_BST_FLASH_DETECTED) {
log_d("Flash detected. ");
}
if (boot_status & BHY2_BST_FLASH_VERIFY_DONE) {
log_d("Flash verify done. ");
}
if (boot_status & BHY2_BST_FLASH_VERIFY_ERROR) {
log_d("Flash verification failed. ");
}
if (boot_status & BHY2_BST_NO_FLASH) {
log_d("No flash installed. ");
}
if (boot_status & BHY2_BST_HOST_INTERFACE_READY) {
log_d("Host interface ready. ");
}
if (boot_status & BHY2_BST_HOST_FW_VERIFY_DONE) {
log_d("Firmware verification done. ");
}
if (boot_status & BHY2_BST_HOST_FW_VERIFY_ERROR) {
log_d("Firmware verification error. ");
}
if (boot_status & BHY2_BST_HOST_FW_IDLE) {
log_d("Firmware halted. ");
}
}
static void handleISR()
{
__data_available = true;
}
bool initImpl()
{
uint8_t product_id = 0;
if (__handler.rst != SENSOR_PIN_NONE) {
pinMode(__handler.rst, OUTPUT);
}
reset();
bhy2 = (struct bhy2_dev *)malloc(sizeof(struct bhy2_dev ));
BHY2_RLST_CHECK(!bhy2, " Device handler malloc failed!", false);
switch (__handler.intf) {
case BHY2_I2C_INTERFACE:
// esp32s3 test I2C maximum read and write is 64 bytes
__max_rw_length = 64;
BHY2_RLST_CHECK(!__handler.u.i2c_dev.wire, "Wire ptr NULL", false);
if (!SensorInterfaces::setup_interfaces(__handler)) {
log_e("setup_interfaces failed");
return false;
}
__error_code = bhy2_init(BHY2_I2C_INTERFACE,
SensorInterfaces::bhy2_i2c_read,
SensorInterfaces::bhy2_i2c_write,
SensorInterfaces::bhy2_delay_us,
__max_rw_length, &__handler, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_init failed!", false);
// __error_code = bhy2_set_host_intf_ctrl(BHY2_I2C_INTERFACE, bhy2);
// BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_host_intf_ctrl failed!", false);
break;
case BHY2_SPI_INTERFACE:
// esp32s3 test SPI maximum read and write is 256 bytes
__max_rw_length = 256;
BHY2_RLST_CHECK(!__handler.u.spi_dev.spi, "SPI ptr NULL", false);
if (!SensorInterfaces::setup_interfaces(__handler)) {
log_e("setup_interfaces failed");
return false;
}
__error_code = bhy2_init(BHY2_SPI_INTERFACE,
SensorInterfaces::bhy2_spi_read,
SensorInterfaces::bhy2_spi_write,
SensorInterfaces::bhy2_delay_us,
__max_rw_length,
&__handler,
bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_init failed!", false);
// __error_code = bhy2_set_host_intf_ctrl(BHY2_SPI_INTERFACE, bhy2);
// BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_host_intf_ctrl failed!", false);
break;
default:
return false;
}
__error_code = bhy2_soft_reset(bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "reset bhy2 failed!", false);
__error_code = bhy2_get_product_id(&product_id, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_product_id failed!", false);
/* Check for a valid product ID */
if (product_id != BHY2_PRODUCT_ID) {
log_e("Product ID read %X. Expected %X", product_id, BHY2_PRODUCT_ID);
return false;
} else {
log_i("BHI260/BHA260 found. Product ID read %X", product_id);
}
if (!__firmware) {
// Default write to ram
setFirmware(bhy2_firmware_image, sizeof(bhy2_firmware_image), false);
}
if (__boot_from_flash) {
if (!bootFromFlash()) {
//** If the boot from flash fails, re-upload the firmware to flash
__error_code = bhy2_soft_reset(bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "reset bhy2 failed!", false);
if (!uploadFirmware(__firmware, __firmware_size, __write_flash)) {
log_e("uploadFirmware failed!");
return false;
}
}
} else {
// ** Upload firmware to RAM
if (!uploadFirmware(__firmware, __firmware_size, __write_flash)) {
log_e("uploadFirmware failed!");
return false;
}
}
uint16_t version = getKernelVersion();
BHY2_RLST_CHECK(!version, "getKernelVersion failed!", false);
log_i("Boot successful. Kernel version %u.", version);
//Set event callback
__error_code = bhy2_register_fifo_parse_callback(BHY2_SYS_ID_META_EVENT, BoschParse::parseMetaEvent, (void *)&__accuracy, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_register_fifo_parse_callback failed!", false);
__error_code = bhy2_register_fifo_parse_callback(BHY2_SYS_ID_META_EVENT_WU, BoschParse::parseMetaEvent, (void *)&__accuracy, bhy2);
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_register_fifo_parse_callback failed!", false);
// __error_code = bhy2_register_fifo_parse_callback(BHY2_SYS_ID_DEBUG_MSG, BoschParse::parseDebugMessage, NULL, bhy2);
// BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_register_fifo_parse_callback parseDebugMessage failed!", false);
//Set process buffer
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32)) && defined(BOARD_HAS_PSRAM)
__pro_buf = (uint8_t *)ps_malloc(__pro_buf_size);
#else
__pro_buf = (uint8_t *)malloc(__pro_buf_size);
#endif
BHY2_RLST_CHECK(!__pro_buf, "process buffer malloc failed!", false);
__error_code = bhy2_get_and_process_fifo(__pro_buf, __pro_buf_size, bhy2);
if (__error_code != BHY2_OK) {
log_e("bhy2_get_and_process_fifo failed");
free(__pro_buf);
return false;
}
/* Update the callback table to enable parsing of sensor hintr_ctrl */
bhy2_update_virtual_sensor_list(bhy2);
/* Get present virtual sensor */
bhy2_get_virt_sensor_list(bhy2);
// Only register valid sensor IDs
for (uint8_t i = 0; i < BHY2_SENSOR_ID_MAX; i++) {
if (bhy2_is_sensor_available(i, bhy2)) {
bhy2_register_fifo_parse_callback(i, BoschParse::parseData, NULL, bhy2);
}
}
if (__handler.irq != SENSOR_PIN_NONE) {
#if defined(ARDUINO_ARCH_RP2040)
attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING);
#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32)
attachInterrupt(__handler.irq, handleISR, RISING);
#else
#error "Interrupt registration not implemented"
#endif
}
return __error_code == BHY2_OK;
}
protected:
struct bhy2_dev *bhy2 = NULL;
SensorLibConfigure __handler;
int8_t __error_code;
static volatile bool __data_available;
uint8_t *__pro_buf = NULL;
size_t __pro_buf_size = BHY_PROCESS_BUFFER_SIZE;
const uint8_t *__firmware;
size_t __firmware_size;
bool __write_flash;
bool __boot_from_flash;
uint16_t __max_rw_length;
uint8_t __accuracy; /* Accuracy is reported as a meta event. */
};
#endif /*defined(ARDUINO)*/

View File

@@ -0,0 +1,846 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorBMA423.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-03-31
* @note Most source code references come from the https://github.com/boschsensortec/BMA423-Sensor-API
* Simplification for Arduino
*/
#pragma once
#include "REG/BMA423Constants.h"
#include "SensorCommon.tpp"
class SensorBMA423 :
public SensorCommon<SensorBMA423>
{
friend class SensorCommon<SensorBMA423>;
public:
enum AccelRange {
RANGE_2G,
RANGE_4G,
RANGE_8G,
RANGE_16G
};
/*! Output data rate in Hz */
enum AccelODR {
ODR_0_78HZ = 1,
ODR_1_56HZ,
ODR_3_12HZ,
ODR_6_25HZ,
ODR_12_5HZ,
ODR_25HZ,
ODR_50HZ,
ODR_100HZ,
ODR_200HZ,
ODR_400HZ,
ODR_800HZ,
ODR_1600HZ,
};
/*! Bandwidth parameter, determines filter configuration */
enum BandWidth {
BW_OSR4_AVG1,
BW_OSR2_AVG2,
BW_NORMAL_AVG4,
BW_CIC_AVG8,
BW_RES_AVG16,
BW_RES_AVG32,
BW_RES_AVG64,
BW_RES_AVG128,
};
enum PerformanceMode {
PERF_CIC_AVG_MODE,
PERF_CONTINUOUS_MODE,
};
enum TemperatureUnit {
TEMP_DEG,
TEMP_FAHREN,
TEMP_KELVIN,
};
// Calculate direction facing the front of the chip
enum SensorDir {
DIRECTION_BOTTOM_LEFT,
DIRECTION_TOP_RIGHT,
DIRECTION_TOP_LEFT,
DIRECTION_BOTTOM_RIGHT,
DIRECTION_BOTTOM,
DIRECTION_TOP
};
// Chip orientation and orientation
enum SensorRemap {
// Top right corner
REMAP_TOP_LAYER_RIGHT_CORNER,
// Front bottom left corner
REMAP_TOP_LAYER_BOTTOM_LEFT_CORNER,
// Top left corner
REMAP_TOP_LAYER_LEFT_CORNER,
// Top bottom right corner
REMAP_TOP_LAYER_BOTTOM_RIGHT_CORNER,
// Bottom top right corner
REMAP_BOTTOM_LAYER_TOP_RIGHT_CORNER,
// Bottom bottom left corner
REMAP_BOTTOM_LAYER_BOTTOM_LEFT_CORNER,
// Bottom bottom right corner
REMAP_BOTTOM_LAYER_BOTTOM_RIGHT_CORNER,
// Bottom top left corner
REMAP_BOTTOM_LAYER_TOP_LEFT_CORNER,
};
enum Feature {
/**\name Feature enable macros for the sensor */
FEATURE_STEP_CNTR = 0x01,
/**\name Below macros are mutually exclusive */
FEATURE_ANY_MOTION = 0x02,
FEATURE_NO_MOTION = 0x04,
FEATURE_ACTIVITY = 0x08,
FEATURE_TILT = 0x10,
FEATURE_WAKEUP = 0x20,
};
/**\name Interrupt status macros */
enum FeatureInterrupt {
INT_STEP_CNTR = 0x02,
INT_ACTIVITY = 0x04,
INT_TILT = 0x05,
INT_WAKEUP = 0x20,
INT_ANY_NO_MOTION = 0x40,
};
#if defined(ARDUINO)
SensorBMA423(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMA423_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorBMA423()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = BMA423_SLAVE_ADDRESS;
}
~SensorBMA423()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMA423_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void reset()
{
writeRegister(BMA423_RESET_REG, 0xB6);
delay(20);
}
bool enablePowerSave()
{
uint8_t val;
val = readRegister(BMA4_POWER_CONF_ADDR);
val |= BMA4_ADVANCE_POWER_SAVE_MSK;
writeRegister(BMA4_POWER_CONF_ADDR, val);
return true;
}
bool disablePowerSave()
{
uint8_t val;
val = readRegister(BMA4_POWER_CONF_ADDR);
val &= ~(BMA4_ADVANCE_POWER_SAVE_MSK);
writeRegister(BMA4_POWER_CONF_ADDR, val);
return true;
}
void disableInterruptCtrl()
{
writeRegister(BMA4_INIT_CTRL_ADDR, 0x00);
}
void enableInterruptCtrl()
{
writeRegister(BMA4_INIT_CTRL_ADDR, 0x01);
}
bool enableAccelerometer()
{
uint8_t val;
val = readRegister(BMA4_POWER_CTRL_ADDR);
val |= BMA4_ACCEL_ENABLE_MSK;
writeRegister(BMA4_POWER_CTRL_ADDR, val);
return true;
}
bool disableAccelerometer()
{
uint8_t val;
val = readRegister( BMA4_POWER_CTRL_ADDR);
val &= (~BMA4_ACCEL_ENABLE_MSK);
writeRegister(BMA4_POWER_CTRL_ADDR, val);
return true;
}
bool configAccelerometer(AccelRange range = RANGE_4G, AccelODR odr = ODR_200HZ,
BandWidth bw = BW_NORMAL_AVG4,
PerformanceMode perfMode = PERF_CONTINUOUS_MODE)
{
uint8_t buffer[2] = {0, 0};
if (perfMode == PERF_CONTINUOUS_MODE) {
if (bw > BW_NORMAL_AVG4) {
return false;
}
} else if (perfMode == PERF_CIC_AVG_MODE) {
if (bw > BW_RES_AVG128) {
return false;
}
} else {
return false;
}
if ((odr < ODR_0_78HZ) || (odr > ODR_1600HZ)) {
return false;
}
buffer[0] = odr & 0x0F;
buffer[0] |= (uint8_t)(bw << 4);
buffer[0] |= (uint8_t)(perfMode << 7);
buffer[1] = range & 0x03;
/* Burst write is not possible in
suspend mode hence individual write is
used with delay of 1 ms */
writeRegister(BMA4_ACCEL_CONFIG_ADDR, buffer[0]);
delay(2);
writeRegister(BMA4_ACCEL_CONFIG_ADDR + 1, buffer[1]);
return true;
}
bool getAccelRaw(int16_t *rawBuffer)
{
uint8_t buffer[6] = {0};
if (readRegister(BMA4_DATA_8_ADDR, buffer, 6) != DEV_WIRE_ERR) {
/* Accel data x axis */
rawBuffer[0] = (int16_t)(buffer[1] << 8) | (buffer[0]);
/* Accel data y axis */
rawBuffer[1] = (int16_t)(buffer[3] << 8) | (buffer[2]);
/* Accel data z axis */
rawBuffer[2] = (int16_t)(buffer[5] << 8) | (buffer[4]);
} else {
return false;
}
return true;
}
bool getAccelerometer(int16_t &x, int16_t &y, int16_t &z)
{
int16_t raw[3];
if (getAccelRaw(raw)) {
x = raw[0] / 16;
y = raw[1] / 16;
z = raw[2] / 16;
return true;
}
return false;
}
float getTemperature(TemperatureUnit unit)
{
int32_t raw = readRegister(BMA4_TEMPERATURE_ADDR);
/* '0' value read from the register corresponds to 23 degree C */
raw = (raw * 1000) + (23 * 1000);
switch (unit) {
case TEMP_FAHREN:
/* Temperature in degree Fahrenheit */
/* 1800 = 1.8 * 1000 */
raw = ((raw / 1000) * 1800) + (32 * 1000);
break;
case TEMP_KELVIN:
/* Temperature in degree Kelvin */
/* 273150 = 273.15 * 1000 */
raw = raw + 273150;
break;
default:
break;
}
float res = (float)raw / (float)1000.0;
/* 0x80 - raw read from the register and 23 is the ambient raw added.
* If the raw read from register is 0x80, it means no valid
* information is available */
if (((raw - 23) / 1000) == 0x80) {
return 0;
}
return res;
}
uint8_t direction()
{
int16_t x = 0, y = 0, z = 0;
getAccelerometer(x, y, z);
uint16_t absX = abs(x);
uint16_t absY = abs(y);
uint16_t absZ = abs(z);
if ((absZ > absX) && (absZ > absY)) {
if (z > 0) {
return DIRECTION_TOP;
} else {
return DIRECTION_BOTTOM;
}
} else if ((absY > absX) && (absY > absZ)) {
if (y > 0) {
return DIRECTION_TOP_RIGHT;
} else {
return DIRECTION_BOTTOM_LEFT;
}
} else {
if (x < 0) {
return DIRECTION_BOTTOM_RIGHT;
} else {
return DIRECTION_TOP_LEFT;
}
}
return 0;
}
bool setRemapAxes(SensorRemap remap)
{
//Top
// No.1 REG: 0x3e -> 0x88 REG: 0x3f -> 0x0
// No.2 REG: 0x3e -> 0xac REG: 0x3f -> 0x0
// No.3 REG: 0x3e -> 0x85 REG: 0x3f -> 0x0
// No.4 REG: 0x3e -> 0xa1 REG: 0x3f -> 0x0
// Bottom
// No.5 REG: 0x3e -> 0x81 REG: 0x3f -> 0x1
// No.6 REG: 0x3e -> 0xa5 REG: 0x3f -> 0x1
// No.7 REG: 0x3e -> 0x8c REG: 0x3f -> 0x1
// No.8 REG: 0x3e -> 0xa8 REG: 0x3f -> 0x1
uint8_t configReg0[] = {0x88, 0xAC, 0x85, 0xA1, 0x81, 0xA5, 0x8C, 0xA8};
if (remap > sizeof(configReg0) / sizeof(configReg0[0])) {
return false;
}
uint8_t buffer[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_AXES_REMAP_OFFSET;
if (readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE) == DEV_WIRE_ERR) {
return false;
}
buffer[index] = configReg0[remap];
buffer[index + 1] = remap >= 4 ? 0x00 : 0x01;
return writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE) != DEV_WIRE_ERR;
}
bool setStepCounterWatermark(uint16_t watermark)
{
uint8_t buffer[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_STEP_CNTR_OFFSET;
uint16_t wm_lsb = 0;
uint16_t wm_msb = 0;
int rslt;
uint16_t data = 0;
rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE);
if (rslt != DEV_WIRE_ERR) {
wm_lsb = buffer[index];
wm_msb = buffer[index + 1] << 8;
data = wm_lsb | wm_msb;
/* Sets only watermark bits in the complete 16 bits of data */
data = ((data & ~(0x03FFU)) | (watermark & 0x03FFU));
/* Splits 16 bits of data to individual 8 bits data */
buffer[index] = (uint8_t)(data & 0x00FFU);
buffer[index + 1] = (uint8_t)((data & 0xFF00U) >> 8);
/* Writes stepcounter watermark settings in the sensor */
rslt = writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE);
}
return rslt != DEV_WIRE_ERR;
}
bool disablePedometer()
{
return enablePedometer(false);
}
bool enablePedometer(bool enable = true)
{
int rslt;
uint8_t buffer[BMA423_FEATURE_SIZE] = {0};
/* Step detector enable bit pos. is 1 byte ahead of the base address */
uint8_t index = BMA423_STEP_CNTR_OFFSET + 1;
rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE);
if (rslt != DEV_WIRE_ERR) {
buffer[index] = ((buffer[index] & ~0x08) | ((enable << 3) & 0x08));
rslt = writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE);
}
return rslt != DEV_WIRE_ERR;
}
uint32_t getPedometerCounter()
{
uint8_t buffer[4] = {0};
/* Reads the step counter output data from the gpio register */
int rslt = readRegister(BMA4_STEP_CNT_OUT_0_ADDR, buffer, 4);
if (rslt != DEV_WIRE_ERR) {
return ((uint32_t)buffer[0]) | ((uint32_t)buffer[1] << 8) | ((uint32_t)buffer[2] << 16) | ((uint32_t)buffer[3] << 24);
}
return DEV_WIRE_NONE;
}
void resetPedometer()
{
uint8_t buffer[BMA423_FEATURE_SIZE] = {0};
/* Reset bit is 1 byte ahead of base address */
uint8_t index = BMA423_STEP_CNTR_OFFSET + 1;
int rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE);
if (rslt != DEV_WIRE_ERR) {
buffer[index] = ((buffer[index] & ~0x04U) | ((1 << 2U) & 0x04U));
writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, BMA423_FEATURE_SIZE);
}
}
bool enableFeature(uint8_t feature, uint8_t enable)
{
uint8_t buffer[BMA423_FEATURE_SIZE] = {0};
int rslt;
uint8_t len;
/* Update the length for read and write */
update_len(&len, feature, enable);
rslt = readRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, len);
if (rslt != DEV_WIRE_ERR) {
if (enable) {
/* Enables the feature */
rslt = feature_enable(feature, len, buffer);
} else {
/* Disables the feature */
rslt = feature_disable(feature, len, buffer);
}
}
return rslt != DEV_WIRE_ERR;
}
uint16_t readIrqStatus()
{
uint8_t data[2] = {0};
if (readRegister(BMA4_INT_STAT_0_ADDR, data, 2) != DEV_WIRE_ERR) {
int_status = data[0] | (data[1] << 8);
return int_status;
}
return DEV_WIRE_NONE;
}
uint16_t getIrqStatus()
{
return int_status;
}
bool configInterrupt(
/*! Trigger condition of interrupt pin */
uint8_t edge_ctrl = BMA4_LEVEL_TRIGGER,
/*! Level of interrupt pin */
uint8_t level = BMA4_ACTIVE_HIGH,
/*! Behaviour of interrupt pin to open drain */
uint8_t od = BMA4_PUSH_PULL,
/*! Output enable for interrupt pin */
uint8_t output_en = BMA4_OUTPUT_ENABLE,
/*! Input enable for interrupt pin */
uint8_t input_en = BMA4_INPUT_DISABLE,
/*! Variable used to select the interrupt pin1 or pin2 for interrupt configuration. */
uint8_t int_line = BMA4_INTR1_MAP
)
{
uint8_t interrupt_address_array[2] = {BMA4_INT1_IO_CTRL_ADDR, BMA4_INT2_IO_CTRL_ADDR};
uint8_t data = 0;
if (int_line > 1) {
return false;
}
data = ((uint8_t)((edge_ctrl & BMA4_INT_EDGE_CTRL_MASK) |
((level << 1) & BMA4_INT_LEVEL_MASK) |
((od << 2) & BMA4_INT_OPEN_DRAIN_MASK) |
((output_en << 3) & BMA4_INT_OUTPUT_EN_MASK) |
((input_en << 4) & BMA4_INT_INPUT_EN_MASK)));
this->int_line = int_line;
return writeRegister(interrupt_address_array[int_line], &data, 1) != DEV_WIRE_ERR;
}
bool configFeatureInterrupt(uint16_t feature_interrupt_mask, bool enable)
{
return interruptMap(int_line, feature_interrupt_mask, enable);
}
bool enablePedometerIRQ()
{
return (interruptMap(int_line, INT_STEP_CNTR, true));
}
bool enableTiltIRQ()
{
return (interruptMap(int_line, INT_TILT, true));
}
bool enableWakeupIRQ()
{
return (interruptMap(int_line, INT_WAKEUP, true));
}
bool enableAnyNoMotionIRQ()
{
return (interruptMap(int_line, INT_ANY_NO_MOTION, true));
}
bool enableActivityIRQ()
{
return (interruptMap(int_line, INT_ACTIVITY, true));
}
bool disablePedometerIRQ()
{
return (interruptMap(int_line, INT_STEP_CNTR, false));
}
bool disableTiltIRQ()
{
return (interruptMap(int_line, INT_TILT, false));
}
bool disableWakeupIRQ()
{
return (interruptMap(int_line, INT_WAKEUP, false));
}
bool disableAnyNoMotionIRQ()
{
return (interruptMap(int_line, INT_ANY_NO_MOTION, false));
}
bool disableActivityIRQ()
{
return (interruptMap(int_line, INT_ACTIVITY, false));
}
inline bool isActivity()
{
return (int_status & BMA423_ACTIVITY_INT);
}
inline bool isTilt()
{
return (int_status & BMA423_TILT_INT);
}
inline bool isDoubleTap()
{
return (int_status & BMA423_WAKEUP_INT);
}
inline bool isAnyNoMotion()
{
return (int_status & BMA423_ACTIVITY_INT);
}
inline bool isPedometer()
{
return (int_status & BMA423_STEP_CNTR_INT);
}
private:
bool interruptMap(uint8_t int_line, uint16_t int_map, uint8_t enable)
{
int rslt;
uint8_t data[3] = {0, 0, 0};
uint8_t index[2] = {BMA4_INT_MAP_1_ADDR, BMA4_INT_MAP_2_ADDR};
rslt = readRegister(BMA4_INT_MAP_1_ADDR, data, 3);
if (enable) {
/* Feature interrupt mapping */
data[int_line] |= (uint8_t)(int_map & (0x00FF));
/* Hardware interrupt mapping */
if (int_line == BMA4_INTR2_MAP)
data[2] |= (uint8_t)((int_map & (0xFF00)) >> 4);
else
data[2] |= (uint8_t)((int_map & (0xFF00)) >> 8);
rslt = writeRegister(index[int_line], &data[int_line], 1);
rslt = writeRegister(BMA4_INT_MAP_DATA_ADDR, &data[2], 1);
} else {
/* Feature interrupt un-mapping */
data[int_line] &= (~(uint8_t)(int_map & (0x00FF)));
/* Hardware interrupt un-mapping */
if (int_line == BMA4_INTR2_MAP)
data[2] &= (~(uint8_t)((int_map & (0xFF00)) >> 4));
else
data[2] &= (~(uint8_t)((int_map & (0xFF00)) >> 8));
rslt = writeRegister(index[int_line], &data[int_line], 1);
rslt = writeRegister(BMA4_INT_MAP_DATA_ADDR, &data[2], 1);
}
return rslt != DEV_WIRE_ERR;
}
/*!
* @brief This API sets the interrupt mode in the sensor.
*/
bool setInterruptMode(uint8_t mode)
{
if (mode == BMA4_NON_LATCH_MODE || mode == BMA4_LATCH_MODE)
return writeRegister(BMA4_INTR_LATCH_ADDR, &mode, 1) != DEV_WIRE_ERR;
return false;
}
bool feature_disable(uint8_t feature, uint8_t len, uint8_t *buffer)
{
uint8_t index = 0;
/* Disable step counter */
if ((feature & FEATURE_STEP_CNTR) > 0) {
/* Step counter enable bit pos. is 1 byte ahead of the
base address */
index = BMA423_STEP_CNTR_OFFSET + 1;
buffer[index] = buffer[index] & (~BMA423_STEP_CNTR_EN_MSK);
}
/* Disable activity */
if ((feature & FEATURE_ACTIVITY) > 0) {
/* Activity enable bit pos. is 1 byte ahead of the
base address */
index = BMA423_STEP_CNTR_OFFSET + 1;
buffer[index] = buffer[index] & (~BMA423_ACTIVITY_EN_MSK);
}
/* Disable tilt */
if ((feature & FEATURE_TILT) > 0) {
/* Tilt enable bit pos. is the base address(0x3A) of tilt */
index = BMA423_TILT_OFFSET;
buffer[index] = buffer[index] & (~BMA423_TILT_EN_MSK);
}
/* Disable wakeup */
if ((feature & FEATURE_WAKEUP) > 0) {
/* Tilt enable bit pos. is the base address(0x38) of wakeup */
index = BMA423_WAKEUP_OFFSET;
buffer[index] = buffer[index] & (~BMA423_WAKEUP_EN_MSK);
}
/* Disable anymotion/nomotion */
if ((feature & FEATURE_ANY_MOTION) > 0 || (feature & FEATURE_NO_MOTION) > 0) {
/* Any/Nomotion enable bit pos. is 1 bytes ahead of the
any/nomotion base address(0x00) */
index = 1;
if ((feature & FEATURE_ANY_MOTION) > 0) {
/* Disable anymotion */
buffer[index] = buffer[index] | BMA423_ANY_NO_MOTION_SEL_MSK;
} else {
/* Disable nomotion */
buffer[index] = buffer[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK);
}
/* Any/Nomotion axis enable bit pos. is 3 byte ahead of the
any/nomotion base address(0x00) */
index = 3;
buffer[index] = buffer[index] & (~BMA423_ANY_NO_MOTION_AXIS_EN_MSK);
}
/* Write the configured settings in the sensor */
return writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, len) != DEV_WIRE_ERR;
}
int feature_enable(uint8_t feature, uint8_t len, uint8_t *buffer)
{
uint8_t index = 0;
/* Enable step counter */
if ((feature & FEATURE_STEP_CNTR) > 0) {
/* Step counter enable bit pos. is 1 byte ahead of the
base address */
index = BMA423_STEP_CNTR_OFFSET + 1;
buffer[index] = buffer[index] | BMA423_STEP_CNTR_EN_MSK;
}
/* Enable activity */
if ((feature & FEATURE_ACTIVITY) > 0) {
/* Activity enable bit pos. is 1 byte ahead of the
base address */
index = BMA423_STEP_CNTR_OFFSET + 1;
buffer[index] = buffer[index] | BMA423_ACTIVITY_EN_MSK;
}
/* Enable tilt */
if ((feature & FEATURE_TILT) > 0) {
/* Tilt enable bit pos. is the base address(0x3A) of tilt */
index = BMA423_TILT_OFFSET;
buffer[index] = buffer[index] | BMA423_TILT_EN_MSK;
}
/* Enable wakeup */
if ((feature & FEATURE_WAKEUP) > 0) {
/* Wakeup enable bit pos. is the base address(0x38) of wakeup */
index = BMA423_WAKEUP_OFFSET;
buffer[index] = buffer[index] | BMA423_WAKEUP_EN_MSK;
}
/* Enable anymotion/nomotion */
if ((feature & FEATURE_ANY_MOTION) > 0 || (feature & FEATURE_NO_MOTION) > 0) {
/* Any/Nomotion enable bit pos. is 1 bytes ahead of the
any/nomotion base address(0x00) */
index = 1;
if ((feature & FEATURE_ANY_MOTION) > 0) {
/* Enable anymotion */
buffer[index] = buffer[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK);
} else {
/* Enable nomotion */
buffer[index] = buffer[index] | BMA423_ANY_NO_MOTION_SEL_MSK;
}
}
/* Write the feature enable settings in the sensor */
return writeRegister(BMA4_FEATURE_CONFIG_ADDR, buffer, len) != DEV_WIRE_ERR;
}
void update_len(uint8_t *len, uint8_t feature, uint8_t enable)
{
uint8_t length = BMA423_FEATURE_SIZE;
if ((feature == FEATURE_ANY_MOTION) || (feature == FEATURE_NO_MOTION)) {
/* Change the feature length to 2 for reading and writing of 2 bytes for
any/no-motion enable */
length = BMA423_ANYMOTION_EN_LEN;
/* Read and write 4 byte to disable the any/no motion completely along with
all axis */
if (!enable) {
/*Change the feature length to 4 for reading and writing
of 4 bytes for any/no-motion enable */
length = length + 2;
}
}
*len = length;
}
bool configure()
{
uint8_t val;
val = readRegister(BMA4_INTERNAL_STAT);
if (val == BMA4_ASIC_INITIALIZED) {
log_d("No need configure!");
readIrqStatus(); //clear irq status
return true;
}
disablePowerSave();
delay(1);
disableInterruptCtrl();
const uint8_t *stream_data = bma423_config_file;
const uint8_t maxReadWriteLenght = 32;
for (size_t index = 0; index < BMA4_CONFIG_STREAM_SIZE; index += maxReadWriteLenght) {
uint8_t asic_msb = (uint8_t)((index / 2) >> 4);
uint8_t asic_lsb = ((index / 2) & 0x0F);
writeRegister(BMA4_RESERVED_REG_5B_ADDR, asic_lsb);
writeRegister(BMA4_RESERVED_REG_5C_ADDR, asic_msb);
writeRegister(BMA4_FEATURE_CONFIG_ADDR, (uint8_t *)(stream_data + index), maxReadWriteLenght);
}
enableInterruptCtrl();
delay(150);
val = readRegister(BMA4_INTERNAL_STAT);
if (val == BMA4_ASIC_INITIALIZED) {
log_d("BMA configure SUCCESS!");
} else {
log_d("BMA configure FAILED!");
}
return val == BMA4_ASIC_INITIALIZED;
}
bool initImpl()
{
uint8_t id;
int retry = 2;
while (retry--) {
id = readRegister(BMA4_CHIP_ID_ADDR);
if (id != BMA423_CHIP_ID) {
reset();
}
}
if (id == BMA423_CHIP_ID) {
return configure();
}
log_d("ChipID:0x%x should be 0x%x", id, BMA423_CHIP_ID);
return false;
}
int getReadMaskImpl()
{
return DEV_WIRE_ERR;
}
uint16_t int_status;
uint8_t int_line;
protected:
};

View File

@@ -0,0 +1,36 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorBMM150.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-24
*
*/
#include "SensorBMM150.hpp"
#if defined(ARDUINO)
volatile bool SensorBMM150::__data_available;
#endif

View File

@@ -0,0 +1,342 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorBMM150.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-09
* @note Most source code references come from the https://github.com/boschsensortec/BMM150-Sensor-API
* Simplification for Arduino
*/
#pragma once
#include "bosch/common/bosch_interfaces.h"
#include "bosch/BMM150/bmm150.h"
#include "bosch/SensorBhy2Define.h"
#if defined(ARDUINO)
/*! @name I2C ADDRESS */
#define BMM150_DEFAULT_I2C_ADDRESS UINT8_C(0x10)
#define BMM150_I2C_ADDRESS_CSB_LOW_SDO_HIGH UINT8_C(0x11)
#define BMM150_I2C_ADDRESS_CSB_HIGH_SDO_LOW UINT8_C(0x12)
#define BMM150_I2C_ADDRESS_CSB_HIGH_SDO_HIGH UINT8_C(0x13)
class SensorBMM150
{
public:
enum PowerMode {
POWERMODE_NORMAL,
POWERMODE_FORCED,
POWERMODE_SLEEP,
POWERMODE_SUSPEND,
};
enum InterruptLevel {
INTERRUPT_HIGH_ACTIVE,
INTERRUPT_LOW_ACTIVE,
};
SensorBMM150(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMM150_DEFAULT_I2C_ADDRESS)
{
__handler.u.i2c_dev.scl = scl;
__handler.u.i2c_dev.sda = sda;
__handler.u.i2c_dev.addr = addr;
__handler.u.i2c_dev.wire = &w;
__handler.intf = SENSORLIB_I2C_INTERFACE;
}
SensorBMM150(int cs, int mosi = -1, int miso = -1, int sck = -1, PLATFORM_SPI_TYPE &spi = SPI )
{
__handler.u.spi_dev.cs = cs;
__handler.u.spi_dev.miso = miso;
__handler.u.spi_dev.mosi = mosi;
__handler.u.spi_dev.sck = sck;
__handler.u.spi_dev.spi = &spi;
__handler.intf = SENSORLIB_SPI_INTERFACE;
}
~SensorBMM150()
{
deinit();
}
SensorBMM150()
{
memset(&__handler, 0, sizeof(__handler));
}
void setPins(int rst, int irq)
{
__handler.irq = irq;
__handler.rst = rst;
}
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = BMM150_DEFAULT_I2C_ADDRESS)
{
__handler.u.i2c_dev.scl = scl;
__handler.u.i2c_dev.sda = sda;
__handler.u.i2c_dev.addr = addr;
__handler.u.i2c_dev.wire = &w;
__handler.intf = SENSORLIB_I2C_INTERFACE;
return initImpl();
}
bool init( PLATFORM_SPI_TYPE &spi, int cs, int mosi = -1, int miso = -1, int sck = -1)
{
__handler.u.spi_dev.cs = cs;
__handler.u.spi_dev.miso = miso;
__handler.u.spi_dev.mosi = mosi;
__handler.u.spi_dev.sck = sck;
__handler.u.spi_dev.spi = &spi;
__handler.intf = SENSORLIB_SPI_INTERFACE;
return initImpl();
}
bool init()
{
return initImpl();
}
void deinit()
{
if (dev) {
free(dev);
dev = NULL;
}
if (__handler.irq != SENSOR_PIN_NONE) {
detachInterrupt(__handler.irq);
}
}
void reset()
{
if (__handler.rst != SENSOR_PIN_NONE) {
digitalWrite(__handler.rst, HIGH);
delay(5);
digitalWrite(__handler.rst, LOW);
delay(10);
digitalWrite(__handler.rst, HIGH);
delay(5);
}
}
void sleep()
{
setMode(POWERMODE_SLEEP);
}
bool setMode(PowerMode mode)
{
settings.pwr_mode = mode;
return bmm150_set_op_mode(&settings, dev) == BMM150_OK;
}
bool setThreshold(uint8_t high_th, uint8_t low_th)
{
settings.int_settings.high_threshold = high_th;
settings.int_settings.low_threshold = low_th;
return bmm150_set_sensor_settings(BMM150_SEL_HIGH_THRESHOLD_SETTING, &settings, dev) == BMM150_OK;
}
bool setInterruptLevel(InterruptLevel level)
{
settings.int_settings.high_int_en = level;
return bmm150_set_sensor_settings(BMM150_SEL_HIGH_THRESHOLD_INT, &settings, dev) == BMM150_OK;
}
bool enableINT()
{
settings.int_settings.int_pin_en = BMM150_INT_ENABLE;
return bmm150_set_sensor_settings(BMM150_SEL_INT_PIN_EN, &settings, dev) == BMM150_OK;
}
bool disableINT()
{
settings.int_settings.int_pin_en = BMM150_INT_DISABLE;
return bmm150_set_sensor_settings(BMM150_SEL_INT_PIN_EN, &settings, dev) == BMM150_OK;
}
bool enabledDataReady()
{
settings.int_settings.drdy_pin_en = BMM150_INT_ENABLE;
return bmm150_set_sensor_settings(BMM150_SEL_DRDY_PIN_EN, &settings, dev) == BMM150_OK;
}
bool disabledDataReady()
{
settings.int_settings.drdy_pin_en = BMM150_INT_DISABLE;
return bmm150_set_sensor_settings(BMM150_SEL_DRDY_PIN_EN, &settings, dev) == BMM150_OK;
}
uint8_t getChipID()
{
return dev->chip_id;
}
uint8_t getIrqStatus()
{
bmm150_get_interrupt_status(dev);
return dev->int_status;
}
bool isDataReady()
{
return dev->int_status & BMM150_INT_ASSERTED_DRDY;
}
bool isLowThreshold()
{
return dev->int_status & BMM150_INT_ASSERTED_LOW_THRES;
}
bool isHighThreshold()
{
return dev->int_status & BMM150_INT_ASSERTED_HIGH_THRES;
}
struct bmm150_mag_data getMag()
{
struct bmm150_mag_data data = {0, 0, 0};
bmm150_read_mag_data(&data, dev);
return data;
}
bool getMag(int16_t &x, int16_t &y, int16_t &z)
{
struct bmm150_mag_data data;
if (bmm150_read_mag_data(&data, dev) != BMM150_OK) {
return false;
}
x = data.x;
y = data.y;
z = data.z;
return true;
}
private:
static void handleISR(/*void *available*/)
{
// *(bool *)(available) = true;
__data_available = true;
}
bool initImpl()
{
memset(&settings, 0, sizeof(settings));
if (__handler.rst != SENSOR_PIN_NONE) {
pinMode(__handler.rst, OUTPUT);
}
reset();
dev = (struct bmm150_dev *)malloc(sizeof(struct bmm150_dev));
BHY2_RLST_CHECK(!dev, " Device handler malloc failed!", false);
switch (__handler.intf) {
case SENSORLIB_I2C_INTERFACE:
BHY2_RLST_CHECK(!__handler.u.i2c_dev.wire, "Wire ptr NULL", false);
if (!SensorInterfaces::setup_interfaces(__handler)) {
log_e("setup_interfaces failed");
free(dev);
return false;
}
dev->intf = BMM150_I2C_INTF;
dev->read = SensorInterfaces::bhy2_i2c_read;
dev->write = SensorInterfaces::bhy2_i2c_write;
dev->intf_ptr = &__handler;
break;
case SENSORLIB_SPI_INTERFACE:
BHY2_RLST_CHECK(!__handler.u.spi_dev.spi, "SPI ptr NULL", false);
if (!SensorInterfaces::setup_interfaces(__handler)) {
log_e("setup_interfaces failed");
free(dev);
return false;
}
dev->intf = BMM150_I2C_INTF;
dev->read = SensorInterfaces::bhy2_spi_read;
dev->write = SensorInterfaces::bhy2_spi_write;
dev->intf_ptr = &__handler;
break;
default:
free(dev);
return false;
}
dev->delay_us = SensorInterfaces::bhy2_delay_us;
__error_code = bmm150_init(dev);
if (__error_code != BMM150_OK) {
log_e("bmm150 init failed!");
free(dev);
return false;
}
__error_code = bmm150_soft_reset(dev);
if (__error_code != BMM150_OK) {
log_e("reset failed!");
free(dev);
return false;
}
bmm150_get_sensor_settings(&settings, dev);
if (__handler.irq != SENSOR_PIN_NONE) {
/*
#if defined(ARDUINO_ARCH_RP2040)
attachInterruptParam((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING, (void *)&__data_available);
#else
attachInterruptArg(__handler.irq, handleISR, (void *)&__data_available, RISING);
#endif
*/
#if defined(ARDUINO_ARCH_RP2040)
attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING);
#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32)
attachInterrupt(__handler.irq, handleISR, RISING);
#else
#error "Interrupt registration not implemented"
#endif
}
return __error_code == BMM150_OK;
}
protected:
struct bmm150_settings settings;
struct bmm150_dev *dev = NULL;
SensorLibConfigure __handler;
int8_t __error_code;
static volatile bool __data_available;
};
#endif /*defined(ARDUINO)*/

View File

@@ -0,0 +1,234 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorCM32181.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-14
*
*/
#pragma once
#include "REG/CM32181Constants.h"
#include "SensorCommon.tpp"
class SensorCM32181 :
public SensorCommon<SensorCM32181>
{
friend class SensorCommon<SensorCM32181>;
public:
enum Sampling {
SAMPLING_X1, //ALS Sensitivity x 1
SAMPLING_X2, //ALS Sensitivity x 2
SAMPLING_X1_8, //ALS Sensitivity x (1/8)
SAMPLING_X1_4, //ALS Sensitivity x (1/4)
};
enum IntegrationTime {
INTEGRATION_TIME_25MS = 0x0C,
INTEGRATION_TIME_50MS = 0x08,
INTEGRATION_TIME_100MS = 0x00, //0000 = 100ms
INTEGRATION_TIME_200MS, //0001 = 200ms
INTEGRATION_TIME_400MS, //0010 = 400ms
INTEGRATION_TIME_800MS, //0011 = 800ms
};
enum PowerSaveMode {
PowerSaveMode1 = 0x00,
PowerSaveMode2,
PowerSaveMode3,
PowerSaveMode4
};
enum InterruptEvent {
ALS_EVENT_LOW_TRIGGER = 0x00,
ALS_EVENT_HIGH_TRIGGER,
ALS_EVENT_NULL,
};
#if defined(ARDUINO)
SensorCM32181(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = CM32181_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorCM32181()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = CM32181_SLAVE_ADDRESS;
}
~SensorCM32181()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = CM32181_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void setSampling(Sampling tempSampling = SAMPLING_X1,
IntegrationTime int_time = INTEGRATION_TIME_200MS
)
{
uint16_t data;
readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
data &= ~(0x03 << 11);
data |= tempSampling << 11;
data &= ~(0xF << 6);
data |= int_time << 6;
readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
}
void setIntThreshold(uint16_t low_threshold, uint16_t high_threshold)
{
uint8_t buffer[2] = {0};
buffer[1] = highByte(high_threshold);
buffer[0] = lowByte(high_threshold);;
writeRegister(CM32181_REG_ALS_THDH, buffer, 2);
buffer[1] = highByte(low_threshold);
buffer[0] = lowByte(low_threshold);
writeRegister(CM32181_REG_ALS_THDL, buffer, 2);
}
void powerSave(PowerSaveMode mode, bool enable)
{
uint16_t data = 0x00;
readRegister(CM32181_REG_ALS_PSM, (uint8_t *)&data, 2);
data |= mode << 1;
enable ? data |= 0x01 : data |= 0x00;
writeRegister(CM32181_REG_ALS_PSM, (uint8_t *)&data, 2);
}
// Read CM32181_REG_ALS_STATUS register to clear interrupt
InterruptEvent getIrqStatus()
{
uint16_t data;
readRegister(CM32181_REG_ALS_STATUS, (uint8_t *)&data, 2);
return bitRead(data, 15) ? ALS_EVENT_LOW_TRIGGER : bitRead(data, 14) ? ALS_EVENT_HIGH_TRIGGER : ALS_EVENT_NULL;
}
void enableINT()
{
uint16_t data;
readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
bitWrite(data, 1, 1);
writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
}
void disableINT()
{
uint16_t data;
readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
bitWrite(data, 1, 0);
writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
}
void powerOn()
{
uint16_t data;
readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
bitClear(data, 0);
writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
}
void powerDown()
{
uint16_t data;
readRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
bitSet(data, 0);
writeRegister(CM32181_REG_ALS_CONF, (uint8_t *)&data, 2);
}
uint16_t getRaw()
{
uint8_t buffer[2] = {0};
readRegister(CM32181_REG_ALS_DATA, buffer, 2);
return (uint16_t) buffer[0] | (uint16_t)(buffer[1] << 8);
}
float getLux()
{
return getRaw() * calibration_factor;
}
int getChipID()
{
uint8_t buffer[2] = {0};
readRegister(CM32181_REG_ID, buffer, 2);
return lowByte(buffer[0]);
}
private:
bool initImpl()
{
setReadRegisterSendStop(false);
int chipID = getChipID();
log_i("chipID:%d\n", chipID);
if (chipID == DEV_WIRE_ERR ) {
return false;
}
if (chipID != CM32181_CHIP_ID) {
return false;
}
return true;
}
int getReadMaskImpl()
{
return -1;
}
protected:
// The default calibration value, learned from the manual,
// is now unable to obtain the calibration value from the specified register
const float calibration_factor = 0.286;
};

View File

@@ -0,0 +1,711 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorCommon.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-10-16
*
*/
#pragma once
#include "SensorLib.h"
typedef int (*iic_fptr_t)(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len);
typedef void (*gpio_write_fptr_t)(uint32_t gpio, uint8_t value);
typedef int (*gpio_read_fptr_t)(uint32_t gpio);
typedef void (*gpio_mode_fptr_t)(uint32_t gpio, uint8_t mode);
typedef void (*delay_ms_fptr_t)(uint32_t ms);
template <class chipType>
class SensorCommon
{
public:
~SensorCommon()
{
#if defined(ARDUINO)
if (__spiSetting) {
delete __spiSetting;
}
#endif
}
#if defined(ARDUINO)
void setSpiSetting(uint32_t freq, uint8_t dataOrder = SPI_DATA_ORDER, uint8_t dataMode = SPI_MODE0)
{
__freq = freq;
__dataOrder = dataOrder;
__dataMode = dataMode;
}
bool begin(PLATFORM_WIRE_TYPE &w, uint8_t addr, int sda, int scl)
{
log_i("Using Arduino Wire interface.");
if (__has_init)return thisChip().initImpl();
__wire = &w;
__sda = sda;
__scl = scl;
#if defined(ARDUINO_ARCH_NRF52)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->setPins(__sda, __scl);
}
__wire->begin();
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->end();
__wire->setSDA(__sda);
__wire->setSCL(__scl);
}
__wire->begin();
#elif defined(ARDUINO_ARCH_ESP32)
__wire->begin(__sda, __scl);
#else
__wire->begin();
#endif
__addr = addr;
__spi = NULL;
__i2c_master_read = NULL;
__i2c_master_write = NULL;
__has_init = thisChip().initImpl();
return __has_init;
}
bool begin(int cs, int mosi = -1, int miso = -1, int sck = -1,
PLATFORM_SPI_TYPE &spi = SPI
)
{
log_i("Using Arduino SPI interface.");
if (__has_init)return thisChip().initImpl();
__cs = cs;
__spi = &spi;
pinMode(__cs, OUTPUT);
digitalWrite(__cs, HIGH);
__spiSetting = new DEFAULT_SPISETTING;
if (!__spiSetting) {
return false;
}
if (mosi != -1 && miso != -1 && sck != -1) {
#if defined(ARDUINO_ARCH_NRF52)
__spi->begin();
#elif defined(ARDUINO_ARCH_RP2040)
__spi->setSCK(sck);
__spi->setRX(miso);
__spi->setTX(mosi);
__spi->begin();
#elif defined(ARDUINO_ARCH_STM32)
__spi->setSCLK(sck);
__spi->setMISO(miso);
__spi->setMOSI(mosi);
__spi->begin();
#else
__spi->begin(sck, miso, mosi);
#endif
} else {
__spi->begin();
}
__wire = NULL;
__readMask = thisChip().getReadMaskImpl();
__has_init = thisChip().initImpl();
return __has_init;
}
#elif defined(ESP_PLATFORM) && !defined(ARDUINO)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
// * Using the new API of esp-idf 5.x, you need to pass the I2C BUS handle,
// * which is useful when the bus shares multiple devices.
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
log_i("Using ESP-IDF Driver interface.");
if (i2c_dev_bus_handle == NULL) return false;
if (__has_init)return thisChip().initImpl();
__i2c_master_read = NULL;
__i2c_master_write = NULL;
__addr = addr;
/*
i2c_master_bus_config_t i2c_bus_config;
memset(&i2c_bus_config, 0, sizeof(i2c_bus_config));
i2c_bus_config.clk_source = I2C_CLK_SRC_DEFAULT;
i2c_bus_config.i2c_port = port_num;
i2c_bus_config.scl_io_num = (gpio_num_t)__scl;
i2c_bus_config.sda_io_num = (gpio_num_t)__sda;
i2c_bus_config.glitch_ignore_cnt = 7;
i2c_new_master_bus(&i2c_bus_config, &bus_handle);
*/
bus_handle = i2c_dev_bus_handle;
__i2c_dev_conf.dev_addr_length = I2C_ADDR_BIT_LEN_7;
__i2c_dev_conf.device_address = __addr;
__i2c_dev_conf.scl_speed_hz = SENSORLIB_I2C_MASTER_SEEED;
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,3,0))
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,4,0))
// New fields since esp-idf-v5.3-beta1
__i2c_dev_conf.scl_wait_us = 0;
#endif
__i2c_dev_conf.flags.disable_ack_check = 0;
#endif
if (ESP_OK != i2c_master_bus_add_device(bus_handle,
&__i2c_dev_conf,
&__i2c_device)) {
log_i("i2c_master_bus_add_device failed !");
return false;
}
log_i("Added Device Address : 0x%X New Dev Address: %p Speed :%lu ", __addr, __i2c_device, __i2c_dev_conf.scl_speed_hz);
__has_init = thisChip().initImpl();
if (!__has_init) {
// Initialization failed, delete device
log_i("i2c_master_bus_rm_device !");
i2c_master_bus_rm_device(__i2c_device);
}
return __has_init;
}
#else //ESP 4.X
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
__i2c_num = port_num;
log_i("Using ESP-IDF Driver interface.");
if (__has_init)return thisChip().initImpl();
__sda = sda;
__scl = scl;
__addr = addr;
__i2c_master_read = NULL;
__i2c_master_write = NULL;
i2c_config_t i2c_conf;
memset(&i2c_conf, 0, sizeof(i2c_conf));
i2c_conf.mode = I2C_MODE_MASTER;
i2c_conf.sda_io_num = sda;
i2c_conf.scl_io_num = scl;
i2c_conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
i2c_conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
i2c_conf.master.clk_speed = SENSORLIB_I2C_MASTER_SEEED;
/**
* @brief Without checking whether the initialization is successful,
* I2C may be initialized externally,
* so just make sure there is an initialization here.
*/
i2c_param_config(__i2c_num, &i2c_conf);
i2c_driver_install(__i2c_num,
i2c_conf.mode,
SENSORLIB_I2C_MASTER_RX_BUF_DISABLE,
SENSORLIB_I2C_MASTER_TX_BUF_DISABLE, 0);
__has_init = thisChip().initImpl();
return __has_init;
}
#endif //ESP 5.X
#endif
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
log_i("Using Custom interface.");
if (__has_init)return thisChip().initImpl();
__i2c_master_read = readRegCallback;
__i2c_master_write = writeRegCallback;
__addr = addr;
#if defined(ARDUINO)
__spi = NULL;
#endif
__has_init = thisChip().initImpl();
return __has_init;
}
void setGpioWriteCallback(gpio_write_fptr_t cb)
{
__set_gpio_level = cb;
}
void setGpioReadCallback(gpio_read_fptr_t cb)
{
__get_gpio_level = cb;
}
void setGpioModeCallback(gpio_mode_fptr_t cb)
{
__set_gpio_mode = cb;
}
void setDelayCallback(delay_ms_fptr_t cb)
{
__delay_ms = cb;
}
protected:
inline void setGpioMode(uint32_t gpio, uint8_t mode)
{
if (__set_gpio_mode) {
return __set_gpio_mode(gpio, mode);
}
#if defined(ARDUINO) || defined(ESP_PLATFORM)
return pinMode(gpio, mode);
#endif
}
inline void setGpioLevel(uint32_t gpio, uint8_t level)
{
if (__set_gpio_level) {
return __set_gpio_level(gpio, level);
}
#if defined(ARDUINO) || defined(ESP_PLATFORM)
return digitalWrite(gpio, level);
#endif
}
inline int getGpioLevel(uint32_t gpio)
{
if (__get_gpio_level) {
return __get_gpio_level(gpio);
}
#if defined(ARDUINO) || defined(ESP_PLATFORM)
return digitalRead(gpio);
#endif
}
bool probe(uint8_t address)
{
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(address);
return __wire->endTransmission() == 0;
}
return false;
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
return i2c_master_probe(bus_handle, address, 1000);
#else
return true;
#endif
#else
return true;
#endif
}
bool probe()
{
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
return __wire->endTransmission() == 0;
}
return false;
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
return i2c_master_probe(bus_handle, __addr, 1000);
#else
return true;
#endif
#else
return true;
#endif
}
//! Write method
int writeRegister(uint8_t reg, uint8_t norVal, uint8_t orVal)
{
int val = readRegister(reg);
if (val == DEV_WIRE_ERR) {
return DEV_WIRE_ERR;
}
val &= norVal;
val |= orVal;
return writeRegister(reg, val);
}
int writeRegister(int reg, uint8_t val)
{
return writeRegister(reg, &val, 1);
}
int writeThenRead(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
{
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
__wire->write(write_buffer, write_len);
if (__wire->endTransmission(__sendStop) != 0) {
return DEV_WIRE_ERR;
}
__wire->requestFrom(__addr, read_len);
return __wire->readBytes(read_buffer, read_len) == read_len ? DEV_WIRE_NONE : DEV_WIRE_ERR;
}
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
if (ESP_OK == i2c_master_transmit_receive(
__i2c_device,
write_buffer,
write_len,
read_buffer,
read_len,
-1)) {
return DEV_WIRE_NONE;
}
#else //ESP_IDF_VERSION
if (ESP_OK == i2c_master_write_read_device(
__i2c_num,
__addr,
write_buffer,
write_len,
read_buffer,
read_len,
SENSORLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) {
return DEV_WIRE_NONE;
}
#endif //ESP_IDF_VERSION
#endif //ESP_PLATFORM
return DEV_WIRE_ERR;
}
int writeBuffer(uint8_t *buf, size_t length)
{
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
__wire->write(buf, length);
uint8_t ret = (__wire->endTransmission());
return ret == 0 ? DEV_WIRE_NONE : DEV_WIRE_ERR;
}
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
if (ESP_OK == i2c_master_transmit(
__i2c_device,
buf,
length,
-1)) {
return DEV_WIRE_NONE;
}
#else //ESP_IDF_VERSION
if (ESP_OK == i2c_master_write_to_device(__i2c_num,
__addr,
buf,
length,
SENSORLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) {
return DEV_WIRE_NONE;
}
#endif //ESP_IDF_VERSION
#endif //ESP_PLATFORM
return DEV_WIRE_ERR;
}
int writeRegister(int reg, uint8_t *buf, size_t length)
{
if (__i2c_master_write) {
return __i2c_master_write(__addr, reg, buf, length);
}
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
if (__reg_addr_len == 1) {
__wire->write(reg);
} else {
for (int i = 0; i < __reg_addr_len; ++i) {
__wire->write(reg >> (8 * ((__reg_addr_len - 1) - i)));
}
}
__wire->write(buf, length);
return (__wire->endTransmission() == 0) ? DEV_WIRE_NONE : DEV_WIRE_ERR;
}
if (__spi) {
__spi->beginTransaction(*__spiSetting);
digitalWrite(__cs, LOW);
if (__reg_addr_len == 1) {
__spi->transfer(reg);
} else {
for (int i = 0; i < __reg_addr_len; ++i) {
__spi->transfer(reg >> (8 * ((__reg_addr_len - 1) - i)));
}
}
__spi->transfer(buf, length);
digitalWrite(__cs, HIGH);
__spi->endTransaction();
return DEV_WIRE_NONE;
}
return DEV_WIRE_ERR;
#elif defined(ESP_PLATFORM)
uint8_t *write_buffer = (uint8_t *)malloc(sizeof(uint8_t) * (length + __reg_addr_len));
if (!write_buffer) {
return DEV_WIRE_ERR;
}
write_buffer[0] = reg;
memcpy(write_buffer, &reg, __reg_addr_len);
memcpy(write_buffer + __reg_addr_len, buf, length);
int ret = writeBuffer(write_buffer, __reg_addr_len + length);
free(write_buffer);
return ret;
#endif //ESP_PLATFORM
}
//! Read method
int readRegister(int reg)
{
uint8_t val = 0;
return readRegister(reg, &val, 1) == -1 ? -1 : val;
}
int readRegister(int reg, uint8_t *buf, uint8_t length)
{
if (__i2c_master_read) {
return __i2c_master_read(__addr, reg, buf, length);
}
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
if (__reg_addr_len == 1) {
__wire->write(reg);
} else {
for (int i = 0; i < __reg_addr_len; ++i) {
__wire->write(reg >> (8 * ((__reg_addr_len - 1) - i)));
}
}
if (__wire->endTransmission(__sendStop) != 0) {
return DEV_WIRE_ERR;
}
__wire->requestFrom(__addr, length);
return __wire->readBytes(buf, length) == length ? DEV_WIRE_NONE : DEV_WIRE_ERR;
}
if (__spi) {
__spi->beginTransaction(*__spiSetting);
digitalWrite(__cs, LOW);
if (__reg_addr_len == 1) {
__spi->transfer(__readMask != -1 ? (reg | __readMask) : reg);
} else {
uint8_t firstBytes = reg >> (8 * ((__reg_addr_len - 1)));
__spi->transfer(__readMask != -1 ? (firstBytes | __readMask) : firstBytes);
for (int i = 1; i < __reg_addr_len; ++i) {
__spi->transfer(reg >> (8 * ((__reg_addr_len - 1) - i)));
}
}
for (size_t i = 0; i < length; i++) {
buf[i] = __spi->transfer(0x00);
}
digitalWrite(__cs, HIGH);
__spi->endTransaction();
return DEV_WIRE_NONE;
}
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
if (ESP_OK == i2c_master_transmit_receive(
__i2c_device,
(const uint8_t *)&reg,
__reg_addr_len,
buf,
length,
-1)) {
return DEV_WIRE_NONE;
}
#else //ESP_IDF_VERSION
if (ESP_OK == i2c_master_write_read_device(__i2c_num,
__addr,
(uint8_t *)&reg,
__reg_addr_len,
buf,
length,
SENSORLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) {
return DEV_WIRE_NONE;
}
#endif //ESP_IDF_VERSION
#endif //ESP_PLATFORM
return DEV_WIRE_ERR;
}
bool inline clrRegisterBit(int registers, uint8_t bit)
{
int val = readRegister(registers);
if (val == DEV_WIRE_ERR) {
return false;
}
return writeRegister(registers, (val & (~_BV(bit)))) == 0;
}
bool inline setRegisterBit(int registers, uint8_t bit)
{
int val = readRegister(registers);
if (val == DEV_WIRE_ERR) {
return false;
}
return writeRegister(registers, (val | (_BV(bit)))) == 0;
}
bool inline getRegisterBit(int registers, uint8_t bit)
{
int val = readRegister(registers);
if (val == DEV_WIRE_ERR) {
return false;
}
return val & _BV(bit);
}
uint16_t inline readRegisterH8L4(uint8_t highReg, uint8_t lowReg)
{
int h8 = readRegister(highReg);
int l4 = readRegister(lowReg);
if (h8 == DEV_WIRE_ERR || l4 == DEV_WIRE_ERR)return 0;
return (h8 << 4) | (l4 & 0x0F);
}
uint16_t inline readRegisterH8L5(uint8_t highReg, uint8_t lowReg)
{
int h8 = readRegister(highReg);
int l5 = readRegister(lowReg);
if (h8 == DEV_WIRE_ERR || l5 == DEV_WIRE_ERR)return 0;
return (h8 << 5) | (l5 & 0x1F);
}
uint16_t inline readRegisterH6L8(uint8_t highReg, uint8_t lowReg)
{
int h6 = readRegister(highReg);
int l8 = readRegister(lowReg);
if (h6 == DEV_WIRE_ERR || l8 == DEV_WIRE_ERR)return 0;
return ((h6 & 0x3F) << 8) | l8;
}
uint16_t inline readRegisterH5L8(uint8_t highReg, uint8_t lowReg)
{
int h5 = readRegister(highReg);
int l8 = readRegister(lowReg);
if (h5 == DEV_WIRE_ERR || l8 == DEV_WIRE_ERR)return 0;
return ((h5 & 0x1F) << 8) | l8;
}
void setRegAddressLength(uint8_t len)
{
__reg_addr_len = len;
}
void setReadRegisterSendStop(bool sendStop)
{
__sendStop = sendStop;
}
bool reallocBuffer(size_t realloc_size)
{
#if defined(ARDUINO)
#ifdef ARDUINO_ARCH_ESP32
// ESP32 I2C BUFFER : 128 Bytes
if (__wire) {
if (__wire->setBufferSize(realloc_size) != realloc_size) {
log_e("realloc I2C buffer failed!");
return false;
}
}
#elif defined(ARDUINO_ARCH_RP2040)
// RP2040 I2C BUFFER : 256 Bytes
#elif defined(ARDUINO_ARCH_NRF52)
// NRF52840 I2C BUFFER : 64 Bytes
// #warning "NRF Platform I2C Buffer expansion is not implemented"
//TODO:"NRF Platform I2C Buffer expansion is not implemented"
#endif
#endif
return true;
}
/*
* CRTP Helper
*/
protected:
void end()
{
#if defined(ARDUINO)
if (__wire) {
#if defined(ESP_IDF_VERSION)
#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4,4,0)
__wire->end();
#endif /*ESP_IDF_VERSION*/
#endif /*ESP_IDF_VERSION*/
}
#endif /*ARDUINO*/
}
inline const chipType &thisChip() const
{
return static_cast<const chipType &>(*this);
}
inline chipType &thisChip()
{
return static_cast<chipType &>(*this);
}
protected:
bool __has_init = false;
#if defined(ARDUINO)
PLATFORM_WIRE_TYPE *__wire = NULL;
PLATFORM_SPI_TYPE *__spi = NULL;
SPISettings *__spiSetting = NULL;
uint8_t __dataOrder = SPI_DATA_ORDER;
uint8_t __dataMode = SPI_MODE0;
uint32_t __freq = 400000;
#elif defined(ESP_PLATFORM)
i2c_port_t __i2c_num;
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
i2c_master_bus_handle_t bus_handle;
i2c_master_dev_handle_t __i2c_device;
i2c_device_config_t __i2c_dev_conf;
#endif //ESP_IDF_VERSION
#endif //ESP_PLATFORM
int __readMask = -1;
int __sda = -1;
int __scl = -1;
int __cs = -1;
int __miso = -1;
int __mosi = -1;
int __sck = -1;
bool __sendStop = true;
uint8_t __addr = 0xFF;
uint8_t __reg_addr_len = 1;
iic_fptr_t __i2c_master_read = NULL;
iic_fptr_t __i2c_master_write = NULL;
gpio_write_fptr_t __set_gpio_level = NULL;
gpio_read_fptr_t __get_gpio_level = NULL;
gpio_mode_fptr_t __set_gpio_mode = NULL;
delay_ms_fptr_t __delay_ms = NULL;
};

View File

@@ -0,0 +1,235 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorDRV2605.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-03
* @note Source code from https://github.com/adafruit/Adafruit_DRV2605_Library
*/
#pragma once
#include "REG/DRV2605Constants.h"
#include "SensorCommon.tpp"
class SensorDRV2605 :
public SensorCommon<SensorDRV2605>
{
friend class SensorCommon<SensorDRV2605>;
public:
#if defined(ARDUINO)
SensorDRV2605(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = DRV2605_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorDRV2605()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = DRV2605_SLAVE_ADDRESS;
}
~SensorDRV2605()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = DRV2605_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
/**************************************************************************/
/*!
@brief Select the haptic waveform to use.
@param slot The waveform slot to set, from 0 to 7
@param w The waveform sequence value, refers to an index in the ROM library.
Playback starts at slot 0 and continues through to slot 7, stopping if it
encounters a value of 0. A list of available waveforms can be found in
section 11.2 of the datasheet: http://www.adafruit.com/datasheets/DRV2605.pdf
*/
/**************************************************************************/
void setWaveform(uint8_t slot, uint8_t w)
{
writeRegister(DRV2605_REG_WAVESEQ1 + slot, w);
}
/**************************************************************************/
/*!
@brief Select the waveform library to use.
@param lib Library to use, 0 = Empty, 1-5 are ERM, 6 is LRA.
See section 7.6.4 in the datasheet for more details:
http://www.adafruit.com/datasheets/DRV2605.pdf
*/
/**************************************************************************/
void selectLibrary(uint8_t lib)
{
writeRegister(DRV2605_REG_LIBRARY, lib);
}
/**************************************************************************/
/*!
@brief Start playback of the waveforms (start moving!).
*/
/**************************************************************************/
void run()
{
writeRegister(DRV2605_REG_GO, 1);
}
/**************************************************************************/
/*!
@brief Stop playback.
*/
/**************************************************************************/
void stop()
{
writeRegister(DRV2605_REG_GO, 0);
}
/**************************************************************************/
/*!
@brief Set the device mode.
@param mode Mode value, see datasheet section 7.6.2:
http://www.adafruit.com/datasheets/DRV2605.pdf
0: Internal trigger, call run() to start playback\n
1: External trigger, rising edge on IN pin starts playback\n
2: External trigger, playback follows the state of IN pin\n
3: PWM/analog input\n
4: Audio\n
5: Real-time playback\n
6: Diagnostics\n
7: Auto calibration
*/
/**************************************************************************/
void setMode(uint8_t mode)
{
writeRegister(DRV2605_REG_MODE, mode);
}
/**************************************************************************/
/*!
@brief Set the realtime value when in RTP mode, used to directly drive the
haptic motor.
@param rtp 8-bit drive value.
*/
/**************************************************************************/
void setRealtimeValue(uint8_t rtp)
{
writeRegister(DRV2605_REG_RTPIN, rtp);
}
/**************************************************************************/
/*!
@brief Use ERM (Eccentric Rotating Mass) mode.
*/
/**************************************************************************/
void useERM()
{
writeRegister(DRV2605_REG_FEEDBACK, readRegister(DRV2605_REG_FEEDBACK) & 0x7F);
}
/**************************************************************************/
/*!
@brief Use LRA (Linear Resonance Actuator) mode.
*/
/**************************************************************************/
void useLRA()
{
writeRegister(DRV2605_REG_FEEDBACK, readRegister(DRV2605_REG_FEEDBACK) | 0x80);
}
private:
bool initImpl()
{
int chipID = readRegister(DRV2605_REG_STATUS);
if (chipID == -1) {
return false;
}
chipID >>= 5;
if (chipID != DRV2604_CHIP_ID &&
chipID != DRV2605_CHIP_ID &&
chipID != DRV2604L_CHIP_ID &&
chipID != DRV2605L_CHIP_ID ) {
LOG("ChipID:0x%x should be 0x03 or 0x04 or 0x06 or 0x07\n", chipID);
return false;
}
writeRegister(DRV2605_REG_MODE, 0x00); // out of standby
writeRegister(DRV2605_REG_RTPIN, 0x00); // no real-time-playback
writeRegister(DRV2605_REG_WAVESEQ1, 1); // strong click
writeRegister(DRV2605_REG_WAVESEQ2, 0); // end sequence
writeRegister(DRV2605_REG_OVERDRIVE, 0); // no overdrive
writeRegister(DRV2605_REG_SUSTAINPOS, 0);
writeRegister(DRV2605_REG_SUSTAINNEG, 0);
writeRegister(DRV2605_REG_BREAK, 0);
writeRegister(DRV2605_REG_AUDIOMAX, 0x64);
// ERM open loop
// turn off N_ERM_LRA
writeRegister(DRV2605_REG_FEEDBACK,
readRegister(DRV2605_REG_FEEDBACK) & 0x7F);
// turn on ERM_OPEN_LOOP
writeRegister(DRV2605_REG_CONTROL3,
readRegister(DRV2605_REG_CONTROL3) | 0x20);
return true;
}
int getReadMaskImpl()
{
return -1;
}
protected:
};

View File

@@ -0,0 +1,349 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorLTR553ALS.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-09
*
*/
#pragma once
#include "REG/LTR533Constants.h"
#include "SensorCommon.tpp"
class SensorLTR553 :
public SensorCommon<SensorLTR553>
{
friend class SensorCommon<SensorLTR553>;
public:
enum IrqLevel {
ALS_IRQ_ACTIVE_LOW, // INT pin is considered active when it is a logic 0 (default)
ALS_IRQ_ACTIVE_HIGH // INT pin is considered active when it is a logic 1
};
enum IrqMode {
ALS_IRQ_ONLY_PS = 1, // Only PS measurement can trigger interrupt
ALS_IRQ_ONLY_ALS, // Only ALS measurement can trigger interrupt
ALS_IRQ_BOTH, // Both ALS and PS measurement can trigger interrupt
};
enum LightSensorGain {
ALS_GAIN_1X = 0x00, // 1 lux to 64k lux (default)
ALS_GAIN_2X = 0x01, // 0.5 lux to 32k lux
ALS_GAIN_4X = 0x02, // 0.25 lux to 16k lux
ALS_GAIN_8X = 0x03, // 0.125 lux to 8k lux
ALS_GAIN_48X = 0x06, // 0.02 lux to 1.3k lux
ALS_GAIN_96X = 0x07, // 0.01 lux to 600 lux
};
enum PsLedPeriod {
PS_LED_PLUSE_30KHZ = 0x00,
PS_LED_PLUSE_40KHZ,
PS_LED_PLUSE_50KHZ,
PS_LED_PLUSE_60KHZ,
PS_LED_PLUSE_70KHZ,
PS_LED_PLUSE_80KHZ,
PS_LED_PLUSE_90KHZ,
PS_LED_PLUSE_100KHZ,
};
enum PsLedDuty {
PS_LED_DUTY_25 = 0x00,
PS_LED_DUTY_50,
PS_LED_DUTY_75,
PS_LED_DUTY_100,
};
enum PsLedCurrent {
PS_LED_CUR_5MA = 0x00,
PS_LED_CUR_10MA,
PS_LED_CUR_20MA,
PS_LED_CUR_50MA,
PS_LED_CUR_100MA,
};
enum PsRate {
PS_MEAS_RATE_50MS,
PS_MEAS_RATE_70MS,
PS_MEAS_RATE_100MS,
PS_MEAS_RATE_200MS,
PS_MEAS_RATE_500MS,
PS_MEAS_RATE_1000MS,
PS_MEAS_RATE_2000MS,
PS_MEAS_RATE_10MS = 8,
};
enum IntegrationTime {
ALS_INTEGRATION_TIME_100MS = 0x00,
ALS_INTEGRATION_TIME_50MS,
ALS_INTEGRATION_TIME_200MS,
ALS_INTEGRATION_TIME_400MS,
ALS_INTEGRATION_TIME_150MS,
ALS_INTEGRATION_TIME_250MS,
ALS_INTEGRATION_TIME_300MS,
ALS_INTEGRATION_TIME_350MS,
};
enum MeasurementRate {
ALS_MEASUREMENT_TIME_50MS,
ALS_MEASUREMENT_TIME_100MS,
ALS_MEASUREMENT_TIME_200MS,
ALS_MEASUREMENT_TIME_500MS,
ALS_MEASUREMENT_TIME_1000MS,
ALS_MEASUREMENT_TIME_2000MS,
};
#if defined(ARDUINO)
SensorLTR553(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = LTR553_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorLTR553()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = LTR553_SLAVE_ADDRESS;
}
~SensorLTR553()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = LTR553_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void setIRQLevel(IrqLevel level)
{
level ? setRegisterBit(LTR553_REG_INTERRUPT, 2) : clrRegisterBit(LTR553_REG_INTERRUPT, 2);
}
void enableIRQ(IrqMode mode)
{
writeRegister(LTR553_REG_INTERRUPT, 0xFC, mode);
}
void disableIRQ()
{
writeRegister(LTR553_REG_INTERRUPT, 0xFC, 0x00);
}
//! Light Sensor !
bool psAvailable()
{
return getRegisterBit(LTR553_REG_ALS_PS_STATUS, 0);
}
void setLightSensorThreshold(uint16_t low, uint16_t high)
{
uint8_t buffer[4] = {
(uint8_t)(high & 0xFF),
(uint8_t)((high >> 8) & 0xFF),
(uint8_t)(low & 0xFF),
(uint8_t)((low >> 8) & 0xFF),
};
writeRegister(LTR553_REG_ALS_THRES_UP_0, buffer, 4);
}
// Controls the N number of times the measurement data is outside the range
// defined by the upper and lower threshold limits before asserting the interrupt.
void setLightSensorPersists(uint8_t count)
{
writeRegister(LTR553_REG_INTERRUPT_PERSIST, 0xF0, count - 1);
}
void setLightSensorRate(IntegrationTime integrationTime, MeasurementRate measurementRate)
{
writeRegister(LTR553_REG_ALS_MEAS_RATE, 0x00, (integrationTime & 0xF) << 8 | (measurementRate & 0xF));
}
void enableLightSensor()
{
setRegisterBit(LTR553_REG_ALS_CONTR, 0);
}
void disableLightSensor()
{
clrRegisterBit(LTR553_REG_ALS_CONTR, 0);
}
void setLightSensorGain(LightSensorGain gain)
{
writeRegister(LTR553_REG_ALS_CONTR, 0xE3, gain);
}
int getLightSensor(uint8_t ch)
{
uint8_t buffer[2] = {0};
// Check ALS Data is Valid
if (getRegisterBit(LTR553_REG_ALS_PS_STATUS, 7) != false) {
return 0;
}
int val = readRegister(ch == 1 ? LTR553_REG_ALS_DATA_CH1_0 : LTR553_REG_ALS_DATA_CH0_0, buffer, 2);
if (val == DEV_WIRE_ERR) {
return DEV_WIRE_ERR;
}
return buffer[0] | (buffer[1] << 8);
}
//! Proximity sensor !
// Controls the N number of times the measurement data is outside the range
// defined by the upper and lower threshold limits before asserting the interrupt.
void setProximityPersists(uint8_t count)
{
writeRegister(LTR553_REG_INTERRUPT_PERSIST, 0x0F, count == 0 ? 0 : count - 1);
}
void setProximityThreshold(uint16_t low, uint16_t high)
{
writeRegister(LTR553_REG_PS_THRES_UP_0, lowByte(high));
writeRegister(LTR553_REG_PS_THRES_UP_1, lowByte(high >> 8) & 0x0F);
writeRegister(LTR553_REG_PS_THRES_LOW_0, lowByte(low));
writeRegister(LTR553_REG_PS_THRES_LOW_1, lowByte(low >> 8) & 0x0F);
}
void setProximityRate(PsRate rate)
{
writeRegister(LTR553_REG_PS_MEAS_RATE, 0xF0, rate & 0x0F);
}
void enableProximity()
{
writeRegister(LTR553_REG_PS_CONTR, 0xF3u, 0x03u);
}
void disableProximity()
{
writeRegister(LTR553_REG_PS_CONTR, 0xF3u, 0x00u);
}
void enablePsIndicator()
{
setRegisterBit(LTR553_REG_PS_CONTR, 5);
}
void disablePsIndicator()
{
clrRegisterBit(LTR553_REG_PS_CONTR, 5);
}
int getProximity(bool *saturated = NULL )
{
uint8_t buffer[2] = {0};
int val = readRegister(LTR553_REG_PS_DATA_0, buffer, 2);
if (val == DEV_WIRE_ERR) {
return DEV_WIRE_ERR;
}
if (saturated) {
*saturated = buffer[1] & 0x80;
}
return buffer[0] | (buffer[1] & 0x03);
}
void setPsLedPulsePeriod(PsLedPeriod period)
{
writeRegister(LTR553_REG_PS_LED, 0x1F, period);
}
void setPsLedDutyCycle(PsLedDuty duty)
{
writeRegister(LTR553_REG_PS_LED, 0xE7, duty);
}
void setPsLedCurrent(PsLedCurrent cur)
{
writeRegister(LTR553_REG_PS_LED, 0xF8, cur);
}
void setPsLedPulses(uint8_t pulesNum)
{
writeRegister(LTR553_REG_PS_N_PULSES, 0xF0, pulesNum & 0x0F);
}
int getPartID()
{
int val = readRegister(LTR553_REG_PART_ID);
if (val == DEV_WIRE_ERR) {
return DEV_WIRE_ERR;
}
return (val >> 4) & 0x0F;
}
int getRevisionID()
{
int val = readRegister(LTR553_REG_PART_ID);
if (val == DEV_WIRE_ERR) {
return DEV_WIRE_ERR;
}
return (val) & 0x0F;
}
int getManufacturerID()
{
// Manufacturer ID (0x05H)
return readRegister(LTR553_REG_MANUFAC_ID);
}
void reset()
{
setRegisterBit(LTR553_REG_ALS_CONTR, 1);
}
private:
bool initImpl()
{
setReadRegisterSendStop(false);
reset();
return getManufacturerID() == LTR553_DEFAULT_MAN_ID;
}
int getReadMaskImpl()
{
return -1;
}
protected:
};

View File

@@ -0,0 +1,248 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorLib.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-05
*/
#pragma once
#if defined(ARDUINO)
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#elif defined(ESP_PLATFORM)
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "esp_log.h"
#include "esp_err.h"
#include <cstring>
#include "esp_idf_version.h"
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
#include "driver/i2c_master.h"
#else
#include "driver/i2c.h"
#endif //ESP_IDF_VERSION
#else
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#endif
#ifdef ARDUINO_ARCH_MBED
// Not supported at the moment
#error The Arduino RP2040 MBED board package is not supported when PIO is used. Use the community package by Earle Philhower.
#endif
#if defined(ARDUINO)
#if defined(ARDUINO_ARCH_RP2040)
#define PLATFORM_SPI_TYPE SPIClassRP2040
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER SPI_MSB_FIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#elif defined(ARDUINO_ARCH_STM32)
#define PLATFORM_SPI_TYPE SPIClass
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER MSBFIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#elif defined(ARDUINO_ARCH_NRF52)
#define PLATFORM_SPI_TYPE SPIClass
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER MSBFIRST
#define DEFAULT_SDA (0xFF)
#define DEFAULT_SCL (0xFF)
#define DEFAULT_SPISETTING SPISettings()
#else
#define PLATFORM_SPI_TYPE SPIClass
#define PLATFORM_WIRE_TYPE TwoWire
#define SPI_DATA_ORDER SPI_MSBFIRST
#define DEFAULT_SDA (SDA)
#define DEFAULT_SCL (SCL)
#define DEFAULT_SPISETTING SPISettings(__freq, __dataOrder, __dataMode);
#endif
#elif defined(ESP_PLATFORM)
#define SENSORLIB_I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define SENSORLIB_I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define SENSORLIB_I2C_MASTER_TIMEOUT_MS 1000
#define SENSORLIB_I2C_MASTER_SEEED 400000
#endif
#ifndef I2C_BUFFER_LENGTH
#define I2C_BUFFER_LENGTH (32)
#endif
enum SensorLibInterface {
SENSORLIB_SPI_INTERFACE = 1,
SENSORLIB_I2C_INTERFACE
};
typedef struct __SensorLibPins {
int irq;
int rst;
union __ {
struct {
int sda;
int scl;
int addr;
#ifdef ARDUINO
PLATFORM_WIRE_TYPE *wire;
#endif
} i2c_dev;
struct {
int cs;
int miso;
int mosi;
int sck;
#ifdef ARDUINO
PLATFORM_SPI_TYPE *spi;
#endif
} spi_dev;
} u ;
SensorLibInterface intf;
} SensorLibConfigure;
#define SENSOR_PIN_NONE (-1)
#define DEV_WIRE_NONE (0)
#define DEV_WIRE_ERR (-1)
#define DEV_WIRE_TIMEOUT (-2)
#ifndef IRAM_ATTR
#define IRAM_ATTR
#endif
#ifdef _BV
#undef _BV
#endif
#define _BV(b) (1UL << (uint32_t)(b))
// #define LOG_PORT Serial
#ifdef LOG_PORT
#define LOG(fmt, ...) LOG_PORT.printf("[%s] " fmt "\n", __func__, ##__VA_ARGS__)
#define LOG_BIN(x) LOG_PORT.println(x,BIN);
#else
#define LOG(fmt, ...) printf("[%s] " fmt "\n", __func__, ##__VA_ARGS__)
#define LOG_BIN(x) printf("[%s] 0x%X\n", __func__, x)
#endif
#ifndef lowByte
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#endif
#ifndef highByte
#define highByte(w) ((uint8_t) ((w) >> 8))
#endif
#ifndef bitRead
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#endif
#ifndef bitSet
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#endif
#ifndef bitClear
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#endif
#ifndef bitToggle
#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
#endif
#ifndef bitWrite
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
#endif
#define SENSORLIB_ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented")))
#define SENSORLIB_COUNT(x) (sizeof(x)/sizeof(*x))
#ifdef ARDUINO
#if !defined(ESP32) || !defined(ARDUINO_ARCH_ESP32)
#define LOG_FILE_LINE_INFO __FILE__, __LINE__
#ifndef log_e
#define log_e(fmt, ...) Serial.printf("[E][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#ifndef log_i
#define log_i(fmt, ...) Serial.printf("[I][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#ifndef log_d
#define log_d(fmt, ...) Serial.printf("[D][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#endif
#elif defined(ESP_PLATFORM)
#define log_e(...) printf(__VA_ARGS__)
#define log_i(...) printf(__VA_ARGS__)
#define log_d(...) printf(__VA_ARGS__)
#else
#define log_e(...)
#define log_i(...)
#define log_d(...)
#endif
#if !defined(ARDUINO) && defined(ESP_PLATFORM)
#ifndef INPUT
#define INPUT (0x0)
#endif
#ifndef OUTPUT
#define OUTPUT (0x1)
#endif
#ifndef RISING
#define RISING (0x01)
#endif
#ifndef FALLING
#define FALLING (0x02)
#endif
#ifndef LOW
#define LOW 0
#endif
#ifndef HIGH
#define HIGH 1
#endif
#include "platform/esp_arduino.h"
#endif
#include "DevicesPins.h"

View File

@@ -0,0 +1,392 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorPCF85063.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-07
*
*/
#pragma once
#include "REG/PCF85063Constants.h"
#include "SensorCommon.tpp"
#include "SensorRTC.h"
class SensorPCF85063 :
public SensorCommon<SensorPCF85063>,
public RTCCommon<SensorPCF85063>
{
friend class SensorCommon<SensorPCF85063>;
friend class RTCCommon<SensorPCF85063>;
public:
enum ClockHz {
CLK_32768HZ = 0,
CLK_16384HZ,
CLK_8192HZ,
CLK_4096HZ,
CLK_2048HZ,
CLK_1024HZ,
CLK_1HZ,
CLK_LOW,
};
#if defined(ARDUINO)
SensorPCF85063(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF85063_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorPCF85063()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = PCF85063_SLAVE_ADDRESS;
}
~SensorPCF85063()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF85063_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void setDateTime(RTC_DateTime datetime)
{
setDateTime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second);
}
void setDateTime(uint16_t year,
uint8_t month,
uint8_t day,
uint8_t hour,
uint8_t minute,
uint8_t second)
{
uint8_t buffer[7];
buffer[0] = DEC2BCD(second) & 0x7F;
buffer[1] = DEC2BCD(minute);
buffer[2] = DEC2BCD(hour);
buffer[3] = DEC2BCD(day);
buffer[4] = getDayOfWeek(day, month, year);
buffer[5] = DEC2BCD(month);
buffer[6] = DEC2BCD(year % 100);
writeRegister(PCF85063_SEC_REG, buffer, 7);
}
RTC_DateTime getDateTime()
{
RTC_DateTime datetime;
uint8_t buffer[7];
readRegister(PCF85063_SEC_REG, buffer, 7);
datetime.available = ((buffer[0] & 0x80) == 0x80) ? false : true;
datetime.second = BCD2DEC(buffer[0] & 0x7F);
datetime.minute = BCD2DEC(buffer[1] & 0x7F);
if (is24Hour) {
datetime.hour = BCD2DEC(buffer[2] & 0x3F); // 24-hour mode
} else {
datetime.AMPM = (buffer[2] & 0x20) == 0x20 ? 'A' : 'P';
datetime.hour = BCD2DEC(buffer[2] & 0x1F); // 12-hour mode
}
datetime.day = BCD2DEC(buffer[3] & 0x3F);
datetime.week = BCD2DEC(buffer[4] & 0x07);
datetime.month = BCD2DEC(buffer[5] & 0x1F);
datetime.year = BCD2DEC(buffer[6]) + 2000;
return datetime;
}
void getDateTime(struct tm *timeinfo)
{
if (!timeinfo)return;
*timeinfo = conversionUnixTime(getDateTime());
}
/*
Defalut use 24H mode
bool is24HourMode()
{
return is24Hour;
}
bool is12HourMode()
{
return !is24Hour;
}
void set24Hour()
{
is24Hour = true;
clrRegisterBit(PCF85063_CTRL1_REG, 1);
}
void set12Hour()
{
is24Hour = false;
setRegisterBit(PCF85063_CTRL1_REG, 1);
}
*/
void stop()
{
setRegisterBit(PCF85063_CTRL1_REG, 5);
}
void start()
{
clrRegisterBit(PCF85063_CTRL1_REG, 5);
}
bool isRunning()
{
return !getRegisterBit(PCF85063_CTRL1_REG, 5);
}
void enableAlarm()
{
setRegisterBit(PCF85063_CTRL2_REG, 7);
}
void disableAlarm()
{
clrRegisterBit(PCF85063_CTRL2_REG, 7);
}
void resetAlarm()
{
clrRegisterBit(PCF85063_CTRL2_REG, 6);
}
bool isAlarmActive()
{
return getRegisterBit(PCF85063_CTRL2_REG, 6);
}
RTC_Alarm getAlarm()
{
uint8_t buffer[5];
readRegister(PCF85063_ALRM_MIN_REG, buffer, 5);
buffer[0] = BCD2DEC(buffer[0] & 0x80); //second
buffer[1] = BCD2DEC(buffer[1] & 0x40); //minute
buffer[2] = BCD2DEC(buffer[2] & 0x40); //hour
buffer[3] = BCD2DEC(buffer[3] & 0x08); //day
buffer[4] = BCD2DEC(buffer[4] & 0x08); //weekday
// RTC_Alarm(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t week)
return RTC_Alarm(buffer[2], buffer[1], buffer[0], buffer[3], buffer[4]);
}
void setAlarm(RTC_Alarm alarm)
{
setAlarm(alarm.hour,
alarm.minute,
alarm.second,
alarm.day,
alarm.week);
}
void setAlarm(uint8_t hour,
uint8_t minute,
uint8_t second,
uint8_t day,
uint8_t week)
{
uint8_t buffer[5] = {0};
RTC_DateTime datetime = getDateTime();
uint8_t daysInMonth = getDaysInMonth(datetime.month, datetime.year);
if (second != PCF85063_NO_ALARM) {
if (second > 59) {
second = 59;
}
buffer[0] = DEC2BCD(second);
buffer[0] &= ~PCF85063_ALARM_ENABLE;
} else {
buffer[0] = PCF85063_ALARM_ENABLE;
}
if (minute != PCF85063_NO_ALARM) {
if (minute > 59) {
minute = 59;
}
buffer[1] = DEC2BCD(minute);
buffer[1] &= ~PCF85063_ALARM_ENABLE;
} else {
buffer[1] = PCF85063_ALARM_ENABLE;
}
if (hour != PCF85063_NO_ALARM) {
if (is24Hour) {
if (hour > 23) {
hour = 23;
}
buffer[2] = DEC2BCD(hour);
buffer[2] &= ~PCF85063_ALARM_ENABLE;
} else {
/*
if (hour > 12) {
hour = 12;
}
buffer[2] = DEC2BCD(hour);
buffer[2] |= isAM ? 0 : _BV(5);
buffer[2] &= ~PCF85063_ALARM_ENABLE;
*/
}
} else {
buffer[2] = PCF85063_ALARM_ENABLE;
}
if (day != PCF85063_NO_ALARM) {
//TODO:Check day in Month
buffer[3] = DEC2BCD(((day) < (1) ? (1) : ((day) > (daysInMonth) ? (daysInMonth) : (day))));
buffer[3] &= ~PCF85063_ALARM_ENABLE;
} else {
buffer[3] = PCF85063_ALARM_ENABLE;
}
if (week != PCF85063_NO_ALARM) {
if (week > 6) {
week = 6;
}
buffer[4] = DEC2BCD(week);
buffer[4] &= ~PCF85063_ALARM_ENABLE;
} else {
buffer[4] = PCF85063_ALARM_ENABLE;
}
writeRegister(PCF85063_ALRM_SEC_REG, buffer, 4);
}
void setAlarmByHours(uint8_t hour)
{
setAlarm(hour,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM);
}
void setAlarmBySecond(uint8_t second)
{
setAlarm(PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
second,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM);
}
void setAlarmByMinutes(uint8_t minute)
{
setAlarm(PCF85063_NO_ALARM,
minute,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM);
}
void setAlarmByDays(uint8_t day)
{
setAlarm(PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
day,
PCF85063_NO_ALARM);
}
void setAlarmByWeekDay(uint8_t week)
{
setAlarm(PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
PCF85063_NO_ALARM,
week);
}
void setClockOutput(ClockHz hz)
{
int val = readRegister(PCF85063_CTRL2_REG);
if (val == DEV_WIRE_ERR)return;
val &= 0xF8;
val |= hz;
writeRegister(PCF85063_CTRL2_REG, val);
}
private:
bool initImpl()
{
// 230704:Does not use power-off judgment, if the RTC backup battery is not installed,
// it will return failure. Here only to judge whether the device communication is normal
//Check device is online
int ret = readRegister(PCF85063_SEC_REG);
if (ret == DEV_WIRE_ERR) {
return false;
}
if (BCD2DEC(ret & 0x7F) > 59) {
return false;
}
//Default use 24-hour mode
is24Hour = !getRegisterBit(PCF85063_CTRL1_REG, 1);
if (!is24Hour) {
// Set 24H Mode
clrRegisterBit(PCF85063_CTRL1_REG, 1);
}
//Turn on RTC
start();
return isRunning();
}
int getReadMaskImpl()
{
return -1;
}
protected:
bool is24Hour = true;
};

View File

@@ -0,0 +1,359 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorPCF8563.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-12-09
*
*/
#pragma once
#include "REG/PCF8563Constants.h"
#include "SensorCommon.tpp"
#include "SensorRTC.h"
class SensorPCF8563 :
public SensorCommon<SensorPCF8563>,
public RTCCommon<SensorPCF8563>
{
friend class SensorCommon<SensorPCF8563>;
friend class RTCCommon<SensorPCF8563>;
public:
enum {
CLK_32_768KHZ,
CLK_1024KHZ,
CLK_32HZ,
CLK_1HZ,
};
#if defined(ARDUINO)
SensorPCF8563(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF8563_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorPCF8563()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = PCF8563_SLAVE_ADDRESS;
}
~SensorPCF8563()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = PCF8563_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void setDateTime(RTC_DateTime datetime)
{
setDateTime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second);
}
void setDateTime(uint16_t year,
uint8_t month,
uint8_t day,
uint8_t hour,
uint8_t minute,
uint8_t second)
{
uint8_t buffer[7];
buffer[0] = DEC2BCD(second) & 0x7F;
buffer[1] = DEC2BCD(minute);
buffer[2] = DEC2BCD(hour);
buffer[3] = DEC2BCD(day);
buffer[4] = getDayOfWeek(day, month, year);
buffer[5] = DEC2BCD(month);
buffer[6] = DEC2BCD(year % 100);
if ((2000 % year) == 2000) {
buffer[5] &= 0x7F;
} else {
buffer[5] |= 0x80;
}
writeRegister(PCF8563_SEC_REG, buffer, 7);
}
RTC_DateTime getDateTime()
{
RTC_DateTime datetime;
uint8_t buffer[7];
readRegister(PCF8563_SEC_REG, buffer, 7);
datetime.available = ((buffer[0] & 0x80) == 0x80) ? false : true;
datetime.second = BCD2DEC(buffer[0] & 0x7F);
datetime.minute = BCD2DEC(buffer[1] & 0x7F);
datetime.hour = BCD2DEC(buffer[2] & 0x3F);
datetime.day = BCD2DEC(buffer[3] & 0x3F);
datetime.week = BCD2DEC(buffer[4] & 0x07);
datetime.month = BCD2DEC(buffer[5] & 0x1F);
datetime.year = BCD2DEC(buffer[6]);
//cetury : 0 = 1900 , 1 = 2000
datetime.year += (buffer[5] & PCF8563_CENTURY_MASK) ? 1900 : 2000;
return datetime;
}
void getDateTime(struct tm *timeinfo)
{
if (!timeinfo)return;
*timeinfo = conversionUnixTime(getDateTime());
}
RTC_Alarm getAlarm()
{
uint8_t buffer[4];
readRegister(PCF8563_ALRM_MIN_REG, buffer, 4);
buffer[0] = BCD2DEC(buffer[0] & 0x80); //minute
buffer[1] = BCD2DEC(buffer[1] & 0x40); //hour
buffer[2] = BCD2DEC(buffer[2] & 0x40); //day
buffer[3] = BCD2DEC(buffer[3] & 0x08); //weekday
// RTC_Alarm(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8_t week)
return RTC_Alarm(buffer[1], buffer[0], 0, buffer[2], buffer[3]);
}
void enableAlarm()
{
setRegisterBit(PCF8563_STAT2_REG, 1);
}
void disableAlarm()
{
clrRegisterBit(PCF8563_STAT2_REG, 1);
}
void resetAlarm()
{
clrRegisterBit(PCF8563_STAT2_REG, 3);
}
bool isAlarmActive()
{
return getRegisterBit(PCF8563_STAT2_REG, 3);
}
void setAlarm(RTC_Alarm alarm)
{
setAlarm( alarm.hour, alarm.minute, alarm.day, alarm.week);
}
void setAlarm(uint8_t hour, uint8_t minute, uint8_t day, uint8_t week)
{
uint8_t buffer[4] = {0};
RTC_DateTime datetime = getDateTime();
uint8_t daysInMonth = getDaysInMonth(datetime.month, datetime.year);
if (minute != PCF8563_NO_ALARM) {
if (minute > 59) {
minute = 59;
}
buffer[0] = DEC2BCD(minute);
buffer[0] &= ~PCF8563_ALARM_ENABLE;
} else {
buffer[0] = PCF8563_ALARM_ENABLE;
}
if (hour != PCF8563_NO_ALARM) {
if (hour > 23) {
hour = 23;
}
buffer[1] = DEC2BCD(hour);
buffer[1] &= ~PCF8563_ALARM_ENABLE;
} else {
buffer[1] = PCF8563_ALARM_ENABLE;
}
if (day != PCF8563_NO_ALARM) {
//TODO:Check day in Month
buffer[2] = DEC2BCD(((day) < (1) ? (1) : ((day) > (daysInMonth) ? (daysInMonth) : (day))));
buffer[2] &= ~PCF8563_ALARM_ENABLE;
} else {
buffer[2] = PCF8563_ALARM_ENABLE;
}
if (week != PCF8563_NO_ALARM) {
if (week > 6) {
week = 6;
}
buffer[3] = DEC2BCD(week);
buffer[3] &= ~PCF8563_ALARM_ENABLE;
} else {
buffer[3] = PCF8563_ALARM_ENABLE;
}
writeRegister(PCF8563_ALRM_MIN_REG, buffer, 4);
}
void setAlarmByMinutes(uint8_t minute)
{
setAlarm(PCF8563_NO_ALARM, minute, PCF8563_NO_ALARM, PCF8563_NO_ALARM);
}
void setAlarmByDays(uint8_t day)
{
setAlarm(PCF8563_NO_ALARM, PCF8563_NO_ALARM, day, PCF8563_NO_ALARM);
}
void setAlarmByHours(uint8_t hour)
{
setAlarm(hour, PCF8563_NO_ALARM, PCF8563_NO_ALARM, PCF8563_NO_ALARM);
}
void setAlarmByWeekDay(uint8_t week)
{
setAlarm(PCF8563_NO_ALARM, PCF8563_NO_ALARM, PCF8563_NO_ALARM, week);
}
bool isCountdownTimerEnable()
{
uint8_t buffer[2];
buffer[0] = readRegister(PCF8563_STAT2_REG);
buffer[1] = readRegister(PCF8563_TIMER1_REG);
if (buffer[0] & PCF8563_TIMER_TIE) {
return buffer[1] & PCF8563_TIMER_TE ? true : false;
}
return false;
}
bool isCountdownTimerActive()
{
return getRegisterBit(PCF8563_STAT2_REG, 2);
}
void enableCountdownTimer()
{
setRegisterBit(PCF8563_STAT2_REG, 0);
}
void disableCountdownTimer()
{
clrRegisterBit(PCF8563_STAT2_REG, 0);
}
void setCountdownTimer(uint8_t val, uint8_t freq)
{
uint8_t buffer[3];
buffer[1] = readRegister(PCF8563_TIMER1_REG);
buffer[1] |= (freq & PCF8563_TIMER_TD10);
buffer[2] = val;
writeRegister(PCF8563_TIMER1_REG, buffer[1]);
writeRegister(PCF8563_TIMER2_REG, buffer[2]);
}
void clearCountdownTimer()
{
uint8_t val;
val = readRegister(PCF8563_STAT2_REG);
val &= ~(PCF8563_TIMER_TF | PCF8563_TIMER_TIE);
val |= PCF8563_ALARM_AF;
writeRegister(PCF8563_STAT2_REG, val);
writeRegister(PCF8563_TIMER1_REG, 0x00);
}
void enableCLK(uint8_t freq)
{
if (freq > CLK_1HZ) return;
writeRegister(PCF8563_SQW_REG, freq | PCF8563_CLK_ENABLE);
}
void disableCLK()
{
clrRegisterBit(PCF8563_SQW_REG, 7);
}
private:
bool initImpl()
{
// Check whether RTC time is valid? If it is invalid, it can be judged
// that there is a problem with the hardware, or the RTC power supply voltage is too low
/*
int count = 0;
for (int i = 0; i < 3; ++i) {
if (!getRegisterBit(PCF8563_SEC_REG, 7)) {
count++;
}
}
if (count != 3 ) {
return false;
}
*/
// 230704:Does not use power-off judgment, if the RTC backup battery is not installed,
// it will return failure. Here only to judge whether the device communication is normal
//Check device is online
int ret = readRegister(PCF8563_SEC_REG);
if (ret == DEV_WIRE_ERR) {
return false;
}
if (BCD2DEC(ret & 0x7F) > 59) {
return false;
}
// Determine whether the hardware clock year, month, and day match the internal time of the RTC.
// If they do not match, it will be updated to the compilation date
// RTC_DateTime compileDatetime = RTC_DateTime(__DATE__, __TIME__);
// RTC_DateTime hwDatetime = getDateTime();
// if (compileDatetime.year != hwDatetime.year ||
// compileDatetime.month != hwDatetime.month ||
// compileDatetime.day != hwDatetime.month
// ) {
// LOG("No match yy:mm:dd . set datetime to compilation date time");
// setDateTime(compileDatetime);
// }
return true;
}
int getReadMaskImpl()
{
return -1;
}
protected:
};

View File

@@ -0,0 +1,402 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorQMC6310.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-10-16
*
*/
#pragma once
#include "REG/QMC6310Constants.h"
#include "SensorCommon.tpp"
class Polar
{
public:
Polar(): polar(0), Gauss(0), uT(0) {}
Polar(float polar, float Gauss, float uT): polar(polar), Gauss(Gauss), uT(uT) {}
float polar;
float Gauss;
float uT;
};
class SensorQMC6310 :
public SensorCommon<SensorQMC6310>
{
friend class SensorCommon<SensorQMC6310>;
public:
enum SensorMode {
MODE_SUSPEND,
MODE_NORMAL,
MODE_SINGLE,
MODE_CONTINUOUS,
};
// Unit:Guass
enum MagRange {
RANGE_30G,
RANGE_12G,
RANGE_8G,
RANGE_2G,
};
enum OutputRate {
DATARATE_10HZ,
DATARATE_50HZ,
DATARATE_100HZ,
DATARATE_200HZ,
};
enum CtrlReg {
SET_RESET_ON,
SET_ONLY_ON,
SET_RESET_OFF,
};
enum OverSampleRatio {
OSR_8,
OSR_4,
OSR_2,
OSR_1,
};
enum DownSampleRatio {
DSR_1,
DSR_2,
DSR_4,
DSR_8,
};
#if defined(ARDUINO)
SensorQMC6310(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = QMC6310_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
SensorQMC6310()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = QMC6310_SLAVE_ADDRESS;
}
~SensorQMC6310()
{
deinit();
}
#if defined(ARDUINO)
bool init(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = QMC6310_SLAVE_ADDRESS)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
void deinit()
{
// end();
}
void reset()
{
writeRegister(QMC6310_REG_CMD2, 0x80);
delay(10);
writeRegister(QMC6310_REG_CMD2, 0x00);
}
uint8_t getChipID()
{
return readRegister(QMC6310_REG_CHIP_ID);
}
int getStatus()
{
return readRegister(QMC6310_REG_STAT);
}
bool isDataReady()
{
if (readRegister(QMC6310_REG_STAT) & 0x01) {
return true;
}
LOG("No ready!\n");
return false;
}
bool isDataOverflow()
{
if (readRegister(QMC6310_REG_STAT) & 0x02) {
return true;
}
return false;
}
int setSelfTest(bool en)
{
return en ? setRegisterBit(QMC6310_REG_CMD2, 1)
: clrRegisterBit(QMC6310_REG_CMD2, 1);
}
int setMode(SensorMode m)
{
return writeRegister(QMC6310_REG_CMD1, 0xFC, m);
}
int setCtrlRegister(CtrlReg c)
{
return writeRegister(QMC6310_REG_CMD2, 0xFC, c);
}
int setDataOutputRate(OutputRate odr)
{
return writeRegister(QMC6310_REG_CMD1, 0xF3, (odr << 2));
}
int setOverSampleRate(OverSampleRatio osr)
{
return writeRegister(QMC6310_REG_CMD1, 0xCF, (osr << 4));
}
int setDownSampleRate(DownSampleRatio dsr)
{
return writeRegister(QMC6310_REG_CMD1, 0x3F, (dsr << 6));
}
// Define the sign for X Y and Z axis
int setSign(uint8_t x, uint8_t y, uint8_t z)
{
int sign = x + y * 2 + z * 4;
return writeRegister(QMC6310_REG_SIGN, sign);
}
int configMagnetometer(SensorMode mode, MagRange range, OutputRate odr,
OverSampleRatio osr, DownSampleRatio dsr)
{
if (setMagRange(range) != DEV_WIRE_NONE) {
return DEV_WIRE_ERR;
}
if (writeRegister(QMC6310_REG_CMD1, 0xFC, mode) != DEV_WIRE_NONE) {
return DEV_WIRE_ERR;
}
if (writeRegister(QMC6310_REG_CMD1, 0xF3, (odr << 2)) != DEV_WIRE_NONE) {
return DEV_WIRE_ERR;
}
if (writeRegister(QMC6310_REG_CMD1, 0xCF, (osr << 4)) != DEV_WIRE_NONE) {
return DEV_WIRE_ERR;
}
if (writeRegister(QMC6310_REG_CMD1, 0x3F, (dsr << 6)) != DEV_WIRE_NONE) {
return DEV_WIRE_ERR;
}
return DEV_WIRE_NONE;
}
int setMagRange(MagRange range)
{
switch (range) {
case RANGE_30G:
sensitivity = 0.1;
break;
case RANGE_12G:
sensitivity = 0.04;
break;
case RANGE_8G:
sensitivity = 0.026;
break;
case RANGE_2G:
sensitivity = 0.0066;
break;
default:
break;
}
return writeRegister(QMC6310_REG_CMD2, 0xF3, (range << 2));
}
void setOffset(int x, int y, int z)
{
x_offset = x; y_offset = y; z_offset = z;
}
int readData()
{
uint8_t buffer[6];
int16_t x, y, z;
if (readRegister(QMC6310_REG_LSB_DX, buffer,
6) != DEV_WIRE_ERR) {
x = (int16_t)(buffer[1] << 8) | (buffer[0]);
y = (int16_t)(buffer[3] << 8) | (buffer[2]);
z = (int16_t)(buffer[5] << 8) | (buffer[4]);
if (x == 32767) {
x = -((65535 - x) + 1);
}
x = (x - x_offset);
if (y == 32767) {
y = -((65535 - y) + 1);
}
y = (y - y_offset);
if (z == 32767) {
z = -((65535 - z) + 1);
}
z = (z - z_offset);
raw[0] = x;
raw[1] = y;
raw[2] = z;
mag[0] = (float)x * sensitivity;
mag[1] = (float)y * sensitivity;
mag[2] = (float)z * sensitivity;
return DEV_WIRE_NONE;
}
return DEV_WIRE_ERR;
}
void setDeclination(float dec)
{
_declination = dec;
}
bool readPolar(Polar &p)
{
if (isDataReady()) {
readData();
float x = getX();
float y = getY();
float z = getZ();
float angle = (atan2(x, -y) / PI) * 180.0 + _declination;
angle = _convertAngleToPositive(angle);
float magnitude = sqrt(x * x + y * y + z * z);
p = Polar(angle, magnitude * 100, magnitude);
return true;
}
return false;
}
int16_t getRawX()
{
return raw[0];
}
int16_t getRawY()
{
return raw[1];
}
int16_t getRawZ()
{
return raw[2];
}
float getX()
{
return mag[0];
}
float getY()
{
return mag[1];
}
float getZ()
{
return mag[2];
}
void getMag(float &x, float &y, float &z)
{
x = mag[0];
y = mag[1];
z = mag[2];
}
void dumpCtrlRegister()
{
uint8_t buffer[2];
readRegister(QMC6310_REG_CMD1, buffer, 2);
for (int i = 0; i < 2; ++i) {
#if defined(ARDUINO)
Serial.printf("CMD%d: 0x%02x", i + 1, buffer[i]);
#else
printf("CTRL%d: 0x%02x", i + 1, buffer[i]);
#endif
#if defined(ARDUINO)
Serial.print("\t\t BIN:");
Serial.println(buffer[i], BIN);
#else
LOG("\n");
#endif
}
#if defined(ARDUINO)
Serial.println();
#else
printf("\n");
#endif
}
private:
float _convertAngleToPositive(float angle)
{
if (angle >= 360.0) {
angle = angle - 360.0;
}
if (angle < 0) {
angle = angle + 360.0;
}
return angle;
}
bool initImpl()
{
reset();
return getChipID() == QMC6310_DEFAULT_ID;
}
int getReadMaskImpl()
{
return -1;
}
protected:
int16_t raw[3];
float mag[3];
float _declination;
float sensitivity;
int16_t x_offset = 0, y_offset = 0, z_offset = 0;
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,344 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorRTC.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-07
*
*/
#pragma once
#ifdef ARDUINO
#include <Arduino.h>
#else
#include <stdint.h>
#endif /*defined(ARDUINO)*/
#include <sys/time.h>
#define RTC_DAYS_IN_JANUARY (31u)
#define RTC_DAYS_IN_FEBRUARY (28u)
#define RTC_DAYS_IN_MARCH (31u)
#define RTC_DAYS_IN_APRIL (30u)
#define RTC_DAYS_IN_MAY (31u)
#define RTC_DAYS_IN_JUNE (30u)
#define RTC_DAYS_IN_JULY (31u)
#define RTC_DAYS_IN_AUGUST (31u)
#define RTC_DAYS_IN_SEPTEMBER (30u)
#define RTC_DAYS_IN_OCTOBER (31u)
#define RTC_DAYS_IN_NOVEMBER (30u)
#define RTC_DAYS_IN_DECEMBER (31u)
enum {
DATETIME_FORMAT_HM,
DATETIME_FORMAT_HMS,
DATETIME_FORMAT_YYYY_MM_DD,
DATETIME_FORMAT_MM_DD_YYYY,
DATETIME_FORMAT_DD_MM_YYYY,
DATETIME_FORMAT_YYYY_MM_DD_H_M_S,
DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK,
};
class RTC_DateTime
{
public:
RTC_DateTime() : year(0), month(0), day(0), hour(0), minute(0), second(0), week(0), available(false) {}
RTC_DateTime(const char *date, const char *time)
{
// sample input: date = "Dec 26 2009", time = "12:34:56"
year = 2000 + StringToUint8(date + 9);
// Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
switch (date[0]) {
case 'J':
if ( date[1] == 'a' )
month = 1;
else if ( date[2] == 'n' )
month = 6;
else
month = 7;
break;
case 'F':
month = 2;
break;
case 'A':
month = date[1] == 'p' ? 4 : 8;
break;
case 'M':
month = date[2] == 'r' ? 3 : 5;
break;
case 'S':
month = 9;
break;
case 'O':
month = 10;
break;
case 'N':
month = 11;
break;
case 'D':
month = 12;
break;
}
day = StringToUint8(date + 4);
hour = StringToUint8(time);
minute = StringToUint8(time + 3);
second = StringToUint8(time + 6);
}
RTC_DateTime(uint16_t year,
uint8_t month,
uint8_t day,
uint8_t hour,
uint8_t minute,
uint8_t second
)
{
this->year = year;
this->month = month;
this->day = day;
this->hour = hour;
this->minute = minute;
this->second = second;
this->week = week;
};
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t week;
char AMPM;
bool available;
bool operator==(RTC_DateTime d)
{
return ((d.year == year) &&
(d.month == month) &&
(d.day == day) &&
(d.hour == hour) &&
(d.minute == minute));
}
private:
uint8_t StringToUint8(const char *pString)
{
uint8_t value = 0;
// skip leading 0 and spaces
while ('0' == *pString || *pString == ' ') {
pString++;
}
// calculate number until we hit non-numeral char
while ('0' <= *pString && *pString <= '9') {
value *= 10;
value += *pString - '0';
pString++;
}
return value;
}
};
class RTC_Alarm
{
public:
RTC_Alarm(void): second(0), minute(0), hour(0), day(0), week(0) {}
RTC_Alarm(
uint8_t hour,
uint8_t minute,
uint8_t second,
uint8_t day,
uint8_t week
): second(second), minute(minute), hour(hour), day(day), week(week)
{
}
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t day;
uint8_t week;
};
template <class chipType>
class RTCCommon
{
public:
const char *strftime(uint8_t sytle = DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK)
{
const char *weekString[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
static char format[64];
RTC_DateTime t = thisChip().getDateTime();
switch (sytle) {
case DATETIME_FORMAT_HM:
snprintf(format, sizeof(format), "%02d:%02d", t.hour, t.minute);
break;
case DATETIME_FORMAT_HMS:
snprintf(format, sizeof(format), "%02d:%02d:%02d", t.hour, t.minute, t.second);
break;
case DATETIME_FORMAT_YYYY_MM_DD:
snprintf(format, sizeof(format), "%d-%02d-%02d", t.year, t.month, t.day);
break;
case DATETIME_FORMAT_MM_DD_YYYY:
snprintf(format, sizeof(format), "%02d-%02d-%d", t.month, t.day, t.year);
break;
case DATETIME_FORMAT_DD_MM_YYYY:
snprintf(format, sizeof(format), "%02d-%02d-%d", t.day, t.month, t.year);
break;
case DATETIME_FORMAT_YYYY_MM_DD_H_M_S:
snprintf(format, sizeof(format), "%d-%02d-%02d/%02d:%02d:%02d", t.year, t.month, t.day, t.hour, t.minute, t.second);
break;
case DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK:
snprintf(format, sizeof(format), "%d-%02d-%02d/%02d:%02d:%02d - %s", t.year, t.month, t.day, t.hour, t.minute, t.second, weekString[t.week > 6 ? 0 : t.week]);
break;
default:
snprintf(format, sizeof(format), "%02d:%02d", t.hour, t.minute);
break;
}
return format;
}
struct tm conversionUnixTime(RTC_DateTime datetime)
{
struct tm t_tm;
t_tm.tm_hour = datetime.hour;
t_tm.tm_min = datetime.minute;
t_tm.tm_sec = datetime.second;
t_tm.tm_year = datetime.year - 1900; //Year, whose value starts from 1900
t_tm.tm_mon = datetime.month - 1; //Month (starting from January, 0 for January) - Value range is [0,11]
t_tm.tm_mday = datetime.day;
t_tm.tm_wday = datetime.week;
return t_tm;
}
time_t hwClockRead()
{
struct tm t_tm = conversionUnixTime(thisChip().getDateTime());
struct timeval val;
val.tv_sec = mktime(&t_tm);
val.tv_usec = 0;
#if __BSD_VISIBLE
settimeofday(&val, NULL);
#endif /*__BSD_VISIBLE*/
return val.tv_sec;
}
void hwClockWrite()
{
time_t now;
struct tm info;
time(&now);
localtime_r(&now, &info);
thisChip().setDateTime(info.tm_year + 1900,
info.tm_mon + 1,
info.tm_mday,
info.tm_hour,
info.tm_min,
info.tm_sec);
}
uint32_t getDayOfWeek(uint32_t day, uint32_t month, uint32_t year)
{
uint32_t val;
if (month < 3) {
month = 12u + month;
year--;
}
val = (day + (((month + 1u) * 26u) / 10u) + year + (year / 4u) + (6u * (year / 100u)) + (year / 400u)) % 7u;
if (0u == val) {
val = 7;
}
return (val - 1);
}
uint8_t getNextMonth(uint8_t curMonth)
{
return ((curMonth < 12u) ? (curMonth + 1u) : 1u);
}
uint16_t getNextYear(uint16_t curYear)
{
return (curYear + 1u);
}
uint32_t getLeapYear(uint32_t year)
{
uint32_t val;
if (((0u == (year % 4Lu)) && (0u != (year % 100Lu))) || (0u == (year % 400Lu))) {
val = 1uL;
} else {
val = 0uL;
}
return val;
}
uint8_t getDaysInMonth(uint8_t month, uint16_t year)
{
const uint8_t daysInMonthTable[12] = {RTC_DAYS_IN_JANUARY,
RTC_DAYS_IN_FEBRUARY,
RTC_DAYS_IN_MARCH,
RTC_DAYS_IN_APRIL,
RTC_DAYS_IN_MAY,
RTC_DAYS_IN_JUNE,
RTC_DAYS_IN_JULY,
RTC_DAYS_IN_AUGUST,
RTC_DAYS_IN_SEPTEMBER,
RTC_DAYS_IN_OCTOBER,
RTC_DAYS_IN_NOVEMBER,
RTC_DAYS_IN_DECEMBER
};
uint8_t val;
val = daysInMonthTable[month - 1u];
if (2 == month) {
if (0u != getLeapYear(year)) {
val++;
}
}
return val;
}
uint8_t BCD2DEC(uint8_t val)
{
return ((val / 16 * 10) + (val % 16));
}
uint8_t DEC2BCD(uint8_t val)
{
return ((val / 10 * 16) + (val % 10));
}
/*
* CRTP Helper
*/
protected:
inline const chipType &thisChip() const
{
return static_cast<const chipType &>(*this);
}
inline chipType &thisChip()
{
return static_cast<chipType &>(*this);
}
};

View File

@@ -0,0 +1,123 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorWireHelper.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-05
*
*/
#include "SensorWireHelper.h"
#if defined(ARDUINO)
int SensorWireHelper::regdump(TwoWire &w, Stream &serial, uint8_t devAddr, uint8_t start, uint8_t length)
{
uint8_t *buffer = (uint8_t *)malloc(length);
if (!buffer) return -1;
w.begin();
w.beginTransmission(devAddr);
w.write(start);
if (w.endTransmission() != 0) {
free(buffer);
return -1;
}
size_t len = w.requestFrom(devAddr, length);
if (length != len) {
free(buffer);
return -1;
}
w.readBytes(buffer, length);
hexdump(buffer, length, serial);
free(buffer);
return 0;
}
void SensorWireHelper::dumpDevices(TwoWire &w, Stream &serial, int first, int last)
{
int i, j;
int ret;
serial.printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
for (i = 0; i < 128; i += 16) {
serial.printf("%02x: ", i);
for (j = 0; j < 16; j++) {
/* Skip unwanted addresses */
if (i + j < first || i + j > last) {
serial.printf(" ");
continue;
}
w.beginTransmission(i + j);
ret = w.endTransmission();
if (ret != 0)
serial.printf("-- ");
else
serial.printf("%02x ", i + j);
}
serial.printf("\n");
}
}
void SensorWireHelper::hexdump(uint8_t *data, size_t len, Stream &serial)
{
size_t rem_len = len;
for (size_t i = 0; i < len; i += 16) {
char str[80];
snprintf(str, 80, "%07x ", i);
size_t line_len = 16;
if (rem_len < line_len) {
line_len = rem_len;
}
for (size_t j = 0; j < line_len; j++) {
snprintf(&str[8 + j * 3], 80, "%02x ", data[i + j]);
}
for (size_t j = line_len; j < 16; j++) {
snprintf(&str[8 + j * 3], 80, " ");
}
str[56] = '|';
str[57] = ' ';
for (size_t j = 0; j < line_len; j++) {
char c = data[i + j];
if ((c < ' ') || (c > '~')) {
c = '.';
}
snprintf(&str[58 + j], 80, "%c", c);
}
for (size_t j = line_len; j < 16; j++) {
snprintf(&str[58 + j], 80, " ");
}
serial.println(str);
rem_len -= 16;
}
}
#endif //ARDUINO

View File

@@ -0,0 +1,46 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorWireHelper.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-10
*
*/
#pragma once
#if defined(ARDUINO)
#include <Arduino.h>
#include <Wire.h>
class SensorWireHelper
{
public:
static int regdump(TwoWire &w, Stream &serial, uint8_t devAddr, uint8_t start, uint8_t len);
static void dumpDevices(TwoWire &w, Stream &serial = Serial, int first = 0, int last = 127);
static void hexdump(uint8_t *data, size_t len, Stream &serial = Serial);
};
#endif /*ARDUINO*/

View File

@@ -0,0 +1,312 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvCHSC5816.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-12
*
*/
#pragma once
#include "REG/CHSC5816Constants.h"
#include "TouchDrvInterface.hpp"
#include "SensorCommon.tpp"
typedef struct __CHSC5816_Header {
uint16_t fw_ver;
uint16_t checksum;
uint32_t sig;
uint32_t vid_pid;
uint16_t raw_offet;
uint16_t dif_offet;
} CHSC5816_Header_t;
union __CHSC5816_PointReg {
struct {
uint8_t status;
uint8_t fingerNumber;
uint8_t x_l8;
uint8_t y_l8;
uint8_t z;
uint8_t x_h4: 4;
uint8_t y_h4: 4;
uint8_t id: 4;
uint8_t event: 4;
uint8_t p2;
} rp;
unsigned char data[8];
};
class TouchDrvCHSC5816 :
public TouchDrvInterface,
public SensorCommon<TouchDrvCHSC5816>
{
friend class SensorCommon<TouchDrvCHSC5816>;
public:
#if defined(ARDUINO)
TouchDrvCHSC5816(PLATFORM_WIRE_TYPE &w,
int sda = DEFAULT_SDA,
int scl = DEFAULT_SCL,
uint8_t addr = CHSC5816_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__rst = SENSOR_PIN_NONE;
__irq = SENSOR_PIN_NONE;
__addr = addr;
}
#endif
TouchDrvCHSC5816()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__rst = SENSOR_PIN_NONE;
__irq = SENSOR_PIN_NONE;
__addr = CHSC5816_SLAVE_ADDRESS;
}
~TouchDrvCHSC5816()
{
// deinit();
}
#if defined(ARDUINO)
bool begin(PLATFORM_WIRE_TYPE &w,
uint8_t addr = CHSC5816_SLAVE_ADDRESS,
int sda = DEFAULT_SDA,
int scl = DEFAULT_SCL)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#endif
#if defined(ESP_PLATFORM) && !defined(ARDUINO)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
return SensorCommon::begin(i2c_dev_bus_handle, addr);
}
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
return SensorCommon::begin(port_num, addr, sda, scl);
}
#endif //ESP_IDF_VERSION
#endif
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
}
void reset()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioLevel(__rst, LOW);
delay(3);
this->setGpioLevel(__rst, HIGH);
delay(5);
}
}
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point = 1)
{
__CHSC5816_PointReg touch;
// CHSC5816_REG_POINT
uint8_t write_buffer[] = {0x20, 0x00, 0x00, 0x2c};
writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), touch.data, 8);
if (touch.rp.status == 0xFF && touch.rp.fingerNumber == 0) {
return 0;
}
if (x_array) {
*x_array = (unsigned int)(touch.rp.x_h4 << 8) | touch.rp.x_l8;
}
if (y_array) {
*y_array = (unsigned int)(touch.rp.y_h4 << 8) | touch.rp.y_l8;
}
updateXY(1, x_array, y_array);
return 1;
}
bool isPressed()
{
if (__irq != SENSOR_PIN_NONE) {
return this->getGpioLevel(__irq) == LOW;
}
return getPoint(NULL, NULL);
}
const char *getModelName()
{
return "CHSC5816";
}
//2uA
void sleep()
{
uint8_t write_buffer[] = {
0x20, 0x00, 0x00, 0x00, // CHSC5816_REG_CMD_BUFF
0xF8, 0x16, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE9
};
writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer));
}
void wakeup()
{
reset();
}
void idle()
{
uint8_t write_buffer[] = {
0x20, 0x00, 0x00, 0x00, // CHSC5816_REG_CMD_BUFF
0x20, 0x16, 0x02, 0x00, 0xDB, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE9
};
writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer));
}
uint8_t getSupportTouchPoint()
{
return 1;
}
bool getResolution(int16_t *x, int16_t *y)
{
/*
uint8_t buffer[16] = {
0xFC, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xe9
};
writeRegister(CHSC5816_REG_CMD_BUFF, buffer, 16);
memset(buffer, 0, 16);
readRegister(CHSC5816_REG_CMD_BUFF, buffer, 16);
for (int i = 0; i < 16; ++i) {
Serial.print(buffer[i], HEX);
Serial.print(",");
}
Serial.println();
return true;
*/
return false;
}
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb)
{
SensorCommon::setGpioModeCallback(mode_cb);
SensorCommon::setGpioWriteCallback(write_cb);
SensorCommon::setGpioReadCallback(read_cb);
}
private:
bool checkOnline()
{
CHSC5816_Header_t tmp;
memset(&tmp, 0, sizeof(CHSC5816_Header_t));
memset(&__header, 0, sizeof(CHSC5816_Header_t));
// CHSC5816_REG_BOOT_STATE 0x20000018
uint8_t write_buffer[] = {0x20, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00};
if (writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer)) == DEV_WIRE_ERR) {
log_e("writeBuffer clean boot state failed!\n");
return false;
}
reset();
for (int i = 0; i < 10; ++i) {
delay(10);
// CHSC5816_REG_IMG_HEAD 0x20000014
uint8_t write_buffer[] = {0x20, 0x00, 0x00, 0x14};
if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer),
(uint8_t *)&__header,
sizeof(CHSC5816_Header_t)) == DEV_WIRE_ERR) {
printf("readRegister 1 failed!\n");
return false;
}
if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer),
(uint8_t *)&tmp,
sizeof(CHSC5816_Header_t)) == DEV_WIRE_ERR) {
printf("readRegister 2 failed!\n");
return false;
}
if (memcmp(&tmp, &__header, sizeof(CHSC5816_Header_t)) != 0 ) {
continue;
}
if (__header.sig == CHSC5816_SIG_VALUE) {
return true;
}
}
return false;
}
bool initImpl()
{
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, INPUT);
}
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
}
reset();
if (checkOnline()) {
reset();
return true;
}
return false;
}
int getReadMaskImpl()
{
return -1;
}
protected:
CHSC5816_Header_t __header;
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,181 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvCST92xx.h
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-07
*/
#pragma once
#include "TouchDrvInterface.hpp"
#include "SensorCommon.tpp"
#include "SensorLib.h"
#include "REG/CST9xxConstants.h"
enum CST92_RunMode {
CST92_MODE_NORMAL = (0x00),
CST92_MODE_LOW_POWER = (0X01),
CST92_MODE_DEEP_SLEEP = (0X02),
CST92_MODE_WAKEUP = (0x03),
CST92_MODE_DEBUG_DIFF = (0x04),
CST92_MODE_DEBUG_RAWDATA = (0X05),
CST92_MODE_FACTORY = (0x06),
CST92_MODE_DEBUG_INFO = (0x07),
CST92_MODE_UPDATE_FW = (0x08),
CST92_MODE_FACTORY_HIGHDRV = (0x10),
CST92_MODE_FACTORY_LOWDRV = (0x11),
CST92_MODE_FACTORY_SHORT = (0x12),
CST92_MODE_LPSCAN = (0x13),
};
class TouchDrvCST92xx : public TouchDrvInterface,
public SensorCommon<TouchDrvCST92xx>
{
friend class SensorCommon<TouchDrvCST92xx>;
public:
#if defined(ARDUINO)
TouchDrvCST92xx();
bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl);
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr);
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl);
#endif //ESP_IDF_VERSION
#endif
void jumpCheck();
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback);
void reset();
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point);
bool isPressed();
const char *getModelName();
void sleep();
void wakeup();
void idle();
uint8_t getSupportTouchPoint();
bool getResolution(int16_t *x, int16_t *y);
void setCoverScreenCallback(home_button_callback_t cb, void *user_data = NULL);
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb);
private:
typedef struct {
uint8_t finger_id;
uint8_t evt;
uint16_t x;
uint16_t y;
} cst9xx_point_t;
bool setMode(uint8_t mode);
bool enterBootloader();
uint32_t readWordFromMem(uint8_t type, uint16_t mem_addr);
void parseFingerData(uint8_t *data, cst9xx_point_t *point);
uint32_t get_u32_from_ptr(const void *ptr);
#if 0 /*DISABLE UPDATE FIRMWARE*/
struct {
bool firmware_info_ok;
uint32_t firmware_ic_type;
uint32_t firmware_version;
uint32_t firmware_checksum;
uint32_t firmware_project_id;
uint8_t tx_num;
uint8_t rx_num;
uint8_t key_num;
} IC_firmware;
struct {
bool ok;
uint8_t *head_data;
uint8_t *data;
uint32_t checksum;
uint32_t version;
uint32_t project_id;
uint32_t chip_type;
} bin_data;
bool getFirmwareInfo(void);
int16_t eraseMem(void);
int16_t writeSRAM(uint8_t *buf, uint16_t len);
int16_t writeMemPage(uint16_t addr, uint8_t *buf, uint16_t len) ;
int16_t writeMemAll(void) ;
int16_t calculateVerifyChecksum(void) ;
int16_t upgradeFirmware(void);
uint32_t verifyFirmware(uint8_t *pdata, uint16_t order);
int16_t parseFirmware(void);
int16_t upgradeFirmwareJudge(void);
int16_t getFirmwareAddress(uint8_t data_seq, uint16_t data_len) ;
int16_t updateFirmware(void);
#endif
uint32_t getChipType();
bool initImpl();
int getReadMaskImpl();
uint16_t chipType;
protected:
int16_t __center_btn_x;
int16_t __center_btn_y;
bool __jump_check;
};

View File

@@ -0,0 +1,295 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvCSTXXX.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-24
* @date last 2023-10-05
*
*/
#pragma once
#include "REG/CSTxxxConstants.h"
#include "touch/TouchClassCST226.h"
#include "touch/TouchClassCST816.h"
#include "SensorCommon.tpp"
class TouchDrvCSTXXX : public TouchDrvInterface
{
public:
TouchDrvCSTXXX(): drv(NULL)
{
}
~TouchDrvCSTXXX()
{
if (drv) {
delete drv;
drv = NULL;
}
}
#if defined(ARDUINO)
bool begin(PLATFORM_WIRE_TYPE &wire,
uint8_t address,
int sda,
int scl
)
{
if (!drv) {
drv = new TouchClassCST816();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(wire, address, sda, scl)) {
delete drv;
drv = NULL;
}
}
if (!drv) {
drv = new TouchClassCST226();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(wire, address, sda, scl)) {
delete drv;
drv = NULL;
}
}
return drv != NULL;
}
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
if (!drv) {
drv = new TouchClassCST816();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(i2c_dev_bus_handle, addr)) {
delete drv;
drv = NULL;
}
}
if (!drv) {
drv = new TouchClassCST226();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(i2c_dev_bus_handle, addr)) {
delete drv;
drv = NULL;
}
}
return drv != NULL;
}
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
if (!drv) {
drv = new TouchClassCST816();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(port_num, addr, sda, scl)) {
delete drv;
drv = NULL;
}
}
if (!drv) {
drv = new TouchClassCST226();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(port_num, addr, sda, scl)) {
delete drv;
drv = NULL;
}
}
return drv != NULL;
}
#endif //ESP_IDF_VERSION
#endif//ARDUINO
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb)
{
__set_gpio_level = write_cb;
__get_gpio_level = read_cb;
__set_gpio_mode = mode_cb;
}
bool begin(uint8_t address, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
if (!drv) {
drv = new TouchClassCST816();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(address, readRegCallback, writeRegCallback)) {
delete drv;
drv = NULL;
}
}
if (!drv) {
drv = new TouchClassCST226();
drv->setGpioCallback(__set_gpio_mode, __set_gpio_level, __get_gpio_level);
drv->setPins(__rst, __irq);
if (!drv->begin(address, readRegCallback, writeRegCallback)) {
delete drv;
drv = NULL;
}
}
return drv != NULL;
}
void reset()
{
if (!drv)return;
drv->reset();
}
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point = 1)
{
if (!drv)return 0;
return drv->getPoint(x_array, y_array, get_point);
}
bool isPressed()
{
if (!drv)return false;
return drv->isPressed();
}
const char *getModelName()
{
if (!drv)return "NULL";
return drv->getModelName();
}
void sleep()
{
if (!drv)return;
drv->sleep();
}
void wakeup()
{
if (!drv)return;
drv->reset();
}
void idle()
{
if (!drv)return;
drv->idle();
}
uint8_t getSupportTouchPoint()
{
if (!drv)return 0;
return drv->getSupportTouchPoint();
}
bool getResolution(int16_t *x, int16_t *y)
{
if (!drv)return false;
return drv->getResolution(x, y);
}
void setCenterButtonCoordinate(uint16_t x, uint16_t y)
{
if (!drv)return ;
const char *model = drv->getModelName();
if (strncmp(model, "CST8", 3) == 0) {
TouchClassCST816 *pT = static_cast<TouchClassCST816 *>(drv);
pT->setCenterButtonCoordinate(x, y);
}
}
void setHomeButtonCallback(home_button_callback_t callback, void *user_data = NULL)
{
if (!drv)return ;
const char *model = drv->getModelName();
if (strncmp(model, "CST8", 3) == 0) {
TouchClassCST816 *pT = static_cast<TouchClassCST816 *>(drv);
pT->setHomeButtonCallback(callback, user_data);
// pT->setCenterButtonCoordinate(600, 120); // Only suitable for AMOLED 1.91 inch
} if (strncmp(model, "CST2", 3) == 0) {
TouchClassCST226 *pT = static_cast<TouchClassCST226 *>(drv);
pT->setHomeButtonCallback(callback, user_data);
}
}
void disableAutoSleep()
{
if (!drv)return ;
const char *model = drv->getModelName();
if (strncmp(model, "CST8", 3) == 0) {
TouchClassCST816 *pT = static_cast<TouchClassCST816 *>(drv);
pT->disableAutoSleep();
}
}
void enableAutoSleep()
{
if (!drv)return ;
const char *model = drv->getModelName();
if (strncmp(model, "CST8", 3) == 0) {
TouchClassCST816 *pT = static_cast<TouchClassCST816 *>(drv);
pT->enableAutoSleep();
}
}
void setSwapXY(bool swap)
{
if (!drv)return ;
drv->setSwapXY(swap);
}
void setMirrorXY(bool mirrorX, bool mirrorY)
{
if (!drv)return ;
drv->setMirrorXY(mirrorX, mirrorY);
}
void setMaxCoordinates(uint16_t x, uint16_t y)
{
if (!drv)return ;
drv->setMaxCoordinates(x, y);
}
private:
gpio_write_fptr_t __set_gpio_level = NULL;
gpio_read_fptr_t __get_gpio_level = NULL;
gpio_mode_fptr_t __set_gpio_mode = NULL;
TouchDrvInterface *drv = NULL;
};

View File

@@ -0,0 +1,426 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvFT6X36.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-01
*
*/
#pragma once
#include "REG/FT6X36Constants.h"
#include "TouchDrvInterface.hpp"
#include "SensorCommon.tpp"
class TouchDrvFT6X36 :
public TouchDrvInterface,
public SensorCommon<TouchDrvFT6X36>
{
friend class SensorCommon<TouchDrvFT6X36>;
public:
enum GesTrue {
NO_GESTURE,
MOVE_UP,
MOVE_LEFT,
MOVE_DOWN,
MOVE_RIGHT,
ZOOM_IN,
ZOOM_OUT,
} ;
enum EventFlag {
EVENT_PUT_DOWN,
EVENT_PUT_UP,
EVENT_CONTACT,
EVENT_NONE,
} ;
enum PowerMode {
PMODE_ACTIVE = 0, // ~4mA
PMODE_MONITOR = 1, // ~3mA
PMODE_DEEPSLEEP = 3, // ~100uA The reset pin must be pulled down to wake up
} ;
EventFlag event;
#if defined(ARDUINO)
TouchDrvFT6X36(PLATFORM_WIRE_TYPE &w, int sda = DEFAULT_SDA, int scl = DEFAULT_SCL, uint8_t addr = FT6X36_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
TouchDrvFT6X36()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__addr = FT6X36_SLAVE_ADDRESS;
}
~TouchDrvFT6X36()
{
deinit();
}
#if defined(ARDUINO)
bool begin(PLATFORM_WIRE_TYPE &w,
uint8_t addr = FT6X36_SLAVE_ADDRESS,
int sda = DEFAULT_SDA,
int scl = DEFAULT_SCL)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#elif defined(ESP_PLATFORM) && !defined(ARDUINO)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
return SensorCommon::begin(i2c_dev_bus_handle, addr);
}
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
return SensorCommon::begin(port_num, addr, sda, scl);
}
#endif //ESP_IDF_VERSION
#endif
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
}
void deinit()
{
// end();
}
uint8_t getDeviceMode(void)
{
return readRegister(FT6X36_REG_MODE) & 0x03;
}
// Obtaining gestures depends on whether the built-in firmware of the chip has this function
uint8_t getGesture()
{
int val = readRegister(FT6X36_REG_GEST);
switch (val) {
case 0x10:
return MOVE_UP;
case 0x14:
return MOVE_RIGHT;
case 0x18:
return MOVE_DOWN;
case 0x1C:
return MOVE_LEFT;
case 0x48:
return ZOOM_IN;
case 0x49:
return ZOOM_OUT;
default:
break;
}
return NO_GESTURE;
}
void setThreshold(uint8_t value)
{
writeRegister(FT6X36_REG_THRESHOLD, value);
}
uint8_t getThreshold(void)
{
return readRegister(FT6X36_REG_THRESHOLD);
}
uint8_t getMonitorTime(void)
{
return readRegister(FT6X36_REG_MONITOR_TIME);
}
void setMonitorTime(uint8_t sec)
{
writeRegister(FT6X36_REG_MONITOR_TIME, sec);
}
// Calibration useless actually,
// any value set will not be valid,
// depending on the internal firmware of the chip.
/*
void enableAutoCalibration(void)
{
writeRegister(FT6X36_REG_AUTO_CLB_MODE, 0x00);
}
void disableAutoCalibration(void)
{
writeRegister(FT6X36_REG_AUTO_CLB_MODE, 0xFF);
}
*/
uint16_t getLibraryVersion()
{
uint8_t buffer[2];
readRegister(FT6X36_REG_LIB_VERSION_H, buffer, 2);
return (buffer[0] << 8) | buffer[1];
}
// The interrupt is triggered only if a touch is detected during the scan cycle
void interruptPolling(void)
{
//datasheet this bit is 0,Actually, it's wrong
writeRegister(FT6X36_REG_INT_STATUS, 1);
}
// Triggers an interrupt whenever a touch is detected
void interruptTrigger(void)
{
//datasheet this bit is 1,Actually, it's wrong
writeRegister(FT6X36_REG_INT_STATUS, 0);
}
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t size = 1)
{
uint8_t buffer[16];
if (!x_array || !y_array || !size)
return 0;
if (readRegister(FT6X36_REG_MODE, buffer, 16) == DEV_WIRE_ERR) {
return 0;
}
// uint8_t mode = buffer[0];
//REG 0x01
// uint8_t gesture = buffer[1];
//REG 0x02
uint8_t point = buffer[2] & 0x0F;
if (point == 0 || point == 0x0F) {
return 0;
}
//REG 0x03 ~ 0x04
// uint8_t eventFlag = (buffer[3] & 0xC0) >> 6;
uint16_t posX = ((buffer[3] & 0x0F) << 8) | buffer[4];
//REG 0x05 ~ 0x06
uint16_t posY = ((buffer[5] & 0x0F) << 8) | buffer[6] ;
x_array[0] = posX;
y_array[0] = posY;
#ifdef LOG_PORT
LOG_PORT.println("----------------------------------------------------------------------------");
LOG_PORT.println("Touched Gesture EvenFlag [0]PosX [0]PosY [1]PosX [1]PosY");
LOG_PORT.print(point); LOG_PORT.print("\t");
// LOG_PORT.print(gesture); LOG_PORT.print("\t");
// LOG_PORT.print(eventFlag); LOG_PORT.print("\t");
LOG_PORT.print(posX); LOG_PORT.print("\t");
LOG_PORT.print(posY); LOG_PORT.print("\t");
#endif
if (point == 2) {
//REG 0x09 ~ 0x0A
posX = ((buffer[9] & 0x0F) << 8) | buffer[10];
//REG 0x0B ~ 0x0C
posY = ((buffer[11] & 0x0F) << 8) | buffer[12] ;
#ifdef LOG_PORT
LOG_PORT.print(posX); LOG_PORT.print("\t");
LOG_PORT.print(posY); LOG_PORT.print("\t");
#endif
if (size == 2) {
x_array[1] = posX;
y_array[1] = posY;
}
}
#ifdef LOG_PORT
LOG_PORT.println();
#endif
updateXY(point, x_array, y_array);
return point;
}
bool isPressed()
{
if (__irq != SENSOR_PIN_NONE) {
return this->getGpioLevel(__irq) == LOW;
}
return readRegister(FT6X36_REG_STATUS) & 0x0F;
}
void setPowerMode(PowerMode mode)
{
writeRegister(FT6X36_REG_POWER_MODE, mode);
}
void sleep()
{
writeRegister(FT6X36_REG_POWER_MODE, PMODE_DEEPSLEEP);
}
void wakeup()
{
reset();
}
void idle()
{
}
uint8_t getSupportTouchPoint()
{
return 1;
}
uint32_t getChipID(void)
{
return readRegister(FT6X36_REG_CHIP_ID);
}
uint8_t getVendorID(void)
{
return readRegister(FT6X36_REG_VENDOR1_ID);
}
uint8_t getErrorCode(void)
{
return readRegister(FT6X36_REG_ERROR_STATUS);
}
const char *getModelName()
{
switch (__chipID) {
case FT6206_CHIP_ID: return "FT6206";
case FT6236_CHIP_ID: return "FT6236";
case FT6236U_CHIP_ID: return "FT6236U";
case FT3267_CHIP_ID: return "FT3267";
default: return "UNKNOWN";
}
}
bool getResolution(int16_t *x, int16_t *y)
{
return false;
}
void reset()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
this->setGpioLevel(__rst, HIGH);
delay(10);
this->setGpioLevel(__rst, LOW);
delay(30);
this->setGpioLevel(__rst, HIGH);
// For the variant of GPIO extended RST,
// communication and delay are carried out simultaneously, and 160ms is measured in T-RGB esp-idf new api
delay(160);
}
}
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb)
{
SensorCommon::setGpioModeCallback(mode_cb);
SensorCommon::setGpioWriteCallback(write_cb);
SensorCommon::setGpioReadCallback(read_cb);
}
private:
bool initImpl()
{
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, INPUT);
}
reset();
uint8_t vendId = readRegister(FT6X36_REG_VENDOR1_ID);
if (vendId != FT6X36_VEND_ID) {
log_e("Vendor id is 0x%X not match!", vendId);
return false;
}
__chipID = readRegister(FT6X36_REG_CHIP_ID);
if ((__chipID != FT6206_CHIP_ID) &&
(__chipID != FT6236_CHIP_ID) &&
(__chipID != FT6236U_CHIP_ID) &&
(__chipID != FT3267_CHIP_ID)
) {
log_e("Vendor id is not match!");
log_e("ChipID:0x%lx should be 0x06 or 0x36 or 0x64", __chipID);
return false;
}
log_i("Vend ID: 0x%X", vendId);
log_i("Chip ID: 0x%lx", __chipID);
log_i("Firm Version: 0x%X", readRegister(FT6X36_REG_FIRM_VERS));
log_i("Point Rate Hz: %u", readRegister(FT6X36_REG_PERIOD_ACTIVE));
log_i("Thresh : %u", readRegister(FT6X36_REG_THRESHOLD));
// change threshold to be higher/lower
writeRegister(FT6X36_REG_THRESHOLD, 60);
log_i("Chip library version : 0x%x", getLibraryVersion());
// This register describes period of monitor status, it should not less than 30.
log_i("Chip period of monitor status : 0x%x", readRegister(FT6X36_REG_PERIOD_MONITOR));
// This register describes the period of active status, it should not less than 12
return true;
}
int getReadMaskImpl()
{
return -1;
}
};

View File

@@ -0,0 +1,653 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvGT911.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-12
*
*/
#pragma once
#include "REG/GT911Constants.h"
#include "TouchDrvInterface.hpp"
#include "SensorCommon.tpp"
#if defined(ARDUINO_ARCH_NRF52)
// NRF52840 I2C BUFFER : 64 Bytes ,
#warning "NRF Platform I2C Buffer expansion is not implemented , GT911 requires at least 188 bytes to read all configurations"
#endif
typedef struct GT911_Struct {
uint8_t trackID;
int16_t x;
int16_t y;
int16_t size;
} GT911Point_t;
#define LOW_LEVEL_QUERY 0x03
#define HIGH_LEVEL_QUERY 0x04
class TouchDrvGT911 :
public TouchDrvInterface,
public SensorCommon<TouchDrvGT911>
{
friend class SensorCommon<TouchDrvGT911>;
public:
#if defined(ARDUINO)
TouchDrvGT911(PLATFORM_WIRE_TYPE &w,
int sda = DEFAULT_SDA,
int scl = DEFAULT_SCL,
uint8_t addr = GT911_SLAVE_ADDRESS_H)
{
__wire = &w;
__sda = sda;
__scl = scl;
__rst = SENSOR_PIN_NONE;
__irq = SENSOR_PIN_NONE;
__addr = addr;
}
#endif
TouchDrvGT911()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = DEFAULT_SDA;
__scl = DEFAULT_SCL;
#endif
__rst = SENSOR_PIN_NONE;
__irq = SENSOR_PIN_NONE;
__addr = GT911_SLAVE_ADDRESS_H;
}
~TouchDrvGT911()
{
deinit();
}
#if defined(ARDUINO)
bool begin(PLATFORM_WIRE_TYPE &w,
uint8_t addr = GT911_SLAVE_ADDRESS_H,
int sda = DEFAULT_SDA,
int scl = DEFAULT_SCL
)
{
return SensorCommon::begin(w, addr, sda, scl);
}
#elif defined(ESP_PLATFORM) && !defined(ARDUINO)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
return SensorCommon::begin(i2c_dev_bus_handle, addr);
}
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
return SensorCommon::begin(port_num, addr, sda, scl);
}
#endif //ESP_IDF_VERSION
#endif
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
}
void deinit()
{
// end();
}
void reset()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
this->setGpioLevel(__rst, HIGH);
delay(10);
}
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, INPUT);
}
/*
* If you perform a software reset on a board without a reset pin connected,
* subsequent interrupt settings or re-writing of configurations will be invalid.
* For example, when debugging a LilyGo T-Deck, resetting the interrupt mode will
* be invalid after a software reset.
* */
// writeRegister(GT911_COMMAND, 0x02);
// writeCommand(0x02);
}
void sleep()
{
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, OUTPUT);
this->setGpioLevel(__irq, LOW);
}
// writeRegister(GT911_COMMAND, 0x05);
writeCommand(0x05);
/*
* Depending on the chip and platform, setting it to input after removing sleep will affect power consumption.
* The chip platform determines whether
*
* * */
// if (__irq != SENSOR_PIN_NONE) {
// this->setGpioLevel(__irq, INPUT);
// }
}
void wakeup()
{
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, OUTPUT);
this->setGpioLevel(__irq, HIGH);
delay(8);
this->setGpioMode(__irq, INPUT);
} else {
reset();
}
}
void idle()
{
}
uint8_t getSupportTouchPoint()
{
return 5;
}
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t size = 1)
{
uint8_t buffer[39];
uint8_t touchPoint = 0;
GT911Point_t p[5];
if (!x_array || !y_array || size == 0)
return 0;
uint8_t val = readGT911(GT911_POINT_INFO);
bool haveKey = GT911_GET_HAVE_KEY(val);
// bool bufferStatus = GT911_GET_BUFFER_STATUS(val);
// log_i("REG:0x%X S:0X%d K:%d\n", val,bufferStatus,haveKey);
if (__homeButtonCb && haveKey) {
__homeButtonCb(__userData);
}
clearBuffer();
touchPoint = GT911_GET_POINT(val);
if (touchPoint == 0) {
return 0;
}
// GT911_POINT_1 0X814F
uint8_t write_buffer[2] = {0x81, 0x4F};
if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer),
buffer, 39) == DEV_WIRE_ERR) {
return 0;
}
for (uint8_t i = 0; i < size; i++) {
p[i].trackID = buffer[i * 8];
p[i].x = buffer[0x01 + i * 8] ;
p[i].x |= (buffer[0x02 + i * 8] << 8 );
p[i].y = buffer[0x03 + i * 8] ;
p[i].y |= (buffer[0x04 + i * 8] << 8);
p[i].size = buffer[0x05 + i * 8] ;
p[i].size |= (buffer[0x06 + i * 8] << 8) ;
x_array[i] = p[i].x;
y_array[i] = p[i].y;
}
#ifdef LOG_PORT
LOG_PORT.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
LOG_PORT.println("Touched [0]ID [0]Size [0]X [0]Y [1]ID [1]Size [1]X [1]Y [2]ID [2]Size [2]X [2]Y [3]ID [3]Size [3]X [3]Y [4]ID [4]Size [4]X [4]Y ");
LOG_PORT.print(touchPoint); LOG_PORT.print("\t");
for (int i = 0; i < size; ++i) {
LOG_PORT.print(p[i].trackID); LOG_PORT.print("\t");
LOG_PORT.print(p[i].size); LOG_PORT.print("\t");
LOG_PORT.print( p[i].x); LOG_PORT.print("\t");
LOG_PORT.print( p[i].y); LOG_PORT.print("\t");
}
LOG_PORT.println();
#endif
updateXY(touchPoint, x_array, y_array);
return touchPoint;
}
bool isPressed()
{
if (__irq != SENSOR_PIN_NONE) {
if (__irq_mode == FALLING) {
return this->getGpioLevel(__irq) == LOW;
} else if (__irq_mode == RISING ) {
return this->getGpioLevel(__irq) == HIGH;
} else if (__irq_mode == LOW_LEVEL_QUERY) {
return this->getGpioLevel(__irq) == LOW;
} else if (__irq_mode == HIGH_LEVEL_QUERY) {
return this->getGpioLevel(__irq) == HIGH;
}
}
return getPoint();
}
bool setInterruptMode(uint8_t mode)
{
// GT911_MODULE_SWITCH_1 0x804D
uint8_t val = readGT911(GT911_MODULE_SWITCH_1);
val &= 0XFC;
if (mode == FALLING) {
val |= 0x01;
} else if (mode == RISING ) {
val |= 0x00;
} else if (mode == LOW_LEVEL_QUERY ) {
val |= 0x02;
} else if (mode == HIGH_LEVEL_QUERY ) {
val |= 0x03;
}
__irq_mode = mode;
writeGT911(GT911_MODULE_SWITCH_1, val);
return reloadConfig();
}
/**
* @retval
* * 0x0: Rising edge trigger
* * 0x1: Falling edge trigger
* * 0x2: Low level query
* * 0x3: High level query
*/
uint8_t getInterruptMode()
{
uint8_t val = readGT911(GT911_MODULE_SWITCH_1);
// return val & 0x03;
val &= 0x03;
if (val == 0x00) {
__irq_mode = RISING;
} else if (val == 0x01) {
__irq_mode = FALLING;
} else if (val == 0x02) {
__irq_mode = LOW_LEVEL_QUERY;
} else if (val == 0x03) {
__irq_mode = HIGH_LEVEL_QUERY;
}
return val;
}
uint8_t getPoint()
{
// GT911_POINT_INFO 0X814E
uint8_t val = readGT911(GT911_POINT_INFO);
clearBuffer();
return GT911_GET_POINT(val);
}
uint32_t getChipID()
{
char product_id[4] = {0};
// GT911_PRODUCT_ID 0x8140
for (int i = 0; i < 4; ++i) {
product_id[i] = readGT911(GT911_PRODUCT_ID + i);
}
return atoi(product_id);
}
uint16_t getFwVersion()
{
uint8_t fw_ver[2] = {0};
// GT911_FIRMWARE_VERSION 0x8144
for (int i = 0; i < 2; ++i) {
fw_ver[i] = readGT911(GT911_FIRMWARE_VERSION + i);
}
return fw_ver[0] | (fw_ver[1] << 8);
}
uint8_t getConfigVersion()
{
return readGT911(GT911_CONFIG_VERSION);
}
bool getResolution(int16_t *x, int16_t *y)
{
uint8_t x_resolution[2] = {0}, y_resolution[2] = {0};
for (int i = 0; i < 2; ++i) {
x_resolution[i] = readGT911(GT911_X_RESOLUTION + i);
}
for (int i = 0; i < 2; ++i) {
y_resolution[i] = readGT911(GT911_Y_RESOLUTION + i);
}
*x = x_resolution[0] | (x_resolution[1] << 8);
*y = y_resolution[0] | (y_resolution[1] << 8);
return true;
}
//Range : 5 ~ 15 ms
void updateRefreshRate(uint8_t rate_ms)
{
if ((rate_ms - 5) < 5) {
rate_ms = 5;
}
if (rate_ms > 15) {
rate_ms = 15;
}
rate_ms -= 5;
writeGT911(GT911_REFRESH_RATE, rate_ms);
reloadConfig();
}
uint8_t getRefreshRate()
{
uint8_t rate_ms = readGT911(GT911_REFRESH_RATE);
return rate_ms + GT911_BASE_REF_RATE ;
}
int getVendorID()
{
return readGT911(GT911_VENDOR_ID);
}
const char *getModelName()
{
return "GT911";
}
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb)
{
SensorCommon::setGpioModeCallback(mode_cb);
SensorCommon::setGpioWriteCallback(write_cb);
SensorCommon::setGpioReadCallback(read_cb);
}
void setHomeButtonCallback(home_button_callback_t cb, void *user_data)
{
__homeButtonCb = cb;
__userData = user_data;
}
bool writeConfig(const uint8_t *config_buffer, size_t buffer_size)
{
setRegAddressLength(2);
int err = writeRegister(GT911_CONFIG_VERSION, (uint8_t *)config_buffer, buffer_size);
setRegAddressLength(1);
return err == DEV_WIRE_NONE;
}
uint8_t *loadConfig(size_t *output_size, bool print_out = false)
{
*output_size = 0;
uint8_t *buffer = (uint8_t * )malloc(GT911_REG_LENGTH * sizeof(uint8_t));
if (!buffer)return NULL;
uint8_t write_buffer[2] = {highByte(GT911_CONFIG_VERSION), lowByte(GT911_CONFIG_VERSION)};
if (writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer), buffer, GT911_REG_LENGTH) == DEV_WIRE_ERR) {
free(buffer);
return NULL;
}
if (print_out) {
printf("const unsigned char config[186] = {");
for (int i = 0; i < GT911_REG_LENGTH; ++i) {
if ( (i % 8) == 0) {
printf("\n");
}
printf("0x%02X", buffer[i]);
if ((i + 1) < GT911_REG_LENGTH) {
printf(",");
}
}
printf("};\n");
}
*output_size = GT911_REG_LENGTH;
return buffer;
}
bool reloadConfig()
{
uint8_t buffer[GT911_REG_LENGTH] = {highByte(GT911_CONFIG_VERSION), lowByte(GT911_CONFIG_VERSION)};
if (writeThenRead(buffer, 2, buffer, GT911_REG_LENGTH - 2) == DEV_WIRE_ERR) {
return false;
}
uint8_t check_sum = 0;
for (int i = 0; i < (GT911_REG_LENGTH - 2 ); i++) {
check_sum += buffer[i];
}
check_sum = (~check_sum) + 1;
log_d("reloadConfig check_sum : 0x%X\n", check_sum);
writeGT911(GT911_CONFIG_CHKSUM, check_sum);
writeGT911(GT911_CONFIG_FRESH, 0x01);
return true;
}
void dumpRegister()
{
size_t output_size = 0;
uint8_t *buffer = loadConfig(&output_size, true);
if (output_size == 0) {
return;
}
if (buffer == NULL)return;
printf("----------Dump register------------\n");
for (size_t i = 0; i < output_size; ++i) {
printf("[%d] REG: 0x%X : 0x%02X\n", i, GT911_CONFIG_VERSION + i, buffer[i]);
}
free(buffer);
}
// Range : 1~5
void setMaxTouchPoint(uint8_t num)
{
if (num < 1)num = 1;
if (num > 5) num = 5;
writeGT911(GT911_TOUCH_NUMBER, num);
reloadConfig();
}
uint8_t getMaxTouchPoint()
{
uint8_t num = readGT911(GT911_TOUCH_NUMBER);
return num & 0x0F;
}
private:
uint8_t readGT911(uint16_t cmd)
{
uint8_t value = 0x00;
uint8_t write_buffer[2] = {highByte(cmd), lowByte(cmd)};
writeThenRead(write_buffer, SENSORLIB_COUNT(write_buffer),
&value, 1);
return value;
}
int writeGT911(uint16_t cmd, uint8_t value)
{
uint8_t write_buffer[3] = {highByte(cmd), lowByte(cmd), value};
return writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer));
}
void writeCommand(uint8_t command)
{
// GT911_COMMAND 0x8040
uint8_t write_buffer[3] = {0x80, 0x40, command};
writeBuffer(write_buffer, SENSORLIB_COUNT(write_buffer));
}
void inline clearBuffer()
{
writeGT911(GT911_POINT_INFO, 0x00);
}
bool probeAddress()
{
const uint8_t device_address[2] = {GT911_SLAVE_ADDRESS_L, GT911_SLAVE_ADDRESS_H};
for (size_t i = 0; i < SENSORLIB_COUNT(device_address); ++i) {
__addr = device_address[i];
for (int retry = 0; retry < 3; ++retry) {
if (getChipID() == GT911_DEV_ID) {
return true;
}
}
}
return false;
}
bool initImpl()
{
int16_t x = 0, y = 0;
if (__rst == SENSOR_PIN_NONE) {
// Automatically determine the current device
// address when using the reset pin without connection
if (!probeAddress()) {
return false;
}
log_i("Probe address is : 0x%X", __addr);
// Reset Config
reset();
this->setGpioMode(__irq, INPUT);
} else if (__addr == GT911_SLAVE_ADDRESS_H &&
__rst != SENSOR_PIN_NONE &&
__irq != SENSOR_PIN_NONE) {
log_i("GT911 using 0x28 address!");
this->setGpioMode(__rst, OUTPUT);
this->setGpioMode(__irq, OUTPUT);
this->setGpioLevel(__rst, LOW);
this->setGpioLevel(__irq, HIGH);
delayMicroseconds(120);
this->setGpioLevel(__rst, HIGH);
delay(18);
this->setGpioMode(__irq, INPUT);
} else if (__addr == GT911_SLAVE_ADDRESS_L &&
__rst != SENSOR_PIN_NONE &&
__irq != SENSOR_PIN_NONE) {
log_i("GT911 using 0xBA address!");
this->setGpioMode(__rst, OUTPUT);
this->setGpioMode(__irq, OUTPUT);
this->setGpioLevel(__rst, LOW);
this->setGpioLevel(__irq, LOW);
delayMicroseconds(120);
this->setGpioLevel(__rst, HIGH);
delay(18);
this->setGpioMode(__irq, INPUT);
}
// For variants where the GPIO is controlled by I2C, a delay is required here
delay(20);
__chipID = getChipID();
log_i("Product id:%ld", __chipID);
if (__chipID != GT911_DEV_ID) {
log_i("Not find device GT911");
return false;
}
log_i("Firmware version: 0x%x", getFwVersion());
getResolution(&x, &y);
log_i("Resolution : X = %d Y = %d", x, y);
log_i("Vendor id:%d", getVendorID());
log_i("Refresh Rate:%d ms", getRefreshRate());
log_i("MaxTouchPoint:%d", getMaxTouchPoint());
/*
* For the ESP32 platform, the default buffer is 128.
* Need to re-apply for a larger buffer to fully read the configuration table.
* */
if (!this->reallocBuffer(GT911_REG_LENGTH + 2 )) {
log_e("realloc i2c buffer failed !");
return false;
}
// Get the default interrupt trigger mode of the current screen
getInterruptMode();
if ( __irq_mode == RISING) {
log_i("Interrupt Mode: RISING");
} else if (__irq_mode == FALLING) {
log_i("Interrupt Mode: FALLING");
} else if (__irq_mode == LOW_LEVEL_QUERY) {
log_i("Interrupt Mode: LOW_LEVEL_QUERY");
} else if (__irq_mode == HIGH_LEVEL_QUERY) {
log_i("Interrupt Mode: HIGH_LEVEL_QUERY");
} else {
log_e("UNKOWN");
}
return true;
}
int getReadMaskImpl()
{
return -1;
}
protected:
int __irq_mode;
};

View File

@@ -0,0 +1,100 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted,free of charge,to any person obtaining a copy
* of this software and associated documentation files (the "Software"),to deal
* in the Software without restriction,including without limitation the rights
* to use,copy,modify,merge,publish,distribute,sublicense,and/or sell
* copies of the Software,and to permit persons to whom the Software is
* furnished to do so,subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
* IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER
* LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvInterface.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-21
*
*/
#include "TouchDrvInterface.hpp"
TouchDrvInterface::TouchDrvInterface() :
__resX(0),
__resY(0),
__xMax(0),
__yMax(0),
__swapXY(false),
__mirrorX(false),
__mirrorY(false),
__rst(-1),
__irq(-1),
__chipID(0x00),
__homeButtonCb(NULL),
__userData(NULL)
{
}
TouchDrvInterface::~TouchDrvInterface()
{
}
uint32_t TouchDrvInterface::getChipID()
{
return __chipID;
}
void TouchDrvInterface::setPins(int rst, int irq)
{
__irq = irq;
__rst = rst;
}
void TouchDrvInterface::setSwapXY(bool swap)
{
__swapXY = swap;
}
void TouchDrvInterface::setMirrorXY(bool mirrorX, bool mirrorY)
{
__mirrorX = mirrorX;
__mirrorY = mirrorY;
}
void TouchDrvInterface::setMaxCoordinates(uint16_t x, uint16_t y)
{
__xMax = x;
__yMax = y;
}
void TouchDrvInterface::updateXY(uint8_t pointNum, int16_t *xBuffer, int16_t *yBuffer)
{
if (!pointNum)
return;
for (int i = 0; i < pointNum; ++i) {
if (__swapXY) {
uint16_t tmp = xBuffer[i];
xBuffer[i] = yBuffer[i];
yBuffer[i] = tmp;
}
if (__mirrorX && __xMax ) {
xBuffer[i] = __xMax - xBuffer[i];
}
if (__mirrorY && __yMax) {
yBuffer[i] = __yMax - yBuffer[i];
}
}
}

View File

@@ -0,0 +1,145 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted,free of charge,to any person obtaining a copy
* of this software and associated documentation files (the "Software"),to deal
* in the Software without restriction,including without limitation the rights
* to use,copy,modify,merge,publish,distribute,sublicense,and/or sell
* copies of the Software,and to permit persons to whom the Software is
* furnished to do so,subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
* IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER
* LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchDrvInterface.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-04-17
*
*/
#pragma once
#include <stdint.h>
#include <stdio.h>
#include "SensorLib.h"
#include "SensorCommon.tpp"
typedef void (*home_button_callback_t)(void *user_data);
class TouchData
{
public:
TouchData() {}
~TouchData() {};
uint8_t available;
uint8_t id[5];
int16_t x[5];
int16_t y[5];
uint8_t status[5];
uint8_t pressure[5];
uint16_t getX(uint8_t index = 0)
{
return x[index];
}
uint16_t getY(uint8_t index = 0)
{
return y[index];
}
uint16_t getPressure(uint8_t index = 0)
{
return pressure[index];
}
uint16_t getStatus(uint8_t index = 0)
{
return status[index];
}
};
class TouchDrvInterface
{
public:
TouchDrvInterface();
virtual ~TouchDrvInterface();
#if defined(ARDUINO)
virtual bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl) = 0;
#elif defined(ESP_PLATFORM) && !defined(ARDUINO)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
virtual bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr) = 0;
#else
virtual bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl) = 0;
#endif //ESP_IDF_VERSION
#endif //defined(ESP_PLATFORM) && !defined(ARDUINO)
virtual bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback) = 0;
virtual void reset() = 0;
virtual uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point) = 0;
virtual bool isPressed() = 0;
virtual const char *getModelName() = 0;
virtual void sleep() = 0;
virtual void wakeup() = 0;
virtual void idle() = 0;
virtual uint8_t getSupportTouchPoint() = 0;
virtual bool getResolution(int16_t *x, int16_t *y) = 0;
virtual void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb) = 0;
uint32_t getChipID();
void setPins(int rst, int irq);
void setSwapXY(bool swap);
void setMirrorXY(bool mirrorX, bool mirrorY);
void setMaxCoordinates(uint16_t x, uint16_t y);
void updateXY(uint8_t pointNum, int16_t *xBuffer, int16_t *yBuffer);
protected:
uint16_t __resX, __resY, __xMax, __yMax;
bool __swapXY, __mirrorX, __mirrorY;
int __rst;
int __irq;
uint32_t __chipID;
home_button_callback_t __homeButtonCb;
void *__userData;
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,479 @@
/**
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bmm150.h
* @date 2020-06-03
* @version v2.0.0
*
*/
/*!
* @defgroup bmm150 BMM150
*/
#ifndef _BMM150_H
#define _BMM150_H
/*! CPP guard */
#ifdef __cplusplus
extern "C" {
#endif
/********************************************************************/
/* header files */
#include "bmm150_defs.h"
/********************************************************************/
/* (extern) variable declarations */
/********************************************************************/
/* function prototype declarations */
/**
* \ingroup bmm150
* \defgroup bmm150ApiInit Initialization
* @brief Initialize the sensor and device structure
*/
/*!
* \ingroup bmm150ApiInit
* \page bmm150_api_bmm150_init bmm150_init
* \code
* int8_t bmm150_init(struct bmm150_dev *dev);
* \endcode
* @details This API is the entry point, Call this API before using other APIs.
* This API reads the chip-id of the sensor which is the first step to
* verify the sensor and also it configures the read mechanism of SPI and
* I2C interface.
*
* @param[in,out] dev : Structure instance of bmm150_dev
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_init(struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiRegs Registers
* @brief Read / Write data to the given register address of the sensor
*/
/*!
* \ingroup bmm150ApiRegs
* \page bmm150_api_bmm150_set_regs bmm150_set_regs
* \code
* int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev);
* \endcode
* @details This API writes the given data to the register address
* of the sensor.
*
* @param[in] reg_addr : Register address from where the data to be written.
* @param[in] reg_data : Pointer to data buffer which is to be written
* in the reg_addr of sensor.
* @param[in] len : No of bytes of data to write..
* @param[in] dev : Structure instance of bmm150_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev);
/*!
* \ingroup bmm150ApiRegs
* \page bmm150_api_bmm150_get_regs bmm150_get_regs
* \code
* int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev)
* \endcode
* @details This API reads the data from the given register address of sensor.
*
* @param[in] reg_addr : Register address from where the data to be read
* @param[out] reg_data : Pointer to data buffer to store the read data.
* @param[in] len : No of bytes of data to be read.
* @param[in] dev : Structure instance of bmm150_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiSoftreset Soft reset
* @brief Perform soft reset of the sensor
*/
/*!
* \ingroup bmm150ApiSoftreset
* \page bmm150_api_bmm150_soft_reset bmm150_soft_reset
* \code
* int8_t bmm150_soft_reset(struct bmm150_dev *dev);
* \endcode
* @details This API is used to perform soft-reset of the sensor
* where all the registers are reset to their default values except 0x4B.
*
* @param[in] dev : Structure instance of bmm150_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_soft_reset(struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiPowermode Power mode
* @brief Set / Get power mode of the sensor
*/
/*!
* \ingroup bmm150ApiPowermode
* \page bmm150_api_bmm150_set_op_mode bmm150_set_op_mode
* \code
* int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev);
* \endcode
* @details This API is used to set the power mode of the sensor.
*
* @param[in] settings : Structure instance of bmm150_settings.
* @param[in] dev : Structure instance of bmm150_dev.
*
*@verbatim
* settings->pwr_mode | Power mode
* ------------------------|-----------------------
* 0x00 | BMM150_POWERMODE_NORMAL
* 0x01 | BMM150_POWERMODE_FORCED
* 0x03 | BMM150_POWERMODE_SLEEP
* 0x04 | BMM150_POWERMODE_SUSPEND
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_set_op_mode(const struct bmm150_settings *settings, struct bmm150_dev *dev);
/*!
* \ingroup bmm150ApiPowermode
* \page bmm150_api_bmm150_get_op_mode bmm150_get_op_mode
* \code
* int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev);
* \endcode
* @details This API is used to get the power mode of the sensor.
*
* @param[out] op_mode : power mode of the sensor.
* @param[in] dev : Structure instance of bmm150_dev.
*
*@verbatim
* op_mode | Power mode
* -------------|-----------------------
* 0x00 | BMM150_POWERMODE_NORMAL
* 0x01 | BMM150_POWERMODE_FORCED
* 0x03 | BMM150_POWERMODE_SLEEP
* 0x04 | BMM150_POWERMODE_SUSPEND
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_get_op_mode(uint8_t *op_mode, struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiPresetmode Preset mode
* @brief Set preset mode of the sensor
*/
/*!
* \ingroup bmm150ApiPresetmode
* \page bmm150_api_bmm150_set_presetmode bmm150_set_presetmode
* \code
* int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev);
* \endcode
* @details This API is used to set the preset mode of the sensor.
*
* @param[in] settings : Structure instance of bmm150_settings.
* @param[in] dev : Structure instance of bmm150_dev.
*
*@verbatim
* settings->preset_mode | Preset mode
* ---------------------------|----------------------------------
* 0x01 | BMM150_PRESETMODE_LOWPOWER
* 0x02 | BMM150_PRESETMODE_REGULAR
* 0x03 | BMM150_PRESETMODE_HIGHACCURACY
* 0x04 | BMM150_PRESETMODE_ENHANCED
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_set_presetmode(struct bmm150_settings *settings, struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiSensorSettings Sensor Settings
* @brief Set / Get sensor settings of the sensor
*/
/*!
* \ingroup bmm150ApiSensorSettings
* \page bmm150_api_bmm150_set_sensor_settings bmm150_set_sensor_settings
* \code
* int8_t bmm150_set_sensor_settings(uint16_t desired_settings, const struct bmm150_settings *settings, struct bmm150_dev *dev);
* \endcode
* @details This API sets the sensor settings based on the desired_settings
* and the dev structure configuration
*
* @param[in] desired_settings : Selection macro for selecting the setting.
* @param[in] settings : Structure instance of bmm150_settings.
* @param[in] dev : Structure instance of bmm150_dev.
*
* @note Assign the sensor setting macros (multiple macros can be
* set by doing a bitwise-OR operation) to the desired_settings parameter
* of this API to perform the corresponding setting.
*
* @note threshold interrupt for each axes are set by using bitwise AND
* operation of the following macros
* - BMM150_THRESHOLD_X
* - BMM150_THRESHOLD_Y
* - BMM150_THRESHOLD_Z
*
*@verbatim
* desired_settings | Selected sensor setting macros
* -------------------|--------------------------------
* 0x0001 | BMM150_SEL_DATA_RATE
* 0x0002 | BMM150_SEL_CONTROL_MEASURE
* 0x0004 | BMM150_SEL_XY_REP
* 0x0008 | BMM150_SEL_Z_REP
* 0x0010 | BMM150_SEL_DRDY_PIN_EN
* 0x0020 | BMM150_SEL_INT_PIN_EN
* 0x0040 | BMM150_SEL_DRDY_POLARITY
* 0x0080 | BMM150_SEL_INT_LATCH
* 0x0100 | BMM150_SEL_INT_POLARITY
* 0x0200 | BMM150_SEL_DATA_OVERRUN_INT
* 0x0400 | BMM150_SEL_OVERFLOW_INT
* 0x0800 | BMM150_SEL_HIGH_THRESHOLD_INT
* 0x1000 | BMM150_SEL_LOW_THRESHOLD_INT
* 0x2000 | BMM150_SEL_LOW_THRESHOLD_SETTING
* 0x4000 | BMM150_SEL_HIGH_THRESHOLD_SETTING
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_set_sensor_settings(uint16_t desired_settings,
const struct bmm150_settings *settings,
struct bmm150_dev *dev);
/*!
* \ingroup bmm150ApiSensorSettings
* \page bmm150_api_bmm150_get_sensor_settings bmm150_get_sensor_settings
* \code
* int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev);
* \endcode
* @details This API gets all the sensor settings and updates the dev structure
*
* @param[in] settings : Structure instance of bmm150_settings.
* @param[in] dev : Structure instance of bmm150_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_get_sensor_settings(struct bmm150_settings *settings, struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiMagData Read magnetometer data
* @brief Read magnetometer data
*/
/*!
* \ingroup bmm150ApiMagData
* \page bmm150_api_bmm150_read_mag_data bmm150_read_mag_data
* \code
* int8_t bbmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev);
* \endcode
* @details This API reads the magnetometer data from registers 0x42 to 0x49
* and updates the dev structure with compensated mag data in micro-tesla
*
* @param[in] mag_data : Structure instance of bmm150_mag_data.
* @param[in,out] dev : Structure instance of bmm150_dev.
*
* @note The output mag data can be obtained either in int16_t or float format
* using this API.
* @note Enable the macro "BMM150_USE_FLOATING_POINT" in the bmm150_defs.h
* file and call this API to get the mag data in float,
* disable this macro to get the mag data in int16_t format
*
*@verbatim
* Mag data output(micro-tesla) | Mag data in dev structure(int16_t/float)
* --------------------------------|------------------------------------------
* X-axis data | mag_data->x
* Y-axis data | mag_data->y
* Z-axis data | mag_data->z
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_read_mag_data(struct bmm150_mag_data *mag_data, struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiSelftest Self test
* @brief Perform self test
*/
/*!
* \ingroup bmm150ApiSelftest
* \page bmm150_api_bmm150_perform_self_test bmm150_perform_self_test
* \code
* int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev);
* \endcode
* @details This API is used to perform the complete self test
* (both normal and advanced) for the BMM150 sensor
*
* @param[in] self_test_mode : The type of self test to be performed
* @param[in] dev : Structure instance of bmm150_dev.
*
*@verbatim
* self_test_mode | Self test enabled
* --------------------|--------------------------
* 0 | BMM150_SELF_TEST_NORMAL
* 1 | BMM150_SELF_TEST_ADVANCED
*@endverbatim
*
* @note The return value of this API gives us the result of self test.
*
* @note Performing advanced self test does soft reset of the sensor, User can
* set the desired settings after performing the advanced self test.
*
* @return Result of API execution status and self test result.
* @retval 0 BMM150_OK
* @retval 1 BMM150_W_NORMAL_SELF_TEST_YZ_FAIL
* @retval 2 BMM150_W_NORMAL_SELF_TEST_XZ_FAIL
* @retval 3 BMM150_W_NORMAL_SELF_TEST_Z_FAIL
* @retval 4 BMM150_W_NORMAL_SELF_TEST_XY_FAIL
* @retval 5 BMM150_W_NORMAL_SELF_TEST_Y_FAIL
* @retval 6 BMM150_W_NORMAL_SELF_TEST_X_FAIL
* @retval 7 BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL
* @retval 8 BMM150_W_ADV_SELF_TEST_FAIL
*/
int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiInt Interrupt status
* @brief Obtain interrupt staus flags
*/
/*!
* \ingroup bmm150ApiInt
* \page bmm150_api_bmm150_get_interrupt_status bmm150_get_interrupt_status
* \code
* int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev);
* \endcode
* @details This API obtains the status flags of all interrupt
* which is used to check for the assertion of interrupts
*
* @param[in,out] dev : Structure instance of bmm150_dev.
*
* @note The status flags of all the interrupts are stored in the
* dev->int_status.
*
* @note The value of dev->int_status is performed a bitwise AND operation
* with predefined interrupt status macros to find the interrupt status
* which is either set or reset.
*
* Ex.
* if (dev->int_status & BMM150_INT_ASSERTED_DRDY)
* {
* Occurrence of data ready interrupt
* } else {
* No interrupt occurred
* }
*
* @return Result of API execution status and self test result.
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev);
/**
* \ingroup bmm150
* \defgroup bmm150ApiAux Compensate magnetometer data
* @brief Compensation of magnetometer data
*/
/*!
* \ingroup bmm150ApiAux
* \page bmm150_api_bmm150_aux_mag_data bmm150_aux_mag_data
* \code
* int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev);
* \endcode
* @details This API is used to compensate the raw mag data
*
* @param[in] aux_data : Raw mag data obtained from BMI160 registers
* @param[in] mag_data : Structure instance of bmm150_mag_data.
* @param[in,out] dev : Structure instance of bmm150_dev.
*
* @return Result of API execution status and self test result.
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Fail
*/
int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_mag_data *mag_data, const struct bmm150_dev *dev);
#ifdef __cplusplus
}
#endif /* End of CPP guard */
#endif /* _BMM150_H */

View File

@@ -0,0 +1,643 @@
/**
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bmm150_defs.h
* @date 2020-06-03
* @version v2.0.0
*
*/
/*! \file bmm150_defs.h */
#ifndef _BMM150_DEFS_H
#define _BMM150_DEFS_H
/******************************************************************************/
/*! @name Header includes */
/******************************************************************************/
#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <stdint.h>
#include <stddef.h>
#endif
/******************************************************************************/
/*! @name Common macros */
/******************************************************************************/
#ifdef __KERNEL__
#if (LONG_MAX) > 0x7fffffff
#define __have_long64 1
#elif (LONG_MAX) == 0x7fffffff
#define __have_long32 1
#endif
#endif
#if !defined(UINT8_C)
#define INT8_C(x) x
#if (INT_MAX) > 0x7f
#define UINT8_C(x) x
#else
#define UINT8_C(x) x##U
#endif
#endif
#if !defined(UINT16_C)
#define INT16_C(x) x
#if (INT_MAX) > 0x7fff
#define UINT16_C(x) x
#else
#define UINT16_C(x) x##U
#endif
#endif
#if !defined(INT32_C) && !defined(UINT32_C)
#if __have_long32
#define INT32_C(x) x##L
#define UINT32_C(x) x##UL
#else
#define INT32_C(x) x
#define UINT32_C(x) x##U
#endif
#endif
#if !defined(INT64_C) && !defined(UINT64_C)
#if __have_long64
#define INT64_C(x) x##L
#define UINT64_C(x) x##UL
#else
#define INT64_C(x) x##LL
#define UINT64_C(x) x##ULL
#endif
#endif
/*! @name C standard macros */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *) 0)
#endif
#endif
/******************************************************************************/
/*! @name Compiler switch macros Definitions */
/******************************************************************************/
#ifndef BMM150_USE_FLOATING_POINT /*< Check if floating point (using BMM150_USE_FLOATING_POINT) is enabled */
#ifndef BMM150_USE_FIXED_POINT /*< If floating point is not enabled then enable BMM150_USE_FIXED_POINT */
#define BMM150_USE_FIXED_POINT
#endif
#endif
/******************************************************************************/
/*! @name General Macro Definitions */
/******************************************************************************/
/*! @name API success code */
#define BMM150_OK INT8_C(0)
/*! @name To define TRUE or FALSE */
#define BMM150_TRUE UINT8_C(1)
#define BMM150_FALSE UINT8_C(0)
/*! @name API error codes */
#define BMM150_E_NULL_PTR INT8_C(-1)
#define BMM150_E_DEV_NOT_FOUND INT8_C(-2)
#define BMM150_E_INVALID_CONFIG INT8_C(-3)
#define BMM150_E_COM_FAIL INT8_C(-4)
/*! @name API warning codes */
#define BMM150_W_NORMAL_SELF_TEST_YZ_FAIL INT8_C(1)
#define BMM150_W_NORMAL_SELF_TEST_XZ_FAIL INT8_C(2)
#define BMM150_W_NORMAL_SELF_TEST_Z_FAIL INT8_C(3)
#define BMM150_W_NORMAL_SELF_TEST_XY_FAIL INT8_C(4)
#define BMM150_W_NORMAL_SELF_TEST_Y_FAIL INT8_C(5)
#define BMM150_W_NORMAL_SELF_TEST_X_FAIL INT8_C(6)
#define BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL INT8_C(7)
#define BMM150_W_ADV_SELF_TEST_FAIL INT8_C(8)
/*! @name CHIP ID & SOFT RESET VALUES */
#define BMM150_CHIP_ID UINT8_C(0x32)
#define BMM150_SET_SOFT_RESET UINT8_C(0x82)
/*! @name POWER MODE DEFINTIONS */
#define BMM150_POWERMODE_NORMAL UINT8_C(0x00)
#define BMM150_POWERMODE_FORCED UINT8_C(0x01)
#define BMM150_POWERMODE_SLEEP UINT8_C(0x03)
#define BMM150_POWERMODE_SUSPEND UINT8_C(0x04)
/*! @name Power mode settings */
#define BMM150_POWER_CNTRL_DISABLE UINT8_C(0x00)
#define BMM150_POWER_CNTRL_ENABLE UINT8_C(0x01)
/*! @name Sensor delay time settings */
#define BMM150_DELAY_SOFT_RESET UINT8_C(1000)
#define BMM150_DELAY_NORMAL_SELF_TEST UINT8_C(2000)
#define BMM150_START_UP_TIME UINT8_C(3000)
#define BMM150_DELAY_ADV_SELF_TEST UINT8_C(4000)
/*! @name ENABLE/DISABLE DEFINITIONS */
#define BMM150_XYZ_CHANNEL_ENABLE UINT8_C(0x00)
#define BMM150_XYZ_CHANNEL_DISABLE UINT8_C(0x07)
/*! @name Register Address */
#define BMM150_REG_CHIP_ID UINT8_C(0x40)
#define BMM150_REG_DATA_X_LSB UINT8_C(0x42)
#define BMM150_REG_DATA_READY_STATUS UINT8_C(0x48)
#define BMM150_REG_INTERRUPT_STATUS UINT8_C(0x4A)
#define BMM150_REG_POWER_CONTROL UINT8_C(0x4B)
#define BMM150_REG_OP_MODE UINT8_C(0x4C)
#define BMM150_REG_INT_CONFIG UINT8_C(0x4D)
#define BMM150_REG_AXES_ENABLE UINT8_C(0x4E)
#define BMM150_REG_LOW_THRESHOLD UINT8_C(0x4F)
#define BMM150_REG_HIGH_THRESHOLD UINT8_C(0x50)
#define BMM150_REG_REP_XY UINT8_C(0x51)
#define BMM150_REG_REP_Z UINT8_C(0x52)
/*! @name Macros to select the sensor settings to be set by the user
* These values are internal for API implementation. Don't relate this to
* data sheet.
*/
#define BMM150_SEL_DATA_RATE UINT16_C(1)
#define BMM150_SEL_CONTROL_MEASURE UINT16_C(1 << 1)
#define BMM150_SEL_XY_REP UINT16_C(1 << 2)
#define BMM150_SEL_Z_REP UINT16_C(1 << 3)
#define BMM150_SEL_DRDY_PIN_EN UINT16_C(1 << 4)
#define BMM150_SEL_INT_PIN_EN UINT16_C(1 << 5)
#define BMM150_SEL_DRDY_POLARITY UINT16_C(1 << 6)
#define BMM150_SEL_INT_LATCH UINT16_C(1 << 7)
#define BMM150_SEL_INT_POLARITY UINT16_C(1 << 8)
#define BMM150_SEL_DATA_OVERRUN_INT UINT16_C(1 << 9)
#define BMM150_SEL_OVERFLOW_INT UINT16_C(1 << 10)
#define BMM150_SEL_HIGH_THRESHOLD_INT UINT16_C(1 << 11)
#define BMM150_SEL_LOW_THRESHOLD_INT UINT16_C(1 << 12)
#define BMM150_SEL_LOW_THRESHOLD_SETTING UINT16_C(1 << 13)
#define BMM150_SEL_HIGH_THRESHOLD_SETTING UINT16_C(1 << 14)
/*! @name DATA RATE DEFINITIONS */
#define BMM150_DATA_RATE_10HZ UINT8_C(0x00)
#define BMM150_DATA_RATE_02HZ UINT8_C(0x01)
#define BMM150_DATA_RATE_06HZ UINT8_C(0x02)
#define BMM150_DATA_RATE_08HZ UINT8_C(0x03)
#define BMM150_DATA_RATE_15HZ UINT8_C(0x04)
#define BMM150_DATA_RATE_20HZ UINT8_C(0x05)
#define BMM150_DATA_RATE_25HZ UINT8_C(0x06)
#define BMM150_DATA_RATE_30HZ UINT8_C(0x07)
#define BMM150_ODR_MAX UINT8_C(0x07)
#define BMM150_ODR_MSK UINT8_C(0x38)
#define BMM150_ODR_POS UINT8_C(0x03)
/*! @name TRIM REGISTERS */
/* Trim Extended Registers */
#define BMM150_DIG_X1 UINT8_C(0x5D)
#define BMM150_DIG_Y1 UINT8_C(0x5E)
#define BMM150_DIG_Z4_LSB UINT8_C(0x62)
#define BMM150_DIG_Z4_MSB UINT8_C(0x63)
#define BMM150_DIG_X2 UINT8_C(0x64)
#define BMM150_DIG_Y2 UINT8_C(0x65)
#define BMM150_DIG_Z2_LSB UINT8_C(0x68)
#define BMM150_DIG_Z2_MSB UINT8_C(0x69)
#define BMM150_DIG_Z1_LSB UINT8_C(0x6A)
#define BMM150_DIG_Z1_MSB UINT8_C(0x6B)
#define BMM150_DIG_XYZ1_LSB UINT8_C(0x6C)
#define BMM150_DIG_XYZ1_MSB UINT8_C(0x6D)
#define BMM150_DIG_Z3_LSB UINT8_C(0x6E)
#define BMM150_DIG_Z3_MSB UINT8_C(0x6F)
#define BMM150_DIG_XY2 UINT8_C(0x70)
#define BMM150_DIG_XY1 UINT8_C(0x71)
/*! @name Threshold interrupt setting macros for x,y,z axes selection */
#define BMM150_THRESHOLD_X UINT8_C(0x06)
#define BMM150_THRESHOLD_Y UINT8_C(0x05)
#define BMM150_THRESHOLD_Z UINT8_C(0x03)
#define BMM150_HIGH_THRESHOLD_INT_MSK UINT8_C(0x38)
#define BMM150_HIGH_THRESHOLD_INT_POS UINT8_C(0x03)
#define BMM150_LOW_THRESHOLD_INT_MSK UINT8_C(0x07)
/*! @name User configurable interrupt setting macros */
#define BMM150_INT_ENABLE UINT8_C(0x01)
#define BMM150_INT_DISABLE UINT8_C(0x00)
#define BMM150_ACTIVE_HIGH_POLARITY UINT8_C(0x01)
#define BMM150_ACTIVE_LOW_POLARITY UINT8_C(0x00)
#define BMM150_LATCHED UINT8_C(0x01)
#define BMM150_NON_LATCHED UINT8_C(0x00)
/*! @name Interrupt status */
#define BMM150_INT_THRESHOLD_X_LOW UINT16_C(0x0001)
#define BMM150_INT_THRESHOLD_Y_LOW UINT16_C(0x0002)
#define BMM150_INT_THRESHOLD_Z_LOW UINT16_C(0x0004)
#define BMM150_INT_THRESHOLD_X_HIGH UINT16_C(0x0008)
#define BMM150_INT_THRESHOLD_Y_HIGH UINT16_C(0x0010)
#define BMM150_INT_THRESHOLD_Z_HIGH UINT16_C(0x0020)
#define BMM150_INT_DATA_OVERFLOW UINT16_C(0x0040)
#define BMM150_INT_DATA_OVERRUN UINT16_C(0x0080)
#define BMM150_INT_DATA_READY UINT16_C(0x0100)
#define BMM150_DRDY_EN_MSK UINT8_C(0x80)
#define BMM150_DRDY_EN_POS UINT8_C(0x07)
#define BMM150_DRDY_POLARITY_MSK UINT8_C(0x04)
#define BMM150_DRDY_POLARITY_POS UINT8_C(0x02)
#define BMM150_INT_PIN_EN_MSK UINT8_C(0x40)
#define BMM150_INT_PIN_EN_POS UINT8_C(0x06)
#define BMM150_INT_LATCH_MSK UINT8_C(0x02)
#define BMM150_INT_LATCH_POS UINT8_C(0x01)
#define BMM150_INT_POLARITY_MSK UINT8_C(0x01)
#define BMM150_DRDY_STATUS_MSK UINT8_C(0x01)
/*! @name Interrupt status macros */
#define BMM150_INT_ASSERTED_DRDY UINT16_C(0x0100)
#define BMM150_INT_ASSERTED_LOW_THRES UINT16_C(0x0007)
#define BMM150_INT_ASSERTED_HIGH_THRES UINT16_C(0x0380)
/*! @name Power control bit macros */
#define BMM150_PWR_CNTRL_MSK UINT8_C(0x01)
#define BMM150_CONTROL_MEASURE_MSK UINT8_C(0x38)
#define BMM150_CONTROL_MEASURE_POS UINT8_C(0x03)
#define BMM150_POWER_CONTROL_BIT_MSK UINT8_C(0x01)
#define BMM150_POWER_CONTROL_BIT_POS UINT8_C(0x00)
/*! @name Data macros */
#define BMM150_DATA_X_MSK UINT8_C(0xF8)
#define BMM150_DATA_X_POS UINT8_C(0x03)
#define BMM150_DATA_Y_MSK UINT8_C(0xF8)
#define BMM150_DATA_Y_POS UINT8_C(0x03)
#define BMM150_DATA_Z_MSK UINT8_C(0xFE)
#define BMM150_DATA_Z_POS UINT8_C(0x01)
#define BMM150_DATA_RHALL_MSK UINT8_C(0xFC)
#define BMM150_DATA_RHALL_POS UINT8_C(0x02)
#define BMM150_DATA_OVERRUN_INT_MSK UINT8_C(0x80)
#define BMM150_DATA_OVERRUN_INT_POS UINT8_C(0x07)
#define BMM150_OVERFLOW_INT_MSK UINT8_C(0x40)
#define BMM150_OVERFLOW_INT_POS UINT8_C(0x06)
/*! @name OVERFLOW DEFINITIONS */
#define BMM150_OVERFLOW_ADCVAL_XYAXES_FLIP INT16_C(-4096)
#define BMM150_OVERFLOW_ADCVAL_ZAXIS_HALL INT16_C(-16384)
#define BMM150_OVERFLOW_OUTPUT INT16_C(-32768)
#define BMM150_NEGATIVE_SATURATION_Z INT16_C(-32767)
#define BMM150_POSITIVE_SATURATION_Z INT16_C(32767)
#ifdef BMM150_USE_FLOATING_POINT
#define BMM150_OVERFLOW_OUTPUT_FLOAT 0.0f
#endif
/*! @name PRESET MODE DEFINITIONS */
#define BMM150_PRESETMODE_LOWPOWER UINT8_C(0x01)
#define BMM150_PRESETMODE_REGULAR UINT8_C(0x02)
#define BMM150_PRESETMODE_HIGHACCURACY UINT8_C(0x03)
#define BMM150_PRESETMODE_ENHANCED UINT8_C(0x04)
#define BMM150_OP_MODE_MSK UINT8_C(0x06)
#define BMM150_OP_MODE_POS UINT8_C(0x01)
/*! @name PRESET MODES - REPETITIONS-XY RATES */
#define BMM150_REPXY_LOWPOWER UINT8_C(0x01)
#define BMM150_REPXY_REGULAR UINT8_C(0x04)
#define BMM150_REPXY_ENHANCED UINT8_C(0x07)
#define BMM150_REPXY_HIGHACCURACY UINT8_C(0x17)
/*! @name PRESET MODES - REPETITIONS-Z RATES */
#define BMM150_REPZ_LOWPOWER UINT8_C(0x01)
#define BMM150_REPZ_REGULAR UINT8_C(0x07)
#define BMM150_REPZ_ENHANCED UINT8_C(0x0D)
#define BMM150_REPZ_HIGHACCURACY UINT8_C(0x29)
/*! @name Self test settings */
#define BMM150_DISABLE_XY_AXIS UINT8_C(0x03)
#define BMM150_SELF_TEST_REP_Z UINT8_C(0x04)
/*! @name Self test selection macros */
#define BMM150_SELF_TEST_NORMAL UINT8_C(0)
#define BMM150_SELF_TEST_ADVANCED UINT8_C(1)
/*! @name Advanced self-test current settings */
#define BMM150_DISABLE_SELF_TEST_CURRENT UINT8_C(0x00)
#define BMM150_ENABLE_NEGATIVE_CURRENT UINT8_C(0x02)
#define BMM150_ENABLE_POSITIVE_CURRENT UINT8_C(0x03)
/*! @name Normal self-test status */
#define BMM150_SELF_TEST_STATUS_XYZ_FAIL UINT8_C(0x00)
#define BMM150_SELF_TEST_STATUS_SUCCESS UINT8_C(0x07)
#define BMM150_SELF_TEST_MSK UINT8_C(0x01)
#define BMM150_ADV_SELF_TEST_MSK UINT8_C(0xC0)
#define BMM150_ADV_SELF_TEST_POS UINT8_C(0x06)
/*! @name Register read lengths */
#define BMM150_LEN_SELF_TEST UINT8_C(5)
#define BMM150_LEN_SETTING_DATA UINT8_C(8)
#define BMM150_LEN_XYZR_DATA UINT8_C(8)
/*! @name Boundary check macros */
#define BMM150_BOUNDARY_MAXIMUM UINT8_C(0)
#define BMM150_BOUNDARY_MINIMUM UINT8_C(1)
/*! @name Macro to SET and GET BITS of a register*/
#define BMM150_SET_BITS(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \
((data << bitname##_POS) & bitname##_MSK))
#define BMM150_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
(bitname##_POS))
#define BMM150_SET_BITS_POS_0(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \
(data & bitname##_MSK))
#define BMM150_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
/********************************************************/
/*!
* @brief Interface selection Enums
*/
enum bmm150_intf {
/*! SPI interface */
BMM150_SPI_INTF,
/*! I2C interface */
BMM150_I2C_INTF
};
/******************************************************************************/
/*! @name Function Pointers */
/******************************************************************************/
#ifndef BMM150_INTF_RET_TYPE
#define BMM150_INTF_RET_TYPE int8_t
#endif
#ifndef BMM150_INTF_RET_SUCCESS
#define BMM150_INTF_RET_SUCCESS INT8_C(0)
#endif
/*!
* @brief Bus communication function pointer which should be mapped to
* the platform specific read functions of the user
*
* @param[in] reg_addr : 8bit register address of the sensor
* @param[out] reg_data : Data from the specified address
* @param[in] length : Length of the reg_data array
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
* for interface related callbacks
* @retval 0 for Success
* @retval Non-zero for Failure
*/
typedef BMM150_INTF_RET_TYPE (*bmm150_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
void *intf_ptr);
/*!
* @brief Bus communication function pointer which should be mapped to
* the platform specific write functions of the user
*
* @param[in] reg_addr : 8bit register address of the sensor
* @param[out] reg_data : Data to the specified address
* @param[in] length : Length of the reg_data array
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
* for interface related callbacks
* @retval 0 for Success
* @retval Non-zero for Failure
*
*/
typedef BMM150_INTF_RET_TYPE (*bmm150_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
void *intf_ptr);
/*!
* @brief Delay function pointer which should be mapped to
* delay function of the user
*
* @param period : The time period in microseconds
* @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors
* for interface related callbacks
*/
typedef void (*bmm150_delay_us_fptr_t)(uint32_t period, void *intf_ptr);
/******************************************************************************/
/*! @name Structure Declarations */
/******************************************************************************/
/*!
* @brief bmm150 trim data structure
*/
struct bmm150_trim_registers {
/*! trim x1 data */
int8_t dig_x1;
/*! trim y1 data */
int8_t dig_y1;
/*! trim x2 data */
int8_t dig_x2;
/*! trim y2 data */
int8_t dig_y2;
/*! trim z1 data */
uint16_t dig_z1;
/*! trim z2 data */
int16_t dig_z2;
/*! trim z3 data */
int16_t dig_z3;
/*! trim z4 data */
int16_t dig_z4;
/*! trim xy1 data */
uint8_t dig_xy1;
/*! trim xy2 data */
int8_t dig_xy2;
/*! trim xyz1 data */
uint16_t dig_xyz1;
};
/*!
* @brief bmm150 interrupt pin settings
*/
struct bmm150_int_ctrl_settings {
/*! Data ready interrupt enable */
uint8_t drdy_pin_en;
/*! Threshold and overflow interrupts enable */
uint8_t int_pin_en;
/*! Data ready interrupt polarity Active high/low */
uint8_t drdy_polarity;
/*! Interrupt pin - Latched or Non-latched */
uint8_t int_latch;
/*! Interrupt polarity Active high/low */
uint8_t int_polarity;
/*! Data overrun interrupt enable */
uint8_t data_overrun_en;
/*! Overflow interrupt enable */
uint8_t overflow_int_en;
/*! high interrupt enable/disable axis selection */
uint8_t high_int_en;
/*! low interrupt enable/disable axis selection */
uint8_t low_int_en;
/*! low threshold limit */
uint8_t low_threshold;
/*! high threshold limit */
uint8_t high_threshold;
};
/*!
* @brief bmm150 sensor settings
*/
struct bmm150_settings {
/*! Control measurement of XYZ axes */
uint8_t xyz_axes_control;
/*! Power mode of sensor */
uint8_t pwr_mode;
/*! Data rate value (ODR) */
uint8_t data_rate;
/*! XY Repetitions */
uint8_t xy_rep;
/*! Z Repetitions */
uint8_t z_rep;
/*! Preset mode of sensor */
uint8_t preset_mode;
/*! Interrupt configuration settings */
struct bmm150_int_ctrl_settings int_settings;
};
/*!
* @brief bmm150 un-compensated (raw) magnetometer data
*/
struct bmm150_raw_mag_data {
/*! Raw mag X data */
int16_t raw_datax;
/*! Raw mag Y data */
int16_t raw_datay;
/*! Raw mag Z data */
int16_t raw_dataz;
/*! Raw mag resistance value */
uint16_t raw_data_r;
};
#ifdef BMM150_USE_FLOATING_POINT
/*!
* @brief bmm150 compensated magnetometer data in float
*/
struct bmm150_mag_data {
/*! compensated mag X data */
float x;
/*! compensated mag Y data */
float y;
/*! compensated mag Z data */
float z;
};
#else
/*!
* @brief bmm150 compensated magnetometer data in int16_t format
*/
struct bmm150_mag_data {
/*! compensated mag X data */
int16_t x;
/*! compensated mag Y data */
int16_t y;
/*! compensated mag Z data */
int16_t z;
};
#endif
/*!
* @brief bmm150 device structure
*/
struct bmm150_dev {
/*! Chip Id */
uint8_t chip_id;
/*! SPI/I2C Interface */
enum bmm150_intf intf;
/*!
* The interface pointer is used to enable the user
* to link their interface descriptors for reference during the
* implementation of the read and write interfaces to the
* hardware.
*/
void *intf_ptr;
/*! Variable that holds result of read/write function */
BMM150_INTF_RET_TYPE intf_rslt;
/*! Bus read function pointer */
bmm150_read_fptr_t read;
/*! Bus write function pointer */
bmm150_write_fptr_t write;
/*! delay(in us) function pointer */
bmm150_delay_us_fptr_t delay_us;
/*! Trim registers */
struct bmm150_trim_registers trim_data;
/*! Interrupt status */
uint16_t int_status;
/*! Power control bit value */
uint8_t pwr_cntrl_bit;
};
#endif /* BMM150_DEFS_H_ */

View File

@@ -0,0 +1,181 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file BoschParse.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-30
*
*/
#include "BoschParse.h"
std::vector<SensorEventCbList_t> BoschParse::bhyEventVector;
std::vector<ParseCallBackList_t> BoschParse::bhyParseEventVector;
uint8_t SensorEventCbList::current_id = 1;
uint8_t ParseCallBackList::current_id = 1;
void BoschParse::parseData(const struct bhy2_fifo_parse_data_info *fifo, void *user_data)
{
int8_t size = fifo->data_size - 1;
#ifdef LOG_PORT
LOG_PORT.print("Sensor: ");
LOG_PORT.print(fifo->sensor_id);
LOG_PORT.print(" size: ");
LOG_PORT.print(fifo->data_size);
LOG_PORT.print(" value:");
for (uint8_t i = 0; i < size; i++) {
LOG_PORT.printf("%04x", fifo->data_ptr[i]);
LOG_PORT.print(" ");
}
LOG_PORT.println();
#endif
for (uint32_t i = 0; i < bhyParseEventVector.size(); i++) {
ParseCallBackList_t entry = bhyParseEventVector[i];
if (entry.cb ) {
if (entry.id == fifo->sensor_id) {
if (entry.cb) {
entry.cb(fifo->sensor_id, fifo->data_ptr, size, fifo->time_stamp);
}
}
}
}
}
void BoschParse::parseMetaEvent(const struct bhy2_fifo_parse_data_info *callback_info, void *user_data)
{
(void)user_data;
uint8_t meta_event_type = callback_info->data_ptr[0];
uint8_t byte1 = callback_info->data_ptr[1];
uint8_t byte2 = callback_info->data_ptr[2];
const char *event_text;
// Remove warning
(void)byte1;
(void)byte2;
(void)event_text;
uint8_t *accuracy = (uint8_t *)user_data;
if (callback_info->sensor_id == BHY2_SYS_ID_META_EVENT) {
event_text = "[META EVENT]";
} else if (callback_info->sensor_id == BHY2_SYS_ID_META_EVENT_WU) {
event_text = "[META EVENT WAKE UP]";
} else {
return;
}
switch (meta_event_type) {
case BHY2_META_EVENT_FLUSH_COMPLETE:
log_i("%s Flush complete for sensor id %u", event_text, byte1);
break;
case BHY2_META_EVENT_SAMPLE_RATE_CHANGED:
log_i("%s Sample rate changed for sensor id %u", event_text, byte1);
break;
case BHY2_META_EVENT_POWER_MODE_CHANGED:
log_i("%s Power mode changed for sensor id %u", event_text, byte1);
break;
case BHY2_META_EVENT_ALGORITHM_EVENTS:
log_i("%s Algorithm event", event_text);
break;
case BHY2_META_EVENT_SENSOR_STATUS:
log_i("%s Accuracy for sensor id %u changed to %u", event_text, byte1, byte2);
if (accuracy) {
*accuracy = byte2;
}
break;
case BHY2_META_EVENT_BSX_DO_STEPS_MAIN:
log_i("%s BSX event (do steps main)", event_text);
break;
case BHY2_META_EVENT_BSX_DO_STEPS_CALIB:
log_i("%s BSX event (do steps calib)", event_text);
break;
case BHY2_META_EVENT_BSX_GET_OUTPUT_SIGNAL:
log_i("%s BSX event (get output signal)", event_text);
break;
case BHY2_META_EVENT_SENSOR_ERROR:
log_i("%s Sensor id %u reported error 0x%02X", event_text, byte1, byte2);
break;
case BHY2_META_EVENT_FIFO_OVERFLOW:
log_i("%s FIFO overflow", event_text);
break;
case BHY2_META_EVENT_DYNAMIC_RANGE_CHANGED:
log_i("%s Dynamic range changed for sensor id %u", event_text, byte1);
break;
case BHY2_META_EVENT_FIFO_WATERMARK:
log_i("%s FIFO watermark reached", event_text);
break;
case BHY2_META_EVENT_INITIALIZED:
log_i("%s Firmware initialized. Firmware version %u", event_text, ((uint16_t)byte2 << 8) | byte1);
break;
case BHY2_META_TRANSFER_CAUSE:
log_i("%s Transfer cause for sensor id %u", event_text, byte1);
break;
case BHY2_META_EVENT_SENSOR_FRAMEWORK:
log_i("%s Sensor framework event for sensor id %u", event_text, byte1);
break;
case BHY2_META_EVENT_RESET:
log_i("%s Reset event", event_text);
break;
case BHY2_META_EVENT_SPACER:
return;
default:
log_i("%s Unknown meta event with id: %u", event_text, meta_event_type);
break;
}
for (uint32_t i = 0; i < bhyEventVector.size(); i++) {
SensorEventCbList_t entry = bhyEventVector[i];
if (entry.cb ) {
if (entry.event == meta_event_type) {
if (entry.cb) {
entry.cb(meta_event_type, callback_info->data_ptr, callback_info->data_size);
}
}
}
}
}
void BoschParse::parseDebugMessage(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref)
{
uint32_t s, ns;
uint64_t tns;
uint8_t msg_length = 0;
uint8_t debug_msg[17] = { 0 }; /* Max payload size is 16 bytes, adds a trailing zero if the payload is full */
if (!callback_info) {
log_i("Null reference");
return;
}
time_to_s_ns(*callback_info->time_stamp, &s, &ns, &tns);
msg_length = callback_info->data_ptr[0];
memcpy(debug_msg, &callback_info->data_ptr[1], msg_length);
debug_msg[msg_length] = '\0'; /* Terminate the string */
log_i("[DEBUG MSG]; T: %lu.%09lu; %s", s, ns, debug_msg);
}

View File

@@ -0,0 +1,58 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file BoschParse.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-30
*
*/
#pragma once
#include "SensorCommon.tpp"
#include "SensorBhy2Define.h"
#include "bosch/bhy2_parse.h"
#include "bosch/common/common.h"
#include <vector>
#include <functional>
enum BoschOrientation {
BHY2_DIRECTION_TOP_RIGHT,
BHY2_DIRECTION_TOP_LEFT,
BHY2_DIRECTION_BOTTOM_LEFT,
BHY2_DIRECTION_BOTTOM_RIGHT,
};
class BoschParse
{
public:
static std::vector<SensorEventCbList_t> bhyEventVector;
static std::vector<ParseCallBackList_t> bhyParseEventVector;
static void parseData(const struct bhy2_fifo_parse_data_info *fifo, void *user_data);
static void parseMetaEvent(const struct bhy2_fifo_parse_data_info *callback_info, void *user_data);
static void parseDebugMessage(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref);
};

View File

@@ -0,0 +1,203 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file SensorBhy2Define.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-09-30
*
*/
#pragma once
#include <stdint.h>
#include <stdio.h>
#define BHI260AP_SLAVE_ADDRESS_L 0x28
#define BHI260AP_SLAVE_ADDRESS_H 0x29
#define BHY_PROCESS_BUFFER_SIZE 512
#define BHY2_RLST_CHECK(ret, str, val) \
do \
{ \
if (ret) \
{ \
log_e(str); \
return val; \
} \
} while (0)
typedef void (*BhyEventCb)(uint8_t event, uint8_t *data, uint32_t size);
typedef void (*BhyParseDataCallback)(uint8_t sensor_id, uint8_t *data, uint32_t size,uint64_t *timestamp);
typedef struct SensorEventCbList {
static uint8_t current_id;
uint8_t id;
BhyEventCb cb;
uint8_t event;
uint8_t *data;
SensorEventCbList() : id(current_id++), cb(NULL), event(0), data(NULL)
{
}
} SensorEventCbList_t;
typedef struct ParseCallBackList {
static uint8_t current_id;
uint8_t id;
BhyParseDataCallback cb;
uint32_t data_length;
uint8_t *data;
ParseCallBackList() : id(current_id++), cb(NULL), data_length(0), data(NULL)
{
}
} ParseCallBackList_t;
enum BhySensorEvent {
BHY2_EVENT_FLUSH_COMPLETE = 1,
BHY2_EVENT_SAMPLE_RATE_CHANGED,
BHY2_EVENT_POWER_MODE_CHANGED,
BHY2_EVENT_ALGORITHM_EVENTS = 5,
BHY2_EVENT_SENSOR_STATUS,
BHY2_EVENT_BSX_DO_STEPS_MAIN,
BHY2_EVENT_BSX_DO_STEPS_CALIB,
BHY2_EVENT_BSX_GET_OUTPUT_SIGNAL,
BHY2_EVENT_SENSOR_ERROR = 11,
BHY2_EVENT_FIFO_OVERFLOW,
BHY2_EVENT_DYNAMIC_RANGE_CHANGED,
BHY2_EVENT_FIFO_WATERMARK,
BHY2_EVENT_INITIALIZED = 16,
BHY2_EVENT_TRANSFER_CAUSE,
BHY2_EVENT_SENSOR_FRAMEWORK,
BHY2_EVENT_RESET,
};
enum BhySensorID {
SENSOR_ID_ACC_PASS = 1, /* Accelerometer passthrough */
SENSOR_ID_ACC_RAW = 3, /* Accelerometer uncalibrated */
SENSOR_ID_ACC = 4, /* Accelerometer corrected */
SENSOR_ID_ACC_BIAS = 5, /* Accelerometer offset */
SENSOR_ID_ACC_WU = 6, /* Accelerometer corrected wake up */
SENSOR_ID_ACC_RAW_WU = 7, /* Accelerometer uncalibrated wake up */
SENSOR_ID_GYRO_PASS = 10, /* Gyroscope passthrough */
SENSOR_ID_GYRO_RAW = 12, /* Gyroscope uncalibrated */
SENSOR_ID_GYRO = 13, /* Gyroscope corrected */
SENSOR_ID_GYRO_BIAS = 14, /* Gyroscope offset */
SENSOR_ID_GYRO_WU = 15, /* Gyroscope wake up */
SENSOR_ID_GYRO_RAW_WU = 16, /* Gyroscope uncalibrated wake up */
SENSOR_ID_MAG_PASS = 19, /* Magnetometer passthrough */
SENSOR_ID_MAG_RAW = 21, /* Magnetometer uncalibrated */
SENSOR_ID_MAG = 22, /* Magnetometer corrected */
SENSOR_ID_MAG_BIAS = 23, /* Magnetometer offset */
SENSOR_ID_MAG_WU = 24, /* Magnetometer wake up */
SENSOR_ID_MAG_RAW_WU = 25, /* Magnetometer uncalibrated wake up */
SENSOR_ID_GRA = 28, /* Gravity vector */
SENSOR_ID_GRA_WU = 29, /* Gravity vector wake up */
SENSOR_ID_LACC = 31, /* Linear acceleration */
SENSOR_ID_LACC_WU = 32, /* Linear acceleration wake up */
SENSOR_ID_RV = 34, /* Rotation vector */
SENSOR_ID_RV_WU = 35, /* Rotation vector wake up */
SENSOR_ID_GAMERV = 37, /* Game rotation vector */
SENSOR_ID_GAMERV_WU = 38, /* Game rotation vector wake up */
SENSOR_ID_GEORV = 40, /* Geo-magnetic rotation vector */
SENSOR_ID_GEORV_WU = 41, /* Geo-magnetic rotation vector wake up */
SENSOR_ID_ORI = 43, /* Orientation */
SENSOR_ID_ORI_WU = 44, /* Orientation wake up */
SENSOR_ID_TILT_DETECTOR = 48, /* Tilt detector */
SENSOR_ID_STD = 50, /* Step detector */
SENSOR_ID_STC = 52, /* Step counter */
SENSOR_ID_STC_WU = 53, /* Step counter wake up */
SENSOR_ID_SIG = 55, /* Significant motion */
SENSOR_ID_WAKE_GESTURE = 57, /* Wake gesture */
SENSOR_ID_GLANCE_GESTURE = 59, /* Glance gesture */
SENSOR_ID_PICKUP_GESTURE = 61, /* Pickup gesture */
SENSOR_ID_AR = 63, /* Activity recognition */
SENSOR_ID_WRIST_TILT_GESTURE = 67, /* Wrist tilt gesture */
SENSOR_ID_DEVICE_ORI = 69, /* Device orientation */
SENSOR_ID_DEVICE_ORI_WU = 70, /* Device orientation wake up */
SENSOR_ID_STATIONARY_DET = 75, /* Stationary detect */
SENSOR_ID_MOTION_DET = 77, /* Motion detect */
SENSOR_ID_ACC_BIAS_WU = 91, /* Accelerometer offset wake up */
SENSOR_ID_GYRO_BIAS_WU = 92, /* Gyroscope offset wake up */
SENSOR_ID_MAG_BIAS_WU = 93, /* Magnetometer offset wake up */
SENSOR_ID_STD_WU = 94, /* Step detector wake up */
SENSOR_ID_BSEC = 115, /* BSEC 1.x output */
SENSOR_ID_TEMP = 128, /* Temperature */
SENSOR_ID_BARO = 129, /* Barometer */
SENSOR_ID_HUM = 130, /* Humidity */
SENSOR_ID_GAS = 131, /* Gas */
SENSOR_ID_TEMP_WU = 132, /* Temperature wake up */
SENSOR_ID_BARO_WU = 133, /* Barometer wake up */
SENSOR_ID_HUM_WU = 134, /* Humidity wake up */
SENSOR_ID_GAS_WU = 135, /* Gas wake up */
SENSOR_ID_STC_HW = 136, /* Hardware Step counter */
SENSOR_ID_STD_HW = 137, /* Hardware Step detector */
SENSOR_ID_SIG_HW = 138, /* Hardware Significant motion */
SENSOR_ID_STC_HW_WU = 139, /* Hardware Step counter wake up */
SENSOR_ID_STD_HW_WU = 140, /* Hardware Step detector wake up */
SENSOR_ID_SIG_HW_WU = 141, /* Hardware Significant motion wake up */
SENSOR_ID_ANY_MOTION = 142, /* Any motion */
SENSOR_ID_ANY_MOTION_WU = 143, /* Any motion wake up */
SENSOR_ID_EXCAMERA = 144, /* External camera trigger */
SENSOR_ID_GPS = 145, /* GPS */
SENSOR_ID_LIGHT = 146, /* Light */
SENSOR_ID_PROX = 147, /* Proximity */
SENSOR_ID_LIGHT_WU = 148, /* Light wake up */
SENSOR_ID_PROX_WU = 149, /* Proximity wake up */
SENSOR_ID_BSEC_LEGACY = 171, /* BSEC 1.x output (legacy, deprecated) */
SENSOR_DEBUG_DATA_EVENT = 250, /* Binary or string debug data */
SENSOR_TIMESTAMP_SMALL_DELTA = 251, /* Incremental time change from previous read */
SENSOR_TIMESTAMP_SMALL_DELTA_WU = 245, /* Incremental time change from previous read wake up */
SENSOR_TIMESTAMP_LARGE_DELTA = 252, /* Incremental time change from previous read */
SENSOR_TIMESTAMP_LARGE_DELTA_WU = 246, /* Incremental time change from previous read wake up */
SENSOR_TIMESTAMP_FULL = 253, /* Incremental time change from previous read */
SENSOR_TIMESTAMP_FULL_WU = 247, /* Incremental time change from previous read wake up */
SENSOR_ALL_ID = 255 /* All Sensor parse event*/
};
#define SENSOR_EULER_ID SENSOR_ID_ORI_WU
#define QUAT_SENSOR_ID SENSOR_ID_RV

View File

@@ -0,0 +1,730 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhi3.c
* @date 2023-03-24
* @version v1.6.0
*
*/
/*********************************************************************/
/* system header files */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*********************************************************************/
/* BHI3 SensorAPI header files */
#include "bhi3.h"
/*************************Private Functions***************************/
/*!
* @brief To set the Physical Sensor Control Parameters
*/
int8_t bhi3_physical_sensor_control_set_config(uint8_t sensor_id,
const uint8_t *payload,
uint16_t len,
uint8_t control_code,
struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint16_t cmnd_len = BHY2_LE24MUL(len + 1); /*1 byte added for control code */
uint8_t cmnd[cmnd_len];
memset(cmnd, 0, cmnd_len);
cmnd[0] = BHI3_PHY_SENSOR_CTRL_CODE(BHI3_PHY_SENSOR_CTRL_WRITE, control_code);
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
if (payload == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
for (int i = 0; i < len; i++)
{
cmnd[i + 1] = *(payload + i);
}
rslt = bhy2_set_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), cmnd, cmnd_len, dev);
}
}
return rslt;
}
/*!
* @brief To get the Physical Sensor Control Parameters
*/
int8_t bhi3_physical_sensor_control_get_config(uint8_t sensor_id,
uint8_t *payload,
uint32_t len,
uint8_t control_code,
struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t ret_len = 0;
uint8_t cmnd[BHY2_COMMAND_HEADER_LEN] = {0};
uint8_t rdbck[BHY2_LE24MUL(len)];
cmnd[0] = BHI3_PHY_SENSOR_CTRL_CODE(BHI3_PHY_SENSOR_CTRL_READ, control_code);
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
rslt = bhy2_set_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), cmnd, BHY2_COMMAND_HEADER_LEN, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
rslt = bhy2_get_parameter(BHI3_PHY_SENSOR_CTRL_PARAM(sensor_id), rdbck, BHY2_LE24MUL(len), &ret_len, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
memcpy(payload, &rdbck[1], len); /*0th element holds control code */
}
return rslt;
}
/**************************Public Functions***************************/
/*!
* @brief To parse Wrist Gesture Detection Data
*/
int8_t bhi3_wrist_gesture_detect_parse_data(const uint8_t *data, bhi3_wrist_gesture_detect_t *output)
{
int8_t rslt = BHY2_OK;
if ((data == NULL) || (output == NULL))
{
rslt = BHY2_E_NULL_PTR;
}
else
{
output->wrist_gesture = (enum bhi3_wrist_gesture_activity) * (data);
}
return rslt;
}
/*!
* @brief To set the Accelerometer Fast Offset Calibration
*/
int8_t bhi3_set_acc_foc(const struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
(uint8_t *)acc_foc,
BHI3_PHY_ACC_FOC_CTRL_LEN,
BHI3_PHY_ACC_FOC_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Accelerometer Fast Offset Calibration
*/
int8_t bhi3_get_acc_foc(struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
(uint8_t *)acc_foc,
BHI3_PHY_ACC_FOC_CTRL_LEN,
BHI3_PHY_ACC_FOC_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Accelerometer Power Mode
*/
int8_t bhi3_set_acc_power_mode(const uint8_t *acc_pwm, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
acc_pwm,
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN,
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Accelerometer Power Mode
*/
int8_t bhi3_get_acc_power_mode(uint8_t *acc_pwm, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_ACCELEROMETER,
acc_pwm,
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN,
BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Gyroscope Fast Offset Calibration
*/
int8_t bhi3_set_gyro_foc(const struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
(uint8_t *)gyro_foc,
BHI3_PHY_GYRO_FOC_CTRL_LEN,
BHI3_PHY_GYRO_FOC_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Gyroscope Fast Offset Calibration
*/
int8_t bhi3_get_gyro_foc(struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
(uint8_t *)gyro_foc,
BHI3_PHY_GYRO_FOC_CTRL_LEN,
BHI3_PHY_GYRO_FOC_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Gyroscope OIS
*/
int8_t bhi3_set_gyro_ois(const uint8_t *gyro_ois, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_ois,
BHI3_PHY_GYRO_OIS_CTRL_LEN,
BHI3_PHY_GYRO_OIS_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Gyroscope OIS
*/
int8_t bhi3_get_gyro_ois(uint8_t *gyro_ois, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_ois,
BHI3_PHY_GYRO_OIS_CTRL_LEN,
BHI3_PHY_GYRO_OIS_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Gyroscope Fast Startup
*/
int8_t bhi3_set_gyro_fast_startup(const uint8_t *gyro_fs, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_fs,
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN,
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Gyroscope Fast Startup
*/
int8_t bhi3_get_gyro_fast_startup(uint8_t *gyro_fs, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_fs,
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN,
BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Gyroscope CRT
*/
int8_t bhi3_set_gyro_crt(const uint8_t *gyro_crt, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_crt,
BHI3_PHY_GYRO_CRT_CTRL_LEN,
BHI3_PHY_GYRO_CRT_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Gyroscope CRT
*/
/*lint -e506, -e778 */
int8_t bhi3_get_gyro_crt(uint8_t *gyro_crt, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt =
bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_crt,
BHY2_LE24MUL(BHI3_PHY_GYRO_CRT_CTRL_LEN),
BHI3_PHY_GYRO_CRT_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Gyroscope Power Mode
*/
int8_t bhi3_set_gyro_power_mode(const uint8_t *gyro_pwm, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_pwm,
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN,
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Gyroscope Power Mode
*/
int8_t bhi3_get_gyro_power_mode(uint8_t *gyro_pwm, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_pwm,
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN,
BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Gyroscope Timer Auto Trim state
*/
int8_t bhi3_set_gyro_timer_auto_trim(const uint8_t *gyro_tat, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_tat,
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN,
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Gyroscope Timer Auto Trim Status
*/
int8_t bhi3_get_gyro_timer_auto_trim(uint8_t *gyro_tat, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_GYROSCOPE,
gyro_tat,
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN,
BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Wrist Wear Wakeup Configuration
*/
int8_t bhi3_set_wrist_wear_wakeup_config(const uint8_t *www_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP,
www_cnfg,
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN,
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Wrist Wear Wakeup Configuration
*/
int8_t bhi3_get_wrist_wear_wakeup_config(uint8_t *www_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP,
www_cnfg,
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN,
BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Any Motion Configuration
*/
int8_t bhi3_set_anymotion_config(const uint8_t *any_motion_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION,
any_motion_cnfg,
BHI3_PHY_ANY_MOTION_CTRL_LEN,
BHI3_PHY_ANY_MOTION_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Any Motion Configuration
*/
int8_t bhi3_get_anymotion_config(uint8_t *any_motion_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION,
any_motion_cnfg,
BHI3_PHY_ANY_MOTION_CTRL_LEN,
BHI3_PHY_ANY_MOTION_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the No Motion Configuration
*/
int8_t bhi3_set_nomotion_config(const uint8_t *no_motion_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION,
no_motion_cnfg,
BHI3_PHY_NO_MOTION_CTRL_LEN,
BHI3_PHY_NO_MOTION_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the No Motion Configuration
*/
int8_t bhi3_get_nomotion_config(uint8_t *no_motion_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the configuration parameter */
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION,
no_motion_cnfg,
BHI3_PHY_NO_MOTION_CTRL_LEN,
BHI3_PHY_NO_MOTION_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To set the Wrist Gesture Detect Configuration
*/
int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the configuration parameter */
rslt = bhi3_physical_sensor_control_set_config(BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT,
wgd_cnfg,
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN,
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE,
dev);
}
return rslt;
}
/*!
* @brief To get the Wrist Gesture Detect Configuration
*/
int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
rslt = bhi3_physical_sensor_control_get_config(BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT,
wgd_cnfg,
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN,
BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE,
dev);
}
return rslt;
}

View File

@@ -0,0 +1,330 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhi3.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHI3_H__
#define __BHI3_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include "bhy2.h"
#include "bhi3_defs.h"
/*!
* @brief To parse Wrist Gesture Detection Data
*
* @param[in] Wrist Gesture Detection Data
* @param[in] Wrist Gesture Detection Output Structure
*
* @return API error codes
*
*/
int8_t bhi3_wrist_gesture_detect_parse_data(const uint8_t *data, bhi3_wrist_gesture_detect_t *output);
/*!
* @brief To set the Accelerometer Fast Offset Calibration
*
* @param[in] Physical Accelerometer FOC data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_acc_foc(const struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev);
/*!
* @brief To get the Accelerometer Fast Offset Calibration
*
* @param[out] Physical Accelerometer FOC data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_acc_foc(struct bhy2_data_xyz *acc_foc, struct bhy2_dev *dev);
/*!
* @brief To set the Accelerometer Power Mode
*
* @param[in] Physical Accelerometer Power Mode data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_acc_power_mode(const uint8_t *acc_pwm, struct bhy2_dev *dev);
/*!
* @brief To get the Accelerometer Power Mode
*
* @param[out] Physical Accelerometer Power Mode data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_acc_power_mode(uint8_t *acc_pwm, struct bhy2_dev *dev);
/*!
* @brief To set the Gyroscope Fast Offset Calibration
*
* @param[in] Physical Gyroscope FOC data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_gyro_foc(const struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev);
/*!
* @brief To get the Gyroscope Fast Offset Calibration
*
* @param[out] Physical Gyroscope FOC data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_gyro_foc(struct bhy2_data_xyz *gyro_foc, struct bhy2_dev *dev);
/*!
* @brief To set the Gyroscope OIS
*
* @param[in] Physical Gyroscope OIS data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_gyro_ois(const uint8_t *gyro_ois, struct bhy2_dev *dev);
/*!
* @brief To get the Gyroscope OIS
*
* @param[out] Physical Gyroscope OIS data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_gyro_ois(uint8_t *gyro_ois, struct bhy2_dev *dev);
/*!
* @brief To set the Gyroscope Fast Startup
*
* @param[in] Physical Gyroscope Fast Startup data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_gyro_fast_startup(const uint8_t *gyro_fs, struct bhy2_dev *dev);
/*!
* @brief To get the Gyroscope Fast Startup
*
* @param[out] Physical Gyroscope Fast Startup data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_gyro_fast_startup(uint8_t *gyro_fs, struct bhy2_dev *dev);
/*!
* @brief To set the Gyroscope CRT
*
* @param[in] Physical Gyroscope CRT data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_gyro_crt(const uint8_t *gyro_crt, struct bhy2_dev *dev);
/*!
* @brief To get the Gyroscope CRT
*
* @param[out] Physical Gyroscope CRT data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_gyro_crt(uint8_t *gyro_crt, struct bhy2_dev *dev);
/*!
* @brief To set the Gyroscope Power Mode
*
* @param[in] Physical Gyroscope Power Mode data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_gyro_power_mode(const uint8_t *gyro_pwm, struct bhy2_dev *dev);
/*!
* @brief To get the Gyroscope Power Mode
*
* @param[out] Physical Gyroscope Power Mode data
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_gyro_power_mode(uint8_t *gyro_pwm, struct bhy2_dev *dev);
/*!
* @brief To set the Gyroscope Timer Auto Trim state
*
* @param[in] Physical Gyroscope Timer Auto Trim state
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_gyro_timer_auto_trim(const uint8_t *gyro_tat, struct bhy2_dev *dev);
/*!
* @brief To get the Gyroscope Timer Auto Trim status
*
* @param[out] Physical Gyroscope Timer Auto Trim state
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_gyro_timer_auto_trim(uint8_t *gyro_tat, struct bhy2_dev *dev);
/*!
* @brief To set the Wrist Wear Wakeup Configuration
*
* @param[in] Wrist Wear Wakeup Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_wrist_wear_wakeup_config(const uint8_t *www_cnfg, struct bhy2_dev *dev);
/*!
* @brief To get the Wrist Wear Wakeup Configuration
*
* @param[out] Wrist Wear Wakeup Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_wrist_wear_wakeup_config(uint8_t *www_cnfg, struct bhy2_dev *dev);
/*!
* @brief To set the Any Motion Configuration
*
* @param[in] Any Motion Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_anymotion_config(const uint8_t *any_motion_cnfg, struct bhy2_dev *dev);
/*!
* @brief To get the Any Motion Configuration
*
* @param[out] Any Motion Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_anymotion_config(uint8_t *any_motion_cnfg, struct bhy2_dev *dev);
/*!
* @brief To set the No Motion Configuration
*
* @param[in] No Motion Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_nomotion_config(const uint8_t *no_motion_cnfg, struct bhy2_dev *dev);
/*!
* @brief To get the No Motion Configuration
*
* @param[out] No Motion Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_nomotion_config(uint8_t *no_motion_cnfg, struct bhy2_dev *dev);
/*!
* @brief To set the Wrist Gesture Detection Configuration
*
* @param[in] Wrist Gesture Detection Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_set_wrist_gesture_detect_config(const uint8_t *wgd_cnfg, struct bhy2_dev *dev);
/*!
* @brief To get the Wrist Gesture Detection Configuration
*
* @param[out] Wrist Gesture Detection Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhi3_get_wrist_gesture_detect_config(uint8_t *wgd_cnfg, struct bhy2_dev *dev);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHI3_H__ */

View File

@@ -0,0 +1,204 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhi3_defs.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHI3_DEFS_H__
#define __BHI3_DEFS_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include "bhy2_defs.h"
/*! The Product ID needs to be replaced with Chip ID for explicit HW specific Identification*/
#define BHI3_PRODUCT_ID BHY2_PRODUCT_ID
/*! Firmware header identifier */
/*#define BHY2_FW_MAGIC UINT16_C(0x662B) */
/*! BHI3 Variant IDs */
#define BHI3_VARIANT_ID_BHI360 UINT32_C(0x18BC5434)
#define BHI3_VARIANT_ID_BHI380 UINT32_C(0x6E6D6CA6)
/*! BHI3 Specifc Sensor IDs */
#define BHI3_SENSOR_ID_AR_WEAR_WU UINT8_C(154) /* Activity Recognition (wear/hear) */
#define BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU UINT8_C(156) /* Wrist Gesture Detector Low Power Wakeup*/
#define BHI3_SENSOR_ID_WRIST_WEAR_LP_WU UINT8_C(158) /* Wrist Wear Low Power Wakeup */
#define BHI3_SENSOR_ID_NO_MOTION_LP_WU UINT8_C(159) /* No motion Low Power */
/*! Physical Sensor Control Parameter Page Base Address*/
#define BHI3_PHY_SENSOR_CTRL_PAGE UINT16_C(0x0E)
/*! Physical Sensor Control pages
* Here the 'id' refers to the Sensor ID of requisite Physical Sensors (Acc/Gyro)
* */
#define BHI3_PHY_SENSOR_CTRL_PARAM(id) (((BHI3_PHY_SENSOR_CTRL_PAGE) << 8) | (id))
#define BHI3_PHY_SENSOR_CTRL_CODE(dir, code) ((dir << 7) | (code))
#define BHI3_PHY_SENSOR_CTRL_WRITE UINT8_C(0x00)
#define BHI3_PHY_SENSOR_CTRL_READ UINT8_C(0x01)
#define BHI3_PHY_ACC_FOC_CTRL_CODE UINT8_C(0x01)
#define BHI3_PHY_ACC_FOC_CTRL_LEN 6
#define BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_CODE UINT8_C(0x05)
#define BHI3_PHY_ACC_NORMAL_POWER_MODE UINT8_C(0x00)
#define BHI3_PHY_ACC_LOW_POWER_MODE UINT8_C(0x02)
#define BHI3_PHY_ACC_LOW_POWER_MODE_CTRL_LEN 1
#define BHI3_PHY_GYRO_FOC_CTRL_CODE UINT8_C(0x01)
#define BHI3_PHY_GYRO_FOC_CTRL_LEN 6
#define BHI3_PHY_GYRO_OIS_CTRL_CODE UINT8_C(0x02)
#define BHI3_PHY_GYRO_DISABLE_OIS UINT8_C(0x00)
#define BHI3_PHY_GYRO_ENABLE_OIS UINT8_C(0x01)
#define BHI3_PHY_GYRO_OIS_CTRL_LEN 1
#define BHI3_PHY_GYRO_FAST_STARTUP_CTRL_CODE UINT8_C(0x03)
#define BHI3_PHY_GYRO_DISABLE_FAST_STARTUP UINT8_C(0x00)
#define BHI3_PHY_GYRO_ENABLE_FAST_STARTUP UINT8_C(0x01)
#define BHI3_PHY_GYRO_FAST_STARTUP_CTRL_LEN 1
#define BHI3_PHY_GYRO_CRT_CTRL_CODE UINT8_C(0x04)
#define BHI3_PHY_GYRO_CRT_STATUS_SUCCESS UINT8_C(0x00)
#define BHI3_PHY_GYRO_ENABLE_CRT UINT8_C(0x01)
#define BHI3_PHY_GYRO_CRT_CTRL_LEN 1
#define BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_CODE UINT8_C(0x05)
#define BHI3_PHY_GYRO_NORMAL_POWER_MODE UINT8_C(0x00)
#define BHI3_PHY_GYRO_PERFORMANCE_POWER_MODE UINT8_C(0x01)
#define BHI3_PHY_GYRO_LOW_POWER_MODE UINT8_C(0x02)
#define BHI3_PHY_GYRO_LOW_POWER_MODE_CTRL_LEN 1
#define BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_CODE UINT8_C(0x06)
#define BHI3_PHY_GYRO_DISABLE_TIMER_AUTO_TRIM UINT8_C(0x00)
#define BHI3_PHY_GYRO_ENABLE_TIMER_AUTO_TRIM UINT8_C(0x01)
#define BHI3_PHY_GYRO_TIMER_AUTO_TRIM_CTRL_LEN 1
#define BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_CODE UINT8_C(0x01)
#define BHI3_PHY_WRIST_WEAR_WAKEUP_CTRL_LEN 10
#define BHI3_PHY_ANY_MOTION_CTRL_CODE UINT8_C(0x01)
#define BHI3_PHY_ANY_MOTION_CTRL_LEN 4
#define BHI3_PHY_NO_MOTION_CTRL_CODE UINT8_C(0x01)
#define BHI3_PHY_NO_MOTION_CTRL_LEN 4
#define BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_CODE UINT8_C(0x07)
#define BHI3_PHY_WRIST_GESTURE_DETECT_CTRL_LEN 19
typedef struct bhi3_wrist_wear_wakeup_config_param {
uint16_t min_angle_focus;
uint16_t min_angle_nonfocus;
uint8_t angle_landscape_right;
uint8_t angle_landscape_left;
uint8_t angle_portrait_down;
uint8_t angle_portrait_up;
uint8_t min_dur_moved;
uint8_t min_dur_quite;
} __attribute__ ((packed)) bhi3_wrist_wear_wakeup_config_param_t;
typedef struct bhi3_any_no_motion_config_param {
uint16_t duration;
uint8_t axis;
uint16_t threshold;
} __attribute__ ((packed)) bhi3_any_no_motion_config_param_t;
typedef struct bhi3_wrist_gesture_detect_config_param {
uint16_t min_flick_peak_y_threshold;
uint16_t min_flick_peak_z_threshold;
uint16_t gravity_bounds_x_pos;
uint16_t gravity_bounds_x_neg;
uint16_t gravity_bounds_y_neg;
uint16_t gravity_bounds_z_neg;
uint16_t flick_peak_decay_coeff;
uint16_t lp_mean_filter_coeff;
uint16_t max_duration_jiggle_peaks;
uint8_t device_position;
} __attribute__ ((packed)) bhi3_wrist_gesture_detect_config_param_t;
enum bhi3_wrist_gesture_activity {
NO_GESTURE,
WRIST_SHAKE_JIGGLE = 0x03,
FLICK_IN,
FLICK_OUT
};
typedef struct bhi3_wrist_gesture_detect {
enum bhi3_wrist_gesture_activity wrist_gesture;
} __attribute__ ((packed)) bhi3_wrist_gesture_detect_t;
static const char *const bhi3_wrist_gesture_detect_output[] = {
[NO_GESTURE] = "NO_GESTURE",
[1] = "",
[2] = "",
[WRIST_SHAKE_JIGGLE] = "WRIST_SHAKE_JIGGLE",
[FLICK_IN] = "FLICK_IN",
[FLICK_OUT] = "FLICK_OUT"
}; /*lint -e528 */
enum bhi3_phy_sensor_acc_power_mode {
ACC_NORMAL,
ACC_LOW_POWER = 0x02
};
enum bhi3_phy_sensor_gyro_power_mode {
GYRO_NORMAL,
GYRO_PERFORMANCE,
GYRO_LOW_POWER
};
static const char *const bhi3_phy_sensor_acc_pwm_output[] = {
[ACC_NORMAL] = "NORMAL",
[1] = "",
[ACC_LOW_POWER] = "LOW POWER"
}; /*lint -e528 */
static const char *const bhi3_phy_sensor_gyro_pwm_output[] = {
[GYRO_NORMAL] = "NORMAL",
[GYRO_PERFORMANCE] = "PERFORMANCE",
[GYRO_LOW_POWER] = "LOW POWER"
}; /*lint -e528 */
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHI3_DEFS_H__ */

View File

@@ -0,0 +1,211 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhi3_multi_tap.c
* @date 2023-03-24
* @version v1.6.0
*
*/
/*********************************************************************/
/* system header files */
/*********************************************************************/
#include <string.h>
#include <stdio.h>
/*********************************************************************/
/* BHI3 SensorAPI header files */
/*********************************************************************/
#include "bhi3.h"
/*********************************************************************/
/* own header files */
/*********************************************************************/
#include "bhi3_multi_tap.h"
/*lint -e506, -e778*/
/*!
* @brief This API writes to the configuration parameter
*
* @param[in] buffer to store Multi Tap configuration
* @param[out] dev hub handle.
*
* @return rslt execution result.
*/
int8_t bhi3_multi_tap_set_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the Multi Tap configuration parameter */
rslt = bhy2_set_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_ENABLE_PARAM),
(uint8_t*)buffer,
BHI3_MULTI_TAP_ENABLE_LENGTH,
dev);
}
return rslt;
}
/*!
* @brief To get the MULTI-TAP configuration parameters
*
* @param[out] buffer to store Multi Tap configuration
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhi3_multi_tap_get_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t ret_length;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the Multi Tap configuration from the parameter page*/
rslt =
bhy2_get_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_ENABLE_PARAM),
(uint8_t *)buffer,
BHY2_LE24MUL(BHI3_MULTI_TAP_ENABLE_LENGTH),
&ret_length,
dev);
if (rslt != BHY2_OK)
{
/*! Invalid number of parameters readout */
rslt = BHY2_E_INVALID_EVENT_SIZE;
}
}
return rslt;
}
/*!
* @brief This API writes to the tap detector configuration parameter
*
* @param[in] buffer to store Multi Tap Detector configuration
* @param[out] dev hub handle.
*
* @return rslt execution result.
*/
int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the Multi Tap configuration parameter */
rslt = bhy2_set_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM),
(uint8_t*)buffer,
BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH,
dev);
}
return rslt;
}
/*!
* @brief To get the MULTI-TAP Detector configuration parameters
*
* @param[out] buffer to store Multi Tap Detector configuration
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t ret_length;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the Multi Tap configuration from the parameter page*/
rslt = bhy2_get_parameter(BHI3_MULTI_TAP_PARAM(BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM),
(uint8_t *)buffer,
BHY2_LE24MUL(BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH),
&ret_length,
dev);
if (rslt != BHY2_OK)
{
/*! Invalid number of parameters readout */
rslt = BHY2_E_INVALID_EVENT_SIZE;
}
}
return rslt;
}
/*!
* @brief Parsing the fifo data to Multi Tap output format
*
* @param[in] Multi Tap data
* @param[out] buffer to store parameter data
*
* @return API error codes
*
*/
int8_t bhi3_multi_tap_parse_data(const uint8_t *data, uint8_t* output)
{
int8_t rslt = BHY2_OK;
if ((data == NULL) || (output == NULL))
{
rslt = BHY2_E_NULL_PTR;
}
else
{
*output = *data;
}
return rslt;
}

View File

@@ -0,0 +1,111 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhi3_multi_tap.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHY2_MULTI_TAP_H_
#define _BHY2_MULTI_TAP_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <stdlib.h>
#include "bhi3.h"
#include "bhi3_multi_tap_defs.h"
/*!
* @brief Parsing the fifo data to MULTI_TAP output structure format
*
* @param[in] Multi Tap data
* @param[out] buffer to store parameter data
*
* @return API error codes
*
*/
int8_t bhi3_multi_tap_parse_data(const uint8_t *data, uint8_t *output);
/*!
* @brief To set the MULTI_TAP configuration parameters
* @param[out] buffer to store parameter data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhi3_multi_tap_set_config(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the MULTI_TAP configuration parameters
*
* @param[out] buffer to store parameter data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhi3_multi_tap_get_config(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the MULTI_TAP Detector configuration parameters
* @param[out] buffer to store parameter data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhi3_multi_tap_detector_set_config(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the MULTI_TAP Detector configuration parameters
*
* @param[out] buffer to store parameter data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhi3_multi_tap_detector_get_config(const void *buffer, struct bhy2_dev *dev);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHY2_MULTI_TAP_H_ */

View File

@@ -0,0 +1,189 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhi3_multi_tap_defs.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHI3_MULTI_TAP_DEFS_H_
#define _BHI3_MULTI_TAP_DEFS_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <string.h>
/*! Sensor ID for Multi-Tap */
#define BHI3_SENSOR_ID_MULTI_TAP UINT8_C(153)
/*! Multi-Tap Parameter Page Base Address*/
#define BHI3_MULTI_TAP_PAGE UINT16_C(0x0D)
/*! Multi-Tap Configuration pages */
#define BHI3_MULTI_TAP_ENABLE_PARAM 0x01
#define BHI3_MULTI_TAP_DETECTOR_CONFIG_PARAM 0x02
#define BHI3_MULTI_TAP_PARAM(id) (((BHI3_MULTI_TAP_PAGE) << 8) | (id))
#define BHI3_MULTI_TAP_ENABLE_LENGTH UINT8_C(4)
#define BHI3_MULTI_TAP_DETECTOR_CONFIG_LENGTH UINT8_C(6)
#define BHI3_MULTI_TAP_AXIS_SEL_X UINT8_C(0)
#define BHI3_MULTI_TAP_AXIS_SEL_Y UINT8_C(1)
#define BHI3_MULTI_TAP_AXIS_SEL_Z UINT8_C(2)
#define BHI3_MULTI_TAP_WAIT_TIMEOUT_DISABLE UINT8_C(0)
#define BHI3_MULTI_TAP_WAIT_TIMEOUT_ENABLE UINT8_C(1)
#define BHI3_MULTI_TAP_FILTER_MODE_SENSITIVE UINT8_C(0)
#define BHI3_MULTI_TAP_FILTER_MODE_NORMAL UINT8_C(1)
#define BHI3_MULTI_TAP_FILTER_MODE_ROBUST UINT8_C(2)
#define BHI3_SINGLE_TAP_AXIS_SEL_MASK 0x03
#define BHI3_SINGLE_TAP_WAIT_TIMEOUT_MASK 0x04
#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_MASK 0x38
#define BHI3_SINGLE_TAP_FILTER_MODE_MASK 0xC0
#define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_MASK 0x03FF
#define BHI3_DOUBLE_TAP_MAX_GES_DUR_MASK 0xFC00
#define BHI3_TRIPLE_TAP_MAX_DUR_BW_PEAKS_MASK 0x0F
#define BHI3_TRIPLE_TAP_TAP_SHOCK_SETL_DUR_MASK 0xF0
#define BHI3_TRIPLE_TAP_MIN_QT_DUR_BW_PEAKS_MASK 0x0F
#define BHI3_TRIPLE_TAP_QT_TM_AFTER_GESTURE_MASK 0xF0
#define BHI3_SINGLE_TAP_AXIS_SEL_SHIFT UINT8_C(0)
#define BHI3_SINGLE_TAP_WAIT_TIMEOUT_SHIFT UINT8_C(2)
#define BHI3_SINGLE_TAP_MAX_PEAKS_FOR_TAP_SHIFT UINT8_C(3)
#define BHI3_SINGLE_TAP_FILTER_MODE_SHIFT UINT8_C(6)
#define BHI3_DOUBLE_TAP_TAP_PEAK_DUR_SHIFT UINT8_C(0)
#define BHI3_DOUBLE_TAP_MAX_GES_DUR_SHIFT UINT8_C(10)
#define BHI3_TRIPLE_TAP_MAX_DUR_BW_PEAKS_SHIFT UINT8_C(0)
#define BHI3_TRIPLE_TAP_TAP_SHOCK_SETL_DUR_SHIFT UINT8_C(4)
#define BHI3_TRIPLE_TAP_MIN_QT_DUR_BW_PEAKS_SHIFT UINT8_C(0)
#define BHI3_TRIPLE_TAP_QT_TM_AFTER_GESTURE_SHIFT UINT8_C(4)
/*!
* Single Tap Configuration.
*/
typedef union bhi3_singletap_detector_settings
{
uint16_t as_uint16;
struct
{
uint16_t axis_sel : 2; /* Tap axis selection */
uint16_t wait_for_timeout : 1; /* Wait for gesture confirmation */
uint16_t max_peaks_for_tap : 3; /* Maximum number of peaks that can occur when a tap is done
* */
uint16_t mode : 2; /* Filter configuration for various detection mode: SENSITIVE, NORMAL and
* ROBUST */
uint16_t reserved8 : 8;
} as_s;
} __attribute__ ((packed)) bhi3_singletap_detector_settings_t;
/*!
* Double Tap Configuration.
*/
typedef union bhi3_doubletap_detector_settings
{
uint16_t as_uint16;
struct
{
uint16_t tap_peak_thres : 10; /* Minimum threshold for peak detection */
uint16_t max_gesture_dur : 6; /* Maximum time duration from first tap within which matching
* tap/s should happen to be detected as double/triple tap */
} as_s;
} __attribute__ ((packed)) bhi3_doubletap_detector_settings_t;
/*!
* Triple Tap Configuration.
*/
typedef union bhi3_tripletap_detector_settings
{
uint16_t as_uint16;
struct
{
uint16_t max_dur_between_peaks : 4; /* Maximum time duration within which matching peaks of tap
* should occur */
uint16_t tap_shock_settling_dur : 4; /* Maximum duration to wait for tap shock settling */
uint16_t min_quite_dur_between_taps : 4; /* Minimum quite time between detection of consecutive taps
* of double/triple taps*/
uint16_t quite_time_after_gesture : 4; /* Minimum quite time between detection of 2 consecutive
* selected gesture */
} as_s;
} __attribute__ ((packed)) bhi3_tripletap_detector_settings_t;
/*!
* Multi Tap Configuration.
*/
typedef struct bhi3_multi_tap_detector
{
bhi3_singletap_detector_settings_t stap_setting;
bhi3_doubletap_detector_settings_t dtap_setting;
bhi3_tripletap_detector_settings_t ttap_setting;
} __attribute__ ((packed)) bhi3_multi_tap_detector_t;
/*!
* Multi Tap Setting.
*/
enum bhi3_multi_tap_val {
NO_TAP,
SINGLE_TAP,
DOUBLE_TAP,
DOUBLE_SINGLE_TAP,
TRIPLE_TAP,
TRIPLE_SINGLE_TAP,
TRIPLE_DOUBLE_TAP,
TRIPLE_DOUBLE_SINGLE_TAP
};
/*!
* Multi Tap Output.
*/
static const char * const bhi3_multi_tap_string_out[] = {
[NO_TAP] = "NO_TAP", [SINGLE_TAP] = "SINGLE_TAP", [DOUBLE_TAP] = "DOUBLE_TAP",
[DOUBLE_SINGLE_TAP] = "DOUBLE_SINGLE_TAP", [TRIPLE_TAP] = "TRIPLE_TAP", [TRIPLE_SINGLE_TAP] = "TRIPLE_SINGLE_TAP",
[TRIPLE_DOUBLE_TAP] = "TRIPLE_DOUBLE_TAP", [TRIPLE_DOUBLE_SINGLE_TAP] = "TRIPLE_DOUBLE_SINGLE_TAP"
}; /*lint -e528 */
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHI3_MULTI_TAP_DEFS_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,664 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHY2_H__
#define __BHY2_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include "bhy2_defs.h"
/**
* @brief Function to link the callback interfaces
* @param[in] intf : Physical communication interface
* @param[in] read : Read function pointer
* @param[in] write : Write function pointer
* @param[in] delay_us : Microsecond delay function pointer
* @param[in] read_write_len : Maximum read/write lengths supported
* @param[in] intf_ptr : Reference to the interface. Can be NULL
* @param[out] dev : Device reference
* @return API error codes
*/
int8_t bhy2_init(enum bhy2_intf intf,
bhy2_read_fptr_t read,
bhy2_write_fptr_t write,
bhy2_delay_us_fptr_t delay_us,
uint32_t read_write_len,
void *intf_ptr,
struct bhy2_dev *dev);
/**
* @brief Function to get data from registers
* @param[in] reg_addr : Register address to be read from
* @param[out] reg_data : Reference to the data buffer
* @param[in] length : Length of the data buffer
* @param[in] dev : Device reference
* @return API Error codes
*/
int8_t bhy2_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev);
/**
* @brief Function to set data to registers
* @param[in] reg_addr : Register address to write to
* @param[in] reg_data : Reference to the data buffer
* @param[in] length : Length of the data buffer
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint16_t length, struct bhy2_dev *dev);
/**
* @brief Function to get the product ID
* @param[out] product_id : Reference to data buffer to store the product ID
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_product_id(uint8_t *product_id, struct bhy2_dev *dev);
/**
* @brief Function to get the chip ID
* @param[out] chip_id : Reference to data buffer to store the chip ID
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_chip_id(uint8_t *chip_id, struct bhy2_dev *dev);
/**
* @brief Function to get the revision ID
* @param[out] revision_id : Reference to data buffer to store the revision ID
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_revision_id(uint8_t *revision_id, struct bhy2_dev *dev);
/**
* @brief Function to get the ROM version
* @param[out] rom_version : Reference to the data buffer to store the ROM version
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_rom_version(uint16_t *rom_version, struct bhy2_dev *dev);
/**
* @brief Function to get the kernel version
* @param[out] kernel_version : Reference to the data buffer to store the kernel version
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_kernel_version(uint16_t *kernel_version, struct bhy2_dev *dev);
/**
* @brief Function to get the user version
* @param[out] user_version : Reference to the data buffer to store the user version
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_user_version(uint16_t *user_version, struct bhy2_dev *dev);
/**
* @brief Function to get the boot status
* @param[out] boot_status : Reference to the data buffer to store the boot status
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_boot_status(uint8_t *boot_status, struct bhy2_dev *dev);
/**
* @brief Function to get the host status
* @param[out] host_status : Reference to the data buffer to store the host status
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_host_status(uint8_t *host_status, struct bhy2_dev *dev);
/**
* @brief Function to get the feature status
* @param[out] feat_status : Reference to the data buffer to store the feature status
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_feature_status(uint8_t *feat_status, struct bhy2_dev *dev);
/**
* @brief Function to get the virtual sensor list and store in the device structure
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_virt_sensor_list(struct bhy2_dev *dev);
/**
* @brief Function to get the virtual sensor configuration
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[out] virt_sensor_conf : Reference to the data buffer to store the virtual sensor configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_virt_sensor_cfg(uint8_t sensor_id, struct bhy2_virt_sensor_conf *virt_sensor_conf,
struct bhy2_dev *dev);
/**
* @brief Function to set the sample rate and latency of the virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] sample_rate : Sample rate in Hz
* @param[in] latency : Report latency in milliseconds
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_virt_sensor_cfg(uint8_t sensor_id, bhy2_float sample_rate, uint32_t latency, struct bhy2_dev *dev);
/**
* @brief Function set the range of the virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] range : Range of the virtual sensor
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_virt_sensor_range(uint8_t sensor_id, uint16_t range, struct bhy2_dev *dev);
/**
* @brief Function to get and process the FIFOs
* @param[in] work_buffer : Reference to the data buffer where the FIFO data is copied to before parsing
* @param[in] buffer_size : Size of the data buffer
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_and_process_fifo(uint8_t *work_buffer, uint32_t buffer_size, struct bhy2_dev *dev);
/**
* @brief Function get the FIFO control register
* @param[out] fifo_ctrl : Reference to the data buffer to store the FIFO control
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_fifo_ctrl(uint32_t *fifo_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to set the Wake up FIFO watermark
* @param[in] watermark : Size of the watermark
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_fifo_wmark_wkup(uint32_t watermark, struct bhy2_dev *dev);
/**
* @brief Function to get the Wake up FIFO watermark
* @param[out] watermark : Reference to the data buffer to store the FIFO watermark size
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_fifo_wmark_wkup(uint32_t *watermark, struct bhy2_dev *dev);
/**
* @brief Function to set the Non wake up FIFO watermark
* @param[in] watermark : Size of the watermark
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_fifo_wmark_nonwkup(uint32_t watermark, struct bhy2_dev *dev);
/**
* @brief Function to get the Non wake up FIFO watermark
* @param[out] watermark : Reference to the data buffer to store the FIFO watermark size
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_fifo_wmark_nonwkup(uint32_t *watermark, struct bhy2_dev *dev);
/**
* @brief Function to flush data of a virtual sensor from the FIFOs
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_flush_fifo(uint8_t sensor_id, struct bhy2_dev *dev);
/**
* @brief Function to set the FIFO format
* @param[in] param : FIFO format settings
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_fifo_format_ctrl(uint8_t param, struct bhy2_dev *dev);
/**
* @brief Function to upload firmware to RAM
* @param[in] firmware : Reference to the data buffer containing the firmware
* @param[in] length : Size of the firmware
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev);
/**
* @brief Function to upload part of the firmware to RAM
* @param[in] firmware : Reference to the data buffer containing the current firmware section
* @param[in] total_size : Total size of the firmware
* @param[in] cur_pos : Current position of the part being loaded
* @param[in] packet_len : Size of the part being loaded
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_upload_firmware_to_ram_partly(const uint8_t *firmware,
uint32_t total_size,
uint32_t cur_pos,
uint32_t packet_len,
struct bhy2_dev *dev);
/**
* @brief Function to boot firmware from RAM
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_boot_from_ram(struct bhy2_dev *dev);
/**
* @brief Function to erase the flash
* @param[in] start_addr : Start address
* @param[in] end_addr : End address
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_erase_flash(uint32_t start_address, uint32_t end_addr, struct bhy2_dev *dev);
/**
* @brief Function to upload firmware to Flash
* @param[in] firmware : Reference to the data buffer containing the firmware
* @param[in] length : Size of the firwmare
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_upload_firmware_to_flash(const uint8_t *firmware, uint32_t length, struct bhy2_dev *dev);
/**
* @brief Function to upload part of the firmware to Flash
* @param[in] firmware : Reference to the data buffer containing the current firmware section
* @param[in] cur_pos : Current position of the part being loaded
* @param[in] packet_len : Size of the part being loaded
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_upload_firmware_to_flash_partly(const uint8_t *firmware,
uint32_t cur_pos,
uint32_t packet_len,
struct bhy2_dev *dev);
/**
* @brief Function to boot from Flash
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_boot_from_flash(struct bhy2_dev *dev);
/**
* @brief Function to set the host interrupt control register
* @param[in] hintr_ctrl : Host interrupt control configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_host_interrupt_ctrl(uint8_t hintr_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to get the host interrupt control register
* @param[out] hintr_ctrl : Reference to the data buffer to store the configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_host_interrupt_ctrl(uint8_t *hintr_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to get the interrupt status register
* @param[out] int_status : Reference to the data buffer to store the interrupt status
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_interrupt_status(uint8_t *int_status, struct bhy2_dev *dev);
/**
* @brief Function to set the host interface control register
* @param[in] hintf_ctrl : Host interface control configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_host_intf_ctrl(uint8_t hintf_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to get the host interface control register
* @param[out] hintf_ctrl : Reference to the data buffer to store the configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_host_intf_ctrl(uint8_t *hintf_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to trigger a timestamp event
* @param[in] ts_ev_req : Pass a non-zero value to trigger a timestamp event
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_timestamp_event_req(uint8_t ts_ev_req, struct bhy2_dev *dev);
/**
* @brief Function to get the timestamp of the sensor in nanoseconds
* @param[out] timestamp_ns : Reference to the data buffer to store the timestamp in nanoseconds
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_hw_timestamp_ns(uint64_t *timestamp_ns, struct bhy2_dev *dev);
/**
* @brief Function to get the host control register
* @param[in] host_ctrl : Host control configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_host_ctrl(uint8_t host_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to get the host control register
* @param[out] host_ctrl : Reference to the data buffer to store the host control configuration
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_host_ctrl(uint8_t *host_ctrl, struct bhy2_dev *dev);
/**
* @brief Function to trigger a soft reset
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_soft_reset(struct bhy2_dev *dev);
/**
* @brief Function to perform a self test of a virtual sensor
* @param[in] phys_sensor_id : Physical sensor ID of the virtual sensor
* @param[out] self_test_resp : Reference to the data buffer to store the self test response from the virtual sensor
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_perform_self_test(uint8_t phys_sensor_id, struct bhy2_self_test_resp *self_test_resp, struct bhy2_dev *dev);
/**
* @brief Function to perform a fast offset compensation of a virtual sensor
* @param[in] phys_sensor_id : Physical Sensor ID of the virtual sensor
* @param[out] self_test_resp : Reference to the data buffer to store the FOC response from the virtual sensor
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_perform_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_dev *dev);
/**
* @brief Function to set the orientation matrix of a physical sensor
* @param[in] phys_sensor_id : Sensor ID of the virtual sensor
* @param[in] orient_matrix : Orientation matrix
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_orientation_matrix(uint8_t phys_sensor_id, struct bhy2_orient_matrix orient_matrix,
struct bhy2_dev *dev);
/**
* @brief Function to get the physical sensor information
* @param[in] phys_sensor_id : Sensor ID of the physical sensor
* @param[out] phy_sen_info : Reference to the data buffer to the store the physical sensor information
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_phys_sensor_info(uint8_t phys_sensor_id,
struct bhy2_phys_sensor_info *phy_sen_info,
struct bhy2_dev *dev);
/**
* @brief Function to get the orientation matrix of a physical sensor
* @param[in] phys_sensor_id : Sensor ID of the virtual sensor
* @param[out] orient_matrix : Reference to the data buffer to the store the orientation matrix
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_orientation_matrix(uint8_t phys_sensor_id,
struct bhy2_orient_matrix *orient_matrix,
struct bhy2_dev *dev);
/**
* @brief Function to set the Soft Iron Correction matrix
* @param[in] sic_matrix : Reference to the data buffer storing the Soft Iron Correction matrix
* @param[in] matrix_len : Length of the matrix
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_sic_matrix(const uint8_t *sic_matrix, uint16_t matrix_len, struct bhy2_dev *dev);
/**
* @brief Function to get the Soft Iron Correction matrix
* @param[out] sic_matrix : Reference to the data buffer to store the Soft Iron Correction matrix
* @param[in] matrix_len : Length of data buffer
* @param[out] actual_len : Actual length of the Soft Iron Correction matrix
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_sic_matrix(uint8_t *sic_matrix, uint16_t matrix_len, uint32_t *actual_len, struct bhy2_dev *dev);
/**
* @brief Function to get the calibration profile of a BSX virtual sensor
* @param[in] phys_sensor_id: Physical Sensor ID of the virtual sensor
* @param[out] calib_prof : Reference to the data buffer to store the calibration profile
* @param[in] prof_len : Length of the data buffer
* @param[out] actual_len : Actual length of the calibration profile
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_calibration_profile(uint8_t phys_sensor_id,
uint8_t *calib_prof,
uint16_t prof_len,
uint32_t *actual_len,
struct bhy2_dev *dev);
/**
* @brief Function to set the calibration profile of a BSX virtual sensor
* @param[in] phys_sensor_id: Physical Sensor ID of the virtual sensor
* @param[in] calib_prof : Reference to the data buffer storing the calibration profile
* @param[in] prof_len : Length of the profil
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_calibration_profile(uint8_t phys_sensor_idv,
const uint8_t *calib_prof,
uint16_t prof_len,
struct bhy2_dev *dev);
/**
* @brief Function to get the post mortem data
* @param[out] post_mortem : Reference to the data buffer to store the post mortem data
* @param[in] buffer_len : Length of the data buffer
* @param[out] actual_len : Actual length of the post mortem data
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_post_mortem_data(uint8_t *post_mortem, uint32_t buffer_len, uint32_t *actual_len, struct bhy2_dev *dev);
/**
* @brief Function to link a callback and relevant reference when the sensor event is available in the FIFO
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] callback : Reference of the callback function
* @param[in] callback_ref : Reference needed inside the callback function. Can be NULL
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_register_fifo_parse_callback(uint8_t sensor_id,
bhy2_fifo_parse_callback_t callback,
void *callback_ref,
struct bhy2_dev *dev);
/**
* @brief Function to unlink a callback and relevant reference
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_deregister_fifo_parse_callback(uint8_t sensor_id, struct bhy2_dev *dev);
/**
* @brief Function to update the callback table's information
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_update_virtual_sensor_list(struct bhy2_dev *dev);
/**
* @brief Function to get information of a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[out] info : Reference to the data buffer to store the virtual sensor information
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_dev *dev);
/**
* @brief Function to set a parameter
* @param[in] param : Parameter ID
* @param[in] payload : Reference to the data buffer storing the parameter's payload
* @param[in] length : Length of the payload
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_dev *dev);
/**
* @brief Function to get a parameter
* @param[in] param : Parameter ID
* @param[out] payload : Reference to the data buffer to store the parameter's payload
* @param[in] payload_len : Length of the data buffer
* @param[out] actual_len : Actual length of the payload
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_parameter(uint16_t param,
uint8_t *payload,
uint32_t payload_len,
uint32_t *actual_len,
struct bhy2_dev *dev);
/**
* @brief Function to get the error value register
* @param[out] error_value : Reference to the data buffer to store the error value
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_get_error_value(uint8_t *error_value, struct bhy2_dev *dev);
/**
* @brief Function to directly communicate with the sensor
* @param[in] conf : The configuration of the transfer
* @param[in] reg_addr : Register address to write to
* @param[in] length : Length of the data buffer to be transferred
* @param[in/out] reg_data : Reference to the data buffer
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_soft_passthrough_transfer(union bhy2_soft_passthrough_conf *conf,
uint8_t reg_addr,
uint8_t length,
uint8_t *reg_data,
struct bhy2_dev *dev);
/**
* @brief Function to check if a virtual sensor is available
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] dev : Device reference
* @return 1 if the sensor is available. 0 otherwise
*/
uint8_t bhy2_is_sensor_available(uint8_t sensor_id, const struct bhy2_dev *dev);
/**
* @brief Function to get the BHy260 variant ID
*
* @param[in] variant_id : Reference to store the variant ID
* @param[in] dev : Device reference
* @return int8_t API error codes
*/
int8_t bhy2_get_variant_id(uint32_t *variant_id, struct bhy2_dev *dev);
/**
* @brief Function to inject data
* @param[in] payload : Reference to the data buffer
* @param[in] payload_len : Length of the data buffer
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_dev *dev);
/**
* @brief Function to set inject mode
* @param[in] mode : Type of data inject mode
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_set_data_injection_mode(enum bhy2_data_inj_mode mode, struct bhy2_dev *dev);
/**
* @brief Function to clear the FIFO
* @param[in] flush_cfg : Type of FIFO Flush
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_clear_fifo(uint8_t flush_cfg, struct bhy2_dev *dev);
/**
* @brief Function to read the status FIFO
* @param[out] status_code : Status Code
* @param[in] status_buff : Buffer for reading Status Response
* @param[in] status_len : Length of the Response
* @param[out] actual_len : Length of Data read
* @param[in] dev : Device reference
* @return API error codes
*/
int8_t bhy2_read_status(uint16_t *status_code,
uint8_t *status_buff,
uint32_t status_len,
uint32_t *actual_len,
struct bhy2_dev *dev);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHY2_H__ */

View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_bsec.c
* @date 2023-03-24
* @version v1.6.0
*
*/
/*********************************************************************/
/* system header files */
/*********************************************************************/
#include <string.h>
#include <stdlib.h>
/*********************************************************************/
/* BHY2 SensorAPI header files */
/*********************************************************************/
#include "bhy2.h"
/*********************************************************************/
/* own header files */
/*********************************************************************/
#include "bhy2_bsec.h"
void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data)
{
uint8_t i = 0;
if ((payload != NULL) && (data != NULL))
{
data->comp_temp = BHY2_LE2U32(payload + i);
i += 4;
data->comp_hum = BHY2_LE2U32(payload + i);
i += 4;
data->comp_gas = BHY2_LE2U32(payload + i);
i += 4;
data->iaq = BHY2_LE2U32(payload + i);
i += 4;
data->static_iaq = BHY2_LE2U32(payload + i);
i += 4;
data->e_co2 = BHY2_LE2U32(payload + i);
i += 4;
data->voc = BHY2_LE2U32(payload + i);
i += 4;
data->iaq_accuracy = payload[i];
}
}

View File

@@ -0,0 +1,74 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_bsec.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHY2_BSEC_H_
#define _BHY2_BSEC_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <stdlib.h>
#include <stdlib.h>
#include "bhy2.h"
#define BHY2_SENSOR_ID_AIR_QUALITY UINT8_C(115)
struct bhy2_bsec_air_quality
{
float comp_temp; /* Sensor heat compensated temperature (deg C) */
float comp_hum; /* Sensor heat compensated humidity (%rH) */
float comp_gas; /* Compensated gas resistance (ohms) */
float iaq; /* Indoor Air Quality index */
float static_iaq; /* Static IAQ index */
float e_co2; /* Equivalent CO2 (ppm) */
float voc; /* Volatile organic compounds (ppb) */
uint8_t iaq_accuracy; /* IAQ index accuracy (0-3) */
};
void bhy2_bsec_parse_air_quality(const uint8_t *payload, struct bhy2_bsec_air_quality *data);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHY2_BSEC_H_ */

View File

@@ -0,0 +1,789 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_defs.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHY2_DEFS_H__
#define __BHY2_DEFS_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#ifdef __KERNEL__
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/types.h>
#else
#include <string.h>
#include <stdint.h>
#endif /*~ __KERNEL__ */
#ifndef UNUSED
#define UNUSED(__x__) ((void)(__x__))
#endif /*~ UNUSED */
#ifdef __KERNEL__
#define bhy2_float u32
#else
#define bhy2_float float
#endif /*~ __KERNEL__ */
#ifdef __KERNEL__
#if !defined(UINT8_C) && !defined(INT8_C)
#define INT8_C(x) S8_C(x)
#define UINT8_C(x) U8_C(x)
#endif
#if !defined(UINT16_C) && !defined(INT16_C)
#define INT16_C(x) S16_C(x)
#define UINT16_C(x) U16_C(x)
#endif
#if !defined(INT32_C) && !defined(UINT32_C)
#define INT32_C(x) S32_C(x)
#define UINT32_C(x) U32_C(x)
#endif
#if !defined(INT64_C) && !defined(UINT64_C)
#define INT64_C(x) S64_C(x)
#define UINT64_C(x) U64_C(x)
#endif
#else /* __KERNEL__ */
#if !defined(UINT8_C) && !defined(INT8_C)
#define INT8_C(x) (x)
#define UINT8_C(x) (x##U)
#endif
#if !defined(UINT16_C) && !defined(INT16_C)
#define INT16_C(x) (x)
#define UINT16_C(x) (x##U)
#endif
#if !defined(INT32_C) && !defined(UINT32_C)
#define INT32_C(x) (x)
#define UINT32_C(x) (x##U)
#endif
#if !defined(INT64_C) && !defined(UINT64_C)
#define INT64_C(x) (x##LL)
#define UINT64_C(x) (x##ULL)
#endif
#endif /* __KERNEL__ */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *) 0)
#endif
#endif
#ifndef BHY2_PACKED
#define BHY2_PACKED __attribute__ ((__packed__))
#endif
/** API error codes */
#define BHY2_OK INT8_C(0)
#define BHY2_E_NULL_PTR INT8_C(-1)
#define BHY2_E_INVALID_PARAM INT8_C(-2)
#define BHY2_E_IO INT8_C(-3)
#define BHY2_E_MAGIC INT8_C(-4)
#define BHY2_E_TIMEOUT INT8_C(-5)
#define BHY2_E_BUFFER INT8_C(-6)
#define BHY2_E_INVALID_FIFO_TYPE INT8_C(-7)
#define BHY2_E_INVALID_EVENT_SIZE INT8_C(-8)
#define BHY2_E_PARAM_NOT_SET INT8_C(-9)
#define BHy2_E_INSUFFICIENT_MAX_SIMUL_SENSORS INT8_C(-10)
#ifndef BHY2_COMMAND_PACKET_LEN
#define BHY2_COMMAND_PACKET_LEN UINT16_C(256)
#endif
#ifndef BHY2_COMMAND_HEADER_LEN
#define BHY2_COMMAND_HEADER_LEN UINT16_C(4)
#endif
#if (BHY2_COMMAND_PACKET_LEN < BHY2_COMMAND_HEADER_LEN)
#error "BHY2_COMMAND_PACKET_LEN should be at least 4 bytes"
#endif
#define BHY2_PRODUCT_ID UINT8_C(0x89)
/*! Register map */
#define BHY2_REG_CHAN_CMD UINT8_C(0x00)
#define BHY2_REG_CHAN_FIFO_W UINT8_C(0x01)
#define BHY2_REG_CHAN_FIFO_NW UINT8_C(0x02)
#define BHY2_REG_CHAN_STATUS UINT8_C(0x03)
#define BHY2_REG_CHIP_CTRL UINT8_C(0x05)
#define BHY2_REG_HOST_INTERFACE_CTRL UINT8_C(0x06)
#define BHY2_REG_HOST_INTERRUPT_CTRL UINT8_C(0x07)
#define BHY2_REG_RESET_REQ UINT8_C(0x14)
#define BHY2_REG_TIME_EV_REQ UINT8_C(0x15)
#define BHY2_REG_HOST_CTRL UINT8_C(0x16)
#define BHY2_REG_HOST_STATUS UINT8_C(0x17)
#define BHY2_REG_CRC_0 UINT8_C(0x18) /* Totally 4 */
#define BHY2_REG_PRODUCT_ID UINT8_C(0x1C)
#define BHY2_REG_REVISION_ID UINT8_C(0x1D)
#define BHY2_REG_ROM_VERSION_0 UINT8_C(0x1E) /* Totally 2 */
#define BHY2_REG_KERNEL_VERSION_0 UINT8_C(0x20) /* Totally 2 */
#define BHY2_REG_USER_VERSION_0 UINT8_C(0x22) /* Totally 2 */
#define BHY2_REG_FEATURE_STATUS UINT8_C(0x24)
#define BHY2_REG_BOOT_STATUS UINT8_C(0x25)
#define BHY2_REG_HOST_INTR_TIME_0 UINT8_C(0x26) /* Totally 5 */
#define BHY2_REG_CHIP_ID UINT8_C(0x2B)
#define BHY2_REG_INT_STATUS UINT8_C(0x2D)
#define BHY2_REG_ERROR_VALUE UINT8_C(0x2E)
#define BHY2_REG_ERROR_AUX UINT8_C(0x2F)
#define BHY2_REG_DEBUG_VALUE UINT8_C(0x30)
#define BHY2_REG_DEBUG_STATE UINT8_C(0x31)
#define BHY2_REG_GP_5 UINT8_C(0x32)
#define BHY2_REG_GP_6 UINT8_C(0x36)
#define BHY2_REG_GP_7 UINT8_C(0x3A)
/*! Command packets */
#define BHY2_CMD_REQ_POST_MORTEM_DATA UINT16_C(0x0001)
#define BHY2_CMD_UPLOAD_TO_PROGRAM_RAM UINT16_C(0x0002)
#define BHY2_CMD_BOOT_PROGRAM_RAM UINT16_C(0x0003)
#define BHY2_CMD_ERASE_FLASH UINT16_C(0x0004)
#define BHY2_CMD_WRITE_FLASH UINT16_C(0x0005)
#define BHY2_CMD_BOOT_FLASH UINT16_C(0x0006)
#define BHY2_CMD_SET_INJECT_MODE UINT16_C(0x0007)
#define BHY2_CMD_INJECT_DATA UINT16_C(0x0008)
#define BHY2_CMD_FIFO_FLUSH UINT16_C(0x0009)
#define BHY2_CMD_SW_PASSTHROUGH UINT16_C(0x000A)
#define BHY2_CMD_REQ_SELF_TEST UINT16_C(0x000B)
#define BHY2_CMD_REQ_FOC UINT16_C(0x000C)
#define BHY2_CMD_CONFIG_SENSOR UINT16_C(0x000D)
#define BHY2_CMD_CHANGE_RANGE UINT16_C(0x000E)
#define BHY2_CMD_FIFO_FORMAT_CTRL UINT16_C(0x0015)
/*! Soft passthrough feature */
#define BHY2_SPASS_READ UINT8_C(0)
#define BHY2_SPASS_WRITE UINT8_C(1)
#define BHY2_SPASS_SINGLE_TRANS UINT8_C(0)
#define BHY2_SPASS_MULTI_TRANS UINT8_C(1)
#define BHY2_SPASS_DELAY_DIS UINT8_C(0)
#define BHY2_SPASS_DELAY_EN UINT8_C(1)
#define BHY2_SPASS_SIF1 UINT8_C(1)
#define BHY2_SPASS_SIF2 UINT8_C(2)
#define BHY2_SPASS_SIF3 UINT8_C(3)
#define BHY2_SPASS_SPI_4_WIRE UINT8_C(0)
#define BHY2_SPASS_SPI_3_WIRE UINT8_C(1)
#define BHY2_SPASS_SPI_CPOL_0 UINT8_C(0)
#define BHY2_SPASS_SPI_CPOL_1 UINT8_C(1)
#define BHY2_SPASS_SPI_CPHA_0 UINT8_C(0)
#define BHY2_SPASS_SPI_CPHA_1 UINT8_C(1)
#define BHY2_SPASS_SPI_CS_LOW UINT8_C(0)
#define BHY2_SPASS_SPI_CS_HIGH UINT8_C(1)
#define BHY2_SPASS_SPI_LSB_FIRST_DIS UINT8_C(0)
#define BHY2_SPASS_SPI_LSB_FIRST_EN UINT8_C(1)
#define BHY2_SPASS_SPI_READ_BIT_POL_LOW UINT8_C(0)
#define BHY2_SPASS_SPI_READ_BIT_POL_HIGH UINT8_C(1)
#define BHY2_SPASS_SPI_READ_BIT_POS_0 UINT8_C(0)
#define BHY2_SPASS_SPI_READ_BIT_POS_1 UINT8_C(1)
#define BHY2_SPASS_SPI_READ_BIT_POS_2 UINT8_C(2)
#define BHY2_SPASS_SPI_READ_BIT_POS_3 UINT8_C(3)
#define BHY2_SPASS_SPI_READ_BIT_POS_4 UINT8_C(4)
#define BHY2_SPASS_SPI_READ_BIT_POS_5 UINT8_C(5)
#define BHY2_SPASS_SPI_READ_BIT_POS_6 UINT8_C(6)
#define BHY2_SPASS_SPI_READ_BIT_POS_7 UINT8_C(7)
#define BHY2_SPASS_READ_PACKET_LEN UINT8_C(0x13)
#define BHY2_SPASS_WRITE_RESP_PACKET_LEN UINT8_C(16)
/*! Helper macros */
#define BHY2_CHK_BIT(data, bit) (((uint32_t)data >> bit) & 0x01)
#define BHY2_ROUND_WORD_LOWER(x) ((x >> 2) << 2)
#define BHY2_ROUND_WORD_HIGHER(x) (((x >> 2) + 1) << 2)
#define BHY2_COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__)))
#define BHY2_DATA_INJECT_MODE_PAYLOAD_LEN UINT8_C(0x04)
/*! Firmware header identifier */
#define BHY2_FW_MAGIC UINT16_C(0x662B)
/*! BHy260 Variant IDs */
#define BHY2_VARIANT_ID_BHA260AB UINT32_C(0x2838C2C2)
#define BHY2_VARIANT_ID_BHI260AB UINT32_C(0x266EB6E7)
#define BHY2_VARIANT_ID_BHI260AP UINT32_C(0x98D7A5D1)
/*! Boot status */
#define BHY2_BST_FLASH_DETECTED UINT8_C(0x01)
#define BHY2_BST_FLASH_VERIFY_DONE UINT8_C(0x02)
#define BHY2_BST_FLASH_VERIFY_ERROR UINT8_C(0x04)
#define BHY2_BST_NO_FLASH UINT8_C(0x08)
#define BHY2_BST_HOST_INTERFACE_READY UINT8_C(0x10)
#define BHY2_BST_HOST_FW_VERIFY_DONE UINT8_C(0x20)
#define BHY2_BST_HOST_FW_VERIFY_ERROR UINT8_C(0x40)
#define BHY2_BST_HOST_FW_IDLE UINT8_C(0x80)
#define BHY2_BST_CHECK_RETRY UINT8_C(100)
/*! Host status */
#define BHY2_HST_POWER_STATE UINT8_C(0x01)
#define BHY2_HST_HOST_PROTOCOL UINT8_C(0x02)
#define BHY2_HST_HOST_CHANNEL_0 UINT8_C(0x10)
#define BHY2_HST_HOST_CHANNEL_1 UINT8_C(0x20)
#define BHY2_HST_HOST_CHANNEL_2 UINT8_C(0x40)
#define BHY2_HST_HOST_CHANNEL_3 UINT8_C(0x80)
/*! Interrupt status masks */
#define BHY2_IST_MASK_ASSERTED (0x1)
#define BHY2_IST_MASK_FIFO_W (0x6)
#define BHY2_IST_MASK_FIFO_NW (0x18)
#define BHY2_IST_MASK_STATUS (0x20)
#define BHY2_IST_MASK_DEBUG (0x40)
#define BHY2_IST_MASK_RESET_FAULT (0x80)
#define BHY2_IST_FIFO_W_DRDY UINT8_C(0x2)
#define BHY2_IST_FIFO_W_LTCY UINT8_C(0x4)
#define BHY2_IST_FIFO_W_WM UINT8_C(0x6)
#define BHY2_IST_FIFO_NW_DRDY UINT8_C(0x8)
#define BHY2_IST_FIFO_NW_LTCY UINT8_C(0x10)
#define BHY2_IST_FIFO_NW_WM UINT8_C(0x18)
#define BHY2_IS_INT_FIFO_W(status) (status & BHY2_IST_MASK_FIFO_W)
#define BHY2_IS_INT_FIFO_NW(status) (status & BHY2_IST_MASK_FIFO_NW)
#define BHY2_IS_INT_STATUS(status) (status & BHY2_IST_MASK_STATUS)
#define BHY2_IS_INT_ASYNC_STATUS(status) (status & BHY2_IST_MASK_DEBUG)
#define BHY2_IS_INT_RESET(status) (status & BHY2_IST_MASK_RESET_FAULT)
#define BHY2_IST_MASK_FIFO (BHY2_IST_MASK_FIFO_W | BHY2_IST_MASK_FIFO_NW)
#define BHY2_IS_INT_FIFO(status) (status & BHY2_IST_MASK_FIFO)
/*! Chip control bits */
#define BHY2_CHIP_CTRL_DISABLE UINT8_C(0x00)
#define BHY2_CHIP_CTRL_TURBO_ENABLE UINT8_C(0x01)
#define BHY2_CHIP_CTRL_CLR_ERR_REG UINT8_C(0x02)
/*! Host interface control bits */
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_0 UINT8_C(0x01)
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_1 UINT8_C(0x02)
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_2 UINT8_C(0x04)
#define BHY2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_3 UINT8_C(0x08)
#define BHY2_HIF_CTRL_AP_SUSPENDED UINT8_C(0x10)
#define BHY2_HIF_CTRL_TIMESTAMP_EV_CTRL UINT8_C(0x40)
#define BHY2_HIF_CTRL_ASYNC_STATUS_CHANNEL UINT8_C(0x80)
/*! Interrupt control bits */
#define BHY2_ICTL_DISABLE_FIFO_W UINT8_C(0x01)
#define BHY2_ICTL_DISABLE_FIFO_NW UINT8_C(0x02)
#define BHY2_ICTL_DISABLE_STATUS_FIFO UINT8_C(0x04)
#define BHY2_ICTL_DISABLE_DEBUG UINT8_C(0x08)
#define BHY2_ICTL_DISABLE_FAULT UINT8_C(0x10)
#define BHY2_ICTL_ACTIVE_LOW UINT8_C(0x20)
#define BHY2_ICTL_EDGE UINT8_C(0x40)
#define BHY2_ICTL_OPEN_DRAIN UINT8_C(0x80)
/*! Reset command */
#define BHY2_REQUEST_RESET UINT8_C(0x01)
/*! FIFO Format bit */
#define BHY2_FIFO_FORMAT_CTRL_MASK UINT8_C(0x03)
#define BHY2_FIFO_FORMAT_CTRL_DIS_DELTA_TS UINT8_C(0x01)
#define BHY2_FIFO_FORMAT_CTRL_DIS_FULL_TS UINT8_C(0x02)
#define BHY2_FIFO_FORMAT_CTRL_DIS_ALL_TS UINT8_C(0x03)
/*! System parameters */
#define BHY2_PARAM_READ_MASK UINT16_C(0x1000)
#define BHY2_PARAM_FIFO_CTRL UINT16_C(0x103)
#define BHY2_PARAM_SYS_VIRT_SENSOR_PRESENT UINT16_C(0x11F)
#define BHY2_PARAM_SYS_PHYS_SENSOR_PRESENT UINT16_C(0x120)
#define BHY2_PARAM_PHYSICAL_SENSOR_BASE UINT16_C(0x120)
#define BHY2_PARAM_BSX_CALIB_STATE_BASE UINT16_C(0x200)
#define BHY2_PARAM_BSX_CALIB_STATE_ACCEL UINT16_C(0x201)
#define BHY2_PARAM_BSX_CALIB_STATE_GYRO UINT16_C(0x203)
#define BHY2_PARAM_BSX_CALIB_STATE_MAG UINT16_C(0x205)
#define BHY2_PARAM_BSX_SIC UINT16_C(0x27D)
#define BHY2_PARAM_BSX_VERSION UINT16_C(0x27E)
#define BHY2_PARAM_SET_SENSOR_CTRL UINT16_C(0x0E00)
#define BHY2_PARAM_GET_SENSOR_CTRL UINT16_C(0x1E00)
#define BHY2_PARAM_SENSOR_CTRL_FOC UINT8_C(0x1)
#define BHY2_PARAM_SENSOR_CTRL_OIS UINT8_C(0x2)
#define BHY2_PARAM_SENSOR_CTRL_FST UINT8_C(0x3)
#define BHY2_PARAM_SENSOR_CTRL_READ UINT8_C(0x80)
#define BHY2_PARAM_SENSOR_INFO_0 UINT16_C(0x300)
#define BHY2_PARAM_SENSOR_CONF_0 UINT16_C(0x500)
#define BHY2_BSX_STATE_TRANSFER_COMPLETE UINT8_C(0x80)
#define BHY2_BSX_STATE_BLOCK_NUM_MSK UINT8_C(0x7F)
#define BHY2_BSX_STATE_BLOCK_LEN UINT8_C(64)
#define BHY2_BSX_STATE_STRUCT_LEN UINT8_C(68)
#define BHY2_QUERY_PARAM_STATUS_READY_MAX_RETRY UINT16_C(1000)
#define BHY2_QUERY_FLASH_MAX_RETRY UINT16_C(1200)
/*! Meta event definitions */
#define BHY2_META_EVENT_FLUSH_COMPLETE (1)
#define BHY2_META_EVENT_SAMPLE_RATE_CHANGED (2)
#define BHY2_META_EVENT_POWER_MODE_CHANGED (3)
#define BHY2_META_EVENT_ALGORITHM_EVENTS (5)
#define BHY2_META_EVENT_SENSOR_STATUS (6)
#define BHY2_META_EVENT_BSX_DO_STEPS_MAIN (7)
#define BHY2_META_EVENT_BSX_DO_STEPS_CALIB (8)
#define BHY2_META_EVENT_BSX_GET_OUTPUT_SIGNAL (9)
#define BHY2_META_EVENT_RESERVED1 (10)
#define BHY2_META_EVENT_SENSOR_ERROR (11)
#define BHY2_META_EVENT_FIFO_OVERFLOW (12)
#define BHY2_META_EVENT_DYNAMIC_RANGE_CHANGED (13)
#define BHY2_META_EVENT_FIFO_WATERMARK (14)
#define BHY2_META_EVENT_RESERVED2 (15)
#define BHY2_META_EVENT_INITIALIZED (16)
#define BHY2_META_TRANSFER_CAUSE (17)
#define BHY2_META_EVENT_SENSOR_FRAMEWORK (18)
#define BHY2_META_EVENT_RESET (19)
#define BHY2_META_EVENT_SPACER (20)
/* Flash start address in memory */
#define BHY2_FLASH_SECTOR_START_ADDR UINT32_C(0x1F84)
#define BHY2_FLASH_BULK_ERASE UINT32_C(0xFFFFFFFF)
/* End address for common flash sizes */
#define BHY2_FLASH_SIZE_0_5MB UINT32_C(0x7FFFF)
#define BHY2_FLASH_SIZE_1MB UINT32_C(0xFFFFF)
#define BHY2_FLASH_SIZE_2MB UINT32_C(0x1FFFFF)
#define BHY2_FLASH_SIZE_4MB UINT32_C(0x3FFFFF)
#define BHY2_FLASH_SIZE_8MB UINT32_C(0x7FFFFF)
/* Sensor IDs */
#define BHY2_SENSOR_ID_CUSTOM_START UINT8_C(160)
#define BHY2_SENSOR_ID_CUSTOM_END UINT8_C(191)
#define BHY2_SENSOR_ID_MAX UINT8_C(200)
#define BHY2_SENSOR_ID_TBD UINT8_C(BHY2_SENSOR_ID_MAX - 1)
/* Virtual Sensor IDs */
#define BHY2_SENSOR_ID_ACC_PASS UINT8_C(1) /* Accelerometer passthrough */
#define BHY2_SENSOR_ID_ACC_RAW UINT8_C(3) /* Accelerometer uncalibrated */
#define BHY2_SENSOR_ID_ACC UINT8_C(4) /* Accelerometer corrected */
#define BHY2_SENSOR_ID_ACC_BIAS UINT8_C(5) /* Accelerometer offset */
#define BHY2_SENSOR_ID_ACC_WU UINT8_C(6) /* Accelerometer corrected wake up */
#define BHY2_SENSOR_ID_ACC_RAW_WU UINT8_C(7) /* Accelerometer uncalibrated wake up */
#define BHY2_SENSOR_ID_SI_ACCEL UINT8_C(8) /* Virtual Sensor ID for Accelerometer */
#define BHY2_SENSOR_ID_GYRO_PASS UINT8_C(10) /* Gyroscope passthrough */
#define BHY2_SENSOR_ID_GYRO_RAW UINT8_C(12) /* Gyroscope uncalibrated */
#define BHY2_SENSOR_ID_GYRO UINT8_C(13) /* Gyroscope corrected */
#define BHY2_SENSOR_ID_GYRO_BIAS UINT8_C(14) /* Gyroscope offset */
#define BHY2_SENSOR_ID_GYRO_WU UINT8_C(15) /* Gyroscope wake up */
#define BHY2_SENSOR_ID_GYRO_RAW_WU UINT8_C(16) /* Gyroscope uncalibrated wake up */
#define BHY2_SENSOR_ID_SI_GYROS UINT8_C(17) /* Virtual Sensor ID for Gyroscope */
#define BHY2_SENSOR_ID_MAG_PASS UINT8_C(19) /* Magnetometer passthrough */
#define BHY2_SENSOR_ID_MAG_RAW UINT8_C(21) /* Magnetometer uncalibrated */
#define BHY2_SENSOR_ID_MAG UINT8_C(22) /* Magnetometer corrected */
#define BHY2_SENSOR_ID_MAG_BIAS UINT8_C(23) /* Magnetometer offset */
#define BHY2_SENSOR_ID_MAG_WU UINT8_C(24) /* Magnetometer wake up */
#define BHY2_SENSOR_ID_MAG_RAW_WU UINT8_C(25) /* Magnetometer uncalibrated wake up */
#define BHY2_SENSOR_ID_GRA UINT8_C(28) /* Gravity vector */
#define BHY2_SENSOR_ID_GRA_WU UINT8_C(29) /* Gravity vector wake up */
#define BHY2_SENSOR_ID_LACC UINT8_C(31) /* Linear acceleration */
#define BHY2_SENSOR_ID_LACC_WU UINT8_C(32) /* Linear acceleration wake up */
#define BHY2_SENSOR_ID_RV UINT8_C(34) /* Rotation vector */
#define BHY2_SENSOR_ID_RV_WU UINT8_C(35) /* Rotation vector wake up */
#define BHY2_SENSOR_ID_GAMERV UINT8_C(37) /* Game rotation vector */
#define BHY2_SENSOR_ID_GAMERV_WU UINT8_C(38) /* Game rotation vector wake up */
#define BHY2_SENSOR_ID_GEORV UINT8_C(40) /* Geo-magnetic rotation vector */
#define BHY2_SENSOR_ID_GEORV_WU UINT8_C(41) /* Geo-magnetic rotation vector wake up */
#define BHY2_SENSOR_ID_ORI UINT8_C(43) /* Orientation */
#define BHY2_SENSOR_ID_ORI_WU UINT8_C(44) /* Orientation wake up */
#define BHY2_SENSOR_ID_TILT_DETECTOR UINT8_C(48) /* Tilt detector */
#define BHY2_SENSOR_ID_STD UINT8_C(50) /* Step detector */
#define BHY2_SENSOR_ID_STC UINT8_C(52) /* Step counter */
#define BHY2_SENSOR_ID_STC_WU UINT8_C(53) /* Step counter wake up */
#define BHY2_SENSOR_ID_SIG UINT8_C(55) /* Significant motion */
#define BHY2_SENSOR_ID_WAKE_GESTURE UINT8_C(57) /* Wake gesture */
#define BHY2_SENSOR_ID_GLANCE_GESTURE UINT8_C(59) /* Glance gesture */
#define BHY2_SENSOR_ID_PICKUP_GESTURE UINT8_C(61) /* Pickup gesture */
#define BHY2_SENSOR_ID_AR UINT8_C(63) /* Activity recognition */
#define BHY2_SENSOR_ID_WRIST_TILT_GESTURE UINT8_C(67) /* Wrist tilt gesture */
#define BHY2_SENSOR_ID_DEVICE_ORI UINT8_C(69) /* Device orientation */
#define BHY2_SENSOR_ID_DEVICE_ORI_WU UINT8_C(70) /* Device orientation wake up */
#define BHY2_SENSOR_ID_STATIONARY_DET UINT8_C(75) /* Stationary detect */
#define BHY2_SENSOR_ID_MOTION_DET UINT8_C(77) /* Motion detect */
#define BHY2_SENSOR_ID_ACC_BIAS_WU UINT8_C(91) /* Accelerometer offset wake up */
#define BHY2_SENSOR_ID_GYRO_BIAS_WU UINT8_C(92) /* Gyroscope offset wake up */
#define BHY2_SENSOR_ID_MAG_BIAS_WU UINT8_C(93) /* Magnetometer offset wake up */
#define BHY2_SENSOR_ID_STD_WU UINT8_C(94) /* Step detector wake up */
#define BHY2_SENSOR_ID_TEMP UINT8_C(128) /* Temperature */
#define BHY2_SENSOR_ID_BARO UINT8_C(129) /* Barometer */
#define BHY2_SENSOR_ID_HUM UINT8_C(130) /* Humidity */
#define BHY2_SENSOR_ID_GAS UINT8_C(131) /* Gas */
#define BHY2_SENSOR_ID_TEMP_WU UINT8_C(132) /* Temperature wake up */
#define BHY2_SENSOR_ID_BARO_WU UINT8_C(133) /* Barometer wake up */
#define BHY2_SENSOR_ID_HUM_WU UINT8_C(134) /* Humidity wake up */
#define BHY2_SENSOR_ID_GAS_WU UINT8_C(135) /* Gas wake up */
#define BHY2_SENSOR_ID_STC_LP UINT8_C(136) /* Step counter Low Power */
#define BHY2_SENSOR_ID_STD_LP UINT8_C(137) /* Step detector Low Power */
#define BHY2_SENSOR_ID_SIG_LP UINT8_C(138) /* Significant motion Low Power */
#define BHY2_SENSOR_ID_STC_LP_WU UINT8_C(139) /* Step counter Low Power wake up */
#define BHY2_SENSOR_ID_STD_LP_WU UINT8_C(140) /* Step detector Low Power wake up */
#define BHY2_SENSOR_ID_SIG_LP_WU UINT8_C(141) /* Significant motion Low Power wake up */
#define BHY2_SENSOR_ID_ANY_MOTION_LP UINT8_C(142) /* Any motion Low Power */
#define BHY2_SENSOR_ID_ANY_MOTION_LP_WU UINT8_C(143) /* Any motion Low Power wake up */
#define BHY2_SENSOR_ID_EXCAMERA UINT8_C(144) /* External camera trigger */
#define BHY2_SENSOR_ID_GPS UINT8_C(145) /* GPS */
#define BHY2_SENSOR_ID_LIGHT UINT8_C(146) /* Light */
#define BHY2_SENSOR_ID_PROX UINT8_C(147) /* Proximity */
#define BHY2_SENSOR_ID_LIGHT_WU UINT8_C(148) /* Light wake up */
#define BHY2_SENSOR_ID_PROX_WU UINT8_C(149) /* Proximity wake up */
/*! Physical sensor IDs*/
#define BHY2_PHYS_SENSOR_ID_ACCELEROMETER UINT8_C(1)
#define BHY2_PHYS_SENSOR_ID_GYROSCOPE UINT8_C(3)
#define BHY2_PHYS_SENSOR_ID_MAGNETOMETER UINT8_C(5)
#define BHY2_PHYS_SENSOR_ID_TEMP_GYRO UINT8_C(7)
#define BHY2_PHYS_SENSOR_ID_ANY_MOTION UINT8_C(9)
#define BHY2_PHYS_SENSOR_ID_PRESSURE UINT8_C(11)
#define BHY2_PHYS_SENSOR_ID_POSITION UINT8_C(13)
#define BHY2_PHYS_SENSOR_ID_HUMIDITY UINT8_C(15)
#define BHY2_PHYS_SENSOR_ID_TEMPERATURE UINT8_C(17)
#define BHY2_PHYS_SENSOR_ID_GAS_RESISTOR UINT8_C(19)
#define BHY2_PHYS_SENSOR_ID_PHYS_STEP_COUNTER UINT8_C(32)
#define BHY2_PHYS_SENSOR_ID_PHYS_STEP_DETECTOR UINT8_C(33)
#define BHY2_PHYS_SENSOR_ID_PHYS_SIGN_MOTION UINT8_C(34)
#define BHY2_PHYS_SENSOR_ID_PHYS_ANY_MOTION UINT8_C(35)
#define BHY2_PHYS_SENSOR_ID_EX_CAMERA_INPUT UINT8_C(36)
#define BHY2_PHYS_SENSOR_ID_GPS UINT8_C(48)
#define BHY2_PHYS_SENSOR_ID_LIGHT UINT8_C(49)
#define BHY2_PHYS_SENSOR_ID_PROXIMITY UINT8_C(50)
#define BHY2_PHYS_SENSOR_ID_PHYS_NO_MOTION UINT8_C(55)
#define BHY2_PHYS_SENSOR_ID_WRIST_GESTURE_DETECT UINT8_C(56)
#define BHY2_PHYS_SENSOR_ID_WRIST_WEAR_WAKEUP UINT8_C(57)
/*! System data IDs */
#define BHY2_IS_SYS_ID(sid) ((sid) >= 224)
#define BHY2_SYS_ID_PADDING UINT8_C(0)
#define BHY2_SYS_ID_TS_SMALL_DELTA UINT8_C(251)
#define BHY2_SYS_ID_TS_LARGE_DELTA UINT8_C(252)
#define BHY2_SYS_ID_TS_FULL UINT8_C(253)
#define BHY2_SYS_ID_META_EVENT UINT8_C(254)
#define BHY2_SYS_ID_TS_SMALL_DELTA_WU UINT8_C(245)
#define BHY2_SYS_ID_TS_LARGE_DELTA_WU UINT8_C(246)
#define BHY2_SYS_ID_TS_FULL_WU UINT8_C(247)
#define BHY2_SYS_ID_META_EVENT_WU UINT8_C(248)
#define BHY2_SYS_ID_FILLER UINT8_C(255)
#define BHY2_SYS_ID_DEBUG_MSG UINT8_C(250)
#define BHY2_SYS_ID_BHY2_LOG_UPDATE_SUB UINT8_C(243)
#define BHY2_SYS_ID_BHY2_LOG_DOSTEP UINT8_C(244)
/*! Status code definitions */
#define BHY2_STATUS_INITIALIZED UINT8_C(0x1)
#define BHY2_STATUS_DEBUG_OUTPUT UINT8_C(0x2)
#define BHY2_STATUS_CRASH_DUMP UINT8_C(0x3)
#define BHY2_STATUS_INJECT_SENSOR_CONF_REQ UINT8_C(0x4)
#define BHY2_STATUS_SW_PASS_THRU_RES UINT8_C(0x5)
#define BHY2_STATUS_SELF_TEST_RES UINT8_C(0x6)
#define BHY2_STATUS_FOC_RES UINT8_C(0x7)
#define BHY2_STATUS_SYSTEM_ERROR UINT8_C(0x8)
#define BHY2_STATUS_SENSOR_ERROR UINT8_C(0x9)
#define BHY2_STATUS_FLASH_ERASE_COMPLETE UINT8_C(0xA)
#define BHY2_STATUS_FLASH_WRITE_COMPLETE UINT8_C(0xB)
#define BHY2_STATUS_FLASH_CONTINUE_UPLOAD UINT8_C(0xC)
#define BHY2_STATUS_HOST_EV_TIMESTAMP UINT8_C(0xD)
#define BHY2_STATUS_DUT_TEST_RES UINT8_C(0xE)
#define BHY2_STATUS_CMD_ERR UINT8_C(0xF)
#define BHY2_IS_STATUS_GET_PARAM_OUTPUT(status) ((status) >= 0x100 && (status) <= 0xFFF)
/*! Activity bits */
#define BHY2_STILL_ACTIVITY_ENDED (0x0001)
#define BHY2_WALKING_ACTIVITY_ENDED (0x0002)
#define BHY2_RUNNING_ACTIVITY_ENDED (0x0004)
#define BHY2_ON_BICYCLE_ACTIVITY_ENDED (0x0008)
#define BHY2_IN_VEHICLE_ACTIVITY_ENDED (0x0010)
#define BHY2_TILTING_ACTIVITY_ENDED (0x0020)
#define BHY2_STILL_ACTIVITY_STARTED (0x0100)
#define BHY2_WALKING_ACTIVITY_STARTED (0x0200)
#define BHY2_RUNNING_ACTIVITY_STARTED (0x0400)
#define BHY2_ON_BICYCLE_ACTIVITY_STARTED (0x0800)
#define BHY2_IN_VEHICLE_ACTIVITY_STARTED (0x1000)
#define BHY2_TILTING_ACTIVITY_STARTED (0x2000)
/*! Feature status */
#define BHY2_FEAT_STATUS_FLASH_DESC_MSK UINT8_C(0x01)
#define BHY2_FEAT_STATUS_OPEN_RTOS_MSK UINT8_C(0x02)
#define BHY2_FEAT_STATUS_OPEN_RTOS_POS (1)
#define BHY2_FEAT_STATUS_HOST_ID_MSK UINT8_C(0x1C)
#define BHY2_FEAT_STATUS_HOST_ID_POS (2)
#define BHY2_FEAT_STATUS_ALGO_ID_MSK UINT8_C(0xE0)
#define BHY2_FEAT_STATUS_ALGO_ID_POS (5)
/*! Fast offset compensation status codes */
#define BHY2_FOC_PASS UINT8_C(0x00)
#define BHY2_FOC_FAILED UINT8_C(0x65)
#define BHY2_FOC_UNKNOWN_FAILURE UINT8_C(0x23)
/*! Self test status codes */
#define BHY2_ST_PASSED UINT8_C(0x00)
#define BHY2_ST_X_AXIS_FAILED UINT8_C(0x01)
#define BHY2_ST_Y_AXIS_FAILED UINT8_C(0x02)
#define BHY2_ST_Z_AXIS_FAILED UINT8_C(0x04)
#define BHY2_ST_MULTI_AXIS_FAILURE UINT8_C(0x07)
#define BHY2_ST_NOT_SUPPORTED UINT8_C(0x08)
#define BHY2_ST_INVALID_PHYS_ID UINT8_C(0x09)
#define BHY2_LE2U16(x) ((uint16_t)((x)[0] | (x)[1] << 8))
#define BHY2_LE2S16(x) ((int16_t)BHY2_LE2U16(x))
#define BHY2_LE2U24(x) ((uint32_t)((x)[0] | (uint32_t)(x)[1] << 8 | (uint32_t)(x)[2] << 16))
#define BHY2_LE2S24(x) ((int32_t)(BHY2_LE2U24(x) << 8) >> 8)
#define BHY2_LE2U32(x) ((uint32_t)((x)[0] | (uint32_t)(x)[1] << 8 | (uint32_t)(x)[2] << 16 | \
(uint32_t)(x)[3] << 24))
#define BHY2_LE2S32(x) ((int32_t)BHY2_LE2U32(x))
#define BHY2_LE2U40(x) (BHY2_LE2U32(x) | (uint64_t)(x)[4] << 32)
#define BHY2_LE2U64(x) (BHY2_LE2U32(x) | (uint64_t)BHY2_LE2U32(&(x)[4]) << 32)
#define BHY2_LE24MUL(x) (((x) % 4) ? (uint16_t)((((x) / 4) + 1) * 4) : (uint16_t)((x) + 4))
/*! Maximum no of available virtual sensor */
#define BHY2_N_VIRTUAL_SENSOR_MAX UINT8_C(256)
#ifndef BHY2_MAX_SIMUL_SENSORS
#define BHY2_MAX_SIMUL_SENSORS 48
#endif
/* Special & debug virtual sensor id starts at 245 */
#define BHY2_SPECIAL_SENSOR_ID_OFFSET UINT8_C(245)
#ifndef BHY2_INTF_RET_TYPE
#define BHY2_INTF_RET_TYPE int8_t
#endif
#ifndef BHY2_INTF_RET_SUCCESS
#define BHY2_INTF_RET_SUCCESS 0
#endif
/* Type definitions for the function pointers */
typedef BHY2_INTF_RET_TYPE (*bhy2_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr);
typedef BHY2_INTF_RET_TYPE (*bhy2_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
void *intf_ptr);
typedef void (*bhy2_delay_us_fptr_t)(uint32_t period_us, void *intf_ptr);
enum bhy2_intf {
BHY2_SPI_INTERFACE = 1,
BHY2_I2C_INTERFACE
};
/* HIF device structure */
struct bhy2_hif_dev {
bhy2_read_fptr_t read;
bhy2_write_fptr_t write;
bhy2_delay_us_fptr_t delay_us;
enum bhy2_intf intf;
void *intf_ptr;
BHY2_INTF_RET_TYPE intf_rslt;
uint32_t read_write_len;
};
enum bhy2_fifo_type {
BHY2_FIFO_TYPE_WAKEUP,
BHY2_FIFO_TYPE_NON_WAKEUP,
BHY2_FIFO_TYPE_STATUS,
BHY2_FIFO_TYPE_MAX
};
struct BHY2_PACKED bhy2_fifo_parse_data_info {
uint8_t sensor_id;
enum bhy2_fifo_type fifo_type;
uint8_t data_size;
uint8_t *data_ptr;
uint64_t *time_stamp;
};
typedef void (*bhy2_fifo_parse_callback_t)(const struct bhy2_fifo_parse_data_info *callback_info, void *private_data);
struct BHY2_PACKED bhy2_fifo_parse_callback_table {
uint8_t sensor_id;
bhy2_fifo_parse_callback_t callback;
void *callback_ref;
};
/* Device structure */
struct bhy2_dev {
struct bhy2_hif_dev hif;
struct bhy2_fifo_parse_callback_table table[BHY2_MAX_SIMUL_SENSORS];
uint8_t event_size[BHY2_N_VIRTUAL_SENSOR_MAX];
uint64_t last_time_stamp[BHY2_FIFO_TYPE_MAX];
uint8_t present_buff[32];
};
struct bhy2_fifo_buffer {
uint32_t read_pos;
uint32_t read_length;
uint32_t remain_length;
uint32_t buffer_size;
uint8_t *buffer;
};
typedef int16_t (*bhy2_frame_parse_func_t)(struct bhy2_fifo_buffer *p_fifo_buffer, struct bhy2_dev *bhy2_p);
struct bhy2_virt_sensor_conf {
uint16_t sensitivity;
uint16_t range;
uint32_t latency;
bhy2_float sample_rate;
};
struct bhy2_data_xyz {
int16_t x;
int16_t y;
int16_t z;
};
struct bhy2_data_quaternion {
int16_t x;
int16_t y;
int16_t z;
int16_t w;
uint16_t accuracy;
};
struct bhy2_data_orientation {
int16_t heading;
int16_t pitch;
int16_t roll;
};
union BHY2_PACKED bhy2_spt_dev_id {
uint8_t slave_address;
uint8_t cs_pin;
};
struct BHY2_PACKED bhy2_spt_bits {
/*! byte 1 */
uint8_t direction : 1; /**< 0: read; 1: write. */
uint8_t trans_type : 1; /**< 0: single burst; 1:multi single transfers. */
uint8_t delay_ctrl : 1; /**< 0: none; 1: delay between bytes. */
uint8_t master_bus : 2; /**< 1: SIF1; 2: SIF2; 3:SIF3. */
uint8_t spi_mode : 1; /**< 0: 4 wire; 1: 3 wire. */
uint8_t cpol : 1; /**< spi clock polarity. */
uint8_t cpha : 1; /**< spi clock phase. */
/*! byte 2 */
uint8_t delay_val : 6; /**< multiples of 50us. min is 200us (4LSB) */
uint8_t cs_level : 1; /**< chip select level. */
uint8_t lsb_first : 1; /**< least significant byte first. */
/*! byte 3~4 */
uint16_t trans_rate; /**< spi clock rate. */
/*! byte 5 */
uint8_t address_shift : 4; /**< number of bits to shift register address. */
uint8_t read_bit_pol : 1; /**< 0: active low; 1: active high. */
uint8_t read_bit_pos : 3; /**< bit number of read bit in command byte. */
/*! byte 6 */
union bhy2_spt_dev_id func_set;
/*! byte 7 */
uint8_t trans_count;
/*! byte 8 */
uint8_t reg;
};
union bhy2_soft_passthrough_conf {
struct bhy2_spt_bits conf;
uint8_t data[8];
};
union bhy2_u16_conv {
uint16_t u16_val;
uint8_t bytes[2];
};
union bhy2_u32_conv {
uint32_t u32_val;
uint8_t bytes[4];
};
union bhy2_float_conv {
bhy2_float f_val;
uint32_t u32_val;
uint8_t bytes[4];
};
struct bhy2_sensor_info {
uint8_t sensor_type;
uint8_t driver_id;
uint8_t driver_version;
uint8_t power;
union bhy2_u16_conv max_range;
union bhy2_u16_conv resolution;
union bhy2_float_conv max_rate;
union bhy2_u32_conv fifo_reserved;
union bhy2_u32_conv fifo_max;
uint8_t event_size;
union bhy2_float_conv min_rate;
};
struct bhy2_phys_sensor_info {
uint8_t sensor_type;
uint8_t driver_id;
uint8_t driver_version;
uint8_t power_current;
union bhy2_u16_conv curr_range;
uint8_t flags;
uint8_t slave_address;
uint8_t gpio_assignment;
union bhy2_float_conv curr_rate;
uint8_t num_axis;
uint8_t orientation_matrix[5];
uint8_t reserved;
};
struct bhy2_self_test_resp {
uint8_t test_status;
int16_t x_offset, y_offset, z_offset;
};
struct bhy2_foc_resp {
uint8_t foc_status;
int16_t x_offset, y_offset, z_offset;
};
struct bhy2_orient_matrix {
int8_t c[9];
};
enum bhy2_data_inj_mode {
BHY2_NORMAL_MODE = 0,
BHY2_REAL_TIME_INJECTION = 1,
BHY2_STEP_BY_STEP_INJECTION = 2
};
#define BHY2_BYTE_TO_NIBBLE(X) (((uint8_t)(X)[0] & 0x0F) | (((uint8_t)(X)[1] << 4) & 0xF0))
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHY2_DEFS_H__ */

View File

@@ -0,0 +1,353 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_head_tracker.c
* @date 2023-03-24
* @version v1.6.0
*
*/
/*********************************************************************/
/* system header files */
/*********************************************************************/
#include <string.h>
#include <stdlib.h>
/*********************************************************************/
/* BHY2 SensorAPI header files */
/*********************************************************************/
#include "bhy2.h"
/*********************************************************************/
/* own header files */
/*********************************************************************/
#include "bhy2_head_tracker.h"
/*Parsing callback for Head Orientation Quaternion*/
void bhy2_head_tracker_quat_parsing(const uint8_t *payload, struct bhy2_head_tracker_quat_data *data)
{
uint8_t i = 0;
if ((payload != NULL) && (data != NULL))
{
data->x = BHY2_LE2S16(&payload[i]);
i += 2;
data->y = BHY2_LE2S16(&payload[i]);
i += 2;
data->z = BHY2_LE2S16(&payload[i]);
i += 2;
data->w = BHY2_LE2S16(&payload[i]);
i += 2;
data->accuracy = payload[i];
}
}
/*Parsing callback for Head Orientation Euler*/
void bhy2_head_tracker_eul_parsing(const uint8_t *payload, struct bhy2_head_tracker_eul_data *data)
{
uint8_t i = 0;
if ((payload != NULL) && (data != NULL))
{
data->heading = BHY2_LE2S16(&payload[i]);
i += 2;
data->pitch = BHY2_LE2S16(&payload[i]);
i += 2;
data->roll = BHY2_LE2S16(&payload[i]);
i += 2;
data->accuracy = payload[i];
}
}
/*Callback for triggering Head Misalignment Calibration*/
int8_t bhy2_head_tracker_trigger_hmc_calibration(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Trigger Head Misalignment Calibration */
rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_TRIGGER_CALIB),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_LENGTH,
dev);
}
return rslt;
}
/*Callback for setting Head Misalignment Calibration Configuration*/
int8_t bhy2_head_tracker_set_hmc_configuration(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set Head Misalignment Configuration */
rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_CONFIG),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_CONFIG_LENGTH,
dev);
}
return rslt;
}
/*Callback for getting Head Misalignment Calibration Configuration*/
int8_t bhy2_head_tracker_get_hmc_configuration(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t act_len;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get Head Misalignment Configuration */
rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_CONFIG),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_CONFIG_LENGTH,
&act_len,
dev);
}
return rslt;
}
/*Callback for setting default Head Misalignment Calibration Configuration*/
int8_t bhy2_head_tracker_set_default_hmc_configuration(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set default Head Misalignment Configuration */
rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_LENGTH,
dev);
}
return rslt;
}
/*Callback for getting Head Misalignment Calibrator Version*/
int8_t bhy2_head_tracker_get_hmc_version(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t act_len;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get Head Misalignment Calibrator Version */
rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_VERSION),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_VERSION_LENGTH,
&act_len,
dev);
}
return rslt;
}
/*Callback for setting Head Misalignment Calibration Correction Quaternion Configuration*/
int8_t bhy2_head_tracker_set_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set Head Misalignment Calibration Correction Quaternion Configuration */
rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_WLENGTH,
dev);
}
return rslt;
}
/*Callback for getting Head Misalignment Calibration Correction Quaternion Configuration*/
int8_t bhy2_head_tracker_get_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t act_len;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get Head Misalignment Calibration Correction Quaternion Configuration */
rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR),
(uint8_t*)buffer,
BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_RLENGTH,
&act_len,
dev);
}
return rslt;
}
/*Callback for setting Head Orientation Initial Head Correction for Quaternion*/
int8_t bhy2_head_tracker_set_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set Head Orientation Initial Head Correction for Quaternion */
rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR),
(uint8_t*)buffer,
BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH,
dev);
}
return rslt;
}
/*Callback for getting Head Orientation Initial Head Correction for Quaternion*/
int8_t bhy2_head_tracker_get_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t act_len;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get Head Orientation Initial Head Correction for Quaternion */
rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR),
(uint8_t*)buffer,
BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH,
&act_len,
dev);
}
return rslt;
}
/*Callback for getting Head Orientation Version*/
int8_t bhy2_head_tracker_get_ho_version(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t act_len;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get IMU/NDOF Head Orientation Version */
rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_VERSION),
(uint8_t*)buffer,
BHY2_HEAD_ORI_VERSION_LENGTH,
&act_len,
dev);
}
return rslt;
}
/*Callback for setting Head Orientation Initial Head Correction for Euler*/
int8_t bhy2_head_tracker_set_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set Head Orientation Initial Head Correction for Euler */
rslt = bhy2_set_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR),
(uint8_t*)buffer,
BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH,
dev);
}
return rslt;
}
/*Callback for getting Head Orientation Initial Head Correction for Euler*/
int8_t bhy2_head_tracker_get_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint32_t act_len;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get Head Orientation Initial Head Correction for Euler */
rslt = bhy2_get_parameter(BHY2_HEAD_ORI_PARAM(BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR),
(uint8_t*)buffer,
BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH,
&act_len,
dev);
}
return rslt;
}

View File

@@ -0,0 +1,213 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_head_tracker.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHY2_HEAD_TRACKER_H_
#define _BHY2_HEAD_TRACKER_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <stdlib.h>
#include <stdlib.h>
#include "bhy2.h"
#include "bhy2_head_tracker_defs.h"
/*!
* @brief Parsing callback for Head Orientation Quaternion
*
* @param[in] payload
* @param[out] bhy2_head_tracker_quat_data to store Head Orientation [Quaternion] data
*
* @return API error codes
*
*/
void bhy2_head_tracker_quat_parsing(const uint8_t *payload, struct bhy2_head_tracker_quat_data *data);
/*!
* @brief Parsing callback for Head Orientation Euler
*
* @param[in] payload
* @param[out] bhy2_head_tracker_eul_data to store Head Orientation [Euler] data
*
* @return API error codes
*
*/
void bhy2_head_tracker_eul_parsing(const uint8_t *payload, struct bhy2_head_tracker_eul_data *data);
/*!
* @brief To trigger the Head Misalignment Calibration
*
* @param[in] buffer
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_trigger_hmc_calibration(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the Head Misalignment Calibration Configuration
*
* @param[in] buffer to hold the Head Misalignment Calibration Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_set_hmc_configuration(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the Head Misalignment Calibration Configuration
*
* @param[out] buffer to hold the Head Misalignment Calibration Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_get_hmc_configuration(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the default Head Misalignment Calibration Configuration
*
* @param[in] command buffer
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_set_default_hmc_configuration(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the Head Misalignment Calibrator Version
*
* @param[out] buffer to hold the Head Misalignment Calibrator Version
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_get_hmc_version(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the Head Misalignment Quaternion Calibration Correction Configuration
*
* @param[in] buffer to hold the Head Misalignment Quaternion Calibration Correction Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_set_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the Head Misalignment Quaternion Calibration Correction Configuration
*
* @param[out] buffer to hold the Head Misalignment Quaternion Calibration Correction Configuration
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_get_hmc_quat_calib_corr_config(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the Head Misalignment Quaternion Initial Head Correction
*
* @param[in] buffer to hold the Head Misalignment Quaternion Initial Head Correction
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_set_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the Head Misalignment Quaternion Initial Head Correction
*
* @param[out] buffer to hold the Head Misalignment Quaternion Initial Head Correction
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_get_quat_initial_head_correction(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the IMU/NDOF Head Orientation Version
*
* @param[out] buffer to hold the IMU/NDOF Head Orientation Version
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_get_ho_version(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the Head Misalignment Euler Initial Head Correction
*
* @param[in] buffer to hold the Head Misalignment Euler Initial Head Correction
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_set_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the Head Misalignment Euler Initial Head Correction
*
* @param[out] buffer to hold the Head Misalignment Euler Initial Head Correction
* @param[in] dev hub handle
*
* @return API error codes
*
*/
int8_t bhy2_head_tracker_get_eul_initial_head_correction(const void *buffer, struct bhy2_dev *dev);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHY2_HEAD_TRACKER_H_ */

View File

@@ -0,0 +1,138 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_head_tracker_defs.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHY2_HEAD_TRACKER_DEFS_H_
#define _BHY2_HEAD_TRACKER_DEFS_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <stdlib.h>
#include <stdlib.h>
#include "bhy2.h"
/*! Virtual Sensor Macros */
#define BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG UINT8_C(120) /*Head Orientation Misalignment*/
#define BHY2_SENSOR_ID_IMU_HEAD_ORI_Q UINT8_C(121) /*IMU Head Orientation Quaternion*/
#define BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q UINT8_C(122) /*NDOF Head Orientation Quaternion*/
#define BHY2_SENSOR_ID_IMU_HEAD_ORI_E UINT8_C(123) /*IMU Head Orientation Euler*/
#define BHY2_SENSOR_ID_NDOF_HEAD_ORI_E UINT8_C(124) /*NDOF Head Orientation Euler*/
#define BHY2_HEAD_ORI_PAGE UINT16_C(12)
#define BHY2_HEAD_ORI_PARAM(id) (((BHY2_HEAD_ORI_PAGE) << 8) | (id))
#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB UINT8_C(1)
#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_LENGTH UINT8_C(4)
#define BHY2_HEAD_ORI_HMC_TRIGGER_CALIB_SET UINT8_C(1)
#define BHY2_HEAD_ORI_HMC_CONFIG UINT8_C(2)
#define BHY2_HEAD_ORI_HMC_CONFIG_LENGTH UINT8_C(8)
#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG UINT8_C(3)
#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_LENGTH UINT8_C(4)
#define BHY2_HEAD_ORI_HMC_SET_DEF_CONFIG_SET UINT8_C(1)
#define BHY2_HEAD_ORI_HMC_VERSION UINT8_C(4)
#define BHY2_HEAD_ORI_HMC_VERSION_LENGTH UINT8_C(4)
#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR UINT8_C(5)
#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_WLENGTH UINT8_C(16)
#define BHY2_HEAD_ORI_HMC_QUAT_CALIB_CORR_RLENGTH UINT8_C(20)
#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR UINT8_C(10)
#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_LENGTH UINT8_C(4)
#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_DISABLE UINT8_C(0)
#define BHY2_HEAD_ORI_QUAT_INITIAL_HEAD_CORR_ENABLE UINT8_C(1)
#define BHY2_HEAD_ORI_VERSION UINT8_C(11)
#define BHY2_HEAD_ORI_VERSION_LENGTH UINT8_C(4)
#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR UINT8_C(12)
#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_LENGTH UINT8_C(4)
#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_DISABLE UINT8_C(0)
#define BHY2_HEAD_ORI_EUL_INITIAL_HEAD_CORR_ENABLE UINT8_C(1)
/*! Sensor Structure for Head Orientation Quaternion */
struct bhy2_head_tracker_quat_data
{
int16_t x, y, z, w;
uint8_t accuracy;
};
/*! Sensor Structure for Head Orientation Euler */
struct bhy2_head_tracker_eul_data
{
int16_t heading, pitch, roll;
uint8_t accuracy;
};
/*! Structure for Head Misalignment Configuration */
struct bhy2_head_tracker_misalignment_config
{
uint8_t still_phase_max_dur;
uint8_t still_phase_min_dur;
uint8_t still_phase_max_samples;
int32_t acc_diff_threshold;
};
/*! Structure for Head Orientation /Head Misalignment version */
struct bhy2_head_tracker_ver
{
uint8_t major, minor, patch, reserved;
};
/*! Structure for Head Misalignment Quaternion Correction */
struct bhy2_head_tracker_misalignment_quat_corr
{
int32_t quaternion_x;
int32_t quaternion_y;
int32_t quaternion_z;
int32_t quaternion_w;
int32_t accuracy;
};
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHY2_HEAD_TRACKER_DEFS_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,576 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_hif.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHY2_HIF_H__
#define __BHY2_HIF_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include "bhy2_defs.h"
/**
* @brief Function to link the callback interfaces
* @param[in] intf : Physical communication interface
* @param[in] read : Read function pointer
* @param[in] write : Write function pointer
* @param[in] delay_us : Microsecond delay function pointer
* @param[in] read_write_len : Maximum read/write lengths supported
* @param[in] intf_ptr : Reference to the interface. Can be NULL
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_init(enum bhy2_intf intf,
bhy2_read_fptr_t read,
bhy2_write_fptr_t write,
bhy2_delay_us_fptr_t delay_us,
uint32_t read_write_len,
void *intf_ptr,
struct bhy2_hif_dev *hif);
/**
* @brief Function to get data from registers
* @param[in] reg_addr : Register address to be read from
* @param[out] reg_data : Reference to the data buffer
* @param[in] length : Length of the data buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif);
/**
* @brief Function to set data to registers
* @param[in] reg_addr : Register address to write to
* @param[in] reg_data : Reference to the data buffer
* @param[in] length : Length of the data buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_regs(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, struct bhy2_hif_dev *hif);
/**
* @brief Function to delay in microseconds
* @param[in] period_us : Period to delay in microseconds
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_delay_us(uint32_t period_us, const struct bhy2_hif_dev *hif);
/**
* Function to execute a command
* @param[in] cmd : Command code
* @param[in] payload : Reference to the data buffer containing the command's payload
* @param[in] length : Length of the data buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_exec_cmd(uint16_t cmd, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif);
/**
* @brief Function to get a parameter
* @param[in] param : Parameter ID
* @param[out] payload : Reference to the data buffer to store the parameter's payload
* @param[in] payload_len : Length of the data buffer
* @param[out] actual_len : Actual length of the payload
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_parameter(uint16_t param,
uint8_t *payload,
uint32_t payload_len,
uint32_t *actual_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to set a parameter
* @param[in] param : Parameter ID
* @param[in] payload : Reference to the data buffer storing the parameter's payload
* @param[in] length : Length of the data buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_parameter(uint16_t param, const uint8_t *payload, uint32_t length, struct bhy2_hif_dev *hif);
/**
* @brief Function to erase the flash
* @param[in] start_addr : Start address
* @param[in] end_addr : End address
* @param[in] hif : HIF device address
* @return API error codes
*/
int8_t bhy2_hif_erase_flash(uint32_t start_addr, uint32_t end_addr, struct bhy2_hif_dev *hif);
/**
* @brief Function to upload data to flash
* @param[in] firmware : Reference to the data buffer storing the firmware
* @param[in] length : Length of the data buffer
* @param[in/out] work_buffer : Reference to the work buffer
* @param[in] work_buf_len : Length of the work buffer
* @param[out] exp_size : Expected size of the work buffer if insufficient size
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_upload_to_flash(const uint8_t *firmware,
uint32_t length,
uint8_t *work_buffer,
uint32_t work_buf_len,
uint32_t *exp_size,
struct bhy2_hif_dev *hif);
/**
* @brief Function to upload data to flash partly
* @param[in] firmware : Reference cur_pos of the data buffer storing the firmware
* @param[in] cur_pos : Current position of the firmware
* @param[in] packet_len : Length of the firmware packet to be transferred
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_upload_to_flash_partly(const uint8_t *firmware,
uint32_t cur_pos,
uint32_t packet_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to boot from flash
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_boot_from_flash(struct bhy2_hif_dev *hif);
/**
* @brief Function to get the product ID
* @param[out] product_id : Reference to the data buffer to store the product ID
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_product_id(uint8_t *product_id, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the chip ID
* @param[out] chip_id : Reference to the data buffer to store the chip ID
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_chip_id(uint8_t *chip_id, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the ROM version
* @param[out] rom_version : Reference to the data buffer to store the ROM version
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_rom_version(uint16_t *rom_version, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the kernel version
* @param[out] kernel_version : Reference to the data buffer to store the kernel version
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_kernel_version(uint16_t *kernel_version, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the user version
* @param[out] user_version : Reference to the data buffer to store the user version
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_user_version(uint16_t *user_version, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the boot status
* @param[out] boot_status : Reference to the data buffer to store the boot status
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_boot_status(uint8_t *boot_status, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the host status
* @param[out] host_status : Reference to the data buffer to store the host status
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_host_status(uint8_t *host_status, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the feature status
* @param[out] feat_status : Reference to the data buffer to store the feature status
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_feature_status(uint8_t *feat_status, struct bhy2_hif_dev *hif);
/**
* @brief Function get the interrupt status
* @param[out] int_status : Reference to the data buffer to store the interrupt status
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_interrupt_status(uint8_t *int_status, struct bhy2_hif_dev *hif);
/**
* @brief Function get the firmware error code
* @param[out] fw_error : Reference to the data buffer to store the firmware error code
* @param[in] hif : HIF device reference
* @return API error code
*/
int8_t bhy2_hif_get_fw_error(uint8_t *fw_error, struct bhy2_hif_dev *hif);
/**
* @brief Function to trigger a soft reset
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_reset(struct bhy2_hif_dev *hif);
/**
* @brief Function to upload a firmware to RAM
* @param[in] firmware : Reference to the data buffer storing the firmware
* @param[in] length : Length of the firmware
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_upload_firmware_to_ram(const uint8_t *firmware, uint32_t length, struct bhy2_hif_dev *hif);
/**
* @brief Function to upload a part of the firmware to RAM
* @param[in] firmware : Reference to the data buffer storing the current part of firmware
* @param[in] total_size : Total size of the firmware
* @param[in] cur_pos : Current position of the firmware
* @param[in] packet_len : Size of firmware part to be uploaded
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_upload_firmware_to_ram_partly(const uint8_t *firmware,
uint32_t total_size,
uint32_t cur_pos,
uint32_t packet_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to boot from RAM
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_boot_program_ram(struct bhy2_hif_dev *hif);
/**
* @brief Function to get data from the Wake-up FIFO
* @param[out] fifo : Reference to the data buffer to store data from the FIFO
* @param[in] fifo_len : Length of the data buffer
* @param[out] bytes_read : Number of bytes read into the data buffer
* @param[out] bytes_remain : Bytes remaining in the sensor FIFO
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_wakeup_fifo(uint8_t *fifo,
uint32_t fifo_len,
uint32_t *bytes_read,
uint32_t *bytes_remain,
struct bhy2_hif_dev *hif);
/**
* @brief Function to get data from the Non-wake-up FIFO
* @param[out] fifo : Reference to the data buffer to store data from the FIFO
* @param[in] fifo_len : Length of the data buffer
* @param[out] bytes_read : Number of bytes read into the data buffer
* @param[out] bytes_remain : Bytes remaining in the sensor FIFO
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_nonwakeup_fifo(uint8_t *fifo,
uint32_t fifo_len,
uint32_t *bytes_read,
uint32_t *bytes_remain,
struct bhy2_hif_dev *hif);
/**
* @brief Function to get synchronous data from the Status FIFO
* @param[out] status_code : Status code received
* @param[out] fifo : Reference to the data buffer to store the payload of the status code
* @param[in] fifo_len : Length of the data buffer
* @param[out] bytes_remain : Number of bytes in the payload
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_status_fifo(uint16_t *status_code,
uint8_t *fifo,
uint32_t fifo_len,
uint32_t *bytes_remain,
struct bhy2_hif_dev *hif);
/**
* @brief Function to get asynchronous data from the Status FIFO
* @param[out] fifo : Reference to the data buffer to store data from the FIFO
* @param[in] fifo_len : Length of the data buffer
* @param[out] bytes_read : Number of bytes read into the data buffer
* @param[out] bytes_remain : Bytes remaining in the sensor FIFO
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_status_fifo_async(uint8_t *fifo,
uint32_t fifo_len,
uint32_t *bytes_read,
uint32_t *bytes_remain,
struct bhy2_hif_dev *hif);
/**
* @brief Function to configure a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] sample_rate : Sample rate in Hz
* @param[in] latency : Report latency in milliseconds
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_exec_sensor_conf_cmd(uint8_t sensor_id,
bhy2_float sample_rate,
uint32_t latency,
struct bhy2_hif_dev *hif);
/**
* @brief Function to flush data of a virtual sensor from the FIFOs
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_fifo_flush(uint8_t sensor_id, struct bhy2_hif_dev *hif);
/**
* @brief Function to perform a self-test for a particular virtual sensor
* @param[in] phys_sensor_id : Physical sensor ID of the virtual sensor
* @param[out] self_test_resp : Reference to the data buffer to store the self-test response
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_do_self_test(uint8_t phys_sensor_id,
struct bhy2_self_test_resp *self_test_resp,
struct bhy2_hif_dev *hif);
/**
* @brief Function to perform a fast offset compensation for a particular virtual sensor
* @param[in] phys_sensor_id : Physical Sensor ID of the virtual sensor
* @param[out] foc_resp : Reference to the data buffer to store the FOC response
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_do_foc(uint8_t phys_sensor_id, struct bhy2_foc_resp *foc_resp, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the sensor control configuration of a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] ctrl_code : Sensor control code
* @param[out] payload : Reference to the data buffer to store the sensor control
* @param[in] payload_len : Length of the data buffer
* @param[out] actual_len : Actual length of the sensor control configuration
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_sensor_ctrl(uint8_t sensor_id,
uint8_t ctrl_code,
uint8_t *payload,
uint32_t payload_len,
uint32_t *actual_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to set the sensor control configuration of a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[in] ctrl_code : Sensor control code
* @param[in] payload : Reference to the data buffer storing the sensor control
* @param[in] payload_len : Length of the sensor control configuration
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_sensor_ctrl(uint8_t sensor_id,
uint8_t ctrl_code,
const uint8_t *payload,
uint32_t payload_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to get the BSX state of a BSX parameter
* @param[in] param_id : Parameter ID of the BSX parameter
* @param[out] bsx_state : Reference to teh data buffer to store the BSX state
* @param[in] state_len : Length of the buffer
* @param[out] actual_len : Actual length of the BSX state
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_bsx_state(uint16_t param_id,
uint8_t *bsx_state,
uint32_t state_len,
uint32_t *actual_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to the BSX state of a BSX parameter
* @param[in] param_id : Parameter ID of the BSX parameter
* @param[in] bsx_state : Reference to the data buffer storing the BSX state
* @param[in] state_len : Length of the BSX state
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_bsx_state(uint16_t param_id, const uint8_t *bsx_state, uint32_t state_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to request a timestamp event
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_request_hw_timestamp(struct bhy2_hif_dev *hif);
/**
* @brief Function to get the hardware timestamp
* @param[out] ts_ticks : Reference to the data buffer to store the timestamp in ticks
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif);
/**
* @brief Function to request and get the hardware timestamp
* @param[out] ts_ticks : Reference to the data buffer to store the timestamp in ticks
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_req_and_get_hw_timestamp(uint64_t *ts_ticks, struct bhy2_hif_dev *hif);
/**
* @brief Function to communicate with connected sensors
* @param[in] payload : Command payload
* @param[in] payload_len : Payload length
* @param[in/out] reg_data : Reference to the data buffer storing the register data
* @param[in] length : Length of the data buffer
* @param[out] actual_len : Registers actually read
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_exec_soft_passthrough(const uint8_t *payload,
uint32_t payload_len,
uint8_t *reg_data,
uint32_t length,
uint32_t *actual_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to get the post-mortem data dump
* @param[out] code : Post-mortem status code
* @param[out] actual_len : Actual length of the post-mortem data dump
* @param[out] post_mortem : Reference to the data buffer to store the data dump
* @param[in] buffer_len : Length of the data buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_post_mortem(uint16_t *code,
uint32_t *actual_len,
uint8_t *post_mortem,
uint32_t buffer_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function get information of a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[out] info : Reference to the data buffer to store the sensor info
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_sensor_info(uint8_t sensor_id, struct bhy2_sensor_info *info, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the physical sensor information of a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[out] info : Reference to the data buffer to store the physical sensor info
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_get_phys_sensor_info(uint8_t sensor_id, struct bhy2_phys_sensor_info *info, struct bhy2_hif_dev *hif);
/**
* @brief Function to get the orientation matrix of a virtual sensor
* @param[in] sensor_id : Sensor ID of the virtual sensor
* @param[out] orient_matrix : Reference to the data buffer to store the orientation matrix
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_orientation_matrix(uint8_t sensor_id,
struct bhy2_orient_matrix orient_matrix,
struct bhy2_hif_dev *hif);
/**
* @brief Function to set the data injection mode
* @param[in] payload : Reference to the data buffer containing the host injection mode
* @param[in] payload_len : Length of the data buffer
* @param[in/out] work_buf : Reference to the work buffer
* @param[in] work_buf_len : Length of the work buffer
* @param[out] actual_len : Expected length of the work buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_set_inject_data_mode(const uint8_t *payload,
uint8_t payload_len,
const uint8_t *work_buf,
uint32_t work_buf_len,
const uint32_t *actual_len,
struct bhy2_hif_dev *hif);
/**
* @brief Function to inject data
* @param[in] payload : Reference to the data buffer
* @param[in] payload_len : Length of the data buffer
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_inject_data(const uint8_t *payload, uint32_t payload_len, struct bhy2_hif_dev *hif);
/**
* @brief Function to wait till status is ready
* @param[in] hif : HIF device reference
* @return API error codes
*/
int8_t bhy2_hif_wait_status_ready(struct bhy2_hif_dev *hif);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHY2_HIF_H__ */

View File

@@ -0,0 +1,373 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_klio.c
* @date 2023-03-24
* @version v1.6.0
*
*/
/*********************************************************************/
/* system header files */
#include <string.h>
#include <stdio.h>
/*********************************************************************/
/* BHY2 SensorAPI header files */
#include "bhy2.h"
/*********************************************************************/
/* own header files */
#include "bhy2_klio.h"
int8_t bhy2_klio_read_pattern(const uint8_t id, uint8_t *buffer, uint16_t *length, struct bhy2_dev *dev)
{
int8_t rslt;
uint32_t ret_len;
bhy2_klio_pattern_transfer_t pattern = { 0 };
if (!buffer || !length || !dev)
{
return BHY2_E_NULL_PTR;
}
if (id != 0 || *length < sizeof(pattern.pattern_data))
{
return BHY2_E_INVALID_PARAM;
}
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN), (uint8_t*)&pattern, sizeof(pattern), &ret_len, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
if (ret_len != sizeof(pattern))
{
return BHY2_E_INVALID_PARAM;
}
memcpy(buffer, pattern.pattern_data, pattern.full_size);
*length = pattern.full_size;
return rslt;
}
int8_t bhy2_klio_read_reset_driver_status(uint32_t *klio_driver_status, struct bhy2_dev *dev)
{
uint32_t ret_len = 0;
int8_t rslt;
if (!klio_driver_status || !dev)
{
return BHY2_E_NULL_PTR;
}
do
{
rslt =
bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_DRIVER_STATUS),
(uint8_t*)klio_driver_status,
sizeof(*klio_driver_status),
&ret_len,
dev);
if (rslt != BHY2_OK)
{
return rslt;
}
} while (*klio_driver_status == KLIO_DRIVER_ERROR_OPERATION_PENDING);
return rslt;
}
int8_t bhy2_klio_write_pattern(const uint8_t idx, const uint8_t *pattern_data, const uint16_t size,
struct bhy2_dev *dev)
{
bhy2_klio_pattern_transfer_t pattern = {
.block_id = 0, .block_size = (uint8_t)size, .full_size = size, .pattern_id = idx, .pattern_data = { 0 }
};
if (!dev || size > sizeof(pattern.pattern_data))
{
return BHY2_E_INVALID_PARAM;
}
memcpy(pattern.pattern_data, pattern_data, size);
return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN), (const uint8_t*)&pattern, sizeof(pattern), dev);
}
int8_t bhy2_klio_set_pattern_states(const bhy2_klio_pattern_state_t operation,
const uint8_t *pattern_ids,
const uint16_t count,
struct bhy2_dev *dev)
{
uint32_t buffer_size = sizeof(bhy2_klio_pattern_state_op_t) + count;
uint8_t buffer[buffer_size];
if (!dev || count == 0)
{
return BHY2_E_INVALID_PARAM;
}
buffer[1] = (uint8_t)count;
buffer[0] = operation;
for (uint8_t i = 0; i < count; i++)
{
buffer[i + 2] = pattern_ids[i];
}
return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_STATE), buffer, buffer_size, dev);
}
int8_t bhy2_klio_set_state(const bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
uint8_t buffer[4];
if (!dev || !state)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
buffer[0] = state->learning_enabled;
buffer[1] = state->learning_reset;
buffer[2] = state->recognition_enabled;
buffer[3] = state->recognition_reset;
rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGORITHM_STATE), buffer, sizeof(buffer), dev);
}
return rslt;
}
int8_t bhy2_klio_get_state(bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
if (!dev || !state)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
uint8_t buffer[4];
uint32_t ret_len;
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGORITHM_STATE), buffer, sizeof(buffer), &ret_len, dev);
if (rslt == BHY2_OK && ret_len == sizeof(buffer))
{
state->learning_enabled = buffer[0];
state->learning_reset = buffer[1];
state->recognition_enabled = buffer[2];
state->recognition_reset = buffer[3];
}
}
return rslt;
}
int8_t bhy2_klio_similarity_score(const uint8_t *first_pattern,
const uint8_t *second_pattern,
const uint16_t size,
float *similarity,
struct bhy2_dev *dev)
{
uint32_t klio_driver_status = 0;
int8_t rslt;
uint32_t ret_len;
bhy2_klio_pattern_transfer_t pattern1 = { 0 }, pattern2 = { 0 };
uint8_t buffer[4];
if (!dev || size > sizeof(pattern1.pattern_data))
{
return BHY2_E_INVALID_PARAM;
}
pattern1.block_size = pattern2.block_size = (uint8_t)size;
pattern1.full_size = pattern2.full_size = size;
memcpy(pattern1.pattern_data, first_pattern, size);
memcpy(pattern2.pattern_data, second_pattern, size);
rslt =
bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)&pattern1, sizeof(pattern1), dev);
if (rslt != BHY2_OK)
{
return rslt;
}
rslt =
bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)&pattern2, sizeof(pattern2), dev);
if (rslt != BHY2_OK)
{
return rslt;
}
/* Wait for similarity calculation to complete. */
rslt = bhy2_klio_read_reset_driver_status(&klio_driver_status, dev);
if (rslt != BHY2_OK || klio_driver_status != KLIO_DRIVER_ERROR_NONE)
{
return BHY2_E_INVALID_PARAM;
}
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), buffer, sizeof(buffer), &ret_len, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
if (ret_len != sizeof(buffer))
{
return BHY2_E_INVALID_PARAM;
}
memcpy(similarity, buffer, sizeof(*similarity));
return BHY2_OK;
}
int8_t bhy2_klio_similarity_score_multiple(const uint8_t idx,
const uint8_t *indexes,
const uint8_t count,
float *similarity,
struct bhy2_dev *dev)
{
uint32_t klio_driver_status;
int8_t rslt;
uint32_t ret_len;
uint32_t buffer_size = sizeof(bhy2_klio_similarity_calculation_t) + count;
buffer_size = BHY2_ROUND_WORD_HIGHER(buffer_size);
uint8_t buffer[256] = { 0 };
if (!indexes || !similarity || !dev)
{
return BHY2_E_NULL_PTR;
}
/* buffer[0-3] values are initialized to zero's to distinguish from regular pattern comparison*/
buffer[4] = idx;
buffer[5] = count;
for (uint8_t i = 0; i < count; i++)
{
buffer[i + 6] = indexes[i];
}
/* Start similarity calculations. */
rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY), (uint8_t*)buffer, buffer_size, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
/* Wait for similarity calculation to complete. */
rslt = bhy2_klio_read_reset_driver_status(&klio_driver_status, dev);
if (rslt != BHY2_OK || klio_driver_status != KLIO_DRIVER_ERROR_NONE)
{
return BHY2_E_INVALID_PARAM;
}
/* Read similarity results. */
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_PATTERN_SIMILARITY),
(uint8_t *)similarity,
sizeof(float) * count,
&ret_len,
dev);
if (rslt != BHY2_OK)
{
return rslt;
}
return BHY2_OK;
}
int8_t bhy2_klio_set_parameter(const bhy2_klio_parameter_t id,
const void *parameter_data,
const uint16_t size,
struct bhy2_dev *dev)
{
bhy2_klio_parameter_wrapper_t buffer;
buffer.id = id;
buffer.flags = 0;
buffer.size = (uint8_t)size;
memcpy(buffer.payload.data, parameter_data, size);
/* Size is 3 bytes header and buffer.size then rounded up to a four byte multiple. */
return bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER),
(uint8_t*)&buffer,
(3 + buffer.size + 3) & ~3,
dev);
}
int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id,
uint8_t *parameter_data,
uint16_t *size,
struct bhy2_dev *dev)
{
uint32_t ret_len;
uint8_t buffer[260] = { 0 };
buffer[0] = id;
int8_t rslt;
/* Size is 3 bytes header and buffer.size then rounded up to a four byte multiple. */
rslt = bhy2_set_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), buffer, (3 + buffer[2] + 3) & ~3, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER), buffer, sizeof(buffer), &ret_len, dev);
if (rslt != BHY2_OK)
{
return rslt;
}
if (ret_len < 3 || buffer[2] > *size)
{
return BHY2_E_INVALID_PARAM;
}
for (uint16_t i = 3, j = 0; i < buffer[2] + 3; i++, j++)
{
parameter_data[j] = buffer[i];
}
*size = buffer[2];
return BHY2_OK;
}

View File

@@ -0,0 +1,227 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_klio.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHY2_KLIO_H__
#define __BHY2_KLIO_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <stdlib.h>
#include "bhy2.h"
#include "bhy2_klio_defs.h"
/*!
* @brief Reads and resets current driver status.
*
* The driver_status will be set to one of the values in
* @ref bhy2_klio_driver_error_state_t. This function will not return a driver
* status of
* @ref bhy2_klio_driver_error_state_t::KLIO_DRIVER_ERROR_OPERATION_PENDING.
* but will retry until the pending operation is finished.
*
* @param[out] driver_status Pointer to uint32_t
* @param[in] dev Device reference.
*
* @return BHY2 API error codes.
*/
int8_t bhy2_klio_read_reset_driver_status(uint32_t *driver_status, struct bhy2_dev *dev);
/*!
* @brief Read learnt pattern.
*
* @param[in] id pattern id (only 0 supported now)
* @param[out] buffer buffer big enough to fit complete pattern fingerprint data
* @param[in,out] length size of buffer, return size of actual pattern data
* @param[in] dev Device reference
*
* @return BHY2 API error codes.
*
* After learning of a new pattern has been signaled by a sensor data event,
* call this function to retrieve the learnt pattern.
*/
int8_t bhy2_klio_read_pattern(const uint8_t id, uint8_t *buffer, uint16_t *length, struct bhy2_dev *dev);
/*!
* @brief Set KLIO algorithm learning and recognition state.
*
* @param[in] state new state for algorithm
* @param[in] dev Device reference
*
* @return BHY2 API error codes.
*
* Writing 1 to the reset fields resets all internal algorithm state and
* removes any patterns loaded for recognition.
*/
int8_t bhy2_klio_set_state(const bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev);
/*!
* @brief Get KLIO algorithm learning and recognition state.
*
* @param[out] state current state for algorithm
* @param[in] dev Device reference
*
* @return BHY2 API error codes.
*
* The resets are always read as 0.
*/
int8_t bhy2_klio_get_state(bhy2_klio_sensor_state_t *state, struct bhy2_dev *dev);
/*!
* @brief Write pattern to recognition algorithm.
*
* @param[in] idx pattern index
* @param[in] pattern_data containing pattern
* @param[in] size pattern size
* @param[in] dev Device reference
*
* @return BHY2 API error codes.
*
* Write a pattern to the specified recognition index. The allowed number of
* recognition patterns may be retrieved using the
* @ref bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_MAX_PATTERNS parameter.
*
* After a pattern is written, it is in disabled state and not used. It must
* be enabled using @ref bhy2_klio_set_pattern_states() before it will be used
* by the recognition algorithm.
*/
int8_t bhy2_klio_write_pattern(const uint8_t idx, const uint8_t *pattern_data, const uint16_t size,
struct bhy2_dev *dev);
/*!
* @brief Sets the specified state for the specified pattern ids.
*
* @param[in] operation operation to perform
* @param[in] pattern_ids ids of pattern(s) to perform operation on
* @param[in] size size of pattern_ids array
* @param[in] dev Device reference
*
* @return BHY2 API error codes.
*/
int8_t bhy2_klio_set_pattern_states(const bhy2_klio_pattern_state_t operation,
const uint8_t *pattern_ids,
const uint16_t size,
struct bhy2_dev *dev);
/*!
* @brief Calculates similarity score between two patterns.
*
* The similariy between patterns is a meassure of the similarity between the
* performed activities or exercises. If the two patterns represent the same
* excercise the similarity will be close to 1.0, and if they are for very
* different excercises, the similarity will be negative.
*
* @param[in] first_pattern Buffer containing first pattern.
* @param[in] second_pattern Buffer containing second pattern.
* @param[in] size Pattern size.
* @param[out] similarity Similarity score.
* @param[in] dev Device reference.
*
* @return BHY2 API error codes.
*/
int8_t bhy2_klio_similarity_score(const uint8_t *first_pattern,
const uint8_t *second_pattern,
const uint16_t size,
float *similarity,
struct bhy2_dev *dev);
/*!
* @brief Calculates similarity score between multiple patterns.
*
* This is more efficient than bhy2_klio_similarity_score() since if the patterns
* are already available on the bhy2, they need not be uploaded again to
* perform the comparison. And several comparisons may be performed with one
* API call.
*
* @param[in] idx Reference pattern.
* @param[in] indexes Buffer containing indexes of patterns to compare reference pattern with.
* @param[in] count Number of patterns in indexes buffer.
* @param[out] similarity Similarity scores (one score for each pattern in indexes buffer).
* @param[in] dev Device reference.
*
* @return BHY2 API error codes.
*/
int8_t bhy2_klio_similarity_score_multiple(const uint8_t idx,
const uint8_t *indexes,
const uint8_t count,
float *similarity,
struct bhy2_dev *dev);
/*!
* @brief Set KLIO algorithm parameter
*
* @param[in] id Parameter to set.
* @param[in] parameter_data Buffer containing new parameter value.
* @param[in] size Parameter size.
* @param[in] dev Device reference.
*
* @return BHY2 API error codes.
*/
int8_t bhy2_klio_set_parameter(const bhy2_klio_parameter_t id,
const void *parameter_data,
const uint16_t size,
struct bhy2_dev *dev);
/*!
* @brief Get KLIO algorithm parameter
*
* @param[in] id Parameter id.
* @param[out] parameter_data Buffer to store parameter data.
* @param[in,out] size Parameter data size.
* @param[in] dev Device reference.
*
* @return BHY2 API error codes.
*
* The expected type or buffer size of parameter_data for respective parameter
* id is specified in the @ref bhy2_klio_parameter_t enum.
*/
int8_t bhy2_klio_get_parameter(const bhy2_klio_parameter_t id,
uint8_t *parameter_data,
uint16_t *size,
struct bhy2_dev *dev);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif

View File

@@ -0,0 +1,349 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_klio_defs.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHY2_KLIO_DEFS_H__
#define __BHY2_KLIO_DEFS_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#define BHY2_SENSOR_ID_KLIO UINT8_C(112)
#define BHY2_SENSOR_ID_KLIO_LOG UINT8_C(127)
#ifndef BHY2_KLIO_PAGE
#define BHY2_KLIO_PAGE UINT16_C(9)
#endif
#define KLIO_PARAM(id) (((BHY2_KLIO_PAGE) << 8) | (id))
/*!
* @enum bhy2_klio_parameter
*
* KLIO algorithm parameters
*
* @var bhy2_klio_parameter::KLIO_PARAM_ALGORITHM_VERSION
* Algorithm version. (read)
* @code{.c} char version[244]; @endcode
*
* @var bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_RESPONSIVNESS
* The approximate number of cycles / repetitions for recognition to recognize
* an activity. (read / write)
* @code{.c} float cycle_fraction; @endcode
*
* @var bhy2_klio_parameter::KLIO_PARAM_PATTERN_BLOB_SIZE
* Pattern blob size in bytes. (read)
* @code{.c} uint16_t pattern_blob_size; @endcode
*
* @var bhy2_klio_parameter::KLIO_PARAM_RECOGNITION_MAX_PATTERNS
* Read Maximum number of patterns. (read)
* @code{.c} uint16_t recognition_max_patterns; @endcode
*
* @var bhy2_klio_parameter::KLIO_PARAM_LEARNING_IGNORE_INSIG_MOVEMENT
* Flag if insignificant movements should be ignored in learning. Value 0 or 1. (read / write)
* @code{.c} uint8_t ignore_insig_movement; @endcode
*/
typedef enum
{
KLIO_PARAM_ALGORITHM_VERSION = 0,
KLIO_PARAM_RECOGNITION_SENSITIVITY = 1,
KLIO_PARAM_RECOGNITION_RESPONSIVNESS = 2,
KLIO_PARAM_LEARNING_SPEED = 3,
KLIO_PARAM_LEARNING_SIMILARITY_THRESHOLD = 4,
KLIO_PARAM_LEARNING_FREQUENCIES = 5,
KLIO_PARAM_LEARNING_PROGRESS = 6,
KLIO_PARAM_PATTERN_BLOB_SIZE = 7,
KLIO_PARAM_RECOGNITION_MAX_PATTERNS = 8,
KLIO_PARAM_INPUT_SENSORS = 9,
KLIO_PARAM_LEARNING_IGNORE_INSIG_MOVEMENT = 10
} bhy2_klio_parameter_t;
/*!
*
* @brief Convenience wrapper used in bhy2_klio.c algo parameter wrapper.
*
*/
typedef struct
{
uint8_t id;
uint8_t flags;
uint8_t size;
union
{
uint8_t data[244];
char version[244];
float cycle_fraction;
uint16_t pattern_blob_size;
uint16_t recognition_max_patterns;
uint8_t ignore_insig_movement;
} BHY2_PACKED payload;
} BHY2_PACKED bhy2_klio_parameter_wrapper_t;
/*!
*
* @brief bhy2 klio state structure
*
*/
typedef struct
{
uint8_t learning_enabled; /*!< 0 - disable learning, 1 - enable learning. */
uint8_t learning_reset; /*!< 0 - nop, 1 - reset learning. Always read as 0. */
uint8_t recognition_enabled; /*!< 0 - disable recognition, 1 - enable recognition. */
uint8_t recognition_reset; /*!< 0 - nop, 1 - reset learning. Always read as 0. */
} BHY2_PACKED bhy2_klio_sensor_state_t;
typedef struct
{
uint8_t instance;
/*!
* A value of -1 means no new learning has occurred. If the value is >= 0,
* then a new pattern has been learnt, and reading of this pattern may be
* performed.
*/
int8_t index;
/*!
* While learning a new pattern, this field counts from 0 to 100. When 100 is
* reached a new pattern will be learnt. If learning is interrupted, this
* progress will return to 0, and change reason will be set to indicate
* why learning was interrupted.
*/
uint8_t progress;
/*!
* | Value | Description |
* |:-----:|:-----------------------------------------------------------------------|
* | 0 | Learning is progressing. |
* | 1 | Learning was interrupted by a non-repetitive activity. |
* | 2 | Learning was interrupted because no significant movement was detected. |
*/
uint8_t change_reason;
} BHY2_PACKED bhy2_klio_sensor_frame_learning_t;
typedef struct
{
uint8_t instance;
/*! The index of the recognized activity. 255 means no activity was
* recognized. */
uint8_t index;
/*! The current repetition count of the recognized activity. */
float count;
} BHY2_PACKED bhy2_klio_sensor_frame_recognition_t;
/*!
*
* @brief bhy2 klio combined data structure
*
* When the algorithm generates a new data frame, it is sent in this structure.
*
*/
typedef struct
{
bhy2_klio_sensor_frame_learning_t learn;
bhy2_klio_sensor_frame_recognition_t recognize;
} BHY2_PACKED bhy2_klio_sensor_frame_t;
/*!
*
* @brief bhy2 klio sensor log frame
*
* When the algorithm consumes a new set of samples, it is sent in this structure.
*
*/
typedef struct
{
float timestamp;
float accel[3];
float gyro[3];
} BHY2_PACKED bhy2_klio_log_frame_t;
/*!
*
* @brief bhy2 klio pattern transfer format
*
*/
typedef struct
{
uint8_t block_id; /*!< Write as 0. */
uint8_t block_size; /*!< Write as 0. */
/*! Size of pattern_data in bytes. The size of patterns may be obtained
using the @ref bhy2_klio_parameter::KLIO_PARAM_PATTERN_BLOB_SIZE
parameter. */
uint16_t full_size;
/*! Id of pattern to write. */
uint8_t pattern_id;
/*! Actual pattern data describing the exercise. */
uint8_t pattern_data[244];
} BHY2_PACKED bhy2_klio_pattern_transfer_t;
/*!
*
* @brief Convenience wrapper used by @ref bhy2_klio_similarity_score_multiple().
*
*/
typedef struct
{
uint32_t zero;
uint8_t index;
uint8_t count;
uint8_t *indexes;
} BHY2_PACKED bhy2_klio_similarity_calculation_t;
/*!
*
* @brief Convenience wrapper used by @ref bhy2_klio_set_pattern_states().
*
*/
typedef struct
{
uint8_t operation;
uint8_t count;
uint8_t *indexes;
} BHY2_PACKED bhy2_klio_pattern_state_op_t;
/*!
* KLIO pattern state
*/
typedef enum
{
/*!< disable pattern */
KLIO_PATTERN_STATE_DISABLE = 0,
/*!< enable pattern */
KLIO_PATTERN_STATE_ENABLE = 1,
/*!< switch hand */
KLIO_PATTERN_STATE_SWITCH_HAND = 2,
/*!< disable adaptive pattern */
KLIO_PATTERN_STATE_AP_DISABLE = 3
} bhy2_klio_pattern_state_t;
/*!
* @brief KLIO host interface parameter identifiers.
*
* The parameter id used when calling the BHY2 functions directly. E.g. to read the driver status this may be used.
*
* ~~~{.c}
* uint32_t klio_driver_status = 0;
* uint32_t ret_len = 0;
* int8_t rslt = bhy2_get_parameter(KLIO_PARAM(KLIO_HIF_PARAM_DRIVER_STATUS),
* (uint8_t*)&klio_driver_status,
* sizeof(klio_driver_status),
* &ret_len,
* dev);
* if (rslt != BHY2_OK)
* {
* return rslt;
* }
* ~~~
*/
typedef enum
{
/*!< Read and write algorighm state. */
KLIO_HIF_PARAM_ALGORITHM_STATE = 0,
/*!< Read and write patterns. */
KLIO_HIF_PARAM_PATTERN = 1,
/*!< Read and write algorithm parameters. */
KLIO_HIF_PARAM_ALGO_DRIVER_PARAMETER = 2,
KLIO_HIF_PARAM_STATISTIC = 3,
KLIO_HIF_PARAM_PATTERN_STATE = 4,
/*!< Perform pattern similarity. */
KLIO_HIF_PARAM_PATTERN_SIMILARITY = 5,
KLIO_HIF_PARAM_PATTERN_COMBINING = 6,
/*!< Read driver status. */
KLIO_HIF_PARAM_DRIVER_STATUS = 7
} bhy2_klio_hif_parameter_t;
/*!
* KLIO driver error codes
*/
typedef enum
{
/*!< No error. */
KLIO_DRIVER_ERROR_NONE = 0,
/*!< Invalid parameter. */
KLIO_DRIVER_ERROR_INVALID_PARAMETER = 1,
/*!< Parameter out of range. */
KLIO_DRIVER_ERROR_PARAMETER_OUT_OF_RANGE = 2,
/*!
* Invalid pattern operation. E.g. trying to read a learnt pattern when no
* pattern has been learnt, or trying to write an invalid pattern.
*/
KLIO_DRIVER_ERROR_INVALID_PATTERN_OPERATION = 3,
/*!< Not implemented. */
KLIO_DRIVER_ERROR_NOT_IMPLEMENTED = 4,
/*!< Insufficient buffer size */
KLIO_DRIVER_ERROR_BUFSIZE = 5,
/*!< Internal error. */
KLIO_DRIVER_ERROR_INTERNAL = 6,
/*!< Undefined error */
KLIO_DRIVER_ERROR_UNDEFINED = 7,
/*!
* Previous operation is still progressing. Read driver status again until
* operation is finished.
*/
KLIO_DRIVER_ERROR_OPERATION_PENDING = 8
} bhy2_klio_driver_error_state_t;
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHY2_KLIO_DEFS_H__ */

View File

@@ -0,0 +1,96 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_parse.c
* @date 2023-03-24
* @version v1.6.0
*
*/
#include "bhy2.h"
#include "bhy2_parse.h"
void bhy2_parse_temperature_celsius(const uint8_t *data, bhy2_float *temperature)
{
/* 1 LSB = 1/100 degC */
float scale_factor = (float)1 / 100;
*temperature = BHY2_LE2S16(data) * scale_factor;
}
void bhy2_parse_humidity(const uint8_t *data, bhy2_float *humidity)
{
float scale_factor = (float)1;
*humidity = data[0] * scale_factor;
}
void bhy2_parse_pressure(const uint8_t *data, bhy2_float *pressure)
{
/* 1 LSB = 1/128 Pa */
float scale_factor = (float)1 / 128;
*pressure = (float)BHY2_LE2U24(data) * scale_factor;
}
void bhy2_parse_altitude(const uint8_t *data, bhy2_float *altitude)
{
*altitude = (float)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24));
}
void bhy2_parse_quaternion(const uint8_t *data, struct bhy2_data_quaternion *quaternion)
{
quaternion->x = BHY2_LE2S16(data);
quaternion->y = BHY2_LE2S16(data + 2);
quaternion->z = BHY2_LE2S16(data + 4);
quaternion->w = BHY2_LE2S16(data + 6);
quaternion->accuracy = BHY2_LE2U16(data + 8);
}
void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector)
{
vector->x = BHY2_LE2S16(data);
vector->y = BHY2_LE2S16(data + 2);
vector->z = BHY2_LE2S16(data + 4);
}
void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *orientation)
{
orientation->heading = BHY2_LE2S16(data);
orientation->pitch = BHY2_LE2S16(data + 2);
orientation->roll = BHY2_LE2S16(data + 4);
}
uint32_t bhy2_parse_step_counter(const uint8_t *data)
{
return (uint32_t)(data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24));
}

View File

@@ -0,0 +1,109 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_parse.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef __BHY2_PARSE_H__
#define __BHY2_PARSE_H__
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include "bhy2.h"
/**
* @brief Function to parse FIFO frame data into temperature
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] temperature : Reference to the data buffer to store temperature in degree C
*/
void bhy2_parse_temperature_celsius(const uint8_t *data, bhy2_float *temperature);
/**
* @brief Function to parse FIFO frame data into humidity
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] humidity : Reference to the data buffer to store humidity in %
*/
void bhy2_parse_humidity(const uint8_t *data, bhy2_float *humidity);
/**
* @brief Function to parse FIFO frame data into barometric pressure
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] pressure : Reference to the data buffer to store pressure in Pascals
*/
void bhy2_parse_pressure(const uint8_t *data, bhy2_float *pressure);
/**
* @brief Function to parse FIFO frame data into altitude
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] altitude : Reference to the data buffer to store altitude
*/
void bhy2_parse_altitude(const uint8_t *data, bhy2_float *altitude);
/**
* @brief Function to parse FIFO frame data into quaternion
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] quaternion : Reference to the data buffer to store quaternion
*/
void bhy2_parse_quaternion(const uint8_t *data, struct bhy2_data_quaternion *quaternion);
/**
* @brief Function to parse FIFO frame data into orientation
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] orientation : Reference to the data buffer to store orientation
*/
void bhy2_parse_orientation(const uint8_t *data, struct bhy2_data_orientation *orientation);
/**
* @brief Function to parse FIFO frame data into 3 axes vector
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @param[out] vector : Reference to the data buffer to store vector
*/
void bhy2_parse_xyz(const uint8_t *data, struct bhy2_data_xyz *vector);
/**
* @brief Function to parse FIFO frame data into step counter
* @param[in] data : Reference to the data buffer storing data from the FIFO
* @return[out] : Reference to the data buffer to step counter
*/
uint32_t bhy2_parse_step_counter(const uint8_t *data);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* __BHY2_PARSE_H__ */

View File

@@ -0,0 +1,203 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_swim.c
* @date 2023-03-24
* @version v1.6.0
*
*/
/*********************************************************************/
/* system header files */
/*********************************************************************/
#include <string.h>
#include <stdio.h>
/*********************************************************************/
/* BHY2 SensorAPI header files */
/*********************************************************************/
#include "bhy2.h"
/*********************************************************************/
/* own header files */
/*********************************************************************/
#include "bhy2_swim.h"
/*!
* @brief This API writes to the configuration parameter
* Config parameters are pool length and handedness
*
* @param[in] buffer to store swim configuration
* @param[out] dev hub handle.
*
* @return rslt execution result.
*/
int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
/*! Length of the configuration is 4 bytes */
uint32_t length = BHY2_SWIM_DATA_LENGTH;
/*! Swim Parameter page with offset 0 used for swim configuration*/
uint16_t param = BHY2_SWIM_CONFIG_PARAM;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Set the swim configuration parameter */
rslt = bhy2_set_parameter(param, (uint8_t *)buffer, length, dev);
}
return rslt;
}
/*!
* @brief To get the SWIM configuration parameters like swim length and handedness
*
* @param[out] buffer to store swim configuration
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhy2_swim_get_config(void *buffer, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
/*! Length of the configuration is 4 bytes */
uint32_t length = BHY2_SWIM_DATA_LENGTH;
uint32_t ret_length;
/*! Swim Parameter page with offset 0 used to store swim configuration*/
uint16_t param = BHY2_SWIM_CONFIG_PARAM;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the swim configuration from the parameter page*/
rslt = bhy2_get_parameter(param, buffer, length, &ret_length, dev);
if ((rslt == BHY2_OK) && (ret_length != BHY2_SWIM_DATA_LENGTH))
{
/*! Invalid number of parameters readout */
rslt = BHY2_E_INVALID_EVENT_SIZE;
}
}
return rslt;
}
/*!
* @brief To get the SWIM Algorithm version
*
* @param[out] buffer to store version data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhy2_swim_get_version(bhy2_swim_version_t *version, struct bhy2_dev *dev)
{
int8_t rslt = BHY2_OK;
/*! Buffer to store the swim version */
uint8_t buffer[4];
/*! Length of the configuration is 4 */
uint32_t length = BHY2_SWIM_DATA_LENGTH;
uint32_t ret_length;
/*! Swim Parameter page with offset 1 used to store swim algorithm version*/
uint16_t param = BHY2_SWIM_VERSION;
if (dev == NULL)
{
rslt = BHY2_E_NULL_PTR;
}
else
{
/*! Get the swim version from the parameter page */
rslt = bhy2_get_parameter(param, buffer, length, &ret_length, dev);
if ((rslt == BHY2_OK) && (ret_length != BHY2_SWIM_DATA_LENGTH))
{
/*! Invalid number of parameters readout */
rslt = BHY2_E_INVALID_EVENT_SIZE;
}
else
{
version->improvement = buffer[0];
version->platform = buffer[1];
version->bugfix = buffer[2];
}
}
return rslt;
}
/*!
* @brief Parsing the fifo data to SWIM output structure format
*
* @param[in] Swim data
* @param[out] bhy2_swim_aglo_output to store parameter data
*
* @return API error codes
*
*/
int8_t bhy2_swim_parse_data(const uint8_t *data, struct bhy2_swim_algo_output* output)
{
int8_t rslt = BHY2_OK;
if ((data == NULL) || (output == NULL))
{
rslt = BHY2_E_NULL_PTR;
}
else
{
output->total_distance = BHY2_LE2U16(data);
output->length_count = BHY2_LE2U16(data + 2);
output->lengths_freestyle = BHY2_LE2U16(data + 4);
output->lengths_breaststroke = BHY2_LE2U16(data + 6);
output->lengths_butterfly = BHY2_LE2U16(data + 8);
output->lengths_backstroke = BHY2_LE2U16(data + 10);
output->stroke_count = BHY2_LE2U16(data + 12);
}
return rslt;
}

View File

@@ -0,0 +1,101 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_swim.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHY2_SWIM_H_
#define _BHY2_SWIM_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
#include <stdlib.h>
#include "bhy2.h"
#include "bhy2_swim_defs.h"
/*!
* @brief Parsing the fifo data to SWIM output structure format
*
* @param[in] data parameter
* @param[out] bhy2_swim_aglo_output to store parameter data
*
* @return API error codes
*
*/
int8_t bhy2_swim_parse_data(const uint8_t *data, struct bhy2_swim_algo_output *output);
/*!
* @brief To get the SWIM configuration parameters like swim length and handedness
*
* @param[out] buffer to store parameter data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhy2_swim_get_config(void *buffer, struct bhy2_dev *dev);
/*!
* @brief To get the SWIM Algorithm version
*
* @param[out] buffer to store version data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhy2_swim_get_version(bhy2_swim_version_t *buffer, struct bhy2_dev *dev);
/*!
* @brief To set the SWIM configuration parameters like swim length and handedness
* @param[out] buffer to store parameter data
* @param[in] dev hub handle
*
* @return status code, BHY_HIF_E_SUCCESS in case of success
*
*/
int8_t bhy2_swim_set_config(const void *buffer, struct bhy2_dev *dev);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHY2_SWIM_H_ */

View File

@@ -0,0 +1,126 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bhy2_swim_defs.h
* @date 2023-03-24
* @version v1.6.0
*
*/
#ifndef _BHY2_SWIM_DEFS_H_
#define _BHY2_SWIM_DEFS_H_
/* Start of CPP Guard */
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus */
#include <stdint.h>
/*! Sensor ID for Swim */
#define BHY2_SENSOR_ID_SWIM UINT8_C(114)
/*! Swim Parameter Page Base Address*/
#define BHY2_SWIM_PAGE UINT16_C(0x0B)
/*! Swim Configuration pages */
#define BHY2_SWIM_CONFIG_PARAM (BHY2_SWIM_PAGE << 8)
#define BHY2_SWIM_VERSION ((BHY2_SWIM_PAGE << 8) | 1)
/*! Swim configurations enable/ disable from parameter page */
#define BHY2_SWIM_ENABLE_CONFIG UINT8_C(1)
#define BHY2_SWIM_DISABLE_CONFIG UINT8_C(0)
/*! Device in left/right hand */
#define BHY2_SWIM_DEVICE_ON_LEFT_HAND UINT8_C(1)
#define BHY2_SWIM_DEVICE_ON_RIGHT_HAND UINT8_C(0)
/*! Pool length */
#define BHY2_SWIM_POOL_LENGTH_25M UINT8_C(25)
#define BHY2_SWIM_POOL_LENGTH_50M UINT8_C(50)
#define BHY2_SWIM_DATA_LENGTH UINT8_C(4)
/*!
* bhy2 swim algo parameter.
*/
typedef struct bhy2_swim_config_param
{
uint8_t update_swim_config;
uint8_t dev_on_left_hand;
uint8_t pool_length_integral;
uint8_t pool_length_floating;
} __attribute__ ((packed)) bhy2_swim_config_param_t;
/*!
* swim output structure
*/
typedef struct bhy2_swim_algo_output
{
uint16_t total_distance;
uint16_t length_count;
uint16_t lengths_freestyle;
uint16_t lengths_breaststroke;
uint16_t lengths_butterfly;
uint16_t lengths_backstroke;
uint16_t stroke_count;
} __attribute__ ((packed)) bhy2_swim_algo_output_t;
/*!
* callback data capturing structure
*/
typedef struct bhy2_swim_data_parse
{
uint8_t sensor_id;
uint8_t data_size;
uint8_t *data_ptr;
uint64_t *time_stamp;
} bhy2_swim_data_parse_t;
/*! @brief structure definition to hold the version information of the software */
typedef struct bhy2_swim_version
{
uint8_t improvement;
uint8_t platform;
uint8_t bugfix;
uint8_t optional;
} bhy2_swim_version_t;
typedef void (*bhy2_swim_algo_callback)(uint32_t seconds, uint32_t nanoseconds,
const struct bhy2_swim_data_parse *callback_info);
/* End of CPP Guard */
#ifdef __cplusplus
}
#endif /*__cplusplus */
#endif /* _BHY2_SWIM_DEFS_H_ */

View File

@@ -0,0 +1,166 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file bosch_interfaces.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-09
*
*/
#include "bosch_interfaces.h"
#if defined(ARDUINO)
#if defined(ARDUINO_ARCH_RP2040)
SPISettings SensorInterfaces::__spiSetting = SPISettings();
#else
SPISettings SensorInterfaces::__spiSetting = SPISettings(4000000, SPI_DATA_ORDER, SPI_MODE0);
#endif
void SensorInterfaces::close_interfaces(SensorLibConfigure config)
{
}
bool SensorInterfaces::setup_interfaces(SensorLibConfigure config)
{
if (config.irq != SENSOR_PIN_NONE) {
pinMode(config.irq, INPUT_PULLDOWN);
}
switch (config.intf) {
case SENSORLIB_I2C_INTERFACE:
#if defined(ARDUINO_ARCH_RP2040)
config.u.i2c_dev.wire->end();
config.u.i2c_dev.wire->setSDA(config.u.i2c_dev.sda);
config.u.i2c_dev.wire->setSCL(config.u.i2c_dev.scl);
config.u.i2c_dev.wire->begin();
#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
config.u.i2c_dev.wire->end();
config.u.i2c_dev.wire->setPins(config.u.i2c_dev.sda, config.u.i2c_dev.scl);
config.u.i2c_dev.wire->begin();
#else
config.u.i2c_dev.wire->begin(config.u.i2c_dev.sda, config.u.i2c_dev.scl);
#endif
config.u.i2c_dev.wire->beginTransmission(config.u.i2c_dev.addr);
if (config.u.i2c_dev.wire->endTransmission() != 0) {
return false;
}
break;
case SENSORLIB_SPI_INTERFACE:
pinMode(config.u.spi_dev.cs, OUTPUT);
digitalWrite(config.u.spi_dev.cs, HIGH);
#if defined(ARDUINO_ARCH_RP2040)
config.u.spi_dev.spi->setSCK(config.u.spi_dev.sck);
config.u.spi_dev.spi->setRX(config.u.spi_dev.miso);
config.u.spi_dev.spi->setTX(config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin();
#elif defined(ARDUINO_ARCH_NRF52)
config.u.spi_dev.spi->setPins(config.u.spi_dev.miso, config.u.spi_dev.sck, config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin();
#elif defined(ARDUINO_ARCH_STM32)
config.u.spi_dev.spi->setSCLK(config.u.spi_dev.sck);
config.u.spi_dev.spi->setMISO(config.u.spi_dev.miso);
config.u.spi_dev.spi->setMOSI(config.u.spi_dev.mosi);
config.u.spi_dev.spi->begin();
#else
config.u.spi_dev.spi->begin(config.u.spi_dev.sck, config.u.spi_dev.miso, config.u.spi_dev.mosi);
#endif
break;
default:
break;
}
return true;
}
int8_t SensorInterfaces::bhy2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
if (!pConfig) {
return DEV_WIRE_ERR;
}
digitalWrite(pConfig->u.spi_dev.cs, LOW);
pConfig->u.spi_dev.spi->beginTransaction(__spiSetting);
pConfig->u.spi_dev.spi->transfer((reg_addr));
for (size_t i = 0; i < length; i++) {
reg_data[i] = pConfig->u.spi_dev.spi->transfer(0x00);
}
pConfig->u.spi_dev.spi->endTransaction();
digitalWrite(pConfig->u.spi_dev.cs, HIGH);
return DEV_WIRE_NONE;
}
int8_t SensorInterfaces::bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
if (!pConfig) {
return DEV_WIRE_ERR;
}
digitalWrite(pConfig->u.spi_dev.cs, LOW);
pConfig->u.spi_dev.spi->beginTransaction(__spiSetting);
pConfig->u.spi_dev.spi->transfer(reg_addr);
pConfig->u.spi_dev.spi->transfer((uint8_t *)reg_data, length);
pConfig->u.spi_dev.spi->endTransaction();
digitalWrite(pConfig->u.spi_dev.cs, HIGH);
return DEV_WIRE_NONE;
}
int8_t SensorInterfaces::bhy2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
if (!pConfig) {
return DEV_WIRE_ERR;
}
pConfig->u.i2c_dev.wire->beginTransmission(pConfig->u.i2c_dev.addr);
pConfig->u.i2c_dev.wire->write(reg_addr);
if (pConfig->u.i2c_dev.wire->endTransmission() != 0) {
return DEV_WIRE_ERR;
}
pConfig->u.i2c_dev.wire->requestFrom(pConfig->u.i2c_dev.addr, length);
return pConfig->u.i2c_dev.wire->readBytes(reg_data, length) == length ? DEV_WIRE_NONE : DEV_WIRE_ERR;
}
int8_t SensorInterfaces::bhy2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
SensorLibConfigure *pConfig = (SensorLibConfigure *)intf_ptr;
if (!pConfig) {
return DEV_WIRE_ERR;
}
pConfig->u.i2c_dev.wire->beginTransmission(pConfig->u.i2c_dev.addr);
pConfig->u.i2c_dev.wire->write(reg_addr);
pConfig->u.i2c_dev.wire->write(reg_data, length);
return (pConfig->u.i2c_dev.wire->endTransmission() == 0) ? 0 : DEV_WIRE_ERR;
}
void SensorInterfaces::bhy2_delay_us(uint32_t us, void *private_data)
{
(void)private_data;
delayMicroseconds(us);
}
#endif /*Arduino */

View File

@@ -0,0 +1,61 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file bosch_interfaces.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-09
*
*/
#pragma once
#include "SensorLib.h"
#if defined(ARDUINO)
class SensorInterfaces
{
public:
static bool setup_interfaces(SensorLibConfigure config);
static void close_interfaces(SensorLibConfigure config);
static int8_t bhy2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr);
static int8_t bhy2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr);
static int8_t bhy2_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr);
static int8_t bhy2_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr);
static void bhy2_delay_us(uint32_t us, void *private_data);
private:
static SPISettings __spiSetting;
};
#endif

View File

@@ -0,0 +1,987 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file common.c
* @brief Common source file for the BHy260 examples
* @note Adapting Arduino based on BHY2-Sensor-API by lewis
*/
#include "common.h"
#include "bosch/bhy2_parse.h"
#include "bosch/bhy2.h"
void time_to_s_ns(uint64_t time_ticks, uint32_t *s, uint32_t *ns, uint64_t *tns)
{
*tns = time_ticks * 15625; /* timestamp is now in nanoseconds */
*s = (uint32_t)(*tns / UINT64_C(1000000000));
*ns = (uint32_t)(*tns - ((*s) * UINT64_C(1000000000)));
}
const char *get_api_error(int8_t error_code)
{
const char *ret;
switch (error_code) {
case BHY2_OK:
ret = "[API Success]";
break;
case BHY2_E_NULL_PTR:
ret = "[API Error] Null pointer";
break;
case BHY2_E_INVALID_PARAM:
ret = "[API Error] Invalid parameter";
break;
case BHY2_E_IO:
ret = "[API Error] IO error";
break;
case BHY2_E_MAGIC:
ret = "[API Error] Invalid firmware";
break;
case BHY2_E_TIMEOUT:
ret = "[API Error] Timed out";
break;
case BHY2_E_BUFFER:
ret = "[API Error] Invalid buffer";
break;
case BHY2_E_INVALID_FIFO_TYPE:
ret = "[API Error] Invalid FIFO type";
break;
case BHY2_E_INVALID_EVENT_SIZE:
ret = "[API Error] Invalid Event size";
break;
case BHY2_E_PARAM_NOT_SET:
ret = "[API Error] Parameter not set";
break;
default:
ret = "[API Error] Unknown API error code";
}
return ret;
}
const char *get_sensor_error_text(uint8_t sensor_error)
{
const char *ret;
switch (sensor_error) {
case 0x00:
break;
case 0x10:
ret = "[Sensor error] Bootloader reports: Firmware Expected Version Mismatch";
break;
case 0x11:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Header CRC";
break;
case 0x12:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: SHA Hash Mismatch";
break;
case 0x13:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Image CRC";
break;
case 0x14:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: ECDSA Signature Verification Failed";
break;
case 0x15:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Bad Public Key CRC";
break;
case 0x16:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: Signed Firmware Required";
break;
case 0x17:
ret = "[Sensor error] Bootloader reports: Firmware Upload Failed: FW Header Missing";
break;
case 0x19:
ret = "[Sensor error] Bootloader reports: Unexpected Watchdog Reset";
break;
case 0x1A:
ret = "[Sensor error] ROM Version Mismatch";
break;
case 0x1B:
ret = "[Sensor error] Bootloader reports: Fatal Firmware Error";
break;
case 0x1C:
ret = "[Sensor error] Chained Firmware Error: Next Payload Not Found";
break;
case 0x1D:
ret = "[Sensor error] Chained Firmware Error: Payload Not Valid";
break;
case 0x1E:
ret = "[Sensor error] Chained Firmware Error: Payload Entries Invalid";
break;
case 0x1F:
ret = "[Sensor error] Bootloader reports: Bootloader Error: OTP CRC Invalid";
break;
case 0x20:
ret = "[Sensor error] Firmware Init Failed";
break;
case 0x21:
ret = "[Sensor error] Sensor Init Failed: Unexpected Device ID";
break;
case 0x22:
ret = "[Sensor error] Sensor Init Failed: No Response from Device";
break;
case 0x23:
ret = "[Sensor error] Sensor Init Failed: Unknown";
break;
case 0x24:
ret = "[Sensor error] Sensor Error: No Valid Data";
break;
case 0x25:
ret = "[Sensor error] Slow Sample Rate";
break;
case 0x26:
ret = "[Sensor error] Data Overflow (saturated sensor data)";
break;
case 0x27:
ret = "[Sensor error] Stack Overflow";
break;
case 0x28:
ret = "[Sensor error] Insufficient Free RAM";
break;
case 0x29:
ret = "[Sensor error] Sensor Init Failed: Driver Parsing Error";
break;
case 0x2A:
ret = "[Sensor error] Too Many RAM Banks Required";
break;
case 0x2B:
ret = "[Sensor error] Invalid Event Specified";
break;
case 0x2C:
ret = "[Sensor error] More than 32 On Change";
break;
case 0x2D:
ret = "[Sensor error] Firmware Too Large";
break;
case 0x2F:
ret = "[Sensor error] Invalid RAM Banks";
break;
case 0x30:
ret = "[Sensor error] Math Error";
break;
case 0x40:
ret = "[Sensor error] Memory Error";
break;
case 0x41:
ret = "[Sensor error] SWI3 Error";
break;
case 0x42:
ret = "[Sensor error] SWI4 Error";
break;
case 0x43:
ret = "[Sensor error] Illegal Instruction Error";
break;
case 0x44:
ret = "[Sensor error] Bootloader reports: Unhandled Interrupt Error / Exception / Postmortem Available";
break;
case 0x45:
ret = "[Sensor error] Invalid Memory Access";
break;
case 0x50:
ret = "[Sensor error] Algorithm Error: BSX Init";
break;
case 0x51:
ret = "[Sensor error] Algorithm Error: BSX Do Step";
break;
case 0x52:
ret = "[Sensor error] Algorithm Error: Update Sub";
break;
case 0x53:
ret = "[Sensor error] Algorithm Error: Get Sub";
break;
case 0x54:
ret = "[Sensor error] Algorithm Error: Get Phys";
break;
case 0x55:
ret = "[Sensor error] Algorithm Error: Unsupported Phys Rate";
break;
case 0x56:
ret = "[Sensor error] Algorithm Error: Cannot find BSX Driver";
break;
case 0x60:
ret = "[Sensor error] Sensor Self-Test Failure";
break;
case 0x61:
ret = "[Sensor error] Sensor Self-Test X Axis Failure";
break;
case 0x62:
ret = "[Sensor error] Sensor Self-Test Y Axis Failure";
break;
case 0x64:
ret = "[Sensor error] Sensor Self-Test Z Axis Failure";
break;
case 0x65:
ret = "[Sensor error] FOC Failure";
break;
case 0x66:
ret = "[Sensor error] Sensor Busy";
break;
case 0x6F:
ret = "[Sensor error] Self-Test or FOC Test Unsupported";
break;
case 0x72:
ret = "[Sensor error] No Host Interrupt Set";
break;
case 0x73:
ret = "[Sensor error] Event ID Passed to Host Interface Has No Known Size";
break;
case 0x75:
ret = "[Sensor error] Host Download Channel Underflow (Host Read Too Fast)";
break;
case 0x76:
ret = "[Sensor error] Host Upload Channel Overflow (Host Wrote Too Fast)";
break;
case 0x77:
ret = "[Sensor error] Host Download Channel Empty";
break;
case 0x78:
ret = "[Sensor error] DMA Error";
break;
case 0x79:
ret = "[Sensor error] Corrupted Input Block Chain";
break;
case 0x7A:
ret = "[Sensor error] Corrupted Output Block Chain";
break;
case 0x7B:
ret = "[Sensor error] Buffer Block Manager Error";
break;
case 0x7C:
ret = "[Sensor error] Input Channel Not Word Aligned";
break;
case 0x7D:
ret = "[Sensor error] Too Many Flush Events";
break;
case 0x7E:
ret = "[Sensor error] Unknown Host Channel Error";
break;
case 0x81:
ret = "[Sensor error] Decimation Too Large";
break;
case 0x90:
ret = "[Sensor error] Master SPI/I2C Queue Overflow";
break;
case 0x91:
ret = "[Sensor error] SPI/I2C Callback Error";
break;
case 0xA0:
ret = "[Sensor error] Timer Scheduling Error";
break;
case 0xB0:
ret = "[Sensor error] Invalid GPIO for Host IRQ";
break;
case 0xB1:
ret = "[Sensor error] Error Sending Initialized Meta Events";
break;
case 0xC0:
ret = "[Sensor error] Bootloader reports: Command Error";
break;
case 0xC1:
ret = "[Sensor error] Bootloader reports: Command Too Long";
break;
case 0xC2:
ret = "[Sensor error] Bootloader reports: Command Buffer Overflow";
break;
case 0xD0:
ret = "[Sensor error] User Mode Error: Sys Call Invalid";
break;
case 0xD1:
ret = "[Sensor error] User Mode Error: Trap Invalid";
break;
case 0xE1:
ret = "[Sensor error] Firmware Upload Failed: Firmware header corrupt";
break;
case 0xE2:
ret = "[Sensor error] Sensor Data Injection: Invalid input stream";
break;
default:
ret = "[Sensor error] Unknown error code";
}
return ret;
}
const char *get_sensor_name(uint8_t sensor_id)
{
const char *ret;
switch (sensor_id) {
case BHY2_SENSOR_ID_ACC_PASS:
ret = "Accelerometer passthrough";
break;
case BHY2_SENSOR_ID_ACC_RAW:
ret = "Accelerometer uncalibrated";
break;
case BHY2_SENSOR_ID_ACC:
ret = "Accelerometer corrected";
break;
case BHY2_SENSOR_ID_ACC_BIAS:
ret = "Accelerometer offset";
break;
case BHY2_SENSOR_ID_ACC_WU:
ret = "Accelerometer corrected wake up";
break;
case BHY2_SENSOR_ID_ACC_RAW_WU:
ret = "Accelerometer uncalibrated wake up";
break;
case BHY2_SENSOR_ID_GYRO_PASS:
ret = "Gyroscope passthrough";
break;
case BHY2_SENSOR_ID_GYRO_RAW:
ret = "Gyroscope uncalibrated";
break;
case BHY2_SENSOR_ID_GYRO:
ret = "Gyroscope corrected";
break;
case BHY2_SENSOR_ID_GYRO_BIAS:
ret = "Gyroscope offset";
break;
case BHY2_SENSOR_ID_GYRO_WU:
ret = "Gyroscope wake up";
break;
case BHY2_SENSOR_ID_GYRO_RAW_WU:
ret = "Gyroscope uncalibrated wake up";
break;
case BHY2_SENSOR_ID_MAG_PASS:
ret = "Magnetometer passthrough";
break;
case BHY2_SENSOR_ID_MAG_RAW:
ret = "Magnetometer uncalibrated";
break;
case BHY2_SENSOR_ID_MAG:
ret = "Magnetometer corrected";
break;
case BHY2_SENSOR_ID_MAG_BIAS:
ret = "Magnetometer offset";
break;
case BHY2_SENSOR_ID_MAG_WU:
ret = "Magnetometer wake up";
break;
case BHY2_SENSOR_ID_MAG_RAW_WU:
ret = "Magnetometer uncalibrated wake up";
break;
case BHY2_SENSOR_ID_GRA:
ret = "Gravity vector";
break;
case BHY2_SENSOR_ID_GRA_WU:
ret = "Gravity vector wake up";
break;
case BHY2_SENSOR_ID_LACC:
ret = "Linear acceleration";
break;
case BHY2_SENSOR_ID_LACC_WU:
ret = "Linear acceleration wake up";
break;
case BHY2_SENSOR_ID_RV:
ret = "Rotation vector";
break;
case BHY2_SENSOR_ID_RV_WU:
ret = "Rotation vector wake up";
break;
case BHY2_SENSOR_ID_GAMERV:
ret = "Game rotation vector";
break;
case BHY2_SENSOR_ID_GAMERV_WU:
ret = "Game rotation vector wake up";
break;
case BHY2_SENSOR_ID_GEORV:
ret = "Geo-magnetic rotation vector";
break;
case BHY2_SENSOR_ID_GEORV_WU:
ret = "Geo-magnetic rotation vector wake up";
break;
case BHY2_SENSOR_ID_ORI:
ret = "Orientation";
break;
case BHY2_SENSOR_ID_ORI_WU:
ret = "Orientation wake up";
break;
case BHY2_SENSOR_ID_ACC_BIAS_WU:
ret = "Accelerometer offset wake up";
break;
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
ret = "Gyroscope offset wake up";
break;
case BHY2_SENSOR_ID_MAG_BIAS_WU:
ret = "Magnetometer offset wake up";
break;
case BHY2_SENSOR_ID_TEMP:
ret = "Temperature";
break;
case BHY2_SENSOR_ID_BARO:
ret = "Barometer";
break;
case BHY2_SENSOR_ID_HUM:
ret = "Humidity";
break;
case BHY2_SENSOR_ID_GAS:
ret = "Gas";
break;
case BHY2_SENSOR_ID_TEMP_WU:
ret = "Temperature wake up";
break;
case BHY2_SENSOR_ID_BARO_WU:
ret = "Barometer wake up";
break;
case BHY2_SENSOR_ID_HUM_WU:
ret = "Humidity wake up";
break;
case BHY2_SENSOR_ID_GAS_WU:
ret = "Gas wake up";
break;
case BHY2_SENSOR_ID_KLIO:
ret = "Klio";
break;
case BHY2_SENSOR_ID_KLIO_LOG:
ret = "Klio log";
break;
case BHY2_SENSOR_ID_SWIM:
ret = "Swim recognition";
break;
case BHY2_SENSOR_ID_SI_ACCEL:
ret = "SI Accel";
break;
case BHY2_SENSOR_ID_SI_GYROS:
ret = "SI Gyro";
break;
case BHY2_SENSOR_ID_LIGHT:
ret = "Light";
break;
case BHY2_SENSOR_ID_LIGHT_WU:
ret = "Light wake up";
break;
case BHY2_SENSOR_ID_PROX:
ret = "Proximity";
break;
case BHY2_SENSOR_ID_PROX_WU:
ret = "Proximity wake up";
break;
case BHY2_SENSOR_ID_STC:
ret = "Step counter";
break;
case BHY2_SENSOR_ID_STC_WU:
ret = "Step counter wake up";
break;
case BHY2_SENSOR_ID_STC_LP:
ret = "Low Power Step counter";
break;
case BHY2_SENSOR_ID_STC_LP_WU:
ret = "Low Power Step counter wake up";
break;
case BHY2_SENSOR_ID_SIG:
ret = "Significant motion";
break;
case BHY2_SENSOR_ID_STD:
ret = "Step detector";
break;
case BHY2_SENSOR_ID_STD_WU:
ret = "Step detector wake up";
break;
case BHY2_SENSOR_ID_TILT_DETECTOR:
ret = "Tilt detector";
break;
case BHY2_SENSOR_ID_WAKE_GESTURE:
ret = "Wake gesture";
break;
case BHY2_SENSOR_ID_GLANCE_GESTURE:
ret = "Glance gesture";
break;
case BHY2_SENSOR_ID_PICKUP_GESTURE:
ret = "Pickup gesture";
break;
case BHY2_SENSOR_ID_SIG_LP:
ret = "Low Power Significant motion";
break;
case BHY2_SENSOR_ID_SIG_LP_WU:
ret = "Low Power Significant motion wake up";
break;
case BHY2_SENSOR_ID_STD_LP:
ret = "Low Power Step detector";
break;
case BHY2_SENSOR_ID_STD_LP_WU:
ret = "Low Power Step detector wake up";
break;
case BHY2_SENSOR_ID_AR:
ret = "Activity recognition";
break;
case BHY2_SENSOR_ID_EXCAMERA:
ret = "External camera trigger";
break;
case BHY2_SENSOR_ID_GPS:
ret = "GPS";
break;
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
ret = "Wrist tilt gesture";
break;
case BHY2_SENSOR_ID_DEVICE_ORI:
ret = "Device orientation";
break;
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
ret = "Device orientation wake up";
break;
case BHY2_SENSOR_ID_STATIONARY_DET:
ret = "Stationary detect";
break;
case BHY2_SENSOR_ID_ANY_MOTION_LP:
ret = "Low Power Any motion";
break;
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
ret = "Low Power Any motion wake up";
break;
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
ret = "Low Power No Motion wake up";
break;
case BHY2_SENSOR_ID_MOTION_DET:
ret = "Motion detect";
break;
case BHI3_SENSOR_ID_AR_WEAR_WU:
ret = "Activity recognition for Wearables";
break;
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
ret = "Low Power Wrist Wear wake up";
break;
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
ret = "Low Power Wrist Gesture wake up";
break;
case BHI3_SENSOR_ID_MULTI_TAP:
ret = "Multi Tap Detector";
break;
case BHY2_SENSOR_ID_AIR_QUALITY:
ret = "Air Quality";
break;
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
ret = "Head Misalignment Calibrator";
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
ret = "IMU Head Orientation Quaternion";
break;
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
ret = "NDOF Head Orientation Quaternion";
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
ret = "IMU Head Orientation Euler";
break;
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
ret = "NDOF Head Orientation Euler";
break;
default:
if ((sensor_id >= BHY2_SENSOR_ID_CUSTOM_START) && (sensor_id <= BHY2_SENSOR_ID_CUSTOM_END)) {
ret = "Custom sensor ID ";
} else {
ret = "Undefined sensor ID ";
}
}
return ret;
}
float get_sensor_default_scaling(uint8_t sensor_id)
{
float scaling = -1.0f;
switch (sensor_id) {
case BHY2_SENSOR_ID_ACC_PASS:
case BHY2_SENSOR_ID_ACC_RAW:
case BHY2_SENSOR_ID_ACC:
case BHY2_SENSOR_ID_ACC_BIAS:
case BHY2_SENSOR_ID_ACC_WU:
case BHY2_SENSOR_ID_ACC_RAW_WU:
case BHY2_SENSOR_ID_GRA:
case BHY2_SENSOR_ID_GRA_WU:
case BHY2_SENSOR_ID_LACC:
case BHY2_SENSOR_ID_LACC_WU:
case BHY2_SENSOR_ID_ACC_BIAS_WU:
scaling = 1.0f / 4096.0f;
break;
case BHY2_SENSOR_ID_GYRO_PASS:
case BHY2_SENSOR_ID_GYRO_RAW:
case BHY2_SENSOR_ID_GYRO:
case BHY2_SENSOR_ID_GYRO_BIAS:
case BHY2_SENSOR_ID_GYRO_WU:
case BHY2_SENSOR_ID_GYRO_RAW_WU:
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
scaling = 2000.0f / 32768.0f;
break;
case BHY2_SENSOR_ID_MAG_PASS:
case BHY2_SENSOR_ID_MAG_RAW:
case BHY2_SENSOR_ID_MAG:
case BHY2_SENSOR_ID_MAG_BIAS:
case BHY2_SENSOR_ID_MAG_WU:
case BHY2_SENSOR_ID_MAG_RAW_WU:
case BHY2_SENSOR_ID_MAG_BIAS_WU:
scaling = 2500.0f / 32768.0f;
break;
case BHY2_SENSOR_ID_RV:
case BHY2_SENSOR_ID_RV_WU:
case BHY2_SENSOR_ID_GAMERV:
case BHY2_SENSOR_ID_GAMERV_WU:
case BHY2_SENSOR_ID_GEORV:
case BHY2_SENSOR_ID_GEORV_WU:
scaling = 1.0f / 16384.0f;
break;
case BHY2_SENSOR_ID_ORI:
case BHY2_SENSOR_ID_ORI_WU:
scaling = 360.0f / 32768.0f;
break;
case BHY2_SENSOR_ID_TEMP:
case BHY2_SENSOR_ID_TEMP_WU:
scaling = 1.0f / 100.0f;
break;
case BHY2_SENSOR_ID_BARO:
case BHY2_SENSOR_ID_BARO_WU:
scaling = 100.0f / 128.0f;
break;
case BHY2_SENSOR_ID_HUM:
case BHY2_SENSOR_ID_HUM_WU:
scaling = 1.0f;
break;
case BHY2_SENSOR_ID_GAS:
case BHY2_SENSOR_ID_GAS_WU:
scaling = 1.0f;
break;
case BHY2_SENSOR_ID_LIGHT:
case BHY2_SENSOR_ID_LIGHT_WU:
scaling = 10000.0f / 216.0f;
break;
case BHY2_SENSOR_ID_PROX:
case BHY2_SENSOR_ID_PROX_WU:
scaling = 1.0f;
break;
case BHY2_SENSOR_ID_SI_ACCEL:
case BHY2_SENSOR_ID_SI_GYROS:
/* Scaling factor already applied in firmware*/
break;
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
scaling = 1.0f / 16384.0f; /*2^14 -> 16384*/
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
scaling = 360.0f / 32768.0f; /*2^15 -> 32768*/
break;
default:
scaling = -1.0f; /* Do not apply the scaling factor */
}
return scaling;
}
const char *get_sensor_parse_format(uint8_t sensor_id)
{
const char *ret;
switch (sensor_id) {
case BHY2_SENSOR_ID_ACC_PASS:
case BHY2_SENSOR_ID_ACC_RAW:
case BHY2_SENSOR_ID_ACC:
case BHY2_SENSOR_ID_ACC_BIAS:
case BHY2_SENSOR_ID_ACC_BIAS_WU:
case BHY2_SENSOR_ID_ACC_WU:
case BHY2_SENSOR_ID_ACC_RAW_WU:
case BHY2_SENSOR_ID_GYRO_PASS:
case BHY2_SENSOR_ID_GYRO_RAW:
case BHY2_SENSOR_ID_GYRO:
case BHY2_SENSOR_ID_GYRO_BIAS:
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
case BHY2_SENSOR_ID_GYRO_WU:
case BHY2_SENSOR_ID_GYRO_RAW_WU:
case BHY2_SENSOR_ID_MAG_PASS:
case BHY2_SENSOR_ID_MAG_RAW:
case BHY2_SENSOR_ID_MAG:
case BHY2_SENSOR_ID_MAG_BIAS:
case BHY2_SENSOR_ID_MAG_BIAS_WU:
case BHY2_SENSOR_ID_MAG_WU:
case BHY2_SENSOR_ID_MAG_RAW_WU:
case BHY2_SENSOR_ID_GRA:
case BHY2_SENSOR_ID_GRA_WU:
case BHY2_SENSOR_ID_LACC:
case BHY2_SENSOR_ID_LACC_WU:
ret = "s16,s16,s16";
break;
case BHY2_SENSOR_ID_RV:
case BHY2_SENSOR_ID_RV_WU:
case BHY2_SENSOR_ID_GAMERV:
case BHY2_SENSOR_ID_GAMERV_WU:
case BHY2_SENSOR_ID_GEORV:
case BHY2_SENSOR_ID_GEORV_WU:
ret = "s16,s16,s16,s16,u16";
break;
case BHY2_SENSOR_ID_ORI:
case BHY2_SENSOR_ID_ORI_WU:
ret = "s16,s16,s16";
break;
case BHY2_SENSOR_ID_DEVICE_ORI:
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
case BHY2_SENSOR_ID_HUM:
case BHY2_SENSOR_ID_HUM_WU:
case BHY2_SENSOR_ID_PROX:
case BHY2_SENSOR_ID_PROX_WU:
case BHY2_SENSOR_ID_EXCAMERA:
case BHI3_SENSOR_ID_MULTI_TAP:
ret = "u8";
break;
case BHY2_SENSOR_ID_TEMP:
case BHY2_SENSOR_ID_TEMP_WU:
ret = "s16";
break;
case BHY2_SENSOR_ID_BARO:
case BHY2_SENSOR_ID_BARO_WU:
ret = "u24";
break;
case BHY2_SENSOR_ID_GAS:
case BHY2_SENSOR_ID_GAS_WU:
case BHY2_SENSOR_ID_STC:
case BHY2_SENSOR_ID_STC_WU:
case BHY2_SENSOR_ID_STC_LP:
case BHY2_SENSOR_ID_STC_LP_WU:
ret = "u32";
break;
case BHY2_SENSOR_ID_KLIO:
ret = "u8,u8,u8,u8,u8,u8,f";
break;
case BHY2_SENSOR_ID_SWIM:
ret = "u16,u16,u16,u16,u16,u16,u16";
break;
case BHY2_SENSOR_ID_SI_ACCEL:
case BHY2_SENSOR_ID_SI_GYROS:
ret = "f,f,f";
break;
case BHY2_SENSOR_ID_LIGHT:
case BHY2_SENSOR_ID_LIGHT_WU:
ret = "s16";
break;
case BHY2_SENSOR_ID_SIG:
case BHY2_SENSOR_ID_STD:
case BHY2_SENSOR_ID_STD_WU:
case BHY2_SENSOR_ID_TILT_DETECTOR:
case BHY2_SENSOR_ID_WAKE_GESTURE:
case BHY2_SENSOR_ID_GLANCE_GESTURE:
case BHY2_SENSOR_ID_PICKUP_GESTURE:
case BHY2_SENSOR_ID_SIG_LP:
case BHY2_SENSOR_ID_SIG_LP_WU:
case BHY2_SENSOR_ID_STD_LP:
case BHY2_SENSOR_ID_STD_LP_WU:
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
case BHY2_SENSOR_ID_STATIONARY_DET:
case BHY2_SENSOR_ID_ANY_MOTION_LP:
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
case BHY2_SENSOR_ID_MOTION_DET:
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
ret = "";
break;
case BHY2_SENSOR_ID_AR:
case BHI3_SENSOR_ID_AR_WEAR_WU:
ret = "u16";
break;
case BHY2_SENSOR_ID_GPS:
ret = "st";
break;
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
ret = "u8";
break;
case BHY2_SENSOR_ID_AIR_QUALITY:
ret = "f32,f32,f32,f32,f32,f32,f32,u8";
break;
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
ret = "s16,s16,s16,s16,u8";
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
ret = "s16,s16,s16,u8";
break;
default:
ret = "";
}
return ret;
}
const char *get_sensor_axis_names(uint8_t sensor_id)
{
const char *ret;
switch (sensor_id) {
case BHY2_SENSOR_ID_ACC_PASS:
case BHY2_SENSOR_ID_ACC_RAW:
case BHY2_SENSOR_ID_ACC:
case BHY2_SENSOR_ID_ACC_BIAS:
case BHY2_SENSOR_ID_ACC_BIAS_WU:
case BHY2_SENSOR_ID_ACC_WU:
case BHY2_SENSOR_ID_ACC_RAW_WU:
case BHY2_SENSOR_ID_GYRO_PASS:
case BHY2_SENSOR_ID_GYRO_RAW:
case BHY2_SENSOR_ID_GYRO:
case BHY2_SENSOR_ID_GYRO_BIAS:
case BHY2_SENSOR_ID_GYRO_BIAS_WU:
case BHY2_SENSOR_ID_GYRO_WU:
case BHY2_SENSOR_ID_GYRO_RAW_WU:
case BHY2_SENSOR_ID_MAG_PASS:
case BHY2_SENSOR_ID_MAG_RAW:
case BHY2_SENSOR_ID_MAG:
case BHY2_SENSOR_ID_MAG_BIAS:
case BHY2_SENSOR_ID_MAG_BIAS_WU:
case BHY2_SENSOR_ID_MAG_WU:
case BHY2_SENSOR_ID_MAG_RAW_WU:
case BHY2_SENSOR_ID_GRA:
case BHY2_SENSOR_ID_GRA_WU:
case BHY2_SENSOR_ID_LACC:
case BHY2_SENSOR_ID_LACC_WU:
case BHY2_SENSOR_ID_SI_ACCEL:
case BHY2_SENSOR_ID_SI_GYROS:
ret = "x,y,z";
break;
case BHY2_SENSOR_ID_RV:
case BHY2_SENSOR_ID_RV_WU:
case BHY2_SENSOR_ID_GAMERV:
case BHY2_SENSOR_ID_GAMERV_WU:
case BHY2_SENSOR_ID_GEORV:
case BHY2_SENSOR_ID_GEORV_WU:
ret = "x,y,z,w,ar";
break;
case BHY2_SENSOR_ID_ORI:
case BHY2_SENSOR_ID_ORI_WU:
ret = "h,p,r";
break;
case BHY2_SENSOR_ID_DEVICE_ORI:
case BHY2_SENSOR_ID_DEVICE_ORI_WU:
ret = "o";
break;
case BHY2_SENSOR_ID_TEMP:
case BHY2_SENSOR_ID_TEMP_WU:
ret = "t";
break;
case BHY2_SENSOR_ID_BARO:
case BHY2_SENSOR_ID_BARO_WU:
ret = "p";
break;
case BHY2_SENSOR_ID_HUM:
case BHY2_SENSOR_ID_HUM_WU:
ret = "h";
break;
case BHY2_SENSOR_ID_GAS:
case BHY2_SENSOR_ID_GAS_WU:
ret = "g";
break;
case BHY2_SENSOR_ID_KLIO:
ret = "lin,lid,lpr,lcr,rin,rid,rc";
break;
case BHY2_SENSOR_ID_SWIM:
ret = "d,lc,f,br,bu,ba,sc";
break;
case BHY2_SENSOR_ID_LIGHT:
case BHY2_SENSOR_ID_LIGHT_WU:
ret = "l";
break;
case BHY2_SENSOR_ID_PROX:
case BHY2_SENSOR_ID_PROX_WU:
ret = "p";
break;
case BHY2_SENSOR_ID_STC:
case BHY2_SENSOR_ID_STC_WU:
case BHY2_SENSOR_ID_STC_LP:
case BHY2_SENSOR_ID_STC_LP_WU:
case BHY2_SENSOR_ID_EXCAMERA:
ret = "c";
break;
case BHY2_SENSOR_ID_SIG:
case BHY2_SENSOR_ID_STD:
case BHY2_SENSOR_ID_STD_WU:
case BHY2_SENSOR_ID_TILT_DETECTOR:
case BHY2_SENSOR_ID_WAKE_GESTURE:
case BHY2_SENSOR_ID_GLANCE_GESTURE:
case BHY2_SENSOR_ID_PICKUP_GESTURE:
case BHY2_SENSOR_ID_SIG_LP:
case BHY2_SENSOR_ID_SIG_LP_WU:
case BHY2_SENSOR_ID_STD_LP:
case BHY2_SENSOR_ID_STD_LP_WU:
case BHY2_SENSOR_ID_WRIST_TILT_GESTURE:
case BHY2_SENSOR_ID_STATIONARY_DET:
case BHY2_SENSOR_ID_ANY_MOTION_LP:
case BHY2_SENSOR_ID_ANY_MOTION_LP_WU:
case BHI3_SENSOR_ID_NO_MOTION_LP_WU:
case BHY2_SENSOR_ID_MOTION_DET:
case BHI3_SENSOR_ID_WRIST_WEAR_LP_WU:
ret = "e";
break;
case BHY2_SENSOR_ID_AR:
case BHI3_SENSOR_ID_AR_WEAR_WU:
ret = "a";
break;
case BHY2_SENSOR_ID_GPS:
ret = "g";
break;
case BHI3_SENSOR_ID_WRIST_GEST_DETECT_LP_WU:
ret = "wrist_gesture";
break;
case BHI3_SENSOR_ID_MULTI_TAP:
ret = "taps";
break;
case BHY2_SENSOR_ID_AIR_QUALITY:
ret = "t,h,g,i,si,c,v,a";
break;
case BHY2_SENSOR_ID_HEAD_ORI_MIS_ALG:
case BHY2_SENSOR_ID_IMU_HEAD_ORI_Q:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_Q:
ret = "x,y,z,w,a";
break;
case BHY2_SENSOR_ID_IMU_HEAD_ORI_E:
case BHY2_SENSOR_ID_NDOF_HEAD_ORI_E:
ret = "h,p,r,a";
break;
default:
ret = "";
}
return ret;
}
void check_bhy2_api(unsigned int line, const char *func, int8_t val)
{
int i = 3;
while (i--) {
Serial.printf("BHI260 API failed at line %u. The function %s returned error code %d. %s\r\n",
line,
func,
val,
get_api_error(val));
delay(1000);
}
}

View File

@@ -0,0 +1,65 @@
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file common.h
* @brief Common header file for the BHI260/BHA260 examples
* @note Adapting Arduino based on BHY2-Sensor-API by lewis
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#include "bosch_interfaces.h"
#include "bosch/bhy2.h"
#include "bosch/bhi3.h"
#include "bosch/bhi3_multi_tap.h"
#include "bosch/bhy2_klio.h"
#include "bosch/bhy2_swim.h"
#include "bosch/bhy2_bsec.h"
#include "bosch/bhy2_head_tracker.h"
#define BHY2_ASSERT(x) if (x) check_bhy2_api(__LINE__, __FUNCTION__, x)
void check_bhy2_api(unsigned int line, const char *func, int8_t val);
void time_to_s_ns(uint64_t time_ticks, uint32_t *s, uint32_t *ns, uint64_t *tns);
const char *get_api_error(int8_t error_code);
const char *get_sensor_error_text(uint8_t sensor_error);
const char *get_sensor_name(uint8_t sensor_id);
float get_sensor_default_scaling(uint8_t sensor_id);
const char *get_sensor_parse_format(uint8_t sensor_id);
const char *get_sensor_axis_names(uint8_t sensor_id);
#endif /* _COMMON_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,66 @@
/**
* @file esp_arduino.cpp
* @author Lewis He (lewishe@outlook.com)
* @license MIT
* @copyright Copyright (c) 2024 Shenzhen Xinyuan Electronic Technology Co., Ltd
* @date 2024-01-08
*
*/
#if !defined(ARDUINO) && defined(ESP_PLATFORM)
#include "SensorLib.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include <rom/ets_sys.h>
void pinMode(uint32_t gpio, uint8_t mode)
{
gpio_config_t config;
memset(&config, 0, sizeof(config));
config.pin_bit_mask = 1ULL << gpio;
switch (mode) {
case INPUT:
config.mode = GPIO_MODE_INPUT;
break;
case OUTPUT:
config.mode = GPIO_MODE_OUTPUT;
break;
}
config.pull_up_en = GPIO_PULLUP_DISABLE;
config.pull_down_en = GPIO_PULLDOWN_DISABLE;
config.intr_type = GPIO_INTR_DISABLE;
ESP_ERROR_CHECK(gpio_config(&config));
}
void digitalWrite(uint32_t gpio, uint8_t level)
{
gpio_set_level((gpio_num_t )gpio, level);
}
int digitalRead(uint32_t gpio)
{
return gpio_get_level((gpio_num_t)gpio);
}
void delay(uint32_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
ets_delay_us((ms % portTICK_PERIOD_MS) * 1000UL);
}
uint32_t millis()
{
return (uint32_t) (esp_timer_get_time() / 1000LL);
}
uint32_t micros()
{
return (uint32_t) esp_timer_get_time();
}
void delayMicroseconds(uint32_t us)
{
ets_delay_us(us);
}
#endif

View File

@@ -0,0 +1,22 @@
/**
* @file esp_arduino.h
* @author Lewis He (lewishe@outlook.com)
* @license MIT
* @copyright Copyright (c) 2024 Shenzhen Xinyuan Electronic Technology Co., Ltd
* @date 2024-01-08
*
*/
#pragma once
#if !defined(ARDUINO) && defined(ESP_PLATFORM)
void pinMode(uint32_t gpio, uint8_t mode);
void digitalWrite(uint32_t gpio, uint8_t level);
int digitalRead(uint32_t gpio);
void delay(uint32_t ms);
uint32_t millis();
uint32_t micros();
void delayMicroseconds(uint32_t us);
#endif

View File

@@ -0,0 +1,323 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchClassCST226.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-06
*/
#include "TouchClassCST226.h"
#define CST2xx_REG_STATUS (0x00)
#define CST226SE_BUFFER_NUM (28)
#if defined(ARDUINO)
TouchClassCST226::TouchClassCST226()
{
}
bool TouchClassCST226::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl)
{
return SensorCommon::begin(wire, address, sda, scl);
}
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool TouchClassCST226::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
return SensorCommon::begin(i2c_dev_bus_handle, addr);
}
#else
bool TouchClassCST226::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
return SensorCommon::begin(port_num, addr, sda, scl);
}
#endif //ESP_IDF_VERSION
#endif //ARDUINO
bool TouchClassCST226::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
}
void TouchClassCST226::reset()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
this->setGpioLevel(__rst, LOW);
delay(100);
this->setGpioLevel(__rst, HIGH);
delay(100);
} else {
writeRegister(0xD1, 0x0E);
delay(20);
}
}
uint8_t TouchClassCST226::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point)
{
uint8_t buffer[CST226SE_BUFFER_NUM];
uint8_t index = 0;
if (readRegister(CST2xx_REG_STATUS, buffer, CST226SE_BUFFER_NUM) == DEV_WIRE_ERR) {
return 0;
}
#ifdef LOG_PORT
LOG_PORT.print("RAW:");
for (int i = 0; i < CST226SE_BUFFER_NUM; ++i) {
LOG_PORT.printf("%02X,", buffer[i]);
}
LOG_PORT.println();
#endif
if (buffer[0] == 0x83 && buffer[1] == 0x17 && buffer[5] == 0x80) {
if (__homeButtonCb) {
__homeButtonCb(__userData);
}
return 0;
}
if (buffer[6] != 0xAB)return 0;
if (buffer[0] == 0xAB)return 0;
if (buffer[5] == 0x80)return 0;
uint8_t point = buffer[5] & 0x7F;
if (point > 5 || !point) {
writeRegister(0x00, 0xAB);
return 0;
}
for (int i = 0; i < point; i++) {
report.id[i] = buffer[index] >> 4;
report.status[i] = buffer[index] & 0x0F;
report.x[i] = (uint16_t)((buffer[index + 1] << 4) | ((buffer[index + 3] >> 4) & 0x0F));
report.y[i] = (uint16_t)((buffer[index + 2] << 4) | (buffer[index + 3] & 0x0F));
report.pressure[i] = buffer[index + 4];
index = (i == 0) ? (index + 7) : (index + 5);
}
updateXY(point, report.x, report.y);
#ifdef LOG_PORT
for (int i = 0; i < point; i++) {
LOG_PORT.printf("[%d]-X:%u Y:%u P:%u sta:%u ", report.id[i], report.x[i], report.y[i], report.pressure[i], report.status[i]);
}
LOG_PORT.println();
#endif
if (point) {
for (int i = 0; i < get_point; i++) {
x_array[i] = report.x[i];
y_array[i] = report.y[i];
}
}
return point;
}
bool TouchClassCST226::isPressed()
{
static uint32_t lastPulse = 0;
if (__irq != SENSOR_PIN_NONE) {
int val = this->getGpioLevel(__irq) == LOW;
if (val) {
//Filter low levels with intervals greater than 1000ms
val = (millis() - lastPulse > 1000) ? false : true;
lastPulse = millis();
return val;
}
return false;
}
return getPoint(NULL, NULL, 1);
}
const char *TouchClassCST226::getModelName()
{
return "CST226SE";
}
void TouchClassCST226::sleep()
{
writeRegister(0xD1, 0x05);
#ifdef ESP32
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, OPEN_DRAIN);
}
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OPEN_DRAIN);
}
#endif
}
void TouchClassCST226::wakeup()
{
reset();
}
void TouchClassCST226::idle()
{
}
uint8_t TouchClassCST226::getSupportTouchPoint()
{
return 5;
}
bool TouchClassCST226::getResolution(int16_t *x, int16_t *y)
{
return false;
}
void TouchClassCST226::setHomeButtonCallback(home_button_callback_t cb, void *user_data)
{
__homeButtonCb = cb;
__userData = user_data;
}
void TouchClassCST226::setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb)
{
SensorCommon::setGpioModeCallback(mode_cb);
SensorCommon::setGpioWriteCallback(write_cb);
SensorCommon::setGpioReadCallback(read_cb);
}
bool TouchClassCST226::initImpl()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
}
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, INPUT);
}
reset();
uint8_t buffer[8];
// Enter Command mode
writeRegister(0xD1, 0x01);
delay(10);
uint8_t write_buffer[2] = {0xD1, 0xFC};
writeThenRead(write_buffer, 2, buffer, 4);
uint32_t checkcode = 0;
checkcode = buffer[3];
checkcode <<= 8;
checkcode |= buffer[2];
checkcode <<= 8;
checkcode |= buffer[1];
checkcode <<= 8;
checkcode |= buffer[0];
log_i("Chip checkcode:0x%lx.\r\n", checkcode);
write_buffer[0] = {0xD1};
write_buffer[1] = {0xF8};
writeThenRead(write_buffer, 2, buffer, 4);
__resX = ( buffer[1] << 8) | buffer[0];
__resY = ( buffer[3] << 8) | buffer[2];
log_i("Chip resolution X:%u Y:%u\r\n", __resX, __resY);
write_buffer[0] = {0xD2};
write_buffer[1] = {0x04};
writeThenRead(write_buffer, 2, buffer, 4);
uint32_t chipType = buffer[3];
chipType <<= 8;
chipType |= buffer[2];
uint32_t ProjectID = buffer[1];
ProjectID <<= 8;
ProjectID |= buffer[0];
log_i("Chip type :0x%lx, ProjectID:0X%lx\r\n",
chipType, ProjectID);
write_buffer[0] = {0xD2};
write_buffer[1] = {0x08};
writeThenRead(write_buffer, 2, buffer, 8);
uint32_t fwVersion = buffer[3];
fwVersion <<= 8;
fwVersion |= buffer[2];
fwVersion <<= 8;
fwVersion |= buffer[1];
fwVersion <<= 8;
fwVersion |= buffer[0];
uint32_t checksum = buffer[7];
checksum <<= 8;
checksum |= buffer[6];
checksum <<= 8;
checksum |= buffer[5];
checksum <<= 8;
checksum |= buffer[4];
log_i("Chip ic version:0x%lx, checksum:0x%lx\n",
fwVersion, checksum);
if (fwVersion == 0xA5A5A5A5) {
log_i("Chip ic don't have firmware. \n");
return false;
}
if ((checkcode & 0xffff0000) != 0xCACA0000) {
log_i("Firmware info read error .\n");
return false;
}
__chipID = chipType;
// Exit Command mode
writeRegister(0xD1, 0x09);
return true;
}
int TouchClassCST226::getReadMaskImpl()
{
return -1;
}

View File

@@ -0,0 +1,97 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchClassCST226.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-06
*/
#pragma once
#include "../TouchDrvInterface.hpp"
#include "../SensorCommon.tpp"
class TouchClassCST226 : public TouchDrvInterface,
public SensorCommon<TouchClassCST226>
{
friend class SensorCommon<TouchClassCST226>;
public:
#if defined(ARDUINO)
TouchClassCST226();
bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl);
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr);
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl);
#endif //ESP_IDF_VERSION
#endif
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback);
void reset();
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point);
bool isPressed();
const char *getModelName();
void sleep();
void wakeup();
void idle();
uint8_t getSupportTouchPoint();
bool getResolution(int16_t *x, int16_t *y);
void setHomeButtonCallback(home_button_callback_t cb, void *user_data);
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb);
private:
bool initImpl();
int getReadMaskImpl();
protected:
TouchData report;
};

View File

@@ -0,0 +1,328 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchClassCST816.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-06
*/
#include "TouchClassCST816.h"
#define CST8xx_REG_STATUS (0x00)
#define CST8xx_REG_XPOS_HIGH (0x03)
#define CST8xx_REG_XPOS_LOW (0x04)
#define CST8xx_REG_YPOS_HIGH (0x05)
#define CST8xx_REG_YPOS_LOW (0x06)
#define CST8xx_REG_DIS_AUTOSLEEP (0xFE)
#define CST8xx_REG_CHIP_ID (0xA7)
#define CST8xx_REG_FW_VERSION (0xA9)
#define CST8xx_REG_SLEEP (0xE5)
#define CST816S_CHIP_ID (0xB4)
#define CST816T_CHIP_ID (0xB5)
#define CST716_CHIP_ID (0x20)
#define CST820_CHIP_ID (0xB7)
#define CST816D_CHIP_ID (0xB6)
#if defined(ARDUINO)
TouchClassCST816::TouchClassCST816():
__center_btn_x(0),
__center_btn_y(0)
{
}
bool TouchClassCST816::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl)
{
return SensorCommon::begin(wire, address, sda, scl);
}
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool TouchClassCST816::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
return SensorCommon::begin(i2c_dev_bus_handle, addr);
}
#else
bool TouchClassCST816::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
return SensorCommon::begin(port_num, addr, sda, scl);
}
#endif //ESP_IDF_VERSION
#endif //ARDUINO
bool TouchClassCST816::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
}
void TouchClassCST816::reset()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
this->setGpioLevel(__rst, LOW);
delay(30);
this->setGpioLevel(__rst, HIGH);
delay(50);
}
}
uint8_t TouchClassCST816::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point)
{
uint8_t buffer[13];
if (readRegister(CST8xx_REG_STATUS, buffer, 13) == DEV_WIRE_ERR) {
return 0;
}
if (!buffer[2] || !x_array || !y_array || !get_point) {
return 0;
}
// Some CST816T will return all 0xFF after turning off automatic sleep.
if (buffer[2] == 0xFF) {
return 0;
}
// Only suitable for AMOLED 1.91 inch
// RAW:00,00,01,80,78,02,58,00,00,FF,FF,FF,FF,
// if (buffer[2] == 0x01 && buffer[3] == 0x80 && buffer[4] == 0x78 && buffer[5] == 0x02 && buffer[6] == 0x58) {
// if (__homeButtonCb) {
// __homeButtonCb(__userData);
// }
// return 0;
// }
uint8_t point = buffer[2] & 0x0F;
// CST816 only supports single touch
if (point > 1) {
return 0;
}
#ifdef LOG_PORT
LOG_PORT.print("RAW:");
for (int i = 0; i < 13; ++i) {
LOG_PORT.printf("%02X,", buffer[i]);
}
LOG_PORT.println();
#endif
int16_t tmp_x, tmp_y;
tmp_x = ((buffer[CST8xx_REG_XPOS_HIGH] & 0x0F) << 8 | buffer[CST8xx_REG_XPOS_LOW]);
tmp_y = ((buffer[CST8xx_REG_YPOS_HIGH] & 0x0F) << 8 | buffer[CST8xx_REG_YPOS_LOW]);
// Depends on touch screen firmware
if (tmp_x == __center_btn_x && tmp_y == __center_btn_y && __homeButtonCb) {
__homeButtonCb(__userData);
return 0;
}
// if (get_point == 2) {
// x_array[1] = ((buffer[((uint8_t)0x09)] & 0x0F) << 8 | buffer[((uint8_t)0x10)]);
// y_array[1] = ((buffer[((uint8_t)0x11)] & 0x0F) << 8 | buffer[((uint8_t)0x12)]);
// }
x_array[0] = tmp_x;
y_array[0] = tmp_y;
#ifdef LOG_PORT
for (int i = 0; i < point; i++) {
LOG_PORT.printf("[%d] --> X:%d Y:%d \n", i, x_array[i], y_array[i]);
}
#endif
updateXY(point, x_array, y_array);
return point;
}
bool TouchClassCST816::isPressed()
{
static uint32_t lastPulse = 0;
if (__irq != SENSOR_PIN_NONE) {
int val = this->getGpioLevel(__irq) == LOW;
if (val) {
//Filter low levels with intervals greater than 1000ms
val = (millis() - lastPulse > 1000) ? false : true;
lastPulse = millis();
return val;
}
return false;
}
return getPoint(NULL, NULL, 1);
}
const char *TouchClassCST816::getModelName()
{
switch (__chipID) {
case CST816S_CHIP_ID:
return "CST816S";
case CST816T_CHIP_ID:
return "CST816T";
case CST716_CHIP_ID:
return "CST716";
case CST820_CHIP_ID:
return "CST820";
case CST816D_CHIP_ID:
return "CST816D";
default:
break;
}
return "UNKONW";
}
void TouchClassCST816::sleep()
{
writeRegister(CST8xx_REG_SLEEP, 0x03);
#ifdef ESP32
if (__irq != SENSOR_PIN_NONE) {
this->setGpioMode(__irq, OPEN_DRAIN);
}
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OPEN_DRAIN);
}
#endif
}
void TouchClassCST816::wakeup()
{
reset();
}
void TouchClassCST816::idle()
{
}
uint8_t TouchClassCST816::getSupportTouchPoint()
{
return 1;
}
bool TouchClassCST816::getResolution(int16_t *x, int16_t *y)
{
return false;
}
void TouchClassCST816::setHomeButtonCallback(home_button_callback_t cb, void *user_data)
{
__homeButtonCb = cb;
__userData = user_data;
}
void TouchClassCST816::setCenterButtonCoordinate(int16_t x, int16_t y)
{
__center_btn_x = x;
__center_btn_y = y;
}
void TouchClassCST816::disableAutoSleep()
{
switch (__chipID) {
case CST816S_CHIP_ID:
case CST816T_CHIP_ID:
case CST820_CHIP_ID:
case CST816D_CHIP_ID:
reset();
delay(50);
writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x01);
break;
case CST716_CHIP_ID:
default:
break;
}
}
void TouchClassCST816::enableAutoSleep()
{
switch (__chipID) {
case CST816S_CHIP_ID:
case CST816T_CHIP_ID:
case CST820_CHIP_ID:
case CST816D_CHIP_ID:
reset();
delay(50);
writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x00);
break;
case CST716_CHIP_ID:
default:
break;
}
}
void TouchClassCST816::setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb)
{
SensorCommon::setGpioModeCallback(mode_cb);
SensorCommon::setGpioWriteCallback(write_cb);
SensorCommon::setGpioReadCallback(read_cb);
}
bool TouchClassCST816::initImpl()
{
if (__rst != SENSOR_PIN_NONE) {
this->setGpioMode(__rst, OUTPUT);
}
reset();
int chip_id = readRegister(CST8xx_REG_CHIP_ID);
log_i("Chip ID:0x%x\n", chip_id);
int version = readRegister(CST8xx_REG_FW_VERSION);
log_i("Version :0x%x\n", version);
// CST716 : 0x20
// CST816S : 0xB4
// CST816T : 0xB5
// CST816D : 0xB6
// CST226SE : A7 = 0X20
if (chip_id != CST816S_CHIP_ID &&
chip_id != CST816T_CHIP_ID &&
chip_id != CST820_CHIP_ID &&
chip_id != CST816D_CHIP_ID &&
(chip_id != CST716_CHIP_ID || version == 0)) {
return false;
}
__chipID = chip_id;
log_i("Touch type:%s\n", getModelName());
return true;
}
int TouchClassCST816::getReadMaskImpl()
{
return -1;
}

View File

@@ -0,0 +1,102 @@
/**
*
* @license MIT License
*
* Copyright (c) 2023 lewis he
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @file TouchClassCST816.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-10-06
*/
#pragma once
#include "../TouchDrvInterface.hpp"
#include "../SensorCommon.tpp"
#include "../SensorLib.h"
class TouchClassCST816 : public TouchDrvInterface,
public SensorCommon<TouchClassCST816>
{
friend class SensorCommon<TouchClassCST816>;
public:
#if defined(ARDUINO)
TouchClassCST816();
bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl);
#elif defined(ESP_PLATFORM)
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr);
#else
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl);
#endif //ESP_IDF_VERSION
#endif
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback);
void reset();
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point);
bool isPressed();
const char *getModelName();
void sleep();
void wakeup();
void idle();
uint8_t getSupportTouchPoint();
bool getResolution(int16_t *x, int16_t *y);
void setCenterButtonCoordinate(int16_t x, int16_t y);
void setHomeButtonCallback(home_button_callback_t cb, void *user_data);
void disableAutoSleep();
void enableAutoSleep();
void setGpioCallback(gpio_mode_fptr_t mode_cb,
gpio_write_fptr_t write_cb,
gpio_read_fptr_t read_cb);
private:
bool initImpl();
int getReadMaskImpl();
protected:
int16_t __center_btn_x;
int16_t __center_btn_y;
};

8
components/thorvg-main/.gitattributes vendored Normal file
View File

@@ -0,0 +1,8 @@
# Normalize EOL for all files that Git considers text files
* text=auto eol=lf
# Except for bat files, which are Windows only files
*.bat eol=crlf
# And some test files where the EOL matters
*.json -text

View File

@@ -0,0 +1,2 @@
github: thorvg
open_collective: thorvg

View File

@@ -0,0 +1,55 @@
"APIs":
- inc/**/*
"binding":
- src/bindings/**/*
"documentation":
- README.md
"font":
- src/loaders/ttf/**/*
"image":
- src/loaders/jpg/**/*
- src/loaders/external_jpg/**/*
- src/loaders/png/**/*
- src/loaders/external_png/**/*
- src/loaders/webp/**/*
- src/loaders/external_webp/**/*
- src/loaders/raw/**/*
- src/savers/gif/**/*
"svg":
- src/loaders/svg/**/*
"tvg":
- src/loaders/tvg/**/*
"test":
- test/**/*
"tools":
- tools/**/*
"infrastructure":
- .github/**/*
- meson.build
- meson_option.txt
"lottie":
- src/loaders/lottie/**/*
"cpu":
- src/renderer/sw_engine/**/*
"webgpu":
- src/renderer/wg_engine/**/*
"gl":
- src/renderer/gl_engine/**/*
"renderer":
- src/renderer/*
- src/common/**/*

View File

@@ -0,0 +1,73 @@
name: Android
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: read
jobs:
build_x86_64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nttld/setup-ndk@v1.3.1
id: setup-ndk
with:
submodules: true
ndk-version: r21e
local-cache: true
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install meson ninja-build libgles-dev
- name: Build
env:
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
API: 21
run: |
sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_x86_64.txt > /tmp/android_cross.txt
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false -Dextra="lottie_exp" --cross-file /tmp/android_cross.txt
sudo ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_x86_64
path: build/src/libthorvg*
build_aarch64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nttld/setup-ndk@v1.3.1
id: setup-ndk
with:
submodules: true
ndk-version: r21e
local-cache: true
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install meson ninja-build libgles-dev
- name: Build
env:
NDK: ${{ steps.setup-ndk.outputs.ndk-path }}
API: 21
run: |
sed -e "s|NDK|$NDK|g" -e "s|HOST_TAG|linux-x86_64|g" -e "s|API|$API|g" ./cross/android_aarch64.txt > /tmp/android_cross.txt
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dthreads=false -Dextra="lottie_exp" --cross-file /tmp/android_cross.txt
sudo ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_aarch64
path: build/src/libthorvg*

View File

@@ -0,0 +1,100 @@
name: iOS
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: read
jobs:
build_simulator_x86_64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Unbreak Python in GitHub Actions
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
- name: Install Packages
run: |
export HOMEBREW_NO_INSTALL_FROM_API=1
brew update
brew install meson
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_simulator_x86_64.txt
ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_simulator_x86_64
path: build/src/libthorvg*
build_simulator_arm64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Unbreak Python in GitHub Actions
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
- name: Install Packages
run: |
export HOMEBREW_NO_INSTALL_FROM_API=1
brew update
brew install meson
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_simulator_arm64.txt
ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_simulator_arm64
path: build/src/libthorvg*
build_arm64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Unbreak Python in GitHub Actions
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
- name: Install Packages
run: |
export HOMEBREW_NO_INSTALL_FROM_API=1
brew update
brew install meson
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dstatic=true -Dextra="lottie_exp" --cross-file ./cross/ios_arm64.txt
ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_arm64
path: build/src/libthorvg*

View File

@@ -0,0 +1,88 @@
name: macOS
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: read
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Unbreak Python in GitHub Actions
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
- name: Install Packages
run: |
export HOMEBREW_NO_INSTALL_FROM_API=1
brew update
brew install meson sdl2
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all -Dextra="lottie_exp"
ninja -C build install
compact_test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Unbreak Python in GitHub Actions
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
- name: Install Packages
run: |
brew update
brew install meson
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false -Dextra="lottie_exp"
ninja -C build install
unit_test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Unbreak Python in GitHub Actions
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew link --overwrite python3
- name: Install Packages
run: |
brew update
brew install meson
- name: Build
run: |
meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true -Dextra="lottie_exp" --errorlogs
ninja -C build install test
- uses: actions/upload-artifact@v4
with:
name: UnitTestReport
path: build/meson-logs/testlog.txt

View File

@@ -0,0 +1,92 @@
name: Ubuntu
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install meson ninja-build libturbojpeg0-dev libpng-dev libwebp-dev libgles-dev libsdl2-dev
- name: Build
run: |
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all
sudo ninja -C build install
compact_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install meson ninja-build libgles-dev
- name: Build
run: |
meson setup build -Dlog=true -Dengines="sw, gl" -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false
sudo ninja -C build install
unit_test:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install meson ninja-build libgtest-dev libasan5 valgrind curl jq software-properties-common libturbojpeg0-dev libpng-dev libwebp-dev libgles-dev
- name: Build
run: |
meson setup build -Dloaders="all" -Dengines="sw, gl" -Dsavers="all" -Dbindings="capi" -Dtests=true --errorlogs
sudo ninja -C build install test
- uses: actions/upload-artifact@v4
with:
name: UnitTestReport
path: build/meson-logs/testlog.txt
- name: Run memcheck Script(valgrind)
run: |
export PATH=$PATH:~/.local/bin/
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh"
"${GITHUB_WORKSPACE}/.github/workflows/memcheck_valgrind.sh"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build & Run memcheck Script(ASAN)
run: |
sudo rm -rf ./build
meson setup build -Db_sanitize="address,undefined" -Dloaders="all" -Dsavers="all" -Dtests="true" -Dbindings="capi"
sudo ninja -C build install
export PATH=$PATH:~/.local/bin/
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/memcheck_asan.sh"
"${GITHUB_WORKSPACE}/.github/workflows/memcheck_asan.sh"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -0,0 +1,77 @@
name: Windows
on:
pull_request:
branches:
- main
push:
branches:
- main
permissions:
contents: read
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- name: Install Packages
run: |
pip install meson ninja
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dbindings=capi -Dtools=all
where link
ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_windows
path: build/src/thorvg*
compact_test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- name: Install Packages
run: |
pip install meson ninja
- name: Build
run: |
meson setup build -Dlog=true -Dloaders=all -Dsavers=all -Dstatic=true -Dthreads=false
where link
ninja -C build install
- uses: actions/upload-artifact@v4
with:
name: result_windows_static
path: build/src/thorvg*
unit_test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- name: Install Packages
run: |
pip install meson ninja
- name: Build
run: |
meson setup build -Dloaders=all -Dsavers=all -Dbindings=capi -Dtests=true --errorlogs
where link
ninja -C build install test
- uses: actions/upload-artifact@v4
with:
name: UnitTestReport
path: build/meson-logs/testlog.txt

View File

@@ -0,0 +1,44 @@
#!/bin/bash
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "The GITHUB_TOKEN is required."
exit 1
fi
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
echo "Run Address Sanitizer"
echo "meson -Db_sanitize=\"address,undefined\" -Dloaders=\"all\" -Dsavers=\"all\" -Dtests=\"true\" -Dbindings=\"capi\" . build"
pwd
cd ${GITHUB_WORKSPACE}/build/test
./tvgUnitTests > memcheck_asan.txt 2>&1
PAYLOAD_MEMCHECK=`cat memcheck_asan.txt`
COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
echo $COMMENTS_URL
echo "MEMCHECK errors:"
echo $PAYLOAD_MEMCHECK
if [[ $PAYLOAD_MEMCHECK == *"runtime error:"* || $PAYLOAD_MEMCHECK == *"ERROR: AddressSanitizer:"* ]]; then
OUTPUT+=$'\n**MEMCHECK(ASAN) RESULT**:\n'
OUTPUT+=$'\n`meson -Db_sanitize="address,undefined" -Dloaders="all" -Dsavers="all" -Dtests="true" -Dbindings="capi" . build`\n'
OUTPUT+=$'\n```\n'
OUTPUT+="$PAYLOAD_MEMCHECK"
OUTPUT+=$'\n```\n'
(
echo '<details><summary>ASAN output</sumary>'
echo
echo "$OUTPUT"
echo
echo '</details>'
) >> "$GITHUB_STEP_SUMMARY"
PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body')
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL"
fi
fi

View File

@@ -0,0 +1,45 @@
#!/bin/bash
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "The GITHUB_TOKEN is required."
exit 1
fi
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
echo "Run Valgrind"
echo "valgrind --leak-check=yes ./tvgUnitTests"
cd ./build/test
valgrind --leak-check=yes ./tvgUnitTests > memcheck_valgrind.txt 2>&1
PAYLOAD_MEMCHECK=`cat memcheck_valgrind.txt`
COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
echo $COMMENTS_URL
echo "MEMCHECK errors:"
echo $PAYLOAD_MEMCHECK
DEFINITELY_LOST_NUMBER=$(echo "$PAYLOAD_MEMCHECK" | grep -oP 'definitely lost:\s*\K[0-9]+(?=\s*bytes in)')
ERROR_NUMBER=$(echo "$PAYLOAD_MEMCHECK" | grep -oP 'ERROR SUMMARY:\s*\K[0-9]+(?=\s*errors)')
if [[ $ERROR_NUMBER != 0 || $DEFINITELY_LOST_NUMBER != 0 || $PAYLOAD_MEMCHECK == *"Invalid read "* || $PAYLOAD_MEMCHECK == *"Invalid write "* ]]; then
OUTPUT+=$'\n**MEMCHECK(VALGRIND) RESULT**:\n'
OUTPUT+=$'\n`valgrind --leak-check=yes ./tvgUnitTests`\n'
OUTPUT+=$'\n```\n'
OUTPUT+="$PAYLOAD_MEMCHECK"
OUTPUT+=$'\n```\n'
(
echo '<details><summary>Valgrind output</sumary>'
echo
echo "$OUTPUT"
echo
echo '</details>'
) >> "$GITHUB_STEP_SUMMARY"
PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body')
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL"
fi
fi

View File

@@ -0,0 +1,13 @@
name: Pull Request Labeler
on: [pull_request_target]
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
sync-labels: true

View File

@@ -0,0 +1,192 @@
name: Regression
# on: [push, pull_request] - enable when testing
on:
pull_request:
branches:
- main
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install things
run: |
sudo apt-get update
sudo apt-get install -y meson wget2 librsvg2-dev librsvg2-bin ninja-build git gcc-multilib g++-multilib earlyoom
- name: Compile Thorvg PR
run: |
meson . build -Dtools=svg2png,lottie2gif -Dsavers=gif -Db_sanitize=address,undefined
sudo ninja -C build install
- name: Compile Thorvg Develop
run: |
git clone https://github.com/thorvg/thorvg.git thorvg_develop
cd thorvg_develop
meson . build -Dtools=svg2png
sudo ninja -C build install
cd ..
- name: Download SVG Regression finder and setup settings
run: |
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.4.0/svg_tester
chmod +x ./svg_tester
- name: Prepare valid files to test
run: |
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgValidFiles.zip -O files.zip
unzip -q files.zip
rm files.zip
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgNotValidFiles.zip -O files.zip
unzip -q files.zip
rm files.zip
mv ThorvgValidFiles FilesToTest
find ThorvgNotValidFiles -type f -exec mv {} FilesToTest \;
rmdir ThorvgNotValidFiles
- name: Setup settings for crash/leak/timeout tests
run: |
mv test/regression/settings_crash_leak.toml settings.toml
- name: Run regression finder tests
run: |
./svg_tester 2>&1 | tee result_crashes.txt
- name: Setup settings for comparison tests
run: |
mv test/regression/settings_comparison.toml settings.toml
- name: Store Crashing/Leaking/Timing out Images
uses: actions/upload-artifact@v4
with:
name: crashing-leaking-timeouting-images
path: BrokenFILES
if-no-files-found: ignore
- name: Clean Data
run: |
rm -rf BrokenSVG || true
rm -rf FilesToTest || true
rm -rf ProblematicSVG || true
rm -rf IgnoredSVG || true
rm -rf BrokenFILES || true
# Test valid files
- name: Prepare valid files to test
run: |
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgValidFiles.zip -O files.zip
unzip -q files.zip
rm files.zip
mv ThorvgValidFiles FilesToTest
- name: Run regression finder tests
run: |
./svg_tester 2>&1 | tee result_valid_files.txt
- name: Store Broken Images for valid inputs
uses: actions/upload-artifact@v4
with:
name: differences-in-valid-files
path: BrokenSVG
if-no-files-found: ignore
- name: Store Problematic Images for valid inputs
uses: actions/upload-artifact@v4
with:
name: problematic-images-in-valid-files
path: ProblematicSVG
if-no-files-found: ignore
- name: Clean Data
run: |
rm -rf BrokenSVG || true
rm -rf FilesToTest || true
rm -rf ProblematicSVG || true
rm -rf IgnoredSVG || true
rm -rf BrokenFILES || true
# Test files that may not work currently good with Thorvg, errors from this are not critical
# it is possible that this will find also some improvements
- name: Prepare not valid to test
run: |
wget -q https://github.com/qarmin/SVG-regression-finder/releases/download/0.3.0/ThorvgNotValidFiles.zip -O files.zip
unzip -q files.zip
rm files.zip
mv ThorvgNotValidFiles FilesToTest
- name: Run invalid files tests
run: |
./svg_tester 2>&1 | tee result_not_valid_files.txt
- name: Store Broken Images for not valid inputs
uses: actions/upload-artifact@v4
with:
name: differences-in-not-valid-files
path: BrokenSVG
if-no-files-found: ignore
- name: Store Problematic Images for not valid inputs
uses: actions/upload-artifact@v4
with:
name: problematic-images-in-not-valid-files
path: ProblematicSVG
if-no-files-found: ignore
- name: Clean Data
run: |
rm -rf BrokenSVG || true
rm -rf FilesToTest || true
rm -rf ProblematicSVG || true
rm -rf IgnoredSVG || true
rm -rf BrokenFILES || true
- name: Test png reproducibility
run: |
wget -q https://github.com/thorvg/thorvg/files/11356766/AA_5.svg.zip -O files.zip
unzip -q files.zip
rm files.zip
cp test/regression/check_same_image_size.py check_same_image_size.py
# Forces to run tasks on different threads if possible, which should help find problem with data races
taskset -c 0-15 python3 check_same_image_size.py AA_5.svg ./build/src/tools/svg2png/tvg-svg2png 100 500 2>&1 | tee result_image_size.txt
- name: Check results
run: |
export PATH=$PATH:~/.local/bin/
python3 "${GITHUB_WORKSPACE}/.github/workflows/regression_check.py"
if [[ -f "fail_ci.txt" ]]; then
(
echo '```'
cat "fail_ci.txt"
echo '```'
) >> "$GITHUB_STEP_SUMMARY"
fi
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Regression report
# TODO - not works
# - name: Create or update comment
# uses: peter-evans/create-or-update-comment@v4
# with:
# comment-id: ${{ steps.fc.outputs.comment-id }}
# issue-number: ${{ github.event.pull_request.number }}
# body-path: 'comment.txt'
# edit-mode: replace
- name: Fail CI if regression found
run: |
if [[ -f "fail_ci.txt" ]]; then
echo "Check Check results section for more details which tests failed"
exit 1
fi

View File

@@ -0,0 +1,67 @@
from typing import Optional
POSSIBLE_PROBLEM = "POSSIBLE_PROBLEM - "
def check_file(file_name: str) -> Optional[str]:
with open(file_name, "r") as file:
print(f"Checking file {file_name}")
for line in file:
line = line.strip()
if line.startswith(POSSIBLE_PROBLEM):
return line[len(POSSIBLE_PROBLEM) :]
return None
if __name__ == "__main__":
data_to_check = [
(
"result_valid_files.txt",
True,
"Found difference in converting images that properly converted in develop branch.",
),
(
"result_not_valid_files.txt",
False,
"Found differences in converting images that were not properly converted in develop branch(this may be improvement).",
),
(
"result_image_size.txt",
True,
"Generated png have different size in each run.",
),
(
"result_crashes.txt",
True,
"Found crashes in crashes during when converting svg to png.",
),
]
fail_ci = False
comment = ""
for file_name, fail_ci_when_triggered, new_comment in data_to_check:
possible_problem = check_file(file_name)
if possible_problem is not None:
print(f">>>>> Found changes in {file_name} (look at CI steps from above)")
print(f"Comment: {new_comment}")
if fail_ci_when_triggered:
fail_ci = True
comment += new_comment + "\n"
to_write = "Regression report:\n"
if len(comment) > 0:
to_write += comment
to_write += "\nCheck CI for artifacts/logs for more details."
else:
to_write += "Not found any changes(both improvements and regressions) in this PR with test data."
print("\n\n" + to_write + "\n\n")
with open("comment.txt", "w") as file:
file.write(to_write)
if fail_ci:
with open("fail_ci.txt", "w") as file:
file.write("Fail")

Some files were not shown because too many files have changed in this diff Show More