qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap.c (1333B)


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