-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f7b82d
commit 2d519de
Showing
28 changed files
with
1,632 additions
and
22 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
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
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
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
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,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}) |
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,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=*" | ||
``` |
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,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.*" |
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,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 |
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,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 |
Oops, something went wrong.