2015-06-05 01:46:25 +00:00
|
|
|
/* The classic "blink" example
|
|
|
|
*
|
|
|
|
* This sample code is in the public domain.
|
|
|
|
*/
|
2016-06-29 23:22:17 +00:00
|
|
|
#include <stdlib.h>
|
2015-06-05 01:46:25 +00:00
|
|
|
#include "espressif/esp_common.h"
|
2015-10-06 12:04:19 +00:00
|
|
|
#include "esp/uart.h"
|
2015-06-05 01:46:25 +00:00
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "esp8266.h"
|
|
|
|
|
2016-02-08 23:58:56 +00:00
|
|
|
const int gpio = 2;
|
2015-06-05 01:46:25 +00:00
|
|
|
|
|
|
|
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void blinkenTask(void *pvParameters)
|
|
|
|
{
|
|
|
|
gpio_enable(gpio, GPIO_OUTPUT);
|
|
|
|
while(1) {
|
2015-06-08 23:00:32 +00:00
|
|
|
gpio_write(gpio, 1);
|
|
|
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
|
|
|
gpio_write(gpio, 0);
|
|
|
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
2015-06-05 01:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-28 07:01:03 +00:00
|
|
|
/* This task demonstrates an alternative way to use raw register
|
|
|
|
operations to blink an LED.
|
2015-06-05 01:46:25 +00:00
|
|
|
|
2015-11-28 07:01:03 +00:00
|
|
|
The step that sets the iomux register can't be automatically
|
|
|
|
updated from the 'gpio' constant variable, so you need to change
|
2016-02-08 23:58:56 +00:00
|
|
|
the line that sets IOMUX_GPIO2 if you change 'gpio'.
|
2015-06-05 01:46:25 +00:00
|
|
|
|
2015-06-08 08:09:06 +00:00
|
|
|
There is no significant performance benefit to this way over the
|
|
|
|
blinkenTask version, so it's probably better to use the blinkenTask
|
|
|
|
version.
|
2015-06-05 01:46:25 +00:00
|
|
|
|
|
|
|
NOTE: This task isn't enabled by default, see the commented out line in user_init.
|
|
|
|
*/
|
|
|
|
void blinkenRegisterTask(void *pvParameters)
|
|
|
|
{
|
2015-08-19 05:46:25 +00:00
|
|
|
GPIO.ENABLE_OUT_SET = BIT(gpio);
|
2016-02-08 23:58:56 +00:00
|
|
|
IOMUX_GPIO2 = IOMUX_GPIO2_FUNC_GPIO | IOMUX_PIN_OUTPUT_ENABLE; /* change this line if you change 'gpio' */
|
2015-06-05 01:46:25 +00:00
|
|
|
while(1) {
|
2015-08-19 05:46:25 +00:00
|
|
|
GPIO.OUT_SET = BIT(gpio);
|
2015-06-08 23:00:32 +00:00
|
|
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
2015-08-19 05:46:25 +00:00
|
|
|
GPIO.OUT_CLEAR = BIT(gpio);
|
2015-06-08 23:00:32 +00:00
|
|
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
2015-06-05 01:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void user_init(void)
|
|
|
|
{
|
2015-10-06 12:04:19 +00:00
|
|
|
uart_set_baud(0, 115200);
|
2015-06-05 01:46:25 +00:00
|
|
|
xTaskCreate(blinkenTask, (signed char *)"blinkenTask", 256, NULL, 2, NULL);
|
|
|
|
//xTaskCreate(blinkenRegisterTask, (signed char *)"blinkenRegisterTask", 256, NULL, 2, NULL);
|
|
|
|
}
|