From 6850751ee808acb9d2620259a4519b3d0dd501ba Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 27 Sep 2016 10:30:07 +1000 Subject: [PATCH] Add very simple "hello world" & "blink" examples --- examples/01_hello_world/Makefile | 9 ++++ examples/01_hello_world/README.md | 5 ++ .../main/component.mk | 0 .../01_hello_world/main/hello_world_main.c | 32 +++++++++++++ examples/02_blink/Makefile | 9 ++++ examples/02_blink/README.md | 5 ++ examples/02_blink/main/Kconfig.projbuild | 14 ++++++ examples/02_blink/main/blink.c | 48 +++++++++++++++++++ .../main/component.mk | 0 .../Makefile | 0 .../README.md | 0 .../main/Kconfig.projbuild | 0 .../main/component.mk | 0 .../main/http_request_main.c | 0 .../Makefile | 0 .../README.md | 0 .../main/Kconfig.projbuild | 0 .../main/cert.c | 0 examples/04_https_request/main/component.mk | 10 ++++ .../main/https_request_main.c | 0 examples/{04_ble_adv => 05_ble_adv}/Makefile | 0 .../{04_ble_adv => 05_ble_adv}/README.rst | 0 .../{04_ble_adv => 05_ble_adv}/main/app_bt.c | 0 examples/05_ble_adv/main/component.mk | 10 ++++ .../sdkconfig.defaults | 0 25 files changed, 142 insertions(+) create mode 100644 examples/01_hello_world/Makefile create mode 100644 examples/01_hello_world/README.md rename examples/{02_http_request => 01_hello_world}/main/component.mk (100%) create mode 100644 examples/01_hello_world/main/hello_world_main.c create mode 100644 examples/02_blink/Makefile create mode 100644 examples/02_blink/README.md create mode 100644 examples/02_blink/main/Kconfig.projbuild create mode 100644 examples/02_blink/main/blink.c rename examples/{03_https_request => 02_blink}/main/component.mk (100%) rename examples/{02_http_request => 03_http_request}/Makefile (100%) rename examples/{02_http_request => 03_http_request}/README.md (100%) rename examples/{02_http_request => 03_http_request}/main/Kconfig.projbuild (100%) rename examples/{04_ble_adv => 03_http_request}/main/component.mk (100%) rename examples/{02_http_request => 03_http_request}/main/http_request_main.c (100%) rename examples/{03_https_request => 04_https_request}/Makefile (100%) rename examples/{03_https_request => 04_https_request}/README.md (100%) rename examples/{03_https_request => 04_https_request}/main/Kconfig.projbuild (100%) rename examples/{03_https_request => 04_https_request}/main/cert.c (100%) create mode 100644 examples/04_https_request/main/component.mk rename examples/{03_https_request => 04_https_request}/main/https_request_main.c (100%) rename examples/{04_ble_adv => 05_ble_adv}/Makefile (100%) rename examples/{04_ble_adv => 05_ble_adv}/README.rst (100%) rename examples/{04_ble_adv => 05_ble_adv}/main/app_bt.c (100%) create mode 100644 examples/05_ble_adv/main/component.mk rename examples/{04_ble_adv => 05_ble_adv}/sdkconfig.defaults (100%) diff --git a/examples/01_hello_world/Makefile b/examples/01_hello_world/Makefile new file mode 100644 index 0000000000..0d1f5e687d --- /dev/null +++ b/examples/01_hello_world/Makefile @@ -0,0 +1,9 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := hello-world + +include $(IDF_PATH)/make/project.mk + diff --git a/examples/01_hello_world/README.md b/examples/01_hello_world/README.md new file mode 100644 index 0000000000..4fb3c40c13 --- /dev/null +++ b/examples/01_hello_world/README.md @@ -0,0 +1,5 @@ +# Hello World Example + +Starts a FreeRTOS task to print "Hello World" + +See the README.md file in the upper level 'examples' directory for more information about examples. diff --git a/examples/02_http_request/main/component.mk b/examples/01_hello_world/main/component.mk similarity index 100% rename from examples/02_http_request/main/component.mk rename to examples/01_hello_world/main/component.mk diff --git a/examples/01_hello_world/main/hello_world_main.c b/examples/01_hello_world/main/hello_world_main.c new file mode 100644 index 0000000000..73c048cbe8 --- /dev/null +++ b/examples/01_hello_world/main/hello_world_main.c @@ -0,0 +1,32 @@ +/* Hello World 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 "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "nvs_flash.h" + +void hello_task(void *pvParameter) +{ + printf("Hello world!\n"); + for (int i = 10; i >= 0; i--) { + printf("Restarting in %d seconds...\n", i); + vTaskDelay(1000 / portTICK_RATE_MS); + } + printf("Restarting now.\n"); + fflush(stdout); + system_restart(); +} + +void app_main() +{ + nvs_flash_init(6, 3); + system_init(); + xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL); +} diff --git a/examples/02_blink/Makefile b/examples/02_blink/Makefile new file mode 100644 index 0000000000..6f8b9fabe8 --- /dev/null +++ b/examples/02_blink/Makefile @@ -0,0 +1,9 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := blink + +include $(IDF_PATH)/make/project.mk + diff --git a/examples/02_blink/README.md b/examples/02_blink/README.md new file mode 100644 index 0000000000..10590f623e --- /dev/null +++ b/examples/02_blink/README.md @@ -0,0 +1,5 @@ +# Blink Example + +Starts a FreeRTOS task to blink an LED + +See the README.md file in the upper level 'examples' directory for more information about examples. diff --git a/examples/02_blink/main/Kconfig.projbuild b/examples/02_blink/main/Kconfig.projbuild new file mode 100644 index 0000000000..f44a3df7c3 --- /dev/null +++ b/examples/02_blink/main/Kconfig.projbuild @@ -0,0 +1,14 @@ +menu "Example Configuration" + +config BLINK_GPIO + int "Blink GPIO number" + range 0 34 + default 5 + help + GPIO number (IOxx) to blink on and off. + + Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink. + + GPIOs 35-39 are input-only so cannot be used as outputs. + +endmenu diff --git a/examples/02_blink/main/blink.c b/examples/02_blink/main/blink.c new file mode 100644 index 0000000000..3f12d92671 --- /dev/null +++ b/examples/02_blink/main/blink.c @@ -0,0 +1,48 @@ +/* Blink 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 "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "nvs_flash.h" +#include "driver/gpio.h" +#include "sdkconfig.h" + +/* 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 CONFIG_BLINK_GPIO + +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_RATE_MS); + /* Blink on (output high) */ + gpio_set_level(BLINK_GPIO, 1); + vTaskDelay(1000 / portTICK_RATE_MS); + } +} + +void app_main() +{ + nvs_flash_init(6, 3); + system_init(); + xTaskCreate(&blink_task, "blink_task", 512, NULL, 5, NULL); +} diff --git a/examples/03_https_request/main/component.mk b/examples/02_blink/main/component.mk similarity index 100% rename from examples/03_https_request/main/component.mk rename to examples/02_blink/main/component.mk diff --git a/examples/02_http_request/Makefile b/examples/03_http_request/Makefile similarity index 100% rename from examples/02_http_request/Makefile rename to examples/03_http_request/Makefile diff --git a/examples/02_http_request/README.md b/examples/03_http_request/README.md similarity index 100% rename from examples/02_http_request/README.md rename to examples/03_http_request/README.md diff --git a/examples/02_http_request/main/Kconfig.projbuild b/examples/03_http_request/main/Kconfig.projbuild similarity index 100% rename from examples/02_http_request/main/Kconfig.projbuild rename to examples/03_http_request/main/Kconfig.projbuild diff --git a/examples/04_ble_adv/main/component.mk b/examples/03_http_request/main/component.mk similarity index 100% rename from examples/04_ble_adv/main/component.mk rename to examples/03_http_request/main/component.mk diff --git a/examples/02_http_request/main/http_request_main.c b/examples/03_http_request/main/http_request_main.c similarity index 100% rename from examples/02_http_request/main/http_request_main.c rename to examples/03_http_request/main/http_request_main.c diff --git a/examples/03_https_request/Makefile b/examples/04_https_request/Makefile similarity index 100% rename from examples/03_https_request/Makefile rename to examples/04_https_request/Makefile diff --git a/examples/03_https_request/README.md b/examples/04_https_request/README.md similarity index 100% rename from examples/03_https_request/README.md rename to examples/04_https_request/README.md diff --git a/examples/03_https_request/main/Kconfig.projbuild b/examples/04_https_request/main/Kconfig.projbuild similarity index 100% rename from examples/03_https_request/main/Kconfig.projbuild rename to examples/04_https_request/main/Kconfig.projbuild diff --git a/examples/03_https_request/main/cert.c b/examples/04_https_request/main/cert.c similarity index 100% rename from examples/03_https_request/main/cert.c rename to examples/04_https_request/main/cert.c diff --git a/examples/04_https_request/main/component.mk b/examples/04_https_request/main/component.mk new file mode 100644 index 0000000000..24356f23ed --- /dev/null +++ b/examples/04_https_request/main/component.mk @@ -0,0 +1,10 @@ +# +# Main Makefile. This is basically the same as a component makefile. +# +# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, +# this will take the sources in the src/ directory, compile them and link them into +# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, +# please read the ESP-IDF documents if you need to do this. +# + +include $(IDF_PATH)/make/component_common.mk diff --git a/examples/03_https_request/main/https_request_main.c b/examples/04_https_request/main/https_request_main.c similarity index 100% rename from examples/03_https_request/main/https_request_main.c rename to examples/04_https_request/main/https_request_main.c diff --git a/examples/04_ble_adv/Makefile b/examples/05_ble_adv/Makefile similarity index 100% rename from examples/04_ble_adv/Makefile rename to examples/05_ble_adv/Makefile diff --git a/examples/04_ble_adv/README.rst b/examples/05_ble_adv/README.rst similarity index 100% rename from examples/04_ble_adv/README.rst rename to examples/05_ble_adv/README.rst diff --git a/examples/04_ble_adv/main/app_bt.c b/examples/05_ble_adv/main/app_bt.c similarity index 100% rename from examples/04_ble_adv/main/app_bt.c rename to examples/05_ble_adv/main/app_bt.c diff --git a/examples/05_ble_adv/main/component.mk b/examples/05_ble_adv/main/component.mk new file mode 100644 index 0000000000..24356f23ed --- /dev/null +++ b/examples/05_ble_adv/main/component.mk @@ -0,0 +1,10 @@ +# +# Main Makefile. This is basically the same as a component makefile. +# +# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, +# this will take the sources in the src/ directory, compile them and link them into +# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, +# please read the ESP-IDF documents if you need to do this. +# + +include $(IDF_PATH)/make/component_common.mk diff --git a/examples/04_ble_adv/sdkconfig.defaults b/examples/05_ble_adv/sdkconfig.defaults similarity index 100% rename from examples/04_ble_adv/sdkconfig.defaults rename to examples/05_ble_adv/sdkconfig.defaults