keymap.c (1509B)
1 #include QMK_KEYBOARD_H 2 3 enum custom_keycodes { 4 BL1 = SAFE_RANGE, 5 BL2, 6 BL3, 7 BL4 8 }; 9 10 const uint8_t LED_PINS[] = LED_ROW_PINS; 11 12 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 13 14 [0] = LAYOUT_ortho_4x4( 15 KC_P7, KC_P8, KC_P9, KC_PPLS, 16 KC_P4, KC_P5, KC_P6, KC_PMNS, 17 KC_P1, KC_P2, KC_P3, KC_PAST, 18 MO(1), KC_P0, KC_PDOT, KC_ENT 19 ), 20 21 [1] = LAYOUT_ortho_4x4( 22 KC_NUM, BL1, KC_TRNS, KC_PSLS, 23 QK_BOOT, BL2, KC_TRNS, KC_TRNS, 24 KC_TRNS, BL3, KC_TRNS, KC_TRNS, 25 KC_TRNS, BL4, KC_TRNS, KC_TRNS 26 ), 27 28 }; 29 30 void set_led(int idx, bool enable) { 31 uint8_t pin = LED_PINS[idx]; 32 if (enable) { 33 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); 34 } else { 35 /* PORTx &= ~n */ 36 _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); 37 } 38 } 39 40 bool process_record_user(uint16_t keycode, keyrecord_t *record) { 41 switch (keycode) { 42 case BL1: 43 gpio_write_pin(B4, record->event.pressed); 44 return false; 45 case BL2: 46 gpio_write_pin(B5, record->event.pressed); 47 return false; 48 case BL3: 49 gpio_write_pin(B6, record->event.pressed); 50 return false; 51 case BL4: 52 gpio_write_pin(B7, record->event.pressed); 53 return false; 54 } 55 return true; 56 } 57 58 void matrix_init_user(void) { 59 /* set LED row pins to output and low */ 60 gpio_set_pin_output(B4); 61 gpio_set_pin_output(B5); 62 gpio_set_pin_output(B6); 63 gpio_set_pin_output(B7); 64 65 gpio_write_pin_low(B4); 66 gpio_write_pin_low(B5); 67 gpio_write_pin_low(B6); 68 gpio_write_pin_low(B7); 69 }