etherforth_logo

Node 014

This part of the USB module controller takes over when the keyboard has been initialized. It requests and processes keyboard reports, and sends relevant data to character conversion in node 013.

Source code

usb node 114 node 015 node 013 node 014
014 controller
x@ 00 @p !b @b ; @ !p
report 02 x@ 43 or 77 and if ; then
left a! x@ ! x@ x@ ! dup or 4 for x@ + next
x@ drop x@ drop x@ + 1FFFF and ! down a! 12008 ack ! ;
sof 1B 12002 sof ! x@ 30001 or if drop ;
then 12028 go !b r--- ;
keys 24 begin 12022 wait ! sof 1200C in01 ! report end
go 2B 12027 go ! r--- ; 2E

init down a! right b! go ; 32

6 d 5 r 0 ether

Definitions

x@
Get data from node 016 via port execution in node 015.
report
Read a byte from node 16 and if it is DATAx PID then read report from LEFT and send to RIGHT. We send one byte with control bits, discard the byte for OEM use, then send the first key scan code and sum up the remaining five scan codes. Finally we skip two bytes of CRC and add 16-bit CRC to the sum and mask the most significant bit. Thus, if only one or no key has been pressed, and report has been received without any error, the resulting value is zero. Otherwise it is non-zero (due to other key scan codes or CRC not being zero). We send this result word to RIGHT, restore A to DOWN and issue ACK handshake packet.
sof
Initiate sof in node 216, and read result of attached/detached line test (30000, 30001). If attached then return, else call go in node 015 and jump to RIGHT.
keys
Request 50 Keep_alive signals by calling wait in node 114, then we check attached/detached status with sof, and finally issue IN ENDP 1 and process a report from the device. This is an endless loop interrupted only if the device is detached.
go
This word starts a chain of calls ending in node 217, where it calls word go, which wakes up the USB controller.
init
Set A and B, and jump to go.

Description

This is the last loaded USB controller node. When we jump to go, we wake up the controller by calling words go in succession in nodes 114, 216, and 217. Then we jump to RIGHT, as node 015 takes care of keyboard initialization, while node 014 functions as a wire node (via RIGHT port execution).

Once the keyboard is initialized in boot protocol, node 014 is given the control through call to word keys, which interrogates the keyboard every 50 ms, and sends relevant bytes of a report received to character conversion in node 013.