-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from niwciu/feature_project_refactor
Feature project refactor
- Loading branch information
Showing
159 changed files
with
713 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 niwciu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,160 +1,39 @@ | ||
# PUSHBUTTON_SWITCH_LIB - simple cross platform library | ||
# PUSHBUTTON_SWITCH_LIB - simple cross platform library | ||
|
||
![GitHub License](https://img.shields.io/github/license/niwciu/PUSHBUTTON_SWITCH_LIB) | ||
![GitHub top language](https://img.shields.io/github/languages/top/niwciu/PUSHBUTTON_SWITCH_LIB) | ||
![GitHub Release](https://img.shields.io/github/v/release/niwciu/PUSHBUTTON_SWITCH_LIB) | ||
![GitHub branch check runs](https://img.shields.io/github/check-runs/niwciu/LCD_HD44780/main) | ||
![Unit Tests](https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB/actions/workflows/run_library_unit_test.yml/badge.svg) | ||
![cppcheck](https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB/actions/workflows/run_cppcheck.yml/badge.svg) | ||
![clang-format](https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB/actions/workflows/clang-format_check.yml/badge.svg) | ||
![code complexity](https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB/actions/workflows/run_lizard_lib_check.yml/badge.svg) | ||
|
||
The `PUSHBUTTON_SWITCH_LIB` is a simple cross-platform C library providing interfaces for pushbuttons and two-state switches (two-state input signals). | ||
|
||
## Features | ||
### Push Buttons: | ||
- 3 trigger modes: | ||
- TRIGGER_ON_PUSH | ||
- TRIGGER_ON_RELEASE | ||
- TRIGGER_ON_SHORT_PUSH_AND_LONG_PUSH | ||
- Option to enable repetition | ||
- Fully configurable time slots for: | ||
- debounce time | ||
- time to the first repetition | ||
- time between continuous repetitions | ||
- time defining the difference between short and long push | ||
- Option to dynamically register callbacks for each trigger source | ||
- Driver interface that is fully separated from the driver layer | ||
|
||
### Switches: | ||
- Debounce functionality based on a repeat count of the same state (no timer needed) | ||
- Fully configurable debounce counter | ||
- Dynamically register callbacks for switch ON and OFF states | ||
- Driver interface that is fully separated from the driver layer | ||
|
||
## Examples, how to use library etc. | ||
For more information about usage, examples, colaboration and all features please refer to [project wiki](https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB/wiki) | ||
|
||
The `PUSHBUTTON_SWITCH_LIB` is a simple cross platform library providing interfaces for pushbutton switches and two-state switches (two-state input signals). It includes features such as debouncing, repetition functionality for pushbuttons, and state management for switches. | ||
|
||
## Usage - simplest cases | ||
|
||
### Pushbutton Module | ||
|
||
1. Include the necessary files in your project: | ||
- `pushbutton.h` | ||
- `pushbutton.c` | ||
- `pushbutton_GPIO_interface.h` | ||
- `pushbutton_TIM_interface.h` | ||
|
||
2. Initialize the pushbutton(s) using `init_pushbutton` function. Example: | ||
|
||
```c | ||
PUSHBUTTON_TypDef myButton; | ||
init_pushbutton(&myButton, REPETITION_ON, TRIGGER_ON_PUSH, pushButton_GPIO_interface_get); | ||
``` | ||
|
||
3. Register callbacks for push events: | ||
|
||
```c | ||
register_button_push_callback(&myButton, myPushCallback); | ||
``` | ||
|
||
4. Periodically check the pushbutton state using `check_pushbutton`: | ||
|
||
```c | ||
check_pushbutton(&myButton); | ||
``` | ||
|
||
### Switch Module | ||
|
||
1. Include the necessary files in your project: | ||
- `switch.h` | ||
- `switch.c` | ||
- `switch_GPIO_interface.h` | ||
2. Initialize the switch using `init_switch` function. Example: | ||
|
||
```c | ||
SWITCH_TypDef mySwitch; | ||
init_switch(&mySwitch, switch_ON_callback, switch_OFF_callback, switch_GPIO_interface_get); | ||
``` | ||
|
||
3. Periodically check the switch state using `check_switch`: | ||
|
||
```c | ||
check_switch(&mySwitch); | ||
``` | ||
|
||
4. Implement your callback functions for switch events. | ||
|
||
## Notes | ||
|
||
- Make sure to include the necessary dependencies for GPIO and timer interfaces as per your hardware platform. | ||
- Adjust debounce and repetition settings based on your application requirements. | ||
|
||
## Examples | ||
### STM32G071_NUCLEO_LL_1_KEY_UI | ||
Example of using the library to create a User Interface Keyboard module in the project. The example includes the initialization of one pushbutton keyboard with short-push and long-push with repetition functionality. | ||
- Short-push triggers the LED ON function, | ||
- Long-push triggers the LED TOGGLE function. | ||
#### Requirements for compiling and running the example: | ||
1. CMake installed | ||
2. Make or Ninja installed | ||
3. ARM GNU Toolchain (gcc-arm-none-eabi) installed | ||
4. STM32_Programmer_CLI installed | ||
5. ST-link (placed on Nucleo Board) installed | ||
#### Hardware requirements, configuration, and connections: | ||
1. STM32G071 Nucleo-64<br> | ||
<img src="https://www.st.com/bin/ecommerce/api/image.PF265386.en.feature-description-include-personalized-no-cpn-medium.jpg" width="400"><br> https://www.st.com/en/evaluation-tools/nucleo-g071rb.html <br> | ||
#### How to build and run the example: | ||
1. Open the location you want to clone the repository to in your terminal | ||
2. Clone the repository to your preferred localization | ||
```bash | ||
git clone https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB.git | ||
``` | ||
3. Enter to PUSHBUTTON_SWITCH_LIB/examples/STM32G071_NUCLEO_LL_1_KEY_UI | ||
```bash | ||
cd ./PUSHBUTTON_SWITCH_LIB/examples/STM32G071_NUCLEO_LL_1_KEY_UI | ||
``` | ||
4. For Make type: | ||
```bash | ||
cmake -S ./ -B Debug -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug | ||
``` | ||
```bash | ||
cd Debug | ||
``` | ||
```bash | ||
make all | ||
``` | ||
```bash | ||
make flash | ||
``` | ||
5. For Ninja type: | ||
```bash | ||
cmake -S ./ -B Debug -G"Ninja" -DCMAKE_BUILD_TYPE=Debug | ||
``` | ||
```bash | ||
cd Debug | ||
``` | ||
```bash | ||
ninja | ||
``` | ||
```bash | ||
ninja flash | ||
``` | ||
6. In some cases Nucleo board requires plugging out and in a USB port to run the program. | ||
### STM32G071_NUCLEO_LL_2_STATE_SWITCH | ||
Example of using the library to create an input signals module in the project. The example includes the initialization of one two-state switch that calls functions when transitioning to ON and OFF states. | ||
- ON state triggers the LED ON function, | ||
- OFF state triggers the LED OFF function. | ||
#### Requirements for compiling and running the example: | ||
1. CMake installed | ||
2. Make or Ninja installed | ||
3. ARM GNU Toolchain (gcc-arm-none-eabi) installed | ||
4. STM32_Programmer_CLI installed | ||
5. ST-link (placed on Nucleo Board) installed | ||
#### Hardware requirements, configuration, and connections: | ||
1. STM32G071 Nucleo-64<br> | ||
<img src="https://www.st.com/bin/ecommerce/api/image.PF265386.en.feature-description-include-personalized-no-cpn-medium.jpg" width="400"><br> https://www.st.com/en/evaluation-tools/nucleo-g071rb.html <br> | ||
#### How to build and run the example | ||
1. Open the location you want to clone the repository to in your terminal | ||
2. Clone the repository to your preferred localization | ||
```bash | ||
git clone https://github.com/niwciu/PUSHBUTTON_SWITCH_LIB.git | ||
``` | ||
3. Enter to PUSHBUTTON_SWITCH_LIB/examples/STM32G071_NUCLEO_LL_2_STATE_SWITCH/ | ||
```bash | ||
cd ./PUSHBUTTON_SWITCH_LIB/examples/STM32G071_NUCLEO_LL_2_STATE_SWITCH | ||
``` | ||
4. For Make type: | ||
```bash | ||
cmake -S ./ -B Debug -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug | ||
``` | ||
```bash | ||
cd Debug | ||
``` | ||
```bash | ||
make all | ||
``` | ||
```bash | ||
make flash | ||
``` | ||
5. For Ninja type: | ||
```bash | ||
cmake -S ./ -B Debug -G"Ninja" -DCMAKE_BUILD_TYPE=Debug | ||
``` | ||
```bash | ||
cd Debug | ||
``` | ||
```bash | ||
ninja | ||
``` | ||
```bash | ||
ninja flash | ||
``` | ||
6. In some cases Nucleo board requires plugging out and in a USB port to run the program. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
examples/STM32G071_NUCLEO_LL_1_KEY_UI/Core/Src/UI_KEYPAD/keypad_TIM_interface.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @file keypad_TIM_interface.h | ||
* @author niwciu (niwciu@gmail.com) | ||
* @brief Defines the interface for integrating pushbutton layer with a timer (TIM) module. It's part of this library but in project this file should come | ||
* from Timer implementation layer side where "observer" design patter is implemented. | ||
* @date 2024-03-02 | ||
* @copyright Copyright (c) 2024 | ||
*/ | ||
#ifndef _KEYPAD_TIM_INTERFACE_H_ | ||
#define _KEYPAD_TIM_INTERFACE_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif /* __cplusplus */ | ||
|
||
/** | ||
* @brief Callback function type for 1 ms timer events. | ||
* | ||
* This function type is used for callback functions that are triggered every 1ms by timer events. | ||
*/ | ||
typedef void (*keypad_timers_update_callback_t)(void); | ||
|
||
/** | ||
* @brief Subscribes a callback function to timer events fired with 1ms resolution. | ||
* | ||
* This function allows subscribing a callback function for keypad (all pusbuttons) timers update. | ||
* subscribed callback should be called with time resolution of 1ms. | ||
* | ||
* @param timers_update_callback The callback function to be subscribed. | ||
*/ | ||
void subscribe_keypad_timers_update_callback(keypad_timers_update_callback_t timers_update_callback); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif /* __cplusplus */ | ||
|
||
#endif /* _KEYPAD_TIM_INTERFACE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.