]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add multiple layout support and Linux flash utility to JJ40 (#1837)
authorOscillope <jvrosenman@gmail.com>
Sat, 14 Oct 2017 05:04:36 +0000 (01:04 -0400)
committerJack Humbert <jack.humb@gmail.com>
Sat, 14 Oct 2017 05:04:36 +0000 (19:04 -1000)
* Adds support for multiple layouts. Adds custom keymap for "offset"
layout.

* Adds a tool to help detach the keyboard from the Linux HID driver before programming.

* Adds a tool to help detach the keyboard from the Linux HID driver before programming.

keyboards/jj40/README.md
keyboards/jj40/jj40.h
keyboards/jj40/keymaps/oscillope/keymap.c [new file with mode: 0644]
keyboards/jj40/tools/README.md [new file with mode: 0644]
keyboards/jj40/tools/usb_detach.c [new file with mode: 0644]

index 6b48c151595e181fc9fc400b4c4df4bd14eea002..03b7533de01f02db0b9074e686823f2bde6678a7 100644 (file)
@@ -48,3 +48,6 @@ $ bootloadHID -r jj40_default.hex
    done, just reflash the board with the original firmware.
 2. Sometimes USB hubs can act weird, so try connecting the board directly
    to your computer or plugging/unplugging the USB hub.
    done, just reflash the board with the original firmware.
 2. Sometimes USB hubs can act weird, so try connecting the board directly
    to your computer or plugging/unplugging the USB hub.
+3. If you get an error such as "Resource Unavailable" when attemting to flash
+   on Linux, you may want to compile and run `tools/usb_detach.c`. See `tools/README.md`
+   for more info.
index 6c9cc19477cc7e761c0e80e4f2a4025dadc52fe4..b1a7a6238600a4db075c60191cdce161b325398d 100644 (file)
@@ -22,7 +22,21 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "keycode.h"
 #include "action.h"
 
 #include "keycode.h"
 #include "action.h"
 
-#define KEYMAP( \
+#define KEYMAP_GRID( \
+    K01, K02, K03, K04, K05, K06, K07, K08, K09, K010, K011, K012, \
+    K11, K12, K13, K14, K15, K16, K17, K18, K19, K110, K111, K112, \
+    K21, K22, K23, K24, K25, K26, K27, K28, K29, K210, K211, K212, \
+    K31, K32, K33, K34, K35, K36, K37, K38, K39, K310, K311, K312  \
+) \
+{ \
+  { K012, K011, K010, K09, K05, K06, K07, K08, K04, K03, K02, K01 }, \
+  { K112, K111, K110, K19, K15, K16, K17, K18, K14, K13, K12, K11 }, \
+  { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
+  { K212, K211, K210, K29, K25, K26, K27, K28, K24, K23, K22, K21 }, \
+  { K312, K311, K310, K39, K35, K36, K37, K38, K34, K33, K32, K31 }  \
+}
+
+#define KEYMAP_MIT( \
     K01, K02, K03, K04, K05, K06, K07, K08, K09, K010, K011, K012, \
     K11, K12, K13, K14, K15, K16, K17, K18, K19, K110, K111, K112, \
     K21, K22, K23, K24, K25, K26, K27, K28, K29, K210, K211, K212, \
     K01, K02, K03, K04, K05, K06, K07, K08, K09, K010, K011, K012, \
     K11, K12, K13, K14, K15, K16, K17, K18, K19, K110, K111, K112, \
     K21, K22, K23, K24, K25, K26, K27, K28, K29, K210, K211, K212, \
@@ -36,4 +50,20 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
   { K312, K311, K310, K39, K35, K3X, KC_NO, K38, K34, K33, K32, K31 }  \
 }
 
   { K312, K311, K310, K39, K35, K3X, KC_NO, K38, K34, K33, K32, K31 }  \
 }
 
