A AVR helper for working with individual buttons.
More...
#include <string.h>
#include <stdint.h>
#include <util/atomic.h>
#include <sls-avr/avr.h>
Go to the source code of this file.
A AVR helper for working with individual buttons.
- Author
- Simon Litt simon.nosp@m.@1it.nosp@m.t.net https://coding.1itt.net, https://github.com/SimonLitt
- Copyright
- GNU General Public License v3.0
...
void init_buttons(void) {
}
void buttons_loop(void) {
on_click1();
}
on_click2();
}
}
...
#define PIN_TO_READ
Definition gpio.h:497
#define PIN_READ(_p, _b)
Definition gpio.h:464
byte_t state
Stages and states flags of click processing.
Definition button.h:163
◆ BTN_ALLOW_LONG
Allows long pressed status.
◆ BTN_ATOMIC_FUNCTIONS
| #define BTN_ATOMIC_FUNCTIONS 0 |
Allow ATOMIC_BLOCK wrappers for button processing.
◆ BTN_DOWN_COUNT
| #define BTN_DOWN_COUNT 3U |
The number that is compared to the counter of inputs to the btn_proc function in the pressed state 1-254. When the set value is reached, the button can receive the pressed status.
◆ BTN_FAST_SOME_CODE
| #define BTN_FAST_SOME_CODE 0 |
If enabled then in the btn_reset function, instead of resetting, only the processing flag is set.
◆ BTN_INFO_STATE_DEFAULT
| #define BTN_INFO_STATE_DEFAULT 0 |
◆ BTN_INFO_STRUCT_DEFAULT
◆ btn_is_clicked
| #define btn_is_clicked |
( |
| _state | ) |
|
Value:
#define flag_is_set(_val, _b)
Test whether bit _b in flags _val is set.
Definition defs.h:141
Tests normal click.
- Parameters
-
| _state | Stages of click processing |
- Returns
- Is clicked
◆ btn_is_holded
| #define btn_is_holded |
( |
| _state | ) |
|
Value:((_state) & (__BTN_IS_HOLDED))
Is button holded.
- Parameters
-
| _state | Stages of click processing |
- Returns
- Is holded
◆ btn_is_long_clicked
| #define btn_is_long_clicked |
( |
| _state | ) |
|
Tests long click.
- Parameters
-
| _state | Stages of click processing |
- Returns
- Is long clicked
◆ btn_is_ready
| #define btn_is_ready |
( |
| _state | ) |
|
Value:((_state) & (__BTN_IS_CLICKED))
Completed but unprocessed click.
- Parameters
-
| _state | Stages of click processing |
- Returns
- Is clicked
◆ BTN_LONG_COUNT
| #define BTN_LONG_COUNT 40U |
The number that is compared to the counter of inputs to the btn_proc function in the pressed state 2-254. When the set value is reached, the button can receive the long pressed status.
◆ BTN_MAX_SCAN_COUNT
| #define BTN_MAX_SCAN_COUNT 254U |
Limit on the number of cycles for which a press is considered complete.
◆ BTN_RESET_UNUSED_COUNT
| #define BTN_RESET_UNUSED_COUNT 0 |
The number that is compared to the counter of unused click 0-254. When the set value is reached, the btn_info_struct structure is reset to its default state.
◆ btn_set_processed
| #define btn_set_processed |
( |
| _state | ) |
|
Value:((_state) = ((_state) & ~(__BTN_IS_CLICKED)) | _BTN_STAGE_PROCESSED)
Is the button taken into account.
It is necessary so that when released, the status does not change to clicked. Used when the button can be a macro button(function modifier).
- Parameters
-
| _state | Stages of click processing |
◆ BTN_UP_COUNT
The number that is compared to the counter of inputs to the btn_proc function in the unpressed state 0-254. When the set value is reached, the button takes on the triggered status.
◆ btn_info_t
◆ btn_get_info()
Actions before events proc.
- Parameters
-
| [out] | btn_info | Information about a button. |
- Returns
- Currently copy of btn_info_struct
◆ btn_get_info_fegi()
Such as the btn_get_info, but with force enabling ot the global interrupts.
- Parameters
-
| [out] | btn_info | Information about a button. |
◆ btn_proc()
| void btn_proc |
( |
btn_info_t *const | btn_info, |
|
|
const bool | is_now_hold ) |
Update counters and button press stages for a button information structure.
If not called from an interrupt, or if other interrupts are enabled in the interrupt, then it should be executed atomically.
- Parameters
-
| [out] | btn_info | Information about a button. |
| [in] | is_now_hold | Is the button currently pressed? |
◆ btn_proc_atomic()
| static void btn_proc_atomic |
( |
btn_info_t *const | btn_info, |
|
|
const bool | is_now_hold ) |
|
inlinestatic |
Such as the btn_proc, but executed atomically.
- Parameters
-
| [out] | btn_info | Information about a button. |
| [in] | is_now_hold | Is the button currently pressed? |
◆ btn_proc_atomic_fegi()
| static void btn_proc_atomic_fegi |
( |
btn_info_t *const | btn_info, |
|
|
const bool | is_now_hold ) |
|
inlinestatic |
Such as the btn_proc, but executed atomically with force enabling ot the global interrupts.
- Parameters
-
| [out] | btn_info | Information about a button. |
| [in] | is_now_hold | Is the button currently pressed? |
◆ btn_reset()
| static void btn_reset |
( |
btn_info_t *const | btn_info | ) |
|
|
inlinestatic |
Resets the button state to default.
- Parameters
-
| [out] | btn_info | Information about a button. |
◆ btn_reset_atomic()
| static void btn_reset_atomic |
( |
btn_info_t *const | btn_info | ) |
|
|
inlinestatic |
Such as the btn_reset, but executed atomically.
- Parameters
-
| [out] | btn_info | Information about a button. |
◆ btn_reset_atomic_fegi()
| static void btn_reset_atomic_fegi |
( |
btn_info_t *const | btn_info | ) |
|
|
inlinestatic |
Such as the btn_reset, but executed atomically with force enabling ot the global interrupts.
- Parameters
-
| [out] | btn_info | Information about a button. |