84PCE:Ports:D000

From WikiTI
Revision as of 22:36, 19 October 2023 by Calc84maniac (Talk | contribs)

Jump to: navigation, search

Synopsis

Port Number: D000

Memory-mapped Address: F80000

Function: LCD Interface

This appears to be an FTSSP010 or compatible SPI controller that interfaces with the LCD. The command set seems to closely match the Sitronix ST7789 family [1].

Note that the SPI controller may also be configured to interface with the ARM coprocessor on Python models, via some ports in the 00xx range. The state of this configuration should be considered unknown when starting a program in TI-OS. In order to reliably use the LCD interface, the _boot_InitializeHardware routine should be called at the start of a program to select the LCD interface and reset its configuration to the default.


Port    Default    Bits    Information   
D000
F80000
0000182B 0000FFFF CR0: Bits 12-15 indicate the protocol, set the value to 1 for SPI.
The selected protocol determines the read mask; the effective mask for SPI is F8EF.
Boot code writes 180B/09 before/after turning on/off the lcd.
D004
F80004
0002000B 007FFFFF CR1: Bits 0-15 are clock divider - 1, bits 16-22 are FIFO entry data length in bits - 1.
According to some drivers, bits 24-31 are padding length, but on this controller it's non-writable and seems to have no effect on transfers or timing.
Base clock is 24 MHz (unconfirmed whether this changes with CPU speed).
Sending with a clock divider of 1 to the LCD has been empirically unreliable across models, but a divider of 2 seems safe. According to LCD controller specs, receiving may require a larger divider.
D008
F80008
0000010C 00000FCF CR2: Bit 0 is set to transfer data and activate the SPI chip select signal.
Bit 1 is set for data output enable according to some drivers, but this has no effect on LCD sends.
Writing a 1 to Bit 2 clears the receive FIFO and writing a 1 to Bit 3 clears the send FIFO. Writing a 1 to Bit 6 resets the SPI controller.
Bit 7 is set to enable receiving, Bit 8 is set to enable sending.
Bits 9-11 are used for chip select, according to some drivers. Set to 0 for LCD sends.
D00C
F8000C
00000002 0001F1F7 Status bits (read-only).
Bit 0 is set if the receive FIFO is full, and Bit 1 is set if the send FIFO is not full (can accept more writes).
Bit 2 is set if data is being sent or received, bits 4-8 are the number of queued receive FIFO entries, and bits 12-16 are the number of queued send FIFO entries.
Boot code waits for bits 12-15 and bit 2 to be 0 (in that order) before/after reading/writing.
Receiving seems to stop after 15 FIFO entries are full, unless the send FIFO is non-empty. Conversely, receiving does not stop before 15 FIFO entries are full, even if the send FIFO is empty.
It's unclear what data is sent when this occurs, so it's best to disable the transfer when the send FIFO underruns.
D010
F80010
00000021 0001FFBF Interrupt control. Masked with interrupt status to generate interrupts.
Bit 0: Receive FIFO overrun interrupt enable.
Bit 1: Send FIFO underrun interrupt enable.
Bit 2: Receive FIFO threshold interrupt enable.
Bit 3: Send FIFO threshold interrupt enable.
Bits 7-11: Receive FIFO threshold. The interrupt status bit is set if and only if the receive FIFO has this many queued entries or more. Ignored when set to 0.
Bits 12-16: Send FIFO threshold. The interrupt status bit is set if and only if the send FIFO has this many queued entries or fewer. Ignored when set to 0.
D014
F80014
0000000F Interrupt status (read-only). Non-threshold bits are cleared after read.
Bit 0: Receive FIFO overrun according to some drivers; however, it seems the transfer simply stops before an overrun can happen.
Bit 1: Send FIFO underrun (set only when both sending and receiving).
Bit 2: Receive FIFO threshold. Cleared only when the condition becomes false.
Bit 3: Send FIFO threshold. Cleared only when the condition becomes false.
D018
F80018
FFFFFFFF FIFO in/out. Writes push to the send FIFO, and reads pop from the receive FIFO.
Supports up to a 32-bit data length, but when working with more than 8 bits, the low byte access must come last because it causes the push/pop of the entire entry.
The upper 24 bits are latched when written to, but seem to be undefined after pushing a FIFO entry.
Any read bits when the FIFO is empty or outside of the receive's configured bit length are undefined, and should be ignored/masked out.
D01C
F8001C
0E0F0F1F Inside reserved range. Appears to be a copy of the feature register at D064.
D060
F80060
00012100 Revision (read-only)
D064
F80064
0E0F0F1F Features (read-only): 32-bit data width, 16-entry send/receive FIFOs, list of extra protocols supported.

Known Commands

