diff --git a/examples/espidf-arduino-blink/platformio.ini b/examples/espidf-arduino-blink/platformio.ini index 5049a0e..eca15ea 100644 --- a/examples/espidf-arduino-blink/platformio.ini +++ b/examples/espidf-arduino-blink/platformio.ini @@ -12,9 +12,13 @@ platform = espressif32 framework = arduino, espidf board = esp32dev monitor_speed = 115200 +build_flags= + -D CONFIG_BLINK_GPIO=2 [env:esp wrover kit] platform = espressif32 framework = arduino, espidf board = esp-wrover-kit -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 +build_flags= + -D CONFIG_BLINK_GPIO=2 diff --git a/examples/espidf-arduino-blink/src/main.cpp b/examples/espidf-arduino-blink/src/main.cpp index 8768c66..771ad74 100644 --- a/examples/espidf-arduino-blink/src/main.cpp +++ b/examples/espidf-arduino-blink/src/main.cpp @@ -5,16 +5,64 @@ CONDITIONS OF ANY KIND, either express or implied. */ +#include +#include +#include +#include +#include "sdkconfig.h" #include +/* Can run 'make menuconfig' to choose the GPIO to blink, + or you can edit the following line and set a number here. +*/ #define BLINK_GPIO (gpio_num_t)CONFIG_BLINK_GPIO #ifndef LED_BUILTIN #define LED_BUILTIN 4 #endif +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); + } +} + +#if !CONFIG_AUTOSTART_ARDUINO +void arduinoTask(void *pvParameter) { + pinMode(LED_BUILTIN, OUTPUT); + while(1) { + digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); + delay(1000); + } +} + +void app_main() +{ + // initialize arduino library before we start the tasks + initArduino(); + + xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL); + xTaskCreate(&arduinoTask, "arduino_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL); +} +#else void setup() { Serial.begin(115200); + xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL); pinMode(LED_BUILTIN, OUTPUT); } void loop() { @@ -22,3 +70,4 @@ void loop() { Serial.println("Hello!"); delay(1000); } +#endif \ No newline at end of file diff --git a/examples/espidf-arduino-wifiscan/src/main.cpp b/examples/espidf-arduino-wifiscan/src/main.cpp index ccaa8d1..3caa3b9 100644 --- a/examples/espidf-arduino-wifiscan/src/main.cpp +++ b/examples/espidf-arduino-wifiscan/src/main.cpp @@ -1,3 +1,13 @@ +/* WiFi scan Example + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include +#include +#include "sdkconfig.h" #include #include @@ -25,15 +35,41 @@ void wifiScan() { Serial.println(""); } -void setup() { +#if !CONFIG_AUTOSTART_ARDUINO +void arduinoTask(void *pvParameter) { // Set WiFi to station mode and disconnect from an AP if it was previously connected - Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.disconnect(); + Serial.begin(115200); + delay(100); + + while(1) { + wifiScan(); + + // Wait a bit before scanning again + delay(5000); + } +} + +void app_main() +{ + // initialize arduino library before we start the tasks + initArduino(); + + xTaskCreate(&arduinoTask, "arduino_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL); +} +#else +void setup() { + // Set WiFi to station mode and disconnect from an AP if it was previously connected + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + Serial.begin(115200); delay(100); } void loop() { wifiScan(); + // Wait a bit before scanning again delay(5000); -} +} +#endif