+#define KEYMAP_OFFSET( \
+    K01, K02, K03, K04, K05, K06, K07, K08, K09, K010, K011, K012, \
+    K11, K12, K13, K14, K15, K16, K17, K18, K19, K110, K111, K112, \
+    K21, K22, K23, K24, K25, K26, K27, K28, K29, K210, K211, K212, \
+    K31, K32, K33, K34, K35, K36,    K3X,   K39, K310, K311, K312  \
+) \
+{ \
+  { K012, K011, K010, K09, K05, K06, K07,   K08, K04, K03, K02, K01 }, \
+  { K112, K111, K110, K19, K15, K16, K17,   K18, K14, K13, K12, K11 }, \
+  { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
+  { K212, K211, K210, K29, K25, K26, K27,   K28, K24, K23, K22, K21 }, \
+  { K312, K311, K310, K39, K35, K36, K3X, KC_NO, K34, K33, K32, K31 }  \
+}
+
+#define KEYMAP KEYMAP_OFFSET
+
 #endif
 #endif
diff --git a/keyboards/jj40/keymaps/oscillope/keymap.c b/keyboards/jj40/keymaps/oscillope/keymap.c
new file mode 100644 (file)
index 0000000..2badb09
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "jj40.h"
+#include "action_layer.h"
+#include "rgblight.h"
+
+#define _QWERTY 0
+#define _LOWER  1
+#define _RAISE  2
+
+enum custom_keycodes {
+  QWERTY = SAFE_RANGE,
+  LOWER,
+  RAISE,
+};
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+/* Qwerty
+ * ,-----------------------------------------------------------------------------------.
+ * | Esc  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |
+ * |------+------+------+------+------+-------------+------+------+------+------+------|
+ * | Tab  |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;  |Enter |
+ * |------+------+------+------+------+------|------+------+------+------+------+------|
+ * |   `  |   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |  '   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Ctrl |  OS  | Alt  |Lower |Shift |Raise |    Space    | Left | Down |  Up  |Right |
+ * `-----------------------------------------------------------------------------------'
+ */
+[_QWERTY] = KEYMAP( \
+  KC_ESC,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC, \
+  KC_TAB,  KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_ENT, \
+  KC_GRV,  KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_QUOT, \
+  KC_LCTL, KC_LGUI, KC_LALT, MO(_LOWER), KC_LSFT, MO(_RAISE),   KC_SPC,   KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT \
+),
+
+/* Lower
+ * ,-----------------------------------------------------------------------------------.
+ * |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |  F7  |  F8  |  F9  | F10  | F11  | F12  |
+ * |------+------+------+------+------+-------------+------+------+------+------+------|
+ * |      |      |      |      |      |      | Left | Down |  Up  |Right |      |      |
+ * |------+------+------+------+------+------|------+------+------+------+------+------|
+ * |      | Back | Fwd  |      |      |      |      |      | Mute | Vol- | Vol+ |      |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * |      |      |      |      |      |             |      | Prev | Stop | Play | Next |
+ * `-----------------------------------------------------------------------------------'
+ */
+[_LOWER] = KEYMAP( \
+  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \
+  KC_DEL,  _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT, _______, _______, \
+  _______, KC_WBAK, KC_WFWD, _______, _______, _______, _______, _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, \
+  _______, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_MSTP, KC_MPLY, KC_MNXT \
+),
+
+/* Raise
+ * ,-----------------------------------------------------------------------------------.
+ * | Esc  |   &  |   *  |   _  |   (  |   )  |   7  |   8  |   9  |   =  | Bksp | Del  |
+ * |------+------+------+------+------+-------------+------+------+------+------+------|
+ * | Ins  |   $  |   %  |   ^  |   [  |   ]  |   4  |   5  |   6  |   -  |   +  |  |   |
+ * |------+------+------+------+------+------|------+------+------+------+------+------|
+ * |   `  |   !  |   @  |   #  |   {  |   }  |   1  |   2  |   3  |   .  |   \  |  '   |
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
+ * | Ctrl |  OS  | Alt  |      |Shift |      |      0      | Home | PgDn | PgUp | End  |
+ * `-----------------------------------------------------------------------------------'
+ */
+[_RAISE] = KEYMAP( \
+  _______, KC_AMPR, KC_ASTR, KC_UNDS, KC_LPRN, KC_RPRN, KC_7,    KC_8,    KC_9,    KC_EQL,  KC_BSPC, KC_DEL, \
+  KC_INS,  KC_DLR,  KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_4,    KC_5,    KC_6,    KC_MINS, KC_PLUS, KC_PIPE, \
+  _______, KC_EXLM, KC_AT,   KC_HASH, KC_LCBR, KC_RCBR, KC_1,    KC_2,    KC_3,    _______, KC_BSLS, _______, \
+  _______, _______, _______, _______, _______, _______, KC_0,    KC_HOME, KC_PGDN, KC_PGUP, KC_END \
+)
+};
diff --git a/keyboards/jj40/tools/README.md b/keyboards/jj40/tools/README.md
new file mode 100644 (file)
index 0000000..081984e
--- /dev/null
@@ -0,0 +1,16 @@
+# JJ40 Tools
+
+## usb_detach.c
+
+When trying to flash on Linux, you may encounter a "Resource Unavailable" error. This means that Linux's HID driver has taken exclusive control of the keyboard, and the program script can't flash it.
+This program can force Linux to give up a device, so that the programming script can reset it.
+
+### To compile:
+```
+gcc usb_detach.c -o usb_detach
+```
+
+### To run:
+1. Use `lsusb` to discover the Bus and Device numbers for your keyboard.
+2. Run the program: `sudo ./usb_detach /dev/bus/usb/<BUS>/<DEVICE>`.
+3. Build and program the firmware as normal.
diff --git a/keyboards/jj40/tools/usb_detach.c b/keyboards/jj40/tools/usb_detach.c
new file mode 100644 (file)
index 0000000..c21e47a
--- /dev/null
@@ -0,0 +1,33 @@
+/* Found at https://www.linuxquestions.org/questions/linux-hardware-18/how-to-unclaim-usb-device-558138/#post3406986 */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <linux/ioctl.h>
+#include <linux/usbdevice_fs.h>
+
+int main(int argc, char**argv)
+{
+        struct usbdevfs_ioctl command;
+        int ret;
+        int fd;
+        int i;
+        if (argc>1) {
+                fd = open(argv[1],O_RDWR);
+                if (fd<1){
+                        perror("unable to open file");
+                        return 1;
+                }
+                for (i=0;i<255;i++){ // hack: should fetch how many interface there is.
+                        command.ifno = i;
+                        command.ioctl_code = USBDEVFS_DISCONNECT;
+                        command.data = NULL;
+                        ret = ioctl(fd, USBDEVFS_IOCTL, &command);
+                        if(ret!=-1)
+                                printf("un claimed interface %d %d\n",i,ret);
+                }
+        } else {
+                printf ("usage: %s /dev/bus/usb/BUS/DEVICE\n",argv[0]);
+                printf("Release all interfaces of this usb device for usage in virtualisation\n");
+        }
+}
\ No newline at end of file