components/u8g2/csrc/u8x8_d_stdio.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*
2
3 u8x8_d_stdio.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 "u8x8.h"
37
38 #include <stdio.h>
39
40 #define W 8
41 #define H 2
42
43 uint8_t bitmap[W*H*8];
44
45 void bitmap_place_tile(uint8_t x, uint8_t y, uint8_t *tile)
46 {
47 uint8_t i;
48 for(i = 0; i < 8; i++ )
49 bitmap[x*8+y*W*8+i] = tile[i];
50 }
51
52 void bitmap_show(void)
53 {
54 int x, y;
55 for( y = 0; y < H*8; y++ )
56 {
57 for( x = 0; x < W*8; x++ )
58 {
59 if ( (bitmap[x+(y/8)*W*8] & (1<<((y&7)))) != 0 )
60 {
61 printf("*");
62 }
63 else
64 {
65 printf(".");
66 }
67 }
68 printf("\n");
69 }
70 }
71
72
73 uint8_t u8x8_d_stdio(U8X8_UNUSED u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
74 {
75 switch(msg)
76 {
77 case U8X8_MSG_DISPLAY_INIT:
78 break;
79 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
80 if ( arg_int == 0 )
81 bitmap_show();
82 break;
83 case U8X8_MSG_DISPLAY_SET_CONTRAST:
84 break;
85 case U8X8_MSG_DISPLAY_DRAW_TILE:
86 bitmap_place_tile(((u8x8_tile_t *)arg_ptr)->x_pos, ((u8x8_tile_t *)arg_ptr)->y_pos, ((u8x8_tile_t *)arg_ptr)->tile_ptr);
87 break;
88 default:
89 break;
90 }
91 return 1;
92 }
93
94
95
96 void u8x8_SetupStdio(u8x8_t *u8x8)
97 {
98 u8x8_SetupDefaults(u8x8);
99 u8x8->display_cb = u8x8_d_stdio;
100 }
101

mercurial