Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse & NKRO support #28

Closed
wants to merge 12 commits into from
2 changes: 2 additions & 0 deletions firmware/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* toggle nkro function
* nkro send keys / add/remove keys by bits if nkro enabled
1 change: 1 addition & 0 deletions firmware/keyboard/ergodox/layout/common/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "../../../../../firmware/lib/usb.h"
#include "../../../../../firmware/lib/usb/usage-page/keyboard.h"
#include "../../../../../firmware/lib/layout/key-functions.h"
#include "../../../../../firmware/lib/layout/mouse.h"
#include "../../../../../firmware/lib/layout/layer-stack.h"
#include "../../../../../firmware/keyboard.h"

Expand Down
13 changes: 13 additions & 0 deletions firmware/keyboard/ergodox/layout/common/keys.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ void R(shR2kcap) (void) { KF(2_keys_capslock)(false, KEYBOARD__RightShift); }
void P(btldr) (void) { KF(jump_to_bootloader)(); }
void R(btldr) (void) {}

/**
* mouse left click
*/

void P(MclkL) (void) { KF(mouse_buttons)(1, 0, 0); }
void R(MclkL) (void) { KF(mouse_buttons)(0, 0, 0); }

/**
* nkro toggle
*/

void P(tnkro) (void) { KF(toggle_nkro)(); }
void R(tnkro) (void) {}

// ----------------------------------------------------------------------------
// --- layer ------------------------------------------------------------------
Expand Down
167 changes: 167 additions & 0 deletions firmware/keyboard/ergodox/layout/repa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */

/** description
* A Dvorak layout adapted from the default Kinesis layout. The position of
* the symbol keys on the function layer was (roughly) taken from the Arensito
* layout.
*
* Implements the "layout" section of '.../firmware/keyboard.h'
*/


#include "./common/definitions.h"

// ----------------------------------------------------------------------------
// matrix control
// ----------------------------------------------------------------------------

#include "./common/exec_key.c.h"


// ----------------------------------------------------------------------------
// LED control
// ----------------------------------------------------------------------------

void kb__led__logical_on(char led) {
switch(led) {
case 'N': kb__led__on(1); break; // numlock
case 'C': kb__led__on(2); break; // capslock
case 'S': kb__led__on(3); break; // scroll lock
case 'O': break; // compose
case 'K': break; // kana
};
}

void kb__led__logical_off(char led) {
switch(led) {
case 'N': kb__led__off(1); break; // numlock
case 'C': kb__led__off(2); break; // capslock
case 'S': kb__led__off(3); break; // scroll lock
case 'O': break; // compose
case 'K': break; // kana
};
}


// ----------------------------------------------------------------------------
// keys
// ----------------------------------------------------------------------------

#include "./common/keys.c.h"

KEYS__LAYER__NUM_PUSH(10, 3);
KEYS__LAYER__NUM_POP(10);


// ----------------------------------------------------------------------------
// layout
// ----------------------------------------------------------------------------

#include "./common/matrix.h"


