Files
@ c1b2840961f0
Branch filter:
Location: therm-ng/src/system/gpio.c
c1b2840961f0
3.4 KiB
text/plain
Hacking thermostatic mode into operation. This code needs some love.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | //
// GPIO: configure general-purpose inputs/outputs
//
#include "stm32f3xx_hal.h"
#include "gpio.h"
// Private variables
// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
static uint32_t change_time_reset = 0;
// Initialize GPIOs
void gpio_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
// GPIO Ports Clock Enable
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOF_CLK_ENABLE();
// Configure LED GPIO pins
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = SW_A_Pin|SW_B_Pin|SW_C_Pin|SW_D_Pin|AUX_INPUT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SW_C_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = AUX_RETURN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(AUX_RETURN_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = SW_BTN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SW_BTN_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
// Define startup State
HAL_GPIO_WritePin(LED, 0);
HAL_GPIO_WritePin(AUX_RETURN, 0);
}
// Increment/decrement unsigned variable with up/down buttons
void user_input(uint16_t* to_modify)
{
if(CHANGE_ELAPSED) {
if(!HAL_GPIO_ReadPin(SW_UP) ) {
CHANGE_RESET;
(*to_modify)++;
}
else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) {
CHANGE_RESET;
(*to_modify)--;
}
}
}
// Increment/decrement unsigned variable with up/down buttons
void user_input_min_max(uint16_t* to_modify, uint16_t min, uint16_t max)
{
if(CHANGE_ELAPSED) {
if(!HAL_GPIO_ReadPin(SW_UP) && ((*to_modify) < max))
{
CHANGE_RESET;
(*to_modify)++;
}
else if(!HAL_GPIO_ReadPin(SW_DOWN) && ((*to_modify) > min))
{
CHANGE_RESET;
(*to_modify)--;
}
}
}
// Increment/decrement signed variable with up/down buttons
void user_input_signed(int32_t* to_modify)
{
//fixme: need to cast to 16/32 bits correctly
if(CHANGE_ELAPSED) {
if(!HAL_GPIO_ReadPin(SW_UP) ) {
CHANGE_RESET;
if (*to_modify < 32768)
(*to_modify)++;
}
else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
CHANGE_RESET;
if (*to_modify >= -32768)
(*to_modify)--;
}
}
}
// Increment/decrement signed variable with up/down buttons
void user_input_float(float* to_modify)
{
//fixme: need to cast to 16/32 bits correctly
if(CHANGE_ELAPSED) {
if(!HAL_GPIO_ReadPin(SW_UP) ) {
CHANGE_RESET;
if (*to_modify < 32768)
(*to_modify)++;
}
else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
CHANGE_RESET;
if (*to_modify >= -32768)
(*to_modify)--;
}
}
}
|