blinky.c 855 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "ets_sys.h"
  2. #include "osapi.h"
  3. #include "gpio.h"
  4. #include "os_type.h"
  5. // ESP-12 modules have LED on GPIO2. Change to another GPIO
  6. // for other boards.
  7. static const int pin = 2;
  8. static volatile os_timer_t some_timer;
  9. void some_timerfunc(void *arg)
  10. {
  11. //Do blinky stuff
  12. if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & (1 << pin))
  13. {
  14. // set gpio low
  15. gpio_output_set(0, (1 << pin), 0, 0);
  16. }
  17. else
  18. {
  19. // set gpio high
  20. gpio_output_set((1 << pin), 0, 0, 0);
  21. }
  22. }
  23. void ICACHE_FLASH_ATTR user_init()
  24. {
  25. // init gpio subsytem
  26. gpio_init();
  27. // configure UART TXD to be GPIO1, set as output
  28. PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
  29. gpio_output_set(0, 0, (1 << pin), 0);
  30. // setup timer (500ms, repeating)
  31. os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
  32. os_timer_arm(&some_timer, 500, 1);
  33. }