forked from Chadderz121/bakingpi-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input01.html
1783 lines (1783 loc) · 46.6 KB
/
input01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Lesson 10 Input01</title>
<link href="stylesheet.css" rel="Stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="contentAll">
<div id="courseHead">
<h1>
Lesson 10 Input01</h1>
</div>
<div id="pageAll">
<div id="pageBody">
<p>
Welcome to the Input lesson series. In this series, you will learn how to receive
inputs to the Raspberry Pi using the keyboard. We will start with just revealing
the input, and then move to a more traditional text prompt.
</p>
<p>
This first input lesson teaches some theory about drivers and linking, as well
as about keyboards and ends up displaying text on the screen.</p>
<div class="ucampas-toc">
</div>
<h2 id="gs">
1 Getting Started</h2>
<p>
It is expected that you have completed the OK series, and it would be helpful to
have completed the Screen series. Many of the files from that series will be called,
without comment. If you do not have these files, or prefer to use a correct implementation,
download the template for this lesson from the <a href="downloads.html">Downloads</a>
page. If you're using your own implementation, please remove everything after your
call to SetGraphicsAddress.</p>
<h2 id="usb">
2 USB</h2>
<div class="informationBox">
<p>
The USB standard was designed to make simple hardware in exchange for complex software.</p>
</div>
<p>
As you are no doubt aware, the Raspberry Pi model B has two USB ports, commonly
used for connecting a mouse and keyboard. This was a very good design decision,
USB is a very generic connector, and many different kinds of device use it. It's
simple to build new devices for, simple to write device drivers for, and is highly
extensible thanks to USB hubs. Could it get any better? Well, no, in fact for an
Operating Systems developer this is our worst nightmare. The USB standard is huge.
I really mean it this time, it is over 700 pages, before you've even thought about
connecting a device.</p>
<p>
I spoke to a number of other hobbyist Operating Systems developers about this and
they all say one thing: don't bother. "It will take too long to implement", "You
won't be able to write a tutorial on it" and "It will be of little benefit". In
many ways they are right, I'm not able to write a tutorial on the USB standard,
as it would take weeks. I also can't teach how to write device drivers for all the
different devices, so it is useless on its own. However, I can do the next best
thing: Get a working USB driver, get a keyboard driver, and then teach how to use
these in an Operating System. I set out searching for a free driver that would run
in an operating system that doesn't even know what a file is yet, but I couldn't
find one. They were all too high level. So, I attempted to write one. Everybody
was right, this took weeks to do. However, I'm pleased to say I did get one that
works with no external help from the Operating System, and can talk to a mouse and
keyboard. It is by no means complete, efficient, or correct, but it does work. It
has been written in C and the full source code can be found on the downloads page
for those interested.
</p>
<p>
So, this tutorial won't be a lesson on the USB standard (at all). Instead we'll
look at how to work with other people's code.</p>
<h2 id="linking">
3 Linking</h2>
<div class="informationBox">
<p>
Linking allows us to make reusable code 'libraries' that anyone can use in their
program.</p>
</div>
<p>
Since we're about to incorporate external code into the Operating System, we need
to talk about linking. Linking is a process which is applied to programs or Operating
System to link in functions. What this means is that when a program is made, we
don't necessarily code every function (almost certainly not in fact). Linking is
what we do to make our program link to functions in other people's code. This has
actually been going on all along in our Operating Systems, as the linker links together
all of the different files, each of which is compiled separately.</p>
<div class="informationBox">
<p>
Programs often just call libraries, which call other libraries and so on until eventually
they call an Operating System library which we would write.</p>
</div>
<p>
There are two types of linking: static and dynamic. Static linking is like what
goes on when we make our Operating Systems. The linker finds all the addresses of
the functions, and writes them into the code, before the program is finished. Dynamic
linking is linking that occurs after the program is 'complete'. When it is loaded,
the dynamic linker goes through the program and links any functions which are not
in the program to libraries in the Operating System. This is one of the jobs our
Operating System should eventually be capable of, but for now everything will be
statically linked.</p>
<p>
The USB driver I have written is suitable for static linking. This means I give
you the compiled code for each of my files, and then the linker finds functions
in your code which are not defined in your code, and links them to functions in
my code. On the <a href="downloads.html">Downloads</a> page for this lesson is a
makefile and my USB driver, which you will need to continue. Download them and replace
the makefile in your code with this one, and also put the driver in the same folder
as that makefile.</p>
<h2 id="keyboards">
4 Keyboards</h2>
<p>
In order to get input into our Operating System, we need to understand at some level
how keyboards actually work. Keyboards have two types of keys: Normal and Modifier
keys. The normal keys are the letters, numbers, function keys, etc. They constitute
almost every key on the keyboard. The modifiers are up to 8 special keys. These
are left shift, right shift, left control, right control, left alt, right alt, left
GUI and right GUI. The keyboard can detect any combination of the modifier keys
being held, as well as up to 6 normal keys. Every time a key changes (i.e. is pushed
or released), it reports this to the computer. Typically, keyboards also have three
LEDs for Caps Lock, Num Lock and Scroll Lock, which are controlled by the computer,
not the keyboard itself. Keyboards may have many more lights such as power, mute,
etc.
</p>
<p>
In order to help standardise USB keyboards, a table of values was produced, such
that every keyboard key ever is given a unique number, as well as every conceivable
LED. The table below lists the first 126 of values.
</p>
<table>
<caption>
Table 4.1 USB Keyboard Keys</caption>
<thead>
<tr>
<th>
Number
</th>
<th>
Description
</th>
<th>
Number
</th>
<th>
Description
</th>
<th>
Number
</th>
<th>
Description
</th>
<th>
Number
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
4
</td>
<td>
a and A
</td>
<td>
5
</td>
<td>
b and B
</td>
<td>
6
</td>
<td>
c and C
</td>
<td>
7
</td>
<td>
d and D
</td>
</tr>
<tr>
<td>
8
</td>
<td>
e and E
</td>
<td>
9
</td>
<td>
f and F
</td>
<td>
10
</td>
<td>
g and G
</td>
<td>
11
</td>
<td>
h and H
</td>
</tr>
<tr>
<td>
12
</td>
<td>
i and I
</td>
<td>
13
</td>
<td>
j and J
</td>
<td>
14
</td>
<td>
k and K
</td>
<td>
15
</td>
<td>
l and L
</td>
</tr>
<tr>
<td>
16
</td>
<td>
m and M
</td>
<td>
17
</td>
<td>
n and N
</td>
<td>
18
</td>
<td>
o and O
</td>
<td>
19
</td>
<td>
p and P
</td>
</tr>
<tr>
<td>
20
</td>
<td>
q and Q
</td>
<td>
21
</td>
<td>
r and R
</td>
<td>
22
</td>
<td>
s and S
</td>
<td>
23
</td>
<td>
t and T
</td>
</tr>
<tr>
<td>
24
</td>
<td>
u and U
</td>
<td>
25
</td>
<td>
v and V
</td>
<td>
26
</td>
<td>
w and W
</td>
<td>
27
</td>
<td>
x and X
</td>
</tr>
<tr>
<td>
28
</td>
<td>
y and Y
</td>
<td>
29
</td>
<td>
z and Z
</td>
<td>
30
</td>
<td>
1 and !
</td>
<td>
31
</td>
<td>
2 and @
</td>
</tr>
<tr>
<td>
32
</td>
<td>
3 and #
</td>
<td>
33
</td>
<td>
4 and $
</td>
<td>
34
</td>
<td>
5 and %
</td>
<td>
35
</td>
<td>
6 and ^
</td>
</tr>
<tr>
<td>
36
</td>
<td>
7 and &
</td>
<td>
37
</td>
<td>
8 and *
</td>
<td>
38
</td>
<td>
9 and (
</td>
<td>
39
</td>
<td>
0 and )
</td>
</tr>
<tr>
<td>
40
</td>
<td>
Return (Enter)
</td>
<td>
41
</td>
<td>
Escape
</td>
<td>
42
</td>
<td>
Delete (Backspace)
</td>
<td>
43
</td>
<td>
Tab
</td>
</tr>
<tr>
<td>
44
</td>
<td>
Spacebar
</td>
<td>
45
</td>
<td>
- and _
</td>
<td>
46
</td>
<td>
= and +
</td>
<td>
47
</td>
<td>
[ and {
</td>
</tr>
<tr>
<td>
48
</td>
<td>
] and }
</td>
<td>
49
</td>
<td>
\ and |
</td>
<td>
50
</td>
<td>
# and ~
</td>
<td>
51
</td>
<td>
; and :
</td>
</tr>
<tr>
<td>
52
</td>
<td>
' and "
</td>
<td>
53
</td>
<td>
` and ~
</td>
<td>
54
</td>
<td>
, and <
</td>
<td>
55
</td>
<td>
. and >
</td>
</tr>
<tr>
<td>
56
</td>
<td>
/ and ?
</td>
<td>
57
</td>
<td>
Caps Lock
</td>
<td>
58
</td>
<td>
F1
</td>
<td>
59
</td>
<td>
F2
</td>
</tr>
<tr>
<td>
60
</td>
<td>
F3
</td>
<td>
61
</td>
<td>
F4
</td>
<td>
62
</td>
<td>
F5
</td>
<td>
63
</td>
<td>
F6
</td>
</tr>
<tr>
<td>
64
</td>
<td>
F7
</td>
<td>
65
</td>
<td>
F8
</td>
<td>
66
</td>
<td>
F9
</td>
<td>
67
</td>
<td>
F10
</td>
</tr>
<tr>
<td>
68
</td>
<td>
F11
</td>
<td>
69
</td>
<td>
F12
</td>
<td>
70
</td>
<td>
Print Screen
</td>
<td>
71
</td>
<td>
Scroll Lock
</td>
</tr>
<tr>
<td>
72
</td>
<td>
Pause
</td>
<td>
73
</td>
<td>
Insert
</td>
<td>
74
</td>
<td>
Home
</td>
<td>
75
</td>
<td>
Page Up
</td>
</tr>
<tr>
<td>
76
</td>
<td>
Delete forward
</td>
<td>
77
</td>
<td>
End
</td>
<td>
78
</td>
<td>
Page Down
</td>
<td>
79
</td>
<td>
Right Arrow
</td>
</tr>
<tr>
<td>
80
</td>
<td>
Left Arrow
</td>
<td>
81
</td>
<td>
Down Arrow
</td>
<td>
82
</td>
<td>
Up Arrow
</td>
<td>
83
</td>
<td>
Num Lock
</td>
</tr>
<tr>
<td>
84
</td>
<td>
Keypad /
</td>
<td>
85
</td>
<td>
Keypad *
</td>
<td>
86
</td>
<td>
Keypad -
</td>
<td>
87
</td>
<td>
Keypad +
</td>
</tr>
<tr>
<td>
88
</td>
<td>
Keypad Enter
</td>
<td>
89
</td>
<td>
Keypad 1 and End
</td>
<td>
90
</td>
<td>
Keypad 2 and Down Arrow
</td>
<td>
91
</td>
<td>
Keypad 3 and Page Down
</td>
</tr>
<tr>
<td>
92
</td>
<td>
Keypad 4 and Left Arrow
</td>
<td>
93
</td>
<td>
Keypad 5
</td>
<td>
94
</td>
<td>
Keypad 6 and Right Arrow
</td>
<td>
95
</td>
<td>
Keypad 7 and Home
</td>
</tr>
<tr>
<td>
96
</td>
<td>
Keypad 8 and Up Arrow
</td>
<td>
97
</td>
<td>
Keypad 9 and Page Up
</td>
<td>
98
</td>
<td>
Keypad 0 and Insert
</td>
<td>
99
</td>
<td>
Keypad . and Delete
</td>
</tr>
<tr>
<td>
100
</td>
<td>
\ and |
</td>
<td>
101
</td>
<td>
Application
</td>
<td>
102
</td>
<td>
Power
</td>
<td>
103
</td>
<td>
Keypad =
</td>
</tr>
<tr>
<td>
104
</td>
<td>
F13
</td>
<td>
105
</td>
<td>
F14
</td>
<td>
106
</td>
<td>
F15
</td>
<td>
107
</td>
<td>
F16
</td>
</tr>
<tr>
<td>
108
</td>
<td>
F17
</td>
<td>
109
</td>
<td>
F18
</td>
<td>
110
</td>
<td>
F19
</td>
<td>
111
</td>
<td>
F20
</td>
</tr>
<tr>
<td>
112
</td>
<td>
F21
</td>
<td>
113
</td>
<td>
F22
</td>
<td>
114
</td>
<td>
F23
</td>
<td>
115
</td>
<td>
F24
</td>
</tr>
<tr>
<td>
116
</td>
<td>
Execute
</td>
<td>
117
</td>
<td>
Help
</td>
<td>
118
</td>
<td>
Menu
</td>
<td>
119
</td>
<td>
Select
</td>
</tr>
<tr>
<td>
120
</td>
<td>
Stop
</td>
<td>
121
</td>
<td>
Again
</td>
<td>
122
</td>
<td>
Undo
</td>
<td>
123
</td>
<td>
Cut
</td>
</tr>
<tr>
<td>
124
</td>
<td>
Copy
</td>
<td>
125
</td>
<td>
Paste
</td>
<td>
126
</td>
<td>
Find
</td>
<td>
127
</td>
<td>
Mute
</td>
</tr>
<tr>
<td>
128
</td>
<td>
Volume Up
</td>
<td>
129
</td>
<td>
Volume Down
</td>
</tr>
</tbody>
</table>
<p>
The full list can be found in section 10, page 53 of <a class="icon-pdf" href="downloads/hut1_12v2.pdf">
HID Usage Tables 1.12</a>.</p>
<h2 id="driver">
5 The Nut Behind the Wheel</h2>
<div class="informationBox">
<p>
These summaries and the code they describe form an API - Application Product Interface.</p>
</div>
<p>
Normally, when you work with someone else's code, they provide a summary of their
methods, what they do and roughly how they work, as well as how they can go wrong.
Here is a table of the relevant instructions required to use my USB driver.</p>
<table>
<caption>
Table 5.1 Keyboard related functions in CSUD</caption>
<thead>
<tr>
<th>
Function