Skip to content

Commit 57a7b17

Browse files
committed
Add lcddrvce docs, update some API names, add more command macros, use enums for flag and field constants
1 parent fa4cf5c commit 57a7b17

File tree

7 files changed

+847
-236
lines changed

7 files changed

+847
-236
lines changed

docs/doxyfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@ INPUT = ../src/graphx/graphx.h \
937937
../src/usbdrvce/usbdrvce.h \
938938
../src/srldrvce/srldrvce.h \
939939
../src/fatdrvce/fatdrvce.h \
940-
../src/msddrvce/msddrvce.h
940+
../src/msddrvce/msddrvce.h \
941+
../src/lcddrvce/lcddrvce.h
941942

942943
# This tag can be used to specify the character encoding of the source files
943944
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

docs/libraries/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Common libraries:
1919
fontlibc
2020
fileioc
2121
keypadc
22+
lcddrvce
2223
libload
2324

2425
USB Libraries:

docs/libraries/lcddrvce.rst

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _lcddrvce_h:
2+
3+
lcddrvce.h
4+
==========
5+
6+
.. code-block:: c
7+
8+
#include <lcddrvce.h>
9+
10+
The :code:`lcddrvce` library is used for interacting with the Sitronix ST7789 LCD controller.
11+
12+
.. contents:: :local:
13+
:depth: 3
14+
15+
Overview
16+
--------
17+
18+
This library exposes interfaces to send any supported command to the LCD (this excludes read commands, which don't work reliably on CE hardware).
19+
20+
Communication with the LCD controller is done over an SPI connection; however, the SPI hardware is also used to communicate with the ARM coprocessor on Python models.
21+
As such, the SPI hardware is not always set up properly to communicate with the LCD controller, and this library exists to provide a reliable and performant interface to the LCD across calculator models.
22+
23+
Library Initialization
24+
----------------------
25+
26+
The :code:`lcd_Init` and :code:`lcd_Cleanup` functions provide reference-counted initialization and cleanup of the SPI configuration.
27+
That means multiple calls to :code:`lcd_Init()` are allowed, and the SPI hardware is restored to its original settings only after the same number of calls to :code:`lcd_Cleanup()`.
28+
Since the configuration is set differently than the OS's default settings for performance reasons, it's not allowed to power off the calculator without cleaning up the library first.
29+
This means if calling certain functions like :code:`os_GetKey` which can auto-power-down the calculator, either the LCD library should be cleaned up or auto-power-down should be disabled with :code:`os_DisableAPD()`.
30+
When using this library as part of another library's implementation and performance is not critical, it's safest to call both :code:`lcd_Init()` and :code:`lcd_Cleanup()` each time commands need to be sent.
31+
That way, users of the library will be able to cleanup the SPI configuration whenever they need to.
32+
33+
API Documentation
34+
-----------------
35+
36+
.. doxygenfile:: lcddrvce.h
37+
:project: CE C/C++ Toolchain

examples/library_examples/lcddrvce/gradient/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ int main(void)
1717
/* Switch RAM access to SPI and display mode to MCU */
1818
lcd_SetRamInterface(LCD_RAM_SPI | LCD_DM_MCU);
1919
/* Set 18bpp pixel format */
20-
lcd_SetPixelFormat(LCD_RGB_18BPP | LCD_MCU_18BPP);
20+
lcd_SetPixelFormat(LCD_SPI_18BPP | LCD_RGB_DEFAULT);
2121

2222
/* Start RAM write command */
23-
lcd_SendCommand(LCD_CMD_RAMWR);
23+
lcd_StartPixelWrite();
2424

2525
/* Generate and display gradient patterns */
2626
DrawGradient(0x040404);

examples/library_examples/lcddrvce/half_res/src/main.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ void SetHalfResMode(bool enable)
122122

123123
typedef struct res_settings
124124
{
125-
uint8_t frctrl2;
126-
uint8_t bpa;
125+
uint8_t frctrl;
126+
uint8_t bp;
127127
uint16_t xe;
128128
uint8_t tfa;
129129
uint8_t ramctrl1;
@@ -134,8 +134,8 @@ void SetHalfResMode(bool enable)
134134
{
135135
{
136136
/* Default ST7789 settings */
137-
.frctrl2 = LCD_FRCTRL2_DEFAULT,
138-
.bpa = LCD_BPA_DEFAULT,
137+
.frctrl = LCD_FRCTRL_DEFAULT,
138+
.bp = LCD_BP_DEFAULT,
139139
.xe = LCD_WIDTH - 1,
140140
.tfa = 0,
141141
.ramctrl1 = LCD_RAMCTRL1_DEFAULT
@@ -145,11 +145,11 @@ void SetHalfResMode(bool enable)
145145
* Refreshes LCD in at most 16.51 ms after VSYNC, assuming worst case 9.5 MHz clock
146146
* Waits at least 3.42 ms after VSYNC to read LCD memory, assuming worst case 10.5 MHz clock
147147
*/
148-
.frctrl2 = 8, /* 378 clocks per line */
149-
.bpa = 95, /* 95 lines of back porch */
148+
.frctrl = LCD_RTN_378 | LCD_NL_DEFAULT, /* 378 clocks per line */
149+
.bp = 95, /* 95 lines of back porch */
150150
.xe = HALF_LCD_WIDTH - 1,
151151
.tfa = HALF_LCD_WIDTH,
152-
.ramctrl1 = LCD_RAM_RGB | LCD_DM_VSYNC,
152+
.ramctrl1 = LCD_DM_VSYNC | LCD_RAM_DEFAULT,
153153
/* With the following PL111 timing:
154154
* Refreshes LCD at 60 Hz = 24 MHz / (800*250*2), a VSYNC period of 16.67 ms
155155
* Outputs 38400 pixels to LCD memory within the first 3.40 ms after VSYNC
@@ -184,9 +184,9 @@ void SetHalfResMode(bool enable)
184184
lcd_Init();
185185

186186
/* Set clocks per line */
187-
lcd_SetNormalFrameRateControl(p->frctrl2);
187+
lcd_SetNormalFrameRateControl(p->frctrl);
188188
/* Set back porch */
189-
lcd_SendCommand1(LCD_CMD_PORCTRL, p->bpa);
189+
lcd_SetNormalBackPorchControl(p->bp);
190190
/* Set horizontal output window */
191191
lcd_SetColumnAddress(0, p->xe);
192192
/* Set fixed left scroll area */

src/lcddrvce/lcddrvce.asm

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ library LCDDRVCE, 0
1414
export lcd_Init
1515
export lcd_Cleanup
1616
export lcd_Wait
17-
export lcd_SendCommandRaw
17+
export lcd_SendSizedCommandRaw
1818
export lcd_SendParamsRaw
1919
export lcd_SendCommand
2020
export lcd_SendCommand1
2121
export lcd_SendCommand2
22-
export lcd_SendCommandBytes
23-
export lcd_SendCommandWords
22+
export lcd_SendSizedCommandBytes
23+
export lcd_SendSizedCommandWords
2424
export lcd_SetUniformGamma
2525
export lcd_SetDefaultGamma
2626

@@ -134,14 +134,14 @@ _Gamma:
134134
; Set positive gamma
135135
ld bc, (14 shl 8) or $E0
136136
push bc
137-
call lcd_SendCommandRaw.entry
137+
call lcd_SendSizedCommandRaw.entry
138138
; Set negative gamma
139139
ex de, hl
140140
pop bc
141141
inc c
142-
jr lcd_SendCommandRaw.entry
142+
jr lcd_SendSizedCommandRaw.entry
143143

144-
lcd_SendCommandRaw:
144+
lcd_SendSizedCommandRaw:
145145
pop hl
146146
pop bc
147147
pop de
@@ -222,17 +222,17 @@ _sendSingleByte:
222222

223223
lcd_SendCommand:
224224
ld b, 0+1
225-
jr lcd_SendCommandBytes.entry
225+
jr lcd_SendSizedCommandBytes.entry
226226

227227
lcd_SendCommand1:
228228
ld b, 1+1
229-
jr lcd_SendCommandBytes.entry
229+
jr lcd_SendSizedCommandBytes.entry
230230

231231
lcd_SendCommand2:
232232
ld b, 2+1
233-
jr lcd_SendCommandBytes.entry
233+
jr lcd_SendSizedCommandBytes.entry
234234

235-
lcd_SendCommandBytes:
235+
lcd_SendSizedCommandBytes:
236236
pop hl
237237
pop bc
238238
push bc
@@ -252,7 +252,7 @@ lcd_SendCommandBytes:
252252
djnz .loop
253253
ret
254254

255-
lcd_SendCommandWords:
255+
lcd_SendSizedCommandWords:
256256
ld hl, 4
257257
add hl, sp
258258
ld b, (hl)

0 commit comments

Comments
 (0)