-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathiic-chat-usb-host.mu4
43 lines (31 loc) · 1.15 KB
/
iic-chat-usb-host.mu4
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
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2025 David Frech. (Read the LICENSE for details.)
loading IIC chat over USB (host)
| Host-side code to drive the IIC chat code in
| target/S08/iic-chat-usb-core.mu4.
hex
| : usb ( bmRequest bRequest wValue wIndex wLength 'buffer)
| Commands:
| 0-3f Bye - exit chat code and return to chat loop
| 40 Read - send cmd, receive data bytes
| 41 ReadAcks - read back collected ACKs
| 42 Write - send cmd, data bytes, collect ACKS
| 43 Ping - send start bit, slave addr, stop, return ACK bit
( Control reads)
: iic.Read ( cmd slave len buf)
cr ." iic.Read " 3 nth u. 2 nth u. over u. dup u.
2push 2push
0c0 40 2pop 2pop usb ;
: iic.ReadAcks ( len buf) 2push
0c0 41 0 0 2pop usb ;
: iic.Ping ( slave - ack) push
0c0 43 0 pop 1 pad usb pad c@ ;
( Control writes)
: iic.Write ( cmd slave len buf)
cr ." iic.Write " 3 nth u. 2 nth u. over u. dup u.
2push 2push
40 42 2pop 2pop usb ;
: iic.Bye 40 0 0 0 0 0 usb ;
: iic.Hello ( start the IIC chat firmware on the connected device)
@iic-chat u.SetPC u.Run ;