diff options
| author | Selene ToyKeeper | 2023-11-02 11:05:02 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-11-02 11:05:02 -0600 |
| commit | ffd9f90898699df87bf9cb283aaa724774bd91bd (patch) | |
| tree | e8b6a33a5814d0b1adc6c630043650dfc19ee959 /spaghetti-monster/fsm-main.c | |
| parent | added a "tactical mode" on "Off -> 6C" (diff) | |
| parent | slightly longer smooth-off animation, to make on and off feel symmetrical (diff) | |
| download | anduril-ffd9f90898699df87bf9cb283aaa724774bd91bd.tar.gz anduril-ffd9f90898699df87bf9cb283aaa724774bd91bd.tar.bz2 anduril-ffd9f90898699df87bf9cb283aaa724774bd91bd.zip | |
merged multi-channel branch with a major refactor and half a year of updates
Diffstat (limited to 'spaghetti-monster/fsm-main.c')
| -rw-r--r-- | spaghetti-monster/fsm-main.c | 116 |
1 files changed, 52 insertions, 64 deletions
diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index 30b8a67..066188c 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -1,24 +1,8 @@ -/* - * fsm-main.c: main() function for SpaghettiMonster. - * - * Copyright (C) 2017 Selene ToyKeeper - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef FSM_MAIN_C -#define FSM_MAIN_C +// fsm-main.c: main() function for SpaghettiMonster. +// Copyright (C) 2017-2023 Selene ToyKeeper +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once #include "fsm-main.h" @@ -39,50 +23,55 @@ ISR(TIMER1_COMPA_vect) { } #endif +// FIXME: hw_setup() shouldn't be here ... move it entirely to hwdef files #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) static inline void hw_setup() { - // configure PWM channels - #if PWM_CHANNELS >= 1 - DDRB |= (1 << PWM1_PIN); - TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...) - TCCR0A = PHASE; - #if (PWM1_PIN == PB4) // Second PWM counter is ... weird - TCCR1 = _BV (CS10); - GTCCR = _BV (COM1B1) | _BV (PWM1B); - OCR1C = 255; // Set ceiling value to maximum - #endif - #endif - // tint ramping needs second channel enabled, - // despite PWM_CHANNELS being only 1 - #if (PWM_CHANNELS >= 2) || defined(USE_TINT_RAMPING) - DDRB |= (1 << PWM2_PIN); - #if (PWM2_PIN == PB4) // Second PWM counter is ... weird - TCCR1 = _BV (CS10); - GTCCR = _BV (COM1B1) | _BV (PWM1B); - OCR1C = 255; // Set ceiling value to maximum - #endif - #endif - #if PWM_CHANNELS >= 3 - DDRB |= (1 << PWM3_PIN); - #if (PWM3_PIN == PB4) // Second PWM counter is ... weird - TCCR1 = _BV (CS10); - GTCCR = _BV (COM1B1) | _BV (PWM1B); - OCR1C = 255; // Set ceiling value to maximum - #endif - #endif - #if PWM_CHANNELS >= 4 - // 4th PWM channel is ... not actually supported in hardware :( - DDRB |= (1 << PWM4_PIN); - //OCR1C = 255; // Set ceiling value to maximum - TCCR1 = 1<<CTC1 | 1<<PWM1A | 3<<COM1A0 | 2<<CS10; - GTCCR = (2<<COM1B0) | (1<<PWM1B); - // set up an interrupt to control PWM4 pin - TIMSK |= (1<<OCIE1A) | (1<<TOIE1); - #endif - - // configure e-switch - PORTB = (1 << SWITCH_PIN); // e-switch is the only input - PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin + #if !defined(USE_GENERIC_HWDEF_SETUP) + hwdef_setup(); + #else + // configure PWM channels + #if PWM_CHANNELS >= 1 + DDRB |= (1 << PWM1_PIN); + TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...) + TCCR0A = PHASE; + #if (PWM1_PIN == PB4) // Second PWM counter is ... weird + TCCR1 = _BV (CS10); + GTCCR = _BV (COM1B1) | _BV (PWM1B); + OCR1C = 255; // Set ceiling value to maximum + #endif + #endif + // tint ramping needs second channel enabled, + // despite PWM_CHANNELS being only 1 + #if (PWM_CHANNELS >= 2) || defined(USE_TINT_RAMPING) + DDRB |= (1 << PWM2_PIN); + #if (PWM2_PIN == PB4) // Second PWM counter is ... weird + TCCR1 = _BV (CS10); + GTCCR = _BV (COM1B1) | _BV (PWM1B); + OCR1C = 255; // Set ceiling value to maximum + #endif + #endif + #if PWM_CHANNELS >= 3 + DDRB |= (1 << PWM3_PIN); + #if (PWM3_PIN == PB4) // Second PWM counter is ... weird + TCCR1 = _BV (CS10); + GTCCR = _BV (COM1B1) | _BV (PWM1B); + OCR1C = 255; // Set ceiling value to maximum + #endif + #endif + #if PWM_CHANNELS >= 4 + // 4th PWM channel is ... not actually supported in hardware :( + DDRB |= (1 << PWM4_PIN); + //OCR1C = 255; // Set ceiling value to maximum + TCCR1 = 1<<CTC1 | 1<<PWM1A | 3<<COM1A0 | 2<<CS10; + GTCCR = (2<<COM1B0) | (1<<PWM1B); + // set up an interrupt to control PWM4 pin + TIMSK |= (1<<OCIE1A) | (1<<TOIE1); + #endif + + // configure e-switch + PORTB = (1 << SWITCH_PIN); // e-switch is the only input + PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin + #endif // ifdef USE_GENERIC_HWDEF_SETUP } #elif (ATTINY == 1634) || defined(AVRXMEGA3) // ATTINY816, 817, etc static inline void hw_setup() { @@ -220,4 +209,3 @@ void handle_deferred_interrupts() { } } -#endif |
