iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_pb8h1.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_pb8h1.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | 8bit height monochrom (1 bit) page buffer |
iforce2d | 0:972874f31c98 | 6 | byte has horizontal orientation |
iforce2d | 0:972874f31c98 | 7 | |
iforce2d | 0:972874f31c98 | 8 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Copyright (c) 2011, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 11 | All rights reserved. |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 14 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 17 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 18 | |
iforce2d | 0:972874f31c98 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 20 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 21 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 22 | |
iforce2d | 0:972874f31c98 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | |
iforce2d | 0:972874f31c98 | 38 | total buffer size is limited to 256 bytes because of the calculation inside the set pixel procedure |
iforce2d | 0:972874f31c98 | 39 | |
iforce2d | 0:972874f31c98 | 40 | 23. Sep 2012: Bug with down procedure, see FPS 1st page --> fixed (bug located in u8g_clip.c) |
iforce2d | 0:972874f31c98 | 41 | |
iforce2d | 0:972874f31c98 | 42 | */ |
iforce2d | 0:972874f31c98 | 43 | |
iforce2d | 0:972874f31c98 | 44 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 45 | #include <string.h> |
iforce2d | 0:972874f31c98 | 46 | |
iforce2d | 0:972874f31c98 | 47 | #ifdef __unix__ |
iforce2d | 0:972874f31c98 | 48 | #include <assert.h> |
iforce2d | 0:972874f31c98 | 49 | #endif |
iforce2d | 0:972874f31c98 | 50 | |
iforce2d | 0:972874f31c98 | 51 | /* NEW_CODE disabled, because the performance increase was too slow and not worth compared */ |
iforce2d | 0:972874f31c98 | 52 | /* to the increase of code size */ |
iforce2d | 0:972874f31c98 | 53 | /* #define NEW_CODE */ |
iforce2d | 0:972874f31c98 | 54 | |
iforce2d | 0:972874f31c98 | 55 | #ifdef __unix__ |
iforce2d | 0:972874f31c98 | 56 | void *u8g_buf_lower_limit; |
iforce2d | 0:972874f31c98 | 57 | void *u8g_buf_upper_limit; |
iforce2d | 0:972874f31c98 | 58 | #endif |
iforce2d | 0:972874f31c98 | 59 | |
iforce2d | 0:972874f31c98 | 60 | void u8g_pb8h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 61 | void u8g_pb8h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 62 | void u8g_pb8h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; |
iforce2d | 0:972874f31c98 | 63 | void u8g_pb8h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 64 | uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); |
iforce2d | 0:972874f31c98 | 65 | |
iforce2d | 0:972874f31c98 | 66 | |
iforce2d | 0:972874f31c98 | 67 | #ifdef NEW_CODE |
iforce2d | 0:972874f31c98 | 68 | struct u8g_pb_h1_struct |
iforce2d | 0:972874f31c98 | 69 | { |
iforce2d | 0:972874f31c98 | 70 | u8g_uint_t x; |
iforce2d | 0:972874f31c98 | 71 | u8g_uint_t y; |
iforce2d | 0:972874f31c98 | 72 | uint8_t *ptr; |
iforce2d | 0:972874f31c98 | 73 | uint8_t mask; |
iforce2d | 0:972874f31c98 | 74 | uint8_t line_byte_len; |
iforce2d | 0:972874f31c98 | 75 | uint8_t cnt; |
iforce2d | 0:972874f31c98 | 76 | }; |
iforce2d | 0:972874f31c98 | 77 | |
iforce2d | 0:972874f31c98 | 78 | static uint8_t u8g_pb8h1_bitmask[8] = { 0x080, 0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001 }; |
iforce2d | 0:972874f31c98 | 79 | |
iforce2d | 0:972874f31c98 | 80 | static void u8g_pb8h1_state_right(struct u8g_pb_h1_struct *s) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 81 | static void u8g_pb8h1_state_right(struct u8g_pb_h1_struct *s) |
iforce2d | 0:972874f31c98 | 82 | { |
iforce2d | 0:972874f31c98 | 83 | register u8g_uint_t x; |
iforce2d | 0:972874f31c98 | 84 | x = s->x; |
iforce2d | 0:972874f31c98 | 85 | x++; |
iforce2d | 0:972874f31c98 | 86 | s->x = x; |
iforce2d | 0:972874f31c98 | 87 | x &= 7; |
iforce2d | 0:972874f31c98 | 88 | s->mask = u8g_pb8h1_bitmask[x]; |
iforce2d | 0:972874f31c98 | 89 | if ( x == 0 ) |
iforce2d | 0:972874f31c98 | 90 | s->ptr++; |
iforce2d | 0:972874f31c98 | 91 | } |
iforce2d | 0:972874f31c98 | 92 | |
iforce2d | 0:972874f31c98 | 93 | static void u8g_pb8h1_state_left(struct u8g_pb_h1_struct *s) |
iforce2d | 0:972874f31c98 | 94 | { |
iforce2d | 0:972874f31c98 | 95 | register u8g_uint_t x; |
iforce2d | 0:972874f31c98 | 96 | x = s->x; |
iforce2d | 0:972874f31c98 | 97 | x--; |
iforce2d | 0:972874f31c98 | 98 | s->x = x; |
iforce2d | 0:972874f31c98 | 99 | x &= 7; |
iforce2d | 0:972874f31c98 | 100 | s->mask = u8g_pb8h1_bitmask[x]; |
iforce2d | 0:972874f31c98 | 101 | if ( x == 7 ) |
iforce2d | 0:972874f31c98 | 102 | s->ptr--; |
iforce2d | 0:972874f31c98 | 103 | } |
iforce2d | 0:972874f31c98 | 104 | |
iforce2d | 0:972874f31c98 | 105 | static void u8g_pb8h1_state_down(struct u8g_pb_h1_struct *s) |
iforce2d | 0:972874f31c98 | 106 | { |
iforce2d | 0:972874f31c98 | 107 | s->y++; |
iforce2d | 0:972874f31c98 | 108 | s->ptr += s->line_byte_len; |
iforce2d | 0:972874f31c98 | 109 | } |
iforce2d | 0:972874f31c98 | 110 | |
iforce2d | 0:972874f31c98 | 111 | static void u8g_pb8h1_state_up(struct u8g_pb_h1_struct *s) |
iforce2d | 0:972874f31c98 | 112 | { |
iforce2d | 0:972874f31c98 | 113 | s->y--; |
iforce2d | 0:972874f31c98 | 114 | s->ptr -= s->line_byte_len; |
iforce2d | 0:972874f31c98 | 115 | } |
iforce2d | 0:972874f31c98 | 116 | |
iforce2d | 0:972874f31c98 | 117 | static void u8g_pb8h1_state_init(struct u8g_pb_h1_struct *s, u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 118 | static void u8g_pb8h1_state_init(struct u8g_pb_h1_struct *s, u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y) |
iforce2d | 0:972874f31c98 | 119 | { |
iforce2d | 0:972874f31c98 | 120 | u8g_uint_t tmp; |
iforce2d | 0:972874f31c98 | 121 | |
iforce2d | 0:972874f31c98 | 122 | uint8_t *ptr = b->buf; |
iforce2d | 0:972874f31c98 | 123 | |
iforce2d | 0:972874f31c98 | 124 | s->x = x; |
iforce2d | 0:972874f31c98 | 125 | s->y = y; |
iforce2d | 0:972874f31c98 | 126 | |
iforce2d | 0:972874f31c98 | 127 | y -= b->p.page_y0; |
iforce2d | 0:972874f31c98 | 128 | |
iforce2d | 0:972874f31c98 | 129 | tmp = b->width; |
iforce2d | 0:972874f31c98 | 130 | tmp >>= 3; |
iforce2d | 0:972874f31c98 | 131 | s->line_byte_len = tmp; |
iforce2d | 0:972874f31c98 | 132 | |
iforce2d | 0:972874f31c98 | 133 | /* assume negative y values, can be down to -7, subtract this from the pointer and add correction of 8 to y */ |
iforce2d | 0:972874f31c98 | 134 | ptr -= tmp*8; |
iforce2d | 0:972874f31c98 | 135 | y+=8; |
iforce2d | 0:972874f31c98 | 136 | /* it is important that the result of tmp*y can be 16 bit value also for 8 bit mode */ |
iforce2d | 0:972874f31c98 | 137 | ptr += tmp*y; |
iforce2d | 0:972874f31c98 | 138 | |
iforce2d | 0:972874f31c98 | 139 | s->mask = u8g_pb8h1_bitmask[x & 7]; |
iforce2d | 0:972874f31c98 | 140 | |
iforce2d | 0:972874f31c98 | 141 | /* assume negative x values (to -7), subtract 8 pixel from the pointer and add 8 to x */ |
iforce2d | 0:972874f31c98 | 142 | ptr--; |
iforce2d | 0:972874f31c98 | 143 | x += 8; |
iforce2d | 0:972874f31c98 | 144 | x >>= 3; |
iforce2d | 0:972874f31c98 | 145 | ptr += x; |
iforce2d | 0:972874f31c98 | 146 | s->ptr = ptr; |
iforce2d | 0:972874f31c98 | 147 | } |
iforce2d | 0:972874f31c98 | 148 | |
iforce2d | 0:972874f31c98 | 149 | static void u8g_pb8h1_state_set_pixel(struct u8g_pb_h1_struct *s, uint8_t color_index) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 150 | static void u8g_pb8h1_state_set_pixel(struct u8g_pb_h1_struct *s, uint8_t color_index) |
iforce2d | 0:972874f31c98 | 151 | { |
iforce2d | 0:972874f31c98 | 152 | |
iforce2d | 0:972874f31c98 | 153 | #ifdef __unix__ |
iforce2d | 0:972874f31c98 | 154 | assert( s->ptr >= u8g_buf_lower_limit ); |
iforce2d | 0:972874f31c98 | 155 | assert( s->ptr < u8g_buf_upper_limit ); |
iforce2d | 0:972874f31c98 | 156 | #endif |
iforce2d | 0:972874f31c98 | 157 | |
iforce2d | 0:972874f31c98 | 158 | if ( color_index ) |
iforce2d | 0:972874f31c98 | 159 | { |
iforce2d | 0:972874f31c98 | 160 | *s->ptr |= s->mask; |
iforce2d | 0:972874f31c98 | 161 | } |
iforce2d | 0:972874f31c98 | 162 | else |
iforce2d | 0:972874f31c98 | 163 | { |
iforce2d | 0:972874f31c98 | 164 | uint8_t mask = s->mask; |
iforce2d | 0:972874f31c98 | 165 | mask ^=0xff; |
iforce2d | 0:972874f31c98 | 166 | *s->ptr &= mask; |
iforce2d | 0:972874f31c98 | 167 | } |
iforce2d | 0:972874f31c98 | 168 | } |
iforce2d | 0:972874f31c98 | 169 | #endif |
iforce2d | 0:972874f31c98 | 170 | |
iforce2d | 0:972874f31c98 | 171 | |
iforce2d | 0:972874f31c98 | 172 | void u8g_pb8h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) |
iforce2d | 0:972874f31c98 | 173 | { |
iforce2d | 0:972874f31c98 | 174 | b->buf = buf; |
iforce2d | 0:972874f31c98 | 175 | b->width = width; |
iforce2d | 0:972874f31c98 | 176 | u8g_pb_Clear(b); |
iforce2d | 0:972874f31c98 | 177 | } |
iforce2d | 0:972874f31c98 | 178 | |
iforce2d | 0:972874f31c98 | 179 | /* limitation: total buffer must not exceed 256 bytes */ |
iforce2d | 0:972874f31c98 | 180 | void u8g_pb8h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) |
iforce2d | 0:972874f31c98 | 181 | { |
iforce2d | 0:972874f31c98 | 182 | #ifdef NEW_CODE |
iforce2d | 0:972874f31c98 | 183 | struct u8g_pb_h1_struct s; |
iforce2d | 0:972874f31c98 | 184 | u8g_pb8h1_state_init(&s, b, x, y); |
iforce2d | 0:972874f31c98 | 185 | u8g_pb8h1_state_set_pixel(&s, color_index); |
iforce2d | 0:972874f31c98 | 186 | |
iforce2d | 0:972874f31c98 | 187 | // u8g_pb8h1_state_up(&s); |
iforce2d | 0:972874f31c98 | 188 | // if ( s.y > b->p.page_y1 ) |
iforce2d | 0:972874f31c98 | 189 | // return; |
iforce2d | 0:972874f31c98 | 190 | // if ( s.x > b->width ) |
iforce2d | 0:972874f31c98 | 191 | // return; |
iforce2d | 0:972874f31c98 | 192 | // u8g_pb8h1_state_set_pixel(&s, color_index); |
iforce2d | 0:972874f31c98 | 193 | #else |
iforce2d | 0:972874f31c98 | 194 | register uint8_t mask; |
iforce2d | 0:972874f31c98 | 195 | u8g_uint_t tmp; |
iforce2d | 0:972874f31c98 | 196 | uint8_t *ptr = b->buf; |
iforce2d | 0:972874f31c98 | 197 | |
iforce2d | 0:972874f31c98 | 198 | y -= b->p.page_y0; |
iforce2d | 0:972874f31c98 | 199 | tmp = b->width; |
iforce2d | 0:972874f31c98 | 200 | tmp >>= 3; |
iforce2d | 0:972874f31c98 | 201 | tmp *= (uint8_t)y; |
iforce2d | 0:972874f31c98 | 202 | ptr += tmp; |
iforce2d | 0:972874f31c98 | 203 | |
iforce2d | 0:972874f31c98 | 204 | mask = 0x080; |
iforce2d | 0:972874f31c98 | 205 | mask >>= x & 7; |
iforce2d | 0:972874f31c98 | 206 | x >>= 3; |
iforce2d | 0:972874f31c98 | 207 | ptr += x; |
iforce2d | 0:972874f31c98 | 208 | if ( color_index ) |
iforce2d | 0:972874f31c98 | 209 | { |
iforce2d | 0:972874f31c98 | 210 | *ptr |= mask; |
iforce2d | 0:972874f31c98 | 211 | } |
iforce2d | 0:972874f31c98 | 212 | else |
iforce2d | 0:972874f31c98 | 213 | { |
iforce2d | 0:972874f31c98 | 214 | mask ^=0xff; |
iforce2d | 0:972874f31c98 | 215 | *ptr &= mask; |
iforce2d | 0:972874f31c98 | 216 | } |
iforce2d | 0:972874f31c98 | 217 | #endif |
iforce2d | 0:972874f31c98 | 218 | } |
iforce2d | 0:972874f31c98 | 219 | |
iforce2d | 0:972874f31c98 | 220 | |
iforce2d | 0:972874f31c98 | 221 | void u8g_pb8h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) |
iforce2d | 0:972874f31c98 | 222 | { |
iforce2d | 0:972874f31c98 | 223 | if ( arg_pixel->y < b->p.page_y0 ) |
iforce2d | 0:972874f31c98 | 224 | return; |
iforce2d | 0:972874f31c98 | 225 | if ( arg_pixel->y > b->p.page_y1 ) |
iforce2d | 0:972874f31c98 | 226 | return; |
iforce2d | 0:972874f31c98 | 227 | if ( arg_pixel->x >= b->width ) |
iforce2d | 0:972874f31c98 | 228 | return; |
iforce2d | 0:972874f31c98 | 229 | u8g_pb8h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); |
iforce2d | 0:972874f31c98 | 230 | } |
iforce2d | 0:972874f31c98 | 231 | |
iforce2d | 0:972874f31c98 | 232 | void u8g_pb8h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) |
iforce2d | 0:972874f31c98 | 233 | { |
iforce2d | 0:972874f31c98 | 234 | register uint8_t pixel = arg_pixel->pixel; |
iforce2d | 0:972874f31c98 | 235 | do |
iforce2d | 0:972874f31c98 | 236 | { |
iforce2d | 0:972874f31c98 | 237 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 238 | { |
iforce2d | 0:972874f31c98 | 239 | u8g_pb8h1_SetPixel(b, arg_pixel); |
iforce2d | 0:972874f31c98 | 240 | } |
iforce2d | 0:972874f31c98 | 241 | switch( arg_pixel->dir ) |
iforce2d | 0:972874f31c98 | 242 | { |
iforce2d | 0:972874f31c98 | 243 | case 0: arg_pixel->x++; break; |
iforce2d | 0:972874f31c98 | 244 | case 1: arg_pixel->y++; break; |
iforce2d | 0:972874f31c98 | 245 | case 2: arg_pixel->x--; break; |
iforce2d | 0:972874f31c98 | 246 | case 3: arg_pixel->y--; break; |
iforce2d | 0:972874f31c98 | 247 | } |
iforce2d | 0:972874f31c98 | 248 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 249 | } while( pixel != 0 ); |
iforce2d | 0:972874f31c98 | 250 | } |
iforce2d | 0:972874f31c98 | 251 | |
iforce2d | 0:972874f31c98 | 252 | void u8g_pb8h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) |
iforce2d | 0:972874f31c98 | 253 | { |
iforce2d | 0:972874f31c98 | 254 | register uint8_t pixel = arg_pixel->pixel; |
iforce2d | 0:972874f31c98 | 255 | u8g_uint_t dx = 0; |
iforce2d | 0:972874f31c98 | 256 | u8g_uint_t dy = 0; |
iforce2d | 0:972874f31c98 | 257 | |
iforce2d | 0:972874f31c98 | 258 | switch( arg_pixel->dir ) |
iforce2d | 0:972874f31c98 | 259 | { |
iforce2d | 0:972874f31c98 | 260 | case 0: dx++; break; |
iforce2d | 0:972874f31c98 | 261 | case 1: dy++; break; |
iforce2d | 0:972874f31c98 | 262 | case 2: dx--; break; |
iforce2d | 0:972874f31c98 | 263 | case 3: dy--; break; |
iforce2d | 0:972874f31c98 | 264 | } |
iforce2d | 0:972874f31c98 | 265 | |
iforce2d | 0:972874f31c98 | 266 | do |
iforce2d | 0:972874f31c98 | 267 | { |
iforce2d | 0:972874f31c98 | 268 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 269 | u8g_pb8h1_SetPixel(b, arg_pixel); |
iforce2d | 0:972874f31c98 | 270 | arg_pixel->x += dx; |
iforce2d | 0:972874f31c98 | 271 | arg_pixel->y += dy; |
iforce2d | 0:972874f31c98 | 272 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 273 | } while( pixel != 0 ); |
iforce2d | 0:972874f31c98 | 274 | } |
iforce2d | 0:972874f31c98 | 275 | |
iforce2d | 0:972874f31c98 | 276 | #ifdef NEW_CODE |
iforce2d | 0:972874f31c98 | 277 | static void u8g_pb8h1_Set8PixelState(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) |
iforce2d | 0:972874f31c98 | 278 | { |
iforce2d | 0:972874f31c98 | 279 | register uint8_t pixel = arg_pixel->pixel; |
iforce2d | 0:972874f31c98 | 280 | struct u8g_pb_h1_struct s; |
iforce2d | 0:972874f31c98 | 281 | uint8_t cnt; |
iforce2d | 0:972874f31c98 | 282 | u8g_pb8h1_state_init(&s, b, arg_pixel->x, arg_pixel->y); |
iforce2d | 0:972874f31c98 | 283 | cnt = 8; |
iforce2d | 0:972874f31c98 | 284 | switch( arg_pixel->dir ) |
iforce2d | 0:972874f31c98 | 285 | { |
iforce2d | 0:972874f31c98 | 286 | case 0: |
iforce2d | 0:972874f31c98 | 287 | do |
iforce2d | 0:972874f31c98 | 288 | { |
iforce2d | 0:972874f31c98 | 289 | if ( s.x < b->width ) |
iforce2d | 0:972874f31c98 | 290 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 291 | u8g_pb8h1_state_set_pixel(&s, arg_pixel->color); |
iforce2d | 0:972874f31c98 | 292 | u8g_pb8h1_state_right(&s); |
iforce2d | 0:972874f31c98 | 293 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 294 | cnt--; |
iforce2d | 0:972874f31c98 | 295 | } while( cnt > 0 && pixel != 0 ); |
iforce2d | 0:972874f31c98 | 296 | break; |
iforce2d | 0:972874f31c98 | 297 | case 1: |
iforce2d | 0:972874f31c98 | 298 | do |
iforce2d | 0:972874f31c98 | 299 | { |
iforce2d | 0:972874f31c98 | 300 | if ( s.y >= b->p.page_y0 ) |
iforce2d | 0:972874f31c98 | 301 | if ( s.y <= b->p.page_y1 ) |
iforce2d | 0:972874f31c98 | 302 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 303 | u8g_pb8h1_state_set_pixel(&s, arg_pixel->color); |
iforce2d | 0:972874f31c98 | 304 | u8g_pb8h1_state_down(&s); |
iforce2d | 0:972874f31c98 | 305 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 306 | cnt--; |
iforce2d | 0:972874f31c98 | 307 | } while( cnt > 0 && pixel != 0 ); |
iforce2d | 0:972874f31c98 | 308 | break; |
iforce2d | 0:972874f31c98 | 309 | case 2: |
iforce2d | 0:972874f31c98 | 310 | do |
iforce2d | 0:972874f31c98 | 311 | { |
iforce2d | 0:972874f31c98 | 312 | if ( s.x < b->width ) |
iforce2d | 0:972874f31c98 | 313 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 314 | u8g_pb8h1_state_set_pixel(&s, arg_pixel->color); |
iforce2d | 0:972874f31c98 | 315 | u8g_pb8h1_state_left(&s); |
iforce2d | 0:972874f31c98 | 316 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 317 | cnt--; |
iforce2d | 0:972874f31c98 | 318 | } while( cnt > 0 && pixel != 0 ); |
iforce2d | 0:972874f31c98 | 319 | break; |
iforce2d | 0:972874f31c98 | 320 | case 3: |
iforce2d | 0:972874f31c98 | 321 | do |
iforce2d | 0:972874f31c98 | 322 | { |
iforce2d | 0:972874f31c98 | 323 | if ( s.y >= b->p.page_y0 ) |
iforce2d | 0:972874f31c98 | 324 | if ( s.y <= b->p.page_y1 ) |
iforce2d | 0:972874f31c98 | 325 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 326 | u8g_pb8h1_state_set_pixel(&s, arg_pixel->color); |
iforce2d | 0:972874f31c98 | 327 | u8g_pb8h1_state_up(&s); |
iforce2d | 0:972874f31c98 | 328 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 329 | cnt--; |
iforce2d | 0:972874f31c98 | 330 | } while( cnt > 0 && pixel != 0 ); |
iforce2d | 0:972874f31c98 | 331 | break; |
iforce2d | 0:972874f31c98 | 332 | } |
iforce2d | 0:972874f31c98 | 333 | } |
iforce2d | 0:972874f31c98 | 334 | #endif |
iforce2d | 0:972874f31c98 | 335 | |
iforce2d | 0:972874f31c98 | 336 | uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 337 | { |
iforce2d | 0:972874f31c98 | 338 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 339 | switch(msg) |
iforce2d | 0:972874f31c98 | 340 | { |
iforce2d | 0:972874f31c98 | 341 | case U8G_DEV_MSG_SET_8PIXEL: |
iforce2d | 0:972874f31c98 | 342 | #ifdef NEW_CODE |
iforce2d | 0:972874f31c98 | 343 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) |
iforce2d | 0:972874f31c98 | 344 | u8g_pb8h1_Set8PixelState(pb, (u8g_dev_arg_pixel_t *)arg); |
iforce2d | 0:972874f31c98 | 345 | #else |
iforce2d | 0:972874f31c98 | 346 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) |
iforce2d | 0:972874f31c98 | 347 | u8g_pb8h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); |
iforce2d | 0:972874f31c98 | 348 | #endif |
iforce2d | 0:972874f31c98 | 349 | break; |
iforce2d | 0:972874f31c98 | 350 | case U8G_DEV_MSG_SET_PIXEL: |
iforce2d | 0:972874f31c98 | 351 | u8g_pb8h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); |
iforce2d | 0:972874f31c98 | 352 | break; |
iforce2d | 0:972874f31c98 | 353 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 354 | break; |
iforce2d | 0:972874f31c98 | 355 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 356 | break; |
iforce2d | 0:972874f31c98 | 357 | case U8G_DEV_MSG_PAGE_FIRST: |
iforce2d | 0:972874f31c98 | 358 | u8g_pb_Clear(pb); |
iforce2d | 0:972874f31c98 | 359 | u8g_page_First(&(pb->p)); |
iforce2d | 0:972874f31c98 | 360 | break; |
iforce2d | 0:972874f31c98 | 361 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 362 | if ( u8g_page_Next(&(pb->p)) == 0 ) |
iforce2d | 0:972874f31c98 | 363 | return 0; |
iforce2d | 0:972874f31c98 | 364 | u8g_pb_Clear(pb); |
iforce2d | 0:972874f31c98 | 365 | break; |
iforce2d | 0:972874f31c98 | 366 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION |
iforce2d | 0:972874f31c98 | 367 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: |
iforce2d | 0:972874f31c98 | 368 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); |
iforce2d | 0:972874f31c98 | 369 | #endif |
iforce2d | 0:972874f31c98 | 370 | case U8G_DEV_MSG_GET_PAGE_BOX: |
iforce2d | 0:972874f31c98 | 371 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); |
iforce2d | 0:972874f31c98 | 372 | break; |
iforce2d | 0:972874f31c98 | 373 | case U8G_DEV_MSG_GET_WIDTH: |
iforce2d | 0:972874f31c98 | 374 | *((u8g_uint_t *)arg) = pb->width; |
iforce2d | 0:972874f31c98 | 375 | break; |
iforce2d | 0:972874f31c98 | 376 | case U8G_DEV_MSG_GET_HEIGHT: |
iforce2d | 0:972874f31c98 | 377 | *((u8g_uint_t *)arg) = pb->p.total_height; |
iforce2d | 0:972874f31c98 | 378 | break; |
iforce2d | 0:972874f31c98 | 379 | case U8G_DEV_MSG_SET_COLOR_ENTRY: |
iforce2d | 0:972874f31c98 | 380 | break; |
iforce2d | 0:972874f31c98 | 381 | case U8G_DEV_MSG_SET_XY_CB: |
iforce2d | 0:972874f31c98 | 382 | break; |
iforce2d | 0:972874f31c98 | 383 | case U8G_DEV_MSG_GET_MODE: |
iforce2d | 0:972874f31c98 | 384 | return U8G_MODE_BW; |
iforce2d | 0:972874f31c98 | 385 | } |
iforce2d | 0:972874f31c98 | 386 | return 1; |
iforce2d | 0:972874f31c98 | 387 | } |
iforce2d | 0:972874f31c98 | 388 | |
iforce2d | 0:972874f31c98 | 389 | |
iforce2d | 0:972874f31c98 | 390 |