Updated libraries (button and audio player) (#16)
This PR updates two dependency libraries to their latest versions: ## espressif/button: v3.5.0 to v4.1.5 [Version 4](https://components.espressif.com/components/espressif/button/versions/4.1.5/changelog?language=en) changed the API. This code makes use of the new API, with no change to the existing behavior. ## chmorgan/esp-audio-player: v1.0.7 to v1.1.0 [Version 1.1.0](https://github.com/chmorgan/esp-audio-player/releases/tag/v1.1.0) introduces the possibility of multiple simultaneous audio streams. This feature is as yet unused by KTag. Co-authored-by: Joe Kearney <joe@clubk.club> Reviewed-on: #16
This commit is contained in:
parent
d86c494d45
commit
89166c8a02
101 changed files with 5845 additions and 2391 deletions
|
|
@ -1,59 +1,88 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "button_matrix.h"
|
||||
#include "button_interface.h"
|
||||
|
||||
static const char *TAG = "matrix button";
|
||||
static const char *TAG = "matrix_button";
|
||||
|
||||
#define MATRIX_BTN_CHECK(a, str, ret_val) \
|
||||
if (!(a)) \
|
||||
{ \
|
||||
ESP_LOGE(TAG, "%s(%d): %s", __FUNCTION__, __LINE__, str); \
|
||||
return (ret_val); \
|
||||
}
|
||||
typedef struct {
|
||||
button_driver_t base; /**< base button driver */
|
||||
int32_t row_gpio_num; /**< row gpio */
|
||||
int32_t col_gpio_num; /**< col gpio */
|
||||
} button_matrix_obj;
|
||||
|
||||
esp_err_t button_matrix_init(const button_matrix_config_t *config)
|
||||
static esp_err_t button_matrix_gpio_init(int32_t gpio_num, gpio_mode_t mode)
|
||||
{
|
||||
MATRIX_BTN_CHECK(NULL != config, "Pointer of config is invalid", ESP_ERR_INVALID_ARG);
|
||||
MATRIX_BTN_CHECK(GPIO_IS_VALID_GPIO(config->row_gpio_num), "row GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
MATRIX_BTN_CHECK(GPIO_IS_VALID_GPIO(config->col_gpio_num), "col GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
// set row gpio as output
|
||||
ESP_RETURN_ON_FALSE(GPIO_IS_VALID_GPIO(gpio_num), ESP_ERR_INVALID_ARG, TAG, "gpio_num error");
|
||||
gpio_config_t gpio_conf = {0};
|
||||
gpio_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
gpio_conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
|
||||
gpio_conf.pin_bit_mask = (1ULL << config->row_gpio_num);
|
||||
gpio_conf.pin_bit_mask = (1ULL << gpio_num);
|
||||
gpio_conf.mode = mode;
|
||||
gpio_config(&gpio_conf);
|
||||
|
||||
// set col gpio as input
|
||||
gpio_conf.mode = GPIO_MODE_INPUT;
|
||||
gpio_conf.pin_bit_mask = (1ULL << config->col_gpio_num);
|
||||
gpio_config(&gpio_conf);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t button_matrix_deinit(int row_gpio_num, int col_gpio_num)
|
||||
esp_err_t button_matrix_del(button_driver_t *button_driver)
|
||||
{
|
||||
button_matrix_obj *matrix_btn = __containerof(button_driver, button_matrix_obj, base);
|
||||
//Reset an gpio to default state (select gpio function, enable pullup and disable input and output).
|
||||
gpio_reset_pin(row_gpio_num);
|
||||
gpio_reset_pin(col_gpio_num);
|
||||
gpio_reset_pin(matrix_btn->row_gpio_num);
|
||||
gpio_reset_pin(matrix_btn->col_gpio_num);
|
||||
free(matrix_btn);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint8_t button_matrix_get_key_level(void *hardware_data)
|
||||
uint8_t button_matrix_get_key_level(button_driver_t *button_driver)
|
||||
{
|
||||
uint32_t row = MATRIX_BUTTON_SPLIT_ROW(hardware_data);
|
||||
uint32_t col = MATRIX_BUTTON_SPLIT_COL(hardware_data);
|
||||
gpio_set_level(row, 1);
|
||||
uint8_t level = gpio_get_level(col);
|
||||
gpio_set_level(row, 0);
|
||||
|
||||
button_matrix_obj *matrix_btn = __containerof(button_driver, button_matrix_obj, base);
|
||||
gpio_set_level(matrix_btn->row_gpio_num, 1);
|
||||
uint8_t level = gpio_get_level(matrix_btn->col_gpio_num);
|
||||
gpio_set_level(matrix_btn->row_gpio_num, 0);
|
||||
return level;
|
||||
}
|
||||
|
||||
esp_err_t iot_button_new_matrix_device(const button_config_t *button_config, const button_matrix_config_t *matrix_config, button_handle_t *ret_button, size_t *size)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_RETURN_ON_FALSE(button_config && matrix_config && ret_button, ESP_ERR_INVALID_ARG, TAG, "Invalid argument");
|
||||
ESP_RETURN_ON_FALSE(matrix_config->col_gpios && matrix_config->row_gpios, ESP_ERR_INVALID_ARG, TAG, "Invalid matrix config");
|
||||
ESP_RETURN_ON_FALSE(matrix_config->col_gpio_num > 0 && matrix_config->row_gpio_num > 0, ESP_ERR_INVALID_ARG, TAG, "Invalid matrix config");
|
||||
ESP_RETURN_ON_FALSE(*size == matrix_config->row_gpio_num * matrix_config->col_gpio_num, ESP_ERR_INVALID_ARG, TAG, "Invalid size");
|
||||
|
||||
button_matrix_obj *matrix_btn = calloc(*size, sizeof(button_matrix_obj));
|
||||
for (int i = 0; i < matrix_config->row_gpio_num; i++) {
|
||||
button_matrix_gpio_init(matrix_config->row_gpios[i], GPIO_MODE_OUTPUT);
|
||||
}
|
||||
|
||||
for (int i = 0; i < matrix_config->col_gpio_num; i++) {
|
||||
button_matrix_gpio_init(matrix_config->col_gpios[i], GPIO_MODE_INPUT);
|
||||
}
|
||||
|
||||
for (int i = 0; i < *size; i++) {
|
||||
matrix_btn[i].base.get_key_level = button_matrix_get_key_level;
|
||||
matrix_btn[i].base.del = button_matrix_del;
|
||||
matrix_btn[i].row_gpio_num = matrix_config->row_gpios[i / matrix_config->col_gpio_num];
|
||||
matrix_btn[i].col_gpio_num = matrix_config->col_gpios[i % matrix_config->col_gpio_num];
|
||||
ESP_LOGD(TAG, "row_gpio_num: %"PRId32", col_gpio_num: %"PRId32"", matrix_btn[i].row_gpio_num, matrix_btn[i].col_gpio_num);
|
||||
ret = iot_button_create(button_config, &matrix_btn[i].base, &ret_button[i]);
|
||||
ESP_GOTO_ON_FALSE(ret == ESP_OK, ESP_FAIL, err, TAG, "Create button failed");
|
||||
}
|
||||
*size = matrix_config->row_gpio_num * matrix_config->col_gpio_num;
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (matrix_btn) {
|
||||
free(matrix_btn);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue