Commit 6dc0dfc0 authored by devsaurus's avatar devsaurus
Browse files
parent f5ae0ed7
......@@ -33,6 +33,7 @@ SUBDIRS= \
coap \
mqtt \
u8glib \
ucglib \
smart \
wofs \
modules \
......@@ -85,6 +86,7 @@ COMPONENTS_eagle.app.v6 = \
coap/coap.a \
mqtt/mqtt.a \
u8glib/u8glib.a \
ucglib/ucglib.a \
smart/smart.a \
wofs/wofs.a \
spiffs/spiffs.a \
......
......@@ -29,6 +29,7 @@
#define LUA_USE_MODULES_MQTT
#define LUA_USE_MODULES_COAP
#define LUA_USE_MODULES_U8G
#define LUA_USE_MODULES_UCG
// #define LUA_USE_MODULES_WS2801
#define LUA_USE_MODULES_WS2812
#define LUA_USE_MODULES_CJSON
......
......@@ -42,6 +42,7 @@ INCLUDES += -I ../libc
INCLUDES += -I ../coap
INCLUDES += -I ../mqtt
INCLUDES += -I ../u8glib
INCLUDES += -I ../ucglib
INCLUDES += -I ../lua
INCLUDES += -I ../platform
INCLUDES += -I ../wofs
......
......@@ -70,6 +70,9 @@ LUALIB_API int ( luaopen_mqtt )( lua_State *L );
#define AUXLIB_U8G "u8g"
LUALIB_API int ( luaopen_u8g )( lua_State *L );
#define AUXLIB_UCG "ucg"
LUALIB_API int ( luaopen_ucg )( lua_State *L );
#define AUXLIB_NODE "node"
LUALIB_API int ( luaopen_node )( lua_State *L );
......
......@@ -61,6 +61,14 @@
#define ROM_MODULES_U8G
#endif
#if defined(LUA_USE_MODULES_UCG)
#define MODULES_UCG "ucg"
#define ROM_MODULES_UCG \
_ROM(MODULES_UCG, luaopen_ucg, lucg_map)
#else
#define ROM_MODULES_UCG
#endif
#if defined(LUA_USE_MODULES_I2C)
#define MODULES_I2C "i2c"
#define ROM_MODULES_I2C \
......
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = ucglib.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../libc
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
This diff is collapsed.
/*
ucg_bitmap.c
Universal uC Color 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.
*/
#include "ucg.h"
#ifdef UCG_MSG_DRAW_L90TC
void ucg_DrawTransparentBitmapLine(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t dir, ucg_int_t len, const unsigned char *bitmap)
{
ucg->arg.pixel.rgb.color[0] = ucg->arg.rgb[0].color[0];
ucg->arg.pixel.rgb.color[1] = ucg->arg.rgb[0].color[1];
ucg->arg.pixel.rgb.color[2] = ucg->arg.rgb[0].color[2];
ucg->arg.pixel.pos.x = x;
ucg->arg.pixel.pos.y = y;
ucg->arg.dir = dir;
ucg->arg.len = len;
ucg->arg.bitmap = bitmap;
ucg->arg.pixel_skip = 0;
ucg_DrawL90TCWithArg(ucg);
}
#endif /* UCG_MSG_DRAW_L90TC */
#ifdef UCG_MSG_DRAW_L90BF
void ucg_DrawBitmapLine(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t dir, ucg_int_t len, const unsigned char *bitmap)
{
/*
ucg->arg.pixel.rgb.color[0] = ucg->arg.rgb[0].color[0];
ucg->arg.pixel.rgb.color[1] = ucg->arg.rgb[0].color[1];
ucg->arg.pixel.rgb.color[2] = ucg->arg.rgb[0].color[2];
*/
ucg->arg.pixel.pos.x = x;
ucg->arg.pixel.pos.y = y;
ucg->arg.dir = dir;
ucg->arg.len = len;
ucg->arg.bitmap = bitmap;
ucg->arg.pixel_skip = 0;
//ucg->arg.scale = 0;
ucg_DrawL90BFWithArg(ucg);
}
#endif /* UCG_MSG_DRAW_L90BF */
#ifdef ON_HOLD
void ucg_DrawRLBitmap(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t dir, const unsigned char *rl_bitmap)
{
ucg->arg.pixel.rgb.color[0] = ucg->arg.rgb[0].color[0];
ucg->arg.pixel.rgb.color[1] = ucg->arg.rgb[0].color[1];
ucg->arg.pixel.rgb.color[2] = ucg->arg.rgb[0].color[2];
ucg->arg.pixel.pos.x = x;
ucg->arg.pixel.pos.y = y;
ucg->arg.dir = dir;
ucg->arg.len = 0;
ucg->arg.bitmap = rl_bitmap;
ucg_DrawL90RLWithArg(ucg);
}
#endif
/*
ucg_box.c
Universal uC Color 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.
*/
#include "ucg.h"
void ucg_DrawBox(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
{
while( h > 0 )
{
ucg_DrawHLine(ucg, x, y, w);
h--;
y++;
}
}
/*
- clear the screen with black color
- reset clip range to max
- set draw color to white
*/
void ucg_ClearScreen(ucg_t *ucg)
{
ucg_SetColor(ucg, 0, 0, 0, 0);
ucg_SetMaxClipRange(ucg);
ucg_DrawBox(ucg, 0, 0, ucg_GetWidth(ucg), ucg_GetHeight(ucg));
ucg_SetColor(ucg, 0, 255, 255, 255);
}
void ucg_DrawRBox(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h, ucg_int_t r)
{
ucg_int_t xl, yu;
ucg_int_t yl, xr;
xl = x;
xl += r;
yu = y;
yu += r;
xr = x;
xr += w;
xr -= r;
xr -= 1;
yl = y;
yl += h;
yl -= r;
yl -= 1;
ucg_DrawDisc(ucg, xl, yu, r, UCG_DRAW_UPPER_LEFT);
ucg_DrawDisc(ucg, xr, yu, r, UCG_DRAW_UPPER_RIGHT);
ucg_DrawDisc(ucg, xl, yl, r, UCG_DRAW_LOWER_LEFT);
ucg_DrawDisc(ucg, xr, yl, r, UCG_DRAW_LOWER_RIGHT);
{
ucg_int_t ww, hh;
ww = w;
ww -= r;
ww -= r;
ww -= 2;
hh = h;
hh -= r;
hh -= r;
hh -= 2;
xl++;
yu++;
h--;
ucg_DrawBox(ucg, xl, y, ww, r+1);
ucg_DrawBox(ucg, xl, yl, ww, r+1);
ucg_DrawBox(ucg, x, yu, w, hh);
}
}
ucg_ccs_t ucg_ccs_box[6]; /* color component sliders used by GradientBox */
void ucg_DrawGradientBox(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
{
uint8_t i;
/* Setup ccs for l90se. This will be updated by ucg_clip_l90se if required */
/* 8. Jan 2014: correct? */
//printf("%d %d %d\n", ucg->arg.rgb[3].color[0], ucg->arg.rgb[3].color[1], ucg->arg.rgb[3].color[2]);
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg_ccs_box+i, ucg->arg.rgb[0].color[i], ucg->arg.rgb[2].color[i], h);
ucg_ccs_init(ucg_ccs_box+i+3, ucg->arg.rgb[1].color[i], ucg->arg.rgb[3].color[i], h);
}
while( h > 0 )
{
ucg->arg.rgb[0].color[0] = ucg_ccs_box[0].current;
ucg->arg.rgb[0].color[1] = ucg_ccs_box[1].current;
ucg->arg.rgb[0].color[2] = ucg_ccs_box[2].current;
ucg->arg.rgb[1].color[0] = ucg_ccs_box[3].current;
ucg->arg.rgb[1].color[1] = ucg_ccs_box[4].current;
ucg->arg.rgb[1].color[2] = ucg_ccs_box[5].current;
//printf("%d %d %d\n", ucg_ccs_box[0].current, ucg_ccs_box[1].current, ucg_ccs_box[2].current);
//printf("%d %d %d\n", ucg_ccs_box[3].current, ucg_ccs_box[4].current, ucg_ccs_box[5].current);
ucg->arg.pixel.pos.x = x;
ucg->arg.pixel.pos.y = y;
ucg->arg.len = w;
ucg->arg.dir = 0;
ucg_DrawL90SEWithArg(ucg);
for ( i = 0; i < 6; i++ )
ucg_ccs_step(ucg_ccs_box+i);
h--;
y++;
}
}
/* restrictions: w > 0 && h > 0 */
void ucg_DrawFrame(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
{
ucg_int_t xtmp = x;
ucg_DrawHLine(ucg, x, y, w);
ucg_DrawVLine(ucg, x, y, h);
x+=w;
x--;
ucg_DrawVLine(ucg, x, y, h);
y+=h;
y--;
ucg_DrawHLine(ucg, xtmp, y, w);
}
void ucg_DrawRFrame(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h, ucg_int_t r)
{
ucg_int_t xl, yu;
xl = x;
xl += r;
yu = y;
yu += r;
{
ucg_int_t yl, xr;
xr = x;
xr += w;
xr -= r;
xr -= 1;
yl = y;
yl += h;
yl -= r;
yl -= 1;
ucg_DrawCircle(ucg, xl, yu, r, UCG_DRAW_UPPER_LEFT);
ucg_DrawCircle(ucg, xr, yu, r, UCG_DRAW_UPPER_RIGHT);
ucg_DrawCircle(ucg, xl, yl, r, UCG_DRAW_LOWER_LEFT);
ucg_DrawCircle(ucg, xr, yl, r, UCG_DRAW_LOWER_RIGHT);
}
{
ucg_int_t ww, hh;
ww = w;
ww -= r;
ww -= r;
ww -= 2;
hh = h;
hh -= r;
hh -= r;
hh -= 2;
xl++;
yu++;
h--;
w--;
ucg_DrawHLine(ucg, xl, y, ww);
ucg_DrawHLine(ucg, xl, y+h, ww);
ucg_DrawVLine(ucg, x, yu, hh);
ucg_DrawVLine(ucg, x+w, yu, hh);
}
}
/*
ucg_ccs.c
color component slide sub library
Universal uC Color 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.
e: end
n: steps
f(0) = s
f(n) = e
f(x) = m*x + s
f(n-1) = m*(n-1) + s =!= e
--> m = (e-s)/n
f(x) = (e-s)/(n-1) * x + s
f(0) = s
f(1) = s + (e-s)/(n-1)
*/
#include "ucg.h"
/*
Setup change from "start" to "end" with a specified amount of "steps".
After calling this procedure, ccs->current will contain the "start" value.
*/
void ucg_ccs_init(ucg_ccs_t *ccs, uint8_t start, uint8_t end, ucg_int_t steps)
{
ccs->start = start;
ccs->num = end-start;
ccs->den = steps-1;
ccs->dir = 1;
ccs->quot = ccs->num / ccs->den;
if ( ccs->num < 0 )
{
ccs->num = -ccs->num;
ccs->dir = -1;
}
ccs->rem = ccs->num % ccs->den;
ccs->frac = ccs->den/2;
ccs->current = start;
}
/*
Make one step towards the "end" value.
ccs->curront will contain the updated value.
*/
void ucg_ccs_step(ucg_ccs_t *ccs)
{
ccs->current += ccs->quot;
ccs->frac += ccs->rem;
if ( ccs->frac >= ccs->den )
{
ccs->current += ccs->dir;
ccs->frac -= ccs->den;
}
}
/*
f(x) = (e-s)/(n-1) * x + s
current = (num / den) * (pos / den)
Seek to the specified "pos"ition.
"pos" must be between 0 and "end"-1
*/
void ucg_ccs_seek(ucg_ccs_t *ccs, ucg_int_t pos)
{
ucg_int_t p;
ccs->current = ccs->quot;
ccs->current *= pos;
p = ccs->rem * pos + ccs->den/2;
if ( ccs->dir >= 0 )
ccs->current += p / ccs->den;
else
ccs->current -= p / ccs->den;
ccs->frac = p % ccs->den;
ccs->current += ccs->start;
}
/*
ucg_circle.c
Circle Drawing Procedures
Universal uC Color Graphics Library
Copyright (c) 2014, 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 "ucg.h"
static void ucg_draw_circle_section(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t x0, ucg_int_t y0, uint8_t option) UCG_NOINLINE;
static void ucg_draw_circle_section(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t x0, ucg_int_t y0, uint8_t option)
{
/* upper right */
if ( option & UCG_DRAW_UPPER_RIGHT )
{
ucg_DrawPixel(ucg, x0 + x, y0 - y);
ucg_DrawPixel(ucg, x0 + y, y0 - x);
}
/* upper left */
if ( option & UCG_DRAW_UPPER_LEFT )
{
ucg_DrawPixel(ucg, x0 - x, y0 - y);
ucg_DrawPixel(ucg, x0 - y, y0 - x);
}
/* lower right */
if ( option & UCG_DRAW_LOWER_RIGHT )
{
ucg_DrawPixel(ucg, x0 + x, y0 + y);
ucg_DrawPixel(ucg, x0 + y, y0 + x);
}
/* lower left */
if ( option & UCG_DRAW_LOWER_LEFT )
{
ucg_DrawPixel(ucg, x0 - x, y0 + y);
ucg_DrawPixel(ucg, x0 - y, y0 + x);
}
}
void ucg_draw_circle(ucg_t *ucg, ucg_int_t x0, ucg_int_t y0, ucg_int_t rad, uint8_t option)
{
ucg_int_t f;
ucg_int_t ddF_x;
ucg_int_t ddF_y;
ucg_int_t x;
ucg_int_t y;
f = 1;
f -= rad;
ddF_x = 1;
ddF_y = 0;
ddF_y -= rad;
ddF_y *= 2;
x = 0;
y = rad;
ucg_draw_circle_section(ucg, x, y, x0, y0, option);
while ( x < y )
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
ucg_draw_circle_section(ucg, x, y, x0, y0, option);
}
}
void ucg_DrawCircle(ucg_t *ucg, ucg_int_t x0, ucg_int_t y0, ucg_int_t rad, uint8_t option)
{
/* check for bounding box */
/*
{
ucg_int_t radp, radp2;
radp = rad;
radp++;
radp2 = radp;
radp2 *= 2;
if ( ucg_IsBBXIntersection(ucg, x0-radp, y0-radp, radp2, radp2) == 0)
return;
}
*/
/* draw circle */
ucg_draw_circle(ucg, x0, y0, rad, option);
}
static void ucg_draw_disc_section(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t x0, ucg_int_t y0, uint8_t option) UCG_NOINLINE;
static void ucg_draw_disc_section(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t x0, ucg_int_t y0, uint8_t option)
{
/* upper right */
if ( option & UCG_DRAW_UPPER_RIGHT )
{
ucg_DrawVLine(ucg, x0+x, y0-y, y+1);
ucg_DrawVLine(ucg, x0+y, y0-x, x+1);
}
/* upper left */
if ( option & UCG_DRAW_UPPER_LEFT )
{
ucg_DrawVLine(ucg, x0-x, y0-y, y+1);
ucg_DrawVLine(ucg, x0-y, y0-x, x+1);
}
/* lower right */
if ( option & UCG_DRAW_LOWER_RIGHT )
{
ucg_DrawVLine(ucg, x0+x, y0, y+1);
ucg_DrawVLine(ucg, x0+y, y0, x+1);
}
/* lower left */
if ( option & UCG_DRAW_LOWER_LEFT )
{
ucg_DrawVLine(ucg, x0-x, y0, y+1);
ucg_DrawVLine(ucg, x0-y, y0, x+1);
}
}
void ucg_draw_disc(ucg_t *ucg, ucg_int_t x0, ucg_int_t y0, ucg_int_t rad, uint8_t option)
{
ucg_int_t f;
ucg_int_t ddF_x;
ucg_int_t ddF_y;
ucg_int_t x;
ucg_int_t y;
f = 1;
f -= rad;
ddF_x = 1;
ddF_y = 0;
ddF_y -= rad;
ddF_y *= 2;
x = 0;
y = rad;
ucg_draw_disc_section(ucg, x, y, x0, y0, option);
while ( x < y )
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
ucg_draw_disc_section(ucg, x, y, x0, y0, option);
}
}
void ucg_DrawDisc(ucg_t *ucg, ucg_int_t x0, ucg_int_t y0, ucg_int_t rad, uint8_t option)
{
/* check for bounding box */
/*
{
ucg_int_t radp, radp2;
radp = rad;
radp++;
radp2 = radp;
radp2 *= 2;
if ( ucg_IsBBXIntersection(ucg, x0-radp, y0-radp, radp2, radp2) == 0)
return;
}
*/
/* draw disc */
ucg_draw_disc(ucg, x0, y0, rad, option);
}
/*
ucg_clip.c
Clipping procedures for the device funktions
Universal uC Color 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.
*/
#include "ucg.h"
static ucg_int_t ucg_clip_is_x_visible(ucg_t *ucg) UCG_NOINLINE;
static ucg_int_t ucg_clip_is_y_visible(ucg_t *ucg) UCG_NOINLINE;
static ucg_int_t ucg_clip_is_x_visible(ucg_t *ucg)
{
ucg_int_t t;
t = ucg->arg.pixel.pos.x;
t -= ucg->clip_box.ul.x;
if ( t < 0 )
return 0;
if ( t >= ucg->clip_box.size.w )
return 0;
return 1;
}
static ucg_int_t ucg_clip_is_y_visible(ucg_t *ucg)
{
ucg_int_t t;
t = ucg->arg.pixel.pos.y;
t -= ucg->clip_box.ul.y;
if ( t < 0 )
return 0;
if ( t >= ucg->clip_box.size.h )
return 0;
return 1;
}
/*
Description:
clip range from a (included) to b (excluded) agains c (included) to d (excluded)
Assumptions:
a <= b
c <= d
*/
static ucg_int_t ucg_clip_intersection(ucg_int_t *ap, ucg_int_t *bp, ucg_int_t c, ucg_int_t d)
{
ucg_int_t a = *ap;
ucg_int_t b = *bp;
if ( a >= d )
return 0;
if ( b <= c )
return 0;
if ( a < c )
*ap = c;
if ( b > d )
*bp = d;
return 1;
}
ucg_int_t ucg_clip_is_pixel_visible(ucg_t *ucg)
{
if ( ucg_clip_is_x_visible(ucg) == 0 )
return 0;
if ( ucg_clip_is_y_visible(ucg) == 0 )
return 0;
return 1;
}
/*
assumes, that ucg->arg contains data for l90fx and does clipping
against ucg->clip_box
*/
ucg_int_t ucg_clip_l90fx(ucg_t *ucg)
{
ucg_int_t a;
ucg_int_t b;
ucg->arg.offset = 0;
switch(ucg->arg.dir)
{
case 0:
if ( ucg_clip_is_y_visible(ucg) == 0 )
return 0;
a = ucg->arg.pixel.pos.x;
b = a;
b += ucg->arg.len;
if ( ucg_clip_intersection(&a, &b, ucg->clip_box.ul.x, ucg->clip_box.ul.x+ucg->clip_box.size.w) == 0 )
return 0;
ucg->arg.offset = a - ucg->arg.pixel.pos.x;
ucg->arg.pixel.pos.x = a;
b -= a;
ucg->arg.len = b;
break;
case 1:
if ( ucg_clip_is_x_visible(ucg) == 0 )
return 0;
a = ucg->arg.pixel.pos.y;
b = a;
b += ucg->arg.len;
if ( ucg_clip_intersection(&a, &b, ucg->clip_box.ul.y, ucg->clip_box.ul.y+ucg->clip_box.size.h) == 0 )
return 0;
ucg->arg.offset = a - ucg->arg.pixel.pos.y;
ucg->arg.pixel.pos.y = a;
b -= a;
ucg->arg.len = b;
break;
case 2:
if ( ucg_clip_is_y_visible(ucg) == 0 )
return 0;
b = ucg->arg.pixel.pos.x;
b++;
a = b;
a -= ucg->arg.len;
if ( ucg_clip_intersection(&a, &b, ucg->clip_box.ul.x, ucg->clip_box.ul.x+ucg->clip_box.size.w) == 0 )
return 0;
ucg->arg.len = b-a;
b--;
ucg->arg.offset = ucg->arg.pixel.pos.x-b;
ucg->arg.pixel.pos.x = b;
break;
case 3:
if ( ucg_clip_is_x_visible(ucg) == 0 )
return 0;
b = ucg->arg.pixel.pos.y;
b++;
a = b;
a -= ucg->arg.len;
if ( ucg_clip_intersection(&a, &b, ucg->clip_box.ul.y, ucg->clip_box.ul.y+ucg->clip_box.size.h) == 0 )
return 0;
ucg->arg.len = b-a;
b--;
ucg->arg.offset = ucg->arg.pixel.pos.y-b;
ucg->arg.pixel.pos.y = b;
break;
}
return 1;
}
ucg_int_t ucg_clip_l90tc(ucg_t *ucg)
{
if ( ucg_clip_l90fx(ucg) == 0 )
return 0;
ucg->arg.pixel_skip = ucg->arg.offset & 0x07;
ucg->arg.bitmap += (ucg->arg.offset >>3);
return 1;
}
/* old code
ucg_int_t ucg_clip_l90tc(ucg_t *ucg)
{
ucg_int_t t;
switch(ucg->arg.dir)
{
case 0:
t = ucg->arg.pixel.pos.x;
if ( ucg_clip_l90fx(ucg) == 0 )
return 0;
t = ucg->arg.pixel.pos.x - t;
break;
case 1:
t = ucg->arg.pixel.pos.y;
if ( ucg_clip_l90fx(ucg) == 0 )
return 0;
t = ucg->arg.pixel.pos.y - t;
break;
case 2:
t = ucg->arg.pixel.pos.x;
if ( ucg_clip_l90fx(ucg) == 0 )
return 0;
t -= ucg->arg.pixel.pos.x;
break;
case 3:
t = ucg->arg.pixel.pos.y;
if ( ucg_clip_l90fx(ucg) == 0 )
return 0;
t -= ucg->arg.pixel.pos.y;
break;
}
ucg->arg.pixel_skip = t & 0x07;
ucg->arg.bitmap += (t >>3);
return 1;
}
*/
ucg_int_t ucg_clip_l90se(ucg_t *ucg)
{
uint8_t i;
if ( ucg_clip_l90fx(ucg) == 0 )
return 0;
for ( i = 0; i < 3; i++ )
{
ucg_ccs_seek(ucg->arg.ccs_line+i, ucg->arg.offset);
}
return 1;
}
/*
ucg_com_msg_api.c
Universal uC Color Graphics Library
Copyright (c) 2014, 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 "ucg.h"
int16_t ucg_com_template_cb(ucg_t *ucg, int16_t msg, uint32_t arg, uint8_t *data)
{
switch(msg)
{
case UCG_COM_MSG_POWER_UP:
break;
case UCG_COM_MSG_POWER_DOWN:
break;
case UCG_COM_MSG_DELAY:
break;
case UCG_COM_MSG_CHANGE_RESET_LINE:
break;
case UCG_COM_MSG_CHANGE_CS_LINE:
break;
case UCG_COM_MSG_CHANGE_CD_LINE:
break;
case UCG_COM_MSG_SEND_BYTE:
break;
case UCG_COM_MSG_REPEAT_1_BYTE:
break;
case UCG_COM_MSG_REPEAT_2_BYTES:
break;
case UCG_COM_MSG_REPEAT_3_BYTES:
break;
case UCG_COM_MSG_SEND_STR:
break;
case UCG_COM_MSG_SEND_CD_DATA_SEQUENCE:
break;
}
return 1;
}
void ucg_com_PowerDown(ucg_t *ucg)
{
if ( (ucg->com_status & UCG_COM_STATUS_MASK_POWER) != 0 )
ucg->com_cb(ucg, UCG_COM_MSG_POWER_DOWN, 0, NULL);
ucg->com_status &= ~UCG_COM_STATUS_MASK_POWER;
}
/*
clk_speed in nano-seconds, range: 0..4095
*/
int16_t ucg_com_PowerUp(ucg_t *ucg, uint16_t serial_clk_speed, uint16_t parallel_clk_speed)
{
int16_t r;
ucg_com_info_t com_info;
com_info.serial_clk_speed = serial_clk_speed;
com_info.parallel_clk_speed = parallel_clk_speed;
ucg_com_PowerDown(ucg);
ucg->com_initial_change_sent = 0;
r = ucg->com_cb(ucg, UCG_COM_MSG_POWER_UP, 0UL, (uint8_t *)&com_info);
if ( r != 0 )
{
ucg->com_status |= UCG_COM_STATUS_MASK_POWER;
}
return r;
}
void ucg_com_SetLineStatus(ucg_t *ucg, uint8_t level, uint8_t mask, uint8_t msg)
{
if ( level == 0 )
{
if ( (ucg->com_initial_change_sent & mask) == 0 || (ucg->com_status & mask) == mask )
{
ucg->com_cb(ucg, msg, level, NULL);
ucg->com_status &= ~mask;
ucg->com_initial_change_sent |= mask;
}
}
else
{
if ( (ucg->com_initial_change_sent & mask) == 0 || (ucg->com_status & mask) == 0 )
{
ucg->com_cb(ucg, msg, level, NULL);
ucg->com_status |= mask;
ucg->com_initial_change_sent |= mask;
}
}
}
void ucg_com_SetResetLineStatus(ucg_t *ucg, uint8_t level)
{
ucg_com_SetLineStatus(ucg, level, UCG_COM_STATUS_MASK_RESET, UCG_COM_MSG_CHANGE_RESET_LINE);
}
void ucg_com_SetCSLineStatus(ucg_t *ucg, uint8_t level)
{
ucg_com_SetLineStatus(ucg, level, UCG_COM_STATUS_MASK_CS, UCG_COM_MSG_CHANGE_CS_LINE);
}
void ucg_com_SetCDLineStatus(ucg_t *ucg, uint8_t level)
{
ucg_com_SetLineStatus(ucg, level, UCG_COM_STATUS_MASK_CD, UCG_COM_MSG_CHANGE_CD_LINE);
}
/* delay in microseconds */
void ucg_com_DelayMicroseconds(ucg_t *ucg, uint16_t delay)
{
ucg->com_cb(ucg, UCG_COM_MSG_DELAY, delay, NULL);
}
/* delay in milliseconds */
void ucg_com_DelayMilliseconds(ucg_t *ucg, uint16_t delay)
{
while( delay > 0 )
{
ucg_com_DelayMicroseconds(ucg, 1000);
delay--;
}
}
#ifndef ucg_com_SendByte
void ucg_com_SendByte(ucg_t *ucg, uint8_t byte)
{
ucg->com_cb(ucg, UCG_COM_MSG_SEND_BYTE, byte, NULL);
}
#endif
void ucg_com_SendRepeatByte(ucg_t *ucg, uint16_t cnt, uint8_t byte)
{
ucg->com_cb(ucg, UCG_COM_MSG_REPEAT_1_BYTE, cnt, &byte);
}
void ucg_com_SendRepeat2Bytes(ucg_t *ucg, uint16_t cnt, uint8_t *byte_ptr)
{
ucg->com_cb(ucg, UCG_COM_MSG_REPEAT_2_BYTES, cnt, byte_ptr);
}
#ifndef ucg_com_SendRepeat3Bytes
void ucg_com_SendRepeat3Bytes(ucg_t *ucg, uint16_t cnt, uint8_t *byte_ptr)
{
ucg->com_cb(ucg, UCG_COM_MSG_REPEAT_3_BYTES, cnt, byte_ptr);
}
#endif
void ucg_com_SendString(ucg_t *ucg, uint16_t cnt, const uint8_t *byte_ptr)
{
ucg->com_cb(ucg, UCG_COM_MSG_SEND_STR, cnt, (uint8_t *)byte_ptr);
}
void ucg_com_SendStringP(ucg_t *ucg, uint16_t cnt, const ucg_pgm_uint8_t *byte_ptr)
{
uint8_t b;
while( cnt > 0 )
{
b = ucg_pgm_read(byte_ptr);
//b = *byte_ptr;
ucg->com_cb(ucg, UCG_COM_MSG_SEND_BYTE, b, NULL);
byte_ptr++;
cnt--;
}
}
void ucg_com_SendCmdDataSequence(ucg_t *ucg, uint16_t cnt, const uint8_t *byte_ptr, uint8_t cd_line_status_at_end)
{
ucg->com_cb(ucg, UCG_COM_MSG_SEND_CD_DATA_SEQUENCE, cnt, (uint8_t *)byte_ptr);
ucg_com_SetCDLineStatus(ucg, cd_line_status_at_end); // ensure that the status is set correctly for the CD line */
}
/*
Command-Sequence Language
CMD10 1x CMD Byte, 0x Argument Data Bytes
CMD20 2x CMD Byte, 0x Argument Data Bytes
CMD11 1x CMD Byte, 1x Argument Data Bytes
CMD21 2x CMD Byte, 1x Argument Data Bytes
CMD12 1x CMD Byte, 2x Argument Data Bytes
CMD22 2x CMD Byte, 2x Argument Data Bytes
CMD13 1x CMD Byte, 3x Argument Data Bytes
CMD23 2x CMD Byte, 3x Argument Data Bytes
CMD14 1x CMD Byte, 4x Argument Data Bytes
CMD24 2x CMD Byte, 4x Argument Data Bytes
DATA1 1x Data Bytes
DATA2 2x Data Bytes
DATA3 3x Data Bytes
DATA4 4x Data Bytes
DATA5 5x Data Bytes
DATA6 6x Data Bytes
RST_LOW Output 0 on reset line
RST_HIGH Output 1 on reset line
CS_LOW Output 0 on chip select line
CS_HIGH Output 1 on chip select line
DLY_MS Delay for specified amount of milliseconds (0..2000)
DLY_US Delay for specified amount of microconds (0..2000)
Configuration
CFG_CD(c,a) Configure CMD/DATA line: "c" logic level CMD, "a" logic level CMD Args
0000xxxx End Marker
0001xxxx 1x CMD Byte, 0..15 Argument Data Bytes
0010xxxx 2x CMD Byte, 0..15 Argument Data Bytes
0011xxxx 3x CMD Byte, 0..15 Argument Data Bytes
0100xxxx
0101xxxx
0110xxxx Arg Bytes 0..15
0111xxxx Data Bytes 0...15
1000xxxx xxxxxxxx DLY MS
1001xxxx xxxxxxxx DLY US
1010sssss aaaaaaaa oooooooo (var0>>s)&a|o, send as argument
1011sssss aaaaaaaa oooooooo (var1>>s)&a|o, send as argument
1100xxxx
1101xxxx
1110xxxx
11110000 RST_LOW
11110001 RST_HIGH
1111001x
11110100 CS_LOW
11110101 CS_HIGH
1111011x
111110xx
111111ca CFG_CD(c,a)
#define C10(c0) 0x010, (c0)
#define C20(c0,c1) 0x020, (c0),(c1)
#define C11(c0,a0) 0x011, (c0),(a0)
#define C21(c0,c1,a0) 0x021, (c0),(c1),(a0)
#define C12(c0,a0,a1) 0x012, (c0),(a0),(a1)
#define C22(c0,c1,a0,a1) 0x022, (c0),(c1),(a0),(a1)
#define C13(c0,a0,a1,a2) 0x013, (c0),(a0),(a1),(a2)
#define C23(c0,c1,a0,a1,a2) 0x023, (c0),(c1),(a0),(a1),(a2)
#define C14(c0,a0,a1,a2,a3) 0x013, (c0),(a0),(a1),(a2),(a3)
#define C24(c0,c1,a0,a1,a2,a3) 0x023, (c0),(c1),(a0),(a1),(a2),(a3)
#define UCG_DATA() 0x070
#define D1(d0) 0x071, (d0)
#define D2(d0,d1) 0x072, (d0),(d1)
#define D3(d0,d1,d3) 0x073, (d0),(d1),(d2)
#define D4(d0,d1,d3,d4) 0x074, (d0),(d1),(d2),(d3)
#define D5(d0,d1,d3,d4,d5) 0x075, (d0),(d1),(d2),(d3),(d5)
#define D6(d0,d1,d3,d4,d5,d6) 0x076, (d0),(d1),(d2),(d3),(d5),(d6)
#define DLY_MS(t) 0x080 | (((t)>>8)&15), (t)&255
#define DLY_US(t) 0x090 | (((t)>>8)&15), (t)&255
s: Shift right
a: And mask
o: Or mask
#define UCG_VARX(s,a,o) 0x0a0 | ((s)&15), (a), (o)
#define UCG_VARY(s,a,o) 0x0b0 | ((s)&15), (a), (o)
#define RST(level) 0x0f0 | ((level)&1)
#define CS(level) 0x0f4 | ((level)&1)
#define CFG_CD(c,a) 0x0fc | (((c)&1)<<1) | ((a)&1)
#define END() 0x00
*/
static void ucg_com_SendCmdArg(ucg_t *ucg, const ucg_pgm_uint8_t *data, uint8_t cmd_cnt, uint8_t arg_cnt)
{
ucg_com_SetCDLineStatus(ucg, (ucg->com_cfg_cd>>1)&1 );
ucg_com_SendStringP(ucg, cmd_cnt, data);
if ( arg_cnt > 0 )
{
data += cmd_cnt;
ucg_com_SetCDLineStatus(ucg, (ucg->com_cfg_cd)&1 );
ucg_com_SendStringP(ucg, arg_cnt, data);
}
}
//void ucg_com_SendCmdSeq(ucg_t *ucg, const ucg_pgm_uint8_t *data)
void ucg_com_SendCmdSeq(ucg_t *ucg, const ucg_pgm_uint8_t *data)
{
uint8_t b;
uint8_t bb;
uint8_t hi;
uint8_t lo;
for(;;)
{
b = ucg_pgm_read(data);
//b = *data;
hi = (b) >> 4;
lo = (b) & 0x0f;
switch( hi )
{
case 0:
return; /* end marker */
case 1:
case 2:
case 3:
ucg_com_SendCmdArg(ucg, data+1, hi, lo);
data+=1+hi+lo;
break;
case 6:
ucg_com_SetCDLineStatus(ucg, (ucg->com_cfg_cd)&1 );
ucg_com_SendStringP(ucg, lo, data+1);
data+=1+lo;
break;
case 7: /* note: 0x070 is used to set data line status */
ucg_com_SetCDLineStatus(ucg, ((ucg->com_cfg_cd>>1)&1)^1 );
if ( lo > 0 )
ucg_com_SendStringP(ucg, lo, data+1);
data+=1+lo;
break;
case 8:
data++;
b = ucg_pgm_read(data);
//b = *data;
ucg_com_DelayMilliseconds(ucg, (((uint16_t)lo)<<8) + b );
data++;
break;
case 9:
data++;
b = ucg_pgm_read(data);
//b = *data;
ucg_com_DelayMicroseconds(ucg, (((uint16_t)lo)<<8) + b );
data++;
break;
case 10:
data++;
b = ucg_pgm_read(data);
data++;
bb = ucg_pgm_read(data);
data++;
//b = data[0];
//bb = data[1];
ucg_com_SetCDLineStatus(ucg, (ucg->com_cfg_cd)&1 );
ucg_com_SendByte(ucg, (((uint8_t)(((ucg->arg.pixel.pos.x)>>lo)))&b)|bb );
//data+=2;
break;
case 11:
data++;
b = ucg_pgm_read(data);
data++;
bb = ucg_pgm_read(data);
data++;
//b = data[0];
//bb = data[1];
ucg_com_SetCDLineStatus(ucg, (ucg->com_cfg_cd)&1 );
ucg_com_SendByte(ucg, (((uint8_t)(((ucg->arg.pixel.pos.y)>>lo)))&b)|bb );
//data+=2;
break;
case 15:
hi = lo >> 2;
lo &= 3;
switch(hi)
{
case 0:
ucg_com_SetResetLineStatus(ucg, lo&1);
break;
case 1:
ucg_com_SetCSLineStatus(ucg, lo&1);
break;
case 3:
ucg->com_cfg_cd = lo;
break;
}
data++;
break;
default:
return;
}
}
}
/*
ucg_dev_default_cb.c
Universal uC Color 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.
*/
#include "ucg.h"
/*
default device callback
this should be (finally) called by any other device callback to handle
messages, which are not yet handled.
*/
ucg_int_t ucg_dev_default_cb(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
return ucg->ext_cb(ucg, msg, data);
case UCG_MSG_SET_CLIP_BOX:
ucg->clip_box = *(ucg_box_t *)data;
break;
}
return 1; /* all ok */
}
/*
will be used as default cb if no extentions callback is provided
*/
ucg_int_t ucg_ext_none(ucg_t *ucg, ucg_int_t msg, void *data)
{
return 1; /* all ok */
}
/*
handle UCG_MSG_DRAW_L90FX message and make calls to "dev_cb" with UCG_MSG_DRAW_PIXEL
return 1 if something has been drawn
*/
ucg_int_t ucg_handle_l90fx(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
if ( ucg_clip_l90fx(ucg) != 0 )
{
ucg_int_t dx, dy;
ucg_int_t i;
switch(ucg->arg.dir)
{
case 0: dx = 1; dy = 0; break;
case 1: dx = 0; dy = 1; break;
case 2: dx = -1; dy = 0; break;
case 3: dx = 0; dy = -1; break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
for( i = 0; i < ucg->arg.len; i++ )
{
dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
}
return 1;
}
return 0;
}
/*
handle UCG_MSG_DRAW_L90TC message and make calls to "dev_cb" with UCG_MSG_DRAW_PIXEL
return 1 if something has been drawn
*/
ucg_int_t ucg_handle_l90tc(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
if ( ucg_clip_l90tc(ucg) != 0 )
{
ucg_int_t dx, dy;
ucg_int_t i;
unsigned char pixmap;
uint8_t bitcnt;
switch(ucg->arg.dir)
{
case 0: dx = 1; dy = 0; break;
case 1: dx = 0; dy = 1; break;
case 2: dx = -1; dy = 0; break;
case 3: dx = 0; dy = -1; break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
//pixmap = *(ucg->arg.bitmap);
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
for( i = 0; i < ucg->arg.len; i++ )
{
if ( (pixmap & 128) != 0 )
{
dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
}
pixmap<<=1;
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
bitcnt++;
if ( bitcnt >= 8 )
{
ucg->arg.bitmap++;
//pixmap = *(ucg->arg.bitmap);
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = 0;
}
}
return 1;
}
return 0;
}
/*
handle UCG_MSG_DRAW_L90FB message and make calls to "dev_cb" with UCG_MSG_DRAW_PIXEL
return 1 if something has been drawn
*/
ucg_int_t ucg_handle_l90bf(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
if ( ucg_clip_l90tc(ucg) != 0 )
{
ucg_int_t dx, dy;
ucg_int_t i, y;
unsigned char pixmap;
uint8_t bitcnt;
switch(ucg->arg.dir)
{
case 0: dx = 1; dy = 0; break;
case 1: dx = 0; dy = 1; break;
case 2: dx = -1; dy = 0; break;
case 3: dx = 0; dy = -1; break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
for( i = 0; i < ucg->arg.len; i++ )
{
for( y = 0; y < ucg->arg.scale; y++ )
{
if ( (pixmap & 128) == 0 )
{
ucg->arg.pixel.rgb = ucg->arg.rgb[1];
dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
}
else
{
ucg->arg.pixel.rgb = ucg->arg.rgb[0];
dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
}
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
}
pixmap<<=1;
bitcnt++;
if ( bitcnt >= 8 )
{
ucg->arg.bitmap++;
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = 0;
}
}
return 1;
}
return 0;
}
/*
handle UCG_MSG_DRAW_L90SE message and make calls to "dev_cb" with UCG_MSG_DRAW_PIXEL
return 1 if something has been drawn
*/
ucg_int_t ucg_handle_l90se(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
uint8_t i;
/* Setup ccs for l90se. This will be updated by ucg_clip_l90se if required */
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg->arg.ccs_line+i, ucg->arg.rgb[0].color[i], ucg->arg.rgb[1].color[i], ucg->arg.len);
}
/* check if the line is visible */
if ( ucg_clip_l90se(ucg) != 0 )
{
ucg_int_t dx, dy;
ucg_int_t i, j;
switch(ucg->arg.dir)
{
case 0: dx = 1; dy = 0; break;
case 1: dx = 0; dy = 1; break;
case 2: dx = -1; dy = 0; break;
case 3: dx = 0; dy = -1; break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
for( i = 0; i < ucg->arg.len; i++ )
{
ucg->arg.pixel.rgb.color[0] = ucg->arg.ccs_line[0].current;
ucg->arg.pixel.rgb.color[1] = ucg->arg.ccs_line[1].current;
ucg->arg.pixel.rgb.color[2] = ucg->arg.ccs_line[2].current;
dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
for ( j = 0; j < 3; j++ )
{
ucg_ccs_step(ucg->arg.ccs_line+j);
}
}
return 1;
}
return 0;
}
/*
l90rl run lenth encoded constant color pattern
yyllllll wwwwbbbb wwwwbbbb wwwwbbbb wwwwbbbb ...
sequence terminates if wwwwbbbb = 0
wwww: number of pixel to skip
bbbb: number of pixel to draw with color
llllll: number of bytes which follow, can be 0
*/
#ifdef ON_HOLD
void ucg_handle_l90rl(ucg_t *ucg, ucg_dev_fnptr dev_cb)
{
ucg_int_t dx, dy;
uint8_t i, cnt;
uint8_t rl_code;
ucg_int_t skip;
switch(ucg->arg.dir)
{
case 0: dx = 1; dy = 0; break;
case 1: dx = 0; dy = 1; break;
case 2: dx = -1; dy = 0; break;
case 3: dx = 0; dy = -1; break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
cnt = ucg_pgm_read(ucg->arg.bitmap);
cnt &= 63;
ucg->arg.bitmap++;
for( i = 0; i < cnt; i++ )
{
rl_code = ucg_pgm_read(ucg->arg.bitmap);
if ( rl_code == 0 )
break;
skip = (ucg_int_t)(rl_code >> 4);
switch(ucg->arg.dir)
{
case 0: ucg->arg.pixel.pos.x+=skip; break;
case 1: ucg->arg.pixel.pos.y+=skip; break;
case 2: ucg->arg.pixel.pos.x-=skip; break;
default:
case 3: ucg->arg.pixel.pos.y-=skip; break;
}
rl_code &= 15;
while( rl_code )
{
dev_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
rl_code--;
}
ucg->arg.bitmap++;
}
}
#endif
\ No newline at end of file
/*
ucg_dev_ic_ili9163.c
Specific code for the ili9163 controller (TFT displays)
Code is for 128x128 display which is shifted by 32 pixel within the controller RAM
Universal uC Color Graphics Library
Copyright (c) 2015, 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 "ucg.h"
const ucg_pgm_uint8_t ucg_ili9163_set_pos_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C11( 0x036, 0x008),
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_D2(0x000, 0x07f), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_D2(0x000, 0x0a1), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ili9163_set_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x008 horizontal increment (dir = 0) */
/* 0x008 vertical increment (dir = 1) */
/* 0x048 horizontal deccrement (dir = 2) */
/* 0x088 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x008),
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_D2(0x000, 0x083), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_D2(0x000, 0x0a1), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ili9163_set_pos_dir1_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x008 horizontal increment (dir = 0) */
/* 0x008 vertical increment (dir = 1) */
/* 0x048 horizontal deccrement (dir = 2) */
/* 0x088 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x008),
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_D2(0x000, 0x0a1), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ili9163_set_pos_dir2_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x008 horizontal increment (dir = 0) */
/* 0x008 vertical increment (dir = 1) */
/* 0x048 horizontal deccrement (dir = 2) */
/* 0x088 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x048),
UCG_C11( 0x036, 0x048), /* it seems that this command needs to be sent twice */
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_D2(0x000, 0x083), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_D2(0x000, 0x0a1), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ili9163_set_pos_dir3_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x008 horizontal increment (dir = 0) */
/* 0x008 vertical increment (dir = 1) */
/* 0x0c8 horizontal deccrement (dir = 2) */
/* 0x0c8 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x088),
UCG_C11( 0x036, 0x088), /* it seems that this command needs to be sent twice */
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_D2(0x000, 0x0a1), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
ucg_int_t ucg_handle_ili9163_l90fx(ucg_t *ucg)
{
uint8_t c[3];
ucg_int_t tmp;
if ( ucg_clip_l90fx(ucg) != 0 )
{
switch(ucg->arg.dir)
{
case 0:
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir0_seq);
ucg->arg.pixel.pos.y -= 32;
break;
case 1:
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir1_seq);
ucg->arg.pixel.pos.y -= 32;
break;
case 2:
tmp = ucg->arg.pixel.pos.x;
ucg->arg.pixel.pos.x = 127-tmp;
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir2_seq);
ucg->arg.pixel.pos.y -= 32;
ucg->arg.pixel.pos.x = tmp;
break;
case 3:
default:
tmp = ucg->arg.pixel.pos.y;
ucg->arg.pixel.pos.y = 127-tmp;
//ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir3_seq);
ucg->arg.pixel.pos.y = tmp;
break;
}
c[0] = ucg->arg.pixel.rgb.color[0];
c[1] = ucg->arg.pixel.rgb.color[1];
c[2] = ucg->arg.pixel.rgb.color[2];
ucg_com_SendRepeat3Bytes(ucg, ucg->arg.len, c);
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
/*
L2TC (Glyph Output)
*/
/* with CmdDataSequence */
ucg_int_t ucg_handle_ili9163_l90tc(ucg_t *ucg)
{
if ( ucg_clip_l90tc(ucg) != 0 )
{
uint8_t buf[16];
ucg_int_t dx, dy;
ucg_int_t i;
unsigned char pixmap;
uint8_t bitcnt;
ucg_com_SetCSLineStatus(ucg, 0); /* enable chip */
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_seq);
buf[0] = 0x001; // change to 0 (cmd mode)
buf[1] = 0x02a; // set x
buf[2] = 0x002; // change to 1 (arg mode)
buf[3] = 0x000; // upper part x
buf[4] = 0x000; // no change
buf[5] = 0x000; // will be overwritten by x value
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x02c; // write data
buf[8] = 0x002; // change to 1 (data mode)
buf[9] = 0x000; // red value
buf[10] = 0x000; // no change
buf[11] = 0x000; // green value
buf[12] = 0x000; // no change
buf[13] = 0x000; // blue value
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
buf[1] = 0x02a; // set x
break;
case 1:
dx = 0; dy = 1;
buf[1] = 0x02b; // set y
break;
case 2:
dx = -1; dy = 0;
buf[1] = 0x02a; // set x
break;
case 3:
default:
dx = 0; dy = -1;
buf[1] = 0x02b; // set y
break;
}
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
buf[9] = ucg->arg.pixel.rgb.color[0];
buf[11] = ucg->arg.pixel.rgb.color[1];
buf[13] = ucg->arg.pixel.rgb.color[2];
//ucg_com_SetCSLineStatus(ucg, 0); /* enable chip */
for( i = 0; i < ucg->arg.len; i++ )
{
if ( (pixmap & 128) != 0 )
{
if ( (ucg->arg.dir&1) == 0 )
{
buf[5] = ucg->arg.pixel.pos.x;
}
else
{
buf[3] = ucg->arg.pixel.pos.y>>8;
buf[5] = ucg->arg.pixel.pos.y&255;
}
ucg_com_SendCmdDataSequence(ucg, 7, buf, 0);
}
pixmap<<=1;
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
bitcnt++;
if ( bitcnt >= 8 )
{
ucg->arg.bitmap++;
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = 0;
}
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
ucg_int_t ucg_handle_ili9163_l90se(ucg_t *ucg)
{
uint8_t i;
uint8_t c[3];
ucg_int_t tmp;
/* Setup ccs for l90se. This will be updated by ucg_clip_l90se if required */
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg->arg.ccs_line+i, ucg->arg.rgb[0].color[i], ucg->arg.rgb[1].color[i], ucg->arg.len);
}
/* check if the line is visible */
if ( ucg_clip_l90se(ucg) != 0 )
{
ucg_int_t i;
switch(ucg->arg.dir)
{
case 0:
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir0_seq);
ucg->arg.pixel.pos.y -= 32;
break;
case 1:
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir1_seq);
ucg->arg.pixel.pos.y -= 32;
break;
case 2:
tmp = ucg->arg.pixel.pos.x;
ucg->arg.pixel.pos.x = 127-tmp;
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir2_seq);
ucg->arg.pixel.pos.y -= 32;
ucg->arg.pixel.pos.x = tmp;
break;
case 3:
default:
tmp = ucg->arg.pixel.pos.y;
ucg->arg.pixel.pos.y = 127-tmp;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_dir3_seq);
ucg->arg.pixel.pos.y = tmp;
break;
}
for( i = 0; i < ucg->arg.len; i++ )
{
c[0] = ucg->arg.ccs_line[0].current;
c[1] = ucg->arg.ccs_line[1].current;
c[2] = ucg->arg.ccs_line[2].current;
ucg_com_SendRepeat3Bytes(ucg, 1, c);
ucg_ccs_step(ucg->arg.ccs_line+0);
ucg_ccs_step(ucg->arg.ccs_line+1);
ucg_ccs_step(ucg->arg.ccs_line+2);
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
static const ucg_pgm_uint8_t ucg_ili9163_power_down_seq[] = {
UCG_CS(0), /* enable chip */
UCG_C10(0x010), /* sleep in */
UCG_C10(0x28), /* display off */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ic_ili9163_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* setup com interface and provide information on the clock speed */
/* of the serial and parallel interface. Values are nanoseconds. */
return ucg_com_PowerUp(ucg, 100, 66);
case UCG_MSG_DEV_POWER_DOWN:
ucg_com_SendCmdSeq(ucg, ucg_ili9163_power_down_seq);
return 1;
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 128;
return 1;
case UCG_MSG_DRAW_PIXEL:
if ( ucg_clip_is_pixel_visible(ucg) !=0 )
{
uint8_t c[3];
ucg->arg.pixel.pos.y += 32;
ucg_com_SendCmdSeq(ucg, ucg_ili9163_set_pos_seq);
ucg->arg.pixel.pos.y -= 32;
c[0] = ucg->arg.pixel.rgb.color[0];
c[1] = ucg->arg.pixel.rgb.color[1];
c[2] = ucg->arg.pixel.rgb.color[2];
ucg_com_SendRepeat3Bytes(ucg, 1, c);
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
}
return 1;
case UCG_MSG_DRAW_L90FX:
//ucg_handle_l90fx(ucg, ucg_dev_ic_ili9163_18);
ucg_handle_ili9163_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
//ucg_handle_l90tc(ucg, ucg_dev_ic_ili9163_18);
ucg_handle_ili9163_l90tc(ucg);
return 1;
#endif /* UCG_MSG_DRAW_L90TC */
#ifdef UCG_MSG_DRAW_L90BF
case UCG_MSG_DRAW_L90BF:
ucg_handle_l90bf(ucg, ucg_dev_ic_ili9163_18);
return 1;
#endif /* UCG_MSG_DRAW_L90BF */
/* msg UCG_MSG_DRAW_L90SE is handled by ucg_dev_default_cb */
/*
case UCG_MSG_DRAW_L90SE:
return ucg->ext_cb(ucg, msg, data);
*/
}
return ucg_dev_default_cb(ucg, msg, data);
}
ucg_int_t ucg_ext_ili9163_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
//ucg_handle_l90se(ucg, ucg_dev_ic_ili9163_18);
ucg_handle_ili9163_l90se(ucg);
break;
}
return 1;
}
\ No newline at end of file
/*
ucg_dev_ic_ili9325.c
Specific code for the ili9325 controller (TFT displays)
Universal uC Color Graphics Library
Copyright (c) 2014, 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 "ucg.h"
static const ucg_pgm_uint8_t ucg_ili9325_set_pos_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x020), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static const ucg_pgm_uint8_t ucg_ili9325_set_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
/* last byte: 0x030 horizontal increment (dir = 0) */
/* last byte: 0x038 vertical increment (dir = 1) */
/* last byte: 0x000 horizontal deccrement (dir = 2) */
/* last byte: 0x008 vertical deccrement (dir = 3) */
UCG_C22(0x000, 0x003, 0xc0 | 0x010, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
UCG_C10(0x020), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static const ucg_pgm_uint8_t ucg_ili9325_set_pos_dir1_seq[] =
{
UCG_CS(0), /* enable chip */
/* last byte: 0x030 horizontal increment (dir = 0) */
/* last byte: 0x038 vertical increment (dir = 1) */
/* last byte: 0x000 horizontal deccrement (dir = 2) */
/* last byte: 0x008 vertical deccrement (dir = 3) */
UCG_C22(0x000, 0x003, 0xc0 | 0x010, 0x038), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
UCG_C10(0x020), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static const ucg_pgm_uint8_t ucg_ili9325_set_pos_dir2_seq[] =
{
UCG_CS(0), /* enable chip */
/* last byte: 0x030 horizontal increment (dir = 0) */
/* last byte: 0x038 vertical increment (dir = 1) */
/* last byte: 0x000 horizontal deccrement (dir = 2) */
/* last byte: 0x008 vertical deccrement (dir = 3) */
UCG_C22(0x000, 0x003, 0xc0 | 0x010, 0x000), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
UCG_C10(0x020), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static const ucg_pgm_uint8_t ucg_ili9325_set_pos_dir3_seq[] =
{
UCG_CS(0), /* enable chip */
/* last byte: 0x030 horizontal increment (dir = 0) */
/* last byte: 0x038 vertical increment (dir = 1) */
/* last byte: 0x000 horizontal deccrement (dir = 2) */
/* last byte: 0x008 vertical deccrement (dir = 3) */
UCG_C22(0x000, 0x003, 0xc0 | 0x010, 0x008), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
UCG_C10(0x020), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static ucg_int_t ucg_handle_ili9325_l90fx(ucg_t *ucg)
{
uint8_t c[3];
if ( ucg_clip_l90fx(ucg) != 0 )
{
switch(ucg->arg.dir)
{
case 0:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir1_seq);
break;
case 2:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir2_seq);
break;
case 3:
default:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir3_seq);
break;
}
c[0] = ucg->arg.pixel.rgb.color[0];
c[1] = ucg->arg.pixel.rgb.color[1];
c[2] = ucg->arg.pixel.rgb.color[2];
ucg_com_SendRepeat3Bytes(ucg, ucg->arg.len, c);
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
/*
L2TC (Glyph Output)
Because of this for vertical lines the x min and max values in
"ucg_ili9325_set_pos_for_y_seq" are identical to avoid changes of the x position
*/
static const ucg_pgm_uint8_t ucg_ili9325_set_x_pos_seq[] =
{
UCG_C10(0x020), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static const ucg_pgm_uint8_t ucg_ili9325_set_y_pos_seq[] =
{
UCG_C10(0x021), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
/* without CmdDataSequence */
ucg_int_t xxxxxx_ucg_handle_ili9325_l90tc(ucg_t *ucg)
{
if ( ucg_clip_l90tc(ucg) != 0 )
{
uint8_t buf[3];
ucg_int_t dx, dy;
ucg_int_t i;
const uint8_t *seq;
unsigned char pixmap;
uint8_t bitcnt;
ucg_com_SetCSLineStatus(ucg, 0); /* enable chip */
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_seq);
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
seq = ucg_ili9325_set_x_pos_seq;
break;
case 1:
dx = 0; dy = 1;
seq = ucg_ili9325_set_y_pos_seq;
break;
case 2:
dx = -1; dy = 0;
seq = ucg_ili9325_set_x_pos_seq;
break;
case 3:
default:
dx = 0; dy = -1;
seq = ucg_ili9325_set_y_pos_seq;
break;
}
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
buf[0] = ucg->arg.pixel.rgb.color[0];
buf[1] = ucg->arg.pixel.rgb.color[1];
buf[2] = ucg->arg.pixel.rgb.color[2];
//ucg_com_SetCSLineStatus(ucg, 0); /* enable chip */
for( i = 0; i < ucg->arg.len; i++ )
{
if ( (pixmap & 128) != 0 )
{
ucg_com_SendCmdSeq(ucg, seq);
ucg_com_SendRepeat3Bytes(ucg, 1, buf);
}
pixmap<<=1;
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
bitcnt++;
if ( bitcnt >= 8 )
{
ucg->arg.bitmap++;
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = 0;
}
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
/* with CmdDataSequence */
static ucg_int_t ucg_handle_ili9325_l90tc(ucg_t *ucg)
{
if ( ucg_clip_l90tc(ucg) != 0 )
{
uint8_t buf[20];
ucg_int_t dx, dy;
ucg_int_t i;
unsigned char pixmap;
uint8_t bitcnt;
ucg_com_SetCSLineStatus(ucg, 0); /* enable chip */
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_seq);
buf[0] = 0x001; // change to 0 (cmd mode)
buf[1] = 0x020; // set x
buf[2] = 0x002; // change to 1 (arg mode)
buf[3] = 0x000; // upper part x
buf[4] = 0x000; // no change
buf[5] = 0x000; // will be overwritten by x value
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x022; // write data
buf[8] = 0x002; // change to 1 (data mode)
buf[9] = 0x000; // red value
buf[10] = 0x000; // no change
buf[11] = 0x000; // green value
buf[12] = 0x000; // no change
buf[13] = 0x000; // blue value
break;
case 1:
dx = 0; dy = 1;
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x021; // set y
buf[8] = 0x002; // change to 1 (arg mode)
buf[9] = 0x000; // upper part y
buf[10] = 0x000; // no change
buf[11] = 0x000; // will be overwritten by y value
buf[12] = 0x001; // change to 0 (cmd mode)
buf[13] = 0x022; // write data
buf[14] = 0x002; // change to 1 (data mode)
buf[15] = 0x000; // red value
buf[16] = 0x000; // no change
buf[17] = 0x000; // green value
buf[18] = 0x000; // no change
buf[19] = 0x000; // blue value
break;
case 2:
dx = -1; dy = 0;
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x022; // write data
buf[8] = 0x002; // change to 1 (data mode)
buf[9] = 0x000; // red value
buf[10] = 0x000; // no change
buf[11] = 0x000; // green value
buf[12] = 0x000; // no change
buf[13] = 0x000; // blue value
break;
case 3:
default:
dx = 0; dy = -1;
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x021; // set y
buf[8] = 0x002; // change to 1 (arg mode)
buf[9] = 0x000; // upper part y
buf[10] = 0x000; // no change
buf[11] = 0x000; // will be overwritten by y value
buf[12] = 0x001; // change to 0 (cmd mode)
buf[13] = 0x022; // write data
buf[14] = 0x002; // change to 1 (data mode)
buf[15] = 0x000; // red value
buf[16] = 0x000; // no change
buf[17] = 0x000; // green value
buf[18] = 0x000; // no change
buf[19] = 0x000; // blue value
break;
}
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
if ( (ucg->arg.dir&1) == 0 )
{
buf[9] = ucg->arg.pixel.rgb.color[0];
buf[11] = ucg->arg.pixel.rgb.color[1];
buf[13] = ucg->arg.pixel.rgb.color[2];
}
else
{
buf[15] = ucg->arg.pixel.rgb.color[0];
buf[17] = ucg->arg.pixel.rgb.color[1];
buf[19] = ucg->arg.pixel.rgb.color[2];
}
//ucg_com_SetCSLineStatus(ucg, 0); /* enable chip */
for( i = 0; i < ucg->arg.len; i++ )
{
if ( (pixmap & 128) != 0 )
{
if ( (ucg->arg.dir&1) == 0 )
{
buf[5] = ucg->arg.pixel.pos.x;
ucg_com_SendCmdDataSequence(ucg, 7, buf, 1);
}
else
{
buf[5] = ucg->arg.pixel.pos.x;
buf[9] = (ucg->arg.pixel.pos.y>>8)&1;
buf[11] = ucg->arg.pixel.pos.y&255;
ucg_com_SendCmdDataSequence(ucg, 10, buf, 1);
}
}
pixmap<<=1;
ucg->arg.pixel.pos.x+=dx;
ucg->arg.pixel.pos.y+=dy;
bitcnt++;
if ( bitcnt >= 8 )
{
ucg->arg.bitmap++;
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = 0;
}
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
static ucg_int_t ucg_handle_ili9325_l90se(ucg_t *ucg)
{
uint8_t i;
uint8_t c[3];
/* Setup ccs for l90se. This will be updated by ucg_clip_l90se if required */
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg->arg.ccs_line+i, ucg->arg.rgb[0].color[i], ucg->arg.rgb[1].color[i], ucg->arg.len);
}
/* check if the line is visible */
if ( ucg_clip_l90se(ucg) != 0 )
{
ucg_int_t i;
switch(ucg->arg.dir)
{
case 0:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir1_seq);
break;
case 2:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir2_seq);
break;
case 3:
default:
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_dir3_seq);
break;
}
for( i = 0; i < ucg->arg.len; i++ )
{
c[0] = ucg->arg.ccs_line[0].current;
c[1] = ucg->arg.ccs_line[1].current;
c[2] = ucg->arg.ccs_line[2].current;
ucg_com_SendRepeat3Bytes(ucg, 1, c);
ucg_ccs_step(ucg->arg.ccs_line+0);
ucg_ccs_step(ucg->arg.ccs_line+1);
ucg_ccs_step(ucg->arg.ccs_line+2);
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
ucg_int_t ucg_dev_ic_ili9325_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* setup com interface and provide information on the clock speed */
/* of the serial and parallel interface. Values are nanoseconds. */
return ucg_com_PowerUp(ucg, 40, 100);
case UCG_MSG_DEV_POWER_DOWN:
/* not yet implemented */
return 1;
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 240;
((ucg_wh_t *)data)->h = 320;
return 1;
case UCG_MSG_DRAW_PIXEL:
if ( ucg_clip_is_pixel_visible(ucg) !=0 )
{
uint8_t c[3];
ucg_com_SendCmdSeq(ucg, ucg_ili9325_set_pos_seq);
c[0] = ucg->arg.pixel.rgb.color[0];
c[1] = ucg->arg.pixel.rgb.color[1];
c[2] = ucg->arg.pixel.rgb.color[2];
ucg_com_SendRepeat3Bytes(ucg, 1, c);
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
}
return 1;
case UCG_MSG_DRAW_L90FX:
//ucg_handle_l90fx(ucg, ucg_dev_ic_ili9325_18);
ucg_handle_ili9325_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
//ucg_handle_l90tc(ucg, ucg_dev_ic_ili9325);
ucg_handle_ili9325_l90tc(ucg);
return 1;
#endif /* UCG_MSG_DRAW_L90TC */
#ifdef UCG_MSG_DRAW_L90BF
case UCG_MSG_DRAW_L90BF:
ucg_handle_l90bf(ucg, ucg_dev_ic_ili9325_18);
return 1;
#endif /* UCG_MSG_DRAW_L90BF */
/* msg UCG_MSG_DRAW_L90SE is handled by ucg_dev_default_cb */
/*
case UCG_MSG_DRAW_L90SE:
return ucg->ext_cb(ucg, msg, data);
*/
}
return ucg_dev_default_cb(ucg, msg, data);
}
ucg_int_t ucg_ext_ili9325_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
//ucg_handle_l90se(ucg, ucg_dev_ic_ili9325);
ucg_handle_ili9325_l90se(ucg);
break;
}
return 1;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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