]> git.gir.st - tmk_keyboard.git/blob - ps2_vusb/main.c
added PS/2 to USB converter use V-USB as protocol stack
[tmk_keyboard.git] / ps2_vusb / main.c
1 /* Name: main.c
2 * Project: hid-mouse, a very simple HID example
3 * Author: Christian Starkjohann
4 * Creation Date: 2008-04-07
5 * Tabsize: 4
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 $
9 */
10
11 /*
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.
16
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!
19 */
20
21 #include <stdint.h>
22 #include <avr/io.h>
23 #include <avr/wdt.h>
24 #include <avr/interrupt.h> /* for sei() */
25 #include <util/delay.h> /* for _delay_ms() */
26
27 #include <avr/pgmspace.h> /* required by usbdrv.h */
28 #include "usbdrv.h"
29 #include "usart_print.h" /* This is also an example for using debug macros */
30 #include "ps2.h"
31 #include "usb_keycodes.h"
32 #include "matrix_skel.h"
33 #include "keymap_skel.h"
34 #include "layer.h"
35 #include "print.h"
36 #include "debug.h"
37 #include "sendchar.h"
38 #include "keyboard.h"
39 #include "timer.h"
40
41 /* ------------------------------------------------------------------------- */
42 /* ----------------------------- USB interface ----------------------------- */
43 /* ------------------------------------------------------------------------- */
44
45
46
47
48
49
50 int main(void)
51 {
52 uchar i;
53
54 print_enable = true;
55 debug_enable = true;
56 timer_init();
57 matrix_init();
58
59 wdt_enable(WDTO_1S);
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!
62 */
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.
66 */
67 odDebugInit();
68 DBG1(0x00, 0, 0); /* debug output: main starts */
69 usbInit();
70 usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
71 i = 0;
72 while(--i){ /* fake USB disconnect for > 250 ms */
73 wdt_reset();
74 _delay_ms(1);
75 }
76 usbDeviceConnect();
77 sei();
78
79 uint8_t fn_bits = 0;
80 while (1) { /* main event loop */
81 DBG1(0x02, 0, 0); /* debug output: main loop iterates */
82 wdt_reset();
83 usbPoll();
84
85 /*
86 static uint8_t code = 0;
87 code = ps2_host_recv();
88 if (code) {
89 odDebug(0x05, &code, 1);
90 }
91 */
92 matrix_scan();
93 if (matrix_is_modified()) {
94 //matrix_print(); // too heavy on USART
95 fn_bits = 0;
96 report_swap();
97 report_clear();
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;
101
102 uint8_t code = layer_get_keycode(row, col);
103 if (code == KB_NO) {
104 // do nothing
105 }
106 else if (IS_MOD(code)) {
107 report_add_mod(MOD_BIT(code));
108 }
109 else if (IS_KEY(code)) {
110 report_add_key(code);
111 }
112 else if (IS_FN(code)) {
113 fn_bits |= FN_BIT(code);
114 }
115 else {
116 debug("ignore keycode: "); debug_hex(code); debug("\n");
117 }
118 }
119 }
120 }
121 layer_switching(fn_bits);
122 if (matrix_is_modified()) {
123 report_send();
124 }
125 }
126 }
Imprint / Impressum