CubeMon-Vue-Demo-STM32F407VGT6U
di.h File Reference

digital inputs with falling/rising edge, short press, long press and double press detection More...

Go to the source code of this file.

Data Structures

struct  digitalInputInitData
 digital input initialization structure More...
 

Typedefs

typedef enum digInputs digInputs
 
typedef GPIO_PinState(* input_get_hw_state) (digInputs input)
 
typedef enum digitalInputActions digitalInputActions
 possible input actions
 
typedef enum digitalInputHWType digitalInputHWType
 possible input HW types
 
typedef enum digitalInputSWType digitalInputSWType
 possible input SW types
 
typedef struct digitalInputInitData digitalInputInitData
 digital input initialization structure
 
typedef enum digitalInputDateTypes digitalInputDateTypes
 digital input data
 

Enumerations

enum  digInputs {
  DI_NONE , DI_BUTTON , DI_1 , DI_2 ,
  DI_NONE
}
 
enum  digitalInputActions {
  INPUT_ACT_FALLING_EDGE , INPUT_ACT_RISING_EDGE , INPUT_ACT_SHORT_PRESS , INPUT_ACT_LONG_PRESS ,
  INPUT_ACT_DOUBLE_PRESS , INPUT_ACT_NONE
}
 possible input actions More...
 
enum  digitalInputHWType { INPUT_HW_ACTIVE_HIGH , INPUT_HW_ACTIVE_LOW }
 possible input HW types More...
 
enum  digitalInputSWType { INPUT_SW_ON_OFF_INPUT , INPUT_SW_BUTTON }
 possible input SW types More...
 
enum  digitalInputDateTypes {
  INPUT_DAT_CURR , INPUT_DAT_DEBOUNCED , INPUT_DAT_RISING_EDGE , INPUT_DAT_FALLING_EDGE ,
  INPUT_DAT_SHORT_PRESS , INPUT_DAT_LONG_PRESS , INPUT_DAT_DOUBLE_PRESS
}
 digital input data More...
 

Functions

retStatus input_get (uint32_t input, uint16_t data, int32_t *value)
 Standardized getter function for digital input library. More...
 
retStatus input_set (uint32_t input, uint16_t data, int32_t value)
 Standardized setter function for digital input library. More...
 
retStatus input_init (digInputs input_name, digitalInputInitData digital_input_init_data)
 Digital input initialization function. More...
 
retStatus input_get_init_data (digInputs input_name, digitalInputInitData *digital_input_init_data)
 Return input initialization data. More...
 
retStatus input_ack_action (digInputs input_name, digitalInputActions action)
 Acknowledge digital input action. More...
 
uint8_t input_get_action (digInputs input_name, digitalInputActions action)
 
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 flag with input_ack_action() or input_set() More...
 
uint8_t input_is_long_press (digInputs input_name)
 Checks if the input detected long press. More...
 
dioStates input_state_now (digInputs input_name)
 Return the input state read from HW at the moment the function is called. More...
 
dioStates input_logical_state_debounced (digInputs input_name)
 Return the input debounced logical state. More...
 
void input_handle (void)
 Handles digital input logic. Call every 1ms. More...
 
__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) More...
 

Detailed Description

digital inputs with falling/rising edge, short press, long press and double press detection

Author
panvicka
Date
2.1.2022

Both active/low input types can be used. The detection of presses can be deactivated if the inputs is a toggle switch. For the tactile input types, the double press detection can be deactived as well.

A support for a direct manipulation of the input state with CUBE MX Monitoring tool is build in. If you want to use it, define flag ALLOW_CUBEMX_OVERWRITE in you project.

To use this library define flag LIB_DI in the lib_config.h file and create an enum in init.h file with the inputs you would like to use. You then have to initialize each input with input_init() function.

typedef enum digInputs{
MY_INPUT_1,
MY_INPUT_2,
MY_INPUT_3,
digInputs
Definition: di.h:41
@ DI_NONE
DUMMY to keep the track of enum length.
Definition: init.h:23
Note
Do not forget to include the DI_NONE at the end of the enum listing.

Typedef Documentation

◆ digInputs

typedef enum digInputs digInputs

If the library is not used (LIB_DI is not defined as symbol) this dummy enum will be created to prevent compilation errors

Enumeration Type Documentation

◆ digInputs

enum digInputs

If the library is not used (LIB_DI is not defined as symbol) this dummy enum will be created to prevent compilation errors

Enumerator
DI_BUTTON 

User button.

DI_1 

DI_1 (PE7, active high)

DI_2 

DI_2 (PE8, active low)

DI_NONE 

DUMMY to keep the track of enum length.

◆ digitalInputActions

possible input actions

Enumerator
INPUT_ACT_FALLING_EDGE 

falling edge of the input logical state

INPUT_ACT_RISING_EDGE 

rising edge of the input logical state

INPUT_ACT_SHORT_PRESS 

short press (input active for a defined debounced time and release again, no second press follows)

INPUT_ACT_LONG_PRESS 

input is hold active for defined time

INPUT_ACT_DOUBLE_PRESS 

two short presses with maximal time between them

INPUT_ACT_NONE 

dummy so we can always have the enum length

◆ digitalInputDateTypes

digital input data

Enumerator
INPUT_DAT_CURR 

input current logical value (not debounced), reading directly from HW

INPUT_DAT_DEBOUNCED 

input debounced logical value

INPUT_DAT_RISING_EDGE 

logical rising edge detected for INPUT_HW_ACTIVE_HIGH this will be set if the input goes from "0" to "1" for INPUT_HW_ACTIVE_LOW this will be set if the input goes from "1" to "0" it must be cleaned: with /ref input_set function and set value "0" or with /ref input_ack_action with argument /ref INPUT_ACT_RISING_EDGE

INPUT_DAT_FALLING_EDGE 

logical falling edge detected for INPUT_HW_ACTIVE_HIGH this will be set if the input goes from "1" to "0" for INPUT_HW_ACTIVE_LOW this will be set if the input goes from "0" to "1" it must be cleaned: with /ref input_set function and set value "0" or with /ref input_ack_action with argument /ref INPUT_ACT_FALLING_EDGE

INPUT_DAT_SHORT_PRESS 

input short press status read status with input_get, clean only the short press status with input_set and value "0" it must be cleaned: with /ref input_set function and set value "0" or with /ref input_ack_action with argument /ref INPUT_ACT_SHORT_PRESS

INPUT_DAT_LONG_PRESS 

input long press status read status with input_get, clean only the long press status with input_set and value "0" it must be cleaned: with /ref input_set function and set value "0" or with /ref input_ack_action with argument /ref INPUT_ACT_LONG_PRESS

INPUT_DAT_DOUBLE_PRESS 

input double press status read status with input_get, clean only the double press status with input_set and value "0" it must be cleaned: with /ref input_set function and set value "0" or with /ref input_ack_action with argument /ref INPUT_ACT_DOUBLE_PRESS

◆ digitalInputHWType

possible input HW types

Enumerator
INPUT_HW_ACTIVE_HIGH 

for inputs that are active if a voltage is applied to the pin (usually with pulldown resistor)

INPUT_HW_ACTIVE_LOW 

for inputs that are activated when pulled to the GND (always with pullup resistor)

◆ digitalInputSWType

possible input SW types

Enumerator
INPUT_SW_ON_OFF_INPUT 

only evaluates logical state and rising/falling edge best used for toggle switches or similar type of input

INPUT_SW_BUTTON 

evaluates state and rising/falling edges and also detects three types of button presses best used for tactile switches (for example for navigating in the display menu)

Function Documentation

◆ input_ack_action()

retStatus input_ack_action ( digInputs  input_name,
digitalInputActions  action 
)

Acknowledge digital input action.

Digital input action digitalInputActions needs to be manually cleared before they are evaluated again.

Parameters
[in]input_nameinput identification, defined by digInputs
[out]actionaction to be cleared
Returns
EOK if the digital_input_init_data value is valid ENODEV if the input_name is out of range defined by digInputs

◆ input_get()

retStatus input_get ( uint32_t  input,
uint16_t  data,
int32_t *  value 
)

Standardized getter function for digital input library.

Parameters
[in]inputis the input name defined by digInputs
[in]datadata for /p input that can be read out of the module, available data digitalInputDateTypes
[out]valuegetter output
Note
/p input and /p data types are changed to uint32_t and uint16_t to keep the standard function prototype
In case you do not need this function footprint you are better of using input_is_short_press(), input_is_long_press() and input_get_action() functions.
Returns
ENODEV if the /p input is not defined or initialized, EINVAL if you are trying to read invalid data and EOK if the /p value contains valid value

◆ input_get_hw_HAL()

__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)

