motorized_fader/inc/main.h

140 lines
2.6 KiB
C
Raw Normal View History

/**
* @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
#include <avr/io.h>
2025-02-12 19:31:37 +00:00
//#############################
//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
2025-02-10 22:38:14 +00:00
//Addresses in the eeprom for the two switch states
#define ROM_SP_ADR 0x0
2025-02-10 22:38:14 +00:00
#define ROM_SS1_ADR 0x1
#define ROM_SS2_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 BUTTON_PIN PB4 // Pin 3 - Button input
/*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;
2025-02-12 19:31:37 +00:00
uint8_t is_active: 1;
uint8_t timer_enabled: 1;
uint8_t pressed_ticks;
uint8_t input_pin;
uint8_t output_pin;
}btn_state;
//#############################
//Public Prototypes
//#############################
/**
* @brief Blinks a defined led pin.
* @param None
*/
2025-02-10 23:06:15 +00:00
void LedBlink(void);
/**
* @brief Initializes the uC for the program.
*/
2025-02-10 23:06:15 +00:00
void InitProg(void);
/**
* @brief Reads the ADC pin
* @param
*/
2025-02-10 23:06:15 +00:00
uint16_t ReadADC(void);
2025-02-12 19:43:06 +00:00
/**
* @brief
2025-02-12 19:43:06 +00:00
* @param
*/
void MotorMoveTo(uint8_t target);
2025-02-12 19:43:06 +00:00
/**
* @brief
* @param
*/
2025-02-10 23:06:15 +00:00
void MotorCoast(void);
/**
* @brief
* @param
*/
2025-02-12 19:48:14 +00:00
void MotorMove(uint8_t fwd);
/**
* @brief
* @param
*/
2025-02-10 23:06:15 +00:00
uint8_t ReadButton(void);
#endif