1 | #include "SSD1309.h"
|
2 | #include "fonts.c"
|
3 |
|
4 |
|
5 | void swap(int16_t *a, int16_t *b)
|
6 | {
|
7 | int16_t temp = 0x0000;
|
8 |
|
9 | temp = *b;
|
10 | *b = *a;
|
11 | *a = temp;
|
12 | }
|
13 |
|
14 |
|
15 | inline void OLED_init()
|
16 | {
|
17 | //init SPI => Done in NRF24 Init
|
18 | //SPI_MasterInit(&spiMasterD, &SPIC, &PORTC, FALSE, SPI_MODE_0_gc, SPI_INTLVL_OFF_gc, TRUE, SPI_PRESCALER_DIV4_gc);
|
19 |
|
20 | OLED_reset_sequence();
|
21 |
|
22 | OLED_write((Set_Display_ON_or_OFF_CMD + Display_OFF) , CMD);;
|
23 |
|
24 | OLED_write(Set_Display_Clock_CMD, CMD);
|
25 | OLED_write(0x80, CMD);
|
26 |
|
27 | OLED_write(Set_Multiplex_Ratio_CMD, CMD);
|
28 | OLED_write(0x3F, CMD);
|
29 |
|
30 | OLED_write(Set_Display_Offset_CMD, CMD);
|
31 | OLED_write(0x00, CMD);
|
32 |
|
33 | OLED_write((Set_Display_Start_Line_CMD | 0x00), CMD);
|
34 |
|
35 | OLED_write(Set_Charge_Pump_CMD, CMD);
|
36 | OLED_write((Set_Higher_Column_Start_Address_CMD | Enable_Charge_Pump), CMD);
|
37 |
|
38 | OLED_write(Set_Memory_Addressing_Mode_CMD, CMD);
|
39 | OLED_write(Page_Addressing_Mode, CMD);
|
40 |
|
41 | OLED_write((Set_Segment_Remap_CMD | Column_Address_0_Mapped_to_SEG127), CMD);
|
42 |
|
43 | OLED_write((Set_COM_Output_Scan_Direction_CMD | Scan_from_COM63_to_0), CMD);
|
44 |
|
45 | OLED_write(Set_Common_HW_Config_CMD, CMD);
|
46 | OLED_write(0x12, CMD);
|
47 |
|
48 | OLED_write(Set_Contrast_Control_CMD, CMD);
|
49 | OLED_write(0xCF, CMD);
|
50 |
|
51 | OLED_write(Set_Pre_charge_Period_CMD, CMD);
|
52 | OLED_write(0xF1, CMD);
|
53 |
|
54 | OLED_write(Set_VCOMH_Level_CMD, CMD);
|
55 | OLED_write(0x40, CMD);
|
56 |
|
57 | OLED_write((Set_Entire_Display_ON_CMD | Normal_Display), CMD);
|
58 |
|
59 | OLED_write((Set_Normal_or_Inverse_Display_CMD | Non_Inverted_Display), CMD);
|
60 |
|
61 | OLED_write((Set_Display_ON_or_OFF_CMD + Display_ON) , CMD);
|
62 |
|
63 | OLED_gotoxy(0, 0);
|
64 |
|
65 | OLED_clear_buffer();
|
66 | OLED_clear_screen();
|
67 |
|
68 | DISPLAY_CTRL_RW(LOW);
|
69 | }
|
70 |
|
71 |
|
72 | inline void OLED_reset_sequence()
|
73 | {
|
74 | _delay_ms(50);
|
75 | DISPLAY_CTRL_RST(LOW);
|
76 | _delay_ms(50);
|
77 | DISPLAY_CTRL_RST(HIGH);
|
78 | }
|
79 |
|
80 |
|
81 | void OLED_write(uint8_t value, uint8_t type)
|
82 | {
|
83 | DISPLAY_CTRL_ERD(HIGH);
|
84 | DISPLAY_CTRL_DC((type & 0x01));
|
85 | DISPLAY_CTRL_CS(LOW);
|
86 |
|
87 | SPI_MasterTransceiveByte(&spiMasterD, value);
|
88 |
|
89 | DISPLAY_CTRL_CS(HIGH);
|
90 | DISPLAY_CTRL_ERD(LOW);
|
91 | }
|
92 |
|
93 |
|
94 | void OLED_gotoxy(uint8_t x_pos, uint8_t y_pos)
|
95 | {
|
96 | OLED_write((Set_Page_Start_Address_CMD + y_pos), CMD);
|
97 | OLED_write(((x_pos & 0x0F) | Set_Lower_Column_Start_Address_CMD), CMD);
|
98 | OLED_write((((x_pos & 0xF0) >> 0x04) | Set_Higher_Column_Start_Address_CMD), CMD);
|
99 | }
|
100 |
|
101 |
|
102 | void OLED_fill(uint8_t bmp_data)
|
103 | {
|
104 | uint8_t x_pos = 0x00;
|
105 | uint8_t page = 0x00;
|
106 |
|
107 | for(page = y_min; page < y_max; page++)
|
108 | {
|
109 | OLED_write((Set_Page_Start_Address_CMD + page), CMD);
|
110 | OLED_write(Set_Lower_Column_Start_Address_CMD, CMD);
|
111 | OLED_write(Set_Higher_Column_Start_Address_CMD, CMD);
|
112 |
|
113 | for(x_pos = x_min; x_pos < x_max; x_pos++)
|
114 | {
|
115 | OLED_write(bmp_data, DAT);
|
116 | }
|
117 | }
|
118 | }
|
119 |
|
120 |
|
121 | void OLED_clear_screen()
|
122 | {
|
123 | OLED_fill(0x00);
|
124 | }
|
125 |
|
126 |
|
127 | void OLED_clear_buffer()
|
128 | {
|
129 | uint16_t s = 0x00;
|
130 |
|
131 | for(s = 0; s < buffer_size; s++)
|
132 | {
|
133 | buffer[s] = 0x00;
|
134 | }
|
135 | }
|
136 |
|
137 |
|
138 | void OLED_cursor(uint8_t x_pos, uint8_t y_pos)
|
139 | {
|
140 | uint8_t i = 0x00;
|
141 |
|
142 | if(y_pos != 0x00)
|
143 | {
|
144 | if(x_pos == 1)
|
145 | {
|
146 | OLED_gotoxy(0x00, (y_pos + 0x02));
|
147 | }
|
148 | else
|
149 | {
|
150 | OLED_gotoxy((0x50 + ((x_pos - 0x02) * 0x06)), (y_pos + 0x02));
|
151 | }
|
152 |
|
153 | for(i = 0; i < 6; i++)
|
154 | {
|
155 | OLED_write(0xFF, DAT);
|
156 | }
|
157 | }
|
158 | }
|
159 |
|
160 |
|
161 | void OLED_print_Image(const uint8_t *bmp, uint8_t pixel)
|
162 | {
|
163 | uint8_t x_pos = 0x00;
|
164 | uint8_t page = 0x00;
|
165 |
|
166 | if(pixel != OFF)
|
167 | {
|
168 | pixel = 0xFF;
|
169 | }
|
170 | else
|
171 | {
|
172 | pixel = 0x00;
|
173 | }
|
174 |
|
175 | for(page = 0; page < y_max; page++)
|
176 | {
|
177 | OLED_gotoxy(x_min, page);
|
178 | for(x_pos = x_min; x_pos < x_max; x_pos++)
|
179 | {
|
180 | OLED_write((*bmp++ ^ pixel), DAT);
|
181 | }
|
182 | }
|
183 | }
|
184 |
|
185 |
|
186 | void OLED_draw_bitmap(uint8_t xb, uint8_t yb, uint8_t xe, uint8_t ye, uint8_t *bmp_img)
|
187 | {
|
188 | uint16_t s = 0x0000;
|
189 | uint8_t x_pos = 0x00;
|
190 | uint8_t y_pos = 0x00;
|
191 |
|
192 | for(y_pos = yb; y_pos <= ye; y_pos++)
|
193 | {
|
194 | OLED_gotoxy(xb, y_pos);
|
195 | for(x_pos = xb; x_pos < xe; x_pos++)
|
196 | {
|
197 | OLED_write(bmp_img[s], DAT);
|
198 | s++;
|
199 | }
|
200 | }
|
201 | }
|
202 |
|
203 |
|
204 | void OLED_print_char(uint8_t x_pos, uint8_t y_pos, uint8_t ch)
|
205 | {
|
206 | uint8_t chr = 0x00;
|
207 | uint8_t s = 0x00;
|
208 |
|
209 | chr = (ch - 32);
|
210 |
|
211 | if(x_pos > (x_max - 6))
|
212 | {
|
213 | x_pos = 0;
|
214 | y_pos++;
|
215 | }
|
216 |
|
217 | OLED_gotoxy(x_pos, y_pos);
|
218 |
|
219 | for(s = 0x00; s < 0x06; s++)
|
220 | {
|
221 | OLED_write(font_regular[chr][s], DAT);
|
222 | }
|
223 | }
|
224 |
|
225 |
|
226 | void OLED_print_string(uint8_t x_pos, uint8_t y_pos, uint8_t *ch)
|
227 | {
|
228 | uint8_t chr = 0x00;
|
229 | uint8_t i = 0x00;
|
230 | uint8_t j = 0x00;
|
231 |
|
232 | while(ch[j] != '\0')
|
233 | {
|
234 | chr = (ch[j] - 32);
|
235 |
|
236 | if(x_pos > (x_max - 0x06))
|
237 | {
|
238 | x_pos = 0x00;
|
239 | y_pos++;
|
240 | }
|
241 | OLED_gotoxy(x_pos, y_pos);
|
242 |
|
243 | for(i = 0x00; i < 0x06; i++)
|
244 | {
|
245 | OLED_write(font_regular[chr][i], DAT);
|
246 | }
|
247 |
|
248 | j++;
|
249 | x_pos += 6;
|
250 | }
|
251 | }
|
252 |
|
253 |
|
254 | void OLED_print_chr(uint8_t x_pos, uint8_t y_pos, int16_t value)
|
255 | {
|
256 | uint8_t ch = 0x00;
|
257 |
|
258 | if(value < 0x00)
|
259 | {
|
260 | OLED_print_char(x_pos, y_pos, '-');
|
261 | value = -value;
|
262 | }
|
263 | else
|
264 | {
|
265 | OLED_print_char(x_pos, y_pos,' ');
|
266 | }
|
267 |
|
268 | if((value > 99) && (value <= 999))
|
269 | {
|
270 | ch = (value / 100);
|
271 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
272 | ch = ((value % 100) / 10);
|
273 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
274 | ch = (value % 10);
|
275 | OLED_print_char((x_pos + 18), y_pos , (0x30 + ch));
|
276 | }
|
277 | else if((value > 9) && (value <= 99))
|
278 | {
|
279 | ch = ((value % 100) / 10);
|
280 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
281 | ch = (value % 10);
|
282 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
283 | OLED_print_char((x_pos + 18), y_pos , 0x20);
|
284 | }
|
285 | else if((value >= 0) && (value <= 9))
|
286 | {
|
287 | ch = (value % 10);
|
288 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
289 | OLED_print_char((x_pos + 12), y_pos , 0x20);
|
290 | OLED_print_char((x_pos + 18), y_pos , 0x20);
|
291 | }
|
292 | }
|
293 |
|
294 |
|
295 | void OLED_print_int(uint8_t x_pos, uint8_t y_pos, int32_t value)
|
296 | {
|
297 | uint8_t ch = 0x00;
|
298 |
|
299 | if(value < 0)
|
300 | {
|
301 | OLED_print_char(x_pos, y_pos, '-');
|
302 | value = -value;
|
303 | }
|
304 | else
|
305 | {
|
306 | OLED_print_char(x_pos, y_pos,' ');
|
307 | }
|
308 |
|
309 | if(value > 9999)
|
310 | {
|
311 | ch = (value / 10000);
|
312 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
313 |
|
314 | ch = ((value % 10000)/ 1000);
|
315 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
316 |
|
317 | ch = ((value % 1000) / 100);
|
318 | OLED_print_char((x_pos + 18), y_pos , (0x30 + ch));
|
319 |
|
320 | ch = ((value % 100) / 10);
|
321 | OLED_print_char((x_pos + 24), y_pos , (0x30 + ch));
|
322 |
|
323 | ch = (value % 10);
|
324 | OLED_print_char((x_pos + 30), y_pos , (0x30 + ch));
|
325 | }
|
326 |
|
327 | else if((value > 999) && (value <= 9999))
|
328 | {
|
329 | ch = ((value % 10000)/ 1000);
|
330 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
331 |
|
332 | ch = ((value % 1000) / 100);
|
333 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
334 |
|
335 | ch = ((value % 100) / 10);
|
336 | OLED_print_char((x_pos + 18), y_pos , (0x30 + ch));
|
337 |
|
338 | ch = (value % 10);
|
339 | OLED_print_char((x_pos + 24), y_pos , (0x30 + ch));
|
340 | OLED_print_char((x_pos + 30), y_pos , 0x20);
|
341 | }
|
342 | else if((value > 99) && (value <= 999))
|
343 | {
|
344 | ch = ((value % 1000) / 100);
|
345 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
346 |
|
347 | ch = ((value % 100) / 10);
|
348 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
349 |
|
350 | ch = (value % 10);
|
351 | OLED_print_char((x_pos + 18), y_pos , (0x30 + ch));
|
352 | OLED_print_char((x_pos + 24), y_pos , 0x20);
|
353 | OLED_print_char((x_pos + 30), y_pos , 0x20);
|
354 | }
|
355 | else if((value > 9) && (value <= 99))
|
356 | {
|
357 | ch = ((value % 100) / 10);
|
358 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
359 |
|
360 | ch = (value % 10);
|
361 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
362 |
|
363 | OLED_print_char((x_pos + 18), y_pos , 0x20);
|
364 | OLED_print_char((x_pos + 24), y_pos , 0x20);
|
365 | OLED_print_char((x_pos + 30), y_pos , 0x20);
|
366 | }
|
367 | else
|
368 | {
|
369 | ch = (value % 10);
|
370 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
371 | OLED_print_char((x_pos + 12), y_pos , 0x20);
|
372 | OLED_print_char((x_pos + 18), y_pos , 0x20);
|
373 | OLED_print_char((x_pos + 24), y_pos , 0x20);
|
374 | OLED_print_char((x_pos + 30), y_pos , 0x20);
|
375 | }
|
376 | }
|
377 |
|
378 |
|
379 | void OLED_print_decimal(uint8_t x_pos, uint8_t y_pos, uint16_t value, uint8_t points)
|
380 | {
|
381 | uint8_t ch = 0x00;
|
382 |
|
383 | OLED_print_char(x_pos, y_pos, '.');
|
384 |
|
385 | ch = (value / 1000);
|
386 | OLED_print_char((x_pos + 6), y_pos , (0x30 + ch));
|
387 |
|
388 | if(points > 1)
|
389 | {
|
390 | ch = ((value % 1000) / 100);
|
391 | OLED_print_char((x_pos + 12), y_pos , (0x30 + ch));
|
392 |
|
393 |
|
394 | if(points > 2)
|
395 | {
|
396 | ch = ((value % 100) / 10);
|
397 | OLED_print_char((x_pos + 18), y_pos , (0x30 + ch));
|
398 |
|
399 | if(points > 3)
|
400 | {
|
401 | ch = (value % 10);
|
402 | OLED_print_char((x_pos + 24), y_pos , (0x30 + ch));
|
403 | }
|
404 | }
|
405 | }
|
406 | }
|
407 |
|
408 |
|
409 | void OLED_print_float(uint8_t x_pos, uint8_t y_pos, float value, uint8_t points)
|
410 | {
|
411 | signed long tmp = 0x00;
|
412 |
|
413 | tmp = value;
|
414 | OLED_print_int(x_pos, y_pos, tmp);
|
415 | tmp = ((value - tmp) * 10000);
|
416 |
|
417 | if(tmp < 0)
|
418 | {
|
419 | tmp = -tmp;
|
420 | }
|
421 |
|
422 | if((value >= 10000) && (value < 100000))
|
423 | {
|
424 | OLED_print_decimal((x_pos + 36), y_pos, tmp, points);
|
425 | }
|
426 | else if((value >= 1000) && (value < 10000))
|
427 | {
|
428 | OLED_print_decimal((x_pos + 30), y_pos, tmp, points);
|
429 | }
|
430 | else if((value >= 100) && (value < 1000))
|
431 | {
|
432 | OLED_print_decimal((x_pos + 24), y_pos, tmp, points);
|
433 | }
|
434 | else if((value >= 10) && (value < 100))
|
435 | {
|
436 | OLED_print_decimal((x_pos + 18), y_pos, tmp, points);
|
437 | }
|
438 | else if(value < 10)
|
439 | {
|
440 | OLED_print_decimal((x_pos + 12), y_pos, tmp, points);
|
441 | if((value) < 0)
|
442 | {
|
443 | OLED_print_char(x_pos, y_pos, '-');
|
444 | }
|
445 | else
|
446 | {
|
447 | OLED_print_char(x_pos, y_pos, ' ');
|
448 | }
|
449 | }
|
450 | }
|
451 |
|
452 |
|
453 | void Draw_Pixel(uint8_t x_pos, uint8_t y_pos, uint8_t colour)
|
454 | {
|
455 | uint8_t value = 0x00;
|
456 | uint8_t page = 0x00;
|
457 | uint8_t bit_pos = 0x00;
|
458 |
|
459 | page = (y_pos / y_max);
|
460 | bit_pos = (y_pos - (page * y_max));
|
461 | value = buffer[((page * x_max) + x_pos)];
|
462 |
|
463 | if((colour & 0x01) != 0)
|
464 | {
|
465 | value |= (1 << bit_pos);
|
466 | }
|
467 | else
|
468 | {
|
469 | value &= (~(1 << bit_pos));
|
470 | }
|
471 |
|
472 | buffer[((page * x_max) + x_pos)] = value;
|
473 | OLED_gotoxy(x_pos, page);
|
474 | OLED_write(value, DAT);
|
475 | }
|
476 |
|
477 |
|
478 | void Draw_Line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t colour)
|
479 | {
|
480 | int16_t dx = 0x0000;
|
481 | int16_t dy = 0x0000;
|
482 | int16_t stepx = 0x0000;
|
483 | int16_t stepy = 0x0000;
|
484 | int16_t fraction = 0x0000;
|
485 |
|
486 | dy = (y2 - y1);
|
487 | dx = (x2 - x1);
|
488 |
|
489 | if (dy < 0)
|
490 | {
|
491 | dy = -dy;
|
492 | stepy = -1;
|
493 | }
|
494 | else
|
495 | {
|
496 | stepy = 1;
|
497 | }
|
498 |
|
499 | if (dx < 0)
|
500 | {
|
501 | dx = -dx;
|
502 | stepx = -1;
|
503 | }
|
504 | else
|
505 | {
|
506 | stepx = 1;
|
507 | }
|
508 |
|
509 | dx <<= 1;
|
510 | dy <<= 1;
|
511 |
|
512 | Draw_Pixel(x1, y1, colour);
|
513 |
|
514 | if(dx > dy)
|
515 | {
|
516 | fraction = (dy - (dx >> 1));
|
517 | while (x1 != x2)
|
518 | {
|
519 | if(fraction >= 0)
|
520 | {
|
521 | y1 += stepy;
|
522 | fraction -= dx;
|
523 | }
|
524 |
|
525 | x1 += stepx;
|
526 | fraction += dy;
|
527 |
|
528 | Draw_Pixel(x1, y1, colour);
|
529 | }
|
530 | }
|
531 | else
|
532 | {
|
533 | fraction = (dx - (dy >> 1));
|
534 | while (y1 != y2)
|
535 | {
|
536 | if (fraction >= 0)
|
537 | {
|
538 | x1 += stepx;
|
539 | fraction -= dy;
|
540 | }
|
541 |
|
542 | y1 += stepy;
|
543 | fraction += dx;
|
544 |
|
545 | Draw_Pixel(x1, y1, colour);
|
546 | }
|
547 | }
|
548 | }
|
549 |
|
550 |
|
551 | void Draw_V_Line(int16_t x1, int16_t y1, int16_t y2, uint8_t colour)
|
552 | {
|
553 | int16_t pos = 0;
|
554 | int16_t temp = 0;
|
555 |
|
556 | if(y1 > y2)
|
557 | {
|
558 | swap(&y1, &y2);
|
559 | }
|
560 |
|
561 | while(y2 > (y1 - 1))
|
562 | {
|
563 | Draw_Pixel(x1, y2, colour);
|
564 | y2--;
|
565 | }
|
566 | }
|
567 |
|
568 |
|
569 | void Draw_H_Line(int16_t x1, int16_t x2, int16_t y1, uint8_t colour)
|
570 | {
|
571 | int16_t pos = 0;
|
572 | int16_t temp = 0;
|
573 |
|
574 | if(x1 > x2)
|
575 | {
|
576 | swap(&x1, &x2);
|
577 | }
|
578 |
|
579 | while(x2 > (x1 - 1))
|
580 | {
|
581 | Draw_Pixel(x2, y1, colour);
|
582 | x2--;
|
583 | }
|
584 | }
|
585 |
|
586 |
|
587 | void Draw_Triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t fill, uint16_t colour)
|
588 | {
|
589 | int16_t a = 0;
|
590 | int16_t b = 0;
|
591 | int16_t sa = 0;
|
592 | int16_t sb = 0;
|
593 | int16_t yp = 0;
|
594 | int16_t last = 0;
|
595 | int16_t dx12 = 0;
|
596 | int16_t dx23 = 0;
|
597 | int16_t dx13 = 0;
|
598 | int16_t dy12 = 0;
|
599 | int16_t dy23 = 0;
|
600 | int16_t dy13 = 0;
|
601 |
|
602 | switch(fill)
|
603 | {
|
604 | case YES:
|
605 | {
|
606 | if(y1 > y2)
|
607 | {
|
608 | swap(&y1, &y2);
|
609 | swap(&x1, &x2);
|
610 | }
|
611 | if(y2 > y3)
|
612 | {
|
613 | swap(&y3, &y2);
|
614 | swap(&x3, &x2);
|
615 | }
|
616 | if(y1 > y2)
|
617 | {
|
618 | swap(&y1, &y2);
|
619 | swap(&x1, &x2);
|
620 | }
|
621 |
|
622 | if(y1 == y3)
|
623 | {
|
624 | a = b = x1;
|
625 |
|
626 | if(x2 < a)
|
627 | {
|
628 | a = x2;
|
629 | }
|
630 | else if(x2 > b)
|
631 | {
|
632 | b = x2;
|
633 | }
|
634 | if(x2 < a)
|
635 | {
|
636 | a = x3;
|
637 | }
|
638 | else if(x3 > b)
|
639 | {
|
640 | b = x3;
|
641 | }
|
642 |
|
643 | Draw_H_Line(a, (a + (b - (a + 1))), y1, colour);
|
644 | return;
|
645 | }
|
646 |
|
647 | dx12 = (x2 - x1);
|
648 | dy12 = (y2 - y1);
|
649 | dx13 = (x3 - x1);
|
650 | dy13 = (y3 - y1);
|
651 | dx23 = (x3 - x2);
|
652 | dy23 = (y3 - y2);
|
653 | sa = 0,
|
654 | sb = 0;
|
655 |
|
656 | if(y2 == y3)
|
657 | {
|
658 | last = y2;
|
659 | }
|
660 | else
|
661 | {
|
662 | last = (y2 - 1);
|
663 | }
|
664 |
|
665 | for(yp = y1; yp <= last; yp++)
|
666 | {
|
667 | a = (x1 + (sa / dy12));
|
668 | b = (x1 + (sb / dy13));
|
669 | sa += dx12;
|
670 | sb += dx13;
|
671 | if(a > b)
|
672 | {
|
673 | swap(&a, &b);
|
674 | }
|
675 | Draw_H_Line(a, (a + (b - (a + 1))), yp, colour);
|
676 | }
|
677 |
|
678 | sa = (dx23 * (yp - y2));
|
679 | sb = (dx13 * (yp - y1));
|
680 | for(; yp <= y3; yp++)
|
681 | {
|
682 | a = (x2 + (sa / dy23));
|
683 | b = (x1 + (sb / dy13));
|
684 | sa += dx23;
|
685 | sb += dx13;
|
686 |
|
687 | if(a > b)
|
688 | {
|
689 | swap(&a, &b);
|
690 | }
|
691 | Draw_H_Line(a, (a + (b - (a + 1))), yp, colour);
|
692 | }
|
693 |
|
694 |
|
695 | break;
|
696 | }
|
697 | default:
|
698 | {
|
699 | Draw_Line(x1, y1, x2, y2, colour);
|
700 | Draw_Line(x2, y2, x3, y3, colour);
|
701 | Draw_Line(x3, y3, x1, y1, colour);
|
702 | break;
|
703 | }
|
704 | }
|
705 | }
|
706 |
|
707 |
|
708 | void Draw_Rectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t fill, uint8_t colour, uint8_t type)
|
709 | {
|
710 | uint16_t i = 0x00;
|
711 | uint16_t xmin = 0x00;
|
712 | uint16_t xmax = 0x00;
|
713 | uint16_t ymin = 0x00;
|
714 | uint16_t ymax = 0x00;
|
715 |
|
716 | if(fill != 0)
|
717 | {
|
718 | if(x1 < x2)
|
719 | {
|
720 | xmin = x1;
|
721 | xmax = x2;
|
722 | }
|
723 | else
|
724 | {
|
725 | xmin = x2;
|
726 | xmax = x1;
|
727 | }
|
728 |
|
729 | if(y1 < y2)
|
730 | {
|
731 | ymin = y1;
|
732 | ymax = y2;
|
733 | }
|
734 | else
|
735 | {
|
736 | ymin = y2;
|
737 | ymax = y1;
|
738 | }
|
739 |
|
740 | for(; xmin <= xmax; ++xmin)
|
741 | {
|
742 | for(i = ymin; i <= ymax; ++i)
|
743 | {
|
744 | Draw_Pixel(xmin, i, colour);
|
745 | }
|
746 | }
|
747 | }
|
748 |
|
749 | else
|
750 | {
|
751 | Draw_Line(x1, y1, x2, y1, colour);
|
752 | Draw_Line(x1, y2, x2, y2, colour);
|
753 | Draw_Line(x1, y1, x1, y2, colour);
|
754 | Draw_Line(x2, y1, x2, y2, colour);
|
755 | }
|
756 |
|
757 | if(type != SQUARE)
|
758 | {
|
759 | Draw_Pixel(x1, y1, ~colour);
|
760 | Draw_Pixel(x1, y2, ~colour);
|
761 | Draw_Pixel(x2, y1, ~colour);
|
762 | Draw_Pixel(x2, y2, ~colour);
|
763 | }
|
764 | }
|
765 |
|
766 |
|
767 | void Draw_Circle(int16_t xc, int16_t yc, int16_t radius, uint8_t fill, uint8_t colour)
|
768 | {
|
769 | int16_t a = 0x0000;
|
770 | int16_t b = 0x0000;
|
771 | int16_t P = 0x0000;
|
772 |
|
773 | b = radius;
|
774 | P = (1 - b);
|
775 |
|
776 | do
|
777 | {
|
778 | if(fill != 0)
|
779 | {
|
780 | Draw_Line((xc - a), (yc + b), (xc + a), (yc + b), colour);
|
781 | Draw_Line((xc - a), (yc - b), (xc + a), (yc - b), colour);
|
782 | Draw_Line((xc - b), (yc + a), (xc + b), (yc + a), colour);
|
783 | Draw_Line((xc - b), (yc - a), (xc + b), (yc - a), colour);
|
784 | }
|
785 | else
|
786 | {
|
787 | Draw_Pixel((xc + a), (yc + b), colour);
|
788 | Draw_Pixel((xc + b), (yc + a), colour);
|
789 | Draw_Pixel((xc - a), (yc + b), colour);
|
790 | Draw_Pixel((xc - b), (yc + a), colour);
|
791 | Draw_Pixel((xc + b), (yc - a), colour);
|
792 | Draw_Pixel((xc + a), (yc - b), colour);
|
793 | Draw_Pixel((xc - a), (yc - b), colour);
|
794 | Draw_Pixel((xc - b), (yc - a), colour);
|
795 | }
|
796 |
|
797 | if(P < 0)
|
798 | {
|
799 | P += (3 + (2 * a++));
|
800 | }
|
801 | else
|
802 | {
|
803 | P += (5 + (2 * ((a++) - (b--))));
|
804 | }
|
805 |
|
806 | }while(a <= b);
|
807 | }
|