// arch/attiny85.c: attiny85 support functions // Copyright (C) 2014-2023 Selene ToyKeeper // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include "arch/attiny85.h" ////////// clock speed / delay stuff ////////// ///// clock dividers ////////// default hw_setup() ////////// // FIXME: fsm/main should call hwdef_setup(), not hw_setup, // and this function should be hwdef_setup #ifdef USE_GENERIC_HWDEF_SETUP static inline void hwdef_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<> 6) + (ADCH << 2); } ////////// WDT ////////// inline void mcu_wdt_active() { // interrupt every 16ms //cli(); // Disable interrupts wdt_reset(); // Reset the WDT WDTCR |= (1<