California Dreamin'
BradC
Posts: 2,601
Ok mobsters, as a bit of a teaser I've attached a _very_ preliminary version of a low-speed USB stack.
I've had to break it into 2 cogs unfortunately (I'm a bit upset about that), but doing it that way just makes more sense when you don't have an interrupt.
This code enumerates as a USB keyboard and types out the lyrics from "California Dreaming" as translated by Michael Hetherington here ...
http://www.sxlist.com/techref/scenix/lib/io/dev/keys/usbdemo-mh.htm
The stack has not been validated, it has bugs and the code is absolutely woeful. I've had my head stuck in 650 pages USB specs all week and not even thought about tidying / optimising any of the code yet.
The advantage of using 2 cogs here is we can properly validate all our inbound CRC's (I've skipped the 5 bit ones at the moment while I build a better checker), and get a response out plus manage *all* possible endpoints.
Most of the embedded stacks face limitations on endpoint management, speed and proper validation. As we run 2 processors for the stack we don't have most of those limitations.
Ignore the :
- bad code (yes I know)
- debug code (it's very hacky)
- typos
- comments written at 3am after half a bottle of Jamesons
- fatal logic errors
- horrid descriptor strings (again, half a bottle of Jamesons at 3am)
Tested on linux and win2k.
I've got improvements and other things in the works. I've learned a hell of a lot about USB in the last couple of days.. but the main thing I learned is that a prop is *just not fast enough* to do Full-Speed.
If, perchance you wanted to run this code up you need 2 68Ohm resistors and a 3.3k.
Plug it into a PC *before* you fire it up as it will enumerate, then about 5 seconds later it will happily type out the lyrics.. then it's game over until you reset the device.
Brad (unicode blows goats)
Why won't the forums allow me to upload a .spin file? I had to add .txt to the end to get it to go! Bah!
[noparse][[/noparse]edit - one of the uploaded files was wrong]
[noparse][[/noparse]edit - IO starts at pin 0 and not pin 1, so 0-2 not 1-3]
Post Edited (BradC) : 9/6/2007 3:21:24 AM GMT
I've had to break it into 2 cogs unfortunately (I'm a bit upset about that), but doing it that way just makes more sense when you don't have an interrupt.
This code enumerates as a USB keyboard and types out the lyrics from "California Dreaming" as translated by Michael Hetherington here ...
http://www.sxlist.com/techref/scenix/lib/io/dev/keys/usbdemo-mh.htm
The stack has not been validated, it has bugs and the code is absolutely woeful. I've had my head stuck in 650 pages USB specs all week and not even thought about tidying / optimising any of the code yet.
The advantage of using 2 cogs here is we can properly validate all our inbound CRC's (I've skipped the 5 bit ones at the moment while I build a better checker), and get a response out plus manage *all* possible endpoints.
Most of the embedded stacks face limitations on endpoint management, speed and proper validation. As we run 2 processors for the stack we don't have most of those limitations.
Ignore the :
- bad code (yes I know)
- debug code (it's very hacky)
- typos
- comments written at 3am after half a bottle of Jamesons
- fatal logic errors
- horrid descriptor strings (again, half a bottle of Jamesons at 3am)
Tested on linux and win2k.
I've got improvements and other things in the works. I've learned a hell of a lot about USB in the last couple of days.. but the main thing I learned is that a prop is *just not fast enough* to do Full-Speed.
If, perchance you wanted to run this code up you need 2 68Ohm resistors and a 3.3k.
Plug it into a PC *before* you fire it up as it will enumerate, then about 5 seconds later it will happily type out the lyrics.. then it's game over until you reset the device.
Brad (unicode blows goats)
Why won't the forums allow me to upload a .spin file? I had to add .txt to the end to get it to go! Bah!
[noparse][[/noparse]edit - one of the uploaded files was wrong]
[noparse][[/noparse]edit - IO starts at pin 0 and not pin 1, so 0-2 not 1-3]
Post Edited (BradC) : 9/6/2007 3:21:24 AM GMT
Comments
Is there anything a prop can't do! I'm beginning to doubt it. well, maybe make a cuppa tea, although some roboteer will probably put that to the test now. lol
Like Harrison, I'm gonna have to get a spare USB cable, to hack up [noparse]:)[/noparse]
Jim.
Well done ! I was wondering if a Propeller could do this.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The first rule to being successful is "Learn from your mistakes",
The second rule is "Be willing to make mistakes"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
John Twomey
Ireland
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Please check my grasp of your program:
A prop,
connected by a generic usb cord [noparse][[/noparse]not a prop plug!]
to a win pc or linux box [noparse][[/noparse]running a program that expects keyboard input],
pretends to be a usb keyboard that is typing California Dreaming.
My real question is this: what references to usb have you found are most useful? And can you share links to them?
Fred
@Fred : Absolutely correct. No additional chips, just the propeller, 3 IO pins and 3 resistors
As for useful docs, these three are all you would need (or all I needed anyway). What made my life easier is I wrote a basic USB analyser based on USB_lowlevel_003.spin (attached above) and used that to watch the enumeration process of a cheapo USB mouse I had lying around. That helped. I have worked with USB HID descriptors before too when playing with Qemu, so I guess that gave me a leg-up.
HID Class specification
http://www.usb.org/developers/devclass_docs/HID1_11.pdf
USB 2.0 specs
http://www.usb.org/developers/docs/usb_20_071607.zip
USB in a nutshell
http://www.beyondlogic.org/usbnutshell/usb-in-a-nutshell.pdf
Despite the somewhat excessive size, the USB 2.0 spec is absolutely the only document you really need. It answers all possible questions.
Plenty of people (well, at least 4 given a cursory search) had done this before. 3 on AVR and one on SX.
I did have a look at Dick Streefland's USBTiny code bit the majority of it is in C and chock full of macros. Made my head hurt. Worth a look if you do AVR though.
http://www.xs4all.nl/~dicks/avr/usbtiny/
He does a nice little 4 bit CRC16 routine in there that would be perfect for a memory starved application.
Shoulders of giants and all that...
The propeller needs 3 IO pins instead of the usual 2 as it's too slow to boot up on power-on. The USB bus tries to enumerate with it prior to it actually being in a running state, so we use the 3rd pin to do the presence signal when the stack is up and running.
A lot of references on this site: www.lvr.com/usb.htm
That particular site is pretty good. Wish I'd had that last week
Post Edited (Fred Hawkins) : 9/6/2007 9:06:08 AM GMT
Gerry·
John Twomey
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Edited : Corrected pin numbers to P0..P2
Edited Again : Pins now selectable in source, 68R plus 1K5, not 680R plus 3K3 as shown earlier. Also 1K5 from P2 to D-, not 3K3 from P2 to P0 as previously shown.
Post Edited (hippy) : 10/1/2007 12:58:51 PM GMT
Yeah, the serial-usb uses the same cable and connections.. it's posted up now along with an improved version of the california dreaming code (read with less bugs) [noparse]:)[/noparse]
47 - 100 - 220 - 470 - 1k - 2k2 - 4k7 - 10k - 22k - 47k- 100k - 220k - 470k - 1M
And I do not plan to use something like 680 or 3k3, or use anything for the video DAC but 220 + 470 + 1k
P.S.: When I look into my resistor box.... 47, 47k and 470k have been also hardly used
BTW, I got some Wales whisky liquer when I visited swansea this summer. Is that OK to imbibe? Name is "xxx Jones". What else could one expect?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I know this work is in the early stages, but where do to you "think" it might be able to go?
Is there any chance of USB host capabilities? Or could we have a USB serial port (even if its at a lower baud rate)
I've been working on designs for cheap educational robot kits and a software only solution for programming a robot using the USB port (since almost no computers come with serial ports anymore) would help a lot.
I'd be interested in helping make this happen.
I know its off topic but has anyone been working on a bit-banging ethernet driver?
I know I've heard of it being done on other micros.
-Chad
http://forums.parallax.com/forums/default.aspx?f=25&m=216569
I can get sustained rates of about 6.8-7K bytes/second in both directions simultaneously. I've not benchmarked it in one direction.
Gonna have a crack at a bi-directional class compliant MIDI interface next I think.
Not to derail this topic, but any links on the other projects that do bit-bang ethernet? I don't know if it's worth it since a spi ethernet chip is about 5 bucks + another 5 bucks for magnetics. The only project I am aware of uses a FPGA and can barely do receive.
I have a feeling I won't get much real work done tomorrow until I get this working on my robot kit.
This is really exciting stuff.
-Chad
I've done some prelim reading on Ethernet.. it _might_ be possible to do transmit, but I can pretty confidently say receive is well out of the Propellers league. If I could do that I could do Full Speed USB (which would be nice)
10Mhz is just not gonna happen. Hard enough doing NRZI and Bit stuff at 1.5Mhz for USB
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1010, so be surprised!
I intend to use your USB generic propeller-keyboard to send makro's and therefore I need for example to send CTRL-C , ALT-F or SHIFT-a to write an 'A'.
If I now send this line of command $E0,$06 it acts as follows --- press-[CTRL]-release-press-[c]-release --- what results in 'c' instead of 'CTRL-C'.
Is there a way to include a 'keep key down' code so it can send --- press-[CTRL]-hold-press-[c]-release -- ?
-Trac
Wireshark has a USB sniffing capability which should help you in debugging what the right codes should be.
(Delete by itself is $C9.)
I don't know if USB has a similar type of protocol.
I added the keyboard layout for a Generic US keyboard. In Red are the hex scancodes.
I did 'googled' extended keyboard scancodes but they are not working with this code. Normally it is as Duane mentioned, there are 2 hex codes to be send, but this code is written to send only the 2 last characters and ignore the first.
This is what I found out.
ep1send mov out1, #1
test ep1len, allones wz
IF_Z mov out1, #0
IF_Z jmp #ep1send_ret
call #bufstart
mov data, #0
call #pushbuf
call #pushbuf
xor ep1toggle, #1 wz
IF_Z jmp #:keyup 'If you remove this line then the USB keyboard acts is like you hold down a key aaaaaaaaaaaaaaaaaaa
rdbyte data, ep1buf
call #pushbuf ' Key down
mov data, #0
jmp #:next
:keyup
add ep1buf, #1
sub ep1len, #1
call #pushbuf ' Key up
My guess is that there is a bit of code to write to look at the first hex code (ex. $06C9) but my assembler knowledge is almost zero.
1
2
3
4
5
6
7
8
9
0A
0B
1
2
3
4
5
6
7
8
9
10
11
-
err
err
err
A (Q)
B
C
D
E
F
G
H
0C
0D
0E
0F
10
11
12
13
14
15
16
17
12
13
14
15
16
17
18
19
20
21
22
23
I
J
K
L
M (;)
N
O
P
Q (A)
R
S
T
18
19
1A
1B
1C
1D
1E
1F
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
U
V
W (Z)
X
Y
Z (W)
1
2
3
4
5
6
24
25
26
27
28
29
2A
2B
2C
2D
2E
2F
36
37
38
39
40
41
42
43
44
45
46
47
7
8
9
0
Enter
Esc
BSp
Tab
Space
- / _
= / +
[ / {
30
31
32
33
34
35
36
37
38
39
3A
3B
48
49
50
51
52
53
54
55
56
57
58
59
] / }
\ / |
...
; / :
' / "
` / ~
, / <
. / >
/ / ?
Caps Lock
F1
F2
3C
3D
3E
3F
40
41
42
43
44
45
46
47
60
61
62
63
64
65
66
67
68
69
70
71
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
PrtScr
Scroll Lock
48
49
4A
4B
4C
4D
4E
4F
50
51
52
53
72
73
74
75
76
77
78
79
80
81
82
83
Pause
Insert
Home
PgUp
Delete
End
PgDn
Right
Left
Down
Up
Num Lock
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F
84
85
86
87
88
89
90
91
92
93
94
95
KP /
KP *
KP -
KP +
KP Enter
KP 1 / End
KP 2 / Down
KP 3 / PgDn
KP 4 / Left
KP 5
KP 6 / Right
KP 7 / Home
60
61
62
63
64
65
66
67
68
69
6A
6B
96
97
98
99
100
101
102
103
104
105
106
107
KP 8 / Up
KP 9 / PgUp
KP 0 / Ins
KP . / Del
...
Applic
Power
KP =
F13
F14
F15
F16
6C
6D
6E
6F
70
71
72
73
74
75
76
77
108
109
110
111
112
113
114
115
116
117
118
119
F17
F18
F19
F20
F21
F22
F23
F24
Execute
Help
Menu
Select
78
79
7A
7B
7C
7D
7E
7F
80
81
82
83
120
121
122
123
124
125
126
127
128
129
130
131
Stop
Again
Undo
Cut
Copy
Paste
Find
Mute
Volume Up
Volume Down
Locking Caps Lock
Locking Num Lock
84
85
86
87
88
89
8A
8B
8C
8D
8E
8F
132
133
134
135
136
137
138
139
140
141
142
143
Locking Scroll Lock
KP ,
KP =
Internat
Internat
Internat
Internat
Internat
Internat
Internat
Internat
Internat
90
91
92
93
94
95
96
97
98
99
9A
9B
144
145
146
147
148
149
150
151
152
153
154
155
LANG
LANG
LANG
LANG
LANG
LANG
LANG
LANG
LANG
Alt Erase
SysRq
Cancel
9C
9D
9E
9F
A0
A1
A2
A3
A4
A5
A6
A7
156
157
158
159
160
161
162
163
164
165
166
167
Clear
Prior
Return
Separ
Out
Oper
Clear / Again
CrSel / Props
ExSel
E0
E1
E2
E3
E4
E5
E6
E7
224
225
226
227
228
229
230
231
LCtrl
LShift
LAlt
LGUI
RCtrl
RShift
RAlt
RGUI