From: Advaith Menon Date: Sun, 16 Nov 2025 22:57:21 +0000 (-0500) Subject: Update GPIO Input Code, Add Output X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=9a1411e3cfdbb1d9cc0638a9ee6bbba826613156;p=smartwatch.git Update GPIO Input Code, Add Output * Add gpio_reset_pin to change pin modes to GPIO * See https://github.com/espressif/esp-idf/issues/11975 for more info --- diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3aeb4cc..ccd5c61 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,4 +1,4 @@ idf_component_register(SRCS "hello_world_main.c" INCLUDE_DIRS "." - PRIV_REQUIRES spi_flash esp_driver_gpio + PRIV_REQUIRES esp_driver_gpio INCLUDE_DIRS "") diff --git a/main/hello_world_main.c b/main/hello_world_main.c index 08f0329..5017b86 100644 --- a/main/hello_world_main.c +++ b/main/hello_world_main.c @@ -9,9 +9,6 @@ #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "esp_chip_info.h" -#include "esp_flash.h" -#include "esp_system.h" #include "driver/gpio.h" #define BUTTON_WHITE 0 @@ -19,51 +16,37 @@ #define BUTTON_YELLOW 11 #define BUTTON_BLUE 18 #define BUTTON_RED 15 +#define VIBRATOR 20 void app_main(void) { printf("Hello world!\n"); - /* Print chip information */ - esp_chip_info_t chip_info; - uint32_t flash_size; - esp_chip_info(&chip_info); - printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", - CONFIG_IDF_TARGET, - chip_info.cores, - (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "", - (chip_info.features & CHIP_FEATURE_BT) ? "BT" : "", - (chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "", - (chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : ""); - - unsigned major_rev = chip_info.revision / 100; - unsigned minor_rev = chip_info.revision % 100; - printf("silicon revision v%d.%d, ", major_rev, minor_rev); - if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) { - printf("Get flash size failed"); - return; - } - - printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024), - (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); - - printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); - + ESP_ERROR_CHECK(gpio_reset_pin(BUTTON_WHITE)); gpio_set_direction(BUTTON_WHITE, GPIO_MODE_INPUT); gpio_pullup_en(BUTTON_WHITE); + ESP_ERROR_CHECK(gpio_reset_pin(BUTTON_GREEN)); gpio_set_direction(BUTTON_GREEN, GPIO_MODE_INPUT); gpio_pullup_en(BUTTON_GREEN); + ESP_ERROR_CHECK(gpio_reset_pin(BUTTON_YELLOW)); gpio_set_direction(BUTTON_YELLOW, GPIO_MODE_INPUT); gpio_pullup_en(BUTTON_YELLOW); + ESP_ERROR_CHECK(gpio_reset_pin(BUTTON_BLUE)); gpio_set_direction(BUTTON_BLUE, GPIO_MODE_INPUT); gpio_pullup_en(BUTTON_BLUE); + ESP_ERROR_CHECK(gpio_reset_pin(BUTTON_RED)); gpio_set_direction(BUTTON_RED, GPIO_MODE_INPUT); gpio_pullup_en(BUTTON_RED); + ESP_ERROR_CHECK(gpio_reset_pin(VIBRATOR)); + gpio_set_direction(VIBRATOR, GPIO_MODE_OUTPUT); + ESP_ERROR_CHECK(gpio_set_drive_capability(VIBRATOR, GPIO_DRIVE_CAP_2)); + + gpio_dump_io_configuration(stdout, (1ULL << VIBRATOR) | (1ULL << BUTTON_RED)); /* for (int i = 10; i >= 0; i--) { printf("Restarting in %d seconds...\n", i); @@ -74,12 +57,15 @@ void app_main(void) esp_restart(); */ while (1) { + /* printf("Button levels: [%d|%d|%d|%d|%d]\n", gpio_get_level(BUTTON_WHITE), gpio_get_level(BUTTON_GREEN), gpio_get_level(BUTTON_YELLOW), gpio_get_level(BUTTON_BLUE), gpio_get_level(BUTTON_RED)); - vTaskDelay(500 / portTICK_PERIOD_MS); + */ + ESP_ERROR_CHECK(gpio_set_level(VIBRATOR, !gpio_get_level(BUTTON_RED))); + vTaskDelay(100 / portTICK_PERIOD_MS); } }