reform

MNT Reform: Open Source Portable Computer
Log (Feed) | Files | Refs (Tags) | README

commit 0ef65dbcb58a87cbffeb06a72aca4dcab4faed45
parent 31f776621931f69407ce90c12ca663539caac1a9
Author: Lukas F. Hartmann <lukas@mntre.com>
Date:   Thu, 26 Oct 2023 19:00:00 +0200

keyboard-fw: PWMVAL 7 makes my v2 kbd blink

Diffstat:
Mreform2-keyboard-fw/backlight.c | 2+-
Mreform2-lpc-fw/src/boards/reform2/board_reform2.c | 28++++++++++++++++------------
2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/reform2-keyboard-fw/backlight.c b/reform2-keyboard-fw/backlight.c @@ -8,7 +8,7 @@ #include "backlight.h" #define KBD_MIN_PWMVAL 0 -#define KBD_MAX_PWMVAL 7 +#define KBD_MAX_PWMVAL 6 #define KBD_PWM_STEP 1 int16_t pwmval = KBD_MAX_PWMVAL; diff --git a/reform2-lpc-fw/src/boards/reform2/board_reform2.c b/reform2-lpc-fw/src/boards/reform2/board_reform2.c @@ -39,7 +39,7 @@ // don't forget to set this to the correct rev for your motherboard! // if you have a motherboard made in 2023 (2.5 R-2): -//#define REFORM_MOTHERBOARD_REV REFORM_MBREV_25_R2 +#define REFORM_MOTHERBOARD_REV REFORM_MBREV_25_R2 // if you have a motherboard made before 2023 (2.0 R-3): //#define REFORM_MOTHERBOARD_REV REFORM_MBREV_20_R3 @@ -183,6 +183,7 @@ enum state_t { // charging state machine int state = ST_CHARGE; int cycles_in_state = 0; +int cycles_uptime = 0; int charge_current = 1; uint32_t cur_second = 0; uint32_t last_second = 0; @@ -526,9 +527,9 @@ void turn_aux_power_off(void) { } void brownout_setup(void) { - // Set brownout threshold to 2.63-2.71V (highest level) + // Set brownout threshold to 1.46-1.63V (lowest level) // and enable brownout reset (BODRSTENA) - LPC_SYSCON->BODCTRL = 0x3 | (1<<4); + LPC_SYSCON->BODCTRL = 0x0 | (1<<4); } void watchdog_feed(void) { @@ -752,21 +753,21 @@ void handle_commands() { // get charger system state if (state == ST_CHARGE) { - sprintf(uartBuffer,FW_REV"normal,%d,%d,%d\r",cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"norm(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime); } else if (state == ST_OVERVOLTED) { - sprintf(uartBuffer,FW_REV"balancing,%d,%d,%d\r",cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"baln(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime); } else if (state == ST_COOLDOWN) { - sprintf(uartBuffer,FW_REV"cooldown,%d,%d,%d\r",cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"cool(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime); } else if (state == ST_UNDERVOLTED) { - sprintf(uartBuffer,FW_REV"undervolted,%d,%d,%d\r",cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"uvol(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime); } else if (state == ST_MISSING) { - sprintf(uartBuffer,FW_REV"cells missing:%d,%d,%d,%d\r",missing_reason,cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"miss:%d(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",missing_reason,cycles_in_state,min_mah,acc_mah,cycles_uptime); } else if (state == ST_FULLY_CHARGED) { - sprintf(uartBuffer,FW_REV"full charge,%d,%d,%d\r",cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"full(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime); } else if (state == ST_POWERSAVE) { - sprintf(uartBuffer,FW_REV"powersave,%d,%d,%d\r",cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"psav(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime); } else { - sprintf(uartBuffer,FW_REV"unknown:%d,%d,%d,%d\r",state,cycles_in_state,min_mah,acc_mah); + sprintf(uartBuffer,"unkn:%d(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",state,cycles_in_state,min_mah,acc_mah,cycles_uptime); } uartSend((uint8_t*)uartBuffer, strlen(uartBuffer)); @@ -1147,6 +1148,7 @@ int main(void) { state = ST_CHARGE; cycles_in_state = 0; + cycles_uptime = 0; powersave_holdoff_cycles = POWERSAVE_HOLDOFF_CYCLES; last_second = delayGetSecondsActive(); @@ -1314,7 +1316,9 @@ int main(void) { if (cur_second-last_second<10) { // prevent rollovers cycles_in_state += cur_second-last_second; - + cycles_uptime += cur_second-last_second; + if (cycles_in_state < 0) cycles_in_state = 0; + if (cycles_uptime < 0) cycles_uptime = 0; } last_second = cur_second;