TM STM32F4xx Libraries  v1.0.0
Libraries for STM32F4xx devices from Tilen Majerle
tm_stm32f4_button.h
1 
30 #ifndef TM_BUTTON_H
31 #define TM_BUTTON_H 100
32 
33 /* C++ detection */
34 #ifdef __cplusplus
35 extern C {
36 #endif
37 
69 #include "stm32f4xx.h"
70 #include "defines.h"
71 #include "tm_stm32f4_gpio.h"
72 #include "tm_stm32f4_delay.h"
73 #include "stdlib.h"
74 
81 /* Number of maximal supported buttons */
82 #ifndef BUTTON_MAX_BUTTONS
83 #define BUTTON_MAX_BUTTONS 10
84 #endif
85 
86 /* Number of milliseconds for normal press detection */
87 #ifndef BUTTON_NORMAL_PRESS_TIME
88 #define BUTTON_NORMAL_PRESS_TIME 100
89 #endif
90 
91 /* Number of milliseconds for long press detection */
92 #ifndef BUTTON_LONG_PRESS_TIME
93 #define BUTTON_LONG_PRESS_TIME 1500
94 #endif
95 
109 typedef enum {
114 
118 typedef struct _TM_BUTTON_t {
119  GPIO_TypeDef* GPIOx;
120  uint16_t GPIO_Pin;
121  uint8_t GPIO_State;
123  uint32_t StartTime;
124  uint8_t LastStatus;
125  uint8_t State;
126  uint16_t PressNormalTime;
127  uint16_t PressLongTime;
128 } TM_BUTTON_t;
129 
153 TM_BUTTON_t* TM_BUTTON_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint8_t ButtonState, void (*ButtonHandler)(TM_BUTTON_PressType_t));
154 
162 TM_BUTTON_t* TM_BUTTON_SetPressTime(TM_BUTTON_t* ButtonStruct, uint16_t Normal, uint16_t Long);
163 
170 void TM_BUTTON_Update(void);
171 
184 /* C++ detection */
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif
GPIO_TypeDef * GPIOx
Definition: tm_stm32f4_button.h:119
struct _TM_BUTTON_t TM_BUTTON_t
Button private structure.
void(* ButtonHandler)(TM_BUTTON_PressType_t)
Definition: tm_stm32f4_button.h:122
uint16_t PressNormalTime
Definition: tm_stm32f4_button.h:126
TM_BUTTON_t * TM_BUTTON_SetPressTime(TM_BUTTON_t *ButtonStruct, uint16_t Normal, uint16_t Long)
Sets press timing values.
TM_BUTTON_PressType_t
Button possible press types.
Definition: tm_stm32f4_button.h:109
void TM_BUTTON_Update(void)
Updates buttons. This function have to be called periodically.
uint8_t GPIO_State
Definition: tm_stm32f4_button.h:121
uint16_t GPIO_Pin
Definition: tm_stm32f4_button.h:120
Definition: tm_stm32f4_button.h:112
uint8_t LastStatus
Definition: tm_stm32f4_button.h:124
uint32_t StartTime
Definition: tm_stm32f4_button.h:123
uint8_t State
Definition: tm_stm32f4_button.h:125
Definition: tm_stm32f4_button.h:110
uint16_t PressLongTime
Definition: tm_stm32f4_button.h:127
Button private structure.
Definition: tm_stm32f4_button.h:118
Definition: tm_stm32f4_button.h:111
TM_BUTTON_t * TM_BUTTON_Init(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint8_t ButtonState, void(*ButtonHandler)(TM_BUTTON_PressType_t))
Initializes a new button to library.