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
/*
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(u8g_t *u8g, u8g_dev_t *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;
}
...@@ -5,7 +5,7 @@ MEMORY ...@@ -5,7 +5,7 @@ MEMORY
dport0_0_seg : org = 0x3FF00000, len = 0x10 dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000 dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000 iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x54000 irom0_0_seg : org = 0x40210000, len = 0x55000
} }
PHDRS PHDRS
...@@ -71,6 +71,10 @@ SECTIONS ...@@ -71,6 +71,10 @@ SECTIONS
_irom0_text_start = ABSOLUTE(.); _irom0_text_start = ABSOLUTE(.);
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
*(.literal.* .text.*) *(.literal.* .text.*)
/* put font and progmem data into irom0 */
*(.u8g_progmem.*)
_irom0_text_end = ABSOLUTE(.); _irom0_text_end = ABSOLUTE(.);
_flash_used_end = ABSOLUTE(.); _flash_used_end = ABSOLUTE(.);
} >irom0_0_seg :irom0_0_phdr } >irom0_0_seg :irom0_0_phdr
......
---
-- @description Shows how to read 8 GPIO pins/buttons via I2C with the MCP23008 I/O expander.
-- Tested on NodeMCU 0.9.5 build 20150213.
-- @circuit
-- Connect GPIO0 of the ESP8266-01 module to the SCL pin of the MCP23008.
-- Connect GPIO2 of the ESP8266-01 module to the SDA pin of the MCP23008.
-- Use 3.3V for VCC.
-- Connect switches or buttons to the GPIOs of the MCP23008 and GND.
-- Connect two 4.7k pull-up resistors on SDA and SCL
-- We will enable the internal pull up resistors for the GPIOS of the MCP23008.
-- @author Miguel (AllAboutEE)
-- GitHub: https://github.com/AllAboutEE
-- YouTube: https://www.youtube.com/user/AllAboutEE
-- Website: http://AllAboutEE.com
---------------------------------------------------------------------------------------------
require ("mcp23008")
-- ESP-01 GPIO Mapping as per GPIO Table in https://github.com/nodemcu/nodemcu-firmware
gpio0, gpio2 = 3, 4
-- Setup the MCP23008
mcp23008.begin(0x0,gpio2,gpio0,i2c.SLOW)
mcp23008.writeIODIR(0xff)
mcp23008.writeGPPU(0xff)
---
-- @name showButtons
-- @description Shows the state of each GPIO pin
-- @return void
---------------------------------------------------------
function showButtons()
local gpio = mcp23008.readGPIO() -- read the GPIO/buttons states
-- get/extract the state of one pin at a time
for pin=0,7 do
local pinState = bit.band(bit.rshift(gpio,pin),0x1) -- extract one pin state
-- change to string state (HIGH, LOW) instead of 1 or 0 respectively
if(pinState == mcp23008.HIGH) then
pinState = "HIGH"
else
pinState = "LOW"
end
print("Pin ".. pin .. ": ".. pinState)
end
print("\r\n")
end
tmr.alarm(0,2000,1,showButtons) -- run showButtons() every 2 seconds
---
-- @description Shows control of 8 GPIO pins/LEDs via I2C with the MCP23008 I/O expander.
-- Tested on odeMCU 0.9.5 build 20150213.
-- @date March 02, 2015
-- @circuit Connect 8 LEDs withs resistors to the GPIO pins of the MCP23008.
-- Connect GPIO0 of the ESP8266-01 module to the SCL pin of the MCP23008.
-- Connect GPIO2 of the ESP8266-01 module to the SDA pin of the MCP23008.
-- Connect two 4.7k pull-up resistors on SDA and SCL
-- Use 3.3V for VCC.
-- @author Miguel (AllAboutEE)
-- GitHub: https://github.com/AllAboutEE
-- Working Example Video: https://www.youtube.com/watch?v=KphAJMZZed0
-- Website: http://AllAboutEE.com
---------------------------------------------------------------------------------------------
require ("mcp23008")
-- ESP-01 GPIO Mapping as per GPIO Table in https://github.com/nodemcu/nodemcu-firmware
gpio0, gpio2 = 3, 4
-- Setup MCP23008
mcp23008.begin(0x0,gpio2,gpio0,i2c.SLOW)
mcp23008.writeIODIR(0x00) -- make all GPIO pins as outputs
mcp23008.writeGPIO(0x00) -- make all GIPO pins off/low
---
-- @name count()
-- @description Reads the value from the GPIO register, increases the read value by 1
-- and writes it back so the LEDs will display a binary count up to 255 or 0xFF in hex.
local function count()
local gpio = 0x00
gpio = mcp23008.readGPIO()
if(gpio<0xff) then
mcp23008.writeGPIO(gpio+1)
else
mcp23008.writeGPIO(0x00)
end
end
-- Run count() every 100ms
tmr.alarm(0,100,1,count)
-- setup I2c and connect display
function init_i2c_display()
sda = 5
scl = 6
sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
end
-- graphic test components
function prepare()
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end
function box_frame(a)
disp:drawStr(0, 0, "drawBox")
disp:drawBox(5, 10, 20, 10)
disp:drawBox(10+a, 15, 30, 7)
disp:drawStr(0, 30, "drawFrame")
disp:drawFrame(5, 10+30, 20, 10)
disp:drawFrame(10+a, 15+30, 30, 7)
end
function disc_circle(a)
disp:drawStr(0, 0, "drawDisc")
disp:drawDisc(10, 18, 9)
disp:drawDisc(24+a, 16, 7)
disp:drawStr(0, 30, "drawCircle")
disp:drawCircle(10, 18+30, 9)
disp:drawCircle(24+a, 16+30, 7)
end
function r_frame(a)
disp:drawStr(0, 0, "drawRFrame/Box")
disp:drawRFrame(5, 10, 40, 30, a+1)
disp:drawRBox(50, 10, 25, 40, a+1)
end
function stringtest(a)
disp:drawStr(30+a, 31, " 0")
disp:drawStr90(30, 31+a, " 90")
disp:drawStr180(30-a, 31, " 180")
disp:drawStr270(30, 31-a, " 270")
end
function line(a)
disp:drawStr(0, 0, "drawLine")
disp:drawLine(7+a, 10, 40, 55)
disp:drawLine(7+a*2, 10, 60, 55)
disp:drawLine(7+a*3, 10, 80, 55)
disp:drawLine(7+a*4, 10, 100, 55)
end
function triangle(a)
local offset = a
disp:drawStr(0, 0, "drawTriangle")
disp:drawTriangle(14,7, 45,30, 10,40)
disp:drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset)
disp:drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53)
disp:drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset)
end
function ascii_1()
local x, y, s
disp:drawStr(0, 0, "ASCII page 1")
for y = 0, 5, 1 do
for x = 0, 15, 1 do
s = y*16 + x + 32
disp:drawStr(x*7, y*10+10, string.char(s))
end
end
end
function ascii_2()
local x, y, s
disp:drawStr(0, 0, "ASCII page 2")
for y = 0, 5, 1 do
for x = 0, 15, 1 do
s = y*16 + x + 160
disp:drawStr(x*7, y*10+10, string.char(s))
end
end
end
function extra_page(a)
disp:drawStr(0, 12, "setScale2x2")
disp:setScale2x2()
disp:drawStr(0, 6+a, "setScale2x2")
disp:undoScale()
end
-- the draw() routine
function draw(draw_state)
local component = bit.rshift(draw_state, 3)
prepare()
if (component == 0) then
box_frame(bit.band(draw_state, 7))
elseif (component == 1) then
disc_circle(bit.band(draw_state, 7))
elseif (component == 2) then
r_frame(bit.band(draw_state, 7))
elseif (component == 3) then
stringtest(bit.band(draw_state, 7))
elseif (component == 4) then
line(bit.band(draw_state, 7))
elseif (component == 5) then
triangle(bit.band(draw_state, 7))
elseif (component == 6) then
ascii_1()
elseif (component == 7) then
ascii_2()
elseif (component == 8) then
extra_page(bit.band(draw_state, 7))
end
end
function graphics_test()
init_i2c_display()
print("--- Starting Graphics Test ---")
-- cycle through all components
local draw_state
for draw_state = 0, 7 + 8*8, 1 do
disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false
--print(node.heap())
-- re-trigger Watchdog!
tmr.wdclr()
end
print("--- Graphics Test done ---")
end
graphics_test()
-- setup I2c and connect display
function init_i2c_display()
sda = 5
scl = 6
sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
end
-- the draw() routine
function draw()
disp:setFont(u8g.font_6x10)
disp:drawStr( 0+0, 20+0, "Hello!")
disp:drawStr( 0+2, 20+16, "Hello!")
disp:drawBox(0, 0, 3, 3)
disp:drawBox(disp:getWidth()-6, 0, 6, 6)
disp:drawBox(disp:getWidth()-9, disp:getHeight()-9, 9, 9)
disp:drawBox(0, disp:getHeight()-12, 12, 12)
end
function rotate()
if (next_rotation < tmr.now() / 1000) then
if (dir == 0) then
disp:undoRotation()
elseif (dir == 1) then
disp:setRot90()
elseif (dir == 2) then
disp:setRot180()
elseif (dir == 3) then
disp:setRot270()
end
dir = dir + 1
dir = bit.band(dir, 3)
next_rotation = tmr.now() / 1000 + 1000
end
end
function rotation_test()
init_i2c_display()
print("--- Starting Rotation Test ---")
dir = 0
next_rotation = 0
local loopcnt
for loopcnt = 1, 100, 1 do
rotate()
disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false
tmr.wdclr()
end
print("--- Rotation Test done ---")
end
rotation_test()
---
-- @description Expands the ESP8266's GPIO to 8 more I/O pins via I2C with the MCP23008 I/O Expander
-- MCP23008 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf
-- Tested on NodeMCU 0.9.5 build 20150213.
-- @date March 02, 2015
-- @author Miguel
-- GitHub: https://github.com/AllAboutEE
-- YouTube: https://www.youtube.com/user/AllAboutEE
-- Website: http://AllAboutEE.com
--------------------------------------------------------------------------------
local moduleName = ...
local M = {}
_G[moduleName] = M
-- Constant device address.
local MCP23008_ADDRESS = 0x20
-- Registers' address as defined in the MCP23008's datashseet
local MCP23008_IODIR = 0x00
local MCP23008_IPOL = 0x01
local MCP23008_GPINTEN = 0x02
local MCP23008_DEFVAL = 0x03
local MCP23008_INTCON = 0x04
local MCP23008_IOCON = 0x05
local MCP23008_GPPU = 0x06
local MCP23008_INTF = 0x07
local MCP23008_INTCAP = 0x08
local MCP23008_GPIO = 0x09
local MCP23008_OLAT = 0x0A
-- Default value for i2c communication
local id = 0
-- pin modes for I/O direction
M.INPUT = 1
M.OUTPUT = 0
-- pin states for I/O i.e. on/off
M.HIGH = 1
M.LOW = 0
-- Weak pull-up resistor state
M.ENABLE = 1
M.DISABLE = 0
---
-- @name write
-- @description Writes one byte to a register
-- @param registerAddress The register where we'll write data
-- @param data The data to write to the register
-- @return void
----------------------------------------------------------
local function write(registerAddress, data)
i2c.start(id)
i2c.address(id,MCP23008_ADDRESS,i2c.TRANSMITTER) -- send MCP's address and write bit
i2c.write(id,registerAddress)
i2c.write(id,data)
i2c.stop(id)
end
---
-- @name read
-- @description Reads the value of a regsiter
-- @param registerAddress The reigster address from which to read
-- @return The byte stored in the register
----------------------------------------------------------
local function read(registerAddress)
-- Tell the MCP which register you want to read from
i2c.start(id)
i2c.address(id,MCP23008_ADDRESS,i2c.TRANSMITTER) -- send MCP's address and write bit
i2c.write(id,registerAddress)
i2c.stop(id)
i2c.start(id)
-- Read the data form the register
i2c.address(id,MCP23008_ADDRESS,i2c.RECEIVER) -- send the MCP's address and read bit
local data = 0x00
data = i2c.read(id,1) -- we expect only one byte of data
i2c.stop(id)
return string.byte(data) -- i2c.read returns a string so we convert to it's int value
end
---
--! @name begin
--! @description Sets the MCP23008 device address's last three bits.
-- Note: The address is defined as binary 0100[A2][A1][A0] where
-- A2, A1, and A0 are defined by the connection of the pins,
-- e.g. if the pins are connected all to GND then the paramter address
-- will need to be 0x0.
-- @param address The 3 least significant bits (LSB) of the address
-- @param pinSDA The pin to use for SDA
-- @param pinSCL The pin to use for SCL
-- @param speed The speed of the I2C signal
-- @return void
---------------------------------------------------------------------------
function M.begin(address,pinSDA,pinSCL,speed)
MCP23008_ADDRESS = bit.bor(MCP23008_ADDRESS,address)
i2c.setup(id,pinSDA,pinSCL,speed)
end
---
-- @name writeGPIO
-- @description Writes a byte of data to the GPIO register
-- @param dataByte The byte of data to write
-- @return void
----------------------------------------------------------
function M.writeGPIO(dataByte)
write(MCP23008_GPIO,dataByte)
end
---
-- @name readGPIO
-- @description reads a byte of data from the GPIO register
-- @return One byte of data
----------------------------------------------------------
function M.readGPIO()
return read(MCP23008_GPIO)
end
---
-- @name writeIODIR
-- @description Writes one byte of data to the IODIR register
-- @param dataByte The byte of data to write
-- @return void
----------------------------------------------------------
function M.writeIODIR(dataByte)
write(MCP23008_IODIR,dataByte)
end
---
-- @name readIODIR
-- @description Reads a byte from the IODIR register
-- @return The byte of data in IODIR
----------------------------------------------------------
function M.readIODIR()
return read(MCP23008_IODIR)
end
---
-- @name writeGPPU The byte to write to the GPPU
-- @description Writes a byte of data to the
-- PULL-UP RESISTOR CONFIGURATION (GPPU)REGISTER
-- @param databyte the value to write to the GPPU register.
-- each bit in this byte is assigned to an individual GPIO pin
-- @return void
----------------------------------------------------------------
function M.writeGPPU(dataByte)
write(MCP23008_GPPU,dataByte)
end
---
-- @name readGPPU
-- @description Reads the GPPU (Pull-UP resistors register) byte
-- @return The GPPU byte i.e. state of all internal pull-up resistors
-------------------------------------------------------------------
function M.readGPPU()
return read(MCP23008_GPPU)
end
return M
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