logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

indicator_leds.c (2261B)


  1. /*
  2. Copyright 2017 MechMerlin <mechmerlin@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/interrupt.h>
  15. #include <avr/io.h>
  16. #include <stdbool.h>
  17. #include <util/delay.h>
  18. #include "indicator_leds.h"
  19. #include "duck_led/duck_led.h"
  20. #define LED_T1H 600
  21. #define LED_T1L 650
  22. #define LED_T0H 250
  23. #define LED_T0L 1000
  24. void send_bit_d4(bool bitVal) {
  25. if(bitVal) {
  26. asm volatile (
  27. "sbi %[port], %[bit] \n\t"
  28. ".rept %[onCycles] \n\t"
  29. "nop \n\t"
  30. ".endr \n\t"
  31. "cbi %[port], %[bit] \n\t"
  32. ".rept %[offCycles] \n\t"
  33. "nop \n\t"
  34. ".endr \n\t"
  35. ::
  36. [port] "I" (_SFR_IO_ADDR(PORTD)),
  37. [bit] "I" (4),
  38. [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2),
  39. [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2));
  40. } else {
  41. asm volatile (
  42. "sbi %[port], %[bit] \n\t"
  43. ".rept %[onCycles] \n\t"
  44. "nop \n\t"
  45. ".endr \n\t"
  46. "cbi %[port], %[bit] \n\t"
  47. ".rept %[offCycles] \n\t"
  48. "nop \n\t"
  49. ".endr \n\t"
  50. ::
  51. [port] "I" (_SFR_IO_ADDR(PORTD)),
  52. [bit] "I" (4),
  53. [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2),
  54. [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2));
  55. }
  56. }
  57. void send_value(uint8_t byte, enum Device device) {
  58. for(uint8_t b = 0; b < 8; b++) {
  59. if(device == Device_STATUSLED) {
  60. send_bit_d4(byte & 0b10000000);
  61. byte <<= 1;
  62. }
  63. }
  64. }
  65. // Send the LED indicators to the WS2811S chips
  66. void indicator_leds_set(bool leds[8]) {
  67. uint8_t led_cnt;
  68. cli();
  69. for(led_cnt = 0; led_cnt < 8; led_cnt++)
  70. send_value(leds[led_cnt] ? 255 : 0, Device_STATUSLED);
  71. sei();
  72. show();
  73. }