forked from olikraus/u8glib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu8g_dogm128_api.c
253 lines (204 loc) · 6.36 KB
/
u8g_dogm128_api.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
u8g_dogm128_api.c
Simulation of the dogm128 api for the u8g library
Universal 8bit Graphics Library
Copyright (c) 2011, [email protected]
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "u8g_dogm128_api.h"
extern void st_Setup(u8g_t *u8g);
u8g_t u8g_dogm128_obj;
uint8_t dog_height_minus_one;
static void u8g_init_dogm_common(void)
{
dog_height_minus_one = DOG_HEIGHT;
dog_height_minus_one--;
st_Setup(&u8g_dogm128_obj);
}
uint8_t u8g_InitDogm128API(u8g_dev_t *dev)
{
if ( u8g_Init(&u8g_dogm128_obj, dev) == 0 )
return 0;
u8g_init_dogm_common();
return 1;
}
#if defined(U8G_WITH_PINLIST)
uint8_t u8g_InitSPIDogm128API(u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
{
if ( u8g_InitSPI(&u8g_dogm128_obj, dev, sck, mosi, cs, a0, reset) == 0 )
return 0;
u8g_init_dogm_common();
return 1;
}
uint8_t u8g_InitHWSPIDogm128API(u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset)
{
if ( u8g_InitHWSPI(&u8g_dogm128_obj, dev, cs, a0, reset) == 0 )
return 0;
u8g_init_dogm_common();
return 1;
}
#endif
void u8g_SetDogmRot90(void)
{
u8g_SetRot90(&u8g_dogm128_obj);
u8g_init_dogm_common();
}
void u8g_SetDogmRot180(void)
{
u8g_SetRot180(&u8g_dogm128_obj);
u8g_init_dogm_common();
}
void u8g_SetDogmRot270(void)
{
u8g_SetRot270(&u8g_dogm128_obj);
u8g_init_dogm_common();
}
void dog_StartPage(void)
{
u8g_FirstPage(&u8g_dogm128_obj);
}
uint8_t dog_NextPage(void)
{
return u8g_NextPage(&u8g_dogm128_obj);
}
void dog_SetPixel(uint8_t x, uint8_t y)
{
y = dog_height_minus_one - y;
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
u8g_DrawPixel(&u8g_dogm128_obj, x, y);
}
void dog_ClrPixel(uint8_t x, uint8_t y)
{
y = dog_height_minus_one - y;
u8g_SetColorIndex(&u8g_dogm128_obj, 0);
u8g_DrawPixel(&u8g_dogm128_obj, x, y);
}
void dog_XorPixel(uint8_t x, uint8_t y)
{
/* not yet implemented */
}
/* x1 must be lower or equal to x2 */
void dog_SetHLine(uint8_t x1, uint8_t x2, uint8_t y)
{
//printf("SetHLine x1:%d x2:%d y:%d\n", x1, x2, y);
y = dog_height_minus_one - y;
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
u8g_DrawHLine(&u8g_dogm128_obj, x1, y, x2-x1+1);
//printf("SetHLine x:%d y:%d w:%d \n", x1, y, x2-x1+1);
}
void dog_ClrHLine(uint8_t x1, uint8_t x2, uint8_t y)
{
y = dog_height_minus_one - y;
u8g_SetColorIndex(&u8g_dogm128_obj, 0);
u8g_DrawHLine(&u8g_dogm128_obj, x1, y, x2-x1+1);
}
void dog_XorHLine(uint8_t x1, uint8_t x2, uint8_t y)
{
/* not yet implemented */
}
void dog_SetVLine(uint8_t x, uint8_t y1, uint8_t y2)
{
y1 = dog_height_minus_one - y1;
y2 = dog_height_minus_one - y2;
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
u8g_DrawVLine(&u8g_dogm128_obj, x, y2, y1-y2+1);
}
void dog_ClrVLine(uint8_t x, uint8_t y1, uint8_t y2)
{
y1 = dog_height_minus_one - y1;
y2 = dog_height_minus_one - y2;
u8g_SetColorIndex(&u8g_dogm128_obj, 0);
u8g_DrawVLine(&u8g_dogm128_obj, x, y2, y1-y2+1);
}
void dog_XorVLine(uint8_t x, uint8_t y1, uint8_t y2)
{
/* not yet implemented */
}
void dog_SetBitmapP(uint8_t x, uint8_t y, DOG_PGM_P bitmap, uint8_t w, uint8_t h)
{
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
y = dog_height_minus_one - y;
/* not fully compatible, it is assumed, that the "not used" bits are set to zero */
u8g_DrawBitmapP(&u8g_dogm128_obj, x, y, (w+7)/8, h, bitmap);
}
void dog_ClrBitmapP(uint8_t x, uint8_t y, DOG_PGM_P bitmap, uint8_t w, uint8_t h)
{
u8g_SetColorIndex(&u8g_dogm128_obj, 0);
y = dog_height_minus_one - y;
/* not fully compatible, it is assumed, that the "not used" bits are set to zero */
u8g_DrawBitmapP(&u8g_dogm128_obj, x, y, (w+7)/8, h, bitmap);
}
/* x1 must be lower or equal to x2 */
/* y1 must be lower or equal to y2 */
void dog_SetBox(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
y1 = dog_height_minus_one - y1;
y2 = dog_height_minus_one - y2;
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
u8g_DrawBox(&u8g_dogm128_obj, x1, y2, x2-x1+1, y1-y2+1);
}
void dog_ClrBox(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
y1 = dog_height_minus_one - y1;
y2 = dog_height_minus_one - y2;
u8g_SetColorIndex(&u8g_dogm128_obj, 0);
u8g_DrawBox(&u8g_dogm128_obj, x1, y2, x2-x1+1, y1-y2+1);
}
void dog_XorBox(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
/* not yet implemented */
}
uint8_t dog_GetStrWidth(DOG_PGM_P font, const char *s)
{
u8g_SetFont(&u8g_dogm128_obj, font);
return u8g_GetStrWidth(&u8g_dogm128_obj, s);
}
uint8_t dog_DrawStr(uint8_t x, uint8_t y, DOG_PGM_P font, const char *s)
{
y = dog_height_minus_one - y;
u8g_SetFont(&u8g_dogm128_obj, font);
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
return u8g_DrawStr(&u8g_dogm128_obj, x, y, s);
}
uint8_t dog_DrawStrP(uint8_t x, uint8_t y, DOG_PGM_P font, const u8g_pgm_uint8_t *s)
{
y = dog_height_minus_one - y;
u8g_SetFont(&u8g_dogm128_obj, font);
u8g_SetColorIndex(&u8g_dogm128_obj, 1);
return u8g_DrawStrP(&u8g_dogm128_obj, x, y, s);
}
char dog_itoa_buf[12];
char *dog_itoa(unsigned long v)
{
volatile unsigned char i = 11;
dog_itoa_buf[11] = '\0';
while( i > 0)
{
i--;
dog_itoa_buf[i] = (v % 10)+'0';
v /= 10;
if ( v == 0 )
break;
}
return dog_itoa_buf+i;
}