/** * @brief The Main program header. * @details this file contains the prototypes and structs. * @author Jake Goodwin * @date 2025 * @copyright None * @file main.h */ #ifndef MAIN_H #define MAIN_H #ifndef __AVR_ATtiny13A__ #define __AVR_ATtiny13A__ #endif #include //############################# //Defines //############################# #ifndef UINT8_MAX #define UINT8_MAX 256 #endif //This is the bitpattern that should be at address 0x00 #define START_PATTERN 0xAA #define END_PATTERN 0x55 //Addresses in the eeprom for the two switch states #define ROM_SP_ADR 0x0 #define POSITION1_ADR 0x1 #define POSITION2_ADR 0x2 #define ROM_EP_ADR 0x3 //Debounce check number. #define MAX_CHECKS 10 #define LED_PORT (1<<5) #define LED_PIN PB5 #define BLINK_DELAY_MS 5000 #define PWM_PIN1 PB0 // Pin 5 - Motor PWM 1 #define PWM_PIN2 PB1 // Pin 6 - Motor PWM 2 #define ADC_PIN PB3 // Pin 2 - Fader position reading #define SPEED_PIN PB2 // Pin 7/ADC1 #define BUTTON_PIN PB4 // Pin 3 - Button input #define MOTOR_PULSE 1 //uS motor base pulse /*The timing of "ticks" is dependent on the AVR timer's counter register * so for an 8bit register the maximum value is 256. Given we stick with * a 1Mhz cpu frequency can use this formula to calculate the number of * interrupts(timer overflows) per second: * * OVF_S = (F_CPU / DIV)/ (2^8) * 61 = (1000000 / 64) / 256 * * This is important because the ATiny13/A only have a single timer built into * them. * * Ticks are used as our way of keep track of long button presses. * */ //original sent had 60 #define LONG_PRESS_TICKS 66 // Define DISABLE_TEMPORARY_SWITCH to turn off the ability to hold // the switch to temporarily engage/bypass. //#define DISABLE_TEMPORARY_SWITCH #define PIN_SW1 PINB2 #define PIN_ACTIVE1 PB1 #define PIN_MUTE PB0 //############################# //Typedefs & sttructs //############################# /*A structure to hold the button info*/ typedef struct { uint8_t is_pressed: 1; uint8_t is_long_pressed: 1; uint8_t is_active: 1; uint8_t timer_enabled: 1; uint8_t pressed_ticks; uint8_t input_pin; }btn_state; //############################# //Public Prototypes //############################# /** * @brief Initializes the uC for the program. */ void InitProg(void); /** * @brief Reads the ADC pin from the fader. */ uint16_t ReadFader(void); /** * @brief Reads the ADC value from the Speed pot. */ uint8_t ReadSpeed(void); /** * @brief Moves the motor to target location based off the PB3. * @param[in] 8bit value representing fader location. */ void MotorMoveTo(uint8_t target); /** * @brief Turns off motor allowing free movement. */ void MotorCoast(void); /** * @brief Activates the motor driver in forward or reverse. * @param[in] moves foward when true and in reverse when false. */ void MotorMove(uint8_t fwd); #endif