logo

qmk_firmware

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

gergoplex.c (1621B)


  1. /* Copyright 2021 Jane Bernhardt
  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 "gergoplex.h"
  17. bool i2c_initialized = 0;
  18. i2c_status_t mcp23018_status = 0x20;
  19. void matrix_init_kb(void) {
  20. matrix_init_user();
  21. }
  22. uint8_t init_mcp23018(void) {
  23. print("starting init");
  24. mcp23018_status = 0x20;
  25. // I2C subsystem
  26. if (i2c_initialized == 0) {
  27. i2c_init(); // on pins D(1,0)
  28. i2c_initialized = true;
  29. _delay_ms(1000);
  30. }
  31. // set pin direction
  32. // - unused : input : 1
  33. // - input : input : 1
  34. // - driving : output : 0
  35. uint8_t data[] = {0b11000001, 0b11111111};
  36. mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT);
  37. if (!mcp23018_status) {
  38. // set pull-up
  39. // - unused : on : 1
  40. // - input : on : 1
  41. // - driving : off : 0
  42. mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT);
  43. }
  44. return mcp23018_status;
  45. }