Commit b440b686 authored by devsaurus's avatar devsaurus
Browse files

u8glib v1.17

parent 33601462
/*
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(void)
{
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_AddPolygonXY(u8g, x0, y0);
u8g_AddPolygonXY(u8g, x1, y1);
u8g_AddPolygonXY(u8g, x2, y2);
u8g_DrawPolygon(u8g);
}
/*
u8g_rect.c
U8G high level interface for horizontal and vertical things
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_draw_hline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
{
uint8_t pixel = 0x0ff;
while( w >= 8 )
{
u8g_Draw8Pixel(u8g, x, y, 0, pixel);
w-=8;
x+=8;
}
if ( w != 0 )
{
w ^=7;
w++;
pixel <<= w&7;
u8g_Draw8Pixel(u8g, x, y, 0, pixel);
}
}
void u8g_draw_vline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t h)
{
uint8_t pixel = 0x0ff;
while( h >= 8 )
{
u8g_Draw8Pixel(u8g, x, y, 1, pixel);
h-=8;
y+=8;
}
if ( h != 0 )
{
h ^=7;
h++;
pixel <<= h&7;
u8g_Draw8Pixel(u8g, x, y, 1, pixel);
}
}
void u8g_DrawHLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
{
if ( u8g_IsBBXIntersection(u8g, x, y, w, 1) == 0 )
return;
u8g_draw_hline(u8g, x, y, w);
}
void u8g_DrawVLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
{
if ( u8g_IsBBXIntersection(u8g, x, y, 1, w) == 0 )
return;
u8g_draw_vline(u8g, x, y, w);
}
/* restrictions: w > 0 && h > 0 */
void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
{
u8g_uint_t xtmp = x;
if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
return;
u8g_draw_hline(u8g, x, y, w);
u8g_draw_vline(u8g, x, y, h);
x+=w;
x--;
u8g_draw_vline(u8g, x, y, h);
y+=h;
y--;
u8g_draw_hline(u8g, xtmp, y, w);
}
void u8g_draw_box(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
{
do
{
u8g_draw_hline(u8g, x, y, w);
y++;
h--;
} while( h != 0 );
}
/* restrictions: h > 0 */
void u8g_DrawBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
{
if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
return;
u8g_draw_box(u8g, x, y, w, h);
}
void u8g_DrawRFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
{
u8g_uint_t xl, yu;
if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
return;
xl = x;
xl += r;
yu = y;
yu += r;
{
u8g_uint_t yl, xr;
xr = x;
xr += w;
xr -= r;
xr -= 1;
yl = y;
yl += h;
yl -= r;
yl -= 1;
u8g_draw_circle(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
u8g_draw_circle(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
u8g_draw_circle(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
u8g_draw_circle(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
}
{
u8g_uint_t ww, hh;
ww = w;
ww -= r;
ww -= r;
ww -= 2;
hh = h;
hh -= r;
hh -= r;
hh -= 2;
xl++;
yu++;
h--;
w--;
u8g_draw_hline(u8g, xl, y, ww);
u8g_draw_hline(u8g, xl, y+h, ww);
u8g_draw_vline(u8g, x, yu, hh);
u8g_draw_vline(u8g, x+w, yu, hh);
}
}
void u8g_DrawRBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
{
u8g_uint_t xl, yu;
u8g_uint_t yl, xr;
if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
return;
xl = x;
xl += r;
yu = y;
yu += r;
xr = x;
xr += w;
xr -= r;
xr -= 1;
yl = y;
yl += h;
yl -= r;
yl -= 1;
u8g_draw_disc(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
u8g_draw_disc(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
u8g_draw_disc(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
u8g_draw_disc(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
{
u8g_uint_t ww, hh;
ww = w;
ww -= r;
ww -= r;
ww -= 2;
hh = h;
hh -= r;
hh -= r;
hh -= 2;
xl++;
yu++;
h--;
u8g_draw_box(u8g, xl, y, ww, r+1);
u8g_draw_box(u8g, xl, yl, ww, r+1);
//u8g_draw_hline(u8g, xl, y+h, ww);
u8g_draw_box(u8g, x, yu, w, hh);
//u8g_draw_vline(u8g, x+w, yu, hh);
}
}
/*
u8g_rot.c
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"
uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
uint8_t u8g_dev_rot_dummy_fn(void *u8g, void *dev, uint8_t msg, void *arg)
{
return 0;
}
u8g_dev_t u8g_dev_rot = { u8g_dev_rot_dummy_fn, NULL, NULL };
void u8g_UndoRotation(u8g_t *u8g)
{
if ( u8g->dev != &u8g_dev_rot )
return;
u8g->dev = u8g_dev_rot.dev_mem;
u8g_UpdateDimension(u8g);
}
void u8g_SetRot90(u8g_t *u8g)
{
if ( u8g->dev != &u8g_dev_rot )
{
u8g_dev_rot.dev_mem = u8g->dev;
u8g->dev = &u8g_dev_rot;
}
u8g_dev_rot.dev_fn = u8g_dev_rot90_fn;
u8g_UpdateDimension(u8g);
}
void u8g_SetRot180(u8g_t *u8g)
{
if ( u8g->dev != &u8g_dev_rot )
{
u8g_dev_rot.dev_mem = u8g->dev;
u8g->dev = &u8g_dev_rot;
}
u8g_dev_rot.dev_fn = u8g_dev_rot180_fn;
u8g_UpdateDimension(u8g);
}
void u8g_SetRot270(u8g_t *u8g)
{
if ( u8g->dev != &u8g_dev_rot )
{
u8g_dev_rot.dev_mem = u8g->dev;
u8g->dev = &u8g_dev_rot;
}
u8g_dev_rot.dev_fn = u8g_dev_rot270_fn;
u8g_UpdateDimension(u8g);
}
uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_dev_t *rotation_chain = (u8g_dev_t *)(dev->dev_mem);
switch(msg)
{
default:
/*
case U8G_DEV_MSG_INIT:
case U8G_DEV_MSG_STOP:
case U8G_DEV_MSG_PAGE_FIRST:
case U8G_DEV_MSG_PAGE_NEXT:
case U8G_DEV_MSG_SET_COLOR_ENTRY:
case U8G_DEV_MSG_SET_XY_CB:
*/
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
{
u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
u8g_uint_t x, y, tmp;
/* transform the reference point */
y = bbx->x;
x = u8g->height;
/* x = u8g_GetWidthLL(u8g, rotation_chain); */
x -= bbx->y;
x--;
/* adjust point to be the uppler left corner again */
x -= bbx->h;
x++;
/* swap box dimensions */
tmp = bbx->w;
bbx->w = bbx->h;
bbx->h = tmp;
/* store x,y */
bbx->x = x;
bbx->y = y;
}
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
#endif /* U8G_DEV_MSG_IS_BBX_INTERSECTION */
case U8G_DEV_MSG_GET_PAGE_BOX:
/* get page size from next device in the chain */
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
//printf("pre x: %3d..%3d y: %3d..%3d ", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
{
u8g_box_t new_box;
//new_box.x0 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y1 - 1;
//new_box.x1 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y0 - 1;
new_box.x0 = ((u8g_box_t *)arg)->y0;
new_box.x1 = ((u8g_box_t *)arg)->y1;
new_box.y0 = ((u8g_box_t *)arg)->x0;
new_box.y1 = ((u8g_box_t *)arg)->x1;
*((u8g_box_t *)arg) = new_box;
//printf("post x: %3d..%3d y: %3d..%3d\n", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
}
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g,rotation_chain);
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, rotation_chain);
break;
case U8G_DEV_MSG_SET_PIXEL:
case U8G_DEV_MSG_SET_TPIXEL:
{
u8g_uint_t x, y;
y = ((u8g_dev_arg_pixel_t *)arg)->x;
x = u8g_GetWidthLL(u8g, rotation_chain);
x -= ((u8g_dev_arg_pixel_t *)arg)->y;
x--;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
}
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
break;
case U8G_DEV_MSG_SET_8PIXEL:
case U8G_DEV_MSG_SET_4TPIXEL:
{
u8g_uint_t x, y;
//uint16_t x,y;
y = ((u8g_dev_arg_pixel_t *)arg)->x;
x = u8g_GetWidthLL(u8g, rotation_chain);
x -= ((u8g_dev_arg_pixel_t *)arg)->y;
x--;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
((u8g_dev_arg_pixel_t *)arg)->dir+=1;
((u8g_dev_arg_pixel_t *)arg)->dir &= 3;
}
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
break;
}
return 1;
}
uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_dev_t *rotation_chain = (u8g_dev_t *)(dev->dev_mem);
switch(msg)
{
default:
/*
case U8G_DEV_MSG_INIT:
case U8G_DEV_MSG_STOP:
case U8G_DEV_MSG_PAGE_FIRST:
case U8G_DEV_MSG_PAGE_NEXT:
case U8G_DEV_MSG_SET_COLOR_ENTRY:
case U8G_DEV_MSG_SET_XY_CB:
*/
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
{
u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
u8g_uint_t x, y;
/* transform the reference point */
//y = u8g_GetHeightLL(u8g, rotation_chain);
y = u8g->height;
y -= bbx->y;
y--;
//x = u8g_GetWidthLL(u8g, rotation_chain);
x = u8g->width;
x -= bbx->x;
x--;
/* adjust point to be the uppler left corner again */
y -= bbx->h;
y++;
x -= bbx->w;
x++;
/* store x,y */
bbx->x = x;
bbx->y = y;
}
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
#endif /* U8G_DEV_MSG_IS_BBX_INTERSECTION */
case U8G_DEV_MSG_GET_PAGE_BOX:
/* get page size from next device in the chain */
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
//printf("pre x: %3d..%3d y: %3d..%3d ", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
{
u8g_box_t new_box;
new_box.x0 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x1 - 1;
new_box.x1 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x0 - 1;
new_box.y0 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y1 - 1;
new_box.y1 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y0 - 1;
*((u8g_box_t *)arg) = new_box;
//printf("post x: %3d..%3d y: %3d..%3d\n", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
}
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g,rotation_chain);
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g, rotation_chain);
break;
case U8G_DEV_MSG_SET_PIXEL:
case U8G_DEV_MSG_SET_TPIXEL:
{
u8g_uint_t x, y;
y = u8g_GetHeightLL(u8g, rotation_chain);
y -= ((u8g_dev_arg_pixel_t *)arg)->y;
y--;
x = u8g_GetWidthLL(u8g, rotation_chain);
x -= ((u8g_dev_arg_pixel_t *)arg)->x;
x--;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
}
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
break;
case U8G_DEV_MSG_SET_8PIXEL:
case U8G_DEV_MSG_SET_4TPIXEL:
{
u8g_uint_t x, y;
y = u8g_GetHeightLL(u8g, rotation_chain);
y -= ((u8g_dev_arg_pixel_t *)arg)->y;
y--;
x = u8g_GetWidthLL(u8g, rotation_chain);
x -= ((u8g_dev_arg_pixel_t *)arg)->x;
x--;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
((u8g_dev_arg_pixel_t *)arg)->dir+=2;
((u8g_dev_arg_pixel_t *)arg)->dir &= 3;
}
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
break;
}
return 1;
}
uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_dev_t *rotation_chain = (u8g_dev_t *)(dev->dev_mem);
switch(msg)
{
default:
/*
case U8G_DEV_MSG_INIT:
case U8G_DEV_MSG_STOP:
case U8G_DEV_MSG_PAGE_FIRST:
case U8G_DEV_MSG_PAGE_NEXT:
case U8G_DEV_MSG_SET_COLOR_ENTRY:
case U8G_DEV_MSG_SET_XY_CB:
*/
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
{
u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
u8g_uint_t x, y, tmp;
/* transform the reference point */
x = bbx->y;
y = u8g->width;
/* y = u8g_GetHeightLL(u8g, rotation_chain); */
y -= bbx->x;
y--;
/* adjust point to be the uppler left corner again */
y -= bbx->w;
y++;
/* swap box dimensions */
tmp = bbx->w;
bbx->w = bbx->h;
bbx->h = tmp;
/* store x,y */
bbx->x = x;
bbx->y = y;
}
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
#endif /* U8G_DEV_MSG_IS_BBX_INTERSECTION */
case U8G_DEV_MSG_GET_PAGE_BOX:
/* get page size from next device in the chain */
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
//printf("pre x: %3d..%3d y: %3d..%3d ", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
{
u8g_box_t new_box;
new_box.x0 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y1 - 1;
new_box.x1 = u8g_GetHeightLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->y0 - 1;
new_box.y0 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x1 - 1;
new_box.y1 = u8g_GetWidthLL(u8g,rotation_chain) - ((u8g_box_t *)arg)->x0 - 1;
*((u8g_box_t *)arg) = new_box;
//printf("post x: %3d..%3d y: %3d..%3d\n", ((u8g_box_t *)arg)->x0, ((u8g_box_t *)arg)->x1, ((u8g_box_t *)arg)->y0, ((u8g_box_t *)arg)->y1);
}
break;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g,rotation_chain);
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, rotation_chain);
break;
case U8G_DEV_MSG_SET_PIXEL:
case U8G_DEV_MSG_SET_TPIXEL:
{
u8g_uint_t x, y;
x = ((u8g_dev_arg_pixel_t *)arg)->y;
y = u8g_GetHeightLL(u8g, rotation_chain);
y -= ((u8g_dev_arg_pixel_t *)arg)->x;
y--;
/*
x = u8g_GetWidthLL(u8g, rotation_chain);
x -= ((u8g_dev_arg_pixel_t *)arg)->y;
x--;
*/
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
}
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
break;
case U8G_DEV_MSG_SET_8PIXEL:
case U8G_DEV_MSG_SET_4TPIXEL:
{
u8g_uint_t x, y;
x = ((u8g_dev_arg_pixel_t *)arg)->y;
y = u8g_GetHeightLL(u8g, rotation_chain);
y -= ((u8g_dev_arg_pixel_t *)arg)->x;
y--;
/*
x = u8g_GetWidthLL(u8g, rotation_chain);
x -= ((u8g_dev_arg_pixel_t *)arg)->y;
x--;
*/
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
((u8g_dev_arg_pixel_t *)arg)->dir+=3;
((u8g_dev_arg_pixel_t *)arg)->dir &= 3;
}
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
break;
}
return 1;
}
/*
u8g_scale.c
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.
Scale screen by some constant factors. Usefull for making bigger fonts wiht less
memory consumption
*/
#include "u8g.h"
uint8_t u8g_dev_scale_2x2_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
u8g_dev_t u8g_dev_scale = { u8g_dev_scale_2x2_fn, NULL, NULL };
void u8g_UndoScale(u8g_t *u8g)
{
if ( u8g->dev != &u8g_dev_scale )
return;
u8g->dev = u8g_dev_scale.dev_mem;
u8g_UpdateDimension(u8g);
}
void u8g_SetScale2x2(u8g_t *u8g)
{
if ( u8g->dev != &u8g_dev_scale )
{
u8g_dev_scale.dev_mem = u8g->dev;
u8g->dev = &u8g_dev_scale;
}
u8g_dev_scale.dev_fn = u8g_dev_scale_2x2_fn;
u8g_UpdateDimension(u8g);
}
uint8_t u8g_dev_scale_2x2_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
u8g_dev_t *chain = (u8g_dev_t *)(dev->dev_mem);
uint8_t pixel;
uint16_t scaled_pixel;
uint8_t i;
uint8_t dir;
u8g_uint_t x, y, xx,yy;
switch(msg)
{
default:
return u8g_call_dev_fn(u8g, chain, msg, arg);
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, chain) / 2;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g, chain) / 2;
break;
case U8G_DEV_MSG_GET_PAGE_BOX:
/* get page size from next device in the chain */
u8g_call_dev_fn(u8g, chain, msg, arg);
((u8g_box_t *)arg)->x0 /= 2;
((u8g_box_t *)arg)->x1 /= 2;
((u8g_box_t *)arg)->y0 /= 2;
((u8g_box_t *)arg)->y1 /= 2;
return 1;
case U8G_DEV_MSG_SET_PIXEL:
x = ((u8g_dev_arg_pixel_t *)arg)->x;
x *= 2;
y = ((u8g_dev_arg_pixel_t *)arg)->y;
y *= 2;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
u8g_call_dev_fn(u8g, chain, msg, arg);
x++;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
u8g_call_dev_fn(u8g, chain, msg, arg);
y++;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
u8g_call_dev_fn(u8g, chain, msg, arg);
x--;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
u8g_call_dev_fn(u8g, chain, msg, arg);
break;
case U8G_DEV_MSG_SET_8PIXEL:
pixel = ((u8g_dev_arg_pixel_t *)arg)->pixel;
dir = ((u8g_dev_arg_pixel_t *)arg)->dir;
scaled_pixel = 0;
for( i = 0; i < 8; i++ )
{
scaled_pixel<<=2;
if ( pixel & 128 )
{
scaled_pixel |= 3;
}
pixel<<=1;
}
x = ((u8g_dev_arg_pixel_t *)arg)->x;
x *= 2;
xx = x;
y = ((u8g_dev_arg_pixel_t *)arg)->y;
y *= 2;
yy = y;
if ( ((u8g_dev_arg_pixel_t *)arg)->dir & 1 )
{
xx++;
}
else
{
yy++;
}
((u8g_dev_arg_pixel_t *)arg)->pixel = scaled_pixel>>8;
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
((u8g_dev_arg_pixel_t *)arg)->dir = dir;
u8g_call_dev_fn(u8g, chain, msg, arg);
((u8g_dev_arg_pixel_t *)arg)->x = xx;
((u8g_dev_arg_pixel_t *)arg)->y = yy;
((u8g_dev_arg_pixel_t *)arg)->dir = dir;
u8g_call_dev_fn(u8g, chain, msg, arg);
((u8g_dev_arg_pixel_t *)arg)->pixel = scaled_pixel&255;
//((u8g_dev_arg_pixel_t *)arg)->pixel = 0x00;
switch(dir)
{
case 0:
x+=8;
xx+=8;
break;
case 1:
y+=8;
yy+=8;
break;
case 2:
x-=8;
xx-=8;
break;
case 3:
y-=8;
yy-=8;
break;
}
((u8g_dev_arg_pixel_t *)arg)->x = x;
((u8g_dev_arg_pixel_t *)arg)->y = y;
((u8g_dev_arg_pixel_t *)arg)->dir = dir;
u8g_call_dev_fn(u8g, chain, msg, arg);
((u8g_dev_arg_pixel_t *)arg)->x = xx;
((u8g_dev_arg_pixel_t *)arg)->y = yy;
((u8g_dev_arg_pixel_t *)arg)->dir = dir;
u8g_call_dev_fn(u8g, chain, msg, arg);
break;
}
return 1;
}
/*
u8g_state.c
backup and restore hardware state
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.
state callback: backup env U8G_STATE_MSG_BACKUP_ENV
device callback: DEV_MSG_INIT
state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G
state callback: restore env U8G_STATE_MSG_RESTORE_ENV
state callback: backup env U8G_STATE_MSG_BACKUP_ENV
state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G
DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT
state callback: restore env U8G_STATE_MSG_RESTORE_ENV
*/
#include <stddef.h>
#include "u8g.h"
void u8g_state_dummy_cb(uint8_t msg)
{
/* the dummy procedure does nothing */
}
void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb)
{
u8g->state_cb = backup_cb;
/* in most cases the init message was already sent, so this will backup the */
/* current u8g state */
backup_cb(U8G_STATE_MSG_BACKUP_U8G);
}
/*===============================================================*/
/* register variable for restoring interrupt state */
#if defined(__AVR__)
uint8_t global_SREG_backup;
#endif
/*===============================================================*/
/* AVR */
#if defined(__AVR__)
#define U8G_ATMEGA_HW_SPI
/* remove the definition for attiny */
#if __AVR_ARCH__ == 2
#undef U8G_ATMEGA_HW_SPI
#endif
#if __AVR_ARCH__ == 25
#undef U8G_ATMEGA_HW_SPI
#endif
#endif
#if defined(U8G_ATMEGA_HW_SPI)
#include <avr/interrupt.h>
static uint8_t u8g_state_avr_spi_memory[2];
void u8g_backup_spi(uint8_t msg)
{
if ( U8G_STATE_MSG_IS_BACKUP(msg) )
{
u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR;
}
else
{
uint8_t tmp = SREG;
cli();
SPCR = 0;
SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)];
SREG = tmp;
}
}
#elif defined (U8G_RASPBERRY_PI)
#include <stdio.h>
void u8g_backup_spi(uint8_t msg) {
printf("u8g_backup_spi %d\r\n",msg);
}
#elif defined(ARDUINO) && defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__
#include "sam.h"
struct sam_backup_struct
{
uint32_t mr;
uint32_t sr;
uint32_t csr[4];
} sam_backup[2];
void u8g_backup_spi(uint8_t msg)
{
uint8_t idx = U8G_STATE_MSG_GET_IDX(msg);
if ( U8G_STATE_MSG_IS_BACKUP(msg) )
{
sam_backup[idx].mr = SPI0->SPI_MR;
sam_backup[idx].sr = SPI0->SPI_SR;
sam_backup[idx].csr[0] = SPI0->SPI_CSR[0];
sam_backup[idx].csr[1] = SPI0->SPI_CSR[1];
sam_backup[idx].csr[2] = SPI0->SPI_CSR[2];
sam_backup[idx].csr[3] = SPI0->SPI_CSR[3];
}
else
{
SPI0->SPI_MR = sam_backup[idx].mr;
SPI0->SPI_CSR[0] = sam_backup[idx].csr[0];
SPI0->SPI_CSR[1] = sam_backup[idx].csr[1];
SPI0->SPI_CSR[2] = sam_backup[idx].csr[2];
SPI0->SPI_CSR[3] = sam_backup[idx].csr[3];
}
}
#else
void u8g_backup_spi(uint8_t msg)
{
}
#endif
/*
u8g_u16toa.c
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"
const char *u8g_u16toap(char * dest, uint16_t v)
{
uint8_t pos;
uint8_t d;
uint16_t c;
c = 10000;
for( pos = 0; pos < 5; pos++ )
{
d = '0';
while( v >= c )
{
v -= c;
d++;
}
dest[pos] = d;
c /= 10;
}
dest[5] = '\0';
return dest;
}
/* v = value, d = number of digits */
const char *u8g_u16toa(uint16_t v, uint8_t d)
{
static char buf[6];
d = 5-d;
return u8g_u16toap(buf, v) + d;
}
/*
u8g_u8toa.c
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"
static const unsigned char u8g_u8toa_tab[3] = { 100, 10, 1 } ;
const char *u8g_u8toap(char * dest, uint8_t v)
{
uint8_t pos;
uint8_t d;
uint8_t c;
for( pos = 0; pos < 3; pos++ )
{
d = '0';
c = *(u8g_u8toa_tab+pos);
while( v >= c )
{
v -= c;
d++;
}
dest[pos] = d;
}
dest[3] = '\0';
return dest;
}
/* v = value, d = number of digits */
const char *u8g_u8toa(uint8_t v, uint8_t d)
{
static char buf[4];
d = 3-d;
return u8g_u8toap(buf, v) + d;
}
/*
u8g_virtual_screen.c
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"
struct _u8g_vs_t
{
u8g_uint_t x;
u8g_uint_t y;
u8g_t *u8g;
};
typedef struct _u8g_vs_t u8g_vs_t;
#define U8g_VS_MAX 4
uint8_t u8g_vs_cnt = 0;
u8g_vs_t u8g_vs_list[U8g_VS_MAX];
uint8_t u8g_vs_current;
u8g_uint_t u8g_vs_width;
u8g_uint_t u8g_vs_height;
uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
switch(msg)
{
default:
{
uint8_t i;
for( i = 0; i < u8g_vs_cnt; i++ )
{
u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg);
}
}
return 1;
case U8G_DEV_MSG_PAGE_FIRST:
u8g_vs_current = 0;
if ( u8g_vs_cnt != 0 )
return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg);
return 0;
case U8G_DEV_MSG_PAGE_NEXT:
{
uint8_t ret = 0;
if ( u8g_vs_cnt != 0 )
ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg);
if ( ret != 0 )
return ret;
u8g_vs_current++; /* next device */
if ( u8g_vs_current >= u8g_vs_cnt ) /* reached end? */
return 0;
return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, U8G_DEV_MSG_PAGE_FIRST, arg);
}
return 0;
case U8G_DEV_MSG_GET_WIDTH:
*((u8g_uint_t *)arg) = u8g_vs_width;
break;
case U8G_DEV_MSG_GET_HEIGHT:
*((u8g_uint_t *)arg) = u8g_vs_height;
break;
case U8G_DEV_MSG_GET_PAGE_BOX:
if ( u8g_vs_current < u8g_vs_cnt )
{
u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg);
((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x;
((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x;
((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y;
((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y;
}
else
{
((u8g_box_t *)arg)->x0 = 0;
((u8g_box_t *)arg)->x1 = 0;
((u8g_box_t *)arg)->y0 = 0;
((u8g_box_t *)arg)->y1 = 0;
}
return 1;
case U8G_DEV_MSG_SET_PIXEL:
case U8G_DEV_MSG_SET_8PIXEL:
if ( u8g_vs_current < u8g_vs_cnt )
{
((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x;
((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y;
return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg);
}
break;
}
return 1;
}
u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL };
void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height)
{
if ( vs_u8g->dev != &u8g_dev_vs )
return; /* abort if there is no a virtual screen device */
u8g_vs_width = width;
u8g_vs_height = height;
}
uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g)
{
if ( vs_u8g->dev != &u8g_dev_vs )
return 0; /* abort if there is no a virtual screen device */
if ( u8g_vs_cnt >= U8g_VS_MAX )
return 0; /* maximum number of child u8g's reached */
u8g_vs_list[u8g_vs_cnt].u8g = child_u8g;
u8g_vs_list[u8g_vs_cnt].x = x;
u8g_vs_list[u8g_vs_cnt].y = y;
u8g_vs_cnt++;
return 1;
}
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