Displays distance to start location on OLED screen.

Dependencies:   mbed

Committer:
iforce2d
Date:
Wed Mar 07 12:49:14 2018 +0000
Revision:
0:972874f31c98
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iforce2d 0:972874f31c98 1 /*
iforce2d 0:972874f31c98 2
iforce2d 0:972874f31c98 3 u8g_ll_api.c
iforce2d 0:972874f31c98 4
iforce2d 0:972874f31c98 5 low level api
iforce2d 0:972874f31c98 6
iforce2d 0:972874f31c98 7 Universal 8bit Graphics Library
iforce2d 0:972874f31c98 8
iforce2d 0:972874f31c98 9 Copyright (c) 2011, olikraus@gmail.com
iforce2d 0:972874f31c98 10 All rights reserved.
iforce2d 0:972874f31c98 11
iforce2d 0:972874f31c98 12 Redistribution and use in source and binary forms, with or without modification,
iforce2d 0:972874f31c98 13 are permitted provided that the following conditions are met:
iforce2d 0:972874f31c98 14
iforce2d 0:972874f31c98 15 * Redistributions of source code must retain the above copyright notice, this list
iforce2d 0:972874f31c98 16 of conditions and the following disclaimer.
iforce2d 0:972874f31c98 17
iforce2d 0:972874f31c98 18 * Redistributions in binary form must reproduce the above copyright notice, this
iforce2d 0:972874f31c98 19 list of conditions and the following disclaimer in the documentation and/or other
iforce2d 0:972874f31c98 20 materials provided with the distribution.
iforce2d 0:972874f31c98 21
iforce2d 0:972874f31c98 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
iforce2d 0:972874f31c98 23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
iforce2d 0:972874f31c98 24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iforce2d 0:972874f31c98 25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
iforce2d 0:972874f31c98 26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
iforce2d 0:972874f31c98 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
iforce2d 0:972874f31c98 28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
iforce2d 0:972874f31c98 29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
iforce2d 0:972874f31c98 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
iforce2d 0:972874f31c98 31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
iforce2d 0:972874f31c98 32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
iforce2d 0:972874f31c98 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
iforce2d 0:972874f31c98 34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
iforce2d 0:972874f31c98 35
iforce2d 0:972874f31c98 36
iforce2d 0:972874f31c98 37 */
iforce2d 0:972874f31c98 38
iforce2d 0:972874f31c98 39 #include <stddef.h>
iforce2d 0:972874f31c98 40 #include "u8g.h"
iforce2d 0:972874f31c98 41
iforce2d 0:972874f31c98 42 uint8_t u8g_call_dev_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
iforce2d 0:972874f31c98 43 {
iforce2d 0:972874f31c98 44 return dev->dev_fn(u8g, dev, msg, arg);
iforce2d 0:972874f31c98 45 }
iforce2d 0:972874f31c98 46
iforce2d 0:972874f31c98 47 /*====================================================================*/
iforce2d 0:972874f31c98 48
iforce2d 0:972874f31c98 49 uint8_t u8g_InitLL(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 50 {
iforce2d 0:972874f31c98 51 uint8_t r;
iforce2d 0:972874f31c98 52 u8g->state_cb(U8G_STATE_MSG_BACKUP_ENV);
iforce2d 0:972874f31c98 53 r = u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_INIT, NULL);
iforce2d 0:972874f31c98 54 u8g->state_cb(U8G_STATE_MSG_BACKUP_U8G);
iforce2d 0:972874f31c98 55 u8g->state_cb(U8G_STATE_MSG_RESTORE_ENV);
iforce2d 0:972874f31c98 56 return r;
iforce2d 0:972874f31c98 57 }
iforce2d 0:972874f31c98 58
iforce2d 0:972874f31c98 59 void u8g_FirstPageLL(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 60 {
iforce2d 0:972874f31c98 61 u8g->state_cb(U8G_STATE_MSG_BACKUP_ENV);
iforce2d 0:972874f31c98 62 u8g->state_cb(U8G_STATE_MSG_RESTORE_U8G);
iforce2d 0:972874f31c98 63 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_PAGE_FIRST, NULL);
iforce2d 0:972874f31c98 64 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_PAGE_BOX, &(u8g->current_page));
iforce2d 0:972874f31c98 65 u8g->state_cb(U8G_STATE_MSG_RESTORE_ENV);
iforce2d 0:972874f31c98 66 }
iforce2d 0:972874f31c98 67
iforce2d 0:972874f31c98 68 uint8_t u8g_NextPageLL(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 69 {
iforce2d 0:972874f31c98 70 uint8_t r;
iforce2d 0:972874f31c98 71 u8g->state_cb(U8G_STATE_MSG_BACKUP_ENV);
iforce2d 0:972874f31c98 72 u8g->state_cb(U8G_STATE_MSG_RESTORE_U8G);
iforce2d 0:972874f31c98 73 r = u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_PAGE_NEXT, NULL);
iforce2d 0:972874f31c98 74 if ( r != 0 )
iforce2d 0:972874f31c98 75 {
iforce2d 0:972874f31c98 76 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_PAGE_BOX, &(u8g->current_page));
iforce2d 0:972874f31c98 77 }
iforce2d 0:972874f31c98 78 u8g->state_cb(U8G_STATE_MSG_RESTORE_ENV);
iforce2d 0:972874f31c98 79 return r;
iforce2d 0:972874f31c98 80 }
iforce2d 0:972874f31c98 81
iforce2d 0:972874f31c98 82 uint8_t u8g_SetContrastLL(u8g_t *u8g, u8g_dev_t *dev, uint8_t contrast)
iforce2d 0:972874f31c98 83 {
iforce2d 0:972874f31c98 84 return u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_CONTRAST, &contrast);
iforce2d 0:972874f31c98 85 }
iforce2d 0:972874f31c98 86
iforce2d 0:972874f31c98 87 void u8g_DrawPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y)
iforce2d 0:972874f31c98 88 {
iforce2d 0:972874f31c98 89 u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
iforce2d 0:972874f31c98 90 arg->x = x;
iforce2d 0:972874f31c98 91 arg->y = y;
iforce2d 0:972874f31c98 92 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_PIXEL, arg);
iforce2d 0:972874f31c98 93 }
iforce2d 0:972874f31c98 94
iforce2d 0:972874f31c98 95 void u8g_Draw8PixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
iforce2d 0:972874f31c98 96 {
iforce2d 0:972874f31c98 97 u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
iforce2d 0:972874f31c98 98 arg->x = x;
iforce2d 0:972874f31c98 99 arg->y = y;
iforce2d 0:972874f31c98 100 arg->dir = dir;
iforce2d 0:972874f31c98 101 arg->pixel = pixel;
iforce2d 0:972874f31c98 102 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_8PIXEL, arg);
iforce2d 0:972874f31c98 103 }
iforce2d 0:972874f31c98 104
iforce2d 0:972874f31c98 105 void u8g_Draw4TPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
iforce2d 0:972874f31c98 106 {
iforce2d 0:972874f31c98 107 u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
iforce2d 0:972874f31c98 108 arg->x = x;
iforce2d 0:972874f31c98 109 arg->y = y;
iforce2d 0:972874f31c98 110 arg->dir = dir;
iforce2d 0:972874f31c98 111 arg->pixel = pixel;
iforce2d 0:972874f31c98 112 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_4TPIXEL, arg);
iforce2d 0:972874f31c98 113 }
iforce2d 0:972874f31c98 114
iforce2d 0:972874f31c98 115
iforce2d 0:972874f31c98 116 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
iforce2d 0:972874f31c98 117 uint8_t u8g_IsBBXIntersectionLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
iforce2d 0:972874f31c98 118 {
iforce2d 0:972874f31c98 119 return u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_IS_BBX_INTERSECTION, &arg);
iforce2d 0:972874f31c98 120 }
iforce2d 0:972874f31c98 121 #endif
iforce2d 0:972874f31c98 122
iforce2d 0:972874f31c98 123
iforce2d 0:972874f31c98 124
iforce2d 0:972874f31c98 125 u8g_uint_t u8g_GetWidthLL(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 126 {
iforce2d 0:972874f31c98 127 u8g_uint_t r;
iforce2d 0:972874f31c98 128 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_WIDTH, &r);
iforce2d 0:972874f31c98 129 return r;
iforce2d 0:972874f31c98 130 }
iforce2d 0:972874f31c98 131
iforce2d 0:972874f31c98 132 u8g_uint_t u8g_GetHeightLL(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 133 {
iforce2d 0:972874f31c98 134 u8g_uint_t r;
iforce2d 0:972874f31c98 135 u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_HEIGHT, &r);
iforce2d 0:972874f31c98 136 return r;
iforce2d 0:972874f31c98 137 }
iforce2d 0:972874f31c98 138
iforce2d 0:972874f31c98 139 u8g_uint_t u8g_GetModeLL(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 140 {
iforce2d 0:972874f31c98 141 return u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_MODE, NULL);
iforce2d 0:972874f31c98 142 }
iforce2d 0:972874f31c98 143
iforce2d 0:972874f31c98 144
iforce2d 0:972874f31c98 145
iforce2d 0:972874f31c98 146 /*====================================================================*/
iforce2d 0:972874f31c98 147
iforce2d 0:972874f31c98 148 void u8g_UpdateDimension(u8g_t *u8g)
iforce2d 0:972874f31c98 149 {
iforce2d 0:972874f31c98 150 u8g->width = u8g_GetWidthLL(u8g, u8g->dev);
iforce2d 0:972874f31c98 151 u8g->height = u8g_GetHeightLL(u8g, u8g->dev);
iforce2d 0:972874f31c98 152 u8g->mode = u8g_GetModeLL(u8g, u8g->dev);
iforce2d 0:972874f31c98 153 /* 9 Dec 2012: u8g_scale.c requires update of current page */
iforce2d 0:972874f31c98 154 u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_GET_PAGE_BOX, &(u8g->current_page));
iforce2d 0:972874f31c98 155 }
iforce2d 0:972874f31c98 156
iforce2d 0:972874f31c98 157 static void u8g_init_data(u8g_t *u8g)
iforce2d 0:972874f31c98 158 {
iforce2d 0:972874f31c98 159 u8g->font = NULL;
iforce2d 0:972874f31c98 160 u8g->cursor_font = NULL;
iforce2d 0:972874f31c98 161 u8g->cursor_bg_color = 0;
iforce2d 0:972874f31c98 162 u8g->cursor_fg_color = 1;
iforce2d 0:972874f31c98 163 u8g->cursor_encoding = 34;
iforce2d 0:972874f31c98 164 u8g->cursor_fn = (u8g_draw_cursor_fn)0;
iforce2d 0:972874f31c98 165
iforce2d 0:972874f31c98 166 #if defined(U8G_WITH_PINLIST)
iforce2d 0:972874f31c98 167 {
iforce2d 0:972874f31c98 168 uint8_t i;
iforce2d 0:972874f31c98 169 for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
iforce2d 0:972874f31c98 170 u8g->pin_list[i] = U8G_PIN_NONE;
iforce2d 0:972874f31c98 171 }
iforce2d 0:972874f31c98 172 #endif
iforce2d 0:972874f31c98 173
iforce2d 0:972874f31c98 174 u8g_SetColorIndex(u8g, 1);
iforce2d 0:972874f31c98 175
iforce2d 0:972874f31c98 176 u8g_SetFontPosBaseline(u8g);
iforce2d 0:972874f31c98 177
iforce2d 0:972874f31c98 178 u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_XTEXT;
iforce2d 0:972874f31c98 179 u8g->font_ref_ascent = 0;
iforce2d 0:972874f31c98 180 u8g->font_ref_descent = 0;
iforce2d 0:972874f31c98 181 u8g->font_line_spacing_factor = 64; /* 64 = 1.0, 77 = 1.2 line spacing factor */
iforce2d 0:972874f31c98 182 u8g->line_spacing = 0;
iforce2d 0:972874f31c98 183
iforce2d 0:972874f31c98 184 u8g->state_cb = u8g_state_dummy_cb;
iforce2d 0:972874f31c98 185
iforce2d 0:972874f31c98 186 }
iforce2d 0:972874f31c98 187
iforce2d 0:972874f31c98 188 uint8_t u8g_Begin(u8g_t *u8g)
iforce2d 0:972874f31c98 189 {
iforce2d 0:972874f31c98 190 /* call and init low level driver and com device */
iforce2d 0:972874f31c98 191 if ( u8g_InitLL(u8g, u8g->dev) == 0 )
iforce2d 0:972874f31c98 192 return 0;
iforce2d 0:972874f31c98 193 /* fetch width and height from the low level */
iforce2d 0:972874f31c98 194 u8g_UpdateDimension(u8g);
iforce2d 0:972874f31c98 195 return 1;
iforce2d 0:972874f31c98 196 }
iforce2d 0:972874f31c98 197
iforce2d 0:972874f31c98 198 uint8_t u8g_Init(u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 199 {
iforce2d 0:972874f31c98 200 u8g_init_data(u8g);
iforce2d 0:972874f31c98 201 u8g->dev = dev;
iforce2d 0:972874f31c98 202
iforce2d 0:972874f31c98 203 /* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
iforce2d 0:972874f31c98 204 /* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
iforce2d 0:972874f31c98 205 /* if Arduino call u8g_UpdateDimension else u8g_Begin */
iforce2d 0:972874f31c98 206 /* issue 146 */
iforce2d 0:972874f31c98 207 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 208 }
iforce2d 0:972874f31c98 209
iforce2d 0:972874f31c98 210 /* special init for pure ARM systems */
iforce2d 0:972874f31c98 211 uint8_t u8g_InitComFn(u8g_t *u8g, u8g_dev_t *dev, u8g_com_fnptr com_fn)
iforce2d 0:972874f31c98 212 {
iforce2d 0:972874f31c98 213 u8g_init_data(u8g);
iforce2d 0:972874f31c98 214
iforce2d 0:972874f31c98 215 #if defined(U8G_WITH_PINLIST)
iforce2d 0:972874f31c98 216 {
iforce2d 0:972874f31c98 217 uint8_t i;
iforce2d 0:972874f31c98 218 for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
iforce2d 0:972874f31c98 219 u8g->pin_list[i] = U8G_PIN_DUMMY;
iforce2d 0:972874f31c98 220 }
iforce2d 0:972874f31c98 221 #endif
iforce2d 0:972874f31c98 222
iforce2d 0:972874f31c98 223 u8g->dev = dev;
iforce2d 0:972874f31c98 224
iforce2d 0:972874f31c98 225 /* replace the device procedure with a custom communication procedure */
iforce2d 0:972874f31c98 226 u8g->dev->com_fn = com_fn;
iforce2d 0:972874f31c98 227
iforce2d 0:972874f31c98 228 /* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
iforce2d 0:972874f31c98 229 /* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
iforce2d 0:972874f31c98 230 /* if Arduino call u8g_UpdateDimension else u8g_Begin */
iforce2d 0:972874f31c98 231 /* issue 146 */
iforce2d 0:972874f31c98 232 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 233 }
iforce2d 0:972874f31c98 234
iforce2d 0:972874f31c98 235
iforce2d 0:972874f31c98 236 #if defined(U8G_WITH_PINLIST)
iforce2d 0:972874f31c98 237 uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
iforce2d 0:972874f31c98 238 {
iforce2d 0:972874f31c98 239
iforce2d 0:972874f31c98 240 /* fill data structure with some suitable values */
iforce2d 0:972874f31c98 241 u8g_init_data(u8g);
iforce2d 0:972874f31c98 242 u8g->dev = dev;
iforce2d 0:972874f31c98 243
iforce2d 0:972874f31c98 244 /* assign user pins */
iforce2d 0:972874f31c98 245 u8g->pin_list[U8G_PI_SCK] = sck;
iforce2d 0:972874f31c98 246 u8g->pin_list[U8G_PI_MOSI] = mosi;
iforce2d 0:972874f31c98 247 u8g->pin_list[U8G_PI_CS] = cs;
iforce2d 0:972874f31c98 248 u8g->pin_list[U8G_PI_A0] = a0;
iforce2d 0:972874f31c98 249 u8g->pin_list[U8G_PI_RESET] = reset;
iforce2d 0:972874f31c98 250
iforce2d 0:972874f31c98 251 /* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
iforce2d 0:972874f31c98 252 /* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
iforce2d 0:972874f31c98 253 /* if Arduino call u8g_UpdateDimension else u8g_Begin */
iforce2d 0:972874f31c98 254 /* issue 146 */
iforce2d 0:972874f31c98 255 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 256 }
iforce2d 0:972874f31c98 257
iforce2d 0:972874f31c98 258 uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset)
iforce2d 0:972874f31c98 259 {
iforce2d 0:972874f31c98 260 /* fill data structure with some suitable values */
iforce2d 0:972874f31c98 261 u8g_init_data(u8g);
iforce2d 0:972874f31c98 262 u8g->dev = dev;
iforce2d 0:972874f31c98 263
iforce2d 0:972874f31c98 264
iforce2d 0:972874f31c98 265 /* assign user pins */
iforce2d 0:972874f31c98 266 u8g->pin_list[U8G_PI_CS] = cs;
iforce2d 0:972874f31c98 267 u8g->pin_list[U8G_PI_A0] = a0;
iforce2d 0:972874f31c98 268 u8g->pin_list[U8G_PI_RESET] = reset;
iforce2d 0:972874f31c98 269
iforce2d 0:972874f31c98 270 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 271 }
iforce2d 0:972874f31c98 272
iforce2d 0:972874f31c98 273 uint8_t u8g_InitI2C(u8g_t *u8g, u8g_dev_t *dev, uint8_t options)
iforce2d 0:972874f31c98 274 {
iforce2d 0:972874f31c98 275 /* fill data structure with some suitable values */
iforce2d 0:972874f31c98 276 u8g_init_data(u8g);
iforce2d 0:972874f31c98 277 u8g->dev = dev;
iforce2d 0:972874f31c98 278
iforce2d 0:972874f31c98 279 u8g->pin_list[U8G_PI_I2C_OPTION] = options;
iforce2d 0:972874f31c98 280
iforce2d 0:972874f31c98 281 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 282 }
iforce2d 0:972874f31c98 283
iforce2d 0:972874f31c98 284
iforce2d 0:972874f31c98 285 uint8_t u8g_Init8BitFixedPort(u8g_t *u8g, u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset)
iforce2d 0:972874f31c98 286 {
iforce2d 0:972874f31c98 287
iforce2d 0:972874f31c98 288 /* fill data structure with some suitable values */
iforce2d 0:972874f31c98 289 u8g_init_data(u8g);
iforce2d 0:972874f31c98 290 u8g->dev = dev;
iforce2d 0:972874f31c98 291
iforce2d 0:972874f31c98 292 /* assign user pins */
iforce2d 0:972874f31c98 293
iforce2d 0:972874f31c98 294 u8g->pin_list[U8G_PI_EN] = en;
iforce2d 0:972874f31c98 295 u8g->pin_list[U8G_PI_CS] = cs;
iforce2d 0:972874f31c98 296 u8g->pin_list[U8G_PI_DI] = di;
iforce2d 0:972874f31c98 297 u8g->pin_list[U8G_PI_RW] = rw;
iforce2d 0:972874f31c98 298 u8g->pin_list[U8G_PI_RESET] = reset;
iforce2d 0:972874f31c98 299
iforce2d 0:972874f31c98 300 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 301 }
iforce2d 0:972874f31c98 302
iforce2d 0:972874f31c98 303 uint8_t u8g_Init8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
iforce2d 0:972874f31c98 304 uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset)
iforce2d 0:972874f31c98 305 {
iforce2d 0:972874f31c98 306
iforce2d 0:972874f31c98 307 /* fill data structure with some suitable values */
iforce2d 0:972874f31c98 308 u8g_init_data(u8g);
iforce2d 0:972874f31c98 309 u8g->dev = dev;
iforce2d 0:972874f31c98 310
iforce2d 0:972874f31c98 311 /* assign user pins */
iforce2d 0:972874f31c98 312
iforce2d 0:972874f31c98 313 u8g->pin_list[U8G_PI_D0] = d0;
iforce2d 0:972874f31c98 314 u8g->pin_list[U8G_PI_D1] = d1;
iforce2d 0:972874f31c98 315 u8g->pin_list[U8G_PI_D2] = d2;
iforce2d 0:972874f31c98 316 u8g->pin_list[U8G_PI_D3] = d3;
iforce2d 0:972874f31c98 317 u8g->pin_list[U8G_PI_D4] = d4;
iforce2d 0:972874f31c98 318 u8g->pin_list[U8G_PI_D5] = d5;
iforce2d 0:972874f31c98 319 u8g->pin_list[U8G_PI_D6] = d6;
iforce2d 0:972874f31c98 320 u8g->pin_list[U8G_PI_D7] = d7;
iforce2d 0:972874f31c98 321
iforce2d 0:972874f31c98 322 u8g->pin_list[U8G_PI_EN] = en;
iforce2d 0:972874f31c98 323 u8g->pin_list[U8G_PI_CS1] = cs1;
iforce2d 0:972874f31c98 324 u8g->pin_list[U8G_PI_CS2] = cs2;
iforce2d 0:972874f31c98 325 u8g->pin_list[U8G_PI_DI] = di;
iforce2d 0:972874f31c98 326 u8g->pin_list[U8G_PI_RW] = rw;
iforce2d 0:972874f31c98 327 u8g->pin_list[U8G_PI_RESET] = reset;
iforce2d 0:972874f31c98 328
iforce2d 0:972874f31c98 329 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 330 }
iforce2d 0:972874f31c98 331
iforce2d 0:972874f31c98 332 /*
iforce2d 0:972874f31c98 333
iforce2d 0:972874f31c98 334 PIN_D0 8
iforce2d 0:972874f31c98 335 PIN_D1 9
iforce2d 0:972874f31c98 336 PIN_D2 10
iforce2d 0:972874f31c98 337 PIN_D3 11
iforce2d 0:972874f31c98 338 PIN_D4 4
iforce2d 0:972874f31c98 339 PIN_D5 5
iforce2d 0:972874f31c98 340 PIN_D6 6
iforce2d 0:972874f31c98 341 PIN_D7 7
iforce2d 0:972874f31c98 342
iforce2d 0:972874f31c98 343 PIN_CS 14
iforce2d 0:972874f31c98 344 PIN_A0 15
iforce2d 0:972874f31c98 345 PIN_RESET 16
iforce2d 0:972874f31c98 346 PIN_WR 17
iforce2d 0:972874f31c98 347 PIN_RD 18
iforce2d 0:972874f31c98 348
iforce2d 0:972874f31c98 349 u8g_InitRW8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset)
iforce2d 0:972874f31c98 350 u8g_InitRW8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16)
iforce2d 0:972874f31c98 351
iforce2d 0:972874f31c98 352 */
iforce2d 0:972874f31c98 353
iforce2d 0:972874f31c98 354 uint8_t u8g_InitRW8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
iforce2d 0:972874f31c98 355 uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset)
iforce2d 0:972874f31c98 356 {
iforce2d 0:972874f31c98 357
iforce2d 0:972874f31c98 358 /* fill data structure with some suitable values */
iforce2d 0:972874f31c98 359 u8g_init_data(u8g);
iforce2d 0:972874f31c98 360 u8g->dev = dev;
iforce2d 0:972874f31c98 361
iforce2d 0:972874f31c98 362 /* assign user pins */
iforce2d 0:972874f31c98 363
iforce2d 0:972874f31c98 364 u8g->pin_list[U8G_PI_D0] = d0;
iforce2d 0:972874f31c98 365 u8g->pin_list[U8G_PI_D1] = d1;
iforce2d 0:972874f31c98 366 u8g->pin_list[U8G_PI_D2] = d2;
iforce2d 0:972874f31c98 367 u8g->pin_list[U8G_PI_D3] = d3;
iforce2d 0:972874f31c98 368 u8g->pin_list[U8G_PI_D4] = d4;
iforce2d 0:972874f31c98 369 u8g->pin_list[U8G_PI_D5] = d5;
iforce2d 0:972874f31c98 370 u8g->pin_list[U8G_PI_D6] = d6;
iforce2d 0:972874f31c98 371 u8g->pin_list[U8G_PI_D7] = d7;
iforce2d 0:972874f31c98 372
iforce2d 0:972874f31c98 373 u8g->pin_list[U8G_PI_CS] = cs;
iforce2d 0:972874f31c98 374 u8g->pin_list[U8G_PI_A0] = a0;
iforce2d 0:972874f31c98 375 u8g->pin_list[U8G_PI_WR] = wr;
iforce2d 0:972874f31c98 376 u8g->pin_list[U8G_PI_RD] = rd;
iforce2d 0:972874f31c98 377 u8g->pin_list[U8G_PI_RESET] = reset;
iforce2d 0:972874f31c98 378
iforce2d 0:972874f31c98 379 return u8g_Begin(u8g);
iforce2d 0:972874f31c98 380 }
iforce2d 0:972874f31c98 381 #endif /* defined(U8G_WITH_PINLIST) */
iforce2d 0:972874f31c98 382
iforce2d 0:972874f31c98 383 void u8g_FirstPage(u8g_t *u8g)
iforce2d 0:972874f31c98 384 {
iforce2d 0:972874f31c98 385 u8g_FirstPageLL(u8g, u8g->dev);
iforce2d 0:972874f31c98 386 }
iforce2d 0:972874f31c98 387
iforce2d 0:972874f31c98 388 uint8_t u8g_NextPage(u8g_t *u8g)
iforce2d 0:972874f31c98 389 {
iforce2d 0:972874f31c98 390 if ( u8g->cursor_fn != (u8g_draw_cursor_fn)0 )
iforce2d 0:972874f31c98 391 {
iforce2d 0:972874f31c98 392 u8g->cursor_fn(u8g);
iforce2d 0:972874f31c98 393 }
iforce2d 0:972874f31c98 394 return u8g_NextPageLL(u8g, u8g->dev);
iforce2d 0:972874f31c98 395 }
iforce2d 0:972874f31c98 396
iforce2d 0:972874f31c98 397 uint8_t u8g_SetContrast(u8g_t *u8g, uint8_t contrast)
iforce2d 0:972874f31c98 398 {
iforce2d 0:972874f31c98 399 return u8g_SetContrastLL(u8g, u8g->dev, contrast);
iforce2d 0:972874f31c98 400 }
iforce2d 0:972874f31c98 401
iforce2d 0:972874f31c98 402 void u8g_SleepOn(u8g_t *u8g)
iforce2d 0:972874f31c98 403 {
iforce2d 0:972874f31c98 404 u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SLEEP_ON, NULL);
iforce2d 0:972874f31c98 405 }
iforce2d 0:972874f31c98 406
iforce2d 0:972874f31c98 407 void u8g_SleepOff(u8g_t *u8g)
iforce2d 0:972874f31c98 408 {
iforce2d 0:972874f31c98 409 u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SLEEP_OFF, NULL);
iforce2d 0:972874f31c98 410 }
iforce2d 0:972874f31c98 411
iforce2d 0:972874f31c98 412
iforce2d 0:972874f31c98 413 void u8g_DrawPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y)
iforce2d 0:972874f31c98 414 {
iforce2d 0:972874f31c98 415 u8g_DrawPixelLL(u8g, u8g->dev, x, y);
iforce2d 0:972874f31c98 416 }
iforce2d 0:972874f31c98 417
iforce2d 0:972874f31c98 418 void u8g_Draw8Pixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
iforce2d 0:972874f31c98 419 {
iforce2d 0:972874f31c98 420 u8g_Draw8PixelLL(u8g, u8g->dev, x, y, dir, pixel);
iforce2d 0:972874f31c98 421 }
iforce2d 0:972874f31c98 422
iforce2d 0:972874f31c98 423 void u8g_Draw4TPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
iforce2d 0:972874f31c98 424 {
iforce2d 0:972874f31c98 425 u8g_Draw4TPixelLL(u8g, u8g->dev, x, y, dir, pixel);
iforce2d 0:972874f31c98 426 }
iforce2d 0:972874f31c98 427
iforce2d 0:972874f31c98 428
iforce2d 0:972874f31c98 429 /* u8g_IsBBXIntersection() has been moved to u8g_clip.c */
iforce2d 0:972874f31c98 430 #ifdef OBSOLETE_CODE
iforce2d 0:972874f31c98 431 uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
iforce2d 0:972874f31c98 432 {
iforce2d 0:972874f31c98 433 /* new code */
iforce2d 0:972874f31c98 434 u8g_dev_arg_bbx_t arg;
iforce2d 0:972874f31c98 435 arg.x = x;
iforce2d 0:972874f31c98 436 arg.y = y;
iforce2d 0:972874f31c98 437 arg.w = w;
iforce2d 0:972874f31c98 438 arg.h = h;
iforce2d 0:972874f31c98 439 return u8g_is_box_bbx_intersection(&(u8g->current_page), &arg);
iforce2d 0:972874f31c98 440
iforce2d 0:972874f31c98 441 /* old code */
iforce2d 0:972874f31c98 442 //return u8g_IsBBXIntersectionLL(u8g, u8g->dev, x, y, w, h);
iforce2d 0:972874f31c98 443 }
iforce2d 0:972874f31c98 444 #endif
iforce2d 0:972874f31c98 445
iforce2d 0:972874f31c98 446 /*
iforce2d 0:972874f31c98 447 idx: index for the palette entry (0..255)
iforce2d 0:972874f31c98 448 r: value for red (0..255)
iforce2d 0:972874f31c98 449 g: value for green (0..255)
iforce2d 0:972874f31c98 450 b: value for blue (0..255)
iforce2d 0:972874f31c98 451 */
iforce2d 0:972874f31c98 452 void u8g_SetColorEntry(u8g_t *u8g, uint8_t idx, uint8_t r, uint8_t g, uint8_t b)
iforce2d 0:972874f31c98 453 {
iforce2d 0:972874f31c98 454 u8g_dev_arg_irgb_t irgb;
iforce2d 0:972874f31c98 455 irgb.idx = idx;
iforce2d 0:972874f31c98 456 irgb.r = r;
iforce2d 0:972874f31c98 457 irgb.g = g;
iforce2d 0:972874f31c98 458 irgb.b = b;
iforce2d 0:972874f31c98 459 u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SET_COLOR_ENTRY, &irgb);
iforce2d 0:972874f31c98 460 }
iforce2d 0:972874f31c98 461
iforce2d 0:972874f31c98 462 void u8g_SetColorIndex(u8g_t *u8g, uint8_t idx)
iforce2d 0:972874f31c98 463 {
iforce2d 0:972874f31c98 464 u8g->arg_pixel.color = idx;
iforce2d 0:972874f31c98 465 /*u8g->color_index = idx; */ /* must be removed */
iforce2d 0:972874f31c98 466 }
iforce2d 0:972874f31c98 467
iforce2d 0:972874f31c98 468 void u8g_SetHiColor(u8g_t *u8g, uint16_t rgb)
iforce2d 0:972874f31c98 469 {
iforce2d 0:972874f31c98 470 u8g->arg_pixel.color = rgb&255;
iforce2d 0:972874f31c98 471 u8g->arg_pixel.hi_color = rgb>>8;
iforce2d 0:972874f31c98 472 /*u8g->color_index = idx; */ /* must be removed */
iforce2d 0:972874f31c98 473 }
iforce2d 0:972874f31c98 474
iforce2d 0:972874f31c98 475 void u8g_SetHiColorByRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
iforce2d 0:972874f31c98 476 {
iforce2d 0:972874f31c98 477
iforce2d 0:972874f31c98 478 r &= ~7;
iforce2d 0:972874f31c98 479 g >>= 2;
iforce2d 0:972874f31c98 480 b >>= 3;
iforce2d 0:972874f31c98 481 u8g->arg_pixel.color = b;
iforce2d 0:972874f31c98 482 u8g->arg_pixel.color |= (g & 7) << 5;
iforce2d 0:972874f31c98 483 u8g->arg_pixel.hi_color = r;
iforce2d 0:972874f31c98 484 u8g->arg_pixel.hi_color |= (g>>3) & 7;
iforce2d 0:972874f31c98 485
iforce2d 0:972874f31c98 486 //u8g_SetHiColor(u8g, U8G_GET_HICOLOR_BY_RGB(r,g,b));
iforce2d 0:972874f31c98 487 }
iforce2d 0:972874f31c98 488
iforce2d 0:972874f31c98 489 void u8g_SetRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
iforce2d 0:972874f31c98 490 {
iforce2d 0:972874f31c98 491 if ( u8g->mode == U8G_MODE_R3G3B2 )
iforce2d 0:972874f31c98 492 {
iforce2d 0:972874f31c98 493 r &= 0x0e0;
iforce2d 0:972874f31c98 494 g &= 0x0e0;
iforce2d 0:972874f31c98 495 g >>= 3;
iforce2d 0:972874f31c98 496 b >>= 6;
iforce2d 0:972874f31c98 497 u8g->arg_pixel.color = r | g | b;
iforce2d 0:972874f31c98 498 }
iforce2d 0:972874f31c98 499 else if ( u8g->mode == U8G_MODE_HICOLOR )
iforce2d 0:972874f31c98 500 {
iforce2d 0:972874f31c98 501 u8g_SetHiColorByRGB(u8g, r,g,b);
iforce2d 0:972874f31c98 502 }
iforce2d 0:972874f31c98 503 else
iforce2d 0:972874f31c98 504 {
iforce2d 0:972874f31c98 505 u8g->arg_pixel.color = r;
iforce2d 0:972874f31c98 506 u8g->arg_pixel.hi_color = g;
iforce2d 0:972874f31c98 507 u8g->arg_pixel.blue = b;
iforce2d 0:972874f31c98 508 }
iforce2d 0:972874f31c98 509 }
iforce2d 0:972874f31c98 510
iforce2d 0:972874f31c98 511
iforce2d 0:972874f31c98 512 uint8_t u8g_GetColorIndex(u8g_t *u8g)
iforce2d 0:972874f31c98 513 {
iforce2d 0:972874f31c98 514 return u8g->arg_pixel.color;
iforce2d 0:972874f31c98 515 }
iforce2d 0:972874f31c98 516
iforce2d 0:972874f31c98 517 uint8_t u8g_GetDefaultForegroundColor(u8g_t *u8g)
iforce2d 0:972874f31c98 518 {
iforce2d 0:972874f31c98 519 uint8_t mode;
iforce2d 0:972874f31c98 520 mode = u8g_GetMode(u8g);
iforce2d 0:972874f31c98 521 if ( mode == U8G_MODE_R3G3B2 )
iforce2d 0:972874f31c98 522 return 255; /* white */
iforce2d 0:972874f31c98 523 else if ( u8g_GetMode(u8g) == U8G_MODE_GRAY2BIT )
iforce2d 0:972874f31c98 524 return 3; /* max intensity */
iforce2d 0:972874f31c98 525 else /* if ( u8g.getMode() == U8G_MODE_BW ) */
iforce2d 0:972874f31c98 526 return 1; /* pixel on */
iforce2d 0:972874f31c98 527 return 1;
iforce2d 0:972874f31c98 528 }
iforce2d 0:972874f31c98 529
iforce2d 0:972874f31c98 530 void u8g_SetDefaultForegroundColor(u8g_t *u8g)
iforce2d 0:972874f31c98 531 {
iforce2d 0:972874f31c98 532 if ( u8g->mode == U8G_MODE_HICOLOR )
iforce2d 0:972874f31c98 533 {
iforce2d 0:972874f31c98 534 u8g->arg_pixel.color = 0x0ff;
iforce2d 0:972874f31c98 535 u8g->arg_pixel.hi_color = 0x0ff;
iforce2d 0:972874f31c98 536 }
iforce2d 0:972874f31c98 537 else
iforce2d 0:972874f31c98 538 {
iforce2d 0:972874f31c98 539 u8g_SetColorIndex(u8g, u8g_GetDefaultForegroundColor(u8g));
iforce2d 0:972874f31c98 540 }
iforce2d 0:972874f31c98 541 }
iforce2d 0:972874f31c98 542
iforce2d 0:972874f31c98 543 uint8_t u8g_GetDefaultBackgroundColor(u8g_t *u8g)
iforce2d 0:972874f31c98 544 {
iforce2d 0:972874f31c98 545 return 0;
iforce2d 0:972874f31c98 546 }
iforce2d 0:972874f31c98 547
iforce2d 0:972874f31c98 548 void u8g_SetDefaultBackgroundColor(u8g_t *u8g)
iforce2d 0:972874f31c98 549 {
iforce2d 0:972874f31c98 550 u8g_SetColorIndex(u8g, u8g_GetDefaultBackgroundColor(u8g)); /* pixel on / black */
iforce2d 0:972874f31c98 551 }
iforce2d 0:972874f31c98 552
iforce2d 0:972874f31c98 553 uint8_t u8g_GetDefaultMidColor(u8g_t *u8g)
iforce2d 0:972874f31c98 554 {
iforce2d 0:972874f31c98 555 uint8_t mode;
iforce2d 0:972874f31c98 556 mode = u8g_GetMode(u8g);
iforce2d 0:972874f31c98 557 if ( mode == U8G_MODE_R3G3B2 )
iforce2d 0:972874f31c98 558 return 0x06d; /* gray: 01101101 */
iforce2d 0:972874f31c98 559 else if ( u8g_GetMode(u8g) == U8G_MODE_GRAY2BIT )
iforce2d 0:972874f31c98 560 return 1; /* low mid intensity */
iforce2d 0:972874f31c98 561 else /* if ( u8g.getMode() == U8G_MODE_BW ) */
iforce2d 0:972874f31c98 562 return 1; /* pixel on */
iforce2d 0:972874f31c98 563 return 1; /* default */
iforce2d 0:972874f31c98 564 }
iforce2d 0:972874f31c98 565
iforce2d 0:972874f31c98 566 void u8g_SetDefaultMidColor(u8g_t *u8g)
iforce2d 0:972874f31c98 567 {
iforce2d 0:972874f31c98 568 u8g_SetColorIndex(u8g, u8g_GetDefaultMidColor(u8g));
iforce2d 0:972874f31c98 569 }
iforce2d 0:972874f31c98 570
iforce2d 0:972874f31c98 571
iforce2d 0:972874f31c98 572
iforce2d 0:972874f31c98 573
iforce2d 0:972874f31c98 574