static void phy_device_power_enable_via_gpio(bool enable) { assert(DEFAULT_ETHERNET_PHY_CONFIG.phy_power_enable); if (!enable) { DEFAULT_ETHERNET_PHY_CONFIG.phy_power_enable(false); } gpio_pad_select_gpio(PIN_PHY_POWER); gpio_set_direction(PIN_PHY_POWER, GPIO_MODE_OUTPUT); if (enable == true) { gpio_set_level(PIN_PHY_POWER, 1); ESP_LOGI(__func__, "Power On Ethernet PHY"); } else { gpio_set_level(PIN_PHY_POWER, 0); ESP_LOGI(__func__, "Power Off Ethernet PHY"); } vTaskDelay(1); // Allow the power up/down to take effect, min 300us if (enable) { /* call the default PHY-specific power on function */ DEFAULT_ETHERNET_PHY_CONFIG.phy_power_enable(true); } }
/* This replaces the default PHY power on/off function with one that also uses a GPIO for power on/off. If this GPIO is not connected on your device (and PHY is always powered), you can use the default PHY-specific power on/off function rather than overriding with this one. */ static void phy_device_power_enable_via_gpio(bool enable) { assert(DEFAULT_ETHERNET_PHY_CONFIG.phy_power_enable); if (!enable) { /* Do the PHY-specific power_enable(false) function before powering down */ DEFAULT_ETHERNET_PHY_CONFIG.phy_power_enable(false); } gpio_pad_select_gpio(PIN_PHY_POWER); gpio_set_direction(PIN_PHY_POWER,GPIO_MODE_OUTPUT); if(enable == true) { gpio_set_level(PIN_PHY_POWER, 1); ESP_LOGD(TAG, "phy_device_power_enable(TRUE)"); } else { gpio_set_level(PIN_PHY_POWER, 0); ESP_LOGD(TAG, "power_enable(FALSE)"); } // Allow the power up/down to take effect, min 300us vTaskDelay(1); if (enable) { /* Run the PHY-specific power on operations now the PHY has power */ DEFAULT_ETHERNET_PHY_CONFIG.phy_power_enable(true); } }
static int checkOverrideGpio() { #ifdef BOOTWIFI_OVERRIDE_GPIO gpio_pad_select_gpio(BOOTWIFI_OVERRIDE_GPIO); gpio_set_direction(BOOTWIFI_OVERRIDE_GPIO, GPIO_MODE_INPUT); gpio_set_pull_mode(BOOTWIFI_OVERRIDE_GPIO, GPIO_PULLDOWN_ONLY); return gpio_get_level(BOOTWIFI_OVERRIDE_GPIO); #else return 0; // If no boot override, return false #endif } // checkOverrideGpio
void blink_task(void *pvParameter) { //短脚设置 gpio_pad_select_gpio(BLINK_GPIO); //设置为输出 gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); while(1) { //设置低电平 gpio_set_level(BLINK_GPIO, 0); //延时1s vTaskDelay(1000 / portTICK_PERIOD_MS); //设置高电平 gpio_set_level(BLINK_GPIO, 1); //延时1s vTaskDelay(1000 / portTICK_PERIOD_MS); } }
esp_comm_gpio_hold_t bootloader_common_check_long_hold_gpio(uint32_t num_pin, uint32_t delay_sec) { gpio_pad_select_gpio(num_pin); if (GPIO_PIN_MUX_REG[num_pin]) { PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[num_pin]); } gpio_pad_pullup(num_pin); uint32_t tm_start = esp_log_early_timestamp(); if (GPIO_INPUT_GET(num_pin) == 1) { return GPIO_NOT_HOLD; } do { if (GPIO_INPUT_GET(num_pin) != 0) { return GPIO_SHORT_HOLD; } } while (delay_sec > ((esp_log_early_timestamp() - tm_start) / 1000L)); return GPIO_LONG_HOLD; }
void blink_task(void *pvParameter) { /* Configure the IOMUX register for pad BLINK_GPIO (some pads are muxed to GPIO on reset already, but some default to other functions and need to be switched to GPIO. Consult the Technical Reference for a list of pads and their default functions.) */ gpio_pad_select_gpio(BLINK_GPIO); /* Set the GPIO as a push/pull output */ gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); while(1) { /* Blink off (output low) */ gpio_set_level(BLINK_GPIO, 0); vTaskDelay(1000 / portTICK_PERIOD_MS); /* Blink on (output high) */ gpio_set_level(BLINK_GPIO, 1); vTaskDelay(1000 / portTICK_PERIOD_MS); } }