1
0
forked from me/IronOS

Cleanup make includes and formatting rules (#1860)

* Draft cleanup of the folder definition mess

* Move old startup

* Fixup! broken hacky includes

* Update Makefile

* Update Makefile

* Update Makefile

* Bulk format

* Who knew, header guards are a wise idea

* Squash some sizing warnings

* Drop broken usb stack

* Fix BLE headers to be sensible

* Cleaning up proper c styling

* We have newer clang, it does bracketing now

* Run clang-format brackets

* We can drop the old messy bracket-checker with newer clang format

* WiP formatter

* Align grids of scripts by right side

Massively easier to read in nearly all cases

* Excempt the table for compression from formatter
This commit is contained in:
Ben V. Brown
2023-12-27 09:23:12 +11:00
committed by GitHub
parent 849d1f7d40
commit ec5f07ec0c
248 changed files with 58306 additions and 70269 deletions

View File

@@ -22,18 +22,18 @@ bool BMA223::detect() {
}
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers[] = {
//
//
{BMA223_PMU_RANGE, 0b00000011, 0}, // 2G range
{BMA223_PMU_BW, 0b00001101, 0}, // 250Hz filter
{BMA223_PMU_LPW, 0b00000000, 0}, // Full power
{BMA223_ACCD_HBW, 0b00000000, 0}, // filtered data out
{BMA223_INT_OUT_CTRL, 0b00001010, 0}, // interrupt active low and OD to get it hi-z
//
//
{ BMA223_PMU_RANGE, 0b00000011, 0}, // 2G range
{ BMA223_PMU_BW, 0b00001101, 0}, // 250Hz filter
{ BMA223_PMU_LPW, 0b00000000, 0}, // Full power
{ BMA223_ACCD_HBW, 0b00000000, 0}, // filtered data out
{ BMA223_INT_OUT_CTRL, 0b00001010, 0}, // interrupt active low and OD to get it hi-z
{BMA223_INT_RST_LATCH, 0b10000000, 0}, // interrupt active low and OD to get it hi-z
{BMA223_INT_EN_0, 0b01000000, 0}, // Enable orientation
{BMA223_INT_A, 0b00100111, 0}, // Setup orientation detection
{ BMA223_INT_EN_0, 0b01000000, 0}, // Enable orientation
{ BMA223_INT_A, 0b00100111, 0}, // Setup orientation detection
//
//
};
bool BMA223::initalize() {
// Setup acceleration readings

View File

@@ -31,23 +31,27 @@ ButtonState getButtonState() {
currentState = (getButtonA()) << 0;
currentState |= (getButtonB()) << 1;
if (currentState)
if (currentState) {
lastButtonTime = xTaskGetTickCount();
}
if (currentState == previousState) {
if (currentState == 0)
if (currentState == 0) {
return BUTTON_NONE;
}
if ((xTaskGetTickCount() - previousStateChange) >= timeout) {
// User has been holding the button down
// We want to send a button is held message
longPressed = true;
if (currentState == 0x01)
if (currentState == 0x01) {
return BUTTON_F_LONG;
else if (currentState == 0x02)
} else if (currentState == 0x02) {
return BUTTON_B_LONG;
else
} else {
return BUTTON_BOTH_LONG; // Both being held case
} else
}
} else {
return BUTTON_NONE;
}
} else {
// A change in button state has occurred
ButtonState retVal = BUTTON_NONE;
@@ -65,12 +69,13 @@ ButtonState getButtonState() {
// The user didn't hold the button for long
// So we send button press
if (previousState == 0x01)
if (previousState == 0x01) {
retVal = BUTTON_F_SHORT;
else if (previousState == 0x02)
} else if (previousState == 0x02) {
retVal = BUTTON_B_SHORT;
else
} else {
retVal = BUTTON_BOTH; // Both being held case
}
}
previousState = 0;
longPressed = false;
@@ -103,13 +108,15 @@ void waitForButtonPressOrTimeout(TickType_t timeout) {
while (buttons) {
buttons = getButtonState();
GUIDelay();
if (xTaskGetTickCount() > timeout)
if (xTaskGetTickCount() > timeout) {
return;
}
}
while (!buttons) {
buttons = getButtonState();
GUIDelay();
if (xTaskGetTickCount() > timeout)
if (xTaskGetTickCount() > timeout) {
return;
}
}
}

View File

@@ -45,8 +45,9 @@ void I2CBB1::init() {
}
bool I2CBB1::probe(uint8_t address) {
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(address);
stop();
@@ -55,8 +56,9 @@ bool I2CBB1::probe(uint8_t address) {
}
bool I2CBB1::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(DevAddress);
if (!ack) {
@@ -91,8 +93,9 @@ bool I2CBB1::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
}
bool I2CBB1::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, const uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(DevAddress);
if (!ack) {
@@ -123,8 +126,9 @@ bool I2CBB1::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, const uint8_t *
}
void I2CBB1::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return;
}
start();
bool ack = send(DevAddress);
if (!ack) {
@@ -147,8 +151,9 @@ void I2CBB1::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
}
void I2CBB1::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return;
}
start();
bool ack = send(DevAddress | 1);
if (!ack) {
@@ -166,10 +171,12 @@ void I2CBB1::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
}
void I2CBB1::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx) {
if (Size_tx == 0 && Size_rx == 0)
if (Size_tx == 0 && Size_rx == 0) {
return;
if (lock() == false)
}
if (lock() == false) {
return;
}
if (Size_tx) {
start();
bool ack = send(DevAddress);
@@ -251,10 +258,11 @@ uint8_t I2CBB1::read(bool ack) {
}
SOFT_SDA1_HIGH();
if (ack)
if (ack) {
write_bit(0);
else
} else {
write_bit(1);
}
return B;
}
@@ -266,10 +274,11 @@ uint8_t I2CBB1::read_bit() {
SOFT_SCL1_HIGH();
SOFT_I2C_DELAY();
if (SOFT_SDA1_READ())
if (SOFT_SDA1_READ()) {
b = 1;
else
} else {
b = 0;
}
SOFT_SCL1_LOW();
return b;
@@ -278,7 +287,8 @@ uint8_t I2CBB1::read_bit() {
void I2CBB1::unlock() { xSemaphoreGive(I2CSemaphore); }
bool I2CBB1::lock() {
if (I2CSemaphore == NULL) {}
if (I2CSemaphore == NULL) {
}
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t)100) == pdTRUE;
return a;
}
@@ -309,16 +319,18 @@ bool I2CBB1::writeRegistersBulk(const uint8_t address, const I2C_REG *registers,
if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) {
return false;
}
if (registers[index].pause_ms)
if (registers[index].pause_ms) {
delay_ms(registers[index].pause_ms);
}
}
return true;
}
bool I2CBB1::wakePart(uint16_t DevAddress) {
// wakepart is a special case where only the device address is sent
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(DevAddress);
stop();

View File

@@ -44,8 +44,9 @@ void I2CBB2::init() {
}
bool I2CBB2::probe(uint8_t address) {
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(address);
stop();
@@ -54,8 +55,9 @@ bool I2CBB2::probe(uint8_t address) {
}
bool I2CBB2::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(DevAddress);
if (!ack) {
@@ -90,8 +92,9 @@ bool I2CBB2::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
}
bool I2CBB2::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, const uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(DevAddress);
if (!ack) {
@@ -122,8 +125,9 @@ bool I2CBB2::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, const uint8_t *
}
void I2CBB2::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return;
}
start();
bool ack = send(DevAddress);
if (!ack) {
@@ -146,8 +150,9 @@ void I2CBB2::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
}
void I2CBB2::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
if (!lock())
if (!lock()) {
return;
}
start();
bool ack = send(DevAddress | 1);
if (!ack) {
@@ -165,10 +170,12 @@ void I2CBB2::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
}
void I2CBB2::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx) {
if (Size_tx == 0 && Size_rx == 0)
if (Size_tx == 0 && Size_rx == 0) {
return;
if (lock() == false)
}
if (lock() == false) {
return;
}
if (Size_tx) {
start();
bool ack = send(DevAddress);
@@ -250,10 +257,11 @@ uint8_t I2CBB2::read(bool ack) {
}
SOFT_SDA2_HIGH();
if (ack)
if (ack) {
write_bit(0);
else
} else {
write_bit(1);
}
return B;
}
@@ -265,10 +273,11 @@ uint8_t I2CBB2::read_bit() {
SOFT_SCL2_HIGH();
SOFT_I2C_DELAY();
if (SOFT_SDA2_READ())
if (SOFT_SDA2_READ()) {
b = 1;
else
} else {
b = 0;
}
SOFT_SCL2_LOW();
return b;
@@ -277,7 +286,8 @@ uint8_t I2CBB2::read_bit() {
void I2CBB2::unlock() { xSemaphoreGive(I2CSemaphore); }
bool I2CBB2::lock() {
if (I2CSemaphore == NULL) {}
if (I2CSemaphore == NULL) {
}
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t)100) == pdTRUE;
return a;
}
@@ -308,16 +318,18 @@ bool I2CBB2::writeRegistersBulk(const uint8_t address, const I2C_REG *registers,
if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) {
return false;
}
if (registers[index].pause_ms)
if (registers[index].pause_ms) {
delay_ms(registers[index].pause_ms);
}
}
return true;
}
bool I2CBB2::wakePart(uint16_t DevAddress) {
// wakepart is a special case where only the device address is sent
if (!lock())
if (!lock()) {
return false;
}
start();
bool ack = send(DevAddress);
stop();

View File

@@ -10,19 +10,21 @@
#include "LIS2DH12.hpp"
#include "cmsis_os.h"
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers[] = {{LIS_CTRL_REG1, 0x17, 0}, // 25Hz
{LIS_CTRL_REG2, 0b00001000, 0}, // Highpass filter off
{LIS_CTRL_REG3, 0b01100000, 0}, // Setup interrupt pins
{LIS_CTRL_REG4, 0b00001000, 0}, // Block update mode off, HR on
{LIS_CTRL_REG5, 0b00000010, 0}, //
{LIS_CTRL_REG6, 0b01100010, 0},
// Basically setup the unit to run, and enable 4D orientation detection
{LIS_INT2_CFG, 0b01111110, 0}, // setup for movement detection
{LIS_INT2_THS, 0x28, 0}, //
{LIS_INT2_DURATION, 64, 0}, //
{LIS_INT1_CFG, 0b01111110, 0}, //
{LIS_INT1_THS, 0x28, 0}, //
{LIS_INT1_DURATION, 64, 0}};
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers[] = {
{ LIS_CTRL_REG1, 0x17, 0}, // 25Hz
{ LIS_CTRL_REG2, 0b00001000, 0}, // Highpass filter off
{ LIS_CTRL_REG3, 0b01100000, 0}, // Setup interrupt pins
{ LIS_CTRL_REG4, 0b00001000, 0}, // Block update mode off, HR on
{ LIS_CTRL_REG5, 0b00000010, 0}, //
{ LIS_CTRL_REG6, 0b01100010, 0},
// Basically setup the unit to run, and enable 4D orientation detection
{ LIS_INT2_CFG, 0b01111110, 0}, // setup for movement detection
{ LIS_INT2_THS, 0x28, 0}, //
{LIS_INT2_DURATION, 64, 0}, //
{ LIS_INT1_CFG, 0b01111110, 0}, //
{ LIS_INT1_THS, 0x28, 0}, //
{LIS_INT1_DURATION, 64, 0}
};
bool LIS2DH12::initalize() { return ACCEL_I2C_CLASS::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }

View File

@@ -11,19 +11,19 @@
#include <array>
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers[] = {
{CTRL_REG2, 0, 0}, // Normal mode
{CTRL_REG2, 0x40, 2}, // Reset all registers to POR values
{FF_MT_CFG_REG, 0x78, 0}, // Enable motion detection for X, Y, Z axis, latch disabled
{PL_CFG_REG, 0x40, 0}, // Enable the orientation detection
{PL_COUNT_REG, 200, 0}, // 200 count debounce
{PL_BF_ZCOMP_REG, 0b01000111, 0}, // Set the threshold to 42 degrees
{P_L_THS_REG, 0b10011100, 0}, // Up the trip angles
{CTRL_REG4, 0x01 | (1 << 4), 0}, // Enable dataready interrupt & orientation interrupt
{CTRL_REG5, 0x01, 0}, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
{CTRL_REG2, 0x12, 0}, // Set maximum resolution oversampling
{XYZ_DATA_CFG_REG, (1 << 4), 0}, // select high pass filtered data
{HP_FILTER_CUTOFF_REG, 0x03, 0}, // select high pass filtered data
{CTRL_REG1, 0x19, 0} // ODR=12 Hz, Active mode
{ CTRL_REG2, 0, 0}, // Normal mode
{ CTRL_REG2, 0x40, 2}, // Reset all registers to POR values
{ FF_MT_CFG_REG, 0x78, 0}, // Enable motion detection for X, Y, Z axis, latch disabled
{ PL_CFG_REG, 0x40, 0}, // Enable the orientation detection
{ PL_COUNT_REG, 200, 0}, // 200 count debounce
{ PL_BF_ZCOMP_REG, 0b01000111, 0}, // Set the threshold to 42 degrees
{ P_L_THS_REG, 0b10011100, 0}, // Up the trip angles
{ CTRL_REG4, 0x01 | (1 << 4), 0}, // Enable dataready interrupt & orientation interrupt
{ CTRL_REG5, 0x01, 0}, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
{ CTRL_REG2, 0x12, 0}, // Set maximum resolution oversampling
{ XYZ_DATA_CFG_REG, (1 << 4), 0}, // select high pass filtered data
{HP_FILTER_CUTOFF_REG, 0x03, 0}, // select high pass filtered data
{ CTRL_REG1, 0x19, 0} // ODR=12 Hz, Active mode
};
bool MMA8652FC::initalize() { return ACCEL_I2C_CLASS::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }

View File

@@ -13,14 +13,13 @@
bool MSA301::detect() { return ACCEL_I2C_CLASS::probe(MSA301_I2C_ADDRESS); }
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers[] = {
//
//
{MSA301_REG_ODR, 0b00001000, 1}, // X/Y/Z enabled @ 250Hz
{MSA301_REG_POWERMODE, 0b0001001, 1}, // Normal mode
{MSA301_REG_RESRANGE, 0b00000001, 0}, // 14bit resolution @ 4G range
//
//
{ MSA301_REG_ODR, 0b00001000, 1}, // X/Y/Z enabled @ 250Hz
{MSA301_REG_POWERMODE, 0b0001001, 1}, // Normal mode
{ MSA301_REG_RESRANGE, 0b00000001, 0}, // 14bit resolution @ 4G range
{MSA301_REG_ORIENT_HY, 0b01000000, 0}, // 4*62.5mg hyst, no blocking, symmetrical
{MSA301_REG_INTSET0, 1 << 6, 0}, // Turn on orientation detection (by enabling its interrupt)
{ MSA301_REG_INTSET0, 1 << 6, 0}, // Turn on orientation detection (by enabling its interrupt)
};
bool MSA301::initalize() { return ACCEL_I2C_CLASS::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }

View File

@@ -32,36 +32,36 @@ uint32_t OLED::displayChecksum;
* Data packets are prefixed with 0x40
*/
I2C_CLASS::I2C_REG OLED_Setup_Array[] = {
/**/
{0x80, OLED_OFF, 0}, /* Display off */
{0x80, OLED_DIVIDER, 0}, /* Set display clock divide ratio / osc freq */
{0x80, 0x52, 0}, /* Divide ratios */
{0x80, 0xA8, 0}, /* Set Multiplex Ratio */
{0x80, OLED_HEIGHT - 1, 0}, /* Multiplex ratio adjusts how far down the matrix it scans */
{0x80, 0xC0, 0}, /* Set COM Scan direction */
{0x80, 0xD3, 0}, /* Set vertical Display offset */
{0x80, 0x00, 0}, /* 0 Offset */
{0x80, 0x40, 0}, /* Set Display start line to 0 */
/**/
{0x80, OLED_OFF, 0}, /* Display off */
{0x80, OLED_DIVIDER, 0}, /* Set display clock divide ratio / osc freq */
{0x80, 0x52, 0}, /* Divide ratios */
{0x80, 0xA8, 0}, /* Set Multiplex Ratio */
{0x80, OLED_HEIGHT - 1, 0}, /* Multiplex ratio adjusts how far down the matrix it scans */
{0x80, 0xC0, 0}, /* Set COM Scan direction */
{0x80, 0xD3, 0}, /* Set vertical Display offset */
{0x80, 0x00, 0}, /* 0 Offset */
{0x80, 0x40, 0}, /* Set Display start line to 0 */
#ifdef OLED_SEGMENT_MAP_REVERSED
{0x80, 0xA1, 0}, /* Set Segment remap to normal */
{0x80, 0xA1, 0}, /* Set Segment remap to normal */
#else
{0x80, 0xA0, 0}, /* Set Segment remap to normal */
#endif
{0x80, 0x8D, 0}, /* Charge Pump */
{0x80, 0x14, 0}, /* Charge Pump settings */
{0x80, 0xDA, 0}, /* Set VCOM Pins hardware config */
{0x80, 0x8D, 0}, /* Charge Pump */
{0x80, 0x14, 0}, /* Charge Pump settings */
{0x80, 0xDA, 0}, /* Set VCOM Pins hardware config */
{0x80, OLED_VCOM_LAYOUT, 0}, /* Combination 0x2 or 0x12 depending on OLED model */
{0x80, 0x81, 0}, /* Brightness */
{0x80, 0x00, 0}, /* ^0 */
{0x80, 0xD9, 0}, /* Set pre-charge period */
{0x80, 0xF1, 0}, /* Pre charge period */
{0x80, 0xDB, 0}, /* Adjust VCOMH regulator ouput */
{0x80, 0x30, 0}, /* VCOM level */
{0x80, 0xA4, 0}, /* Enable the display GDDR */
{0x80, 0xA6, 0}, /* Normal display */
{0x80, 0x20, 0}, /* Memory Mode */
{0x80, 0x00, 0}, /* Wrap memory */
{0x80, OLED_ON, 0}, /* Display on */
{0x80, 0x81, 0}, /* Brightness */
{0x80, 0x00, 0}, /* ^0 */
{0x80, 0xD9, 0}, /* Set pre-charge period */
{0x80, 0xF1, 0}, /* Pre charge period */
{0x80, 0xDB, 0}, /* Adjust VCOMH regulator ouput */
{0x80, 0x30, 0}, /* VCOM level */
{0x80, 0xA4, 0}, /* Enable the display GDDR */
{0x80, 0xA6, 0}, /* Normal display */
{0x80, 0x20, 0}, /* Memory Mode */
{0x80, 0x00, 0}, /* Wrap memory */
{0x80, OLED_ON, 0}, /* Display on */
};
// Setup based on the SSD1307 and modified for the SSD1306

View File

@@ -42,37 +42,39 @@ bool SC7A20::detect() {
}
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers[] = {
//
//
{SC7A20_CTRL_REG1, 0b01100111, 0}, // 200Hz, XYZ enabled
{SC7A20_CTRL_REG2, 0b00000000, 0}, // Setup filter to 0x00 ??
{SC7A20_CTRL_REG3, 0b00000000, 0}, // int1 off
{SC7A20_CTRL_REG4, 0b01001000, 0}, // Block mode off,little-endian,2G,High-pres,self test off
{SC7A20_CTRL_REG5, 0b00000100, 0}, // fifo off, D4D on int1
{SC7A20_CTRL_REG6, 0x00, 0}, // INT2 off
// Basically setup the unit to run, and enable 4D orientation detection
{SC7A20_INT2_CFG, 0b01111110, 0}, // setup for movement detection
{SC7A20_INT2_THS, 0x28, 0}, //
{SC7A20_INT2_DURATION, 64, 0}, //
{SC7A20_INT1_CFG, 0b01111110, 0}, //
{SC7A20_INT1_THS, 0x28, 0}, //
{SC7A20_INT1_DURATION, 64, 0}
//
//
{ SC7A20_CTRL_REG1, 0b01100111, 0}, // 200Hz, XYZ enabled
{ SC7A20_CTRL_REG2, 0b00000000, 0}, // Setup filter to 0x00 ??
{ SC7A20_CTRL_REG3, 0b00000000, 0}, // int1 off
{ SC7A20_CTRL_REG4, 0b01001000, 0}, // Block mode off,little-endian,2G,High-pres,self test off
{ SC7A20_CTRL_REG5, 0b00000100, 0}, // fifo off, D4D on int1
{ SC7A20_CTRL_REG6, 0x00, 0}, // INT2 off
// Basically setup the unit to run, and enable 4D orientation detection
{ SC7A20_INT2_CFG, 0b01111110, 0}, // setup for movement detection
{ SC7A20_INT2_THS, 0x28, 0}, //
{SC7A20_INT2_DURATION, 64, 0}, //
{ SC7A20_INT1_CFG, 0b01111110, 0}, //
{ SC7A20_INT1_THS, 0x28, 0}, //
{SC7A20_INT1_DURATION, 64, 0}
//
//
};
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers_alt[] = {
{ LIS_CTRL_REG1, 0b00110111, 0}, // 200Hz XYZ
{ LIS_CTRL_REG2, 0b00000000, 0}, //
{ LIS_CTRL_REG3, 0b01100000, 0}, // Setup interrupt pins
{ LIS_CTRL_REG4, 0b00001000, 0}, // Block update mode off, HR on
{ LIS_CTRL_REG5, 0b00000010, 0}, //
{ LIS_CTRL_REG6, 0b01100010, 0},
// Basically setup the unit to run, and enable 4D orientation detection
{ LIS_INT2_CFG, 0b01111110, 0}, // setup for movement detection
{ LIS_INT2_THS, 0x28, 0}, //
{LIS_INT2_DURATION, 64, 0}, //
{ LIS_INT1_CFG, 0b01111110, 0}, //
{ LIS_INT1_THS, 0x28, 0}, //
{LIS_INT1_DURATION, 64, 0}
};
static const ACCEL_I2C_CLASS::I2C_REG i2c_registers_alt[] = {{LIS_CTRL_REG1, 0b00110111, 0}, // 200Hz XYZ
{LIS_CTRL_REG2, 0b00000000, 0}, //
{LIS_CTRL_REG3, 0b01100000, 0}, // Setup interrupt pins
{LIS_CTRL_REG4, 0b00001000, 0}, // Block update mode off, HR on
{LIS_CTRL_REG5, 0b00000010, 0}, //
{LIS_CTRL_REG6, 0b01100010, 0},
// Basically setup the unit to run, and enable 4D orientation detection
{LIS_INT2_CFG, 0b01111110, 0}, // setup for movement detection
{LIS_INT2_THS, 0x28, 0}, //
{LIS_INT2_DURATION, 64, 0}, //
{LIS_INT1_CFG, 0b01111110, 0}, //
{LIS_INT1_THS, 0x28, 0}, //
{LIS_INT1_DURATION, 64, 0}};
bool SC7A20::initalize() {
// Setup acceleration readings

View File

@@ -31,27 +31,33 @@ bool Si7210::init() {
}
/* Disable periodic auto-wakeup by device, and tamper detect. */
if ((!write_reg(SI7210_CTRL3, (uint8_t)~SL_TIMEENA_MASK, 0)))
if ((!write_reg(SI7210_CTRL3, (uint8_t)~SL_TIMEENA_MASK, 0))) {
return false;
}
/* Disable tamper detection by setting sw_tamper to 63 */
if (!write_reg(SI7210_CTRL3, SL_FAST_MASK | SL_TIMEENA_MASK, 63 << 2))
if (!write_reg(SI7210_CTRL3, SL_FAST_MASK | SL_TIMEENA_MASK, 63 << 2)) {
return false;
}
if (!set_high_range())
if (!set_high_range()) {
return false;
}
/* Stop the control loop by setting stop bit */
if (!write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK)) /* WARNING: Removed USE_STORE MASK */
if (!write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK)) { /* WARNING: Removed USE_STORE MASK */
return false;
}
/* Use a burst size of 128/4096 samples in FIR and IIR modes */
if (!write_reg(SI7210_CTRL4, 0, DF_BURSTSIZE_128 | DF_BW_4096))
if (!write_reg(SI7210_CTRL4, 0, DF_BURSTSIZE_128 | DF_BW_4096)) {
return false;
}
/* Select field strength measurement */
if (!write_reg(SI7210_DSPSIGSEL, 0, DSP_SIGSEL_FIELD_MASK))
if (!write_reg(SI7210_DSPSIGSEL, 0, DSP_SIGSEL_FIELD_MASK)) {
return false;
}
return true; // start_periodic_measurement();
}
@@ -84,8 +90,9 @@ bool Si7210::read_reg(const uint8_t reg, uint8_t *val) { return ACCEL_I2C_CLASS:
bool Si7210::start_periodic_measurement() {
/* Enable periodic wakeup */
if (!write_reg(SI7210_CTRL3, (uint8_t)~SL_TIMEENA_MASK, SL_TIMEENA_MASK))
if (!write_reg(SI7210_CTRL3, (uint8_t)~SL_TIMEENA_MASK, SL_TIMEENA_MASK)) {
return false;
}
/* Start measurement */
/* Change to ~STOP_MASK with STOP_MASK */
@@ -97,17 +104,20 @@ bool Si7210::get_field_strength(int16_t *field) {
uint8_t val = 0;
ACCEL_I2C_CLASS::wakePart(SI7210_ADDRESS);
if (!write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK))
if (!write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, STOP_MASK)) {
return false;
}
/* Read most-significant byte */
if (!read_reg(SI7210_DSPSIGM, &val))
if (!read_reg(SI7210_DSPSIGM, &val)) {
return false;
}
*field = (val & DSP_SIGM_DATA_MASK) << 8;
/* Read least-significant byte of data */
if (!read_reg(SI7210_DSPSIGL, &val))
if (!read_reg(SI7210_DSPSIGL, &val)) {
return false;
}
*field += val;
*field -= 16384U;

View File

@@ -46,7 +46,8 @@ void USBPowerDelivery::IRQOccured() { pe.IRQOccured(); }
bool USBPowerDelivery::negotiationHasWorked() { return pe.pdHasNegotiated(); }
uint8_t USBPowerDelivery::getStateNumber() { return pe.currentStateCode(true); }
void USBPowerDelivery::step() {
while (pe.thread()) {}
while (pe.thread()) {
}
}
void USBPowerDelivery::PPSTimerCallback() { pe.TimersCallback(); }