Skip to content

Commit

Permalink
Merge branch 'feat/esp_keyboard' into 'master'
Browse files Browse the repository at this point in the history
feat: Add component esp_keyboard

Closes AEG-1428

See merge request ae_group/esp-iot-solution!972
  • Loading branch information
leeebo committed Apr 26, 2024
2 parents a281955 + 2d519de commit d014b23
Show file tree
Hide file tree
Showing 28 changed files with 1,632 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/upload_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
components/display/lcd_touch/esp_lcd_touch_spd2010;
components/display/lcd_touch/esp_lcd_touch_st7123;
components/elf_loader;
components/keyboard_button;
components/extended_vfs;
components/gprof;
components/ir/ir_learn;
Expand Down
12 changes: 12 additions & 0 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,18 @@ build_components_display_lcd_touch_esp_lcd_touch_st7123_test_apps:
variables:
EXAMPLE_DIR: components/display/lcd_touch/esp_lcd_touch_st7123/test_apps

build_components_keyboard_button_test_apps:
extends:
- .build_examples_template
- .rules:build:components_keyboard_button_test_apps
parallel:
matrix:
- IMAGE: espressif/idf:release-v5.0
- IMAGE: espressif/idf:release-v5.1
- IMAGE: espressif/idf:release-v5.2
variables:
EXAMPLE_DIR: components/keyboard_button/test_apps

build_components_ir_ir_learn_test_apps:
extends:
- .build_examples_template
Expand Down
1 change: 1 addition & 0 deletions .gitlab/ci/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ push_to_github:
image: $CI_DOCKER_REGISTRY/esp32-ci-env
variables:
GIT_STRATEGY: clone
dependencies: []
before_script:
- echo "skip default before_script"
script:
Expand Down
16 changes: 16 additions & 0 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
.patterns-components_display_touch_panel: &patterns-components_display_touch_panel
- "components/display/touch_panel/**/*"

.patterns-components_keyboard_button: &patterns-components_keyboard_button
- "components/keyboard_button/**/*"

.patterns-components_expander_io_expander_mcp23017: &patterns-components_expander_io_expander_mcp23017
- "components/expander/io_expander/mcp23017/**/*"

Expand Down Expand Up @@ -252,6 +255,7 @@
- "components/display/screen/screen_driver.h"
- "components/display/touch_panel/touch_panel.h"
- "components/ir/ir_learn/include/ir_learn.h"
- "components/keyboard_button/include/keyboard_button.h"
- "components/knob/iot_knob.h"
- "components/led/led_indicator/include/led_indicator.h"
- "components/motor/esp_sensorless_bldc_control/control/include/bldc_control.h"
Expand Down Expand Up @@ -1410,6 +1414,18 @@
- <<: *if-dev-push
changes: *patterns-components_display_touch_panel

.rules:build:components_keyboard_button_test_apps:
rules:
- <<: *if-protected
- <<: *if-label-build
- <<: *if-label-target_test
- <<: *if-trigger-job
- <<: *if-dev-push
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_keyboard_button


