add mouse function.
This commit is contained in:
parent
e7c6839d2d
commit
d3b1af9572
14 changed files with 281 additions and 123 deletions
139
mykey.c
139
mykey.c
|
|
@ -30,7 +30,9 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "usb_device.h"
|
||||
#include "usb.h"
|
||||
#include "usb_keyboard.h"
|
||||
#include "usb_mouse.h"
|
||||
#include "print.h"
|
||||
#include "matrix.h"
|
||||
#include "keymap.h"
|
||||
|
|
@ -50,16 +52,9 @@ uint16_t idle_count=0;
|
|||
|
||||
int main(void)
|
||||
{
|
||||
bool modified = false;
|
||||
bool has_ghost = false;
|
||||
uint8_t key_index = 0;
|
||||
|
||||
// set for 16 MHz clock
|
||||
CPU_PRESCALE(0);
|
||||
|
||||
matrix_init();
|
||||
|
||||
|
||||
// Initialize the USB, and then wait for the host to set configuration.
|
||||
// If the Teensy is powered without a PC connected to the USB port,
|
||||
// this will wait forever.
|
||||
|
|
@ -78,69 +73,21 @@ int main(void)
|
|||
TCCR0B = 0x05;
|
||||
TIMSK0 = (1<<TOIE0);
|
||||
|
||||
|
||||
matrix_init();
|
||||
print("firmware 0.2 for t.m.k.\n");
|
||||
|
||||
bool modified = false;
|
||||
bool has_ghost = false;
|
||||
int key_index = 0;
|
||||
int loop_count = 0;
|
||||
int layer = 0;
|
||||
while (1) {
|
||||
int layer = 0;
|
||||
|
||||
matrix_scan();
|
||||
layer = get_layer();
|
||||
|
||||
modified = matrix_is_modified();
|
||||
has_ghost = matrix_has_ghost();
|
||||
|
||||
// doesnt send keys during ghost occurs
|
||||
if (modified && !has_ghost) {
|
||||
key_index = 0;
|
||||
keyboard_modifier_keys = 0;
|
||||
for (int i = 0; i < 6; i++) keyboard_keys[i] = KB_NO;
|
||||
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
if (matrix[row] & 1<<col) continue;
|
||||
|
||||
uint8_t code = get_keycode(layer, row, col);
|
||||
if (code == KB_NO) {
|
||||
continue;
|
||||
} else if (KB_LCTRL <= code && code <= KB_RGUI) {
|
||||
// modifier keycode: 0xE0-0xE7
|
||||
keyboard_modifier_keys |= 1<<(code & 0x07);
|
||||
} else {
|
||||
if (key_index < 6)
|
||||
keyboard_keys[key_index] = code;
|
||||
key_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run bootloader 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(1000);
|
||||
jump_bootloader();
|
||||
}
|
||||
|
||||
if (key_index > 6) {
|
||||
//Rollover
|
||||
}
|
||||
|
||||
usb_keyboard_send();
|
||||
|
||||
|
||||
// variables shared with interrupt routines must be
|
||||
// accessed carefully so the interrupt routine doesn't
|
||||
// try to use the variable in the middle of our access
|
||||
cli();
|
||||
//idle_count = 0;
|
||||
sei();
|
||||
}
|
||||
|
||||
// print matrix state for debug
|
||||
if (modified) {
|
||||
print_matrix();
|
||||
|
|
@ -150,27 +97,61 @@ int main(void)
|
|||
PORTD |= 1<<PD6;
|
||||
}
|
||||
|
||||
/*
|
||||
// print counts for debug
|
||||
if ((loop_count % 0x1000) == 0) {
|
||||
//print(".");
|
||||
print("idle_count: "); phex((idle_count & 0xFF00) >> 8); phex(idle_count & 0xFF); print("\n");
|
||||
print("loop_count: "); phex((loop_count & 0xFF00) >> 8); phex(loop_count & 0xFF); print("\n");
|
||||
print_matrix();
|
||||
// set matrix state to keyboard_keys, keyboard_modifier_keys
|
||||
key_index = 0;
|
||||
keyboard_modifier_keys = 0;
|
||||
for (int i = 0; i < 6; i++) keyboard_keys[i] = KB_NO;
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
if (matrix[row] & 1<<col) continue;
|
||||
|
||||
uint8_t code = get_keycode(layer, row, col);
|
||||
if (code == KB_NO) {
|
||||
continue;
|
||||
} else if (KB_LCTRL <= code && code <= KB_RGUI) {
|
||||
// modifier keycode: 0xE0-0xE7
|
||||
keyboard_modifier_keys |= 1<<(code & 0x07);
|
||||
} else {
|
||||
if (key_index < 6)
|
||||
keyboard_keys[key_index] = code;
|
||||
key_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// teensy LED flush for debug
|
||||
if ((loop_count & 0x100) == 0) {
|
||||
DDRD |= 1<<PD6;
|
||||
PORTD |= 1<<PD6;
|
||||
}
|
||||
*/
|
||||
if (!has_ghost) {
|
||||
// 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();
|
||||
|
||||
// now the current pins will be the previous, and
|
||||
// wait a short delay so we're not highly sensitive
|
||||
// to mechanical "bounce".
|
||||
_delay_ms(2);
|
||||
/*
|
||||
print("jump to bootloader...\n");
|
||||
_delay_ms(1000);
|
||||
jump_bootloader();
|
||||
*/
|
||||
|
||||
// mouse
|
||||
print("usb_mouse_move\n");
|
||||
usb_mouse_move(10, 0, 0);
|
||||
|
||||
_delay_ms(100);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// send keys to host
|
||||
if (modified) {
|
||||
if (key_index > 6) {
|
||||
//Rollover
|
||||
}
|
||||
usb_keyboard_send();
|
||||
}
|
||||
}
|
||||
loop_count++;
|
||||
_delay_ms(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue