diff options
| author | Selene ToyKeeper | 2025-04-29 00:10:31 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2025-04-29 00:10:31 -0600 |
| commit | 04f43399041029b9d5a03160be6ba0588325fad0 (patch) | |
| tree | 53bfb6e033c42665b8ab7b5221e85cb969d6a041 /hw/hank/lume-x1/hwdef.c | |
| parent | memester egg (diff) | |
| parent | changed hank-lume-x1 model number back on 2024-09-28 (diff) | |
| download | anduril-04f43399041029b9d5a03160be6ba0588325fad0.tar.gz anduril-04f43399041029b9d5a03160be6ba0588325fad0.tar.bz2 anduril-04f43399041029b9d5a03160be6ba0588325fad0.zip | |
Merge branch 'hank-lume-x1' into trunk
Finally remembered to merge this. Thought I had done it months ago...
Anyway, now that I've been able to test it on production hardware,
everything seems fine. The super-low firefly modes are a bit more
usable on production hardware too. Level 1/150 is dimmer than the low
aux LEDs, while level 2/150 is about as bright as low aux.
* hank-lume-x1:
changed hank-lume-x1 model number back on 2024-09-28 for some reason, and didn't commit... saving now to change branches, but should delete this commit if it turns out there was no reason for it
hank-lume-x1: minor calibration and cleaning - calibrated party strobe - removed duplicate or commented-out code - added a basic readme
hank-lume-x1 cleanup and calibration, part 1: - changed model number from 0281 to 0171 - cleaned up blink_negative and AUXLED_RGB_DIFFERENT_PORTS a little (but the latter needs a complete refactor, as soon as the hardware abstraction code can handle aux LEDs better) - cleaned up USE_LONG_BLINK_FOR_NEGATIVE_SIGN a little - removed USE_OTG_IN_MOMENTARY since it's not actually used - moved hw/loneoceans/lume-x1-avr32dd20/* files into hw/hank/lume-x1/ - superficial cleanup on hank/lume-x1/hwdef.* - removed some of the extra stuff from hank/lume-x1/anduril.h - adjusted calibration (especially ramp table) on hank-lume-x1 (ramp shape is pretty close to a D4K-boost now, but with more firefly modes) (calibration is based on a sample size of 1, further testing needed)
cherry-picked hank-lume-x1 code from https://github.com/loneoceans/anduril/commit/d83ebb75dab8c462b7efa841bccc00a136ff15a2
Diffstat (limited to 'hw/hank/lume-x1/hwdef.c')
| -rw-r--r-- | hw/hank/lume-x1/hwdef.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/hw/hank/lume-x1/hwdef.c b/hw/hank/lume-x1/hwdef.c new file mode 100644 index 0000000..3fe32f3 --- /dev/null +++ b/hw/hank/lume-x1/hwdef.c @@ -0,0 +1,116 @@ +// Copyright (C) 2017-2023 Selene ToyKeeper +// 2021-2024 loneoceans +// SPDX-License-Identifier: GPL-3.0-or-later + +//*********************************************** +//** HELPER FUNCTIONS FOR LUME-X1-AVR32DD20 ** +//*********************************************** + +#pragma once + +#include "fsm/chan-rgbaux.c" + +// Declare variables and functions to support UDR multiple power paths +uint8_t is_boost_currently_on = 0; // for turn-on delay during first turn on + +void set_level_zero(); +void set_level_udr(uint8_t level); +bool gradual_tick_main(uint8_t gt); +void set_power_path(uint8_t ramp_level); + +Channel channels[] = { + { // main LEDs + .set_level = set_level_udr, + .gradual_tick = gradual_tick_main + }, + RGB_AUX_CHANNELS +}; + +// turn off +void set_level_zero() { + + DAC_LVL = 0; // set DAC to 0 + DAC_VREF = V10; // set DAC Vref to lowest + + // turn off DC/DC converter and amplifier + BST_ENABLE_PORT &= ~(1 << BST_ENABLE_PIN); + is_boost_currently_on = 0; + + // turn off all UDR paths + LED_PATH1_PORT &= ~LED_PATH1_PIN; + LED_PATH2_PORT &= ~LED_PATH2_PIN; + LED_PATH3_PORT &= ~LED_PATH3_PIN; +} + +// UDR for set_level, which sets the led brightness based on ramp tables. +// single set of LED(s), fully regulated boost at all levels +void set_level_udr(uint8_t level) { + if (level == actual_level - 1) return; // no-op + + // get the ramp data + PWM1_DATATYPE dac_lvl = PWM1_GET(level) << 6; // dac register is left-aligned + PWM2_DATATYPE dac_vref = PWM2_GET(level); + + if(is_boost_currently_on != 1){ + // boost is not on, enable buck and add boot-up delay + is_boost_currently_on = 1; + BST_ENABLE_PORT |= (1 << BST_ENABLE_PIN); // turn on buck and amplifier + delay_4ms(BST_ON_DELAY/4); // boot-up delay + } + // set the DAC + DAC_LVL = dac_lvl; + DAC_VREF = dac_vref; + + // set the power paths + set_power_path(level); +} + +// handles dynamic Vref used in the ramp tables +bool gradual_tick_main(uint8_t gt) { + // TODO overall smoothness can be improved due to gt using linear + // adjustments, but ramp table is non-linear. + + // if Vref is the same, make gradual adjustments. + // else, jump to the next ramp level and use set_level() to handle power paths. + PWM2_DATATYPE vref_next = PWM2_GET(gt); // DAC ramp table Vref + + // if different vref level, make a ramp level adjustment.. + if (vref_next != DAC_VREF) return true; // use set_level() to handle normally + + // .. else, same vref, adjust level gradually. + PWM1_DATATYPE dac_next = PWM1_GET(gt); // DAC ramp table data + PWM1_DATATYPE dac_curr = DAC_LVL >> 6; // register is left-aligned + + GRADUAL_ADJUST_SIMPLE(dac_next, dac_curr); + DAC_LVL = dac_curr << 6; + + if (dac_next == dac_curr) return true; // done + + return false; +} + +// handles dynamic power pathways based on threshold levels +void set_power_path(uint8_t ramp_level){ + + ramp_level ++; // convert to 1-based indexing + + if (ramp_level >= LED_PATH3_PIN_LEVEL_MIN) { + // high mode + LED_PATH1_PORT |= LED_PATH1_PIN; + LED_PATH2_PORT |= LED_PATH2_PIN; + LED_PATH3_PORT |= LED_PATH3_PIN; + } + else if (ramp_level >= LED_PATH2_PIN_LEVEL_MIN) { + // low mode + LED_PATH1_PORT |= LED_PATH1_PIN; + LED_PATH2_PORT |= LED_PATH2_PIN; + LED_PATH3_PORT &= ~LED_PATH3_PIN; + } + else if (ramp_level >= LED_PATH1_PIN_LEVEL_MIN) { + // firefly mode + LED_PATH1_PORT |= LED_PATH1_PIN; + LED_PATH2_PORT &= ~LED_PATH2_PIN; + LED_PATH3_PORT &= ~LED_PATH3_PIN; + } +} + |
