TM STM32Fxxx HAL Libraries  v1.0.0
Libraries for STM32Fxxx (F0, F4 and F7 series) devices based on HAL drivers from ST from Tilen Majerle
tm_stm32_button.h
1 
37 #ifndef TM_BUTTON_H
38 #define TM_BUTTON_H 100
39 
40 /* C++ detection */
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
76 #include "stm32fxxx_hal.h"
77 #include "defines.h"
78 #include "tm_stm32_gpio.h"
79 #include "tm_stm32_delay.h"
80 #include "stdlib.h"
81 
88 /* Number of maximal supported buttons */
89 #ifndef BUTTON_MAX_BUTTONS
90 #define BUTTON_MAX_BUTTONS 10
91 #endif
92 
93 /* Time for debounce */
94 #ifndef BUTTON_DEBOUNCE_TIME
95 #define BUTTON_DEBOUNCE_TIME 5
96 #endif
97 
98 /* Number of milliseconds for normal press detection */
99 #ifndef BUTTON_NORMAL_PRESS_TIME
100 #define BUTTON_NORMAL_PRESS_TIME 100
101 #endif
102 
103 /* Number of milliseconds for long press detection */
104 #ifndef BUTTON_LONG_PRESS_TIME
105 #define BUTTON_LONG_PRESS_TIME 1500
106 #endif
107 
108 /* Library allocation function */
109 #ifndef LIB_ALLOC_FUNC
110 #define LIB_ALLOC_FUNC malloc
111 #endif
112 
113 /* Library free function */
114 #ifndef LIB_FREE_FUNC
115 #define LIB_FREE_FUNC free
116 #endif
117 
131 typedef enum {
137 
141 typedef struct _TM_BUTTON_t {
142  GPIO_TypeDef* GPIOx;
143  uint16_t GPIO_Pin;
144  uint8_t GPIO_State;
146  uint32_t StartTime;
147  uint8_t LastStatus;
148  uint8_t State;
149  uint16_t PressDebounceTime;
150  uint16_t PressNormalTime;
151  uint16_t PressLongTime;
152 } TM_BUTTON_t;
153 
177 TM_BUTTON_t* TM_BUTTON_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint8_t ButtonState, void (*ButtonHandler)(TM_BUTTON_t*, TM_BUTTON_PressType_t));
178 
186 TM_BUTTON_t* TM_BUTTON_SetPressTime(TM_BUTTON_t* ButtonStruct, uint16_t Normal, uint16_t Long);
187 
194 void TM_BUTTON_Update(void);
195 
208 /* C++ detection */
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif
GPIO_TypeDef * GPIOx
Definition: tm_stm32_button.h:142
struct _TM_BUTTON_t TM_BUTTON_t
Button structure.
uint16_t PressNormalTime
Definition: tm_stm32_button.h:150
TM_BUTTON_t * TM_BUTTON_SetPressTime(TM_BUTTON_t *ButtonStruct, uint16_t Normal, uint16_t Long)
Sets press timing values.
void(* ButtonHandler)(struct _TM_BUTTON_t *, TM_BUTTON_PressType_t)
Definition: tm_stm32_button.h:145
Definition: tm_stm32_button.h:133
uint16_t PressDebounceTime
Definition: tm_stm32_button.h:149
TM_BUTTON_PressType_t
Button possible press types.
Definition: tm_stm32_button.h:131
void TM_BUTTON_Update(void)
Updates buttons. This function have to be called periodically.
uint8_t GPIO_State
Definition: tm_stm32_button.h:144
uint16_t GPIO_Pin
Definition: tm_stm32_button.h:143
Definition: tm_stm32_button.h:135
uint8_t LastStatus
Definition: tm_stm32_button.h:147
uint32_t StartTime
Definition: tm_stm32_button.h:146
uint8_t State
Definition: tm_stm32_button.h:148
Definition: tm_stm32_button.h:132
uint16_t PressLongTime
Definition: tm_stm32_button.h:151
Button structure.
Definition: tm_stm32_button.h:141
TM_BUTTON_t * TM_BUTTON_Init(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint8_t ButtonState, void(*ButtonHandler)(TM_BUTTON_t *, TM_BUTTON_PressType_t))
Initializes a new button to library.
Definition: tm_stm32_button.h:134