Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_gp1294ai.c

182 lines · 6.6 KB · C

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