.rules:build:components_expander_io_expander_mcp23017_test:
rules:
- <<: *if-protected
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The registered components in ESP-IoT-Solution are listed below:
| [esp_lcd_st77922](https://components.espressif.com/components/espressif/esp_lcd_st77922) | [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_st77922/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_st77922)
| [esp_lcd_touch_spd2010](https://components.espressif.com/components/espressif/esp_lcd_touch_spd2010) | [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_touch_spd2010/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_touch_spd2010) |
| [esp_lcd_touch_st7123](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123) | [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123) |
| [keyboard_button](https://components.espressif.com/components/espressif/keyboard_button) | [![Component Registry](https://components.espressif.com/components/espressif/keyboard_button/badge.svg)](https://components.espressif.com/components/espressif/keyboard_button) |
| [esp_simplefoc](https://components.espressif.com/components/espressif/esp_simplefoc) | [![Component Registry](https://components.espressif.com/components/espressif/esp_simplefoc/badge.svg)](https://components.espressif.com/components/espressif/esp_simplefoc) |
| [esp_sensorless_bldc_control](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control) | [![Component Registry](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control/badge.svg)](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control)
| [esp_tinyuf2](https://components.espressif.com/components/espressif/esp_tinyuf2) | [![Component Registry](https://components.espressif.com/components/espressif/esp_tinyuf2/badge.svg)](https://components.espressif.com/components/espressif/esp_tinyuf2) |
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ESP-IoT-Solution 中注册的组件如下:
| [esp_lcd_st77922](https://components.espressif.com/components/espressif/esp_lcd_st77922) | [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_st77922/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_st77922)
| [esp_lcd_touch_spd2010](https://components.espressif.com/components/espressif/esp_lcd_touch_spd2010) | [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_touch_spd2010/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_touch_spd2010) |
| [esp_lcd_touch_st7123](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123) | [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123) |
| [keyboard_button](https://components.espressif.com/components/espressif/keyboard_button) | [![Component Registry](https://components.espressif.com/components/espressif/keyboard_button/badge.svg)](https://components.espressif.com/components/espressif/keyboard_button) |
| [esp_simplefoc](https://components.espressif.com/components/espressif/esp_simplefoc) | [![Component Registry](https://components.espressif.com/components/espressif/esp_simplefoc/badge.svg)](https://components.espressif.com/components/espressif/esp_simplefoc) |
| [esp_sensorless_bldc_control](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control) | [![Component Registry](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control/badge.svg)](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control)
| [esp_tinyuf2](https://components.espressif.com/components/espressif/esp_tinyuf2) | [![Component Registry](https://components.espressif.com/components/espressif/esp_tinyuf2/badge.svg)](https://components.espressif.com/components/espressif/esp_tinyuf2) |
Expand Down
5 changes: 5 additions & 0 deletions components/.build-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ components/motor/esp_sensorless_bldc_control/test_apps/bldc_adc:
components/motor/esp_sensorless_bldc_control/test_apps/bldc_comparer:
disable:
- if: IDF_TARGET in ["esp32c2"]

components/led/lightbulb_driver/test_apps:
enable:
- if: INCLUDE_DEFAULT == 1
Expand Down Expand Up @@ -96,3 +97,7 @@ components/display/lcd_touch/esp_lcd_touch_spd2010/test_apps:
components/display/lcd_touch/esp_lcd_touch_st7123/test_apps:
enable:
- if: INCLUDE_DEFAULT == 1

components/keyboard_button/test_apps:
enable:
- if: INCLUDE_DEFAULT == 1
6 changes: 6 additions & 0 deletions components/keyboard_button/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
idf_component_register(SRC_DIRS "src" "."
INCLUDE_DIRS "include"
REQUIRES driver esp_timer)

include(package_manager)
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
22 changes: 22 additions & 0 deletions components/keyboard_button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[![Component Registry](https://components.espressif.com/components/espressif/keyboard_button/badge.svg)](https://components.espressif.com/components/espressif/keyboard_button)

# Component: Keyboard Button
[Online documentation](https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/keyboard_button.html)

`keyboard_button` is a library for scanning keyboard matrix, supporting the following features:

List of supported events:
* KBD_EVENT_PRESSED
* KBD_EVENT_COMBINATION

* Supports full-key anti-ghosting scanning method.
* Supports efficient key scanning with a scan rate of no less than 1K.
* Supports low-power keyboard scanning.

## Add component to your project

Please use the component manager command `add-dependency` to add the `keyboard_button` to your project's dependency, during the `CMake` step the component will be downloaded automatically

```
idf.py add-dependency "espressif/keyboard_button=*"
```
9 changes: 9 additions & 0 deletions components/keyboard_button/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "0.1.0"
description: Keyboard button driver
url: https://github.com/espressif/esp-iot-solution/tree/master/components/keyboard_button
repository: https://github.com/espressif/esp-iot-solution.git
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/keyboard_button.html
issues: https://github.com/espressif/esp-iot-solution/issues
dependencies:
idf: ">=5.0"
cmake_utilities: "0.*"
151 changes: 151 additions & 0 deletions components/keyboard_button/include/kbd_gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "driver/gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Enumeration defining keyboard GPIO modes
*/
typedef enum {
KBD_GPIO_MODE_OUTPUT = 0,
KBD_GPIO_MODE_INPUT,
} kbd_gpio_mode_t;

typedef struct {
const int *gpios; /*!< Array, contains GPIO numbers */
uint32_t gpio_num; /*!< gpios array size */
kbd_gpio_mode_t gpio_mode; /*!< GPIO mode */
uint32_t active_level; /*!< Active level, only for input mode */
bool enable_power_save; /*!< Enable power save, only for input mode */
} kbd_gpio_config_t;

/**
* @brief Init GPIOs for keyboard
*
* @param config Pointer to kbd_gpio_config_t
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
*/
esp_err_t kbd_gpio_init(const kbd_gpio_config_t *config);

/**
* @brief Deinitialize GPIOs used for keyboard
*
* This function deinitializes the GPIO pins used by the keyboard.
* It is a counterpart of kbd_gpio_init().
*
* @param gpios Pointer to an array of GPIO numbers
* @param gpio_num Number of elements in the gpios array
*/
void kbd_gpio_deinit(const int *gpios, uint32_t gpio_num);

/**
* @brief Read levels of multiple GPIOs
*
* This function reads levels of multiple GPIOs in one call.
*
* @param gpios Pointer to an array of GPIO numbers
* @param gpio_num Number of elements in the gpios array
*
* @return Bitmask of GPIO levels, bit N is set if GPIO N level is high
*/
uint32_t kbd_gpios_read_level(const int *gpios, uint32_t gpio_num);

/**
* Read the level of a GPIO pin.
*
* @param gpio The GPIO pin number to read the level from
*
* @return The level of the GPIO pin (0 or 1)
*/
uint32_t kbd_gpio_read_level(int gpio);

/**
* Set the level of one or more GPIO pins.
*
* @param gpio_num The GPIO pin number to set the level for
* @param level The level to set (0 or 1)
*
* @return esp_err_t The error code indicating success or failure
*/
void kbd_gpios_set_level(const int *gpios, uint32_t gpio_num, uint32_t level);

/**
* Set the level of a GPIO pin.
*
* @param gpio The GPIO pin number to set the level for
* @param level The level to set (0 or 1)
*
* @return esp_err_t The error code indicating success or failure
*/
void kbd_gpio_set_level(int gpio, uint32_t level);

/**
* @brief Enable holding of GPIOs to prevent them from floating
*
* This function enables holding of GPIOs to prevent them from floating.
* It iterates through the array of GPIO pins provided and enables hold
* for each of them.
*
* @param gpios Pointer to an array of GPIO numbers
* @param gpio_num Number of GPIOs in the array
*/
void kbd_gpios_set_hold_en(const int *gpios, uint32_t gpio_num);

/**
* @brief Disable holding of GPIOs to prevent them from being held in reset
*
* This function disables holding of GPIOs to prevent them from being held in reset.
* It iterates through the array of GPIO pins provided and disables hold for each of them.
*
* @param gpios Pointer to an array of GPIO numbers
* @param gpio_num Number of GPIOs in the array
*/
void kbd_gpios_set_hold_dis(const int *gpios, uint32_t gpio_num);

/**
* @brief Set interrupt configuration for multiple GPIOs
*
* This function configures interrupt settings for multiple GPIOs.
* It installs the ISR service if not already installed, then iterates
* through the array of GPIO pins provided and sets the interrupt type
* and ISR handler for each GPIO.
*
* @param gpios Pointer to an array of GPIO numbers
* @param gpio_num Number of GPIOs in the array
* @param intr_type Type of GPIO interrupt (GPIO_INTR_POSEDGE, GPIO_INTR_NEGEDGE, GPIO_INTR_ANYEDGE, GPIO_INTR_HIGH_LEVEL, GPIO_INTR_LOW_LEVEL)
* @param isr_handler ISR handler function pointer
* @param args Pointer to additional arguments for the ISR handler
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t kbd_gpios_set_intr(const int *gpios, uint32_t gpio_num, gpio_int_type_t intr_type, gpio_isr_t isr_handler, void *args);

/**
* @brief Enable or disable GPIO interrupts
*
* This function enables or disables interrupts on the specified GPIOs.
*
* @param gpios Pointer to an array of GPIO numbers
* @param gpio_num Number of elements in the gpios array
* @param enable true to enable interrupts, false to disable
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
*/
esp_err_t kbd_gpios_intr_control(const int *gpios, uint32_t gpio_num, bool enable);

#ifdef __cplusplus
}
#endif
75 changes: 75 additions & 0 deletions components/keyboard_button/include/kbd_gptimer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "driver/gptimer.h"

// 1MHz, 1 tick = 1us
#define GPTIMER_CONFIG_DEFAULT() \
{ \
.clk_src = GPTIMER_CLK_SRC_DEFAULT, \
.direction = GPTIMER_COUNT_UP, \
.resolution_hz = 1 * 1000 * 1000, \
}

#define GPTIMER_ALARM_CONFIG_DEFAULT(count) \
{ \
.reload_count = 0, \
.flags.auto_reload_on_alarm = true, \
.alarm_count = count, \
}

typedef struct {
gptimer_handle_t *gptimer; /*!< Pointer to gptimer handle */
gptimer_event_callbacks_t cbs; /*!< gptimer event callbacks */
void *user_data; /*!< User data */
uint32_t alarm_count_us; /*!< Timer interrupt period */
} kbd_gptimer_config_t;

/**
* @brief Initialize gptime
*
* @param config Configuration for the gptimer
* @return
* ESP_OK on success
* ESP_ERR_INVALID_ARG if the parameter is invalid
*/
esp_err_t kbd_gptimer_init(kbd_gptimer_config_t *config);

/**
* @brief deinitialize gptimer
*
* @param gptimer gptimer handle
* @return
* ESP_ERR_INVALID_ARG if parameter is invalid
* ESP_OK if success
*/
esp_err_t kbd_gptimer_deinit(gptimer_handle_t gptimer);

/**
* @brief Stop the gptimer.
*
* @param gptimer gptimer handle
* @return ESP_OK if success
*/
esp_err_t kbd_gptimer_stop(gptimer_handle_t gptimer);

/**
* @brief Start the gptimer.
*
* @param gptimer gptimer handle
* @return ESP_OK if success
*/
esp_err_t kbd_gptimer_start(gptimer_handle_t gptimer);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit d014b23

Please sign in to comment.