From 45f91a7c5a2a3d2b6295359429d3b30a11065cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 26 Dec 2021 20:27:20 +0100 Subject: [PATCH 1/5] Add commands for DIGIO channels to profile parser and add base construct to the profile interpreter --- .../reflow-controller/temp-profile/temp-profile-parser.h | 3 +++ stm-firmware/temp-profile/temp-profile-executer.c | 9 +++++++++ stm-firmware/temp-profile/temp-profile-parser.c | 3 +++ 3 files changed, 15 insertions(+) diff --git a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h index f05d3c9..799ffc8 100644 --- a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h +++ b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h @@ -41,6 +41,9 @@ enum pl_command_type { PL_LOUDSPEAKER_SET, /**< @brief Set the loudspeaker/beeper */ PL_OFF, /**< @brief Disable the temperature output and shutdown the PID controller */ PL_CLEAR_FLAGS, /**< @brief Try clear all flags */ + PL_DIGIO_CONF, /**< @brief Configure a DIGIO pin */ + PL_DIGIO_SET, /**< @brief Set a DIGIO pin */ + PL_DIGIO_WAIT, /**< @brief Wait until a DIGIO pin is set to the specified level */ _PL_NUM_CMDS, /**< @brief Sentinel to determine the total amount of commands */ }; diff --git a/stm-firmware/temp-profile/temp-profile-executer.c b/stm-firmware/temp-profile/temp-profile-executer.c index f9b8fd8..2ee1170 100644 --- a/stm-firmware/temp-profile/temp-profile-executer.c +++ b/stm-firmware/temp-profile/temp-profile-executer.c @@ -250,6 +250,15 @@ int temp_profile_executer_handle(void) cmd_ack_flags(); advance = true; break; + case PL_DIGIO_CONF: + advance = true; + break; + case PL_DIGIO_SET: + advance = true; + break; + case PL_DIGIO_WAIT: + advance = true; + break; default: tpe_abort(); advance = true; diff --git a/stm-firmware/temp-profile/temp-profile-parser.c b/stm-firmware/temp-profile/temp-profile-parser.c index a87e9b2..a48def7 100644 --- a/stm-firmware/temp-profile/temp-profile-parser.c +++ b/stm-firmware/temp-profile/temp-profile-parser.c @@ -48,6 +48,9 @@ static const struct pl_command_list_map cmd_list_map[_PL_NUM_CMDS] = { {PL_LOUDSPEAKER_SET, "beep", 1u}, {PL_OFF, "temp_off", 0u}, {PL_CLEAR_FLAGS, "clear_flags", 0u}, + {PL_DIGIO_CONF, "digio_conf", 2u}, + {PL_DIGIO_SET, "digio_set", 2u}, + {PL_DIGIO_WAIT, "digio_wait", 2u}, }; /** From a8a622df25257f978604ced7533c4d181c9bedf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 26 Dec 2021 20:36:49 +0100 Subject: [PATCH 2/5] Make temperture profile executer reset the DIGIO settings after profile execution/abort --- stm-firmware/digio.c | 22 +++++++++++-------- .../include/reflow-controller/digio.h | 12 ++++++++-- stm-firmware/main.c | 4 ++-- .../temp-profile/temp-profile-executer.c | 2 ++ 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/stm-firmware/digio.c b/stm-firmware/digio.c index a8c67e9..c544072 100644 --- a/stm-firmware/digio.c +++ b/stm-firmware/digio.c @@ -52,17 +52,10 @@ static void digio_setup_pin_int(uint8_t bit_no, uint8_t in_out, uint8_t alt_func } -void digio_setup_default_all(void) +void digio_init(void) { - unsigned int i; - rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(DIGIO_RCC_MASK)); - - for (i = 0; i < COUNT_OF(digio_pins); i++) { - digio_setup_pin_int(digio_pins[i], digio_default_io[i], digio_default_altfunc[i]); - if (digio_default_io[i] == 1) - digio_set(i, 0); - } + digio_set_default_values(); } void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func) @@ -219,3 +212,14 @@ void TIM7_IRQHandler(void) #endif /** @} */ + +void digio_set_default_values() +{ + unsigned int i; + + for (i = 0; i < COUNT_OF(digio_pins); i++) { + digio_setup_pin_int(digio_pins[i], digio_default_io[i], digio_default_altfunc[i]); + if (digio_default_io[i] == 1) + digio_set(i, 0); + } +} diff --git a/stm-firmware/include/reflow-controller/digio.h b/stm-firmware/include/reflow-controller/digio.h index d8316e5..495aa3d 100644 --- a/stm-firmware/include/reflow-controller/digio.h +++ b/stm-firmware/include/reflow-controller/digio.h @@ -65,11 +65,19 @@ #define BEEPER_RCC_MASK RCC_AHB1ENR_GPIOBEN /** - * @brief Enable all clocks and setup pins in default setting + * @brief Enable all clocks and setup pins in default setting. * @warning This function uses @ref rcc_manager_enable_clock to enable the clocks. Therefore, it must not be called * multiple times. + * @note Calls @ref digio_set_default_values() internally. */ -void digio_setup_default_all(void); +void digio_init(void); + +/** + * @brief Setup or restore the default DIGIO settings. + * + * This function can be called multiple times. + */ +void digio_set_default_values(void); /** * @brief Set up a DIGIO pin. diff --git a/stm-firmware/main.c b/stm-firmware/main.c index be066e1..dcf8145 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -219,8 +219,8 @@ static inline void setup_system(void) /** - Initialize the oven output driver outputting the wavepacket control signal for the SSR and */ oven_driver_init(); - /** - Initialize all DIGIO Pins to theri default state and pin functions */ - digio_setup_default_all(); + /** - Initialize all DIGIO Pins to their default state and pin functions */ + digio_init(); /** - Set-up the LED outputs */ led_setup(); diff --git a/stm-firmware/temp-profile/temp-profile-executer.c b/stm-firmware/temp-profile/temp-profile-executer.c index 2ee1170..f5631a8 100644 --- a/stm-firmware/temp-profile/temp-profile-executer.c +++ b/stm-firmware/temp-profile/temp-profile-executer.c @@ -299,7 +299,9 @@ int temp_profile_executer_stop(void) if (command_list) temp_profile_free_command_list(&command_list); + /* Reset loudspeaker and reset default state of DIGIO channels */ loudspeaker_set(0); + digio_set_default_values(); return 0; } From 3bb4607798007277b9bc9600cc500d5d09327db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 26 Dec 2021 20:40:28 +0100 Subject: [PATCH 3/5] digio: Make digio check if an port to set is an output port. --- stm-firmware/digio.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stm-firmware/digio.c b/stm-firmware/digio.c index c544072..f6d67b2 100644 --- a/stm-firmware/digio.c +++ b/stm-firmware/digio.c @@ -67,12 +67,22 @@ void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func) void digio_set(uint8_t num, int val) { + uint8_t pin; + if (num >= COUNT_OF(digio_pins)) return; + + pin = digio_pins[num]; + + /* Check if port is an output. If not, do noting. */ + if ((DIGIO_PORT->MODER & (0x3<ODR |= (1<ODR |= (1<ODR &= ~(1<ODR &= ~(1< Date: Sun, 26 Dec 2021 20:54:04 +0100 Subject: [PATCH 4/5] Issue #39: Implement DIGIO profile commands --- .../temp-profile/temp-profile-executer.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/stm-firmware/temp-profile/temp-profile-executer.c b/stm-firmware/temp-profile/temp-profile-executer.c index f5631a8..ed983ef 100644 --- a/stm-firmware/temp-profile/temp-profile-executer.c +++ b/stm-firmware/temp-profile/temp-profile-executer.c @@ -185,6 +185,36 @@ static void cmd_ack_flags(void) } +static void cmd_digio_conf(uint8_t digio_num, uint8_t mode) +{ + uint8_t pin_mode; + uint8_t alt_func = 0; + + if (mode == 0 || mode == 1) { + pin_mode = mode; + } else if (mode >= 0x80 && mode <= 0x87) { + /* Alternate function */ + pin_mode = 2; + alt_func = mode - 0x80; + } else { + return; + } + + digio_setup_pin(digio_num, pin_mode, alt_func); +} + +bool cmd_digio_wait(uint8_t digio_num, uint8_t digio_state) +{ + bool advance = false; + int res; + + res = digio_get(digio_num); + if (res < 0 || (uint8_t)res == digio_state) + advance = true; + + return advance; +} + int temp_profile_executer_handle(void) { struct pl_command *current_cmd; @@ -252,12 +282,14 @@ int temp_profile_executer_handle(void) break; case PL_DIGIO_CONF: advance = true; + cmd_digio_conf((uint8_t)current_cmd->params[0], (uint8_t)current_cmd->params[1]); break; case PL_DIGIO_SET: + digio_set((uint8_t)current_cmd->params[0], current_cmd->params[1] ? 1u : 0u); advance = true; break; case PL_DIGIO_WAIT: - advance = true; + advance = cmd_digio_wait((uint8_t)current_cmd->params[0], current_cmd->params[1] ? 1u : 0u); break; default: tpe_abort(); From 2957a42cef3d5c86e8b883d761a05900fffe5df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 26 Dec 2021 20:59:08 +0100 Subject: [PATCH 5/5] Fix indetation in header file --- .../reflow-controller/temp-profile/temp-profile-parser.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h index 799ffc8..6b2556c 100644 --- a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h +++ b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h @@ -41,9 +41,9 @@ enum pl_command_type { PL_LOUDSPEAKER_SET, /**< @brief Set the loudspeaker/beeper */ PL_OFF, /**< @brief Disable the temperature output and shutdown the PID controller */ PL_CLEAR_FLAGS, /**< @brief Try clear all flags */ - PL_DIGIO_CONF, /**< @brief Configure a DIGIO pin */ - PL_DIGIO_SET, /**< @brief Set a DIGIO pin */ - PL_DIGIO_WAIT, /**< @brief Wait until a DIGIO pin is set to the specified level */ + PL_DIGIO_CONF, /**< @brief Configure a DIGIO pin */ + PL_DIGIO_SET, /**< @brief Set a DIGIO pin */ + PL_DIGIO_WAIT, /**< @brief Wait until a DIGIO pin is set to the specified level */ _PL_NUM_CMDS, /**< @brief Sentinel to determine the total amount of commands */ };