4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 * \author Andrea Righi <arighi@develer.com>
35 * \brief BeRTOS virtual keyboard.
37 * This project implements a HID USB device using the Olimex STM32-P103
38 * evaluation board. The virtual keyboard can be connected to the USB port of a
41 * The WAKE_UP button on the board can be pressed to send to the host the
42 * keyboard scancodes that simulate the typing of http://www.bertos.org.
44 * NOTE: this only works if the keyboard layout on the host PC is set to "US"
47 * Example (keyboard detection on Linux):
50 * [24388.400573] usb 1-8.1.3: new full speed USB device using ehci_hcd and address 32
51 * [24388.623957] usb 1-8.1.3: configuration #1 chosen from 1 choice
52 * [24388.685827] input: BeRTOS USB Keyboard as /devices/pci0000:00/0000:00:1d.7/usb1/1-8/1-8.1/1-8.1.3/1-8.1.3:1.0/input/input18
53 * [24388.688953] generic-usb 0003:FFFF:0000.0007: input,hidraw3: USB HID v1.10 Keyboard [BeRTOS USB Keyboard] on usb-0000:00:1d.7-8.1.3/input0
58 #include "hw/hw_led.h"
60 #include <cfg/debug.h>
63 #include <cpu/power.h>
66 #include <drv/timer.h>
67 #include <drv/usbkbd.h>
69 static void init(void)
71 /* Enable all the interrupts */
74 /* Initialize debugging module (allow kprintf(), etc.) */
76 /* Initialize system timer */
78 /* Initialize LED driver */
80 /* Enable the WAKE_UP button on the board */
82 /* Initialize the USB keyboard device */
86 /* Simulate the pression and release of a key on the keyboard */
87 static void usb_send_key(uint8_t mod, uint8_t c)
89 usbkbd_sendEvent(mod, c);
90 usbkbd_sendEvent(0, 0);
93 /* XXX: note that these scancodes are valid only with the US keyboard layout */
94 static const uint16_t keys[] =
97 0x000b, 0x0017, 0x0017, 0x0013, 0x2033, 0x0038, 0x0038,
99 0x001a, 0x001a, 0x001a, 0x0037,
101 0x0005, 0x0008, 0x0015, 0x0017, 0x0012, 0x0016, 0x0037,
103 0x0012, 0x0015, 0x000a,
110 /* Hardware initialization */
113 kprintf("USB HID Keyboard configured\n");
114 kbd_setRepeatMask(K_WAKEUP);
119 /* Wait until the WAKE_UP button is pressed */
121 /* Send the keyboard scancodes */
122 for (i = 0; i < countof(keys); i++)
123 usb_send_key((keys[i] & 0xff00) >> 8, keys[i] & 0xff);