Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_gp1287ai.c

212 lines · 7.5 KB · C

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