Skip to content

Commit 9f5eff6

Browse files
committed
Arduino compatibility
1 parent 770f552 commit 9f5eff6

File tree

12 files changed

+2606
-4
lines changed

12 files changed

+2606
-4
lines changed

examples/gammacalibration-stm32-st7789/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
platform = ststm32
33
board = stm32f103c8
44
framework = libopencm3
5-
lib_extra_dirs = ../../mcu-renderer
5+
lib_extra_dirs = ../..

examples/helloworld-sdl/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ project(sdl_example)
55
set(CMAKE_C_STANDARD 99)
66

77
FILE(GLOB sources *.c)
8-
FILE(GLOB mcu_renderer_sources ../../mcu-renderer/src/*.c)
8+
FILE(GLOB mcu_renderer_sources ../../src/*.c)
99

1010
find_package(SDL2 CONFIG REQUIRED)
1111

1212
add_definitions(-D MCURENDERER_SDL)
1313

1414
add_executable(sdl_example ${sources} ${mcu_renderer_sources})
1515

16-
target_include_directories(sdl_example PRIVATE ../../mcu-renderer/src ../../fonts)
16+
target_include_directories(sdl_example PRIVATE ../../src ../../fonts)
1717
target_link_libraries(sdl_example
1818
PRIVATE
1919
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>

examples/helloworld-stm32-st7789/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
platform = ststm32
33
board = stm32f103c8
44
framework = libopencm3
5-
lib_extra_dirs = ../../mcu-renderer
5+
lib_extra_dirs = ../..

src/mcu-renderer-ili9341.h

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* MCU renderer
3+
* ILI9341 driver
4+
*
5+
* (C) 2023-2024 Gissio
6+
*
7+
* License: MIT
8+
*/
9+
10+
#if !defined(MCURENDERER_ILI9341_H)
11+
#define MCURENDERER_ILI9341_H
12+
13+
#include "mcu-renderer-st7789.h"
14+
15+
// ILI9341 level 1 commands
16+
17+
#define MR_ILI9341_NOP 0x00
18+
#define MR_ILI9341_SWRESET 0x01
19+
#define MR_ILI9341_RDDID 0x04
20+
#define MR_ILI9341_RDDST 0x09
21+
#define MR_ILI9341_RDDPM 0x0a
22+
#define MR_ILI9341_RDDMADCTL 0x0b
23+
#define MR_ILI9341_RDDCOLMOD 0x0c
24+
#define MR_ILI9341_RDDDIM 0x0d
25+
#define MR_ILI9341_RDDDSP 0x0e
26+
#define MR_ILI9341_RDDSDR 0x0f
27+
#define MR_ILI9341_SLPIN 0x10
28+
#define MR_ILI9341_SLPOUT 0x11
29+
#define MR_ILI9341_PTLON 0x12
30+
#define MR_ILI9341_NORON 0x13
31+
#define MR_ILI9341_INVOFF 0x20
32+
#define MR_ILI9341_INVON 0x21
33+
#define MR_ILI9341_GAMSET 0x26
34+
#define MR_ILI9341_DISPOFF 0x28
35+
#define MR_ILI9341_DISPON 0x29
36+
#define MR_ILI9341_CASET 0x2a
37+
#define MR_ILI9341_RASET 0x2b
38+
#define MR_ILI9341_RAMWR 0x2c
39+
#define MR_ILI9341_RAMRD 0x2e
40+
#define MR_ILI9341_PTLAR 0x30
41+
#define MR_ILI9341_VSCRDEF 0x33
42+
#define MR_ILI9341_TEOFF 0x34
43+
#define MR_ILI9341_TEON 0x35
44+
#define MR_ILI9341_MADCTL 0x36
45+
#define MR_ILI9341_MADCTL_MY (1 << 7)
46+
#define MR_ILI9341_MADCTL_MX (1 << 6)
47+
#define MR_ILI9341_MADCTL_MV (1 << 5)
48+
#define MR_ILI9341_MADCTL_BGR (1 << 3)
49+
#define MR_ILI9341_VSCRSADD 0x37
50+
#define MR_ILI9341_IDMOFF 0x38
51+
#define MR_ILI9341_IDMON 0x39
52+
#define MR_ILI9341_COLMOD 0x3a
53+
#define MR_ILI9341_COLMOD_16BPP ((0b101 << 4) | (0b101 << 0))
54+
#define MR_ILI9341_RAMWRC 0x3c
55+
#define MR_ILI9341_RAMRDC 0x3e
56+
#define MR_ILI9341_TESCAN 0x44
57+
#define MR_ILI9341_RDTESCAN 0x45
58+
#define MR_ILI9341_WRDISBV 0x51
59+
#define MR_ILI9341_RDDISBV 0x52
60+
#define MR_ILI9341_WRCTRLD 0x53
61+
#define MR_ILI9341_RDCTRLD 0x54
62+
#define MR_ILI9341_WRCACE 0x55
63+
#define MR_ILI9341_RDCABC 0x56
64+
#define MR_ILI9341_WRCABCMB 0x5e
65+
#define MR_ILI9341_RDCABCMB 0x5f
66+
#define MR_ILI9341_RDABCSDR 0x68
67+
#define MR_ILI9341_RDID1 0xda
68+
#define MR_ILI9341_RDID2 0xdb
69+
#define MR_ILI9341_RDID3 0xde
70+
71+
// ILI9341 Level 2 commands
72+
73+
#define MR_ILI9341_RGBCTRL 0xb0
74+
#define MR_ILI9341_FRCNORMAL 0xb1
75+
#define MR_ILI9341_FRCIDLE 0xb2
76+
#define MR_ILI9341_FRCPARTIAL 0xb3
77+
#define MR_ILI9341_DISPINVCTRL 0xb4
78+
#define MR_ILI9341_PORCTRL 0xb5
79+
#define MR_ILI9341_DISPFUNCCTRL 0xb6
80+
#define MR_ILI9341_ENTRYMODESET 0xb7
81+
#define MR_ILI9341_BACKLIGHTCTRL1 0xb8
82+
#define MR_ILI9341_BACKLIGHTCTRL2 0xb9
83+
#define MR_ILI9341_BACKLIGHTCTRL3 0xba
84+
#define MR_ILI9341_BACKLIGHTCTRL4 0xbb
85+
#define MR_ILI9341_BACKLIGHTCTRL5 0xbc
86+
#define MR_ILI9341_BACKLIGHTCTRL6 0xbd
87+
#define MR_ILI9341_BACKLIGHTCTRL7 0xbe
88+
#define MR_ILI9341_BACKLIGHTCTRL8 0xbf
89+
#define MR_ILI9341_POWERCTRL1 0xc0
90+
#define MR_ILI9341_POWERCTRL2 0xc1
91+
#define MR_ILI9341_VCOMCTRL1 0xc5
92+
#define MR_ILI9341_VCOMCTRL2 0xc7
93+
#define MR_ILI9341_NVMEMWR 0xd0
94+
#define MR_ILI9341_NVMEMPROT 0xd1
95+
#define MR_ILI9341_NVMEMRD 0xd2
96+
#define MR_ILI9341_ID4RD 0xd3
97+
#define MR_ILI9341_POSGAMMACORR 0xe0
98+
#define MR_ILI9341_NEGGAMMACORR 0xe1
99+
#define MR_ILI9341_DIGGAMMACTRL1 0xe2
100+
#define MR_ILI9341_DIGGAMMACTRL2 0xe3
101+
#define MR_ILI9341_IFCTRL 0xf6
102+
103+
// ILI9341 extended register commands
104+
105+
#define MR_ILI9341_POWCTRLA 0xcb
106+
#define MR_ILI9341_POWCTRLB 0xcf
107+
#define MR_ILI9341_TIMINGCTRLA1 0xe8
108+
#define MR_ILI9341_TIMINGCTRLA2 0xe9
109+
#define MR_ILI9341_POWERONSEQCTRL 0xed
110+
#define MR_ILI9341_TIMINGCTRLB 0xea
111+
#define MR_ILI9341_ENABLE3G 0xf2
112+
#define MR_ILI9341_PUMPRATIOCTRL 0xf7
113+
114+
/**
115+
* Initializes an mcu-renderer ILI9341 instance.
116+
*
117+
* @param mr The mcu-renderer instance.
118+
* @param width The physical pixel width of the display (e.g. 240).
119+
* @param height The physical pixel height of the display (e.g. 320).
120+
* @param rotation The desired display rotation.
121+
* @param textbuffer A user-provided buffer for rendering text.
122+
* @param textbuffer_size The size of the user-provided buffer.
123+
* @param sleep_callback A user-provided sleep callback.
124+
* @param set_reset_callback A user-provided set reset callback.
125+
* @param set_command_callback A user-provided set command callback.
126+
* @param send_callback A user-provided send 8-bit data callback.
127+
* @param send_callback A user-provided send 16-bit data callback.
128+
*/
129+
static inline void mr_ili9341_init(mr_t *mr,
130+
int16_t width,
131+
int16_t height,
132+
mr_display_rotation_t rotation,
133+
uint8_t *textbuffer,
134+
uint32_t textbuffer_size,
135+
mr_sleep_callback_t sleep_callback,
136+
mr_set_reset_callback_t set_reset_callback,
137+
mr_set_command_callback_t set_command_callback,
138+
mr_send_callback_t send_callback,
139+
mr_send_callback_t send16_callback)
140+
{
141+
mr_st7789_init(mr,
142+
width,
143+
height,
144+
rotation,
145+
textbuffer,
146+
textbuffer_size,
147+
sleep_callback,
148+
set_reset_callback,
149+
set_command_callback,
150+
send_callback,
151+
send16_callback);
152+
}
153+
154+
/**
155+
* Enables/disables the ILI9341 display.
156+
*
157+
* @param mr The mcu-renderer instance.
158+
* @param value Display enable.
159+
*/
160+
static inline void mr_ili9341_set_display(mr_t *mr,
161+
bool value)
162+
{
163+
mr_st7789_set_display(mr, value);
164+
}
165+
166+
/**
167+
* Enables/disables ILI9341 sleep mode. Takes 120 ms to finish.
168+
*
169+
* @param mr The mcu-renderer instance.
170+
* @param value Display enable.
171+
*/
172+
static inline void mr_ili9341_set_sleep(mr_t *mr,
173+
bool value)
174+
{
175+
mr_st7789_set_sleep(mr, value);
176+
}
177+
178+
#endif

0 commit comments

Comments
 (0)