bmc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "bmc.h"
  17. #include "rgblight.h"
  18. #include "i2c_master.h"
  19. void matrix_init_kb(void) {
  20. // put your keyboard start-up code here
  21. // runs once when the firmware starts up
  22. matrix_init_user();
  23. }
  24. void matrix_scan_kb(void) {
  25. // put your looping keyboard code here
  26. // runs every cycle (a lot)
  27. matrix_scan_user();
  28. }
  29. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  30. // put your per-action keyboard code here
  31. // runs for every action, just before processing by the firmware
  32. return process_record_user(keycode, record);
  33. }
  34. void led_set_kb(uint8_t usb_led) {
  35. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  36. led_set_user(usb_led);
  37. }
  38. #ifdef RGBLIGHT_ENABLE
  39. extern rgblight_config_t rgblight_config;
  40. void rgblight_set(void) {
  41. if (!rgblight_config.enable) {
  42. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  43. led[i].r = 0;
  44. led[i].g = 0;
  45. led[i].b = 0;
  46. }
  47. }
  48. i2c_init();
  49. i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
  50. }
  51. #endif
  52. __attribute__ ((weak))
  53. void matrix_scan_user(void) {
  54. }
  55. void backlight_init_ports(void) {
  56. // initialize pins D0, D1, D4 and D6 as output
  57. setPinOutput(D0);
  58. setPinOutput(D1);
  59. setPinOutput(D4);
  60. setPinOutput(D6);
  61. // turn RGB LEDs on
  62. writePinHigh(D0);
  63. writePinHigh(D1);
  64. writePinHigh(D4);
  65. writePinHigh(D6);
  66. }
  67. void backlight_set(uint8_t level) {
  68. if (level == 0) {
  69. // turn RGB LEDs off
  70. writePinLow(D0);
  71. writePinLow(D1);
  72. writePinLow(D4);
  73. writePinLow(D6);
  74. } else {
  75. // turn RGB LEDs on
  76. writePinHigh(D0);
  77. writePinHigh(D1);
  78. writePinHigh(D4);
  79. writePinHigh(D6);
  80. }
  81. }