CubeMon-Vue-Demo-STM32F407VGT6U
di.h
Go to the documentation of this file.
1
27#ifndef INC_DI_DI_H_
28#define INC_DI_DI_H_
29
31#include <lib/uti/utility.h>
32#include <lib/uti/lib_config.h>
33
34#ifdef LIB_DI
35#include <prog/init.h>
36#else
41typedef enum digInputs {
42 DI_NONE,
44#endif
45
46typedef GPIO_PinState (*input_get_hw_state)(digInputs input);
47
48
50typedef enum digitalInputActions {
58
60typedef enum digitalInputHWType {
63
67
69typedef enum digitalInputSWType {
73
78
80typedef struct digitalInputInitData {
81 uint16_t mcu_pin;
82 GPIO_TypeDef *mcu_port;
83
87 uint16_t debounc_time;
88
91 uint16_t long_press_ms;
92
97
100
103
104
109
117
125
132
139
147
162retStatus input_get(uint32_t input, uint16_t data, int32_t *value);
163
181retStatus input_set(uint32_t input, uint16_t data, int32_t value);
182
195 digitalInputInitData digital_input_init_data);
196
210 digitalInputInitData *digital_input_init_data);
211
226
227//todo rename this + maybe boolean?
228uint8_t input_get_action(digInputs input_name, digitalInputActions action);
229
237uint8_t input_is_short_press(digInputs input_name);
238
246uint8_t input_is_long_press(digInputs input_name);
247
258
269
275void input_handle(void);
276
282__weak GPIO_PinState input_get_hw_HAL(digInputs input_name);
283
284#endif /* INC_DI_DI_H_ */
retStatus input_init(digInputs input_name, digitalInputInitData digital_input_init_data)
Digital input initialization function.
Definition: di.c:150
uint8_t input_is_long_press(digInputs input_name)
Checks if the input detected long press.
dioStates input_logical_state_debounced(digInputs input_name)
Return the input debounced logical state.
Definition: di.c:216
retStatus input_ack_action(digInputs input_name, digitalInputActions action)
Acknowledge digital input action.
Definition: di.c:247
dioStates input_state_now(digInputs input_name)
Return the input state read from HW at the moment the function is called.
Definition: di.c:224
struct digitalInputInitData digitalInputInitData
digital input initialization structure
retStatus input_set(uint32_t input, uint16_t data, int32_t value)
Standardized setter function for digital input library.
Definition: di.c:100
__weak GPIO_PinState input_get_hw_HAL(digInputs input_name)
Get HW input state. In case you want to implement it differently (f.e. not using HAL)
Definition: di.c:255
retStatus input_get(uint32_t input, uint16_t data, int32_t *value)
Standardized getter function for digital input library.
Definition: di.c:65
digitalInputSWType
possible input SW types
Definition: di.h:69
@ INPUT_SW_ON_OFF_INPUT
only evaluates logical state and rising/falling edge best used for toggle switches or similar type of...
Definition: di.h:72
@ INPUT_SW_BUTTON
evaluates state and rising/falling edges and also detects three types of button presses best used for...
Definition: di.h:76
digitalInputHWType
possible input HW types
Definition: di.h:60
@ INPUT_HW_ACTIVE_HIGH
for inputs that are active if a voltage is applied to the pin (usually with pulldown resistor)
Definition: di.h:62
@ INPUT_HW_ACTIVE_LOW
for inputs that are activated when pulled to the GND (always with pullup resistor)
Definition: di.h:65
digitalInputDateTypes
digital input data
Definition: di.h:106
@ INPUT_DAT_DOUBLE_PRESS
input double press status read status with input_get, clean only the double press status with input_s...
Definition: di.h:145
@ INPUT_DAT_RISING_EDGE
logical rising edge detected for INPUT_HW_ACTIVE_HIGH this will be set if the input goes from "0" to ...
Definition: di.h:116
@ INPUT_DAT_LONG_PRESS
input long press status read status with input_get, clean only the long press status with input_set a...
Definition: di.h:138
@ INPUT_DAT_CURR
input current logical value (not debounced), reading directly from HW
Definition: di.h:107
@ INPUT_DAT_DEBOUNCED
input debounced logical value
Definition: di.h:108
@ INPUT_DAT_SHORT_PRESS
input short press status read status with input_get, clean only the short press status with input_set...
Definition: di.h:131
@ INPUT_DAT_FALLING_EDGE
logical falling edge detected for INPUT_HW_ACTIVE_HIGH this will be set if the input goes from "1" to...
Definition: di.h:124
uint8_t input_is_short_press(digInputs input_name)
Checks if the input detected short press. After reading out the value, you need to clean the action f...
void input_handle(void)
Handles digital input logic. Call every 1ms.
Definition: di.c:232
retStatus input_get_init_data(digInputs input_name, digitalInputInitData *digital_input_init_data)
Return input initialization data.
Definition: di.c:139
digInputs
Definition: di.h:41
digitalInputActions
possible input actions
Definition: di.h:50
@ INPUT_ACT_DOUBLE_PRESS
two short presses with maximal time between them
Definition: di.h:55
@ INPUT_ACT_FALLING_EDGE
falling edge of the input logical state
Definition: di.h:51
@ INPUT_ACT_SHORT_PRESS
short press (input active for a defined debounced time and release again, no second press follows)
Definition: di.h:53
@ INPUT_ACT_NONE
dummy so we can always have the enum length
Definition: di.h:56
@ INPUT_ACT_RISING_EDGE
rising edge of the input logical state
Definition: di.h:52
@ INPUT_ACT_LONG_PRESS
input is hold active for defined time
Definition: di.h:54
provides HAL includes for different MCU cores
Initialization of digital/analog inputs and outputs.
@ DI_NONE
DUMMY to keep the track of enum length.
Definition: init.h:23
Defines for turning on/off the library modules.
digital input initialization structure
Definition: di.h:80
input_get_hw_state input_get_hw_state
function for getting GPIO state, pass NULL pointer to default to HAL_GPIO_Read
Definition: di.h:101
digitalInputSWType sw_type
input sw_type
Definition: di.h:99
GPIO_TypeDef * mcu_port
MCU GPIO port.
Definition: di.h:82
digitalInputHWType hw_type
input hw_type
Definition: di.h:98
uint16_t long_press_ms
minimal time [ms] to consider the input change to logical "true" as a long press set to "0" to deacti...
Definition: di.h:91
uint16_t debounc_time
minimal time [ms] to consider the input change as a valid change recommended value for mechanical swi...
Definition: di.h:87
uint16_t mcu_pin
MCU GPIO pin number.
Definition: di.h:81
uint16_t double_press_spacing
maximal time [ms] before two presses that will result in double press, recommended value ~60ms set to...
Definition: di.h:96
Defines and functions that are useful for all library files.
dioStates
digital input/output states
Definition: utility.h:31
retStatus
possible return values
Definition: utility.h:13