Skip to content

Commit 6df2ed7

Browse files
authored
Merge branch 'pololu:master' into master
2 parents 3d90884 + ff078e0 commit 6df2ed7

File tree

5 files changed

+125
-1
lines changed

5 files changed

+125
-1
lines changed

README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ which has an integrated radio transceiver, 32 KB of flash memory, 4 KB
3535
of RAM, and a full-speed USB interface.
3636

3737
For documentation of this SDK, see:
38-
http://pololu.github.com/wixel-sdk
38+
http://pololu.github.io/wixel-sdk
3939

4040
(You can also generate the documentation yourself by running
4141
Doxygen on libraries/Doxyfile.)

apps/usb_keyboard_typer/data.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <cc2511_types.h>
2+
#include "data.h"
3+
4+
uint8 CODE payload_data[] = "Hello, world!";

apps/usb_keyboard_typer/data.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _DATA_H
2+
#define _DATA_H
3+
4+
extern uint8 CODE payload_data[];
5+
6+
#endif

apps/usb_keyboard_typer/options.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_LIBS := dma.lib usb.lib usb_hid.lib wixel.lib gpio.lib
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#include <wixel.h>
2+
#include <usb.h>
3+
#include <usb_hid.h>
4+
#include "data.h"
5+
6+
uint8 lastKeyCodeSent = 0;
7+
BIT sending = 0;
8+
char XDATA * nextCharToSend;
9+
BIT started = 0;
10+
11+
void updateLeds()
12+
{
13+
usbShowStatusWithGreenLed();
14+
15+
LED_YELLOW(!sending);
16+
LED_RED(sending);
17+
}
18+
19+
uint8 usbHidModifiersFromAsciiChar(char c)
20+
{
21+
if ( (c >= 0x21 && c <= 0x26) ||
22+
(c >= 0x28 && c <= 0x2B) ||
23+
(c == ':') ||
24+
(c == '<') ||
25+
(c >= 0x3E && c <= 0x5A) ||
26+
(c >= 0x5E && c <= 0x5F) ||
27+
(c == '|') ||
28+
(c == '~')
29+
)
30+
{
31+
return (1<<MODIFIER_SHIFT_LEFT);
32+
}
33+
else
34+
{
35+
return 0;
36+
}
37+
}
38+
39+
// See keyboardService for an example of how to use this function correctly.
40+
// Assumption: usbHidKeyboardInputUpdated == 0. Otherwise, this function
41+
// could clobber a keycode sitting in the buffer that has not been sent to
42+
// the computer yet.
43+
// Assumption: usbHidKeyBoardInput[1 through 5] are all zero.
44+
// Assumption: usbHidKeyboardInput.modifiers is 0.
45+
// NOTE: To send two identical characters, you must send a 0 in between.
46+
void sendKeyCode(uint8 keyCode, uint8 modifiers)
47+
{
48+
lastKeyCodeSent = keyCode;
49+
usbHidKeyboardInput.keyCodes[0] = keyCode;
50+
usbHidKeyboardInput.modifiers = modifiers;
51+
52+
// Tell the HID library to send the new keyboard state to the computer.
53+
usbHidKeyboardInputUpdated = 1;
54+
}
55+
56+
void keyboardService()
57+
{
58+
if (getMs() >= 5000 && !started && !sending)
59+
{
60+
started = 1;
61+
sending = 1;
62+
nextCharToSend = (char XDATA *)payload_data;
63+
}
64+
65+
// Feed data to the HID library, one character at a time.
66+
if (sending && !usbHidKeyboardInputUpdated)
67+
{
68+
uint8 nextChar = *nextCharToSend;
69+
if (nextChar == 0)
70+
{
71+
sending = 0;
72+
}
73+
else
74+
{
75+
uint8 keyCode = usbHidKeyCodeFromAsciiChar(*nextCharToSend);
76+
uint8 nextChar = *nextCharToSend;
77+
78+
if (keyCode != 0 && keyCode == lastKeyCodeSent)
79+
{
80+
// If we need to send the same character twice in a row,
81+
// send a 0 between them so the computer registers it as
82+
// two different separate key strokes.
83+
keyCode = 0;
84+
}
85+
else
86+
{
87+
nextCharToSend++;
88+
}
89+
90+
sendKeyCode(keyCode, usbHidModifiersFromAsciiChar(nextChar));
91+
}
92+
}
93+
94+
// Send a 0 to signal the release of the last key.
95+
if (!sending && lastKeyCodeSent != 0 && !usbHidKeyboardInputUpdated)
96+
{
97+
sendKeyCode(0, 0);
98+
}
99+
}
100+
101+
void main()
102+
{
103+
systemInit();
104+
usbInit();
105+
106+
while(1)
107+
{
108+
updateLeds();
109+
boardService();
110+
usbHidService();
111+
keyboardService();
112+
}
113+
}

0 commit comments

Comments
 (0)