From 3d12b7066d27b591e0283e20ed066bc66e29fbe4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 10 Nov 2023 21:34:40 -0700 Subject: refactor checkpoint: splitting MCU-specific code into arch/$MCU.[ch] Phew, that's a lot of changes! And there's still a lot more to do... --- ui/anduril/anduril.c | 18 +++++++++++------- ui/anduril/config-default.h | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/anduril/anduril.c b/ui/anduril/anduril.c index e72c3b5..c434518 100644 --- a/ui/anduril/anduril.c +++ b/ui/anduril/anduril.c @@ -34,16 +34,19 @@ * as possible. These are mostly "USE" flags. */ +/********* load up MCU info, like ROM size and such *********/ +#include "arch/mcu.h" + /********* User-configurable options *********/ #include "anduril/config-default.h" /********* specific settings for known driver types *********/ -// Anduril config file name (set it here or define it at the gcc command line) -//#define CFG_H cfg-blf-q8.h -#include "fsm/tk.h" #include incfile(CFG_H) +#ifdef HWDEF_H +#include incfile(HWDEF_H) +#endif /********* Include headers which need to be before FSM *********/ @@ -77,11 +80,12 @@ #include "fsm/spaghetti-monster.h" /********* does this build target have special code to include? *********/ -#ifdef HWDEF_C_FILE -#include incfile(HWDEF_C_FILE) +#ifdef CFG_C +#include incfile(CFG_C) #endif -#ifdef CFG_C_FILE -#include incfile(CFG_C_FILE) + +#ifdef HWDEF_C +#include incfile(HWDEF_C) #endif diff --git a/ui/anduril/config-default.h b/ui/anduril/config-default.h index 899bc4a..04fc956 100644 --- a/ui/anduril/config-default.h +++ b/ui/anduril/config-default.h @@ -20,7 +20,7 @@ // overheat protection #define USE_THERMAL_REGULATION -#if (ATTINY==85) || (ATTINY==1634) +#if (MCU==0x85) || (MCU==0x1634) // sloppy temperature sensor needs bigger error margin #define DEFAULT_THERM_CEIL 45 // try not to get hotter than this (in C) #else @@ -185,7 +185,7 @@ // if the aux LEDs oscillate between "full battery" and "empty battery" // while in "voltage" mode, enable this to reduce the amplitude of // those oscillations -#if (ATTINY==1616) || (ATTINY==1634) +#if (ROM_SIZE > 10000) #define USE_LOWPASS_WHILE_ASLEEP #endif @@ -195,7 +195,7 @@ // Use "smooth steps" to soften on/off and step changes // on MCUs with enough room for extra stuff like this -#if (ATTINY==1616) || (ATTINY==1634) +#if (ROM_SIZE > 10000) #define USE_SMOOTH_STEPS #endif // 0 = none, 1 = smooth, 2+ = undefined -- cgit v1.2.3 From a4d96f08a017ce9d475b2575c597e741c6e8af1e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 19 Nov 2023 01:42:33 -0700 Subject: version check: allow hex digits --- ui/anduril/version-check-mode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/anduril/version-check-mode.c b/ui/anduril/version-check-mode.c index eebe59b..1cd6968 100644 --- a/ui/anduril/version-check-mode.c +++ b/ui/anduril/version-check-mode.c @@ -15,7 +15,10 @@ uint8_t version_check_state(Event event, uint16_t arg) { inline void version_check_iter() { for (uint8_t i=0; i ? + if (digit < 16) blink_digit(digit); else { // "buzz" for non-numeric characters for(uint8_t frame=0; frame<25; frame++) { set_level((frame&1) << 5); -- cgit v1.2.3 From 95d931dc167ae01d6af1973ea68496584fe03541 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 19 Nov 2023 01:44:35 -0700 Subject: ramp-mode: allow hwdef to adjust gradual tick speed The gradual tick frequency was written for 8-bit PWM, but it can be too slow on hardware with more bits. The hwdef can compensate by using larger steps, but that makes adjustments more visible... So this provides an option to increase speed without visibility. --- ui/anduril/config-default.h | 6 ++++++ ui/anduril/ramp-mode.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/anduril/config-default.h b/ui/anduril/config-default.h index 04fc956..cd25b52 100644 --- a/ui/anduril/config-default.h +++ b/ui/anduril/config-default.h @@ -113,6 +113,12 @@ // timer is available in regular ramp mode and candle mode #define USE_SUNSET_TIMER +// optionally make gradual ticks happen faster +// Affects: thermal regulation speed, sunset mode, maybe other features +// (default is calibrated for 8-bit PWM, +// but 10-bit should set this value to 4 instead of 1) +#define GRADUAL_ADJUST_SPEED 1 + ///// What to do when power is connected ///// // factory reset function erases user's runtime configuration in eeprom diff --git a/ui/anduril/ramp-mode.c b/ui/anduril/ramp-mode.c index 9e19025..4c535b4 100644 --- a/ui/anduril/ramp-mode.c +++ b/ui/anduril/ramp-mode.c @@ -287,7 +287,7 @@ uint8_t steady_state(Event event, uint16_t arg) { static uint16_t ticks_since_adjust = 0; ticks_since_adjust++; if (diff) { - uint16_t ticks_per_adjust = 256; + uint16_t ticks_per_adjust = 256 / GRADUAL_ADJUST_SPEED; if (diff < 0) { //diff = -diff; if (actual_level > THERM_FASTER_LEVEL) { -- cgit v1.2.3 From 8bc6e16569474487efcee3eaee7b6af9738585b8 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 21 Nov 2023 02:44:11 -0700 Subject: 1.55V AA battery should not show as "white" voltage color, only purple --- ui/anduril/aux-leds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/anduril/aux-leds.c b/ui/anduril/aux-leds.c index 1b30d34..dce8d26 100644 --- a/ui/anduril/aux-leds.c +++ b/ui/anduril/aux-leds.c @@ -67,7 +67,7 @@ uint8_t voltage_to_rgb() { 12, 4, // G+B 13, 5, // B 14, 6, // R + B - 15, 7, // R+G+B + 16, 7, // R+G+B 20, 0, // black #endif // li-ion voltages -- cgit v1.2.3 From baaa035cf93340b8f2c626bdba47e8066cf40067 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 22 Nov 2023 05:34:26 -0700 Subject: ADC voltage: battcheck 3 digits, fixed t1616, switched back to 8-bit internal volt unit Before this branch, `voltage` was 6 bits: Volts * 10 A couple patches ago, I upgraded it to 16 bits: 65535 * Volts / 10.24 That costs too much extra ROM on attiny85 though, for extra precision it doesn't even use... so I switched back to an 8-bit value. It's still more precise than before though: Volts * 40 ... and battcheck displays an extra digit now, on devices with ROM for it. ... and battcheck waits a second to get a more accurate measurement before displaying the first value. It has *much* less variation between first and later readings now. Also: - got t1616 builds working again (tested fc13 and thefreeman-boost-fwaa) - upgraded t1616 voltage and temp to 12-bit (10 bits + 4x oversampling) - removed expensive temp conversion from t1616 ADC interrupt - recalibrated t1616 bogomips again; runs faster after interrupt fix - increased t1616 internal VDD measurement resolution by 36% (1.5V Vref, not 1.1V) - fixed sloppy setting of Vref bits I still need to test / update other t1616 builds, and fix all the t85 + t1634 code and build targets. --- ui/anduril/anduril.c | 1 + ui/anduril/aux-leds.c | 34 +++++++++++++++++----------------- ui/anduril/config-default.h | 4 ++++ 3 files changed, 22 insertions(+), 17 deletions(-) (limited to 'ui') diff --git a/ui/anduril/anduril.c b/ui/anduril/anduril.c index c434518..1cdb8d0 100644 --- a/ui/anduril/anduril.c +++ b/ui/anduril/anduril.c @@ -316,6 +316,7 @@ void loop() { #ifdef USE_BATTCHECK else if (state == battcheck_state) { + nice_delay_ms(1000); // wait a moment for a more accurate reading battcheck(); #ifdef USE_SIMPLE_UI // in simple mode, turn off after one readout diff --git a/ui/anduril/aux-leds.c b/ui/anduril/aux-leds.c index dce8d26..fd184fc 100644 --- a/ui/anduril/aux-leds.c +++ b/ui/anduril/aux-leds.c @@ -58,27 +58,27 @@ void indicator_led_update(uint8_t mode, uint8_t tick) { uint8_t voltage_to_rgb() { static const uint8_t levels[] = { // voltage, color - 0, 0, // black + 0, 0, // black #ifdef DUAL_VOLTAGE_FLOOR // AA / NiMH voltages - 9, 1, // R - 10, 2, // R+G - 11, 3, // G - 12, 4, // G+B - 13, 5, // B - 14, 6, // R + B - 16, 7, // R+G+B - 20, 0, // black + 4* 9, 1, // R + 4*10, 2, // R+G + 4*11, 3, // G + 4*12, 4, // G+B + 4*13, 5, // B + 4*14, 6, // R + B + 4*16, 7, // R+G+B + 4*20, 0, // black #endif // li-ion voltages - 29, 1, // R - 33, 2, // R+G - 35, 3, // G - 37, 4, // G+B - 39, 5, // B - 41, 6, // R + B - 44, 7, // R+G+B // skip; looks too similar to G+B - 255, 7, // R+G+B + 4*29, 1, // R + 4*33, 2, // R+G + 4*35, 3, // G + 4*37, 4, // G+B + 4*39, 5, // B + 4*41, 6, // R + B + 4*44, 7, // R+G+B // skip; looks too similar to G+B + 255, 7, // R+G+B }; uint8_t volts = voltage; //if (volts < VOLTAGE_LOW) return 0; diff --git a/ui/anduril/config-default.h b/ui/anduril/config-default.h index cd25b52..1b34e8c 100644 --- a/ui/anduril/config-default.h +++ b/ui/anduril/config-default.h @@ -143,6 +143,10 @@ #define BATTCHECK_VpT //#define BATTCHECK_8bars // FIXME: breaks build //#define BATTCHECK_4bars // FIXME: breaks build +#if ROM_SIZE > 10000 + // battcheck displays 1.25V instead of 1.2V + #define USE_EXTRA_BATTCHECK_DIGIT +#endif // allow the user to calibrate the voltage readings? // (adjust in 0.05V increments from -0.30V to +0.30V) // (1 = -0.30V, 2 = -0.25V, ... 7 = 0V, ... 13 = +0.30V) -- cgit v1.2.3 From 4373ed25154fb77f44d3b0ba6d3f5cc78127cc45 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 28 Nov 2023 13:12:05 -0700 Subject: prevent future issues like the FW3X had 1/3rd of the ramp size is probably a more reliable default than MAX_1x7135. The 7135-based reference points need to eventually be removed entirely and replaced by something more universal, but for now at least don't fail when a thermal stepdown isn't defined. --- ui/anduril/ramp-mode.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/anduril/ramp-mode.h b/ui/anduril/ramp-mode.h index 59c8db0..1392981 100644 --- a/ui/anduril/ramp-mode.h +++ b/ui/anduril/ramp-mode.h @@ -4,14 +4,15 @@ #pragma once -#ifndef RAMP_LENGTH -#define RAMP_LENGTH 150 // default, if not overridden in a driver cfg file +#ifndef RAMP_SIZE +#define RAMP_SIZE 150 // default, if not overridden in a driver cfg file #endif +// TODO: Replace MAX_Xx7135 with MAX_CH1, MAX_CH2, MAX_REGULATED, etc + // thermal properties, if not defined per-driver #ifndef MIN_THERM_STEPDOWN -// TODO: Replace MAX_Xx7135 with MAX_CH1, MAX_CH2, MAX_REGULATED, etc -#define MIN_THERM_STEPDOWN MAX_1x7135 // lowest value it'll step down to +#define MIN_THERM_STEPDOWN (RAMP_SIZE/3) // lowest value it'll step down to #endif #ifndef THERM_FASTER_LEVEL #ifdef MAX_Nx7135 -- cgit v1.2.3