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 $
12 This example should run on most AVRs with only little changes. No special
13 hardware resources except INT0 are used. You may have to change usbconfig.h for
14 different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
15 at least be connected to INT0 as well.
17 We use VID/PID 0x046D/0xC00E which is taken from a Logitech mouse. Don't
18 publish any hardware using these IDs! This is for demonstration only!
24 #include <avr/interrupt.h> /* for sei() */
25 #include <util/delay.h> /* for _delay_ms() */
27 #include <avr/pgmspace.h> /* required by usbdrv.h */
29 #include "usart_print.h" /* This is also an example for using debug macros */
31 #include "usb_keycodes.h"
32 #include "matrix_skel.h"
33 #include "keymap_skel.h"
41 /* ------------------------------------------------------------------------- */
42 /* ----------------------------- USB interface ----------------------------- */
43 /* ------------------------------------------------------------------------- */
60 /* Even if you don't use the watchdog, turn it off here. On newer devices,
61 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
63 /* RESET status: all port bits are inputs without pull-up.
64 * That's the way we need D+ and D-. Therefore we don't need any
65 * additional hardware initialization.
68 DBG1(0x00, 0, 0); /* debug output: main starts */
70 usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
72 while(--i){ /* fake USB disconnect for > 250 ms */
80 while (1) { /* main event loop */
81 DBG1(0x02, 0, 0); /* debug output: main loop iterates */
86 static uint8_t code = 0;
87 code = ps2_host_recv();
89 odDebug(0x05, &code, 1);
93 if (matrix_is_modified()) {
94 //matrix_print(); // too heavy on USART
98 for (int row = 0; row < matrix_rows(); row++) {
99 for (int col = 0; col < matrix_cols(); col++) {
100 if (!matrix_is_on(row, col)) continue;
102 uint8_t code = layer_get_keycode(row, col);
106 else if (IS_MOD(code)) {
107 report_add_mod(MOD_BIT(code));
109 else if (IS_KEY(code)) {
110 report_add_key(code);
112 else if (IS_FN(code)) {
113 fn_bits |= FN_BIT(code);
116 debug("ignore keycode: "); debug_hex(code); debug("\n");
121 layer_switching(fn_bits);
122 if (matrix_is_modified()) {