keymap.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include QMK_KEYBOARD_H
  2. #include "i2c_master.h"
  3. #include "debug.h"
  4. #define TIMEOUT 50
  5. // TODO: remove patch
  6. #ifdef PROTOCOL_CHIBIOS
  7. # pragma message("ChibiOS is currently 'best effort' and might not report accurate results")
  8. i2c_status_t i2c_start_bodge(uint8_t address, uint16_t timeout) {
  9. i2c_start(address);
  10. // except on ChibiOS where the only way is do do "something"
  11. uint8_t data = 0;
  12. return i2c_readReg(address, 0, &data, sizeof(data), TIMEOUT);
  13. }
  14. # define i2c_start i2c_start_bodge
  15. #endif
  16. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  17. LAYOUT_ortho_1x1(KC_A)
  18. };
  19. void do_scan(void) {
  20. uint8_t nDevices = 0;
  21. dprintf("Scanning...\n");
  22. for (uint8_t address = 1; address < 127; address++) {
  23. // The i2c_scanner uses the return value of
  24. // i2c_start to see if a device did acknowledge to the address.
  25. i2c_status_t error = i2c_start(address << 1, TIMEOUT);
  26. if (error == I2C_STATUS_SUCCESS) {
  27. i2c_stop();
  28. dprintf(" I2C device found at address 0x%02X\n", address);
  29. nDevices++;
  30. } else {
  31. // dprintf(" Unknown error (%u) at address 0x%02X\n", error, address);
  32. }
  33. }
  34. if (nDevices == 0)
  35. dprintf("No I2C devices found\n");
  36. else
  37. dprintf("done\n");
  38. }
  39. uint16_t scan_timer = 0;
  40. void matrix_scan_user(void) {
  41. if (timer_elapsed(scan_timer) > 5000) {
  42. do_scan();
  43. scan_timer = timer_read();
  44. }
  45. }
  46. void keyboard_post_init_user(void) {
  47. debug_enable = true;
  48. debug_matrix = true;
  49. i2c_init();
  50. scan_timer = timer_read();
  51. }