ADD: keymap macro for human to read easier
ADD: controller.h for controller board definition(teensy) ADD: debug toggle
This commit is contained in:
@@ -116,15 +116,15 @@ CSTANDARD = -std=gnu99
|
||||
|
||||
|
||||
# Place -D or -U options here for C sources
|
||||
CDEFS = -DF_CPU=$(F_CPU)UL
|
||||
CDEFS = -DF_CPU=$(F_CPU)UL -DDESCRIPTION=$(DESCRIPTION)
|
||||
|
||||
|
||||
# Place -D or -U options here for ASM sources
|
||||
ADEFS = -DF_CPU=$(F_CPU)
|
||||
ADEFS = -DF_CPU=$(F_CPU) -DDESCRIPTION=$(DESCRIPTION)
|
||||
|
||||
|
||||
# Place -D or -U options here for C++ sources
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL
|
||||
CPPDEFS = -DF_CPU=$(F_CPU)UL -DDESCRIPTION=$(DESCRIPTION)
|
||||
#CPPDEFS += -D__STDC_LIMIT_MACROS
|
||||
#CPPDEFS += -D__STDC_CONSTANT_MACROS
|
||||
|
||||
|
10
controller_teensy.h
Normal file
10
controller_teensy.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef TEENSY_H
|
||||
#define TEENSY_H 1
|
||||
|
||||
// for Teensy/Teensy++ 2.0
|
||||
#define DEBUG_LED 1
|
||||
#define DEBUG_LED_CONFIG (DDRD |= (1<<6))
|
||||
#define DEBUG_LED_ON (PORTD |= (1<<6))
|
||||
#define DEBUG_LED_OFF (PORTD &= ~(1<<6))
|
||||
|
||||
#endif
|
19
debug.h
Normal file
19
debug.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H 1
|
||||
|
||||
#include "print.h"
|
||||
|
||||
|
||||
#define debug(s) if(debug_enable) print(s)
|
||||
#define debug_hex(c) if(debug_enable) phex(c)
|
||||
#define debug_hex16(i) if(debug_enable) phex(i)
|
||||
#define debug_bin(c) if(debug_enable) pbin(c)
|
||||
#define debug_bin_reverse(c) if(debug_enable) pbin_reverse(c)
|
||||
|
||||
|
||||
bool debug_enable;
|
||||
bool debug_matrix;
|
||||
bool debug_keyboard;
|
||||
bool debug_mouse;
|
||||
|
||||
#endif
|
@@ -39,6 +39,7 @@
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
DESCRIPTION = 't.m.k. firmware for HHKB pro\n'
|
||||
|
||||
# Target file name (without extension).
|
||||
TARGET = tmk_hhkb
|
||||
|
6
hhkb/controller.h
Normal file
6
hhkb/controller.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef CONTROLLER_H
|
||||
#define CONTROLLER_H 1
|
||||
|
||||
#include "controller_teensy.h"
|
||||
|
||||
#endif
|
297
hhkb/keymap.c
297
hhkb/keymap.c
File diff suppressed because it is too large
Load Diff
@@ -35,12 +35,14 @@ static int bit_pop(uint8_t bits);
|
||||
|
||||
|
||||
inline
|
||||
int matrix_rows(void) {
|
||||
int matrix_rows(void)
|
||||
{
|
||||
return MATRIX_ROWS;
|
||||
}
|
||||
|
||||
inline
|
||||
int matrix_cols(void) {
|
||||
int matrix_cols(void)
|
||||
{
|
||||
return MATRIX_COLS;
|
||||
}
|
||||
|
||||
@@ -55,8 +57,8 @@ void matrix_init(void)
|
||||
PORTE = 0xC0;
|
||||
|
||||
// initialize matrix state: all keys off
|
||||
for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0xFF;
|
||||
for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0xFF;
|
||||
for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
|
||||
for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
|
||||
matrix = _matrix0;
|
||||
matrix_prev = _matrix1;
|
||||
}
|
||||
@@ -76,9 +78,9 @@ int matrix_scan(void)
|
||||
KEY_ENABLE;
|
||||
_delay_us(10); // from logic analyzer chart
|
||||
if (KEY_ON) {
|
||||
matrix[row] &= ~(1<<col);
|
||||
} else {
|
||||
matrix[row] |= (1<<col);
|
||||
} else {
|
||||
matrix[row] &= ~(1<<col);
|
||||
}
|
||||
KEY_UNABLE;
|
||||
_delay_us(150); // from logic analyzer chart
|
||||
@@ -87,7 +89,8 @@ int matrix_scan(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool matrix_is_modified(void) {
|
||||
bool matrix_is_modified(void)
|
||||
{
|
||||
for (int i = 0; i < MATRIX_ROWS; i++) {
|
||||
if (matrix[i] != matrix_prev[i])
|
||||
return true;
|
||||
@@ -96,16 +99,25 @@ bool matrix_is_modified(void) {
|
||||
}
|
||||
|
||||
inline
|
||||
bool matrix_has_ghost(void) {
|
||||
bool matrix_has_ghost(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
uint16_t matrix_get_row(int row) {
|
||||
bool matrix_is_on(int row, int col)
|
||||
{
|
||||
return (matrix[row] & (1<<col));
|
||||
}
|
||||
|
||||
inline
|
||||
uint16_t matrix_get_row(int row)
|
||||
{
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_print(void) {
|
||||
void matrix_print(void)
|
||||
{
|
||||
print("\nr/c 01234567\n");
|
||||
for (int row = 0; row < matrix_rows(); row++) {
|
||||
phex(row); print(": ");
|
||||
@@ -117,20 +129,24 @@ void matrix_print(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int matrix_key_count(void) {
|
||||
int matrix_key_count(void)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < MATRIX_ROWS; i++) {
|
||||
count += bit_pop(~matrix[i]);
|
||||
count += bit_pop(matrix[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
inline
|
||||
static bool matrix_has_ghost_in_row(int row) {
|
||||
static bool matrix_has_ghost_in_row(int row)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static int bit_pop(uint8_t bits) {
|
||||
inline
|
||||
static int bit_pop(uint8_t bits)
|
||||
{
|
||||
int c;
|
||||
for (c = 0; bits; c++)
|
||||
bits &= bits -1;
|
||||
|
171
key_process.c
171
key_process.c
@@ -1,28 +1,24 @@
|
||||
// TODO: clean unused headers
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include "usb.h"
|
||||
#include "usb_keyboard.h"
|
||||
#include "usb_mouse.h"
|
||||
#include "usb_keycodes.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "util.h"
|
||||
#include "jump_bootloader.h"
|
||||
#include "matrix_skel.h"
|
||||
#include "keymap_skel.h"
|
||||
#include "controller.h"
|
||||
|
||||
#include "key_process.h"
|
||||
|
||||
|
||||
// for Teensy/Teensy++ 2.0
|
||||
#define LED_CONFIG (DDRD |= (1<<6))
|
||||
#define LED_ON (PORTD |= (1<<6))
|
||||
#define LED_OFF (PORTD &= ~(1<<6))
|
||||
|
||||
#define MOUSE_MOVE_UNIT 10
|
||||
#define MOUSE_DELAY_MS 200
|
||||
#define MOUSE_DELAY_ACC 5
|
||||
#define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10)
|
||||
#define MOUSE_DELAY_TIME 255
|
||||
#define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 5))
|
||||
|
||||
|
||||
// TODO: refactoring
|
||||
@@ -35,7 +31,7 @@ void proc_matrix(void) {
|
||||
uint8_t mouse_btn = 0;
|
||||
int8_t mouse_x = 0;
|
||||
int8_t mouse_y = 0;
|
||||
int8_t mouse_wheel = 0;
|
||||
int8_t mouse_vwheel = 0;
|
||||
int8_t mouse_hwheel = 0;
|
||||
int fn_bits = 0;
|
||||
|
||||
@@ -43,50 +39,51 @@ void proc_matrix(void) {
|
||||
modified = matrix_is_modified();
|
||||
|
||||
if (modified) {
|
||||
matrix_print();
|
||||
|
||||
if (debug_matrix) matrix_print();
|
||||
#ifdef DEBUG_LED
|
||||
// LED flash for debug
|
||||
LED_CONFIG;
|
||||
LED_ON;
|
||||
DEBUG_LED_CONFIG;
|
||||
DEBUG_LED_ON;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (matrix_has_ghost()) {
|
||||
// should send error?
|
||||
print("matrix has ghost!!\n");
|
||||
debug("matrix has ghost!!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
usb_keyboard_clear();
|
||||
for (int row = 0; row < matrix_rows(); row++) {
|
||||
for (int col = 0; col < matrix_cols(); col++) {
|
||||
if (matrix_get_row(row) & 1<<col) continue;
|
||||
if (!matrix_is_on(row, col)) continue;
|
||||
|
||||
uint8_t code = keymap_get_keycode(row, col);
|
||||
if (code == KB_NO) {
|
||||
code = keymap_get_keycodel(0, row, col);
|
||||
if (FN_0 <= code && code <= FN_7) {
|
||||
fn_bits |= 1<<(code - FN_0);
|
||||
}
|
||||
} else if (KB_LCTRL <= code && code <= KB_RGUI) {
|
||||
// modifier keys(0xE0-0xE7)
|
||||
keyboard_modifier_keys |= 1<<(code & 0x07);
|
||||
} else if (code >= MS_UP) {
|
||||
// do nothing
|
||||
} else if (IS_MOD(code)) {
|
||||
keyboard_modifier_keys |= MOD_BIT(code);
|
||||
} else if (IS_MOUSE(code)) {
|
||||
// mouse
|
||||
if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_RIGHT) mouse_x += MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_BTN1) mouse_btn |= 1<<0;
|
||||
if (code == MS_BTN2) mouse_btn |= 1<<1;
|
||||
if (code == MS_BTN3) mouse_btn |= 1<<2;
|
||||
if (code == MS_BTN4) mouse_btn |= 1<<3;
|
||||
if (code == MS_BTN5) mouse_btn |= 1<<4;
|
||||
if (code == MS_WH_UP) mouse_wheel += 1;
|
||||
if (code == MS_WH_DOWN) mouse_wheel -= 1;
|
||||
if (code == MS_UP)
|
||||
mouse_y -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL;
|
||||
if (code == MS_DOWN)
|
||||
mouse_y += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL;
|
||||
if (code == MS_LEFT)
|
||||
mouse_x -= MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL;
|
||||
if (code == MS_RIGHT)
|
||||
mouse_x += MOUSE_MOVE_UNIT + MOUSE_MOVE_ACCEL;
|
||||
if (code == MS_BTN1) mouse_btn |= BIT_BTN1;
|
||||
if (code == MS_BTN2) mouse_btn |= BIT_BTN2;
|
||||
if (code == MS_BTN3) mouse_btn |= BIT_BTN3;
|
||||
if (code == MS_BTN4) mouse_btn |= BIT_BTN4;
|
||||
if (code == MS_BTN5) mouse_btn |= BIT_BTN5;
|
||||
if (code == MS_WH_UP) mouse_vwheel += 1;
|
||||
if (code == MS_WH_DOWN) mouse_vwheel -= 1;
|
||||
if (code == MS_WH_LEFT) mouse_hwheel -= 1;
|
||||
if (code == MS_WH_RIGHT) mouse_hwheel += 1;
|
||||
} else if (FN_0 <= code && code <= FN_7) {
|
||||
fn_bits |= 1<<(code - FN_0);
|
||||
} else if (IS_FN(code)) {
|
||||
fn_bits |= FN_BIT(code);
|
||||
} else {
|
||||
// normal keys
|
||||
if (key_index < 6)
|
||||
@@ -98,41 +95,103 @@ void proc_matrix(void) {
|
||||
keymap_fn_proc(fn_bits);
|
||||
|
||||
// when 4 left modifier keys down
|
||||
if (keyboard_modifier_keys == (MOD_LCTRL | MOD_LSHIFT | MOD_LALT | MOD_LGUI)) {
|
||||
// cancel all keys
|
||||
keyboard_modifier_keys = 0;
|
||||
for (int i = 0; i < 6; i++) keyboard_keys[i] = KB_NO;
|
||||
usb_keyboard_send();
|
||||
|
||||
print("jump to bootloader...\n");
|
||||
_delay_ms(100);
|
||||
jump_bootloader(); // not return
|
||||
if (keymap_is_special_mode(fn_bits)) {
|
||||
switch (keyboard_keys[0]) {
|
||||
case KB_B: // bootloader
|
||||
usb_keyboard_clear();
|
||||
usb_keyboard_send();
|
||||
print_enable = true;
|
||||
print("jump to bootloader...\n");
|
||||
_delay_ms(1000);
|
||||
jump_bootloader(); // not return
|
||||
break;
|
||||
case KB_D: // debug all toggle
|
||||
usb_keyboard_clear();
|
||||
usb_keyboard_send();
|
||||
debug_enable = !debug_enable;
|
||||
if (debug_enable) {
|
||||
print("debug enabled.\n");
|
||||
print_enable = true;
|
||||
debug_matrix = true;
|
||||
debug_keyboard = true;
|
||||
debug_mouse = true;
|
||||
} else {
|
||||
print("debug disabled.\n");
|
||||
print_enable = false;
|
||||
debug_matrix = false;
|
||||
debug_keyboard = false;
|
||||
debug_mouse = false;
|
||||
}
|
||||
_delay_ms(1000);
|
||||
break;
|
||||
case KB_X: // debug matrix toggle
|
||||
usb_keyboard_clear();
|
||||
usb_keyboard_send();
|
||||
debug_matrix = !debug_matrix;
|
||||
if (debug_matrix)
|
||||
print("debug matrix enabled.\n");
|
||||
else
|
||||
print("debug matrix disabled.\n");
|
||||
_delay_ms(1000);
|
||||
break;
|
||||
case KB_K: // debug keyboard toggle
|
||||
usb_keyboard_clear();
|
||||
usb_keyboard_send();
|
||||
debug_keyboard = !debug_keyboard;
|
||||
if (debug_keyboard)
|
||||
print("debug keyboard enabled.\n");
|
||||
else
|
||||
print("debug keyboard disabled.\n");
|
||||
_delay_ms(1000);
|
||||
break;
|
||||
case KB_M: // debug mouse toggle
|
||||
usb_keyboard_clear();
|
||||
usb_keyboard_send();
|
||||
debug_mouse = !debug_mouse;
|
||||
if (debug_mouse)
|
||||
print("debug mouse enabled.\n");
|
||||
else
|
||||
print("debug mouse disabled.\n");
|
||||
_delay_ms(1000);
|
||||
break;
|
||||
case KB_V: // print version & information
|
||||
usb_keyboard_clear();
|
||||
usb_keyboard_send();
|
||||
print(XSTR(DESCRIPTION));
|
||||
_delay_ms(1000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mouse_x || mouse_y || mouse_wheel || mouse_hwheel || mouse_btn != mouse_buttons) {
|
||||
// send mouse packet to host
|
||||
if (mouse_x || mouse_y || mouse_vwheel || mouse_hwheel || mouse_btn != mouse_buttons) {
|
||||
mouse_buttons = mouse_btn;
|
||||
usb_mouse_move(mouse_x, mouse_y, mouse_wheel, mouse_hwheel);
|
||||
usb_mouse_print(mouse_x, mouse_y, mouse_wheel, mouse_hwheel);
|
||||
if (mouse_x && mouse_y)
|
||||
usb_mouse_move(mouse_x*0.7, mouse_y*0.7, mouse_vwheel, mouse_hwheel);
|
||||
else
|
||||
usb_mouse_move(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel);
|
||||
usb_mouse_print(mouse_x, mouse_y, mouse_vwheel, mouse_hwheel);
|
||||
|
||||
// acceleration
|
||||
_delay_ms(MOUSE_DELAY_MS >> (mouse_repeat < MOUSE_DELAY_ACC ? mouse_repeat : MOUSE_DELAY_ACC));
|
||||
_delay_ms(MOUSE_DELAY_MS);
|
||||
mouse_repeat++;
|
||||
} else {
|
||||
mouse_repeat = 0;
|
||||
}
|
||||
|
||||
|
||||
// send keys to host
|
||||
// send key packet to host
|
||||
if (modified) {
|
||||
if (key_index > 6) {
|
||||
//Rollover
|
||||
}
|
||||
usb_keyboard_send();
|
||||
|
||||
usb_keyboard_print();
|
||||
#ifdef DEBUG_LED
|
||||
// LED flash for debug
|
||||
LED_CONFIG;
|
||||
LED_OFF;
|
||||
DEBUG_LED_CONFIG;
|
||||
DEBUG_LED_OFF;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ uint8_t keymap_get_keycodel(int layer, int row, int col);
|
||||
int keymap_get_layer(void);
|
||||
int keymap_set_layer(int layer);
|
||||
|
||||
bool keymap_is_special_mode(int fn_bits);
|
||||
/* process Fn keys. This.should be called every scan. */
|
||||
void keymap_fn_proc(int fn_bits);
|
||||
|
||||
|
@@ -15,6 +15,8 @@ int matrix_scan(void);
|
||||
bool matrix_is_modified(void);
|
||||
/* whether ghosting occur on matrix. */
|
||||
bool matrix_has_ghost(void);
|
||||
/* whether a swtich is on */
|
||||
bool matrix_is_on(int row, int col);
|
||||
/* matrix state on row */
|
||||
uint16_t matrix_get_row(int row);
|
||||
/* count keys pressed */
|
||||
|
43
tmk.c
43
tmk.c
@@ -24,30 +24,25 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// TODO: clean unused headers
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include "usb.h"
|
||||
#include "usb_keyboard.h"
|
||||
#include "usb_mouse.h"
|
||||
#include "print.h"
|
||||
#include "matrix_skel.h"
|
||||
#include "keymap.h"
|
||||
#include "jump_bootloader.h"
|
||||
|
||||
#include "key_process.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "util.h"
|
||||
#include "controller.h"
|
||||
|
||||
|
||||
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
|
||||
|
||||
// TODO: should go to hardware dependent file
|
||||
// for Teensy/Teensy++ 2.0
|
||||
#define LED_CONFIG (DDRD |= (1<<6))
|
||||
#define LED_ON (PORTD |= (1<<6))
|
||||
#define LED_OFF (PORTD &= ~(1<<6))
|
||||
|
||||
bool debug_enable = false;
|
||||
bool debug_matrix = false;
|
||||
bool debug_keyboard = false;
|
||||
bool debug_mouse = false;
|
||||
|
||||
uint16_t idle_count=0;
|
||||
|
||||
@@ -74,20 +69,26 @@ int main(void)
|
||||
|
||||
matrix_init();
|
||||
matrix_scan();
|
||||
// debug on when 4 keys are pressed
|
||||
// debug on by pressing down any 4 keys during boot time.
|
||||
if (matrix_key_count() == 4) print_enable = true;
|
||||
|
||||
/* wait for debug pipe to print greetings. */
|
||||
/* wait for debug pipe ready */
|
||||
if (print_enable) {
|
||||
for (int i =0; i < 6; i++) {
|
||||
LED_CONFIG;
|
||||
LED_ON;
|
||||
#ifdef DEBUG_LED
|
||||
for (int i = 0; i < 6; i++) {
|
||||
DEBUG_LED_CONFIG;
|
||||
DEBUG_LED_ON;
|
||||
_delay_ms(500);
|
||||
LED_OFF;
|
||||
DEBUG_LED_OFF;
|
||||
_delay_ms(500);
|
||||
}
|
||||
#else
|
||||
_delay_ms(6000);
|
||||
#endif
|
||||
}
|
||||
print("\nt.m.k. keyboard 1.2\n");
|
||||
// print description
|
||||
print(XSTR(DESCRIPTION));
|
||||
|
||||
while (1) {
|
||||
proc_matrix();
|
||||
_delay_ms(2);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include "usb_keyboard.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
static bool is_sent = false;
|
||||
@@ -112,6 +113,7 @@ bool usb_keyboard_has_mod(void) {
|
||||
}
|
||||
|
||||
void usb_keyboard_print(void) {
|
||||
if (!debug_keyboard) return;
|
||||
print("\nkeys: ");
|
||||
for (int i = 0; i < 6; i++) { phex(keyboard_keys[i]); print(" "); }
|
||||
print("\n");
|
||||
|
@@ -11,16 +11,18 @@
|
||||
#define KEYBOARD_SIZE 8
|
||||
#define KEYBOARD_BUFFER EP_DOUBLE_BUFFER
|
||||
|
||||
// TODO: move to usb_keycodes.h ?
|
||||
// modifier bits
|
||||
#define MOD_LCTRL (1<<0)
|
||||
#define MOD_LSHIFT (1<<1)
|
||||
#define MOD_LALT (1<<2)
|
||||
#define MOD_LGUI (1<<3)
|
||||
#define MOD_RCTRL (1<<4)
|
||||
#define MOD_RSHIFT (1<<5)
|
||||
#define MOD_RALT (1<<6)
|
||||
#define MOD_RGUI (1<<7)
|
||||
#define BIT_LCTRL (1<<0)
|
||||
#define BIT_LSHIFT (1<<1)
|
||||
#define BIT_LALT (1<<2)
|
||||
#define BIT_LGUI (1<<3)
|
||||
#define BIT_RCTRL (1<<4)
|
||||
#define BIT_RSHIFT (1<<5)
|
||||
#define BIT_RALT (1<<6)
|
||||
#define BIT_RGUI (1<<7)
|
||||
#define BIT_LCTL BIT_LCTRL
|
||||
#define BIT_RCTL BIT_RCTRL
|
||||
#define BIT_LSFT BIT_LSHIFT
|
||||
#define BIT_RSFT BIT_RSHIFT
|
||||
|
||||
|
||||
// TODO: change variable name: usb_keyboard_ or usb_kb_
|
||||
|
@@ -36,6 +36,55 @@
|
||||
#ifndef USB_KEYCODES_H
|
||||
#define USB_KEYCODES_H
|
||||
|
||||
#define IS_ERROR(code) (KB_ROLL_OVER <= (code) && (code) <= KB_UNDEFINED)
|
||||
#define IS_KEY(code) (KB_A <= (code) && (code) <= KP_HEXADECIMAL)
|
||||
#define IS_MOD(code) (KB_LCTRL <= (code) && (code) <= KB_RGUI)
|
||||
#define IS_FN(code) (FN_0 <= (code) && (code) <= FN_7)
|
||||
#define IS_MOUSE(code) (MS_UP <= (code) && (code) <= MS_WH_RIGHT)
|
||||
#define IS_MOUSE_MOVE(code) (MS_UP <= (code) && (code) <= MS_RIGHT)
|
||||
#define IS_MOUSE_BUTTON(code) (MS_BTN1 <= (code) && (code) <= MS_BTN5)
|
||||
#define IS_MOUSE_WHEEL(code) (MS_WH_UP <= (code) && (code) <= MS_WH_RIGHT)
|
||||
|
||||
#define MOD_BIT(code) (1<<((code) & 0x07))
|
||||
#define FN_BIT(code) (1<<((code) - FN_0))
|
||||
|
||||
|
||||
// short names
|
||||
#define KB_LCTL KB_LCTRL
|
||||
#define KB_RCTL KB_RCTRL
|
||||
#define KB_LSFT KB_LSHIFT
|
||||
#define KB_RSFT KB_RSHIFT
|
||||
#define KB_ESC KB_ESCAPE
|
||||
#define KB_BSPC KB_BSPACE
|
||||
#define KB_ENT KB_ENTER
|
||||
#define KB_DEL KB_DELETE
|
||||
#define KB_INS KB_INSERT
|
||||
#define KB_CAPS KB_CAPSLOCK
|
||||
#define KB_RGHT KB_RIGHT
|
||||
#define KB_PGDN KB_PGDOWN
|
||||
#define KB_PSCR KB_PSCREEN
|
||||
#define KB_SLCK KB_SCKLOCK
|
||||
#define KB_BRK KB_BREAK
|
||||
#define KB_SPC KB_SPACE
|
||||
#define KB_MINS KB_MINUS
|
||||
#define KB_EQL KB_EQUAL
|
||||
#define KB_GRV KB_GRAVE
|
||||
#define KB_RBRC KB_RBRACKET
|
||||
#define KB_LBRC KB_LBRACKET
|
||||
#define KB_COMM KB_COMMA
|
||||
#define KB_BSLS KB_BSLASH
|
||||
#define KB_SLSH KB_SLASH
|
||||
#define KB_SCLN KB_SCOLON
|
||||
#define KB_PWR KB_POWER
|
||||
#define KP_SLSH KP_SLASH
|
||||
#define KP_ASTR KP_ASTERISK
|
||||
#define KP_MINS KP_MINUS
|
||||
#define MS_RGHT MS_RIGHT
|
||||
#define MS_WH_U MS_WH_UP
|
||||
#define MS_WH_D MS_WH_DOWN
|
||||
#define MS_WH_L MS_WH_LEFT
|
||||
#define MS_WH_R MS_WH_RIGHT
|
||||
|
||||
|
||||
enum keycodes {
|
||||
KB_NO = 0,
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <util/delay.h>
|
||||
#include "usb_mouse.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
static bool is_sent = false;
|
||||
@@ -76,6 +77,7 @@ bool usb_mouse_is_sent(void) {
|
||||
}
|
||||
|
||||
void usb_mouse_print(int8_t mouse_x, int8_t mouse_y, int8_t wheel_v, int8_t wheel_h) {
|
||||
if (!debug_mouse) return;
|
||||
print("mouse btn|x y v h: ");
|
||||
phex(mouse_buttons); print("|");
|
||||
phex(mouse_x); print(" ");
|
||||
|
@@ -11,6 +11,13 @@
|
||||
#define MOUSE_SIZE 8
|
||||
#define MOUSE_BUFFER EP_DOUBLE_BUFFER
|
||||
|
||||
#define BIT_BTN1 (1<<0)
|
||||
#define BIT_BTN2 (1<<1)
|
||||
#define BIT_BTN3 (1<<2)
|
||||
#define BIT_BTN4 (1<<3)
|
||||
#define BIT_BTN5 (1<<4)
|
||||
|
||||
|
||||
extern uint8_t mouse_buttons;
|
||||
extern uint8_t mouse_protocol;
|
||||
|
||||
|
Reference in New Issue
Block a user