diff --git a/workspace/TS100/Core/BSP/Miniware/Model_Config.h b/workspace/TS100/Core/BSP/Miniware/Model_Config.h index 0ed53702..d2732c6a 100644 --- a/workspace/TS100/Core/BSP/Miniware/Model_Config.h +++ b/workspace/TS100/Core/BSP/Miniware/Model_Config.h @@ -21,6 +21,7 @@ #define ACCEL_MMA #define ACCEL_LIS #define TEMP_TMP36 +#define BATTFILTERDEPTH 32 #endif #ifdef MODEL_TS80 @@ -29,6 +30,7 @@ #define TEMP_TMP36 #define ACCEL_ORI_FLIP #define OLED_FLIP +#define BATTFILTERDEPTH 8 #endif #ifdef MODEL_TS80P @@ -39,6 +41,7 @@ #define I2C_SOFT #define ACCEL_ORI_FLIP #define OLED_FLIP +#define BATTFILTERDEPTH 8 #endif #endif /* BSP_MINIWARE_MODEL_CONFIG_H_ */ diff --git a/workspace/TS100/Core/BSP/Pine64/BSP.cpp b/workspace/TS100/Core/BSP/Pine64/BSP.cpp index e1632cfb..e027635f 100644 --- a/workspace/TS100/Core/BSP/Pine64/BSP.cpp +++ b/workspace/TS100/Core/BSP/Pine64/BSP.cpp @@ -11,37 +11,32 @@ #include //2 second filter (ADC is PID_TIM_HZ Hz) -history rawTempFilter = {{0}, 0, 0}; +history rawTempFilter = { { 0 }, 0, 0 }; void resetWatchdog() { - //TODO + //TODO } uint16_t getTipInstantTemperature() { - uint16_t sum = 0; // 12 bit readings * 8 -> 15 bits + uint16_t sum = 0; // 12 bit readings * 8 -> 15 bits - for (int i = 0; i < 4; i++) { - sum += adc_inserted_data_read(ADC0, i); - sum += adc_inserted_data_read(ADC1, i); - } - return sum; // 8x over sample + for (int i = 0; i < 4; i++) { + sum += adc_inserted_data_read(ADC0, i); + sum += adc_inserted_data_read(ADC1, i); + } + return sum; // 8x over sample } -uint16_t getTipRawTemp(uint8_t refresh) -{ - if (refresh) - { +uint16_t getTipRawTemp(uint8_t refresh) { + if (refresh) { uint16_t lastSample = getTipInstantTemperature(); rawTempFilter.update(lastSample); return lastSample; - } - else - { + } else { return rawTempFilter.average(); } } -uint16_t getHandleTemperature() -{ +uint16_t getHandleTemperature() { #ifdef TEMP_TMP36 // We return the current handle temperature in X10 C // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for @@ -61,29 +56,21 @@ uint16_t getHandleTemperature() #error #endif } -uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) -{ +uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) { // ADC maximum is 32767 == 3.3V at input == 28.05V at VIN // Therefore we can divide down from there // Multiplying ADC max by 4 for additional calibration options, // ideal term is 467 -#ifdef MODEL_TS100 -#define BATTFILTERDEPTH 32 -#else -#define BATTFILTERDEPTH 8 -#endif static uint8_t preFillneeded = 10; static uint32_t samples[BATTFILTERDEPTH]; static uint8_t index = 0; - if (preFillneeded) - { + if (preFillneeded) { for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) samples[i] = getADC(1); preFillneeded--; } - if (sample) - { + if (sample) { samples[index] = getADC(1); index = (index + 1) % BATTFILTERDEPTH; } @@ -93,28 +80,29 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) sum += samples[i]; sum /= BATTFILTERDEPTH; - if (divisor == 0) - { + if (divisor == 0) { divisor = 1; } return sum * 4 / divisor; } void unstick_I2C() { - // TODO + // TODO } uint8_t getButtonA() { - return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; + return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; } uint8_t getButtonB() { - return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; + return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; } void reboot() { - // TODO - for (;;) { - } + // TODO + for (;;) { + } } -void delay_ms(uint16_t count) { delay_1ms(count); } +void delay_ms(uint16_t count) { + delay_1ms(count); +} diff --git a/workspace/TS100/Core/BSP/Pine64/Model_Config.h b/workspace/TS100/Core/BSP/Pine64/Model_Config.h index 6a64a04f..e2aff5d7 100644 --- a/workspace/TS100/Core/BSP/Pine64/Model_Config.h +++ b/workspace/TS100/Core/BSP/Pine64/Model_Config.h @@ -17,9 +17,11 @@ #ifdef MODEL_Pinecil #define POW_PD -#define POW_QC +//#define POW_QC #define TEMP_TMP36 -#define ACCEL_BMA +//#define ACCEL_BMA + +#define BATTFILTERDEPTH 32 #endif #endif /* BSP_MINIWARE_MODEL_CONFIG_H_ */ diff --git a/workspace/TS100/Core/BSP/Pine64/fusb302b.cpp b/workspace/TS100/Core/BSP/Pine64/fusb302b.cpp index 6d35bb57..fae5882a 100644 --- a/workspace/TS100/Core/BSP/Pine64/fusb302b.cpp +++ b/workspace/TS100/Core/BSP/Pine64/fusb302b.cpp @@ -70,14 +70,12 @@ static bool fusb_write_byte(uint8_t addr, uint8_t byte) { * buf: The buffer to write */ static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { - FRToSI2C::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*)buf, size); + FRToSI2C::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) buf, size); return true; //TODO } void fusb_send_message(const union pd_msg *msg) { - if (!FRToSI2C::lock2()) { - return; - } + /* Token sequences for the FUSB302B */ static uint8_t sop_seq[5] = { FUSB_FIFO_TX_SOP1, @@ -104,14 +102,10 @@ void fusb_send_message(const union pd_msg *msg) { fusb_write_buf( FUSB_FIFOS, msg_len, msg->bytes); fusb_write_buf( FUSB_FIFOS, 4, eop_seq); - FRToSI2C::unlock2(); - } uint8_t fusb_read_message(union pd_msg *msg) { - if (!FRToSI2C::lock2()) { - return 1; - } + static uint8_t garbage[4]; uint8_t numobj; @@ -129,33 +123,23 @@ uint8_t fusb_read_message(union pd_msg *msg) { /* Throw the CRC32 in the garbage, since the PHY already checked it. */ fusb_read_buf( FUSB_FIFOS, 4, garbage); - FRToSI2C::unlock2(); return 0; } void fusb_send_hardrst() { - if (!FRToSI2C::lock2()) { - return; - } /* Send a hard reset */ fusb_write_byte( FUSB_CONTROL3, 0x07 | FUSB_CONTROL3_SEND_HARD_RESET); - FRToSI2C::unlock2(); } void fusb_setup() { - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - if (!FRToSI2C::lock2()) { - return; - } - } /* Fully reset the FUSB302B */ fusb_write_byte( FUSB_RESET, FUSB_RESET_SW_RES); osDelay(2); - if (!fusb_read_id()) { - return; + while (!fusb_read_id()) { + osDelay(10); } /* Turn on all power */ @@ -194,48 +178,27 @@ void fusb_setup() { fusb_write_byte( FUSB_SWITCHES1, 0x26); fusb_write_byte( FUSB_SWITCHES0, 0x0B); } - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - FRToSI2C::unlock2(); - } + fusb_reset(); } void fusb_get_status(union fusb_status *status) { - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - if (!FRToSI2C::lock2()) { - return; - } - } /* Read the interrupt and status flags into status */ fusb_read_buf( FUSB_STATUS0A, 7, status->bytes); - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - FRToSI2C::unlock2(); - } } enum fusb_typec_current fusb_get_typec_current() { - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - if (!FRToSI2C::lock2()) { - return fusb_tcc_none; - } - } + /* Read the BC_LVL into a variable */ enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte( FUSB_STATUS0) & FUSB_STATUS0_BC_LVL); - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - FRToSI2C::unlock2(); - } + return bc_lvl; } void fusb_reset() { - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - if (!FRToSI2C::lock2()) { - return; - } - } /* Flush the TX buffer */ fusb_write_byte( FUSB_CONTROL0, 0x44); @@ -243,9 +206,6 @@ void fusb_reset() { fusb_write_byte( FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH); /* Reset the PD logic */ // fusb_write_byte( FUSB_RESET, FUSB_RESET_PD_RESET); - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { - FRToSI2C::unlock2(); - } } bool fusb_read_id() { diff --git a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp index a94e21b7..addd92e3 100644 --- a/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp +++ b/workspace/TS100/Core/Drivers/FUSB302/int_n.cpp @@ -32,8 +32,7 @@ uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize]; osStaticThreadDef_t InterruptHandler::TaskControlBlock; void InterruptHandler::init() { - osThreadStaticDef(intTask, Thread, PDB_PRIO_PRL_INT_N, 0, TaskStackSize, - TaskBuffer, &TaskControlBlock); + osThreadStaticDef(intTask, Thread, PDB_PRIO_PRL_INT_N, 0, TaskStackSize, TaskBuffer, &TaskControlBlock); TaskHandle = osThreadCreate(osThread(intTask), NULL); } @@ -42,8 +41,7 @@ void InterruptHandler::Thread(const void *arg) { union fusb_status status; while (true) { /* If the INT_N line is low */ - if (xTaskNotifyWait(0x00, 0x0F, NULL, - PolicyEngine::setupCompleteOrTimedOut() ? 1000 : 10) == pdPASS) { + if (xTaskNotifyWait(0x00, 0x0F, NULL, PolicyEngine::setupCompleteOrTimedOut() ? 1000 : 10) == pdPASS) { //delay slightly so we catch the crc with better timing osDelay(1); } @@ -52,12 +50,10 @@ void InterruptHandler::Thread(const void *arg) { /* If the I_TXSENT or I_RETRYFAIL flag is set, tell the Protocol TX * thread */ if (status.interrupta & FUSB_INTERRUPTA_I_TXSENT) { - ProtocolTransmit::notify( - ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_TXSENT); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_TXSENT); } if (status.interrupta & FUSB_INTERRUPTA_I_RETRYFAIL) { - ProtocolTransmit::notify( - ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_RETRYFAIL); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_I_RETRYFAIL); } /* If the I_GCRCSENT flag is set, tell the Protocol RX thread */ @@ -68,8 +64,7 @@ void InterruptHandler::Thread(const void *arg) { /* If the I_OCP_TEMP and OVRTEMP flags are set, tell the Policy * Engine thread */ - if (status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP - && status.status1 & FUSB_STATUS1_OVRTEMP) { + if ((status.interrupta & FUSB_INTERRUPTA_I_OCP_TEMP) && (status.status1 & FUSB_STATUS1_OVRTEMP)) { PolicyEngine::notify(PDB_EVT_PE_I_OVRTEMP); } } @@ -77,8 +72,7 @@ void InterruptHandler::Thread(const void *arg) { void InterruptHandler::irqCallback() { if (TaskHandle != NULL) { BaseType_t taskWoke = pdFALSE; - xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetBits, - &taskWoke); + xTaskNotifyFromISR(TaskHandle, 0x01, eNotifyAction::eSetBits, &taskWoke); portYIELD_FROM_ISR(taskWoke); } }