Update config and clean up debugging calls

This commit is contained in:
Ben V. Brown
2020-07-28 21:20:36 +10:00
parent 8f395e2294
commit 0b2311e001
6 changed files with 29 additions and 30 deletions

View File

@@ -32,7 +32,7 @@
static uint8_t fusb_read_byte(uint8_t addr) { static uint8_t fusb_read_byte(uint8_t addr) {
uint8_t data[1]; uint8_t data[1];
if (!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) data, 1)) { if (!I2CBB::Mem_Read(FUSB302B_ADDR, addr, (uint8_t*) data, 1)) {
asm("bkpt"); return 0;
} }
return data[0]; return data[0];
} }
@@ -74,7 +74,7 @@ static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
void fusb_send_message(const union pd_msg *msg) { void fusb_send_message(const union pd_msg *msg) {
if (!I2CBB::lock2()) { if (!I2CBB::lock2()) {
asm("bkpt"); return;
} }
/* Token sequences for the FUSB302B */ /* Token sequences for the FUSB302B */
static uint8_t sop_seq[5] = { static uint8_t sop_seq[5] = {
@@ -113,16 +113,9 @@ uint8_t fusb_read_message(union pd_msg *msg) {
static uint8_t garbage[4]; static uint8_t garbage[4];
uint8_t numobj; uint8_t numobj;
/* If this isn't an SOP message, return error. // Read the header. If its not a SOP we dont actually want it at all
* Because of our configuration, we should be able to assume this means the // But on some revisions of the fusb if you dont both pick them up and read them out of the fifo, it gets stuck
* buffer is empty, and not try to read past a non-SOP message. */
fusb_read_byte( FUSB_FIFOS); fusb_read_byte( FUSB_FIFOS);
// if ((fusb_read_byte( FUSB_FIFOS) & FUSB_FIFO_RX_TOKEN_BITS)
// != FUSB_FIFO_RX_SOP) {
//
// I2CBB::unlock2();
// return 1;
// }
/* Read the message header into msg */ /* Read the message header into msg */
fusb_read_buf( FUSB_FIFOS, 2, msg->bytes); fusb_read_buf( FUSB_FIFOS, 2, msg->bytes);
/* Get the number of data objects */ /* Get the number of data objects */
@@ -141,7 +134,7 @@ uint8_t fusb_read_message(union pd_msg *msg) {
void fusb_send_hardrst() { void fusb_send_hardrst() {
if (!I2CBB::lock2()) { if (!I2CBB::lock2()) {
asm("bkpt"); return;
} }
/* Send a hard reset */ /* Send a hard reset */
fusb_write_byte( FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET); fusb_write_byte( FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET);
@@ -161,14 +154,14 @@ void fusb_setup() {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) { if (!I2CBB::lock2()) {
asm("bkpt"); return;
} }
} }
/* Fully reset the FUSB302B */ /* Fully reset the FUSB302B */
fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES); fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES);
delay_ms(2); osDelay(2);
if (!fusb_read_id()) { if (!fusb_read_id()) {
asm("bkpt"); return;
} }
/* Turn on all power */ /* Turn on all power */
fusb_write_byte( FUSB_POWER, 0x0F); fusb_write_byte( FUSB_POWER, 0x0F);
@@ -192,7 +185,7 @@ void fusb_setup() {
/* Measure CC1 */ /* Measure CC1 */
fusb_write_byte( FUSB_SWITCHES0, 0x07); fusb_write_byte( FUSB_SWITCHES0, 0x07);
resetWatchdog(); resetWatchdog();
delay_ms(1); osDelay(1);
resetWatchdog(); resetWatchdog();
uint8_t cc1 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL; uint8_t cc1 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL;
resetWatchdog(); resetWatchdog();
@@ -201,7 +194,7 @@ void fusb_setup() {
resetWatchdog(); resetWatchdog();
fusb_write_byte( FUSB_SWITCHES0, 0x0B); fusb_write_byte( FUSB_SWITCHES0, 0x0B);
resetWatchdog(); resetWatchdog();
delay_ms(1); osDelay(1);
resetWatchdog(); resetWatchdog();
uint8_t cc2 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL; uint8_t cc2 = fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL;
@@ -214,16 +207,16 @@ void fusb_setup() {
fusb_write_byte( FUSB_SWITCHES0, 0x0B); fusb_write_byte( FUSB_SWITCHES0, 0x0B);
} }
resetWatchdog(); resetWatchdog();
fusb_reset();
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
I2CBB::unlock2(); I2CBB::unlock2();
} }
fusb_reset();
} }
void fusb_get_status(union fusb_status *status) { void fusb_get_status(union fusb_status *status) {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) { if (!I2CBB::lock2()) {
asm("bkpt"); return;
} }
} }
@@ -238,7 +231,7 @@ void fusb_get_status(union fusb_status *status) {
enum fusb_typec_current fusb_get_typec_current() { enum fusb_typec_current fusb_get_typec_current() {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) { if (!I2CBB::lock2()) {
asm("bkpt"); return fusb_tcc_none;
} }
} }
/* Read the BC_LVL into a variable */ /* Read the BC_LVL into a variable */
@@ -253,7 +246,7 @@ enum fusb_typec_current fusb_get_typec_current() {
void fusb_reset() { void fusb_reset() {
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
if (!I2CBB::lock2()) { if (!I2CBB::lock2()) {
asm("bkpt"); return;
} }
} }

View File

@@ -8,8 +8,12 @@
#include "stdlib.h" #include "stdlib.h"
#include "task.h" #include "task.h"
#include "I2C_Wrapper.hpp" #include "I2C_Wrapper.hpp"
#include "fusbpd.h"
void postRToSInit() { void postRToSInit() {
// Any after RTos setup // Any after RTos setup
FRToSI2C::FRToSInit(); FRToSI2C::FRToSInit();
#ifdef POW_PD
//Spawn all of the USB-C processors
fusb302_start_processing();
#endif
} }

View File

@@ -25,8 +25,5 @@ void preRToSInit() {
I2CBB::init(); I2CBB::init();
#endif #endif
#ifdef POW_PD
//Spawn all of the USB-C processors
fusb302_start_processing();
#endif
} }

View File

@@ -23,6 +23,7 @@ void fusb302_start_processing() {
/* Initialize the FUSB302B */ /* Initialize the FUSB302B */
resetWatchdog(); resetWatchdog();
fusb_setup(); fusb_setup();
osDelay(50);
resetWatchdog(); resetWatchdog();
/* Create the policy engine thread. */ /* Create the policy engine thread. */
PolicyEngine::init(); PolicyEngine::init();

View File

@@ -728,6 +728,10 @@ static void settings_setCalibrateVIN(void) {
case BUTTON_F_LONG: case BUTTON_F_LONG:
case BUTTON_B_LONG: case BUTTON_B_LONG:
saveSettings(); saveSettings();
OLED::setCursor(0, 0);
OLED::printNumber(systemSettings.voltageDiv, 3);
OLED::refresh();
waitForButtonPressOrTimeout(100);
return; return;
break; break;
case BUTTON_NONE: case BUTTON_NONE:

View File

@@ -119,11 +119,11 @@
#endif #endif
#ifdef MODEL_TS80P #ifdef MODEL_TS80P
#define VOLTAGE_DIV 768 // Default for TS80P with slightly different resistors #define VOLTAGE_DIV 650 // Default for TS80P with slightly different resistors
#define PID_POWER_LIMIT 30 // Sets the max pwm power limit #define PID_POWER_LIMIT 35 // Sets the max pwm power limit
#define CALIBRATION_OFFSET 900 // the adc offset in uV #define CALIBRATION_OFFSET 900 // the adc offset in uV
#define POWER_LIMIT 24 // 24 watts default power limit #define POWER_LIMIT 30 // 30 watts default power limit
#define MAX_POWER_LIMIT 30 // #define MAX_POWER_LIMIT 35 //
#define POWER_LIMIT_STEPS 2 #define POWER_LIMIT_STEPS 2
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80 #define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
#endif #endif