diff options
Diffstat (limited to 'hw')
| -rw-r--r-- | hw/hank/lume-x1/anduril.h | 33 | ||||
| -rw-r--r-- | hw/hank/lume-x1/arch | 1 | ||||
| -rw-r--r-- | hw/hank/lume-x1/model | 1 | ||||
| -rw-r--r-- | hw/loneoceans/lume-x1-avr32dd20/anduril.h | 198 | ||||
| -rw-r--r-- | hw/loneoceans/lume-x1-avr32dd20/arch | 1 | ||||
| -rw-r--r-- | hw/loneoceans/lume-x1-avr32dd20/hwdef.c | 130 | ||||
| -rw-r--r-- | hw/loneoceans/lume-x1-avr32dd20/hwdef.h | 232 | ||||
| -rw-r--r-- | hw/loneoceans/lume-x1-avr32dd20/model | 1 |
8 files changed, 597 insertions, 0 deletions
diff --git a/hw/hank/lume-x1/anduril.h b/hw/hank/lume-x1/anduril.h new file mode 100644 index 0000000..509b442 --- /dev/null +++ b/hw/hank/lume-x1/anduril.h @@ -0,0 +1,33 @@ +// Hank Emisar/Noctigon Lume-X1 config options for Anduril +// Copyright (C) 2018-2024 Selene ToyKeeper, Loneoceans +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +// For flashlights using the Loneoceans Lume-X1-40W boost driver (AVR32DD20) +// - Same firmware for 6V, 9V, or 12V configs + +// same as loneoceans lume-x1-avr32dd20 but with Hank-specific defaults +#include "loneoceans/lume-x1-avr32dd20/anduril.h" +#include "hank/anduril.h" + +#undef DEFAULT_THERM_CEIL +#define DEFAULT_THERM_CEIL 50 + +// disable beacontower mode +#ifdef USE_BEACONTOWER_MODE +#undef USE_BEACONTOWER_MODE +#endif + +// set smooth ramping by default +#ifdef RAMP_STYLE +#undef RAMP_STYLE +#endif + +// reset to anduril default number of steps +#ifdef RAMP_DISCRETE_STEPS +#undef RAMP_DISCRETE_STEPS +#endif +#ifdef SIMPLE_UI_STEPS +#undef SIMPLE_UI_STEPS +#endif diff --git a/hw/hank/lume-x1/arch b/hw/hank/lume-x1/arch new file mode 100644 index 0000000..bcf4552 --- /dev/null +++ b/hw/hank/lume-x1/arch @@ -0,0 +1 @@ +avr32dd20 diff --git a/hw/hank/lume-x1/model b/hw/hank/lume-x1/model new file mode 100644 index 0000000..7c5bbe4 --- /dev/null +++ b/hw/hank/lume-x1/model @@ -0,0 +1 @@ +0281
\ No newline at end of file diff --git a/hw/loneoceans/lume-x1-avr32dd20/anduril.h b/hw/loneoceans/lume-x1-avr32dd20/anduril.h new file mode 100644 index 0000000..b396dbb --- /dev/null +++ b/hw/loneoceans/lume-x1-avr32dd20/anduril.h @@ -0,0 +1,198 @@ +// Copyright (C) 2017-2023 Selene ToyKeeper +// 2021-2024 Loneoceans +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +//************************************************** +//** CONFIGURATION OPTIONS FOR LUME-X1-AVR32DD20 ** +//************************************************** + +#define HWDEF_H loneoceans/lume-x1-avr32dd20/hwdef.h + +//*************************************** +//** RAMP TABLE AND OPERATIONS ** +//*************************************** + +#define RAMP_SIZE 150 // Change to 160 as well as table and values below if desired + +// PWM1: DAC Data +// UDR x^4 curves specifically for Lume-X1 (AVR32DD20) + +// 150 levels: +#define PWM1_LEVELS 1, 2, 10, 31, 77, 159, 295, 504, 807, 504, 737, 1023, 14, 19, 25, 32, 41, 52, 65, 79, 96, 116, 139, 164, 194, 226, 263, 305, 351, 401, 458, 520, 588, 662, 744, 832, 929, 423, 470, 520, 574, 632, 694, 761, 832, 909, 991, 25, 27, 30, 33, 36, 39, 42, 45, 48, 51, 55, 59, 63, 67, 71, 76, 81, 86, 91, 96, 102, 108, 114, 121, 128, 135, 142, 149, 157, 165, 174, 183, 192, 201, 211, 221, 232, 242, 254, 265, 277, 289, 302, 315, 329, 343, 357, 372, 387, 403, 419, 435, 452, 470, 488, 506, 525, 545, 565, 586, 607, 628, 651, 673, 697, 721, 745, 770, 796, 822, 849, 877, 905, 934, 963, 994, 420, 432, 446, 459, 473, 487, 501, 516, 531, 546, 562, 578, 594, 610, 627, 644, 662, 680, 698, 716, 735, 754, 774, 794, 814, 835, 856 +// 160 levels: +// #define PWM1_LEVELS 1, 2, 8, 24, 59, 123, 228, 389, 623, 950, 569, 807, 11, 15, 19, 25, 32, 40, 50, 61, 74, 90, 107, 127, 150, 175, 203, 235, 271, 310, 354, 401, 454, 512, 575, 643, 718, 798, 886, 980, 443, 488, 536, 588, 643, 702, 765, 832, 904, 980, 28, 30, 32, 35, 37, 40, 43, 46, 49, 52, 56, 59, 63, 67, 71, 76, 80, 85, 90, 95, 100, 106, 111, 117, 123, 130, 137, 144, 151, 158, 166, 174, 182, 191, 199, 208, 218, 227, 237, 248, 258, 269, 281, 292, 304, 316, 329, 342, 355, 369, 383, 398, 413, 428, 444, 460, 476, 493, 510, 528, 546, 565, 584, 603, 623, 644, 665, 686, 708, 730, 753, 777, 800, 825, 850, 875, 901, 927, 954, 982, 1010, 425, 437, 450, 462, 475, 487, 501, 514, 528, 541, 556, 570, 585, 599, 615, 630, 646, 662, 678, 694, 711, 728, 745, 763, 780, 799, 817, 836, 856 + +// PWM2_LEVELS - used to set the internal voltage reference for the DAC +// Makes use the of concept of dynamic Vref for higher resolution output +// despite DAC being only 10 bits. +// Bits 2:0 of register ADC0REF set the reference voltage: +// 0x0 - 1.024V - ..000 +// 0x1 - 2.048V - ..001 +// 0x2 - 4.096V - ..010 +// 0x3 - 2.500V- ..011 +// 0x5 - VDD - ..101 +// 0x6 - VREFA - ..111 +// Bit 7 controls if the reference is always on or not. +// Hence set PWM2_LEVELS to be 1xxx000 (0d64) for 1.024V DAC vref (V10) +// set PWM2_LEVELS to be 1xxx011 (0d67) for 2.500V DAC vref (V25) +// Other references are not so important since we have a 10-bit DAC + +// 150 levels: +#define PWM2_LEVELS V10, V10, V10, V10, V10, V10, V10, V10, V10, V25, V25, V25, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25 +// 160 levels: +// #define PWM2_LEVELS V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V25, V25, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V10, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25, V25 + +// Enable usage of multiple power paths +//#define USE_MULTIPLE_POWER_PATH (no longer required, defined in hwdef.c for >2023 Anduril) +#define LED_PATH1_PIN_LEVEL_MIN 1 +#define LED_PATH2_PIN_LEVEL_MIN 13 +#define LED_PATH3_PIN_LEVEL_MIN 48 // 51 for 160 levels + +#define HALFSPEED_LEVEL 50 +#define QUARTERSPEED_LEVEL 40 // check with TK about the mechanics of this + +#define DEFAULT_LEVEL 59 // about same as 1 AMC7135, (61 for 160 levels) +#define MAX_1x7135 59 // about same as 1 AMC7135 +// MIN_THERM_STEPDOWN defined as MAX_1x7135 in ramp-mode.h if not otherwise defined + +#define RAMP_SMOOTH_FLOOR 8 +#define RAMP_SMOOTH_CEIL 124 // about ~18-20W (Turbo ~40W), (132 for 160 levels) + +#define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 6 + +#define SIMPLE_UI_FLOOR 13 +#define SIMPLE_UI_CEIL 112 // about ~12W, (119 for 160 levels) +#define SIMPLE_UI_STEPS 5 + +// don't blink mid-ramp +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif + +//*************************************** +//** THERMAL SETTINGS ** +//*************************************** + +//#define USE_THERMAL_REGULATION + +// set thermal ceiling + +//#ifdef DEFAULT_THERM_CEIL +//#undef DEFAULT_THERM_CEIL +//#endif +#define DEFAULT_THERM_CEIL 50 + +// extra boost during turbo, lower when temp = temp_ceil + extra +//#define TURBO_TEMP_EXTRA 0 + +// stop panicking at 6W (not sure of this numbers yet since it depends on the host..) +#define THERM_FASTER_LEVEL 98 // about 6W +#define MIN_THERM_STEPDOWN 62 // similar to single amc7135 in a 3V light +//#define THERM_NEXT_WARNING_THRESHOLD 24 // 24 by default -> increase for fewer adjustments (more stable output on large time scale) +//#define THERM_RESPONSE_MAGNITUDE 64 // 64 by default -> decrease for smaller adjustments (removes dip post turbo) +//#define THERM_WINDOW_SIZE 1 // 2 by default -> decrease for tighter temperature regulation +//#define THERM_LOOKAHEAD 4 // 4 by default -> decrease for longer turbo + +// easier access to thermal config mode, similar to Emisar, Noctigon +//#define USE_TENCLICK_THERMAL_CONFIG + +//*************************************** +//** USER INTERFACE ** +//*************************************** + +//#define SIMPLE_UI_ACTIVE 0 // advanced UI by default + +// allow Aux Config and Strobe Modes in Simple UI +//#define USE_EXTENDED_SIMPLE_UI + +// Allow 3C in Simple UI for switching between smooth and stepped ramping +#define USE_SIMPLE_UI_RAMPING_TOGGLE + +// double click while on goes to full-power turbo, not ramp ceiling +#define DEFAULT_2C_STYLE 1 + +// set this light to use stepped ramp by default (instead of smooth) +#undef RAMP_STYLE +#define RAMP_STYLE 1 + +// uncomment to disable smooth steps +//#ifdef USE_SMOOTH_STEPS +//#undef USE_SMOOTH_STEPS +//#endif + +#define BLINK_BRIGHTNESS (MAX_LEVEL/5) // increase blink brightness from max/6 +#define BLINK_ONCE_TIME 32 // increase from 10 to make brighter + +//*************************************** +//** AUX LEDs and MISC ** +//*************************************** + +#define USE_BUTTON_LED + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS + +// show each channel while it scroll by in the menu +#define USE_CONFIG_COLORS + +// blink numbers on the main LEDs by default +#define DEFAULT_BLINK_CHANNEL CM_MAIN + +// this light only has one main led channel +// use aux red + aux blue for police strobe +#define USE_POLICE_COLOR_STROBE_MODE +#define POLICE_STROBE_USES_AUX +#define POLICE_COLOR_STROBE_CH1 CM_AUXRED +#define POLICE_COLOR_STROBE_CH2 CM_AUXBLU + +// the aux LEDs are front-facing, so turn them off while main LEDs are on +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + +// RGB aux LEDs should use rainbow cycling mode +// to impress new customers +// (people usually change it to voltage mode later though) +#ifdef RGB_LED_OFF_DEFAULT +#undef RGB_LED_OFF_DEFAULT +#endif +#define RGB_LED_OFF_DEFAULT 0x18 // low, rainbow +#define RGB_LED_LOCKOUT_DEFAULT 0x37 // blinking, rainbow + +// enable blinking aux LEDs +#define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s +//#define STANDBY_TICK_SPEED 4 // every 0.256 s +//#define STANDBY_TICK_SPEED 5 // every 0.512 s + +// enable SOS mode +#define USE_SOS_MODE +#define USE_SOS_MODE_IN_BLINKY_GROUP + +// enable Beacontower blinky mode +#define USE_BEACONTOWER_MODE + +// party strobe on-time +#define PARTY_STROBE_ONTIME 4 +#define STROBE_OFF_LEVEL 1 // keep regulators on between strobes + +// smoother candle mode with bigger oscillations +#define CANDLE_AMPLITUDE 30 // default 25 + +// avr32dd20 has enough space to smooth out voltage readings +#define USE_VOLTAGE_LOWPASS + +// can reset the normal way because power is not connected before the button, but do this anyway! +#define USE_SOFT_FACTORY_RESET + +// enable long-blink as negative sign +#define USE_LONG_BLINK_FOR_NEGATIVE_SIGN + +// Uncomment to use Microphone mode +//#define USE_MICROPHONE_MODE +//#define MICROPHONE_SCALER 10 + +// ======================================
\ No newline at end of file diff --git a/hw/loneoceans/lume-x1-avr32dd20/arch b/hw/loneoceans/lume-x1-avr32dd20/arch new file mode 100644 index 0000000..bcf4552 --- /dev/null +++ b/hw/loneoceans/lume-x1-avr32dd20/arch @@ -0,0 +1 @@ +avr32dd20 diff --git a/hw/loneoceans/lume-x1-avr32dd20/hwdef.c b/hw/loneoceans/lume-x1-avr32dd20/hwdef.c new file mode 100644 index 0000000..275037b --- /dev/null +++ b/hw/loneoceans/lume-x1-avr32dd20/hwdef.c @@ -0,0 +1,130 @@ +// 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 power_path_level = 0; // 0 = off, 1 = firefly, 2 = low, 3 = high +uint8_t is_boost_currently_on = 0; // for turn-on delay during first turn on + +void set_level_udr(uint8_t level); +void set_power_path(uint8_t ramp_level); +void set_level_zero(); +bool gradual_tick_main(uint8_t gt); + +Channel channels[] = { + { // main LEDs + .set_level = set_level_udr, + .gradual_tick = gradual_tick_main + }, + RGB_AUX_CHANNELS +}; + +// turn off +void set_level_zero() { + + power_path_level = 0; // set power path level to 0 + 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 + + // check if the ramp level corresponds to a new power path or not; + // if it doesn't, no need to change anything. + if (ramp_level>=LED_PATH3_PIN_LEVEL_MIN){ + if (power_path_level != 3){ + // high Mode + LED_PATH1_PORT |= LED_PATH1_PIN; + LED_PATH2_PORT |= LED_PATH2_PIN; + LED_PATH3_PORT |= LED_PATH3_PIN; + power_path_level = 3; + } + } + else if (ramp_level>=LED_PATH2_PIN_LEVEL_MIN){ + if (power_path_level != 2){ + // low Mode + //LED_PATH1_PORT &= ~LED_PATH1_PIN; + LED_PATH1_PORT |= LED_PATH1_PIN; + LED_PATH2_PORT |= LED_PATH2_PIN; + LED_PATH3_PORT &= ~LED_PATH3_PIN; + power_path_level = 2; + } + } + else if (ramp_level>=LED_PATH1_PIN_LEVEL_MIN){ + if (power_path_level != 1){ + // firefly mode + LED_PATH1_PORT |= LED_PATH1_PIN; + LED_PATH2_PORT &= ~LED_PATH2_PIN; + LED_PATH3_PORT &= ~LED_PATH3_PIN; + power_path_level = 1; + } + } +} + diff --git a/hw/loneoceans/lume-x1-avr32dd20/hwdef.h b/hw/loneoceans/lume-x1-avr32dd20/hwdef.h new file mode 100644 index 0000000..22340ec --- /dev/null +++ b/hw/loneoceans/lume-x1-avr32dd20/hwdef.h @@ -0,0 +1,232 @@ +// Copyright (C) 2017-2023 Selene ToyKeeper +// 2021-2024 loneoceans +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +//************************************************** +//** HARDWARE DEFINITIONS FOR LUME-X1-AVR32DD20 ** +//************************************************** + +/* Loneoceans Lume-X1 with AVR32DD20 + + 40W Boost Driver with Ultra Dynamic Range, RGB & SW Aux, Powerbank. + + The following pins are invariant (20 QFN package 3x3 0.4mm BSC) + - PD6 / PP11 - DAC OUT + - PF6 / PP15 - nRST + - PF7 / PP16 - UPDI + - xx / PP13 - VDD (read voltage from VDD, PFET RPP, no voltage drop) + - xx / PP8 - VDDIO2 + - xx / PP14 - GND + + Used Pins + - PA0 / PP17 - FET via PWM (TCA0-WO0) - N/C for Lume X1 + - PA5 / PP2 - PATH3 - High Range + - PA6 / PP3 - PATH2 - Low Range + - PA7 / PP4 - PATH1 - Moon Range + - PC1 / PP5 - Enable for Boost, Amplifier + - PC2 / PP6 - Enable for Microphone - N/C + - PC3 / PP7 - Neo Dat - N/C + - PD4 / PP9 - E-Switch + - PD5 / PP10 - Mic Output - N/C + - PD6 / PP11 - DAC Out + - PD7 / PP12 - Power Bank - N/C + - PA1 / PP18 - AUX R LED + - PA2 / PP19 - AUX G LED + - PA3 / PP20 - AUX B LED + - PA4 / PP1 - AUX SW LED + +*/ + +#define HWDEF_C loneoceans/lume-x1-avr32dd20/hwdef.c + +// allow using aux LEDs as extra channel modes +#include "fsm/chan-rgbaux.h" + +// channel modes: +// * 0. main LEDs +// * 1+. aux RGB +#define NUM_CHANNEL_MODES (1 + NUM_RGB_AUX_CHANNEL_MODES) +enum CHANNEL_MODES { + CM_MAIN = 0, + RGB_AUX_ENUMS +}; + +#define DEFAULT_CHANNEL_MODE CM_MAIN + +// right-most bit first, modes are in fedcba9876543210 order +#define CHANNEL_MODES_ENABLED 0b0000000000000001 + +//*************************************** +//** SET UP DAC AND PWM ** +//*************************************** + +// Define DAC control +#define PWM_BITS 16 // 10-bit DAC +#define PWM_DATATYPE uint16_t +#define PWM_DATATYPE2 uint32_t +#define PWM1_DATATYPE uint16_t // main regulated ramp 10-bit +#define PWM1_GET(x) PWM_GET16(pwm1_levels, x) +#define PWM2_DATATYPE uint8_t // DAC Vref table (4/6 options) +#define PWM2_GET(x) PWM_GET8(pwm2_levels, x) + +//*************************************** +//** PIN DEFINITIONS ** +//*************************************** + +// Boost and Amplifier Enable (PC1) +#define BST_ENABLE_PIN PIN1_bp +#define BST_ENABLE_PORT PORTC_OUT +#define BST_ON_DELAY 8 // ms delay turning on the led after enable + +// Ultra Dynamic Range (UDR) +/* + UDR makes use of the concept of multiple power paths. 3 are used in this + design to achieve extremely low moonlight levels. This is combined with + dynamic Vref for smoother brightness level transitions that would + normally be limited by the 10-bit DAC resolution. + + Lume drivers uses the internal DAC to generate a reference voltage for + a current-regulated amplifier which drives the LED. Each power path + routes current through different sense resistors, allowing for improved + current sense resolution especially at the low end. Using UDR, Lume1/X1 + is capable of ultra-low firefly / moonlight levels with a dynamic range + on the order of >10-50 million : 1. +*/ + +// For UDR Path 1 (firefly mode) - PA7 +#define LED_PATH1_PIN PIN7_bm +#define LED_PATH1_PORT PORTA_OUT + +// For UDR Path 2 (low mode) - PA6 +#define LED_PATH2_PIN PIN6_bm +#define LED_PATH2_PORT PORTA_OUT + +// For UDR Path 3 (high mode) - PA5 +#define LED_PATH3_PIN PIN5_bm +#define LED_PATH3_PORT PORTA_OUT + +// Define Aux LED Pins + +// lighted switch button aux led (PA4) +#ifndef BUTTON_LED_PIN +#define BUTTON_LED_PIN PIN4_bp +#define BUTTON_LED_PORT PORTA +#endif + +// this driver allows for aux LEDs under the optic +#define AUXLED_R_PIN PIN1_bp +#define AUXLED_G_PIN PIN2_bp +#define AUXLED_B_PIN PIN3_bp + +#define AUXLED_RGB_PORT PORTA + +/* +#define AUXLED_R_PORT PORTA +#define AUXLED_G_PORT PORTA +#define AUXLED_B_PORT PORTA + +// if aux leds are on different ports +#define AUXLED_RGB_DIFFERENT_PORTS +*/ + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS + +// Define e-switch Pin and ISR +#ifndef SWITCH_PIN // PD4 +#define SWITCH_PIN PIN4_bp +#define SWITCH_PORT VPORTD.IN +#define SWITCH_ISC_REG PORTD.PIN4CTRL +#define SWITCH_VECT PORTD_PORT_vect +#define SWITCH_INTFLG VPORTD.INTFLAGS +#endif + +// average drop across diode on this hardware +#ifndef VOLTAGE_FUDGE_FACTOR +#define VOLTAGE_FUDGE_FACTOR 1 // PFET for RRP, essentially 0 v-drop, but experimentally add 0.05V for better UX +#endif + +//*************************************** +//** HARDWARE INIT ** +//*************************************** + +inline void hwdef_setup() { + + // TODO: for this DAC controlled-light, try to decrease the clock speed + // to reduce overall system power + mcu_clock_speed(); + + // set output pins + VPORTA.DIR = PIN1_bm | PIN2_bm | PIN3_bm | + PIN4_bm | PIN5_bm | PIN6_bm | PIN7_bm; + VPORTC.DIR = PIN1_bm; + VPORTD.DIR = PIN6_bm; + + // now set pullups on input pins, and unused pins (reduce power) + PORTA.PIN0CTRL = PORT_PULLUPEN_bm; // FET + //PORTA.PIN1CTRL = PORT_PULLUPEN_bm; // AUX R + //PORTA.PIN2CTRL = PORT_PULLUPEN_bm; // AUX G + //PORTA.PIN3CTRL = PORT_PULLUPEN_bm; // AUX B + //PORTA.PIN4CTRL = PORT_PULLUPEN_bm; // AUX SW + //PORTA.PIN5CTRL = PORT_PULLUPEN_bm; // PATH3 + //PORTA.PIN6CTRL = PORT_PULLUPEN_bm; // PATH2 + //PORTA.PIN7CTRL = PORT_PULLUPEN_bm; // PATH1 + + //PORTC.PIN1CTRL = PORT_PULLUPEN_bm; // ENABLE + PORTC.PIN2CTRL = PORT_PULLUPEN_bm; // MIC ENABLE + PORTC.PIN3CTRL = PORT_PULLUPEN_bm; // NEO + + //PORTD.PIN4CTRL = PORT_PULLUPEN_bm; // ESW (100kR PULLUP) + PORTD.PIN5CTRL = PORT_PULLUPEN_bm; // MIC OUT + //PORTD.PIN6CTRL = PORT_PULLUPEN_bm; // DAC OUT + PORTD.PIN7CTRL = PORT_PULLUPEN_bm; // PWR BNK ENABLE + + // clear some pins we don't need for now or want to initialize as low + PORTC_OUT &= ~(1 << PIN1_bp); // ENABLE + PORTC_OUT &= ~(1 << PIN2_bp); // MIC ENABLE + PORTD_OUT &= ~(1 << PIN7_bp); // PWR BNK ENABLE + + //E-Switch (now uses external pullup) + PORTD.DIRCLR = PIN4_bm; // set ESW as input pin + PORTD.PIN4CTRL = PORT_ISC_BOTHEDGES_gc; + + // set up the DAC (used for the switching regulator) + // https://www.microchip.com/en-us/product/avr32dd20 + // DAC ranges from 0V to (255 * Vref) / 256 + + // Datasheet 34.3.1-2/2: input for DAC must be disabled + PORTD.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; + //VREF.CTRLA |= VREF_DAC0REFSEL_2V5_gc; // also VREF_DAC0REFSEL_0V55_gc and VREF_DAC0REFSEL_1V1_gc and VREF_DAC0REFSEL_2V5_gc + //VREF.CTRLB |= VREF_DAC0REFEN_bm; // enable vref + DAC_VREF = V10; + DAC0.CTRLA = DAC_ENABLE_bm | DAC_OUTEN_bm; // enable DAC + DAC_LVL = 0; // lowest output during boot + // TODO: instead of enabling the DAC at boot, pull pin down + // to generate a zero without spending power on the DAC + // (and do this in set_level_zero() too) + +} + +// set fuses, these carry over to the ELF file +// we need this for enabling BOD in Active Mode from the factory. +// settings can be verified / dumped from the ELF file using this +// command: avr-objdump -d -S -j .fuse anduril.elf +FUSES = { + .WDTCFG = FUSE_WDTCFG_DEFAULT, // Watchdog Configuration + + // enable BOD (continuous) in active mode + .BODCFG = ACTIVE_ENABLE_gc, // BOD Configuration + + .OSCCFG = FUSE_OSCCFG_DEFAULT, // Oscillator Configuration + .SYSCFG0 = FUSE_SYSCFG0_DEFAULT, // System Configuration 0 + + // enable MVIO because VDDIO2 pin isn't connected + // set startup time to 64ms to allow power to stabilize + .SYSCFG1 = MVSYSCFG_DUAL_gc | SUT_64MS_gc, + + .CODESIZE = FUSE_CODESIZE_DEFAULT, + .BOOTSIZE = FUSE_BOOTSIZE_DEFAULT, +}; + +#define LAYOUT_DEFINED
\ No newline at end of file diff --git a/hw/loneoceans/lume-x1-avr32dd20/model b/hw/loneoceans/lume-x1-avr32dd20/model new file mode 100644 index 0000000..50244f6 --- /dev/null +++ b/hw/loneoceans/lume-x1-avr32dd20/model @@ -0,0 +1 @@ +4212
\ No newline at end of file |
