budget96.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright 2019 MechMerlin
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "budget96.h"
  17. #ifdef BACKLIGHT_ENABLE
  18. #include "backlight.h"
  19. #endif
  20. #ifdef RGBLIGHT_ENABLE
  21. #include "rgblight.h"
  22. #endif
  23. #include <avr/pgmspace.h>
  24. #include "action_layer.h"
  25. #include "i2c_master.h"
  26. #include "quantum.h"
  27. __attribute__ ((weak))
  28. void matrix_scan_user(void) {
  29. }
  30. #ifdef RGBLIGHT_ENABLE
  31. extern rgblight_config_t rgblight_config;
  32. void rgblight_set(void) {
  33. if (!rgblight_config.enable) {
  34. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  35. led[i].r = 0;
  36. led[i].g = 0;
  37. led[i].b = 0;
  38. }
  39. }
  40. i2c_init();
  41. i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
  42. }
  43. #endif
  44. void matrix_init_kb(void) {
  45. #ifdef RGBLIGHT_ENABLE
  46. if (rgblight_config.enable) {
  47. i2c_init();
  48. i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
  49. }
  50. #endif
  51. // call user level keymaps, if any
  52. matrix_init_user();
  53. }
  54. void matrix_scan_kb(void) {
  55. #ifdef RGBLIGHT_ENABLE
  56. rgblight_task();
  57. #endif
  58. matrix_scan_user();
  59. /* Nothing else for now. */
  60. }
  61. void backlight_init_ports(void) {
  62. // initialize pins D0, D1, D4 and D6 as output
  63. setPinOutput(D0);
  64. setPinOutput(D1);
  65. setPinOutput(D4);
  66. setPinOutput(D6);
  67. // turn RGB LEDs on
  68. writePinHigh(D0);
  69. writePinHigh(D1);
  70. writePinHigh(D4);
  71. writePinHigh(D6);
  72. }
  73. void backlight_set(uint8_t level) {
  74. if (level == 0) {
  75. // turn RGB LEDs off
  76. writePinLow(D0);
  77. writePinLow(D1);
  78. writePinLow(D4);
  79. writePinLow(D6);
  80. } else {
  81. // turn RGB LEDs on
  82. writePinHigh(D0);
  83. writePinHigh(D1);
  84. writePinHigh(D4);
  85. writePinHigh(D6);
  86. }
  87. }