Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8g2_buffer.c

213 lines · 6.7 KB · C

1/*
2
3 u8g2_buffer.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2016, 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 "u8g2.h"
37#include <string.h>
38
39/*============================================*/
40void u8g2_ClearBuffer(u8g2_t *u8g2)
41{
42 size_t cnt;
43 cnt = u8g2_GetU8x8(u8g2)->display_info->tile_width;
44 cnt *= u8g2->tile_buf_height;
45 cnt *= 8;
46 memset(u8g2->tile_buf_ptr, 0, cnt);
47}
48
49/*============================================*/
50
51static void u8g2_send_tile_row(u8g2_t *u8g2, uint8_t src_tile_row, uint8_t dest_tile_row)
52{
53 uint8_t *ptr;
54 uint16_t offset;
55 uint8_t w;
56
57 w = u8g2_GetU8x8(u8g2)->display_info->tile_width;
58 offset = src_tile_row;
59 ptr = u8g2->tile_buf_ptr;
60 offset *= w;
61 offset *= 8;
62 ptr += offset;
63 u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0, dest_tile_row, w, ptr);
64}
65
66/*
67 write the buffer to the display RAM.
68 For most displays, this will make the content visible to the user.
69 Some displays (like the SSD1606) require a u8x8_RefreshDisplay()
70*/
71static void u8g2_send_buffer(u8g2_t *u8g2) U8X8_NOINLINE;
72static void u8g2_send_buffer(u8g2_t *u8g2)
73{
74 uint8_t src_row;
75 uint8_t src_max;
76 uint8_t dest_row;
77 uint8_t dest_max;
78
79 src_row = 0;
80 src_max = u8g2->tile_buf_height;
81 dest_row = u8g2->tile_curr_row;
82 dest_max = u8g2_GetU8x8(u8g2)->display_info->tile_height;
83
84 do
85 {
86 u8g2_send_tile_row(u8g2, src_row, dest_row);
87 src_row++;
88 dest_row++;
89 } while( src_row < src_max && dest_row < dest_max );
90}
91
92/* same as u8g2_send_buffer but also send the DISPLAY_REFRESH message (used by SSD1606) */
93void u8g2_SendBuffer(u8g2_t *u8g2)
94{
95 u8g2_send_buffer(u8g2);
96 u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
97}
98
99/*============================================*/
100void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
101{
102 u8g2->tile_curr_row = row;
103 u8g2->cb->update_dimension(u8g2);
104 u8g2->cb->update_page_win(u8g2);
105}
106
107void u8g2_FirstPage(u8g2_t *u8g2)
108{
109 if ( u8g2->is_auto_page_clear )
110 {
111 u8g2_ClearBuffer(u8g2);
112 }
113 u8g2_SetBufferCurrTileRow(u8g2, 0);
114}
115
116uint8_t u8g2_NextPage(u8g2_t *u8g2)
117{
118 uint8_t row;
119 u8g2_send_buffer(u8g2);
120 row = u8g2->tile_curr_row;
121 row += u8g2->tile_buf_height;
122 if ( row >= u8g2_GetU8x8(u8g2)->display_info->tile_height )
123 {
124 u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
125 return 0;
126 }
127 if ( u8g2->is_auto_page_clear )
128 {
129 u8g2_ClearBuffer(u8g2);
130 }
131 u8g2_SetBufferCurrTileRow(u8g2, row);
132 return 1;
133}
134
135
136
137/*============================================*/
138/*
139 Description:
140 Update a sub area of the display, given by tile position, width and height.
141 The arguments are "tile" coordinates. Any u8g2 rotation is ignored.
142 This procedure only checks whether full buffer mode is active.
143 There is no error checking for the arguments: It is the responsibility of the
144 user to ensure, that the provided arguments are correct.
145
146 Limitations:
147 - Only available in full buffer mode (will not do anything in page mode)
148 - Tile positions and sizes (pixel position divided by 8)
149 - Any display rotation/mirror is ignored
150 - Only works with displays, which support U8x8 API
151 - Will not send the e-paper refresh message (will probably not work with e-paper devices)
152*/
153void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th)
154{
155 uint16_t page_size;
156 uint8_t *ptr;
157
158 /* check, whether we are in full buffer mode */
159 if ( u8g2->tile_buf_height != u8g2_GetU8x8(u8g2)->display_info->tile_height )
160 return; /* not in full buffer mode, do nothing */
161
162 page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */
163
164 ptr = u8g2_GetBufferPtr(u8g2);
165 ptr += tx*8;
166 ptr += page_size*ty;
167
168 while( th > 0 )
169 {
170 u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw, ptr );
171 ptr += page_size;
172 ty++;
173 th--;
174 }
175}
176
177/* same as sendBuffer, but does not send the ePaper refresh message */
178void u8g2_UpdateDisplay(u8g2_t *u8g2)
179{
180 u8g2_send_buffer(u8g2);
181}
182
183
184/*============================================*/
185
186/* vertical_top memory architecture */
187void u8g2_WriteBufferPBM(u8g2_t *u8g2, void (*out)(const char *s))
188{
189 u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
190 u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
191}
192
193void u8g2_WriteBufferXBM(u8g2_t *u8g2, void (*out)(const char *s))
194{
195 u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
196 u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
197}
198
199
200/* horizontal right memory architecture */
201/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
202void u8g2_WriteBufferPBM2(u8g2_t *u8g2, void (*out)(const char *s))
203{
204 u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
205 u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
206}
207
208void u8g2_WriteBufferXBM2(u8g2_t *u8g2, void (*out)(const char *s))
209{
210 u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
211 u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
212}
213