-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathteensy.asm
74 lines (62 loc) · 2.11 KB
/
teensy.asm
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
;-----------------------------------------------------------------------
; Routines for interacting with the Teensy 3.2 peripheral
;-----------------------------------------------------------------------
#local
#code _ROM
;-----------------------------------------------------------------------
; Send a device and address to the Teensy
; B - device
; C - addr
;-----------------------------------------------------------------------
TEENSY_REQ::
CALL TEENSY_WRITE ; Send the device first
LD B, C
JR TEENSY_WRITE ; Then the address (tail call)
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; Read a byte from device & addr from the Teensy
; B - device
; C - addr
; Returns:
; A - byte val
;-----------------------------------------------------------------------
TEENSY_RDDEV::
CALL TEENSY_REQ
JR TEENSY_READ
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; Write a byte to a device & addr in the Teensy
; B - Device
; C - Addr
; A - Value
;-----------------------------------------------------------------------
TEENSY_WRDEV::
PUSH AF
CALL TEENSY_REQ
POP AF
JR TEENSY_WRITE
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; Send a byte to the teensy
; B - byte
;-----------------------------------------------------------------------
TEENSY_WRITE::
IN A, (PIO_C) ; Read in status
BIT 7,A ; Check if output buffer full
JR Z, TEENSY_WRITE
LD A, B
OUT (PIO_A), A
RET
;-----------------------------------------------------------------------
;-----------------------------------------------------------------------
; Read a byte from the teensy
; Returns A - byte
;-----------------------------------------------------------------------
TEENSY_READ::
IN A, (PIO_C) ; Check status
BIT 5, A ; Check if input buffer full
JR Z, TEENSY_READ
IN A, (PIO_A)
RET
;-----------------------------------------------------------------------
#endlocal