You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
4.6 KiB

  1. /*
  2. * Copyright 2020 Richard Titmuss <richard.titmuss@gmail.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "torn.h"
  18. #include "i2c_master.h"
  19. #include "mcp23018.h"
  20. static uint8_t led_state[3] = {1, 1, 1};
  21. void matrix_init_kb(void) {
  22. // put your keyboard start-up code here
  23. // runs once when the firmware starts up
  24. i2c_init();
  25. matrix_init_user();
  26. }
  27. void matrix_scan_kb(void) {
  28. // put your looping keyboard code here
  29. // runs every cycle (a lot)
  30. if (mcp23018_reset_required()) {
  31. msp23018_init();
  32. secondary_encoder_init();
  33. // torn_set_led(2, 1);
  34. }
  35. matrix_scan_user();
  36. secondary_encoder_read();
  37. }
  38. void torn_set_led(uint8_t led, bool state) {
  39. led_state[led] = !state;
  40. // toggle leds by setting the pin direction
  41. uint8_t iodir = 0b11111000 | led_state[0] << 2 | led_state[1] << 1 | led_state[2];
  42. mcp23018_writeReg(IODIRB, &iodir, 1);
  43. }
  44. // clang-format off
  45. const char PROGMEM bongocat_logo[] = {
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0x98, 0x98, 0x98, 0x98, 0x98, 0x18, 0x18, 0x98,
  47. 0x98, 0x98, 0x98, 0x98, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0x00, 0x80, 0xc0, 0x60, 0x30, 0x30, 0x18, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98,
  49. 0x18, 0x30, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0x18, 0x18, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x18, 0x38,
  51. 0x70, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0xf8, 0xf8, 0x38, 0x70, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53. 0xf8, 0xf8, 0x18, 0x18, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0xff, 0xff, 0x00, 0x00, 0xff,
  55. 0xff, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0xf8, 0xfe, 0x07, 0x01, 0xf0, 0xfc, 0x0e, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  57. 0x03, 0x03, 0x0e, 0xfc, 0xf0, 0x01, 0x07, 0xfe, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xc1, 0xc1, 0xc1, 0x63, 0x3f, 0x1c,
  59. 0xc0, 0xe1, 0x7f, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  60. 0xff, 0xff, 0x00, 0x00, 0xf8, 0xf1, 0xe3, 0xc7, 0x8e, 0x1c, 0x38, 0x70, 0xe0, 0xc0, 0x80, 0x00,
  61. 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  62. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
  63. 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x0f, 0x3f, 0x70, 0xc0, 0x87, 0x1f, 0x38, 0x60, 0x60, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
  65. 0x60, 0x60, 0x38, 0x1f, 0x87, 0xc0, 0xf0, 0x7f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xfe, 0x0e, 0x3c, 0x78, 0xe2, 0xc7, 0x1f,
  67. 0x39, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x01, 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x71, 0xe3, 0xc7,
  69. 0x8f, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0c, 0x0c, 0x0f,
  71. 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72. 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
  73. 0x0c, 0x06, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74. 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0c, 0x0c, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0f,
  75. 0x0c, 0x0c, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  76. 0x0f, 0x0f, 0x0c, 0x0c, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  77. 0x03, 0x07, 0x0e, 0x0c, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  78. };
  79. // clang-format on