From a4dac16aa89b148aec93eab5a4f13971b46c3fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 4 Feb 2022 11:21:34 +0000 Subject: [PATCH 1/5] [fw] add helper functions --- Firmware/Pump/app.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index a5aa494..c0fb843 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -73,6 +73,7 @@ void core_callback_catastrophic_error_detected(void) uint16_t inactivity_counter = 0; +/* Buttons */ uint8_t but_push_counter_ms = 0; uint16_t but_long_push_counter_ms = 0; bool but_push_long_press = false; @@ -84,8 +85,12 @@ bool but_pull_long_press = false; uint8_t but_reset_counter_ms = 0; bool but_reset_pressed = false; bool but_reset_dir_change = false; + +/* Switches */ bool switch_f_active = false; bool switch_r_active = false; +uint8_t sw_f_counter_ms = 0; +uint8_t sw_r_counter_ms = 0; uint8_t curr_dir = DIR_FORWARD; uint8_t prev_dir = DIR_FORWARD; @@ -172,6 +177,18 @@ void clear_but_pull() but_pull_long_press = false; } +/* Switches */ +extern void clear_sw_f() +{ + switch_f_active = false; + sw_f_counter_ms = 50; +} + +extern void clear_sw_r() +{ + switch_r_active = false; + sw_r_counter_ms = 50; +} /************************************************************************/ /* Initialization Callbacks */ From 746cba7f09bb70188ea93776cd5f3a83429df714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 4 Feb 2022 11:21:34 +0000 Subject: [PATCH 2/5] [fw] add switches debounce --- Firmware/Pump/app.c | 47 ++++++++++++++++++++++++++++++++++++++ Firmware/Pump/interrupts.c | 43 ++++++++-------------------------- 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index c0fb843..b25b328 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -420,6 +420,53 @@ void core_callback_t_1ms(void) inactivity_counter = 0; } + /* handle switches */ + /* De-bounce Switch FORWARD */ + if(sw_f_counter_ms) + { + if(read_SW_F) + { + if(!--sw_f_counter_ms) + { + switch_pressed(DIR_FORWARD); + + if(app_regs.REG_EVT_ENABLE & B_EVT_SW_FORWARD_STATE) + core_func_send_event(ADD_REG_SW_FORWARD_STATE, true); + + if((app_regs.REG_DO0_CONFIG & MSK_OUT0_CONF) == GM_OUT0_SWLIMIT) + { + if(read_SW_F) + set_OUT00; + else + clr_OUT00; + } + } + } + } + + /* De-bounce Switch REVERSE */ + if(sw_r_counter_ms) + { + if(read_SW_R) + { + if(!--sw_r_counter_ms) + { + switch_pressed(DIR_REVERSE); + + if(app_regs.REG_EVT_ENABLE & B_EVT_SW_REVERSE_STATE) + core_func_send_event(ADD_REG_SW_REVERSE_STATE, true); + + if((app_regs.REG_DO0_CONFIG & MSK_OUT0_CONF) == GM_OUT0_SWLIMIT) + { + if(read_SW_R) + set_OUT00; + else + clr_OUT00; + } + } + } + } + /* handle buttons */ /* De-bounce PUSH button */ if(but_push_counter_ms) diff --git a/Firmware/Pump/interrupts.c b/Firmware/Pump/interrupts.c index 5a5a4b7..93307f7 100644 --- a/Firmware/Pump/interrupts.c +++ b/Firmware/Pump/interrupts.c @@ -79,58 +79,33 @@ ISR(PORTB_INT0_vect, ISR_NAKED) /************************************************************************/ /* SW_F, SW_R, TYPE0 & TYPE1 */ /************************************************************************/ +extern void clear_sw_f(); +extern void clear_sw_r(); + ISR(PORTC_INT0_vect, ISR_NAKED) { - if(read_SW_F) - { - // TODO: change this to use DIR_FORWARD - switch_pressed(1); - - if(app_regs.REG_EVT_ENABLE & B_EVT_SW_FORWARD_STATE) - core_func_send_event(ADD_REG_SW_FORWARD_STATE, true); - } - else + if(!(read_SW_F)) { - // should send event when down (only if previously was up) if(switch_f_active) { app_regs.REG_SW_FORWARD_STATE = 0; if(app_regs.REG_EVT_ENABLE & B_EVT_SW_FORWARD_STATE) core_func_send_event(ADD_REG_SW_FORWARD_STATE, true); } - - switch_f_active = false; + clear_sw_f(); } - - if(read_SW_R) + + if(!(read_SW_R)) { - // TODO: change this to use DIR_REVERSE - switch_pressed(0); - - if(app_regs.REG_EVT_ENABLE & B_EVT_SW_REVERSE_STATE) - core_func_send_event(ADD_REG_SW_REVERSE_STATE, true); - } - else - { - // should send event when down (only if previously was up) if(switch_r_active) { app_regs.REG_SW_REVERSE_STATE = 0; if(app_regs.REG_EVT_ENABLE & B_EVT_SW_REVERSE_STATE) core_func_send_event(ADD_REG_SW_REVERSE_STATE, true); } - - switch_r_active = false; + clear_sw_r(); } - - if((app_regs.REG_DO0_CONFIG & MSK_OUT0_CONF) == GM_OUT0_SWLIMIT) - { - if(read_SW_F || read_SW_R) - set_OUT00; - else - clr_OUT00; - } - + reti(); } From 3b5ec3cf1bc5de743dd88853b4c81063b9542cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 4 Feb 2022 11:21:34 +0000 Subject: [PATCH 3/5] [fw] fix event triggering on protocol change --- Firmware/Pump/app_funcs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Firmware/Pump/app_funcs.c b/Firmware/Pump/app_funcs.c index 5c5b600..fab1717 100644 --- a/Firmware/Pump/app_funcs.c +++ b/Firmware/Pump/app_funcs.c @@ -124,14 +124,18 @@ bool app_write_REG_START_PROTOCOL(void *a) if( running_protocol ) { prev_dir = curr_dir; - //FIXME: seems that the first event is not triggered app_write_REG_DIR_STATE(&app_regs.REG_PROTOCOL_DIRECTION); } app_regs.REG_START_PROTOCOL = reg; - app_regs.REG_PROTOCOL_STATE = reg; - app_write_REG_PROTOCOL_STATE(&app_regs.REG_PROTOCOL_STATE); - + + if(app_regs.REG_PROTOCOL_STATE != reg) + { + app_regs.REG_PROTOCOL_STATE = reg; + app_write_REG_PROTOCOL_STATE(&app_regs.REG_PROTOCOL_STATE); + } + + return true; } From 533e526d84bcd343f4eefd6c4611a4484e7db212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 4 Feb 2022 11:21:34 +0000 Subject: [PATCH 4/5] [fw] allow protocol state to be changed on the register code --- Firmware/Pump/app.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index b25b328..b11846b 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -347,9 +347,8 @@ void core_callback_t_before_exec(void) else { // we reached the end, lets stop everything and reset variables - stop_and_reset_protocol(); - app_regs.REG_PROTOCOL_STATE = 0; - app_write_REG_PROTOCOL_STATE(&app_regs.REG_PROTOCOL_STATE); + app_regs.REG_START_PROTOCOL = 0; + app_write_REG_START_PROTOCOL(&app_regs.REG_START_PROTOCOL); } } } From 6e786132b71c56ce7b7231c306ae5543d8e7abee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Teixeira?= Date: Fri, 4 Feb 2022 13:14:00 +0000 Subject: [PATCH 5/5] [fw] update firmware version --- Firmware/Pump/app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Pump/app.c b/Firmware/Pump/app.c index b11846b..31d6e24 100644 --- a/Firmware/Pump/app.c +++ b/Firmware/Pump/app.c @@ -30,7 +30,7 @@ void hwbp_app_initialize(void) uint8_t hwH = 1; uint8_t hwL = 1; uint8_t fwH = 0; - uint8_t fwL = 4; + uint8_t fwL = 5; uint8_t ass = 0; /* Start core */