1313#include "esp_phy_cert_test.h"
1414#include "cmd_phy.h"
1515
16+ #include "driver/gpio.h"
17+
1618#define TAG "cmd_phy"
1719
1820#define CERT_TASK_PRIO 2
@@ -30,6 +32,7 @@ static phy_ble_tx_t phy_ble_tx_args;
3032static phy_ble_rx_t phy_ble_rx_args ;
3133static phy_bt_tx_tone_t phy_bt_tx_tone_args ;
3234#endif
35+ static phy_gpio_output_set_t phy_gpio_output_set_args ;
3336
3437#if CONFIG_ESP_PHY_LEGACY_COMMANDS
3538#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)
396399}
397400#endif
398401
402+ void esp_phy_gpio_output_set (int number , int level ) {
403+ if (!GPIO_IS_VALID_OUTPUT_GPIO (number )) {
404+ ESP_LOGE (TAG , "gpio number %d is invalid out gpio" , number );
405+ return ;
406+ }
407+ if (level != 0 && level != 1 ) {
408+ ESP_LOGE (TAG , "gpio level %d is invalid, should be 0 or 1" , level );
409+ return ;
410+ }
411+
412+ gpio_config_t io_conf = {};
413+ //disable interrupt
414+ io_conf .intr_type = GPIO_INTR_DISABLE ;
415+ //set as output mode
416+ io_conf .mode = GPIO_MODE_OUTPUT ;
417+ //bit mask of the pin that you want to set,e.g.GPIO18/19
418+ io_conf .pin_bit_mask = (1ULL <<number );
419+ //disable pull-down mode
420+ io_conf .pull_down_en = 0 ;
421+ //disable pull-up mode
422+ io_conf .pull_up_en = 0 ;
423+ //configure GPIO with the given settings
424+ gpio_config (& io_conf );
425+
426+ ESP_LOGI (TAG , "Set output gpio number %d level to %d" , number , level );
427+ gpio_set_level (number , level );
428+ }
429+
430+ static int esp_phy_gpio_output_set_func (int argc , char * * argv )
431+ {
432+ uint8_t number ;
433+ uint8_t level ;
434+ int nerrors = arg_parse (argc , argv , (void * * ) & phy_gpio_output_set_args );
435+ if (nerrors != 0 ) {
436+ arg_print_errors (stderr , phy_gpio_output_set_args .end , argv [0 ]);
437+ return 1 ;
438+ }
439+
440+ if (phy_gpio_output_set_args .gpio_number -> count == 1 ) {
441+ number = phy_gpio_output_set_args .gpio_number -> ival [0 ];
442+ } else {
443+ ESP_LOGE (TAG , "please input gpio number" );
444+ return 1 ;
445+ }
446+
447+ if (phy_gpio_output_set_args .gpio_level -> count == 1 ) {
448+ level = phy_gpio_output_set_args .gpio_level -> ival [0 ];
449+ } else {
450+ ESP_LOGE (TAG , "please input gpio level" );
451+ return 1 ;
452+ }
453+
454+ esp_phy_gpio_output_set (number , level );
455+
456+ return 0 ;
457+ }
458+
399459void register_phy_cmd (void )
400460{
401461 phy_args .enable = arg_int0 (NULL , NULL , "<enable>" , "enable" );
@@ -538,5 +598,17 @@ void register_phy_cmd(void)
538598 };
539599 ESP_ERROR_CHECK ( esp_console_cmd_register (& bt_tx_tone_cmd ) );
540600#endif
601+ phy_gpio_output_set_args .gpio_number = arg_int0 ("n" , "number" , "<gpio_number>" , "output gpio number" );
602+ phy_gpio_output_set_args .gpio_level = arg_int0 ("l" , "level" , "<gpio_level>" , "output gpio level" );
603+ phy_gpio_output_set_args .end = arg_end (1 );
604+
605+ const esp_console_cmd_t gpio_output_set_cmd = {
606+ .command = "gpio_output_set" ,
607+ .help = "gpio output set command" ,
608+ .hint = NULL ,
609+ .func = & esp_phy_gpio_output_set_func ,
610+ .argtable = & phy_gpio_output_set_args
611+ };
612+ ESP_ERROR_CHECK ( esp_console_cmd_register (& gpio_output_set_cmd ) );
541613}
542614#endif
0 commit comments