Hex
Defaults
Command Details
01 Software Reset
10
10
Enable Sleep Mode Turns pixels black, low power mode?
11
11
Disable Sleep Mode
12 Enable Partial Mode Resets vertical scrolling start to 0.
13 Disable Partial Mode Also disables vertical scrolling mode and resets vertical scrolling start to 0.
20 Uninvert Colors
21 Invert Colors
26 <8:GC>
26 00
26 02
Set Gamma Selects between 4 preset gamma curves: Valid values are 1, 2, 4, 8, invalid values appear to use 1.
28 Turn Off Display Turns all pixels white.
29
29
Turn On Display Restore GRAM pixels.
2A <BE16:StartCol> <BE16:EndCol>
2A 0000 013F
Set Window Columns Set the pixel update window from StartCol to EndCol inclusive.
2B <BE16:StartLine> <BE16:EndRow>
2B 0000 00EF
Set Window Rows Set the pixel update window from StartRow to EndRow inclusive.
30 <BE16:StartRow> <BE16:EndRow> Set Partial Area Rows Only displays from StartRow to EndRow inclusive, other lines white.
33 <BE16:TopArea> <BE16:ScrollArea> <BE16:BottomArea> Vertical Scrolling Definition TopArea/BottomArea are static (non-scrolling) line counts before and after the ScrollArea whose value is ignored.
36 <8:MAC>
36 08
Memory Address Control Bit 2: Horizontal Refresh Order
Bit 3: BGR Order
Bit 4: Vertical Refresh Order
Bit 5: Column Major Update
Bit 6: Column Update Order
Bit 7: Row Update Order
37 <BE16:VSP> Vertical Scrolling Start Position First line of ScrollArea starts at this GRAM line.
38 Disable Idle Mode Restore 18bpp mode.
39 Enable Idle Mode 3bpp 8 color mode (only uses msb of each color component).
3A ?
3A 66
Interface Pixel Format Upper and lower nibbles are modes for the two interfaces: 3 is 12bpp, 5 is 16bpp, 6 is 18bpp (msb is ignored, invalid uses 18bpp).
B0 ? ?
B0 11 F0
Interface Control First Param:
Bit 0: Use lcd controller clocks instead of internal clocks.
Bit 4: Get GRAM data from lcd controller instead of spi interface.
Bit 7: Bypass GRAM and output directly to lcd.
Second Param:
Polarity of clocks?
B1 ? ? ?
B1 01 05 14
B1 01 15 14
Unknown?
B2 ? ? ? ? ?
B2 0C 0C 00 33 33
Unknown?
B7 ?
B7 35
Unknown?
BB ?
BB 17
BB 1B
Unknown?
C0 ?
C0 2C
C0 22
Unknown?
C2 ?
C2 01
Unknown?
C3 ?
C3 03
C3 15
Unknown?
C4 ?
C4 20
Unknown?
C6 ?
C6 0F
Unknown?
D0 ? ?
D0 AF A1
Unknown?
D2 ?
D2 00
Unknown?
DC Unknown? One parameter "read" and checked if equal to 0x35, but reading doesn't appear to work in the first place...
E0 ? ? ? ? ? ? ? ? ? ? ? ? ? ?
E0 D0 00 00 10 0F 1A 2D 54 3F 3B 18 17 13 17
E0 D0 00 00 10 0F 1A 2D 54 3F 3B 18 17 13 17
Positive Gamma Correction Definitely affects gamma, parameters unknown and don't match docs.
E1 ? ? ? ? ? ? ? ? ? ? ? ? ? ?
E1 D0 00 00 10 0F 09 2B 43 40 3B 18 17 13 17
E1 D0 00 00 10 0F 09 2B 43 40 3B 18 17 13 17
Negative Gamma Correction Definitely affects gamma, parameters unknown and don't match docs.
E9 ? ? ?
E9 08 08 08
Unknown?
EB Something!
F0 Gamma?
F1 Gamma?
F2 Gamma?

Example

Sending

 ld a,036h ; Flips the lcd horizontally, vertically, and swaps the b and r components
 call spiCmd
 ld a,0C0h
 call spiParam

 ld a,002h ; Resetting the lcd on exit
 call spiCmd
 jp boot_InitializeHardware

; Input: A = parameter
spiParam:
 scf ; First bit is set for data
 .db 030h ; jr nc,? ; skips over one byte
; Input: A = command
spiCmd:
 or a,a ; First bit is clear for commands
 ld hl,0F80818h
 call spiWrite
 ld l,h
 ld (hl),001h
spiWait:
 ld l,00Dh
spiWait1:
 ld a,(hl)
 and a,0F0h
 jr nz,spiWait1
 dec l
spiWait2:
 bit 2,(hl)
 jr nz,spiWait2
 ld l,h
 ld (hl),a
 ret
spiWrite:
 ld b,3
spiWriteLoop:
 rla
 rla
 rla
 ld (hl),a ; send 3 bits
 djnz spiWriteLoop
 ret

Receiving

This does not appear to work, always returning 0 on the calcs I've tested, due to either a TI bug or hardware issue.

; Input: A = command
; Ouput: A = data
spiRead:
 ld hl,0F80808
 ld (hl),00Ch
 ld l,018h
 or a,a
 call spiWrite
 xor a,a ; not sure what this is for
 call spiWrite
 ld l,009h
 ld (hl),001h
 dec l
 ld (hl),081h
 call spiWait
 ld l,$18
 ld a,(hl) ; dummy read
 ld a,(hl)
 ld a,(hl) ; Why is there no wait after dummy read?
 ld a,(hl)
 rla
 rla
 rla
 rla
 rla
 and a,0E0h
 ld c,a
 ld a,(hl)
 rla
 rla
 and a,01Ch
 or a,c
 ld c,a
 ld a,(hl)
 rra ; why are we throwing away the lsb instead of the msb
 and a,003h
 or a,c
 ret