Skip to content

Commit 4772fde

Browse files
committed
Make sure to fully reinitialize SPI after APD, skip magic init on non-Python
1 parent 3362940 commit 4772fde

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/lcddrvce/lcddrvce.asm

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,26 @@ lcd_Init:
6868
ld (.refcount), hl
6969
ret c
7070
; Initialize if the old refcount was 0
71-
ld hl, ((9-1) shl 16) or (2-1)
72-
ld (ti.mpSpiCtrl1), hl
73-
; Only fully initialize once per program invocation
71+
; Always fully initialize on the first call per program invocation
7472
ld hl, .fullinit
7573
srl (hl)
76-
jr nc, .fastinit
74+
jr c, .checkPython
75+
; Additionally, fully initialize if an APD reset the SPI state to something other than LCD
76+
ld a, (ti.mpSpiCtrl0)
77+
cp a, ti.bmSpiMasterMono or ti.bmSpiClkPhase or ti.bmSpiClkPolarity
78+
jr z, .fastinit
79+
.checkPython:
7780
; Check certificate for Python model
7881
ld de, $0330
7982
call ti.FindFirstCertField
80-
jr nz, .magicinit
83+
jr nz, .notPython
8184
call ti.GetFieldSizeFromType
8285
ld de, $0430
8386
call ti.FindField
87+
jr nz, .notPython
8488
; Reinitializes Python hardware, probably (routine available on rev M+ boot code)
8589
; Without this, LCD SPI transfers start failing a short time after init
86-
call z, $000654
87-
.magicinit:
90+
call $000654
8891
; Magic SPI initialization sequence to work on Python models
8992
ld de, ti.spiSpiFrFmt or ti.bmSpiFlash or ti.bmSpiFsPolarity or ti.bmSpiMasterMono
9093
.loop:
@@ -100,12 +103,15 @@ lcd_Init:
100103
bit ti.bSpiClkPolarity, e
101104
ld e, ti.bmSpiFsPolarity or ti.bmSpiMasterMono or ti.bmSpiClkPhase or ti.bmSpiClkPolarity
102105
jr z, .loop
103-
.fastinit:
104106
ld hl, $21
105107
ld (ti.mpSpiIntCtrl), hl
106-
ld l, ti.bmSpiChipEn
107-
assert ti.bmSpiTxEn = (ti.bmSpiChipEn shl 8)
108-
ld h, l
108+
.notPython:
109+
ld a, ti.bmSpiMasterMono or ti.bmSpiClkPhase or ti.bmSpiClkPolarity
110+
ld (ti.mpSpiCtrl0), a
111+
.fastinit:
112+
ld hl, ((9-1) shl 16) or (2-1)
113+
ld (ti.mpSpiCtrl1), hl
114+
ld hl, ti.bmSpiTxEn or ti.bmSpiTxClr or ti.bmSpiRxClr or ti.bmSpiChipEn
109115
ld (ti.mpSpiCtrl2), hl
110116
ret
111117

0 commit comments

Comments
 (0)