From: Nathael Pajani Date: Wed, 13 Dec 2023 21:55:15 +0000 (+0100) Subject: Fix relay command to avoid holding relay current in bistable relays X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=86b952183619f7a2006853f89a634bbd98242f97;p=soft%2Flpc122x%2Fscialys Fix relay command to avoid holding relay current in bistable relays --- diff --git a/tor/config.c b/tor/config.c index 00b2053..9379301 100644 --- a/tor/config.c +++ b/tor/config.c @@ -78,12 +78,12 @@ const struct pio status_light_green = LPC_GPIO_0_26; const struct pio status_light_red = LPC_GPIO_0_27; /* Outputs */ -const struct pio relay1_off_pin = LPC_GPIO_0_4; -const struct pio relay1_on_pin = LPC_GPIO_0_3; -const struct pio relay2_off_pin = LPC_GPIO_0_0; -const struct pio relay2_on_pin = LPC_GPIO_0_28; -const struct pio relay3_off_pin = LPC_GPIO_0_6; -const struct pio relay3_on_pin = LPC_GPIO_0_5; +const struct pio relay1_on_pin = LPC_GPIO_0_4; +const struct pio relay1_off_pin = LPC_GPIO_0_3; +const struct pio relay2_on_pin = LPC_GPIO_0_0; +const struct pio relay2_off_pin = LPC_GPIO_0_28; +const struct pio relay3_on_pin = LPC_GPIO_0_6; +const struct pio relay3_off_pin = LPC_GPIO_0_5; @@ -138,12 +138,12 @@ void fault_info(const char* name, uint32_t len) void board_io_config(void) { /* Immediatly turn off relay commands */ - config_gpio(&relay1_on_pin, 0, GPIO_DIR_OUT, 1); - config_gpio(&relay1_off_pin, 0, GPIO_DIR_OUT, 1); - config_gpio(&relay2_on_pin, 0, GPIO_DIR_OUT, 1); - config_gpio(&relay2_off_pin, 0, GPIO_DIR_OUT, 1); - config_gpio(&relay3_on_pin, 0, GPIO_DIR_OUT, 1); - config_gpio(&relay3_off_pin, 0, GPIO_DIR_OUT, 1); + config_gpio(&relay1_on_pin, 0, GPIO_DIR_OUT, 0); + config_gpio(&relay1_off_pin, 0, GPIO_DIR_OUT, 0); + config_gpio(&relay2_on_pin, 0, GPIO_DIR_OUT, 0); + config_gpio(&relay2_off_pin, 0, GPIO_DIR_OUT, 0); + config_gpio(&relay3_on_pin, 0, GPIO_DIR_OUT, 0); + config_gpio(&relay3_off_pin, 0, GPIO_DIR_OUT, 0); } diff --git a/tor/main.c b/tor/main.c index 45d7d61..1c26877 100644 --- a/tor/main.c +++ b/tor/main.c @@ -97,13 +97,16 @@ volatile uint8_t relay_states[4] = { 0, RELAY_OFF, RELAY_OFF, RELAY_OFF}; void relay_pin_toggle(const struct pio relay_pin) { - gpio_clear(relay_pin); - msleep(12); gpio_set(relay_pin); + msleep(12); + gpio_clear(relay_pin); } void change_relay_state(uint8_t relay_num, uint8_t state) { + if (relay_states[relay_num] == state) { + return; + } uprintf(UART0, "R%d:%d\n", relay_num, state); switch (relay_num | (state << 2)) { case 1: