torn.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }