diff options
Diffstat (limited to 'radiator-plc/stm32/app/inputs.c')
-rw-r--r-- | radiator-plc/stm32/app/inputs.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/radiator-plc/stm32/app/inputs.c b/radiator-plc/stm32/app/inputs.c new file mode 100644 index 0000000..825a3fe --- /dev/null +++ b/radiator-plc/stm32/app/inputs.c @@ -0,0 +1,26 @@ +#include "project.h" + +#define N_INPUTS 14 + +static const uint32_t input_bank[N_INPUTS] = { GPIOC, GPIOC, GPIOB, GPIOA, GPIOA, GPIOC, GPIOD, GPIOD, 0, 0, GPIOD, GPIOD, GPIOD, GPIOD}; +static const uint32_t input[N_INPUTS] = { GPIO7, GPIO6, GPIO15, GPIO1, GPIO0, GPIO4, GPIO15, GPIO14, 0, 0, GPIO13, GPIO12, GPIO11, GPIO10}; + +int input_get (unsigned r) +{ + if (r >= N_INPUTS) return 0; + + if (!input[r]) return 0; + + return !gpio_get (input_bank[r], input[r]); +} + + +void inputs_init (void) +{ + unsigned r; + + for (r = 0; r < N_INPUTS; ++r) + if (input[r]) + gpio_set_mode (input_bank[r], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, input[r]); + +} |