summaryrefslogtreecommitdiffstats
path: root/mykey.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2010-09-30 07:17:01 +0200
committertmk <nobody@nowhere>2010-09-30 07:50:23 +0200
commitd3b1af9572e123c939fc355474bf12402c86d292 (patch)
tree5c3f18f6af2bd7ed0333b7f5ed8dd16c4fa69245 /mykey.c
parente7c6839d2d17dd084c8bea1dd43208b3144979d2 (diff)
downloadqmk_firmware-d3b1af9572e123c939fc355474bf12402c86d292.tar.gz
qmk_firmware-d3b1af9572e123c939fc355474bf12402c86d292.tar.xz
add mouse function.
Diffstat (limited to 'mykey.c')
-rw-r--r--mykey.c127
1 files changed, 54 insertions, 73 deletions
diff --git a/mykey.c b/mykey.c
index 94cbbfb5a..a295b8c57 100644
--- a/mykey.c
+++ b/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,99 +73,85 @@ 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;
+ // print matrix state for debug
+ if (modified) {
+ print_matrix();
- 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++;
- }
+ // LED flush
+ DDRD |= 1<<PD6;
+ PORTD |= 1<<PD6;
+ }
+
+ // 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++;
}
}
+ }
- // run bootloader when 4 left modifier keys down
+ 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();
+ /*
print("jump to bootloader...\n");
_delay_ms(1000);
jump_bootloader();
- }
+ */
- if (key_index > 6) {
- //Rollover
- }
+ // mouse
+ print("usb_mouse_move\n");
+ usb_mouse_move(10, 0, 0);
- 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();
-
- // LED flush
- DDRD |= 1<<PD6;
- PORTD |= 1<<PD6;
- }
+ _delay_ms(100);
+ continue;
+ }
-/*
- // 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();
- }
- // teensy LED flush for debug
- if ((loop_count & 0x100) == 0) {
- DDRD |= 1<<PD6;
- PORTD |= 1<<PD6;
+ // send keys to host
+ if (modified) {
+ if (key_index > 6) {
+ //Rollover
+ }
+ 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);
loop_count++;
+ _delay_ms(2);
}
}