1
0
forked from me/IronOS

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

View File

@@ -8,8 +8,12 @@
#include "stdlib.h"
#include "task.h"
#include "I2C_Wrapper.hpp"
#include "fusbpd.h"
void postRToSInit() {
// Any after RTos setup
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();
#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 */
resetWatchdog();
fusb_setup();
osDelay(50);
resetWatchdog();
/* Create the policy engine thread. */
PolicyEngine::init();

View File

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

View File

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