From af8ca546f99e9b5096fa28709b5fcfdb86955a67 Mon Sep 17 00:00:00 2001 From: muhaidong Date: Wed, 25 Sep 2024 11:38:39 +0800 Subject: [PATCH] feat(phy): add gpio cmd for cert test --- examples/phy/cert_test/main/cmd_phy.c | 72 +++++++++++++++++++++++++++ examples/phy/cert_test/main/cmd_phy.h | 6 +++ 2 files changed, 78 insertions(+) diff --git a/examples/phy/cert_test/main/cmd_phy.c b/examples/phy/cert_test/main/cmd_phy.c index 6ed7dd0cf6..a1cda33955 100644 --- a/examples/phy/cert_test/main/cmd_phy.c +++ b/examples/phy/cert_test/main/cmd_phy.c @@ -13,6 +13,8 @@ #include "esp_phy_cert_test.h" #include "cmd_phy.h" +#include "driver/gpio.h" + #define TAG "cmd_phy" #define CERT_TASK_PRIO 2 @@ -30,6 +32,7 @@ static phy_ble_tx_t phy_ble_tx_args; static phy_ble_rx_t phy_ble_rx_args; static phy_bt_tx_tone_t phy_bt_tx_tone_args; #endif +static phy_gpio_output_set_t phy_gpio_output_set_args; #if CONFIG_ESP_PHY_LEGACY_COMMANDS #define arg_int0(_a, _b, _c, _d) arg_int0(NULL, NULL, _c, _d) @@ -396,6 +399,63 @@ static int esp_phy_bt_tx_tone_func(int argc, char **argv) } #endif +void esp_phy_gpio_output_set(int number, int level) { + if (!GPIO_IS_VALID_OUTPUT_GPIO(number)) { + ESP_LOGE(TAG, "gpio number %d is invalid out gpio", number); + return; + } + if (level != 0 && level != 1) { + ESP_LOGE(TAG, "gpio level %d is invalid, should be 0 or 1", level); + return; + } + + gpio_config_t io_conf = {}; + //disable interrupt + io_conf.intr_type = GPIO_INTR_DISABLE; + //set as output mode + io_conf.mode = GPIO_MODE_OUTPUT; + //bit mask of the pin that you want to set,e.g.GPIO18/19 + io_conf.pin_bit_mask = (1ULL<count == 1) { + number = phy_gpio_output_set_args.gpio_number->ival[0]; + } else { + ESP_LOGE(TAG, "please input gpio number"); + return 1; + } + + if (phy_gpio_output_set_args.gpio_level->count == 1) { + level = phy_gpio_output_set_args.gpio_level->ival[0]; + } else { + ESP_LOGE(TAG, "please input gpio level"); + return 1; + } + + esp_phy_gpio_output_set(number, level); + + return 0; +} + void register_phy_cmd(void) { phy_args.enable = arg_int0(NULL, NULL, "", "enable"); @@ -538,5 +598,17 @@ void register_phy_cmd(void) }; ESP_ERROR_CHECK( esp_console_cmd_register(&bt_tx_tone_cmd) ); #endif + phy_gpio_output_set_args.gpio_number = arg_int0("n", "number" , "" , "output gpio number"); + phy_gpio_output_set_args.gpio_level = arg_int0("l", "level", "", "output gpio level"); + phy_gpio_output_set_args.end = arg_end(1); + + const esp_console_cmd_t gpio_output_set_cmd = { + .command = "gpio_output_set", + .help = "gpio output set command", + .hint = NULL, + .func = &esp_phy_gpio_output_set_func, + .argtable = &phy_gpio_output_set_args + }; + ESP_ERROR_CHECK( esp_console_cmd_register(&gpio_output_set_cmd) ); } #endif diff --git a/examples/phy/cert_test/main/cmd_phy.h b/examples/phy/cert_test/main/cmd_phy.h index 9f05f65d04..2fb178ca33 100644 --- a/examples/phy/cert_test/main/cmd_phy.h +++ b/examples/phy/cert_test/main/cmd_phy.h @@ -98,6 +98,12 @@ typedef struct { } phy_ble_rx_s; #endif +typedef struct { + struct arg_int *gpio_number; + struct arg_int *gpio_level; + struct arg_end *end; +} phy_gpio_output_set_t; + void register_phy_cmd(void); #ifdef __cplusplus