Merge remote-tracking branch 'origin/dev' into magic

This commit is contained in:
Ben V. Brown
2022-06-16 20:35:21 +10:00
65 changed files with 3201 additions and 3332 deletions

View File

@@ -5,7 +5,7 @@
* Author: Ralim
*/
#include "FreeRTOS.h"
#include "gui.hpp"
#include "settingsGUI.hpp"
#include "task.h"
#include <Buttons.hpp>
uint32_t lastButtonTime = 0;

View File

@@ -124,7 +124,7 @@ const uint8_t WarningBlock24[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x0C, 0x02, 0xF1, 0xF1, 0xF1, 0x02, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0xB0, 0x8C, 0x83, 0x80, 0x80, 0x80, 0x80, 0xB3, 0xB3, 0xB3, 0x80, 0x80, 0x80, 0x80, 0x83, 0x8C, 0xB0, 0xC0, 0x00, 0x00};
#if defined(MODEL_TS100) + defined(MODEL_Pinecil) >= 1
#if defined(MODEL_TS100) + defined(MODEL_Pinecil) > 0
const uint8_t buttonA[] = {
// width = 42
// height = 16
@@ -156,7 +156,7 @@ const uint8_t disconnectedTip[] = {
0x04, 0x31, 0x38, 0x1c, 0x0e, 0x04, 0x01, 0x03, 0x07, 0x0e, 0x1c, 0x39, 0x30, 0x01, 0x03, 0x00, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x04, 0x09, 0x0f, 0x00};
#endif
#if defined(MODEL_TS80) + defined(MODEL_TS80P) >= 1
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
const uint8_t buttonA[] = {
// width = 42
// height = 16

View File

@@ -5,11 +5,16 @@
* Author: Ralim
*/
#include "LIS2DH12_defines.hpp"
#include <SC7A20.hpp>
#include <SC7A20_defines.h>
#include <array>
uint8_t SC7A20::activeAddress;
bool SC7A20::isInImitationMode;
/*
- This little accelerometer seems to come in two forms, its "normal" setup, and then one where it imitates the LIS2DH12
- This can be detected by checking the whoami registers
*/
bool SC7A20::detect() {
if (FRToSI2C::probe(SC7A20_ADDRESS)) {
@@ -17,7 +22,7 @@ bool SC7A20::detect() {
uint8_t id = 0;
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_WHO_AMI_I, &id, 1)) {
if (id == SC7A20_WHO_AM_I_VALUE) {
activeAddress = SC7A20_ADDRESS;
isInImitationMode = false;
return true;
}
}
@@ -27,7 +32,7 @@ bool SC7A20::detect() {
uint8_t id = 0;
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS2, SC7A20_WHO_AMI_I, &id, 1)) {
if (id == SC7A20_WHO_AM_I_VALUE) {
activeAddress = SC7A20_ADDRESS2;
isInImitationMode = true;
return true;
}
}
@@ -54,6 +59,20 @@ static const FRToSI2C::I2C_REG i2c_registers[] = {
//
};
static const FRToSI2C::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
// 2G range
@@ -63,15 +82,18 @@ bool SC7A20::initalize() {
// Orientation recognition in symmetrical mode
// Hysteresis is set to ~ 16 counts
// Theta blocking is set to 0b10
return FRToSI2C::writeRegistersBulk(activeAddress, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
if (isInImitationMode) {
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS2, i2c_registers_alt, sizeof(i2c_registers_alt) / sizeof(i2c_registers_alt[0]));
} else {
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
}
}
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
// We can tell the accelerometer to output in LE mode which makes this simple
uint16_t sensorData[3] = {0, 0, 0};
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_OUT_X_L, (uint8_t *)sensorData, 6) == false) {
if (FRToSI2C::Mem_Read(isInImitationMode ? SC7A20_ADDRESS2 : SC7A20_ADDRESS, isInImitationMode ? SC7A20_OUT_X_L_ALT : SC7A20_OUT_X_L, (uint8_t *)sensorData, 6) == false) {
x = y = z = 0;
return;
}

View File

@@ -17,7 +17,7 @@ public:
static bool initalize();
// 1 = rh, 2,=lh, 8=flat
static Orientation getOrientation() {
uint8_t val = ((FRToSI2C::I2C_RegisterRead(activeAddress, SC7A20_INT2_SOURCE) >> 2) - 1);
uint8_t val = ((FRToSI2C::I2C_RegisterRead(isInImitationMode ? SC7A20_ADDRESS2 : SC7A20_ADDRESS, SC7A20_INT2_SOURCE) >> 2) - 1);
if (val == 1) {
#ifdef SC7_ORI_FLIP
return Orientation::ORIENTATION_RIGHT_HAND;
@@ -36,7 +36,7 @@ public:
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
private:
static uint8_t activeAddress;
static bool isInImitationMode;
};
#endif /* CORE_DRIVERS_BMA223_HPP_ */

View File

@@ -23,6 +23,7 @@
#define SC7A20_REFERENCE 0x26
#define SC7A20_STATUS_REG 0x27
#define SC7A20_OUT_X_L 0x28
#define SC7A20_OUT_X_L_ALT 0xA8
#define SC7A20_OUT_X_H 0x29
#define SC7A20_OUT_Y_L 0x2A
#define SC7A20_OUT_Y_H 0x2B

View File

@@ -65,12 +65,25 @@ bool USBPowerDelivery::fusbPresent() {
return detectionState == 1;
}
bool USBPowerDelivery::isVBUSConnected() { return fusb.isVBUSConnected(); }
void USBPowerDelivery::triggerRenegotiation() {
void USBPowerDelivery::triggerRenegotiation() {}
bool USBPowerDelivery::isVBUSConnected() {
static uint8_t state = 0;
if (state) {
return state == 1;
}
if (fusb.isVBUSConnected()) {
state = 1;
return true;
} else {
state = 2;
return false;
}
}
bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request) {
pd_msg lastCapabilities;
pd_msg *USBPowerDelivery::getLastSeenCapabilities() { return &lastCapabilities; }
bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request) {
memcpy(&lastCapabilities, capabilities, sizeof(pd_msg));
/* Get the number of PDOs */
uint8_t numobj = PD_NUMOBJ_GET(capabilities);

View File

@@ -2,6 +2,7 @@
#ifndef DRIVERS_USBPD_H_
#define DRIVERS_USBPD_H_
#include "configuration.h"
#include "pdb_msg.h"
#include <stdbool.h>
#include <stdint.h>
@@ -9,17 +10,19 @@
#if POW_PD
class USBPowerDelivery {
public:
static bool start(); // Start the PD stack
static bool negotiationComplete(); // Has negotiation completed to a voltage > 5v
static bool negotiationInProgress(); // Is negotiation ongoing
static bool fusbPresent(); // Is the FUSB302 present on the bus
static void PPSTimerCallback(); // PPS Timer
static void IRQOccured(); // Thread callback that an irq occured
static void step(); // Iterate the step machine
static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract)
static uint8_t getStateNumber(); // Debugging - Get the internal state number
static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302
static void triggerRenegotiation(); // Trigger a restart of voltage selection
static bool start(); // Start the PD stack
static bool negotiationComplete(); // Has negotiation completed to a voltage > 5v
static bool negotiationInProgress(); // Is negotiation ongoing
static bool fusbPresent(); // Is the FUSB302 present on the bus
static void PPSTimerCallback(); // PPS Timer
static void IRQOccured(); // Thread callback that an irq occured
static void step(); // Iterate the step machine
static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract)
static uint8_t getStateNumber(); // Debugging - Get the internal state number
static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302
static void triggerRenegotiation(); // Trigger a restart of voltage selection
static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302
static pd_msg *getLastSeenCapabilities(); // returns pointer to the last seen capabilities from the powersource
private:
//
static int detectionState;