Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_st7539.c

179 lines · 6.3 KB · C

1/*
2
3 u8x8_d_st7539.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
39
40
41static const uint8_t u8x8_d_st7539_192x64_powersave0_seq[] = {
42 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
43 U8X8_C(0x0af), /* display on */
44 U8X8_END_TRANSFER(), /* disable chip */
45 U8X8_END() /* end of sequence */
46};
47
48static const uint8_t u8x8_d_st7539_192x64_powersave1_seq[] = {
49 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
50 U8X8_C(0x0ae), /* display off */
51 U8X8_END_TRANSFER(), /* disable chip */
52 U8X8_END() /* end of sequence */
53};
54
55static const uint8_t u8x8_d_st7539_192x64_flip0_seq[] = {
56 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
57 U8X8_C(0x0c2), /* bit 1: MX, bit 2: MY */
58 U8X8_END_TRANSFER(), /* disable chip */
59 U8X8_END() /* end of sequence */
60};
61
62static const uint8_t u8x8_d_st7539_192x64_flip1_seq[] = {
63 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
64 U8X8_C(0x0c4), /* bit 1: MX, bit 2: MY */
65 U8X8_END_TRANSFER(), /* disable chip */
66 U8X8_END() /* end of sequence */
67};
68
69
70static const u8x8_display_info_t u8x8_st7539_192x64_display_info =
71{
72 /* chip_enable_level = */ 0,
73 /* chip_disable_level = */ 1,
74
75 /* post_chip_enable_wait_ns = */ 1, /* st7539 datasheet, page 46 */
76 /* pre_chip_disable_wait_ns = */ 5, /* st7539 datasheet, page 46 */
77 /* reset_pulse_width_ms = */ 1,
78 /* post_reset_wait_ms = */ 6,
79 /* sda_setup_time_ns = */ 12, /* st7539 datasheet, page 44 */
80 /* sck_pulse_width_ns = */ 15, /* st7539 datasheet, page 44 */
81 /* sck_clock_hz = */ 2000000UL, /* */
82 /* spi_mode = */ 0, /* active high, rising edge */
83 /* i2c_bus_clock_100kHz = */ 1,
84 /* data_setup_time_ns = */ 60, /* st7539 datasheet, page 43 */
85 /* write_pulse_width_ns = */ 80, /* st7539 datasheet, page 43 */
86 /* tile_width = */ 24,
87 /* tile_height = */ 8,
88 /* default_x_offset = */ 0,
89 /* flipmode_x_offset = */ 0,
90 /* pixel_width = */ 192,
91 /* pixel_height = */ 64
92};
93
94static const uint8_t u8x8_d_st7539_192x64_init_seq[] = {
95
96 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
97
98 U8X8_C(0x0e2), /* soft reset */
99 U8X8_C(0x0a0), /* 76Hz FPS*/
100 U8X8_C(0x0eb), /* LCD Bias: 0xe8: 6, 0xe9: 7, 0xea: 8, 0xeb: 9 */
101 U8X8_C(0x0c2), /* RAM mapping ctrl */
102 U8X8_CA(0x081, 145), /* set contrast */
103 U8X8_C(0x02e), /* LCD Load + Internal Charge Pump (default: 0x2e) */
104 U8X8_C(0x040), /* set display start line to 0 */
105
106 U8X8_C(0x0a6), /* normal display */
107
108 U8X8_END_TRANSFER(), /* disable chip */
109 U8X8_END() /* end of sequence */
110};
111
112// https://github.com/olikraus/u8g2/issues/2146
113
114uint8_t u8x8_d_st7539_192x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
115{
116 uint8_t x, c;
117 uint8_t *ptr;
118 switch(msg)
119 {
120 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
121 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7539_192x64_display_info);
122 break;
123 case U8X8_MSG_DISPLAY_INIT:
124 u8x8_d_helper_display_init(u8x8);
125 u8x8_cad_SendSequence(u8x8, u8x8_d_st7539_192x64_init_seq);
126 break;
127 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
128 if ( arg_int == 0 )
129 u8x8_cad_SendSequence(u8x8, u8x8_d_st7539_192x64_powersave0_seq);
130 else
131 u8x8_cad_SendSequence(u8x8, u8x8_d_st7539_192x64_powersave1_seq);
132 break;
133 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
134 if ( arg_int == 0 )
135 {
136 u8x8_cad_SendSequence(u8x8, u8x8_d_st7539_192x64_flip0_seq);
137 u8x8->x_offset = u8x8->display_info->default_x_offset;
138 }
139 else
140 {
141 u8x8_cad_SendSequence(u8x8, u8x8_d_st7539_192x64_flip1_seq);
142 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
143 }
144 break;
145#ifdef U8X8_WITH_SET_CONTRAST
146 case U8X8_MSG_DISPLAY_SET_CONTRAST:
147 u8x8_cad_StartTransfer(u8x8);
148 u8x8_cad_SendCmd(u8x8, 0x081 );
149 u8x8_cad_SendArg(u8x8, arg_int ); /* st7539 has range from 0 to 255 */
150 u8x8_cad_EndTransfer(u8x8);
151 break;
152#endif
153 case U8X8_MSG_DISPLAY_DRAW_TILE:
154 u8x8_cad_StartTransfer(u8x8);
155
156 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
157 x *= 8;
158 x += u8x8->x_offset;
159 u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
160 u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
161 u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
162
163 c = ((u8x8_tile_t *)arg_ptr)->cnt;
164 c *= 8;
165 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
166 do
167 {
168 u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
169 arg_int--;
170 } while( arg_int > 0 );
171
172 u8x8_cad_EndTransfer(u8x8);
173 break;
174 default:
175 return 0;
176 }
177 return 1;
178}
179