diff options
Diffstat (limited to 'keyboard')
| -rw-r--r-- | keyboard/lightpad/Makefile.lufa | 117 | ||||
| -rw-r--r-- | keyboard/lightpad/README.md | 24 | ||||
| -rw-r--r-- | keyboard/lightpad/backlight.c | 129 | ||||
| -rw-r--r-- | keyboard/lightpad/backlight.h | 39 | ||||
| -rw-r--r-- | keyboard/lightpad/config.h | 46 | ||||
| -rw-r--r-- | keyboard/lightpad/keymap.c | 73 | ||||
| -rw-r--r-- | keyboard/lightpad/keymap_lightpad.h | 29 | ||||
| -rw-r--r-- | keyboard/lightpad/led.c | 24 | ||||
| -rw-r--r-- | keyboard/lightpad/matrix.c | 205 |
9 files changed, 686 insertions, 0 deletions
diff --git a/keyboard/lightpad/Makefile.lufa b/keyboard/lightpad/Makefile.lufa new file mode 100644 index 000000000..7bce7ebff --- /dev/null +++ b/keyboard/lightpad/Makefile.lufa | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | #---------------------------------------------------------------------------- | ||
| 2 | # On command line: | ||
| 3 | # | ||
| 4 | # make all = Make software. | ||
| 5 | # | ||
| 6 | # make clean = Clean out built project files. | ||
| 7 | # | ||
| 8 | # make coff = Convert ELF to AVR COFF. | ||
| 9 | # | ||
| 10 | # make extcoff = Convert ELF to AVR Extended COFF. | ||
| 11 | # | ||
| 12 | # make program = Download the hex file to the device. | ||
| 13 | # Please customize your programmer settings(PROGRAM_CMD) | ||
| 14 | # | ||
| 15 | # make teensy = Download the hex file to the device, using teensy_loader_cli. | ||
| 16 | # (must have teensy_loader_cli installed). | ||
| 17 | # | ||
| 18 | # make dfu = Download the hex file to the device, using dfu-programmer (must | ||
| 19 | # have dfu-programmer installed). | ||
| 20 | # | ||
| 21 | # make flip = Download the hex file to the device, using Atmel FLIP (must | ||
| 22 | # have Atmel FLIP installed). | ||
| 23 | # | ||
| 24 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer | ||
| 25 | # (must have dfu-programmer installed). | ||
| 26 | # | ||
| 27 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP | ||
| 28 | # (must have Atmel FLIP installed). | ||
| 29 | # | ||
| 30 | # make debug = Start either simulavr or avarice as specified for debugging, | ||
| 31 | # with avr-gdb or avr-insight as the front end for debugging. | ||
| 32 | # | ||
| 33 | # make filename.s = Just compile filename.c into the assembler code only. | ||
| 34 | # | ||
| 35 | # make filename.i = Create a preprocessed source file for use in submitting | ||
| 36 | # bug reports to the GCC project. | ||
| 37 | # | ||
| 38 | # To rebuild project do "make clean" then "make all". | ||
| 39 | #---------------------------------------------------------------------------- | ||
| 40 | |||
| 41 | # Target file name (without extension). | ||
| 42 | TARGET = lightpad_lufa | ||
| 43 | |||
| 44 | # Directory common source filess exist | ||
| 45 | TOP_DIR = ../.. | ||
| 46 | |||
| 47 | # Directory keyboard dependent files exist | ||
| 48 | TARGET_DIR = . | ||
| 49 | |||
| 50 | # List C source files here. (C dependencies are automatically generated.) | ||
| 51 | SRC = keymap.c \ | ||
| 52 | matrix.c \ | ||
| 53 | led.c \ | ||
| 54 | backlight.c | ||
| 55 | |||
| 56 | CONFIG_H = config.h | ||
| 57 | |||
| 58 | # MCU name | ||
| 59 | MCU = atmega32u4 | ||
| 60 | |||
| 61 | # Processor frequency. | ||
| 62 | # This will define a symbol, F_CPU, in all source code files equal to the | ||
| 63 | # processor frequency in Hz. You can then use this symbol in your source code to | ||
| 64 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done | ||
| 65 | # automatically to create a 32-bit value in your source code. | ||
| 66 | # | ||
| 67 | # This will be an integer division of F_USB below, as it is sourced by | ||
| 68 | # F_USB after it has run through any CPU prescalers. Note that this value | ||
| 69 | # does not *change* the processor frequency - it should merely be updated to | ||
| 70 | # reflect the processor speed set externally so that the code can use accurate | ||
| 71 | # software delays. | ||
| 72 | F_CPU = 8000000 | ||
| 73 | |||
| 74 | # | ||
| 75 | # LUFA specific | ||
| 76 | # | ||
| 77 | # Target architecture (see library "Board Types" documentation). | ||
| 78 | ARCH = AVR8 | ||
| 79 | |||
| 80 | # Input clock frequency. | ||
| 81 | # This will define a symbol, F_USB, in all source code files equal to the | ||
| 82 | # input clock frequency (before any prescaling is performed) in Hz. This value may | ||
| 83 | # differ from F_CPU if prescaling is used on the latter, and is required as the | ||
| 84 | # raw input clock is fed directly to the PLL sections of the AVR for high speed | ||
| 85 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' | ||
| 86 | # at the end, this will be done automatically to create a 32-bit value in your | ||
| 87 | # source code. | ||
| 88 | # | ||
| 89 | # If no clock division is performed on the input clock inside the AVR (via the | ||
| 90 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | ||
| 91 | F_USB = $(F_CPU) | ||
| 92 | |||
| 93 | # Build Options | ||
| 94 | # comment out to disable the options. | ||
| 95 | # | ||
| 96 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) | ||
| 97 | #MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | ||
| 98 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | ||
| 99 | #CONSOLE_ENABLE = yes # Console for debug(+400) | ||
| 100 | #COMMAND_ENABLE = yes # Commands for debug and configuration | ||
| 101 | #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend | ||
| 102 | #NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA | ||
| 103 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | ||
| 104 | |||
| 105 | # Boot Section Size in bytes | ||
| 106 | # Teensy halfKay 512 | ||
| 107 | # Atmel DFU loader 4096 | ||
| 108 | # LUFA bootloader 4096 | ||
| 109 | OPT_DEFS += -DBOOTLOADER_SIZE=4096 | ||
| 110 | |||
| 111 | # Search Path | ||
| 112 | VPATH += $(TARGET_DIR) | ||
| 113 | VPATH += $(TOP_DIR) | ||
| 114 | |||
| 115 | include $(TOP_DIR)/protocol/lufa.mk | ||
| 116 | include $(TOP_DIR)/common.mk | ||
| 117 | include $(TOP_DIR)/rules.mk | ||
diff --git a/keyboard/lightpad/README.md b/keyboard/lightpad/README.md new file mode 100644 index 000000000..b21cccc6a --- /dev/null +++ b/keyboard/lightpad/README.md | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | Lightpad keypad firmware | ||
| 2 | ====================== | ||
| 3 | Korean custom keypad designed by Duck. | ||
| 4 | |||
| 5 | *Note that this is not the official firmware* | ||
| 6 | |||
| 7 | |||
| 8 | Supported models | ||
| 9 | ---------------- | ||
| 10 | All pcb options are supported. | ||
| 11 | |||
| 12 | |||
| 13 | Build | ||
| 14 | ----- | ||
| 15 | Move to this directory then just run `make` like: | ||
| 16 | |||
| 17 | $ make -f Makefile.lufa | ||
| 18 | |||
| 19 | |||
| 20 | Bootloader | ||
| 21 | --------- | ||
| 22 | The PCB is hardwired to run the bootloader if the key at the `top left` position is held down when connecting the keyboard. | ||
| 23 | |||
| 24 | It is still possible to use Boot Magic and Command to access the bootloader though. | ||
diff --git a/keyboard/lightpad/backlight.c b/keyboard/lightpad/backlight.c new file mode 100644 index 000000000..693c566fc --- /dev/null +++ b/keyboard/lightpad/backlight.c | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | ||
| 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 | |||
| 18 | #include <avr/io.h> | ||
| 19 | #include "backlight.h" | ||
| 20 | |||
| 21 | /* Backlight pin configuration | ||
| 22 | * | ||
| 23 | * FN1 PB0 (low) | ||
| 24 | * FN2 PB5 (low) | ||
| 25 | * FN3 PB4 (low) | ||
| 26 | * FN4 PD7 (low) | ||
| 27 | * REAR PD6 (high) | ||
| 28 | * NUMPAD PB2 (high) | ||
| 29 | * NUMLOCK PB1 (low) | ||
| 30 | */ | ||
| 31 | void backlight_init_ports() { | ||
| 32 | DDRB |= (1<<0) | (1<<1) | (1<<2) | (1<<4) | (1<<5); | ||
| 33 | DDRD |= (1<<6) | (1<<7); | ||
| 34 | |||
| 35 | backlight_disable_numlock(); | ||
| 36 | } | ||
| 37 | |||
| 38 | void backlight_set(uint8_t level) { | ||
| 39 | (level & BACKLIGHT_FN1) ? backlight_enable_fn1() : backlight_disable_fn1(); | ||
| 40 | (level & BACKLIGHT_FN2) ? backlight_enable_fn2() : backlight_disable_fn2(); | ||
| 41 | (level & BACKLIGHT_FN3) ? backlight_enable_fn3() : backlight_disable_fn3(); | ||
| 42 | (level & BACKLIGHT_FN4) ? backlight_enable_fn4() : backlight_disable_fn4(); | ||
| 43 | (level & BACKLIGHT_NUMPAD) ? backlight_enable_numpad() : backlight_disable_numpad(); | ||
| 44 | (level & BACKLIGHT_REAR) ? backlight_enable_rear() : backlight_disable_rear(); | ||
| 45 | } | ||
| 46 | |||
| 47 | void backlight_enable_fn1() { | ||
| 48 | PORTB &= ~(1<<0); | ||
| 49 | } | ||
| 50 | |||
| 51 | void backlight_disable_fn1() { | ||
| 52 | PORTB |= (1<<0); | ||
| 53 | } | ||
| 54 | |||
| 55 | void backlight_invert_fn1() { | ||
| 56 | PORTB ^= (1<<0); | ||
| 57 | } | ||
| 58 | |||
| 59 | void backlight_enable_fn2() { | ||
| 60 | PORTB &= ~(1<<5); | ||
| 61 | } | ||
| 62 | |||
| 63 | void backlight_disable_fn2() { | ||
| 64 | PORTB |= (1<<5); | ||
| 65 | } | ||
| 66 | |||
| 67 | void backlight_invert_fn2() { | ||
| 68 | PORTB ^= (1<<5); | ||
| 69 | } | ||
| 70 | |||
| 71 | void backlight_enable_fn3() { | ||
| 72 | PORTB &= ~(1<<4); | ||
| 73 | } | ||
| 74 | |||
| 75 | void backlight_disable_fn3() { | ||
| 76 | PORTB |= (1<<4); | ||
| 77 | } | ||
| 78 | |||
| 79 | void backlight_invert_fn3() { | ||
| 80 | PORTB ^= (1<<4); | ||
| 81 | } | ||
| 82 | |||
| 83 | void backlight_enable_fn4() { | ||
| 84 | PORTD &= ~(1<<7); | ||
| 85 | } | ||
| 86 | |||
| 87 | void backlight_disable_fn4() { | ||
| 88 | PORTD |= (1<<7); | ||
| 89 | } | ||
| 90 | |||
| 91 | void backlight_invert_fn4() { | ||
| 92 | PORTD ^= (1<<7); | ||
| 93 | } | ||
| 94 | |||
| 95 | void backlight_enable_numpad() { | ||
| 96 | PORTB |= (1<<2); | ||
| 97 | } | ||
| 98 | |||
| 99 | void backlight_disable_numpad() { | ||
| 100 | PORTB &= ~(1<<2); | ||
| 101 | } | ||
| 102 | |||
| 103 | void backlight_invert_numpad() { | ||
| 104 | PORTB ^= (1<<2); | ||
| 105 | } | ||
| 106 | |||
| 107 | void backlight_enable_numlock() { | ||
| 108 | PORTB &= ~(1<<1); | ||
| 109 | } | ||
| 110 | |||
| 111 | void backlight_disable_numlock() { | ||
| 112 | PORTB |= (1<<1); | ||
| 113 | } | ||
| 114 | |||
| 115 | void backlight_invert_numlock() { | ||
| 116 | PORTB ^= (1<<1); | ||
| 117 | } | ||
| 118 | |||
| 119 | void backlight_enable_rear() { | ||
| 120 | PORTD |= (1<<6); | ||
| 121 | } | ||
| 122 | |||
| 123 | void backlight_disable_rear() { | ||
| 124 | PORTD &= ~(1<<6); | ||
| 125 | } | ||
| 126 | |||
| 127 | void backlight_invert_rear() { | ||
| 128 | PORTD ^= (1<<6); | ||
| 129 | } | ||
diff --git a/keyboard/lightpad/backlight.h b/keyboard/lightpad/backlight.h new file mode 100644 index 000000000..3b3cfd9ae --- /dev/null +++ b/keyboard/lightpad/backlight.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | |||
| 2 | enum backlight_level { | ||
| 3 | BACKLIGHT_FN1 = 0b0000001, | ||
| 4 | BACKLIGHT_FN2 = 0b0000010, | ||
| 5 | BACKLIGHT_FN3 = 0b0000100, | ||
| 6 | BACKLIGHT_FN4 = 0b0001000, | ||
| 7 | BACKLIGHT_NUMPAD = 0b0010000, | ||
| 8 | BACKLIGHT_REAR = 0b0100000, | ||
| 9 | }; | ||
| 10 | |||
| 11 | void backlight_init_ports(void); | ||
| 12 | |||
| 13 | void backlight_invert_fn1(void); | ||
| 14 | void backlight_enable_fn1(void); | ||
| 15 | void backlight_disable_fn1(void); | ||
| 16 | |||
| 17 | void backlight_invert_fn2(void); | ||
| 18 | void backlight_enable_fn2(void); | ||
| 19 | void backlight_disable_fn2(void); | ||
| 20 | |||
| 21 | void backlight_invert_fn3(void); | ||
| 22 | void backlight_enable_fn3(void); | ||
| 23 | void backlight_disable_fn3(void); | ||
| 24 | |||
| 25 | void backlight_invert_fn4(void); | ||
| 26 | void backlight_enable_fn4(void); | ||
| 27 | void backlight_disable_fn4(void); | ||
| 28 | |||
| 29 | void backlight_invert_numlock(void); | ||
| 30 | void backlight_enable_numlock(void); | ||
| 31 | void backlight_disable_numlock(void); | ||
| 32 | |||
| 33 | void backlight_enable_numpad(void); | ||
| 34 | void backlight_disable_numpad(void); | ||
| 35 | void backlight_invert_numpad(void); | ||
| 36 | |||
| 37 | void backlight_enable_rear(void); | ||
| 38 | void backlight_disable_rear(void); | ||
| 39 | void backlight_invert_rear(void); | ||
diff --git a/keyboard/lightpad/config.h b/keyboard/lightpad/config.h new file mode 100644 index 000000000..7f5a596c0 --- /dev/null +++ b/keyboard/lightpad/config.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | ||
| 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 | |||
| 18 | #ifndef CONFIG_H | ||
| 19 | #define CONFIG_H | ||
| 20 | |||
| 21 | /* USB Device descriptor parameter */ | ||
| 22 | #define VENDOR_ID 0xFEED | ||
| 23 | #define PRODUCT_ID 0x6050 | ||
| 24 | #define DEVICE_VER 0x0104 | ||
| 25 | #define MANUFACTURER Duck | ||
| 26 | #define PRODUCT Lightpad | ||
| 27 | |||
| 28 | /* message strings */ | ||
| 29 | #define DESCRIPTION t.m.k. keyboard firmware for Lightpad | ||
| 30 | |||
| 31 | /* matrix size */ | ||
| 32 | #define MATRIX_ROWS 6 | ||
| 33 | #define MATRIX_COLS 4 | ||
| 34 | |||
| 35 | /* number of backlight levels */ | ||
| 36 | #define BACKLIGHT_LEVELS 1 | ||
| 37 | |||
| 38 | /* Set 0 if need no debouncing */ | ||
| 39 | #define DEBOUNCE 5 | ||
| 40 | |||
| 41 | /* key combination for command */ | ||
| 42 | #define IS_COMMAND() ( \ | ||
| 43 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | ||
| 44 | ) | ||
| 45 | |||
| 46 | #endif | ||
diff --git a/keyboard/lightpad/keymap.c b/keyboard/lightpad/keymap.c new file mode 100644 index 000000000..6d078230b --- /dev/null +++ b/keyboard/lightpad/keymap.c | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | ||
| 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 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include <stdbool.h> | ||
| 20 | #include <avr/pgmspace.h> | ||
| 21 | #include "keycode.h" | ||
| 22 | #include "action.h" | ||
| 23 | #include "action_macro.h" | ||
| 24 | #include "report.h" | ||
| 25 | #include "host.h" | ||
| 26 | #include "debug.h" | ||
| 27 | #include "keymap.h" | ||
| 28 | |||
| 29 | /* Map physical keyboard layout to matrix array */ | ||
| 30 | #define KEYMAP( \ | ||
| 31 | K5A, K5B, K5C, K5D, \ | ||
| 32 | K4A, K4B, K4C, K4D, \ | ||
| 33 | K3A, K3B, K3C, K3D, \ | ||
| 34 | K2A, K2B, K2C, \ | ||
| 35 | K1A, K1B, K1C, K1D, \ | ||
| 36 | K0A, K0B, K0C \ | ||
| 37 | ) { \ | ||
| 38 | /* 0 1 2 3 */ \ | ||
| 39 | /* 5 */ { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D}, \ | ||
| 40 | /* 4 */ { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D}, \ | ||
| 41 | /* 3 */ { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D}, \ | ||
| 42 | /* 2 */ { KC_##K2A, KC_##K2B, KC_##K2C, KC_NO}, \ | ||
| 43 | /* 1 */ { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D}, \ | ||
| 44 | /* 0 */ { KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, } \ | ||
| 45 | } | ||
| 46 | |||
| 47 | #include "keymap_lightpad.h" | ||
| 48 | |||
| 49 | #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) | ||
| 50 | #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) | ||
| 51 | |||
| 52 | /* translates key to keycode */ | ||
| 53 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) | ||
| 54 | { | ||
| 55 | if (layer < KEYMAPS_SIZE) { | ||
| 56 | return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); | ||
| 57 | } else { | ||
| 58 | // fall back to layer 0 | ||
| 59 | return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | /* translates Fn keycode to action */ | ||
| 64 | action_t keymap_fn_to_action(uint8_t keycode) | ||
| 65 | { | ||
| 66 | action_t action; | ||
| 67 | if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) { | ||
| 68 | action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); | ||
| 69 | } else { | ||
| 70 | action.code = ACTION_NO; | ||
| 71 | } | ||
| 72 | return action; | ||
| 73 | } | ||
diff --git a/keyboard/lightpad/keymap_lightpad.h b/keyboard/lightpad/keymap_lightpad.h new file mode 100644 index 000000000..9333964e3 --- /dev/null +++ b/keyboard/lightpad/keymap_lightpad.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #include "backlight.h" | ||
| 2 | |||
| 3 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 4 | KEYMAP(\ | ||
| 5 | FN0, F1, DEL, BSPC, \ | ||
| 6 | NLCK,PSLS,PAST,PMNS, \ | ||
| 7 | P7, P8, P9, PPLS, \ | ||
| 8 | P4, P5, P6, \ | ||
| 9 | P1, P2, P3, PENT, \ | ||
| 10 | P0, NO, PDOT), \ | ||
| 11 | KEYMAP(\ | ||
| 12 | TRNS,PGDN,PGUP,MUTE, \ | ||
| 13 | MSEL,MPRV,MNXT,VOLD, \ | ||
| 14 | P7, P8, P9, VOLU, \ | ||
| 15 | FN4, FN5, FN6, \ | ||
| 16 | FN1, FN2, FN3, MPLY, \ | ||
| 17 | FN7, NO, MSTP) | ||
| 18 | }; | ||
| 19 | |||
| 20 | static const uint16_t PROGMEM fn_actions[] = { | ||
| 21 | [0] = ACTION_LAYER_MOMENTARY(1), | ||
| 22 | [1] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN1), | ||
| 23 | [2] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN2), | ||
| 24 | [3] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN3), | ||
| 25 | [4] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_FN4), | ||
| 26 | [5] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_NUMPAD), | ||
| 27 | [6] = ACTION_BACKLIGHT_LEVEL(BACKLIGHT_REAR), | ||
| 28 | [7] = ACTION_BACKLIGHT_TOGGLE() | ||
| 29 | }; | ||
diff --git a/keyboard/lightpad/led.c b/keyboard/lightpad/led.c new file mode 100644 index 000000000..ebfac3af8 --- /dev/null +++ b/keyboard/lightpad/led.c | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | ||
| 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 | |||
| 18 | #include <avr/io.h> | ||
| 19 | #include "stdint.h" | ||
| 20 | #include "led.h" | ||
| 21 | |||
| 22 | void led_set(uint8_t usb_led) { | ||
| 23 | (usb_led & (1<<USB_LED_NUM_LOCK)) ? backlight_enable_numlock() : backlight_disable_numlock(); | ||
| 24 | } | ||
diff --git a/keyboard/lightpad/matrix.c b/keyboard/lightpad/matrix.c new file mode 100644 index 000000000..87d338395 --- /dev/null +++ b/keyboard/lightpad/matrix.c | |||
| @@ -0,0 +1,205 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | ||
| 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 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include <stdbool.h> | ||
| 20 | #include <avr/io.h> | ||
| 21 | #include <util/delay.h> | ||
| 22 | #include "print.h" | ||
| 23 | #include "debug.h" | ||
| 24 | #include "util.h" | ||
| 25 | #include "matrix.h" | ||
| 26 | #include "eeconfig.h" | ||
| 27 | #include "action_layer.h" | ||
| 28 | #include "backlight.h" | ||
| 29 | |||
| 30 | #ifndef DEBOUNCE | ||
| 31 | # define DEBOUNCE 0 | ||
| 32 | #endif | ||
| 33 | static uint8_t debouncing = DEBOUNCE; | ||
| 34 | |||
| 35 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 36 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 37 | |||
| 38 | static uint8_t read_rows(void); | ||
| 39 | static uint8_t read_fwkey(void); | ||
| 40 | static void init_rows(void); | ||
| 41 | static void unselect_cols(void); | ||
| 42 | static void select_col(uint8_t col); | ||
| 43 | |||
| 44 | inline | ||
| 45 | uint8_t matrix_rows(void) | ||
| 46 | { | ||
| 47 | return MATRIX_ROWS; | ||
| 48 | } | ||
| 49 | |||
| 50 | inline | ||
| 51 | uint8_t matrix_cols(void) | ||
| 52 | { | ||
| 53 | return MATRIX_COLS; | ||
| 54 | } | ||
| 55 | |||
| 56 | void misc_init(void) { | ||
| 57 | } | ||
| 58 | |||
| 59 | void matrix_init(void) | ||
| 60 | { | ||
| 61 | backlight_init_ports(); | ||
| 62 | unselect_cols(); | ||
| 63 | init_rows(); | ||
| 64 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 65 | matrix[i] = 0; | ||
| 66 | matrix_debouncing[i] = 0; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | uint8_t matrix_scan(void) | ||
| 71 | { | ||
| 72 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 73 | select_col(col); | ||
| 74 | _delay_us(3); | ||
| 75 | uint8_t rows = read_rows(); | ||
| 76 | // Use the otherwise unused col: 0 row: 0 for firmware key | ||
| 77 | if(col == 0) { | ||
| 78 | rows |= read_fwkey(); | ||
| 79 | } | ||
| 80 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 81 | bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col); | ||
| 82 | bool curr_bit = rows & (1<<row); | ||
| 83 | if (prev_bit != curr_bit) { | ||
| 84 | matrix_debouncing[row] ^= ((matrix_row_t)1<<col); | ||
| 85 | if (debouncing) { | ||
| 86 | dprint("bounce!: "); dprintf("%02X", debouncing); dprintln(); | ||
| 87 | } | ||
| 88 | debouncing = DEBOUNCE; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | unselect_cols(); | ||
| 92 | } | ||
| 93 | |||
| 94 | if (debouncing) { | ||
| 95 | if (--debouncing) { | ||
| 96 | _delay_ms(1); | ||
| 97 | } else { | ||
| 98 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 99 | matrix[i] = matrix_debouncing[i]; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | return 1; | ||
| 105 | } | ||
| 106 | |||
| 107 | bool matrix_is_modified(void) | ||
| 108 | { | ||
| 109 | if (debouncing) return false; | ||
| 110 | return true; | ||
| 111 | } | ||
| 112 | |||
| 113 | inline | ||
| 114 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 115 | { | ||
| 116 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 117 | } | ||
| 118 | |||
| 119 | inline | ||
| 120 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 121 | { | ||
| 122 | return matrix[row]; | ||
| 123 | } | ||
| 124 | |||
| 125 | void matrix_print(void) | ||
| 126 | { | ||
| 127 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 128 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 129 | xprintf("%02X: %032lb\n", row, bitrev32(matrix_get_row(row))); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | uint8_t matrix_key_count(void) | ||
| 134 | { | ||
| 135 | uint8_t count = 0; | ||
| 136 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 137 | count += bitpop32(matrix[i]); | ||
| 138 | } | ||
| 139 | return count; | ||
| 140 | } | ||
| 141 | |||
| 142 | /* Row configuration | ||
| 143 | * | ||
| 144 | * row: 0 1 2 3 4 5 | ||
| 145 | * pin: PD0 PD1 PD2 PD3 PD5 PB7 | ||
| 146 | * | ||
| 147 | * Firmware uses pin PE2 | ||
| 148 | */ | ||
| 149 | static void init_rows(void) | ||
| 150 | { | ||
| 151 | DDRD &= ~0b00101111; | ||
| 152 | PORTD |= 0b00101111; | ||
| 153 | |||
| 154 | DDRB &= ~0b10000000; | ||
| 155 | PORTB |= 0b10000000; | ||
| 156 | |||
| 157 | DDRE &= ~0b00000100; | ||
| 158 | PORTE |= 0b00000100; | ||
| 159 | } | ||
| 160 | |||
| 161 | static uint8_t read_rows(void) | ||
| 162 | { | ||
| 163 | return (PIND&(1<<0) ? (1<<0) : 0) | | ||
| 164 | (PIND&(1<<1) ? (1<<1) : 0) | | ||
| 165 | (PIND&(1<<2) ? (1<<2) : 0) | | ||
| 166 | (PIND&(1<<3) ? (1<<3) : 0) | | ||
| 167 | (PIND&(1<<5) ? (1<<4) : 0) | | ||
| 168 | (PINB&(1<<7) ? (1<<5) : 0); | ||
| 169 | } | ||
| 170 | |||
| 171 | static uint8_t read_fwkey(void) | ||
| 172 | { | ||
| 173 | return PINE&(1<<2) ? 0 : (1<<0); | ||
| 174 | } | ||
| 175 | |||
| 176 | /* Column configuration | ||
| 177 | * | ||
| 178 | * col: 0 1 2 3 | ||
| 179 | * pin: PF0 PF1 PC7 PC6 | ||
| 180 | */ | ||
| 181 | static void unselect_cols(void) | ||
| 182 | { | ||
| 183 | DDRF |= 0b00000011; | ||
| 184 | PORTF &= ~0b00000011; | ||
| 185 | DDRC |= 0b11000000; | ||
| 186 | PORTC &= ~0b11000000; | ||
| 187 | } | ||
| 188 | |||
| 189 | static void select_col(uint8_t col) | ||
| 190 | { | ||
| 191 | switch (col) { | ||
| 192 | case 0: | ||
| 193 | PORTF |= (1<<0); | ||
| 194 | break; | ||
| 195 | case 1: | ||
| 196 | PORTF |= (1<<1); | ||
| 197 | break; | ||
| 198 | case 2: | ||
| 199 | PORTC |= (1<<7); | ||
| 200 | break; | ||
| 201 | case 3: | ||
| 202 | PORTC |= (1<<6); | ||
| 203 | break; | ||
| 204 | } | ||
| 205 | } | ||
