led.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. void rt_hw_led_init(void)
  2. {
  3. return;
  4. }
  5. #include <stdint.h>
  6. #include "platform.h"
  7. void rt_hw_led_on(int led)
  8. {
  9. uint16_t r=0xFF;
  10. uint16_t g=0;
  11. uint16_t b=0;
  12. char c = 0;
  13. // Set up RGB PWM
  14. /*
  15. PWM1_REG(PWM_CFG) = 0;
  16. // To balance the power consumption, make one left, one right, and one center aligned.
  17. PWM1_REG(PWM_CFG) = (PWM_CFG_ENALWAYS) | (PWM_CFG_CMP2CENTER);
  18. PWM1_REG(PWM_COUNT) = 0;
  19. // Period is approximately 244 Hz
  20. // the LEDs are intentionally left somewhat dim,
  21. // as the full brightness can be painful to look at.
  22. PWM1_REG(PWM_CMP0) = 0;
  23. */
  24. if(r > 0 && b == 0){
  25. r--;
  26. g++;
  27. }
  28. if(g > 0 && r == 0){
  29. g--;
  30. b++;
  31. }
  32. if(b > 0 && g == 0){
  33. r++;
  34. b--;
  35. }
  36. uint32_t G = g;
  37. uint32_t R = r;
  38. uint32_t B = b;
  39. PWM1_REG(PWM_CMP1) = G << 4; // PWM is low on the left, GPIO is low on the left side, LED is ON on the left.
  40. PWM1_REG(PWM_CMP2) = (B << 1) << 4; // PWM is high on the middle, GPIO is low in the middle, LED is ON in the middle.
  41. PWM1_REG(PWM_CMP3) = 0xFFFF - (R << 4); // PWM is low on the left, GPIO is low on the right, LED is on on the right.
  42. return;
  43. }
  44. void rt_hw_led_off(int led)
  45. {
  46. return;
  47. }