led.c 715 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * (c) danielinux 2019
  3. * GPLv.2
  4. *
  5. * See LICENSE for details
  6. */
  7. #include <stdint.h>
  8. #include "system.h"
  9. #include "led.h"
  10. void led_setup(uint32_t led)
  11. {
  12. uint32_t reg;
  13. AHB1_CLOCK_ER |= GPIOA_AHB1_CLOCK_ER;
  14. reg = GPIOA_MODE & ~ (0x03 << (led * 2));
  15. GPIOA_MODE = reg | (1 << (led * 2));
  16. reg = GPIOA_PUPD & (0x03 << (led * 2));
  17. GPIOA_PUPD = reg | (0x02 << (led * 2));
  18. led_off(led);
  19. }
  20. void pio_on(uint32_t pio)
  21. {
  22. GPIOA_BSRR |= (1 << pio);
  23. }
  24. void pio_off(uint32_t pio)
  25. {
  26. GPIOA_BSRR |= (1 << (pio + 16));
  27. }
  28. void pio_toggle(uint32_t pio)
  29. {
  30. uint32_t reg;
  31. reg = GPIOA_ODR;
  32. if ((reg & (1 << pio)) == (1 << pio))
  33. pio_off(pio);
  34. else
  35. pio_on(pio);
  36. }