diff options
| author | Selene ToyKeeper | 2019-08-11 15:16:23 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-08-11 15:16:23 -0600 |
| commit | 89a86871aa6330218043586f0347c0c1e7c79dab (patch) | |
| tree | e3a4cc2a4517e5563e91cdaaf86718170d4f0a37 /spaghetti-monster/fsm-misc.c | |
| parent | Added setup info for Fedora. (diff) | |
| parent | added scripts to flash attiny1634, which were missing before (diff) | |
| download | anduril-89a86871aa6330218043586f0347c0c1e7c79dab.tar.gz anduril-89a86871aa6330218043586f0347c0c1e7c79dab.tar.bz2 anduril-89a86871aa6330218043586f0347c0c1e7c79dab.zip | |
merged fsm to trunk... lots of updates:
+ attiny1634 support
+ Emisar D4v2 support
+ Mateminco MF01S / MT18 support
+ Fireflies E01 and E07v2 support
+ RGB aux LED support
+ added factory reset function
+ added manual / automatic memory toggle
+ added 2-level brightness during lockout
+ added Fireflies UI
+ made momentary mode also support strobe-group modes
* thermal regulation rewritten, behaves mostly better now
* strobe modes auto-reverse their ramp now
* muggle mode fixes
* UI diagram and manual updated
* button timing adjusted, and compile-time options added for it
* general refactoring
Diffstat (limited to 'spaghetti-monster/fsm-misc.c')
| -rw-r--r-- | spaghetti-monster/fsm-misc.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index 9f953fa..8e88cbd 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -20,6 +20,7 @@ #ifndef FSM_MISC_C #define FSM_MISC_C + #ifdef USE_DYNAMIC_UNDERCLOCKING void auto_clock_speed() { uint8_t level = actual_level; // volatile, avoid repeat access @@ -27,14 +28,14 @@ void auto_clock_speed() { // run at quarter speed // note: this only works when executed as two consecutive instructions // (don't try to combine them or put other stuff between) - CLKPR = 1<<CLKPCE; CLKPR = 2; + clock_prescale_set(clock_div_4); } else if (level < HALFSPEED_LEVEL) { // run at half speed - CLKPR = 1<<CLKPCE; CLKPR = 1; + clock_prescale_set(clock_div_2); } else { // run at full speed - CLKPR = 1<<CLKPCE; CLKPR = 0; + clock_prescale_set(clock_div_1); } } #endif @@ -146,6 +147,34 @@ void indicator_led_auto() { */ #endif // USE_INDICATOR_LED +#ifdef USE_AUX_RGB_LEDS +void rgb_led_set(uint8_t value) { + // value: 0b00BBGGRR + uint8_t pins[] = { AUXLED_R_PIN, AUXLED_G_PIN, AUXLED_B_PIN }; + for (uint8_t i=0; i<3; i++) { + uint8_t lvl = (value >> (i<<1)) & 0x03; + uint8_t pin = pins[i]; + switch (lvl) { + case 0: // LED off + AUXLED_RGB_DDR &= 0xff ^ (1 << pin); + AUXLED_RGB_PUE &= 0xff ^ (1 << pin); + AUXLED_RGB_PORT &= 0xff ^ (1 << pin); + break; + case 1: // LED low + AUXLED_RGB_DDR &= 0xff ^ (1 << pin); + AUXLED_RGB_PUE |= (1 << pin); + AUXLED_RGB_PORT |= (1 << pin); + break; + default: // LED high + AUXLED_RGB_DDR |= (1 << pin); + AUXLED_RGB_PUE |= (1 << pin); + AUXLED_RGB_PORT |= (1 << pin); + break; + } + } +} +#endif // ifdef USE_AUX_RGB_LEDS + #ifdef USE_TRIANGLE_WAVE uint8_t triangle_wave(uint8_t phase) { uint8_t result = phase << 1; @@ -154,4 +183,21 @@ uint8_t triangle_wave(uint8_t phase) { } #endif +#ifdef USE_REBOOT +void reboot() { + #if 1 // WDT method, safer but larger + cli(); + WDTCR = 0xD8 | WDTO_15MS; + sei(); + wdt_reset(); + while (1) {} + #else // raw assembly method, doesn't reset registers or anything + __asm__ __volatile__ ( + "cli" "\n\t" + "rjmp 0x00" "\n\t" + ); + #endif +} +#endif + #endif |
