|
1 /* |
|
2 |
|
3 u8x8_display.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 Abstraction layer for the graphics controller. |
|
36 Main goal is the placement of a 8x8 pixel block (tile) on the display. |
|
37 |
|
38 */ |
|
39 |
|
40 |
|
41 #include "u8x8.h" |
|
42 |
|
43 |
|
44 /*==========================================*/ |
|
45 /* internal library function */ |
|
46 |
|
47 /* |
|
48 this is a helper function for the U8X8_MSG_DISPLAY_SETUP_MEMORY function. |
|
49 It can be called within the display callback function to carry out the usual standard tasks. |
|
50 |
|
51 */ |
|
52 void u8x8_d_helper_display_setup_memory(u8x8_t *u8x8, const u8x8_display_info_t *display_info) |
|
53 { |
|
54 /* 1) set display info struct */ |
|
55 u8x8->display_info = display_info; |
|
56 u8x8->x_offset = u8x8->display_info->default_x_offset; |
|
57 } |
|
58 |
|
59 /* |
|
60 this is a helper function for the U8X8_MSG_DISPLAY_INIT function. |
|
61 It can be called within the display callback function to carry out the usual standard tasks. |
|
62 |
|
63 */ |
|
64 void u8x8_d_helper_display_init(u8x8_t *u8x8) |
|
65 { |
|
66 /* 2) apply port directions to the GPIO lines and apply default values for the IO lines*/ |
|
67 u8x8_gpio_Init(u8x8); |
|
68 u8x8_cad_Init(u8x8); |
|
69 |
|
70 /* 3) do reset */ |
|
71 u8x8_gpio_SetReset(u8x8, 1); |
|
72 u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms); |
|
73 u8x8_gpio_SetReset(u8x8, 0); |
|
74 u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms); |
|
75 u8x8_gpio_SetReset(u8x8, 1); |
|
76 u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->post_reset_wait_ms); |
|
77 } |
|
78 |
|
79 /*==========================================*/ |
|
80 /* official functions */ |
|
81 |
|
82 uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr) |
|
83 { |
|
84 u8x8_tile_t tile; |
|
85 tile.x_pos = x; |
|
86 tile.y_pos = y; |
|
87 tile.cnt = cnt; |
|
88 tile.tile_ptr = tile_ptr; |
|
89 return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, 1, (void *)&tile); |
|
90 } |
|
91 |
|
92 /* should be implemented as macro */ |
|
93 void u8x8_SetupMemory(u8x8_t *u8x8) |
|
94 { |
|
95 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SETUP_MEMORY, 0, NULL); |
|
96 } |
|
97 |
|
98 void u8x8_InitDisplay(u8x8_t *u8x8) |
|
99 { |
|
100 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_INIT, 0, NULL); |
|
101 } |
|
102 |
|
103 void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable) |
|
104 { |
|
105 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_POWER_SAVE, is_enable, NULL); |
|
106 } |
|
107 |
|
108 void u8x8_SetFlipMode(u8x8_t *u8x8, uint8_t mode) |
|
109 { |
|
110 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_FLIP_MODE, mode, NULL); |
|
111 } |
|
112 |
|
113 void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value) |
|
114 { |
|
115 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_CONTRAST, value, NULL); |
|
116 } |
|
117 |
|
118 void u8x8_RefreshDisplay(u8x8_t *u8x8) |
|
119 { |
|
120 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_REFRESH, 0, NULL); |
|
121 } |
|
122 |
|
123 void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf) |
|
124 { |
|
125 u8x8_tile_t tile; |
|
126 uint8_t h; |
|
127 |
|
128 tile.x_pos = 0; |
|
129 tile.cnt = 1; |
|
130 tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */ |
|
131 |
|
132 h = u8x8->display_info->tile_height; |
|
133 tile.y_pos = 0; |
|
134 do |
|
135 { |
|
136 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile); |
|
137 tile.y_pos++; |
|
138 } while( tile.y_pos < h ); |
|
139 } |
|
140 |
|
141 void u8x8_ClearDisplay(u8x8_t *u8x8) |
|
142 { |
|
143 uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
|
144 u8x8_ClearDisplayWithTile(u8x8, buf); |
|
145 } |
|
146 |
|
147 void u8x8_FillDisplay(u8x8_t *u8x8) |
|
148 { |
|
149 uint8_t buf[8] = { 255, 255, 255, 255, 255, 255, 255, 255 }; |
|
150 u8x8_ClearDisplayWithTile(u8x8, buf); |
|
151 } |
|
152 |
|
153 void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line) |
|
154 { |
|
155 uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
|
156 u8x8_tile_t tile; |
|
157 if ( line < u8x8->display_info->tile_height ) |
|
158 { |
|
159 tile.x_pos = 0; |
|
160 tile.y_pos = line; |
|
161 tile.cnt = 1; |
|
162 tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */ |
|
163 u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile); |
|
164 } |
|
165 } |