2 * Project: hid-mouse, a very simple HID example
3 * Author: Christian Starkjohann
4 * Creation Date: 2008-04-07
6 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
13 #include <avr/interrupt.h> /* for sei() */
14 #include <avr/pgmspace.h> /* required by usbdrv.h */
15 #include <util/delay.h> /* for _delay_ms() */
17 #include "usart_print.h" /* This is also an example for using debug macros */
18 #include "usb_keycodes.h"
19 #include "matrix_skel.h"
20 #include "keymap_skel.h"
28 #include "host_vusb.h"
35 /* Even if you don't use the watchdog, turn it off here. On newer devices,
36 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
39 /* RESET status: all port bits are inputs without pull-up.
40 * That's the way we need D+ and D-. Therefore we don't need any
41 * additional hardware initialization.
47 //debug_enable = true;
51 /* enforce re-enumeration, do this while interrupts are disabled! */
52 usbDeviceDisconnect();
54 while(--i){ /* fake USB disconnect for > 250 ms */
62 while (1) { /* main event loop */
65 host_vusb_keyboard_send();
69 keyboard_swap_report();
70 keyboard_clear_report();
71 mousekey_clear_report();
72 for (int row = 0; row < matrix_rows(); row++) {
73 for (int col = 0; col < matrix_cols(); col++) {
74 if (!matrix_is_on(row, col)) continue;
76 uint8_t code = layer_get_keycode(row, col);
80 else if (IS_MOD(code)) {
81 keyboard_add_mod(MOD_BIT(code));
83 else if (IS_KEY(code)) {
84 keyboard_add_key(code);
86 else if (IS_FN(code)) {
87 fn_bits |= FN_BIT(code);
89 else if (IS_MOUSEKEY(code)) {
90 mousekey_decode(code);
93 debug("ignore keycode: "); debug_hex(code); debug("\n");
97 layer_switching(fn_bits);
98 if (matrix_is_modified()) {