blinky.c 774 B

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