static _layout_t _layout = {

// ............................................................................

MATRIX_LAYER( // layer 0 : default
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
equal, 1, 2, 3, 4, 5, esc,
tab, quote, comma, period, p, y, lpu1l1,
bkslash, a, o, e, u, i,
shL2kcap, semicol, q, j, k, x, lpupo1l1,
guiL, grave, bkslash, arrowL, arrowR,
ctrlL, altL,
nop, nop, home,
bs, del, end,
// right hand ..... ......... ......... ......... ......... ......... .........
btldr, 6, 7, 8, 9, 0, dash,
MclkL, f, g, c, r, l, brktR,
d, h, t, n, s, slash,
tnkro, b, m, w, v, z, shR2kcap,
arrowL, arrowD, arrowU, arrowR, guiR,
altR, ctrlR,
pageU, nop, nop,
pageD, enter, space ),

// ............................................................................

MATRIX_LAYER( // layer 1 : function and symbol keys
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
nop, F1, F2, F3, F4, F5, F11,
transp, braceL, braceR, brktL, brktR, nop, lpo1l1,
transp, semicol, slash, dash, kp0, colon,
transp, kp6, kp7, kp8, kp9, plus, lpupo2l2,
transp, transp, transp, transp, transp,
transp, transp,
transp, transp, transp,
transp, transp, transp,
// right hand ..... ......... ......... ......... ......... ......... .........
F12, F6, F7, F8, F9, F10, power,
transp, nop, undersc, lessThan, grtrThan, dollar, volumeU,
bkslash, kp1, parenL, parenR, equal, volumeD,
lpupo2l2, asterisk, kp2, kp3, kp4, kp5, mute,
transp, transp, transp, transp, transp,
transp, transp,
transp, transp, transp,
transp, transp, transp ),

// ............................................................................

MATRIX_LAYER( // layer 2 : keyboard functions
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
btldr, nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop,
nop, nop,
nop, nop, nop,
nop, nop, nop,
// right hand ..... ......... ......... ......... ......... ......... .........
nop, nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop, nop, nop,
nop, nop, nop, nop, nop,
nop, nop,
nop, nop, nop,
nop, nop, nop ),

// ............................................................................

MATRIX_LAYER( // layer 3 : numpad
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
transp, transp, transp, transp, transp, transp, transp,
transp, transp, transp, transp, transp, transp, transp,
transp, transp, transp, transp, transp, transp,
transp, transp, transp, transp, transp, transp, transp,
transp, ins, transp, transp, transp,
transp, transp,
transp, transp, transp,
transp, transp, transp,
// right hand ..... ......... ......... ......... ......... ......... .........
numPop, transp, numPop, equal, kpDiv, kpMul, transp,
transp, transp, kp7, kp8, kp9, kpSub, transp,
transp, kp4, kp5, kp6, kpAdd, transp,
transp, transp, kp1, kp2, kp3, kpEnter, transp,
transp, transp, period, kpEnter, transp,
transp, transp,
transp, transp, transp,
transp, transp, kp0 ),

// ............................................................................
};

13 changes: 8 additions & 5 deletions firmware/keyboard/ergodox/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ void kb__led__on(uint8_t led) {
case 3: (DDRB |= (1<<7)); break; // bottommost
case 4: break;
case 5: break;
case 6: (PORTD |= (1<<6)); break; // teensy
};
}

void kb__led__off(uint8_t led) {
switch(led) {
case 1: (DDRB &= ~(1<<5)); break; // topmost
case 2: (DDRB &= ~(1<<6)); break; // middle
case 3: (DDRB &= ~(1<<7)); break; // bottommost
case 4: break;
case 5: break;
case 1: (DDRB &= ~(1<<5)); break; // topmost
case 2: (DDRB &= ~(1<<6)); break; // middle
case 3: (DDRB &= ~(1<<7)); break; // bottommost
case 4: break;
case 5: break;
case 6: (PORTD &= ~(1<<6)); break; // teensy
};
}

Expand All @@ -55,6 +57,7 @@ void kb__led__set(uint8_t led, float n) {
case 3: (OCR1C = (uint8_t)((n) * 0xFF)); break; // bottommost
case 4: break;
case 5: break;
case 6: break;
};
}

Expand Down
9 changes: 7 additions & 2 deletions firmware/keyboard/ergodox/options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ F_CPU := 16000000
# processor speed, in Hz; max value is 16000000 (16MHz); must match
# initialization in source

KEYBOARD_LAYOUT := qwerty--kinesis-mod
KEYBOARD_LAYOUT := repa
# default layout for this keyboard

KEYBOARD_LAYOUTS := \
colemak--kinesis-mod \
dvorak--kinesis-mod \
qwerty--kinesis-mod
qwerty--kinesis-mod \
repa
# a list of all available layouts for this keyboard

MOUSE_ENABLE := true
NKRO_ENABLE := true

# -----------------------------------------------------------------------------

$(call include_options_once,lib/eeprom)
$(call include_options_once,lib/twi)
$(call include_options_once,lib/layout/eeprom-macro)
$(call include_options_once,lib/layout/key-functions)
$(call include_options_once,lib/layout/mouse)
$(call include_options_once,lib/layout/layer-stack)

# -----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions firmware/lib/layout/key-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void key_functions__toggle_capslock (void);
void key_functions__type_byte_hex (uint8_t byte);
void key_functions__type_string (const char * string);

// nkro
void key_functions__toggle_nkro (void);

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion firmware/lib/layout/key-functions/device/atmega32u4.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ void key_functions__jump_to_bootloader(void) {
PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
asm volatile("jmp 0x7E00");
}

6 changes: 6 additions & 0 deletions firmware/lib/layout/key-functions/special.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ void key_functions__toggle_capslock(void) {
usb__kb__send_report();
}

// nkro toggle

void key_functions__toggle_nkro(void) {
usb__kb__toggle_nkro();
}

/*
* TODO: try using number pad numbers; see how it works
*/
Expand Down
24 changes: 24 additions & 0 deletions firmware/lib/layout/mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Gyuri Horak <dyuri@horak.hu>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/dyuri/ergodox-firmware>
* ------------------------------------------------------------------------- */

/**
* Mouse related key functions
*
* Prefix: `key_functions__`
*/


#ifndef ERGODOX_FIRMWARE__FIRMWARE__LIB__LAYOUT__MOUSE__H
#define ERGODOX_FIRMWARE__FIRMWARE__LIB__LAYOUT__MOUSE__H
// ----------------------------------------------------------------------------

#include <stdint.h>

void key_functions__mouse_left_click (void);
void key_functions__mouse_buttons(uint8_t left, uint8_t middle, uint8_t right);

// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__LIB__LAYOUT__MOUSE__H
28 changes: 28 additions & 0 deletions firmware/lib/layout/mouse/mouse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Gyuri Horak <dyuri@horak.hu>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/dyuri/ergodox-firmware>
* ------------------------------------------------------------------------- */

#include <stdbool.h>
#include "../../../../firmware/lib/usb.h"
#include "../../../../firmware/keyboard.h"

//
void key_functions__mouse_buttons(uint8_t left, uint8_t middle, uint8_t right)
{
uint8_t mask=0;

if (left) mask |= 1;
if (middle) mask |= 4;
if (right) mask |= 2;

usb__m__buttons(mask);
}

// single left click (?)
void key_functions__mouse_left_click(void) {
usb__m__send(0, 0, 0, 0, MOUSE_BTN1);
usb__m__send(0, 0, 0, 0, 0);
}

16 changes: 16 additions & 0 deletions firmware/lib/layout/mouse/options.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2013 Gyuri Horak <dyuri@horak.hu>
# Released under The MIT License (see "doc/licenses/MIT.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------

##
# mouse options
#
# This file is meant to be included by the using '.../options.mk'
#

ifdef MOUSE_ENABLE
SRC += $(wildcard $(CURDIR)/*.c)
endif

11 changes: 11 additions & 0 deletions firmware/lib/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ bool usb__kb__read_key (uint8_t keycode);
bool usb__kb__read_led (char led);
uint8_t usb__kb__send_report (void);

void usb__kb__toggle_nkro (void);

// --- mouse ---
#define MOUSE_BTN1 (1<<0)
#define MOUSE_BTN2 (1<<1)
#define MOUSE_BTN3 (1<<2)
#define MOUSE_BTN4 (1<<3)
#define MOUSE_BTN5 (1<<4)

void usb__m__send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons);
void usb__m__buttons(uint8_t buttons);

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion firmware/lib/usb/atmega32u4/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

#include <stdbool.h>
#include "./keyboard/from-pjrc/usb_keyboard.h"
#include "./keyboard/from-pjrc/usb.h"
#include "../../usb.h"

// ----------------------------------------------------------------------------
Expand Down
Loading