代码如下:
1 /* Blink Example 2 3 This example code is in the Public Domain (or CC0 licensed, at your option.) 4 5 Unless required by applicable law or agreed to in writing, this 6 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 CONDITIONS OF ANY KIND, either express or implied. 8 */ 9 #include <stdio.h> 10 #include "freertos/FreeRTOS.h" 11 #include "freertos/task.h" 12 #include "driver/gpio.h" 13 #include "sdkconfig.h" 14 15 /* Can run 'make menuconfig' to choose the GPIO to blink, 16 or you can edit the following line and set a number here. 17 */ 18 #define LED_GPIO CONFIG_LED_GPIO 19 20 void blink_task(void *pvParameter) 21 { 22 /* Configure the IOMUX register for pad LED_GPIO (some pads are 23 muxed to GPIO on reset already, but some default to other 24 functions and need to be switched to GPIO. Consult the 25 Technical Reference for a list of pads and their default 26 functions.) 27 */ 28 gpio_pad_select_gpio(LED_GPIO); 29 /* Set the GPIO as a push/pull output */ 30 gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT); 31 while(1) { 32 /* Blink off (output low) */ 33 gpio_set_level(LED_GPIO, 0); 34 vTaskDelay(1000 / portTICK_PERIOD_MS); 35 /* Blink on (output high) */ 36 gpio_set_level(LED_GPIO, 1); 37 vTaskDelay(1000 / portTICK_PERIOD_MS); 38 } 39 } 40 41 void app_main() 42 { 43 xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL); 44 }
案例使用了make menuconfig菜单来进行led IO口定义。