From 46454fc1b4194d34a40b87be4c0bb526c06fd15a Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 23 Apr 2025 09:29:57 +0800 Subject: Add lock and unlock IRQ handlers to frontend. --- lock/fend.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lock') diff --git a/lock/fend.c b/lock/fend.c index 340daeb..2215ec5 100644 --- a/lock/fend.c +++ b/lock/fend.c @@ -12,6 +12,7 @@ #include "util.h" #define LOCK_PIN PD2 +#define UNLOCK_PIN PD3 #define RX_PIN PD7 #define RX_DDR DDRD @@ -36,11 +37,11 @@ static inline void init_rx(void) static inline void init_btns(void) { - DDRD &= ~(1 << LOCK_PIN); - PORTD |= (1 << LOCK_PIN); + DDRD &= ~((1 << LOCK_PIN) | (1 << UNLOCK_PIN)); + PORTD |= ((1 << LOCK_PIN) | (1 << UNLOCK_PIN)); EICRA = 0b00000000; - EIMSK = (1 << INT0); + EIMSK = (1 << INT0) | (1 << INT1); } int main(void) @@ -62,6 +63,7 @@ int main(void) for (;;) { if ((islock || isunlock) && !sync) { + sync = 1; xor(KEY, SYN, buf, WDLEN); do { sync = radio_sendto(txaddr, buf, WDLEN); @@ -100,5 +102,14 @@ ISR(RX_PCINTVEC) ISR(INT0_vect) { - islock = 1; + if (is_btn_pressed(PIND, LOCK_PIN)) + islock = 1; + uart_write_line(" start lock"); +} + +ISR(INT1_vect) +{ + if (is_btn_pressed(PIND, UNLOCK_PIN)) + isunlock = 1; + uart_write_line("start unlock"); } -- cgit v1.2.3