Parameters
[in]input_nameinput identification, defined by digInputs
Returns
GPIO_PinState (from the HAL library)

◆ input_get_init_data()

retStatus input_get_init_data ( digInputs  input_name,
digitalInputInitData digital_input_init_data 
)

Return input initialization data.

In case you want to re-initialize some values but keep the rest as it was

Parameters
[in]input_nameinput identification, defined by digInputs
[out]digital_input_init_datainput initialization data digitalInputInitData
Returns
EOK if the digital_input_init_data value is valid ENODEV if the input_name is out of range defined by digInputs

◆ input_handle()

void input_handle ( void  )

Handles digital input logic. Call every 1ms.

Note
can be called faster or slower but the initialization values are no longer in ms.
Returns
void

◆ input_init()

retStatus input_init ( digInputs  input_name,
digitalInputInitData  digital_input_init_data 
)

Digital input initialization function.

Parameters
[in]input_nameinput identification, defined by digInputs
[in]digital_input_init_datainput initialization data digitalInputInitData
Returns
EOK is the initialization completed OK ENODEV if the input_name is out of range defined by digInputs EINVAL if the digital_input_init_data contains invalid values (check SWO)

◆ input_is_long_press()

uint8_t input_is_long_press ( digInputs  input_name)

Checks if the input detected long press.

Parameters
[in]input_nameinput identification, defined by digInputs
Note
action INPUT_ACT_LONG_PRESS is self-cleaning (action active only if the input is in the long-hold state)
Returns
1 - input is being hold in "active" state that classifies as "long press" 0 - long press not active

◆ input_is_short_press()

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 flag with input_ack_action() or input_set()

Parameters
[in]input_nameinput identification, defined by digInputs
Returns
1 - short press detected 0 - short press not detected

◆ input_logical_state_debounced()

dioStates input_logical_state_debounced ( digInputs  input_name)

Return the input debounced logical state.

Debounced input logical state is evaluated using the initialization data.

Parameters
[in]input_nameinput identification, defined by digInputs
Returns
DIO_OFF - if the logical state of the input is "0" (not active) DIO_ON - if the logical state of the input is "1" (active) ENODEV - if the /p input_name is out of range defined by digInputs

◆ input_set()

retStatus input_set ( uint32_t  input,
uint16_t  data,
int32_t  value 
)

Standardized setter function for digital input library.

Parameters
[in]inputinput identification, defined by digInputs
[in]datadata for /p input that can be read out of the module, available data digitalInputDateTypes
[in]valuevalue to be set

You can not set values that are read from HW or calculated from the HW value: INPUT_DAT_CURR and INPUT_DAT_DEBOUNCED

Note
input and /p data types are changed to uint32_t and uint16_t to keep the standard function prototype
In case you do not need this function footprint you are better of using input_ack_action()
Returns
returns EACCES in case you try setting HW dependent variables, EOVERFLOW if the set value is invalid, EINVAL if invalid data type is passed, ENODEV in case the input is not defined or initialized and EOK if the value was successfully set

◆ input_state_now()

dioStates input_state_now ( digInputs  input_name)

Return the input state read from HW at the moment the function is called.

Parameters
[in]input_nameinput identification, defined by digInputs
Note
the value is not converted to a logical state (you need to consider the INPUT_HW_ACTIVE_HIGH and INPUT_HW_ACTIVE_LOW in your logic *
Returns
DIO_OFF - if the value on HW is "0" DIO_ON - if the value on HW is "1 ENODEV - if the /p input_name is out of range defined by digInputs