Commit 6ea3d639 authored by HuangRui's avatar HuangRui
Browse files

Merge branch 'dev' of https://github.com/nodemcu/nodemcu-firmware

Conflicts:
	app/include/user_config.h
	ld/eagle.app.v6.ld
parents f51b4725 1d1f0857
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
u8g_line.h
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
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.h"
void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2)
{
u8g_uint_t tmp;
u8g_uint_t x,y;
u8g_uint_t dx, dy;
u8g_int_t err;
u8g_int_t ystep;
uint8_t swapxy = 0;
/* no BBX intersection check at the moment, should be added... */
if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1;
if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1;
if ( dy > dx )
{
swapxy = 1;
tmp = dx; dx =dy; dy = tmp;
tmp = x1; x1 =y1; y1 = tmp;
tmp = x2; x2 =y2; y2 = tmp;
}
if ( x1 > x2 )
{
tmp = x1; x1 =x2; x2 = tmp;
tmp = y1; y1 =y2; y2 = tmp;
}
err = dx >> 1;
if ( y2 > y1 ) ystep = 1; else ystep = -1;
y = y1;
for( x = x1; x <= x2; x++ )
{
if ( swapxy == 0 )
u8g_DrawPixel(u8g, x, y);
else
u8g_DrawPixel(u8g, y, x);
err -= (uint8_t)dy;
if ( err < 0 )
{
y += (u8g_uint_t)ystep;
err += (u8g_uint_t)dx;
}
}
}
/*
u8g_ll_api.c
low level api
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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 <stddef.h>
#include "u8g.h"
uint8_t u8g_call_dev_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
return dev->dev_fn(u8g, dev, msg, arg);
}
/*====================================================================*/
uint8_t u8g_InitLL(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t r;
u8g->state_cb(U8G_STATE_MSG_BACKUP_ENV);
r = u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_INIT, NULL);
u8g->state_cb(U8G_STATE_MSG_BACKUP_U8G);
u8g->state_cb(U8G_STATE_MSG_RESTORE_ENV);
return r;
}
void u8g_FirstPageLL(u8g_t *u8g, u8g_dev_t *dev)
{
u8g->state_cb(U8G_STATE_MSG_BACKUP_ENV);
u8g->state_cb(U8G_STATE_MSG_RESTORE_U8G);
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_PAGE_FIRST, NULL);
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_PAGE_BOX, &(u8g->current_page));
u8g->state_cb(U8G_STATE_MSG_RESTORE_ENV);
}
uint8_t u8g_NextPageLL(u8g_t *u8g, u8g_dev_t *dev)
{
uint8_t r;
u8g->state_cb(U8G_STATE_MSG_BACKUP_ENV);
u8g->state_cb(U8G_STATE_MSG_RESTORE_U8G);
r = u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_PAGE_NEXT, NULL);
if ( r != 0 )
{
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_PAGE_BOX, &(u8g->current_page));
}
u8g->state_cb(U8G_STATE_MSG_RESTORE_ENV);
return r;
}
uint8_t u8g_SetContrastLL(u8g_t *u8g, u8g_dev_t *dev, uint8_t contrast)
{
return u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_CONTRAST, &contrast);
}
void u8g_DrawPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y)
{
u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
arg->x = x;
arg->y = y;
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_PIXEL, arg);
}
void u8g_Draw8PixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
{
u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
arg->x = x;
arg->y = y;
arg->dir = dir;
arg->pixel = pixel;
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_8PIXEL, arg);
}
void u8g_Draw4TPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
{
u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
arg->x = x;
arg->y = y;
arg->dir = dir;
arg->pixel = pixel;
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_4TPIXEL, arg);
}
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
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)
{
return u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_IS_BBX_INTERSECTION, &arg);
}
#endif
u8g_uint_t u8g_GetWidthLL(u8g_t *u8g, u8g_dev_t *dev)
{
u8g_uint_t r;
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_WIDTH, &r);
return r;
}
u8g_uint_t u8g_GetHeightLL(u8g_t *u8g, u8g_dev_t *dev)
{
u8g_uint_t r;
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_HEIGHT, &r);
return r;
}
u8g_uint_t u8g_GetModeLL(u8g_t *u8g, u8g_dev_t *dev)
{
return u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_GET_MODE, NULL);
}
/*====================================================================*/
void u8g_UpdateDimension(u8g_t *u8g)
{
u8g->width = u8g_GetWidthLL(u8g, u8g->dev);
u8g->height = u8g_GetHeightLL(u8g, u8g->dev);
u8g->mode = u8g_GetModeLL(u8g, u8g->dev);
/* 9 Dec 2012: u8g_scale.c requires update of current page */
u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_GET_PAGE_BOX, &(u8g->current_page));
}
static void u8g_init_data(u8g_t *u8g)
{
u8g->font = NULL;
u8g->cursor_font = NULL;
u8g->cursor_bg_color = 0;
u8g->cursor_fg_color = 1;
u8g->cursor_encoding = 34;
u8g->cursor_fn = (u8g_draw_cursor_fn)0;
#if defined(U8G_WITH_PINLIST)
{
uint8_t i;
for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
u8g->pin_list[i] = U8G_PIN_NONE;
}
#endif
u8g_SetColorIndex(u8g, 1);
u8g_SetFontPosBaseline(u8g);
u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_XTEXT;
u8g->font_ref_ascent = 0;
u8g->font_ref_descent = 0;
u8g->font_line_spacing_factor = 64; /* 64 = 1.0, 77 = 1.2 line spacing factor */
u8g->line_spacing = 0;
u8g->state_cb = u8g_state_dummy_cb;
}
uint8_t u8g_Begin(u8g_t *u8g)
{
/* call and init low level driver and com device */
if ( u8g_InitLL(u8g, u8g->dev) == 0 )
return 0;
/* fetch width and height from the low level */
u8g_UpdateDimension(u8g);
return 1;
}
uint8_t u8g_Init(u8g_t *u8g, u8g_dev_t *dev)
{
u8g_init_data(u8g);
u8g->dev = dev;
/* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
/* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
/* if Arduino call u8g_UpdateDimension else u8g_Begin */
/* issue 146 */
return u8g_Begin(u8g);
}
/* special init for pure ARM systems */
uint8_t u8g_InitComFn(u8g_t *u8g, u8g_dev_t *dev, u8g_com_fnptr com_fn)
{
u8g_init_data(u8g);
#if defined(U8G_WITH_PINLIST)
{
uint8_t i;
for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
u8g->pin_list[i] = U8G_PIN_DUMMY;
}
#endif
u8g->dev = dev;
/* replace the device procedure with a custom communication procedure */
u8g->dev->com_fn = com_fn;
/* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
/* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
/* if Arduino call u8g_UpdateDimension else u8g_Begin */
/* issue 146 */
return u8g_Begin(u8g);
}
#if defined(U8G_WITH_PINLIST)
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)
{
/* fill data structure with some suitable values */
u8g_init_data(u8g);
u8g->dev = dev;
/* assign user pins */
u8g->pin_list[U8G_PI_SCK] = sck;
u8g->pin_list[U8G_PI_MOSI] = mosi;
u8g->pin_list[U8G_PI_CS] = cs;
u8g->pin_list[U8G_PI_A0] = a0;
u8g->pin_list[U8G_PI_RESET] = reset;
/* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
/* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
/* if Arduino call u8g_UpdateDimension else u8g_Begin */
/* issue 146 */
return u8g_Begin(u8g);
}
uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset)
{
/* fill data structure with some suitable values */
u8g_init_data(u8g);
u8g->dev = dev;
/* assign user pins */
u8g->pin_list[U8G_PI_CS] = cs;
u8g->pin_list[U8G_PI_A0] = a0;
u8g->pin_list[U8G_PI_RESET] = reset;
return u8g_Begin(u8g);
}
uint8_t u8g_InitI2C(u8g_t *u8g, u8g_dev_t *dev, uint8_t options)
{
/* fill data structure with some suitable values */
u8g_init_data(u8g);
u8g->dev = dev;
u8g->pin_list[U8G_PI_I2C_OPTION] = options;
return u8g_Begin(u8g);
}
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)
{
/* fill data structure with some suitable values */
u8g_init_data(u8g);
u8g->dev = dev;
/* assign user pins */
u8g->pin_list[U8G_PI_EN] = en;
u8g->pin_list[U8G_PI_CS] = cs;
u8g->pin_list[U8G_PI_DI] = di;
u8g->pin_list[U8G_PI_RW] = rw;
u8g->pin_list[U8G_PI_RESET] = reset;
return u8g_Begin(u8g);
}
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,
uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset)
{
/* fill data structure with some suitable values */
u8g_init_data(u8g);
u8g->dev = dev;
/* assign user pins */
u8g->pin_list[U8G_PI_D0] = d0;
u8g->pin_list[U8G_PI_D1] = d1;
u8g->pin_list[U8G_PI_D2] = d2;
u8g->pin_list[U8G_PI_D3] = d3;
u8g->pin_list[U8G_PI_D4] = d4;
u8g->pin_list[U8G_PI_D5] = d5;
u8g->pin_list[U8G_PI_D6] = d6;
u8g->pin_list[U8G_PI_D7] = d7;
u8g->pin_list[U8G_PI_EN] = en;
u8g->pin_list[U8G_PI_CS1] = cs1;
u8g->pin_list[U8G_PI_CS2] = cs2;
u8g->pin_list[U8G_PI_DI] = di;
u8g->pin_list[U8G_PI_RW] = rw;
u8g->pin_list[U8G_PI_RESET] = reset;
return u8g_Begin(u8g);
}
/*
PIN_D0 8
PIN_D1 9
PIN_D2 10
PIN_D3 11
PIN_D4 4
PIN_D5 5
PIN_D6 6
PIN_D7 7
PIN_CS 14
PIN_A0 15
PIN_RESET 16
PIN_WR 17
PIN_RD 18
u8g_InitRW8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset)
u8g_InitRW8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16)
*/
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,
uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset)
{
/* fill data structure with some suitable values */
u8g_init_data(u8g);
u8g->dev = dev;
/* assign user pins */
u8g->pin_list[U8G_PI_D0] = d0;
u8g->pin_list[U8G_PI_D1] = d1;
u8g->pin_list[U8G_PI_D2] = d2;
u8g->pin_list[U8G_PI_D3] = d3;
u8g->pin_list[U8G_PI_D4] = d4;
u8g->pin_list[U8G_PI_D5] = d5;
u8g->pin_list[U8G_PI_D6] = d6;
u8g->pin_list[U8G_PI_D7] = d7;
u8g->pin_list[U8G_PI_CS] = cs;
u8g->pin_list[U8G_PI_A0] = a0;
u8g->pin_list[U8G_PI_WR] = wr;
u8g->pin_list[U8G_PI_RD] = rd;
u8g->pin_list[U8G_PI_RESET] = reset;
return u8g_Begin(u8g);
}
#endif /* defined(U8G_WITH_PINLIST) */
void u8g_FirstPage(u8g_t *u8g)
{
u8g_FirstPageLL(u8g, u8g->dev);
}
uint8_t u8g_NextPage(u8g_t *u8g)
{
if ( u8g->cursor_fn != (u8g_draw_cursor_fn)0 )
{
u8g->cursor_fn(u8g);
}
return u8g_NextPageLL(u8g, u8g->dev);
}
uint8_t u8g_SetContrast(u8g_t *u8g, uint8_t contrast)
{
return u8g_SetContrastLL(u8g, u8g->dev, contrast);
}
void u8g_SleepOn(u8g_t *u8g)
{
u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SLEEP_ON, NULL);
}
void u8g_SleepOff(u8g_t *u8g)
{
u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SLEEP_OFF, NULL);
}
void u8g_DrawPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y)
{
u8g_DrawPixelLL(u8g, u8g->dev, x, y);
}
void u8g_Draw8Pixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
{
u8g_Draw8PixelLL(u8g, u8g->dev, x, y, dir, pixel);
}
void u8g_Draw4TPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
{
u8g_Draw4TPixelLL(u8g, u8g->dev, x, y, dir, pixel);
}
/* u8g_IsBBXIntersection() has been moved to u8g_clip.c */
#ifdef OBSOLETE_CODE
uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
{
/* new code */
u8g_dev_arg_bbx_t arg;
arg.x = x;
arg.y = y;
arg.w = w;
arg.h = h;
return u8g_is_box_bbx_intersection(&(u8g->current_page), &arg);
/* old code */
//return u8g_IsBBXIntersectionLL(u8g, u8g->dev, x, y, w, h);
}
#endif
/*
idx: index for the palette entry (0..255)
r: value for red (0..255)
g: value for green (0..255)
b: value for blue (0..255)
*/
void u8g_SetColorEntry(u8g_t *u8g, uint8_t idx, uint8_t r, uint8_t g, uint8_t b)
{
u8g_dev_arg_irgb_t irgb;
irgb.idx = idx;
irgb.r = r;
irgb.g = g;
irgb.b = b;
u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SET_COLOR_ENTRY, &irgb);
}
void u8g_SetColorIndex(u8g_t *u8g, uint8_t idx)
{
u8g->arg_pixel.color = idx;
/*u8g->color_index = idx; */ /* must be removed */
}
void u8g_SetHiColor(u8g_t *u8g, uint16_t rgb)
{
u8g->arg_pixel.color = rgb&255;
u8g->arg_pixel.hi_color = rgb>>8;
/*u8g->color_index = idx; */ /* must be removed */
}
void u8g_SetHiColorByRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
{
r &= ~7;
g >>= 2;
b >>= 3;
u8g->arg_pixel.color = b;
u8g->arg_pixel.color |= (g & 7) << 5;
u8g->arg_pixel.hi_color = r;
u8g->arg_pixel.hi_color |= (g>>3) & 7;
//u8g_SetHiColor(u8g, U8G_GET_HICOLOR_BY_RGB(r,g,b));
}
void u8g_SetRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
{
if ( u8g->mode == U8G_MODE_R3G3B2 )
{
r &= 0x0e0;
g &= 0x0e0;
g >>= 3;
b >>= 6;
u8g->arg_pixel.color = r | g | b;
}
else if ( u8g->mode == U8G_MODE_HICOLOR )
{
u8g_SetHiColorByRGB(u8g, r,g,b);
}
else
{
u8g->arg_pixel.color = r;
u8g->arg_pixel.hi_color = g;
u8g->arg_pixel.blue = b;
}
}
uint8_t u8g_GetColorIndex(u8g_t *u8g)
{
return u8g->arg_pixel.color;
}
uint8_t u8g_GetDefaultForegroundColor(u8g_t *u8g)
{
uint8_t mode;
mode = u8g_GetMode(u8g);
if ( mode == U8G_MODE_R3G3B2 )
return 255; /* white */
else if ( u8g_GetMode(u8g) == U8G_MODE_GRAY2BIT )
return 3; /* max intensity */
else /* if ( u8g.getMode() == U8G_MODE_BW ) */
return 1; /* pixel on */
return 1;
}
void u8g_SetDefaultForegroundColor(u8g_t *u8g)
{
if ( u8g->mode == U8G_MODE_HICOLOR )
{
u8g->arg_pixel.color = 0x0ff;
u8g->arg_pixel.hi_color = 0x0ff;
}
else
{
u8g_SetColorIndex(u8g, u8g_GetDefaultForegroundColor(u8g));
}
}
uint8_t u8g_GetDefaultBackgroundColor(u8g_t *u8g)
{
return 0;
}
void u8g_SetDefaultBackgroundColor(u8g_t *u8g)
{
u8g_SetColorIndex(u8g, u8g_GetDefaultBackgroundColor(u8g)); /* pixel on / black */
}
uint8_t u8g_GetDefaultMidColor(u8g_t *u8g)
{
uint8_t mode;
mode = u8g_GetMode(u8g);
if ( mode == U8G_MODE_R3G3B2 )
return 0x06d; /* gray: 01101101 */
else if ( u8g_GetMode(u8g) == U8G_MODE_GRAY2BIT )
return 1; /* low mid intensity */
else /* if ( u8g.getMode() == U8G_MODE_BW ) */
return 1; /* pixel on */
return 1; /* default */
}
void u8g_SetDefaultMidColor(u8g_t *u8g)
{
u8g_SetColorIndex(u8g, u8g_GetDefaultMidColor(u8g));
}
/*
u8g_page.c
page helper functions, only called by the dev handler.
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
/*
setup page count structure
conditions: page_height <= total_height
*/
void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height )
{
p->page_height = page_height;
p->total_height = total_height;
p->page = 0;
u8g_page_First(p);
}
void u8g_page_First(u8g_page_t *p)
{
p->page_y0 = 0;
p->page_y1 = p->page_height;
p->page_y1--;
p->page = 0;
}
uint8_t u8g_page_Next(u8g_page_t * p)
{
register u8g_uint_t y1;
p->page_y0 += p->page_height;
if ( p->page_y0 >= p->total_height )
return 0;
p->page++;
y1 = p->page_y1;
y1 += p->page_height;
if ( y1 >= p->total_height )
{
y1 = p->total_height;
y1--;
}
p->page_y1 = y1;
return 1;
}
/*
u8g_pb.c
common procedures for the page buffer
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
void u8g_pb_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
end_ptr += b->width;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
/* the following procedure does not work. why? Can be checked with descpic */
/*
void u8g_pb_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t cnt = b->width;
do
{
*ptr++ = 0;
cnt--;
} while( cnt != 0 );
}
*/
/*
intersection assumptions:
a1 <= a2 is always true
*/
/*
minimized version
---1----0 1 b1 <= a2 && b1 > b2
-----1--0 1 b2 >= a1 && b1 > b2
---1-1--- 1 b1 <= a2 && b2 >= a1
*/
/*
uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
{
uint8_t c0, c1, c;
c0 = v0 <= b->p.page_y1;
c1 = v1 >= b->p.page_y0;
c = v0 > v1;
if ( c0 && c1 ) return 1;
if ( c0 && c ) return 1;
if ( c1 && c ) return 1;
return 0;
}
*/
uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1)
{
uint8_t c1, c2, c3, tmp;
c1 = v0 <= pb->p.page_y1;
c2 = v1 >= pb->p.page_y0;
c3 = v0 > v1;
/*
if ( c1 && c2 )
return 1;
if ( c1 && c3 )
return 1;
if ( c2 && c3 )
return 1;
return 0;
*/
tmp = c1;
c1 &= c2;
c2 &= c3;
c3 &= tmp;
c1 |= c2;
c1 |= c3;
return c1 & 1;
}
uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
{
uint8_t /*c0, c1, */ c2, c3;
/*
conditions: b->p.page_y0 < b->p.page_y1
there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed
*/
/*
c0 = v0 < 0;
c1 = v1 < 0;
*/
c2 = v0 > b->width;
c3 = v1 > b->width;
/*if ( c0 && c1 ) return 0;*/
if ( c2 && c3 ) return 0;
/*if ( c1 && c2 ) return 0;*/
return 1;
}
uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx)
{
u8g_uint_t tmp;
tmp = bbx->y;
tmp += bbx->h;
tmp--;
if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 )
return 0;
/* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */
tmp = bbx->x;
tmp += bbx->w;
tmp--;
return u8g_pb_IsXIntersection(pb, bbx->x, tmp);
}
void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box)
{
box->x0 = 0;
box->y0 = pb->p.page_y0;
box->x1 = pb->width;
box->x1--;
box->y1 = pb->p.page_y1;
}
uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
u8g_uint_t v0, v1;
v0 = arg_pixel->y;
v1 = v0;
switch( arg_pixel->dir )
{
case 0:
break;
case 1:
v1 += 8; /* this is independent from the page height */
break;
case 2:
break;
case 3:
v0 -= 8;
break;
}
return u8g_pb_IsYIntersection(b, v0, v1);
}
uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev)
{
return u8g_WriteSequence(u8g, dev, b->width, b->buf);
}
/*
u8g_pb14v1.c
14bit height monochrom (1 bit) page buffer,
byte has vertical orientation, 7 bits per byte
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb14v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb14v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb14v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb14v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
void u8g_pb14v1_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
end_ptr += b->width*2;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
/* Obsolete, usually set by the init of the structure */
void u8g_pb14v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb14v1_Clear(b);
}
void u8g_pb14v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
if ( y >= 7 )
{
ptr += b->width;
y -= 7;
}
mask = 1;
mask <<= y;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
}
void u8g_pb14v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb14v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb14v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb14v1_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb14v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb14v1_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb14v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb14v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb14v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb14v1_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb14v1_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb16h1.c
2x 8bit height monochrom (1 bit) page buffer
byte has horizontal orientation
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
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.
total buffer size is limited to 2*256 bytes because of the calculation inside the set pixel procedure
*/
#include "u8g.h"
#include <string.h>
void u8g_pb16h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb16h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb16h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb16h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
void u8g_pb16h1_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
end_ptr += b->width*2;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pb16h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb16h1_Clear(b);
}
/* limitation: total buffer must not exceed 2*256 bytes */
void u8g_pb16h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
u8g_uint_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
if ( y >= 8 )
{
ptr += b->width;
y &= 0x07;
}
tmp = b->width;
tmp >>= 3;
tmp *= (uint8_t)y;
ptr += tmp;
mask = 0x080;
mask >>= x & 7;
x >>= 3;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
}
void u8g_pb16h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb16h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb16h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb16h1_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb16h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb16h1_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb16h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb16h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb16h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb16h1_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb16h1_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb16h2.c
2 bit per pixel page buffer
byte has horizontal orientation
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb16h2_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
/* two bits per pixel, 16 bits height --> 8 pixel --> 4 pixel per byte */
end_ptr += b->width;
end_ptr += b->width;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pb16h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb16h2_Clear(b);
}
static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index, uint8_t is_or) U8G_NOINLINE;
static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index, uint8_t is_or)
{
register uint8_t mask;
register uint16_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = b->width;
tmp >>= 2;
tmp *= (uint8_t)y;
ptr += tmp;
tmp = x;
tmp >>= 2;
ptr += tmp;
tmp = x;
tmp &= 3;
tmp <<= 1;
if ( is_or == 0 )
{
mask = 3;
mask <<= tmp;
mask = ~mask;
*ptr &= mask;
}
color_index &= 3;
color_index <<= tmp;
*ptr |= color_index;
}
void u8g_pb16h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel, uint8_t is_or)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb16h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, is_or);
}
void u8g_pb16h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb16h2_SetPixel(b, arg_pixel, 0);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb16h2_Or4PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
arg_pixel->color = pixel & 0x0c0;
arg_pixel->color >>= 6;
u8g_pb16h2_SetPixel(b, arg_pixel, 1);
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 2;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb16h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
{
u8g_pb16h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
}
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb16h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg, 0);
break;
case U8G_DEV_MSG_SET_4TPIXEL:
u8g_pb16h2_Or4PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_TPIXEL:
u8g_pb16h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg, 1);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_page_First(&(pb->p));
u8g_pb16h2_Clear(pb);
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb16h2_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_GRAY2BIT;
}
return 1;
}
/*
u8g_pb16v1.c
16bit height monochrom (1 bit) page buffer
byte has vertical orientation
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb16v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
void u8g_pb16v1_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
end_ptr += b->width*2;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
/* Obsolete, usually set by the init of the structure */
void u8g_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb16v1_Clear(b);
}
void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
if ( y >= 8 )
{
ptr += b->width;
y &= 0x07;
}
mask = 1;
mask <<= y;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
}
void u8g_pb16v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb16v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb16v1_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb16v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb16v1_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb16v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb16v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb16v1_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb16v1_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb16v2.c
16 bit height 2 bit per pixel page buffer
byte has vertical orientation
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb16v2_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
/* two bits per pixel, 16 bits height --> 8 pixel --> 4 pixel per byte */
end_ptr += b->width;
end_ptr += b->width;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pb16v2Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb16v2_Clear(b);
}
void u8g_pb16v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
if ( y >= 4 )
{
ptr += b->width;
}
mask = 0x03;
y &= 0x03;
y <<= 1;
mask <<= y;
mask ^=0xff;
color_index &= 3;
color_index <<= y;
ptr += x;
*ptr &= mask;
*ptr |= color_index;
}
void u8g_pb16v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb16v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb16v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb16v2_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
{
u8g_pb16v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
}
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb16v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb16v2_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb16v2_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_GRAY2BIT;
}
return 1;
}
/*
u8g_pb32h1.c
2x 8bit height monochrom (1 bit) page buffer
byte has horizontal orientation
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
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.
total buffer size is limited to 2*256 bytes because of the calculation inside the set pixel procedure
*/
#include "u8g.h"
#include <string.h>
void u8g_pb32h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb32h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb32h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb32h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
void u8g_pb32h1_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
end_ptr += b->width*4;
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pb32h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb32h1_Clear(b);
}
/* limitation: total buffer must not exceed 2*256 bytes */
void u8g_pb32h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
uint16_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = b->width;
tmp >>= 3;
tmp *= y;
ptr += tmp;
mask = 0x080;
mask >>= x & 7;
x >>= 3;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
}
void u8g_pb32h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb32h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb32h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb32h1_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb32h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb32h1_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb32h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb32h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb32h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb32h1_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb32h1_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb8h1.c
8bit height monochrom (1 bit) page buffer
byte has horizontal orientation
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.
total buffer size is limited to 256 bytes because of the calculation inside the set pixel procedure
23. Sep 2012: Bug with down procedure, see FPS 1st page --> fixed (bug located in u8g_clip.c)
*/
#include "u8g.h"
#include <string.h>
#ifdef __unix__
#include <assert.h>
#endif
/* NEW_CODE disabled, because the performance increase was too slow and not worth compared */
/* to the increase of code size */
/* #define NEW_CODE */
#ifdef __unix__
void *u8g_buf_lower_limit;
void *u8g_buf_upper_limit;
#endif
void u8g_pb8h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb8h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb8h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb8h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
#ifdef NEW_CODE
struct u8g_pb_h1_struct
{
u8g_uint_t x;
u8g_uint_t y;
uint8_t *ptr;
uint8_t mask;
uint8_t line_byte_len;
uint8_t cnt;
};
static uint8_t u8g_pb8h1_bitmask[8] = { 0x080, 0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001 };
static void u8g_pb8h1_state_right(struct u8g_pb_h1_struct *s) U8G_NOINLINE;
static void u8g_pb8h1_state_right(struct u8g_pb_h1_struct *s)
{
register u8g_uint_t x;
x = s->x;
x++;
s->x = x;
x &= 7;
s->mask = u8g_pb8h1_bitmask[x];
if ( x == 0 )
s->ptr++;
}
static void u8g_pb8h1_state_left(struct u8g_pb_h1_struct *s)
{
register u8g_uint_t x;
x = s->x;
x--;
s->x = x;
x &= 7;
s->mask = u8g_pb8h1_bitmask[x];
if ( x == 7 )
s->ptr--;
}
static void u8g_pb8h1_state_down(struct u8g_pb_h1_struct *s)
{
s->y++;
s->ptr += s->line_byte_len;
}
static void u8g_pb8h1_state_up(struct u8g_pb_h1_struct *s)
{
s->y--;
s->ptr -= s->line_byte_len;
}
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;
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_uint_t tmp;
uint8_t *ptr = b->buf;
s->x = x;
s->y = y;
y -= b->p.page_y0;
tmp = b->width;
tmp >>= 3;
s->line_byte_len = tmp;
/* assume negative y values, can be down to -7, subtract this from the pointer and add correction of 8 to y */
ptr -= tmp*8;
y+=8;
/* it is important that the result of tmp*y can be 16 bit value also for 8 bit mode */
ptr += tmp*y;
s->mask = u8g_pb8h1_bitmask[x & 7];
/* assume negative x values (to -7), subtract 8 pixel from the pointer and add 8 to x */
ptr--;
x += 8;
x >>= 3;
ptr += x;
s->ptr = ptr;
}
static void u8g_pb8h1_state_set_pixel(struct u8g_pb_h1_struct *s, uint8_t color_index) U8G_NOINLINE;
static void u8g_pb8h1_state_set_pixel(struct u8g_pb_h1_struct *s, uint8_t color_index)
{
#ifdef __unix__
assert( s->ptr >= u8g_buf_lower_limit );
assert( s->ptr < u8g_buf_upper_limit );
#endif
if ( color_index )
{
*s->ptr |= s->mask;
}
else
{
uint8_t mask = s->mask;
mask ^=0xff;
*s->ptr &= mask;
}
}
#endif
void u8g_pb8h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb_Clear(b);
}
/* limitation: total buffer must not exceed 256 bytes */
void u8g_pb8h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
#ifdef NEW_CODE
struct u8g_pb_h1_struct s;
u8g_pb8h1_state_init(&s, b, x, y);
u8g_pb8h1_state_set_pixel(&s, color_index);
// u8g_pb8h1_state_up(&s);
// if ( s.y > b->p.page_y1 )
// return;
// if ( s.x > b->width )
// return;
// u8g_pb8h1_state_set_pixel(&s, color_index);
#else
register uint8_t mask;
u8g_uint_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = b->width;
tmp >>= 3;
tmp *= (uint8_t)y;
ptr += tmp;
mask = 0x080;
mask >>= x & 7;
x >>= 3;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
#endif
}
void u8g_pb8h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb8h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb8h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb8h1_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb8h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb8h1_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
#ifdef NEW_CODE
static void u8g_pb8h1_Set8PixelState(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
struct u8g_pb_h1_struct s;
uint8_t cnt;
u8g_pb8h1_state_init(&s, b, arg_pixel->x, arg_pixel->y);
cnt = 8;
switch( arg_pixel->dir )
{
case 0:
do
{
if ( s.x < b->width )
if ( pixel & 128 )
u8g_pb8h1_state_set_pixel(&s, arg_pixel->color);
u8g_pb8h1_state_right(&s);
pixel <<= 1;
cnt--;
} while( cnt > 0 && pixel != 0 );
break;
case 1:
do
{
if ( s.y >= b->p.page_y0 )
if ( s.y <= b->p.page_y1 )
if ( pixel & 128 )
u8g_pb8h1_state_set_pixel(&s, arg_pixel->color);
u8g_pb8h1_state_down(&s);
pixel <<= 1;
cnt--;
} while( cnt > 0 && pixel != 0 );
break;
case 2:
do
{
if ( s.x < b->width )
if ( pixel & 128 )
u8g_pb8h1_state_set_pixel(&s, arg_pixel->color);
u8g_pb8h1_state_left(&s);
pixel <<= 1;
cnt--;
} while( cnt > 0 && pixel != 0 );
break;
case 3:
do
{
if ( s.y >= b->p.page_y0 )
if ( s.y <= b->p.page_y1 )
if ( pixel & 128 )
u8g_pb8h1_state_set_pixel(&s, arg_pixel->color);
u8g_pb8h1_state_up(&s);
pixel <<= 1;
cnt--;
} while( cnt > 0 && pixel != 0 );
break;
}
}
#endif
uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
#ifdef NEW_CODE
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb8h1_Set8PixelState(pb, (u8g_dev_arg_pixel_t *)arg);
#else
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb8h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
#endif
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb8h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb8h1f.c
8bit height monochrom (1 bit) page buffer
byte has horizontal orientation, same as u8g_pb8h1, but byte is flipped
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.
total buffer size is limited to 256 bytes because of the calculation inside the set pixel procedure
*/
#include "u8g.h"
#include <string.h>
void u8g_pb8h1f_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb8h1f_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb8h1f_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb8h1f_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
void u8g_pb8h1f_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb_Clear(b);
}
/* limitation: total buffer must not exceed 256 bytes, 20 nov 2012: extended to >256 bytes */
void u8g_pb8h1f_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
/*register uint8_t mask, tmp;*/
register uint8_t mask;
register u8g_uint_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = b->width >> 3;
tmp *= (uint8_t)y;
ptr += tmp;
mask = 1;
mask <<= x & 7;
x >>= 3;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
}
void u8g_pb8h1f_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb8h1f_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb8h1f_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb8h1f_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb8h1f_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb8h1f_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb8h1f_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb8h1f_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb8h2.c
8bit height 2 bit per pixel page buffer
byte has horizontal orientation
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb8h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb_Clear(b);
}
static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
register uint16_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = b->width;
tmp >>= 2;
tmp *= (uint8_t)y;
ptr += tmp;
tmp = x;
tmp >>= 2;
ptr += tmp;
tmp = x;
tmp &= 3;
tmp <<= 1;
mask = 3;
mask <<= tmp;
mask = ~mask;
color_index &= 3;
color_index <<= tmp;
*ptr &= mask;
*ptr |= color_index;
}
void u8g_pb8h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb8h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb8h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb8h2_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
{
u8g_pb8h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
}
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb8h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_GRAY2BIT;
}
return 1;
}
/*
u8g_pb8h8.c
8 lines per page, horizontal, 8 bits per pixel
(22 May 2013: might also support any number of lines --> needs to be checked)
Universal 8bit Graphics Library
Copyright (c) 2012, olikraus@gmail.com
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.
struct _u8g_pb_t
{
u8g_page_t p;
u8g_uint_t width;
void *buf;
};
typedef struct _u8g_pb_t u8g_pb_t;
uint8_t u8g_index_color_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
u8g_pb_t u8g_index_color_8h8_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_8h8_buff};
u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn }
*/
#include "u8g.h"
/*
#define WIDTH_BITS 7
#define WIDTH (1<<WIDTH_BITS)
#define PAGE_HEIGHT_BITS 3
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
*/
void u8g_pb8h8_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
uint8_t cnt = b->p.page_height;
end_ptr += b->width*cnt;
/*
do
{
end_ptr += b->width;
cnt--;
} while( cnt > 0 );
*/
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pb8h8_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb8h8_Clear(b);
}
static void u8g_pb8h8_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
uint16_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = y;
tmp *= b->width;
tmp += x;
ptr += tmp;
*ptr = color_index;
}
void u8g_pb8h8_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb8h8_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb8h8_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb8h8_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb8h8_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb8h8_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb8h8_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb8h8_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_R3G3B2;
}
return 1;
}
/*
u8g_pb8v1.c
8bit height monochrom (1 bit) page buffer
byte has vertical orientation
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
/* Obsolete, usually set by the init of the structure */
void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb_Clear(b);
}
void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
mask = 1;
y &= 0x07;
mask <<= y;
ptr += x;
if ( color_index )
{
*ptr |= mask;
}
else
{
mask ^=0xff;
*ptr &= mask;
}
}
void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb8v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb8v1_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pb8v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pb8v1_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pb8v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb8v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_BW;
}
return 1;
}
/*
u8g_pb8v2.c
8bit height 2 bit per pixel page buffer
byte has vertical orientation
Universal 8bit Graphics Library
Copyright (c) 2011, olikraus@gmail.com
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.h"
#include <string.h>
void u8g_pb8v2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pb_Clear(b);
}
void u8g_pb8v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
{
register uint8_t mask;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
mask = 0x03;
y &= 0x03;
y <<= 1;
mask <<= y;
mask ^=0xff;
color_index &= 3;
color_index <<= y;
ptr += x;
*ptr &= mask;
*ptr |= color_index;
}
void u8g_pb8v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pb8v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
}
void u8g_pb8v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
do
{
if ( pixel & 128 )
{
u8g_pb8v2_SetPixel(b, arg_pixel);
}
switch( arg_pixel->dir )
{
case 0: arg_pixel->x++; break;
case 1: arg_pixel->y++; break;
case 2: arg_pixel->x--; break;
case 3: arg_pixel->y--; break;
}
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
{
u8g_pb8v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
}
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pb8v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pb_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pb_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_GRAY2BIT;
}
return 1;
}
/*
u8g_pbxh16.c
x lines per page, horizontal, 16 bits per pixel (hi color modes)
Universal 8bit Graphics Library
Copyright (c) 2013, olikraus@gmail.com
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.
struct _u8g_pb_t
{
u8g_page_t p;
u8g_uint_t width;
void *buf;
};
typedef struct _u8g_pb_t u8g_pb_t;
uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
*/
#include "u8g.h"
/*
#define WIDTH_BITS 7
#define WIDTH (1<<WIDTH_BITS)
#define PAGE_HEIGHT_BITS 3
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
*/
void u8g_pbxh16_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
uint8_t cnt = b->p.page_height;
do
{
end_ptr += b->width*2;
cnt--;
} while( cnt > 0 );
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pbxh16_Clear(b);
}
static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high)
{
uint16_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = y;
tmp *= b->width;
tmp += x;
tmp <<= 1;
ptr += tmp;
*ptr = low;
ptr++;
*ptr = high;
}
void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color);
}
void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pbxh16_SetPixel(b, arg_pixel);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pbxh16_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pbxh16_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_HICOLOR;
}
return 1;
}
/*
u8g_pbxh24.c
x lines per page, horizontal, 24 bits per pixel (true color modes)
Universal 8bit Graphics Library
Copyright (c) 2013, olikraus@gmail.com
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.
struct _u8g_pb_t
{
u8g_page_t p;
u8g_uint_t width;
void *buf;
};
typedef struct _u8g_pb_t u8g_pb_t;
uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
*/
#include "u8g.h"
/*
#define WIDTH_BITS 7
#define WIDTH (1<<WIDTH_BITS)
#define PAGE_HEIGHT_BITS 3
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
*/
void u8g_pbxh24_Clear(u8g_pb_t *b)
{
uint8_t *ptr = (uint8_t *)b->buf;
uint8_t *end_ptr = ptr;
uint8_t cnt = b->p.page_height;
do
{
end_ptr += b->width*3;
cnt--;
} while( cnt > 0 );
do
{
*ptr++ = 0;
} while( ptr != end_ptr );
}
void u8g_pbxh24_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
{
b->buf = buf;
b->width = width;
u8g_pbxh24_Clear(b);
}
#ifdef OBSOLETE
static void u8g_pbxh24_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t r, uint8_t g, uint8_t b)
{
uint16_t tmp;
uint8_t *ptr = b->buf;
y -= b->p.page_y0;
tmp = y;
tmp *= b->width;
tmp += x;
tmp *= 3;
ptr += tmp;
*ptr = r;
ptr++;
*ptr = g;
ptr++;
*ptr = b;
}
#endif
/*
intensity
0..3 intensity value
4 replace color
*/
static void u8g_pbxh24_set_tpixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t red, uint8_t green, uint8_t blue, uint8_t intensity)
{
uint16_t tmp;
uint8_t *ptr = b->buf;
if ( intensity == 0 )
return;
y -= b->p.page_y0;
tmp = y;
tmp *= b->width;
tmp += x;
tmp *= 3;
ptr += tmp;
if ( intensity == 4 )
{
*ptr = red;
ptr++;
*ptr = green;
ptr++;
*ptr = blue;
return;
}
if ( intensity == 2 )
{
/*
red = red/4 + red/2;
green = green/4 + green/2;
blue = blue/4 + blue/2;
*/
red >>= 1;
green >>= 1;
blue >>= 1;
}
else if ( intensity == 1 )
{
red >>= 2;
green >>= 2;
blue >>= 2;
}
if ( *ptr >= 255-red ) *ptr = 255;
else *ptr += red;
ptr++;
if ( *ptr >= 255-green ) *ptr = 255;
else *ptr += green;
ptr++;
if ( *ptr >= 255-blue ) *ptr = 255;
else *ptr += blue;
/*
if ( *ptr < red ) *ptr = red;
ptr++;
if ( *ptr < green ) *ptr = green;
ptr++;
if ( *ptr < blue ) *ptr = blue;
*/
}
void u8g_pbxh24_SetTPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel, uint8_t intensity)
{
if ( arg_pixel->y < b->p.page_y0 )
return;
if ( arg_pixel->y > b->p.page_y1 )
return;
if ( arg_pixel->x >= b->width )
return;
u8g_pbxh24_set_tpixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color, arg_pixel->blue, intensity);
}
void u8g_pbxh24_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
if ( pixel & 128 )
u8g_pbxh24_SetTPixel(b, arg_pixel, 4);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 1;
} while( pixel != 0 );
}
void u8g_pbxh24_Set4TPixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
{
register uint8_t pixel = arg_pixel->pixel;
u8g_uint_t dx = 0;
u8g_uint_t dy = 0;
switch( arg_pixel->dir )
{
case 0: dx++; break;
case 1: dy++; break;
case 2: dx--; break;
case 3: dy--; break;
}
do
{
u8g_pbxh24_SetTPixel(b, arg_pixel, pixel >> 6);
arg_pixel->x += dx;
arg_pixel->y += dy;
pixel <<= 2;
} while( pixel != 0 );
}
uint8_t u8g_dev_pbxh24_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
switch(msg)
{
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
u8g_pbxh24_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_PIXEL:
u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, 4);
break;
case U8G_DEV_MSG_SET_4TPIXEL:
u8g_pbxh24_Set4TPixel(pb, (u8g_dev_arg_pixel_t *)arg);
break;
case U8G_DEV_MSG_SET_TPIXEL:
u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, ((u8g_dev_arg_pixel_t *)arg)->pixel&3);
break;
case U8G_DEV_MSG_INIT:
break;
case U8G_DEV_MSG_STOP:
break;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_pbxh24_Clear(pb);
u8g_page_First(&(pb->p));
break;
case U8G_DEV_MSG_PAGE_NEXT:
if ( u8g_page_Next(&(pb->p)) == 0 )
return 0;
u8g_pbxh24_Clear(pb);
break;
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
#endif
case U8G_DEV_MSG_GET_PAGE_BOX:
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = pb->width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = pb->p.total_height;
break;
case U8G_DEV_MSG_SET_COLOR_ENTRY:
break;
case U8G_DEV_MSG_SET_XY_CB:
break;
case U8G_DEV_MSG_GET_MODE:
return U8G_MODE_TRUECOLOR;
}
return 1;
}
/*
u8g_polygon.c
Implementation of a polygon draw algorithm for "convex" polygons.
Universal 8bit Graphics Library
Copyright (c) 2013, olikraus@gmail.com
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.
See also:
http://www.angelfire.com/linux/myp/ConvexPolRas/ConvexPolRas.html
Computer Graphics, Principles and Practice, Foley, van Dam, Feiner, Hughes (pp 92)
Michael Abrash's Graphics Programming Black Book, Special Edition (Chapter 38 and 39)
Optimized for embedded systems
- static memory usage only
- consistent data types
- low flash ROM consumption
*/
#include "u8g.h"
/*===========================================*/
/* procedures, which should not be inlined (save as much flash ROM as possible */
static uint8_t pge_Next(struct pg_edge_struct *pge) PG_NOINLINE;
static uint8_t pg_inc(pg_struct *pg, uint8_t i) PG_NOINLINE;
static uint8_t pg_dec(pg_struct *pg, uint8_t i) PG_NOINLINE;
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx) PG_NOINLINE;
static void pg_line_init(pg_struct * const pg, uint8_t pge_index) PG_NOINLINE;
/*===========================================*/
/* line draw algorithm */
static uint8_t pge_Next(struct pg_edge_struct *pge)
{
if ( pge->current_y >= pge->max_y )
return 0;
pge->current_x += pge->current_x_offset;
pge->error += pge->error_offset;
if ( pge->error > 0 )
{
pge->current_x += pge->x_direction;
pge->error -= pge->height;
}
pge->current_y++;
return 1;
}
/* assumes y2 > y1 */
static void pge_Init(struct pg_edge_struct *pge, pg_word_t x1, pg_word_t y1, pg_word_t x2, pg_word_t y2)
{
pg_word_t dx = x2 - x1;
pg_word_t width;
pge->height = y2 - y1;
pge->max_y = y2;
pge->current_y = y1;
pge->current_x = x1;
if ( dx >= 0 )
{
pge->x_direction = 1;
width = dx;
pge->error = 0;
}
else
{
pge->x_direction = -1;
width = -dx;
pge->error = 1 - pge->height;
}
pge->current_x_offset = dx / pge->height;
pge->error_offset = width % pge->height;
}
/*===========================================*/
/* convex polygon algorithm */
static uint8_t pg_inc(pg_struct *pg, uint8_t i)
{
i++;
if ( i >= pg->cnt )
i = 0;
return i;
}
static uint8_t pg_dec(pg_struct *pg, uint8_t i)
{
i--;
if ( i >= pg->cnt )
i = pg->cnt-1;
return i;
}
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx)
{
uint8_t i = pg->pge[pge_idx].curr_idx;
for(;;)
{
i = pg->pge[pge_idx].next_idx_fn(pg, i);
if ( pg->list[i].y != min_y )
break;
pg->pge[pge_idx].curr_idx = i;
}
}
static uint8_t pg_prepare(pg_struct *pg)
{
pg_word_t max_y;
pg_word_t min_y;
uint8_t i;
/* setup the next index procedures */
pg->pge[PG_RIGHT].next_idx_fn = pg_inc;
pg->pge[PG_LEFT].next_idx_fn = pg_dec;
/* search for highest and lowest point */
max_y = pg->list[0].y;
min_y = pg->list[0].y;
pg->pge[PG_LEFT].curr_idx = 0;
for( i = 1; i < pg->cnt; i++ )
{
if ( max_y < pg->list[i].y )
{
max_y = pg->list[i].y;
}
if ( min_y > pg->list[i].y )
{
pg->pge[PG_LEFT].curr_idx = i;
min_y = pg->list[i].y;
}
}
/* calculate total number of scan lines */
pg->total_scan_line_cnt = max_y;
pg->total_scan_line_cnt -= min_y;
/* exit if polygon height is zero */
if ( pg->total_scan_line_cnt == 0 )
return 0;
/* if the minimum y side is flat, try to find the lowest and highest x points */
pg->pge[PG_RIGHT].curr_idx = pg->pge[PG_LEFT].curr_idx;
pg_expand_min_y(pg, min_y, PG_RIGHT);
pg_expand_min_y(pg, min_y, PG_LEFT);
/* check if the min side is really flat (depends on the x values) */
pg->is_min_y_not_flat = 1;
if ( pg->list[pg->pge[PG_LEFT].curr_idx].x != pg->list[pg->pge[PG_RIGHT].curr_idx].x )
{
pg->is_min_y_not_flat = 0;
}
else
{
pg->total_scan_line_cnt--;
if ( pg->total_scan_line_cnt == 0 )
return 0;
}
return 1;
}
static void pg_hline(pg_struct *pg, u8g_t *u8g)
{
pg_word_t x1, x2, y;
x1 = pg->pge[PG_LEFT].current_x;
x2 = pg->pge[PG_RIGHT].current_x;
y = pg->pge[PG_RIGHT].current_y;
if ( y < 0 )
return;
if ( y >= u8g_GetHeight(u8g) )
return;
if ( x1 < x2 )
{
if ( x2 < 0 )
return;
if ( x1 >= u8g_GetWidth(u8g) )
return;
if ( x1 < 0 )
x1 = 0;
if ( x2 >= u8g_GetWidth(u8g) )
x2 = u8g_GetWidth(u8g);
u8g_DrawHLine(u8g, x1, y, x2 - x1);
}
else
{
if ( x1 < 0 )
return;
if ( x2 >= u8g_GetWidth(u8g) )
return;
if ( x2 < 0 )
x1 = 0;
if ( x1 >= u8g_GetWidth(u8g) )
x1 = u8g_GetWidth(u8g);
u8g_DrawHLine(u8g, x2, y, x1 - x2);
}
}
static void pg_line_init(pg_struct * pg, uint8_t pge_index)
{
struct pg_edge_struct *pge = pg->pge+pge_index;
uint8_t idx;
pg_word_t x1;
pg_word_t y1;
pg_word_t x2;
pg_word_t y2;
idx = pge->curr_idx;
y1 = pg->list[idx].y;
x1 = pg->list[idx].x;
idx = pge->next_idx_fn(pg, idx);
y2 = pg->list[idx].y;
x2 = pg->list[idx].x;
pge->curr_idx = idx;
pge_Init(pge, x1, y1, x2, y2);
}
static void pg_exec(pg_struct *pg, u8g_t *u8g)
{
pg_word_t i = pg->total_scan_line_cnt;
/* first line is skipped if the min y line is not flat */
pg_line_init(pg, PG_LEFT);
pg_line_init(pg, PG_RIGHT);
if ( pg->is_min_y_not_flat != 0 )
{
pge_Next(&(pg->pge[PG_LEFT]));
pge_Next(&(pg->pge[PG_RIGHT]));
}
do
{
pg_hline(pg, u8g);
while ( pge_Next(&(pg->pge[PG_LEFT])) == 0 )
{
pg_line_init(pg, PG_LEFT);
}
while ( pge_Next(&(pg->pge[PG_RIGHT])) == 0 )
{
pg_line_init(pg, PG_RIGHT);
}
i--;
} while( i > 0 );
}
/*===========================================*/
/* API procedures */
void pg_ClearPolygonXY(pg_struct *pg)
{
pg->cnt = 0;
}
void pg_AddPolygonXY(pg_struct *pg, u8g_t *u8g, int16_t x, int16_t y)
{
if ( pg->cnt < PG_MAX_POINTS )
{
pg->list[pg->cnt].x = x;
pg->list[pg->cnt].y = y;
pg->cnt++;
}
}
void pg_DrawPolygon(pg_struct *pg, u8g_t *u8g)
{
if ( pg_prepare(pg) == 0 )
return;
pg_exec(pg, u8g);
}
//pg_struct u8g_pg;
void u8g_ClearPolygonXY(u8g_t *u8g)
{
pg_ClearPolygonXY(&(u8g->pg));
}
void u8g_AddPolygonXY(u8g_t *u8g, int16_t x, int16_t y)
{
pg_AddPolygonXY(&(u8g->pg), u8g, x, y);
}
void u8g_DrawPolygon(u8g_t *u8g)
{
pg_DrawPolygon(&(u8g->pg), u8g);
}
void u8g_DrawTriangle(u8g_t *u8g, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
{
u8g_ClearPolygonXY(u8g);
u8g_AddPolygonXY(u8g, x0, y0);
u8g_AddPolygonXY(u8g, x1, y1);
u8g_AddPolygonXY(u8g, x2, y2);
u8g_DrawPolygon(u8g);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment