mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
Add very simple "hello world" & "blink" examples
This commit is contained in:
parent
de76546227
commit
6850751ee8
9
examples/01_hello_world/Makefile
Normal file
9
examples/01_hello_world/Makefile
Normal file
@ -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
|
||||
|
5
examples/01_hello_world/README.md
Normal file
5
examples/01_hello_world/README.md
Normal file
@ -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.
|
32
examples/01_hello_world/main/hello_world_main.c
Normal file
32
examples/01_hello_world/main/hello_world_main.c
Normal file
@ -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 <stdio.h>
|
||||
#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);
|
||||
}
|
9
examples/02_blink/Makefile
Normal file
9
examples/02_blink/Makefile
Normal file
@ -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
|
||||
|
5
examples/02_blink/README.md
Normal file
5
examples/02_blink/README.md
Normal file
@ -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.
|
14
examples/02_blink/main/Kconfig.projbuild
Normal file
14
examples/02_blink/main/Kconfig.projbuild
Normal file
@ -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
|
48
examples/02_blink/main/blink.c
Normal file
48
examples/02_blink/main/blink.c
Normal file
@ -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 <stdio.h>
|
||||
#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);
|
||||
}
|
10
examples/04_https_request/main/component.mk
Normal file
10
examples/04_https_request/main/component.mk
Normal file
@ -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
|
10
examples/05_ble_adv/main/component.mk
Normal file
10
examples/05_ble_adv/main/component.mk
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user