diff options
Diffstat (limited to 'drivers/ugfx/gdisp/is31fl3731c/gdisp_is31fl3731c.c')
-rw-r--r-- | drivers/ugfx/gdisp/is31fl3731c/gdisp_is31fl3731c.c | 302 |
1 files changed, 0 insertions, 302 deletions
diff --git a/drivers/ugfx/gdisp/is31fl3731c/gdisp_is31fl3731c.c b/drivers/ugfx/gdisp/is31fl3731c/gdisp_is31fl3731c.c deleted file mode 100644 index 718824402..000000000 --- a/drivers/ugfx/gdisp/is31fl3731c/gdisp_is31fl3731c.c +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Fred Sundvik <fsundvik@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "gfx.h" | ||
19 | |||
20 | #if GFX_USE_GDISP | ||
21 | |||
22 | # define GDISP_DRIVER_VMT GDISPVMT_IS31FL3731C_QMK | ||
23 | # define GDISP_SCREEN_HEIGHT LED_HEIGHT | ||
24 | # define GDISP_SCREEN_WIDTH LED_WIDTH | ||
25 | |||
26 | # include "gdisp_lld_config.h" | ||
27 | # include "src/gdisp/gdisp_driver.h" | ||
28 | |||
29 | # include "board_is31fl3731c.h" | ||
30 | |||
31 | // Can't include led_tables from here | ||
32 | extern const uint8_t CIE1931_CURVE[]; | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Driver local definitions. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | # ifndef GDISP_INITIAL_CONTRAST | ||
39 | # define GDISP_INITIAL_CONTRAST 0 | ||
40 | # endif | ||
41 | # ifndef GDISP_INITIAL_BACKLIGHT | ||
42 | # define GDISP_INITIAL_BACKLIGHT 0 | ||
43 | # endif | ||
44 | |||
45 | # define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER << 0) | ||
46 | |||
47 | # define IS31_ADDR_DEFAULT 0x74 | ||
48 | |||
49 | # define IS31_REG_CONFIG 0x00 | ||
50 | // bits in reg | ||
51 | # define IS31_REG_CONFIG_PICTUREMODE 0x00 | ||
52 | # define IS31_REG_CONFIG_AUTOPLAYMODE 0x08 | ||
53 | # define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18 | ||
54 | // D2:D0 bits are starting frame for autoplay mode | ||
55 | |||
56 | # define IS31_REG_PICTDISP 0x01 // D2:D0 frame select for picture mode | ||
57 | |||
58 | # define IS31_REG_AUTOPLAYCTRL1 0x02 | ||
59 | // D6:D4 number of loops (000=infty) | ||
60 | // D2:D0 number of frames to be used | ||
61 | |||
62 | # define IS31_REG_AUTOPLAYCTRL2 0x03 // D5:D0 delay time (*11ms) | ||
63 | |||
64 | # define IS31_REG_DISPLAYOPT 0x05 | ||
65 | # define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames | ||
66 | # define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x8 | ||
67 | // D2:D0 bits blink period time (*0.27s) | ||
68 | |||
69 | # define IS31_REG_AUDIOSYNC 0x06 | ||
70 | # define IS31_REG_AUDIOSYNC_ENABLE 0x1 | ||
71 | |||
72 | # define IS31_REG_FRAMESTATE 0x07 | ||
73 | |||
74 | # define IS31_REG_BREATHCTRL1 0x08 | ||
75 | // D6:D4 fade out time (26ms*2^i) | ||
76 | // D2:D0 fade in time (26ms*2^i) | ||
77 | |||
78 | # define IS31_REG_BREATHCTRL2 0x09 | ||
79 | # define IS31_REG_BREATHCTRL2_ENABLE 0x10 | ||
80 | // D2:D0 extinguish time (3.5ms*2^i) | ||
81 | |||
82 | # define IS31_REG_SHUTDOWN 0x0A | ||
83 | # define IS31_REG_SHUTDOWN_OFF 0x0 | ||
84 | # define IS31_REG_SHUTDOWN_ON 0x1 | ||
85 | |||
86 | # define IS31_REG_AGCCTRL 0x0B | ||
87 | # define IS31_REG_ADCRATE 0x0C | ||
88 | |||
89 | # define IS31_COMMANDREGISTER 0xFD | ||
90 | # define IS31_FUNCTIONREG 0x0B // helpfully called 'page nine' | ||
91 | # define IS31_FUNCTIONREG_SIZE 0xD | ||
92 | |||
93 | # define IS31_FRAME_SIZE 0xB4 | ||
94 | |||
95 | # define IS31_PWM_REG 0x24 | ||
96 | # define IS31_PWM_SIZE 0x90 | ||
97 | |||
98 | # define IS31_LED_MASK_SIZE 0x12 | ||
99 | |||
100 | # define IS31 | ||
101 | |||
102 | /*===========================================================================*/ | ||
103 | /* Driver local functions. */ | ||
104 | /*===========================================================================*/ | ||
105 | |||
106 | typedef struct { | ||
107 | uint8_t write_buffer_offset; | ||
108 | uint8_t write_buffer[IS31_FRAME_SIZE]; | ||
109 | uint8_t frame_buffer[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH]; | ||
110 | uint8_t page; | ||
111 | } __attribute__((__packed__)) PrivData; | ||
112 | |||
113 | // Some common routines and macros | ||
114 | # define PRIV(g) ((PrivData *)g->priv) | ||
115 | |||
116 | /*===========================================================================*/ | ||
117 | /* Driver exported functions. */ | ||
118 | /*===========================================================================*/ | ||
119 | |||
120 | static GFXINLINE void write_page(GDisplay *g, uint8_t page) { | ||
121 | uint8_t tx[2] __attribute__((aligned(2))); | ||
122 | tx[0] = IS31_COMMANDREGISTER; | ||
123 | tx[1] = page; | ||
124 | write_data(g, tx, 2); | ||
125 | } | ||
126 | |||
127 | static GFXINLINE void write_register(GDisplay *g, uint8_t page, uint8_t reg, uint8_t data) { | ||
128 | uint8_t tx[2] __attribute__((aligned(2))); | ||
129 | tx[0] = reg; | ||
130 | tx[1] = data; | ||
131 | write_page(g, page); | ||
132 | write_data(g, tx, 2); | ||
133 | } | ||
134 | |||
135 | static GFXINLINE void write_ram(GDisplay *g, uint8_t page, uint16_t offset, uint16_t length) { | ||
136 | PRIV(g)->write_buffer_offset = offset; | ||
137 | write_page(g, page); | ||
138 | write_data(g, (uint8_t *)PRIV(g), length + 1); | ||
139 | } | ||
140 | |||
141 | LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { | ||
142 | // The private area is the display surface. | ||
143 | g->priv = gfxAlloc(sizeof(PrivData)); | ||
144 | __builtin_memset(PRIV(g), 0, sizeof(PrivData)); | ||
145 | PRIV(g)->page = 0; | ||
146 | |||
147 | // Initialise the board interface | ||
148 | init_board(g); | ||
149 | gfxSleepMilliseconds(10); | ||
150 | |||
151 | // zero function page, all registers (assuming full_page is all zeroes) | ||
152 | write_ram(g, IS31_FUNCTIONREG, 0, IS31_FUNCTIONREG_SIZE); | ||
153 | set_hardware_shutdown(g, false); | ||
154 | gfxSleepMilliseconds(10); | ||
155 | // software shutdown | ||
156 | write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); | ||
157 | gfxSleepMilliseconds(10); | ||
158 | // zero function page, all registers | ||
159 | write_ram(g, IS31_FUNCTIONREG, 0, IS31_FUNCTIONREG_SIZE); | ||
160 | gfxSleepMilliseconds(10); | ||
161 | |||
162 | // zero all LED registers on all 8 pages, and enable the mask | ||
163 | __builtin_memcpy(PRIV(g)->write_buffer, get_led_mask(g), IS31_LED_MASK_SIZE); | ||
164 | for (uint8_t i = 0; i < 8; i++) { | ||
165 | write_ram(g, i, 0, IS31_FRAME_SIZE); | ||
166 | gfxSleepMilliseconds(1); | ||
167 | } | ||
168 | |||
169 | // software shutdown disable (i.e. turn stuff on) | ||
170 | write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); | ||
171 | gfxSleepMilliseconds(10); | ||
172 | |||
173 | // Finish Init | ||
174 | post_init_board(g); | ||
175 | |||
176 | /* Initialise the GDISP structure */ | ||
177 | g->g.Width = GDISP_SCREEN_WIDTH; | ||
178 | g->g.Height = GDISP_SCREEN_HEIGHT; | ||
179 | g->g.Orientation = GDISP_ROTATE_0; | ||
180 | g->g.Powermode = powerOff; | ||
181 | g->g.Backlight = GDISP_INITIAL_BACKLIGHT; | ||
182 | g->g.Contrast = GDISP_INITIAL_CONTRAST; | ||
183 | return TRUE; | ||
184 | } | ||
185 | |||
186 | # if GDISP_HARDWARE_FLUSH | ||
187 | LLDSPEC void gdisp_lld_flush(GDisplay *g) { | ||
188 | // Don't flush if we don't need it. | ||
189 | if (!(g->flags & GDISP_FLG_NEEDFLUSH)) return; | ||
190 | |||
191 | PRIV(g)->page++; | ||
192 | PRIV(g)->page %= 2; | ||
193 | // TODO: some smarter algorithm for this | ||
194 | // We should run only one physical page at a time | ||
195 | // This way we don't need to send so much data, and | ||
196 | // we could use slightly less memory | ||
197 | uint8_t *src = PRIV(g)->frame_buffer; | ||
198 | for (int y = 0; y < GDISP_SCREEN_HEIGHT; y++) { | ||
199 | for (int x = 0; x < GDISP_SCREEN_WIDTH; x++) { | ||
200 | uint8_t val = (uint16_t)*src * g->g.Backlight / 100; | ||
201 | PRIV(g)->write_buffer[get_led_address(g, x, y)] = CIE1931_CURVE[val]; | ||
202 | ++src; | ||
203 | } | ||
204 | } | ||
205 | write_ram(g, PRIV(g)->page, IS31_PWM_REG, IS31_PWM_SIZE); | ||
206 | gfxSleepMilliseconds(1); | ||
207 | write_register(g, IS31_FUNCTIONREG, IS31_REG_PICTDISP, PRIV(g)->page); | ||
208 | |||
209 | g->flags &= ~GDISP_FLG_NEEDFLUSH; | ||
210 | } | ||
211 | # endif | ||
212 | |||
213 | # if GDISP_HARDWARE_DRAWPIXEL | ||
214 | LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { | ||
215 | coord_t x, y; | ||
216 | |||
217 | switch (g->g.Orientation) { | ||
218 | default: | ||
219 | case GDISP_ROTATE_0: | ||
220 | x = g->p.x; | ||
221 | y = g->p.y; | ||
222 | break; | ||
223 | case GDISP_ROTATE_180: | ||
224 | x = GDISP_SCREEN_WIDTH - 1 - g->p.x; | ||
225 | y = g->p.y; | ||
226 | break; | ||
227 | } | ||
228 | PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x] = gdispColor2Native(g->p.color); | ||
229 | g->flags |= GDISP_FLG_NEEDFLUSH; | ||
230 | } | ||
231 | # endif | ||
232 | |||
233 | # if GDISP_HARDWARE_PIXELREAD | ||
234 | LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { | ||
235 | coord_t x, y; | ||
236 | |||
237 | switch (g->g.Orientation) { | ||
238 | default: | ||
239 | case GDISP_ROTATE_0: | ||
240 | x = g->p.x; | ||
241 | y = g->p.y; | ||
242 | break; | ||
243 | case GDISP_ROTATE_180: | ||
244 | x = GDISP_SCREEN_WIDTH - 1 - g->p.x; | ||
245 | y = g->p.y; | ||
246 | break; | ||
247 | } | ||
248 | return gdispNative2Color(PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x]); | ||
249 | } | ||
250 | # endif | ||
251 | |||
252 | # if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL | ||
253 | LLDSPEC void gdisp_lld_control(GDisplay *g) { | ||
254 | switch (g->p.x) { | ||
255 | case GDISP_CONTROL_POWER: | ||
256 | if (g->g.Powermode == (powermode_t)g->p.ptr) return; | ||
257 | switch ((powermode_t)g->p.ptr) { | ||
258 | case powerOff: | ||
259 | case powerSleep: | ||
260 | case powerDeepSleep: | ||
261 | write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); | ||
262 | break; | ||
263 | case powerOn: | ||
264 | write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON); | ||
265 | break; | ||
266 | default: | ||
267 | return; | ||
268 | } | ||
269 | g->g.Powermode = (powermode_t)g->p.ptr; | ||
270 | return; | ||
271 | |||
272 | case GDISP_CONTROL_ORIENTATION: | ||
273 | if (g->g.Orientation == (orientation_t)g->p.ptr) return; | ||
274 | switch ((orientation_t)g->p.ptr) { | ||
275 | /* Rotation is handled by the drawing routines */ | ||
276 | case GDISP_ROTATE_0: | ||
277 | case GDISP_ROTATE_180: | ||
278 | g->g.Height = GDISP_SCREEN_HEIGHT; | ||
279 | g->g.Width = GDISP_SCREEN_WIDTH; | ||
280 | break; | ||
281 | case GDISP_ROTATE_90: | ||
282 | case GDISP_ROTATE_270: | ||
283 | g->g.Height = GDISP_SCREEN_WIDTH; | ||
284 | g->g.Width = GDISP_SCREEN_HEIGHT; | ||
285 | break; | ||
286 | default: | ||
287 | return; | ||
288 | } | ||
289 | g->g.Orientation = (orientation_t)g->p.ptr; | ||
290 | return; | ||
291 | |||
292 | case GDISP_CONTROL_BACKLIGHT: | ||
293 | if (g->g.Backlight == (unsigned)g->p.ptr) return; | ||
294 | unsigned val = (unsigned)g->p.ptr; | ||
295 | g->g.Backlight = val > 100 ? 100 : val; | ||
296 | g->flags |= GDISP_FLG_NEEDFLUSH; | ||
297 | return; | ||
298 | } | ||
299 | } | ||
300 | # endif // GDISP_NEED_CONTROL | ||
301 | |||
302 | #endif // GFX_USE_GDISP | ||