Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_gp1247ai.c

206 lines · 7.2 KB · C

1/*
2
3 u8x8_d_gp1247ai.c
4
5 252x64
6
7 https://github.com/olikraus/u8g2/issues/1907
8 https://github.com/olikraus/u8g2/pull/1892
9
10 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
11
12 Copyright (c) 2022, olikraus@gmail.com
13 All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without modification,
16 are permitted provided that the following conditions are met:
17
18 * Redistributions of source code must retain the above copyright notice, this list
19 of conditions and the following disclaimer.
20
21 * Redistributions in binary form must reproduce the above copyright notice, this
22 list of conditions and the following disclaimer in the documentation and/or other
23 materials provided with the distribution.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39*/
40
41#include "u8x8.h"
42
43#define SWAP8(a) ((((a)&0x80) >> 7) | (((a)&0x40) >> 5) | (((a)&0x20) >> 3) | (((a)&0x10) >> 1) | (((a)&0x08) << 1) | (((a)&0x04) << 3) | (((a)&0x02) << 5) | (((a)&0x01) << 7))
44
45/* ========== GP1247AI ========== */
46static const u8x8_display_info_t u8x8_gp1247ai_display_info = {
47 /* chip_enable_level = */ 0,
48 /* chip_disable_level = */ 1,
49
50 /* post_chip_enable_wait_ns = */ 240, /* tCS-CLK */
51 /* pre_chip_disable_wait_ns = */ 120, /* tCLK-CS */
52 /* reset_pulse_width_ms = */ 1, /* Trw */
53 /* post_reset_wait_ms = */ 1, /* Trth */
54 /* sda_setup_time_ns = */ 60, /* tsu */
55 /* sck_pulse_width_ns = */ 120, /* tcyc/2 */
56 /* sck_clock_hz = */ 4000000UL, /* MAX 4.16 MHz */
57 /* spi_mode = */ 3, /* active low, falling edge, MSBFIRST */
58 /* i2c_bus_clock_100kHz = */ 4, /* */
59 /* data_setup_time_ns = */ 60, /* tsu */
60 /* write_pulse_width_ns = */ 120, /* tcyc/2 */
61 /* tile_width = */ 32, /* 32*8=256 memory size */
62 /* tile_height = */ 8, /* 8*8=64 memory size */
63 /* default_x_offset = */ 0, /* */
64 /* flipmode_x_offset = */ 0, /* */
65 /* pixel_width = */ 253, /* display size */
66 /* pixel_height = */ 63 /* display size */
67};
68static const uint8_t u8x8_d_gp1247ai_init_seq[] = {
69 U8X8_START_TRANSFER(),
70 U8X8_C(SWAP8(0x0AA)), /* Software reset */
71 U8X8_END_TRANSFER(),
72 U8X8_DLY(1), /* Wait for reset */
73
74 U8X8_START_TRANSFER(),
75 U8X8_CA(SWAP8(0x078), SWAP8(0x008)), /* Oscillation Setting */
76 U8X8_END_TRANSFER(),
77
78 U8X8_START_TRANSFER(),
79 U8X8_CAA(SWAP8(0x0CC), SWAP8(0x005), SWAP8(0x000)), /* VFD Mode Setting */
80 U8X8_END_TRANSFER(),
81
82 U8X8_START_TRANSFER(),
83 U8X8_CAAA(SWAP8(0x0E0), SWAP8(0x0FC), SWAP8(0x03E), SWAP8(0x000)), /* Display Area Setting */
84 U8X8_A4(SWAP8(0x020), SWAP8(0x080), SWAP8(0x080), SWAP8(0x080)), /* Display Area Setting */
85 U8X8_END_TRANSFER(),
86
87 U8X8_START_TRANSFER(),
88 U8X8_CAAAA(SWAP8(0x0B1), SWAP8(0x020), SWAP8(0x03F), SWAP8(0x000), SWAP8(0x001)), /* Internal Speed Setting */
89 U8X8_END_TRANSFER(),
90
91 U8X8_START_TRANSFER(),
92 U8X8_CAA(SWAP8(0x0A0), SWAP8(0x000), SWAP8(0x028)), /* Dimming level Setting (1024 level, 0x3FF max) */
93 U8X8_END_TRANSFER(),
94
95 U8X8_START_TRANSFER(),
96 U8X8_C(SWAP8(0x055)), /* Memory Map Clear */
97 U8X8_END_TRANSFER(),
98 U8X8_DLY(15), /* Wait for memory clear */
99
100 U8X8_START_TRANSFER(),
101 U8X8_CAA(SWAP8(0x0C0), SWAP8(0x000), SWAP8(0x000)), /* DW1 position setting */
102 U8X8_END_TRANSFER(),
103
104 U8X8_START_TRANSFER(),
105 U8X8_CAA(SWAP8(0x0D0), SWAP8(0x000), SWAP8(0x040)), /* DW2 position setting */
106 U8X8_END_TRANSFER(),
107
108 U8X8_START_TRANSFER(),
109 U8X8_CA(SWAP8(0x080), SWAP8(0x080)), /* Display Mode Setting */
110 U8X8_END_TRANSFER(),
111
112 U8X8_START_TRANSFER(),
113 U8X8_C(SWAP8(0x061)), /* Standby Mode */
114 U8X8_END_TRANSFER(),
115
116 U8X8_END() /* end of sequence */
117};
118static const uint8_t u8x8_d_gp1247ai_standby_seq[] = {
119 U8X8_START_TRANSFER(),
120 U8X8_C(SWAP8(0x061)), /* Standby */
121 U8X8_END_TRANSFER(),
122
123 U8X8_END() /* end of sequence */
124};
125static const uint8_t u8x8_d_gp1247ai_wakeup_seq[] = {
126 U8X8_START_TRANSFER(),
127 U8X8_C(SWAP8(0x06D)), /* Wake up */
128 U8X8_END_TRANSFER(),
129 U8X8_DLY(1), /* Wait for OSC stabilize */
130
131 U8X8_START_TRANSFER(),
132 U8X8_CA(SWAP8(0x080), SWAP8(0x080)), /* After entering standby mode, the SC bit will be automatically cleared */
133 U8X8_END_TRANSFER(),
134
135 U8X8_END() /* end of sequence */
136};
137uint8_t u8x8_d_gp1247ai_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
138{
139 uint8_t *ptr;
140 uint8_t x, y;
141 uint16_t tx_cnt;
142 uint8_t swapped_byte;
143 switch (msg)
144 {
145 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
146 if (arg_int == 0)
147 u8x8_cad_SendSequence(u8x8, u8x8_d_gp1247ai_wakeup_seq);
148 else
149 u8x8_cad_SendSequence(u8x8, u8x8_d_gp1247ai_standby_seq);
150 break;
151#ifdef U8X8_WITH_SET_CONTRAST
152 case U8X8_MSG_DISPLAY_SET_CONTRAST:
153 u8x8_cad_StartTransfer(u8x8);
154 u8x8_cad_SendCmd(u8x8, SWAP8(0x0A0));
155 u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) >> 8)); /* Dimming level */
156 u8x8_cad_SendArg(u8x8, SWAP8((arg_int * 4) & 0xFF)); /* Dimming level */
157 u8x8_cad_EndTransfer(u8x8);
158 break;
159#endif
160 case U8X8_MSG_DISPLAY_DRAW_TILE:
161 x = ((u8x8_tile_t *)arg_ptr)->x_pos * 8;
162 y = ((u8x8_tile_t *)arg_ptr)->y_pos * 8;
163
164 u8x8_cad_StartTransfer(u8x8);
165
166 u8x8_cad_SendCmd(u8x8, SWAP8(0x0F0));
167 u8x8_cad_SendArg(u8x8, SWAP8(x));
168 u8x8_cad_SendArg(u8x8, SWAP8(y));
169 u8x8_cad_SendArg(u8x8, SWAP8(0x007)); /* return every 8 pixels */
170 do
171 {
172 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
173 tx_cnt = ((u8x8_tile_t *)arg_ptr)->cnt * 8;
174 while (tx_cnt > 0)
175 {
176 swapped_byte = SWAP8(*ptr);
177 u8x8_cad_SendData(u8x8, 1, &swapped_byte);
178 ptr += 1;
179 tx_cnt -= 1;
180 }
181 arg_int--;
182 } while (arg_int > 0);
183
184 u8x8_cad_EndTransfer(u8x8);
185 break;
186 default:
187 return 0;
188 }
189 return 1;
190}
191uint8_t u8x8_d_gp1247ai_253x63(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
192{
193 switch (msg)
194 {
195 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
196 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_gp1247ai_display_info);
197 break;
198 case U8X8_MSG_DISPLAY_INIT:
199 u8x8_d_helper_display_init(u8x8);
200 u8x8_cad_SendSequence(u8x8, u8x8_d_gp1247ai_init_seq);
201 break;
202 default:
203 return u8x8_d_gp1247ai_common(u8x8, msg, arg_int, arg_ptr);
204 }
205 return 1;
206}