2025-02-10 22:35:14 +00:00
|
|
|
/**
|
|
|
|
* @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>
|
|
|
|
|
|
|
|
//#############################
|
|
|
|
//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
|
2025-02-10 22:35:14 +00:00
|
|
|
#define ROM_SP_ADR 0x0
|
2025-02-10 22:38:14 +00:00
|
|
|
#define ROM_SS1_ADR 0x1
|
|
|
|
#define ROM_SS2_ADR 0x2
|
2025-02-10 22:35:14 +00:00
|
|
|
#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;
|
|
|
|
uint8_t is_bypassed: 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
|
|
|
|
*/
|
|
|
|
void led_blink(void);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes the uC for the program.
|
|
|
|
*/
|
|
|
|
void init_prog(void);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reads the ADC pin
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
uint16_t readADC(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
void motorCoast(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
void motorMove(int direction);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
uint8_t readButton(void);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|