Compare commits
2 Commits
08f348d8fe
...
ef86085343
Author | SHA256 | Date | |
---|---|---|---|
ef86085343 | |||
3c15aa5eac |
@ -12,8 +12,8 @@ set(CMAKE_SYSTEM_NAME Generic)
|
|||||||
set(CMAKE_C_COMPILER avr-gcc)
|
set(CMAKE_C_COMPILER avr-gcc)
|
||||||
set(OBJCOPY avr-objcopy)
|
set(OBJCOPY avr-objcopy)
|
||||||
|
|
||||||
# Compiler flags
|
# Compiler flags: optimize, warnings, treat warnings as errors
|
||||||
set(CMAKE_C_FLAGS "-mmcu=${MCU} -DF_CPU=${F_CPU} -Os -Wall")
|
set(CMAKE_C_FLAGS "-mmcu=${MCU} -DF_CPU=${F_CPU} -Os -Wall -Werror")
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
add_executable(main.elf main.c)
|
add_executable(main.elf main.c)
|
||||||
|
11
main.c
11
main.c
@ -12,10 +12,11 @@
|
|||||||
/** @defgroup LED_Masks LED bitmasks for PORTA
|
/** @defgroup LED_Masks LED bitmasks for PORTA
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#define BUTTON_PIN_MASK 0x01 // PA0
|
||||||
#define PA1_SET_MASK 0x02 ///< LED 1–2
|
#define PA1_SET_MASK 0x02 ///< LED 1–2
|
||||||
#define PA2_SET_MASK 0x04 ///< LED 3–6
|
#define PA2_SET_MASK 0x04 ///< LED 3–6
|
||||||
#define PA3_SET_MASK 0x08 ///< LED 7–8
|
#define PA3_SET_MASK 0x08 ///< LED 7–8
|
||||||
#define PA6_SET_MASK 0x40 ///< Switch input (was green LED pin) TODO: Switch to PA0
|
#define PA6_SET_MASK 0x40 ///< Green LED pin
|
||||||
#define PA7_SET_MASK 0x80 ///< Red LED
|
#define PA7_SET_MASK 0x80 ///< Red LED
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
@ -50,9 +51,9 @@ int main(void)
|
|||||||
/*PA6_SET_MASK |*/ // PA6 now input (switch)
|
/*PA6_SET_MASK |*/ // PA6 now input (switch)
|
||||||
PA7_SET_MASK);
|
PA7_SET_MASK);
|
||||||
|
|
||||||
// Configure PA6 as input with pull-up TODO: Switch to PA0
|
// Configure PA0 as input with pull-up
|
||||||
VPORTA.DIR &= ~PA6_SET_MASK; // Input
|
VPORTA.DIR &= ~BUTTON_PIN_MASK; // Input
|
||||||
PORTA.PIN6CTRL = PORT_PULLUPEN_bm; // Pull-up enabled
|
PORTA.PIN0CTRL = PORT_PULLUPEN_bm; // Pull-up enabled
|
||||||
|
|
||||||
// --- ensure all LEDs off at startup ---
|
// --- ensure all LEDs off at startup ---
|
||||||
leds_off();
|
leds_off();
|
||||||
@ -128,7 +129,7 @@ static void handleSwitch(void)
|
|||||||
static uint16_t pressTicks = 0; ///< press duration counter
|
static uint16_t pressTicks = 0; ///< press duration counter
|
||||||
static bool prevPressed = false; ///< previous switch state
|
static bool prevPressed = false; ///< previous switch state
|
||||||
|
|
||||||
bool pressed = !(VPORTA.IN & PA6_SET_MASK); // active-low
|
bool pressed = !(VPORTA.IN & BUTTON_PIN_MASK); // active-low
|
||||||
|
|
||||||
if (pressed)
|
if (pressed)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user