ILI9225 lcd driver: remove backlight control function, is a SAM3N-EK only
[bertos.git] / boards / stm32-p103 / examples / usbkeyboard / main.c
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Andrea Righi <arighi@develer.com>
34  *
35  * \brief BeRTOS virtual keyboard.
36  *
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
39  * normal PC.
40  *
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.
43  *
44  * NOTE: this only works if the keyboard layout on the host PC is set to "US"
45  * (QWERTY).
46  *
47  * Example (keyboard detection on Linux):
48  *
49  * \verbatim
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
54  * \endverbatim
55  *
56  */
57
58 #include "hw/hw_led.h"
59
60 #include <cfg/debug.h>
61
62 #include <cpu/irq.h>
63 #include <cpu/power.h>
64
65 #include <drv/kbd.h>
66 #include <drv/timer.h>
67 #include <drv/usbkbd.h>
68
69 static void init(void)
70 {
71         /* Enable all the interrupts */
72         IRQ_ENABLE;
73
74         /* Initialize debugging module (allow kprintf(), etc.) */
75         kdbg_init();
76         /* Initialize system timer */
77         timer_init();
78         /* Initialize LED driver */
79         LED_INIT();
80         /* Enable the WAKE_UP button on the board */
81         kbd_init();
82         /* Initialize the USB keyboard device */
83         usbkbd_init(0);
84 }
85
86 /* Simulate the pression and release of a key on the keyboard */
87 static void usb_send_key(uint8_t mod, uint8_t c)
88 {
89         usbkbd_sendEvent(mod, c);
90         usbkbd_sendEvent(0, 0);
91 }
92
93 /* XXX: note that these scancodes are valid only with the US keyboard layout */
94 static const uint16_t keys[] =
95 {
96         /* http:// */
97         0x000b, 0x0017, 0x0017, 0x0013, 0x2033, 0x0038, 0x0038,
98         /* www. */
99         0x001a, 0x001a, 0x001a, 0x0037,
100         /* bertos. */
101         0x0005, 0x0008, 0x0015, 0x0017, 0x0012, 0x0016, 0x0037,
102         /* org. */
103         0x0012, 0x0015, 0x000a,
104         /* \n */
105         0x0028,
106 };
107
108 int main(void)
109 {
110         /* Hardware initialization */
111         init();
112
113         kprintf("USB HID Keyboard configured\n");
114         kbd_setRepeatMask(K_WAKEUP);
115         while (1)
116         {
117                 unsigned int i;
118
119                 /* Wait until the WAKE_UP button is pressed */
120                 kbd_get();
121                 /* Send the keyboard scancodes */
122                 for (i = 0; i < countof(keys); i++)
123                         usb_send_key((keys[i] & 0xff00) >> 8, keys[i] & 0xff);
124         }
125 }