Commit 6dc0dfc0 authored by devsaurus's avatar devsaurus
Browse files
parent f5ae0ed7
/*
ucg_dev_ic_seps225.c
Specific code for the SEPS225 controller (OLED displays)
128x128x18 display buffer
Note: Only 65K color support, because 262K mode is not possible with 8 Bit SPI.
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"
static uint8_t ucg_seps225_get_color_high_byte(ucg_t *ucg)
{
return (ucg->arg.pixel.rgb.color[0]&0x0f8) | (((ucg->arg.pixel.rgb.color[1]) >>5));
}
static uint8_t ucg_seps225_get_color_low_byte(ucg_t *ucg)
{
return ((((ucg->arg.pixel.rgb.color[1]))<<3)&0x0e0) | (((ucg->arg.pixel.rgb.color[2]) >>3));
}
/*
Write Memory Mode 0x016
Bit 0: HV
HV= 0, data is continuously written horizontally
HV= 1, data is continuously written vertically
Bit 1: VC
VC= 0, vertical address counter is decreased
VC= 1, vertical address counter is increased
Bit 2: HC
HC= 0, horizontal address counter is decreased
HC= 1, horizontal address counter is increased
Bit 4..6: Dual Transfer, 65K Mode (Bit 4 = 0, Bit 5 = 1, Bit 6 = 1)
*/
static const ucg_pgm_uint8_t ucg_seps255_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x020), UCG_VARX(0,0x07f, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(0,0x07f, 0), /* set y position */
UCG_C11(0x016, 0x064), /* Memory Mode */
UCG_C10(0x022), /* prepare for data */
UCG_DATA(), /* change to data mode */
UCG_END()
};
static const ucg_pgm_uint8_t ucg_seps255_pos_dir1_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C11(0x016, 0x063), /* Memory Mode */
UCG_C10(0x020), UCG_VARX(0,0x07f, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(0,0x07f, 0), /* set y position */
UCG_C10(0x022), /* prepare for data */
UCG_DATA(), /* change to data mode */
UCG_END()
};
#ifdef NOT_USED
static const ucg_pgm_uint8_t ucg_seps255_pos_dir2_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C11(0x016, 0x060), /* Memory Mode */
UCG_C10(0x020), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* prepare for data */
UCG_DATA(), /* change to data mode */
UCG_END()
};
/* it seems that this mode does not work*/
static const ucg_pgm_uint8_t ucg_seps255_pos_dir3_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C11(0x016, 0x061), /* Memory Mode */
UCG_C10(0x020), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x021), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x022), /* prepare for data */
UCG_DATA(), /* change to data mode */
UCG_END()
};
#endif
ucg_int_t ucg_handle_seps225_l90fx(ucg_t *ucg)
{
if ( ucg_clip_l90fx(ucg) != 0 )
{
switch(ucg->arg.dir)
{
case 0:
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir1_seq);
break;
case 2:
ucg->arg.pixel.pos.x -= ucg->arg.len;
ucg->arg.pixel.pos.x++;
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
break;
case 3:
default:
ucg->arg.pixel.pos.y -= ucg->arg.len;
ucg->arg.pixel.pos.y++;
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir1_seq);
break;
}
{
uint8_t c[2];
c[0] = ucg_seps225_get_color_high_byte(ucg);
c[1] = ucg_seps225_get_color_low_byte(ucg);
ucg_com_SendRepeat2Bytes(ucg, ucg->arg.len, c);
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
/*
L2TC (Bitmap Output)
Not implemented for this controller, fallback to standard. However this msg is not used
at all at the moment (Jul 2015)
*/
/*
L2SE Color Change
*/
ucg_int_t ucg_handle_seps225_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 */
switch(ucg->arg.dir)
{
case 0:
case 1:
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);
}
break;
default:
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg->arg.ccs_line+i, ucg->arg.rgb[1].color[i], ucg->arg.rgb[0].color[i], ucg->arg.len);
}
break;
}
/* check if the line is visible */
if ( ucg_clip_l90se(ucg) != 0 )
{
ucg_int_t dx, dy;
ucg_int_t i, j;
//uint8_t r, g, b;
switch(ucg->arg.dir)
{
case 0: dx = 1; dy = 0;
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
break;
case 1: dx = 0; dy = 1;
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir1_seq);
break;
case 2: dx = 1; dy = 0;
ucg->arg.pixel.pos.x -= ucg->arg.len;
ucg->arg.pixel.pos.x++;
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
break;
case 3: dx = 0; dy = 1;
ucg->arg.pixel.pos.y -= ucg->arg.len;
ucg->arg.pixel.pos.y++;
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir1_seq);
break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
for( i = 0; i < ucg->arg.len; i++ )
{
/*
r = ucg->arg.ccs_line[0].current;
r &= 0x0f8;
g = ucg->arg.ccs_line[1].current;
c[0] = g;
c[0] >>= 5;
c[0] |= r;
g <<= 3;
g &= 0x0e0;
b = ucg->arg.ccs_line[2].current;
b >>= 3;
c[1] = g;
c[1] |= b;
*/
c[0] = (ucg->arg.ccs_line[0].current&0x0f8) | (((ucg->arg.ccs_line[1].current) >>5));
c[1] = ((((ucg->arg.ccs_line[1].current))<<3)&0x0e0) | (((ucg->arg.ccs_line[2].current) >>3));
ucg_com_SendRepeat2Bytes(ucg, 1, c);
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);
}
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
static const ucg_pgm_uint8_t ucg_seps225_power_down_seq[] = {
UCG_CS(0), /* enable chip */
UCG_C11(0x006, 0x000), /* SEPS225: display off */
UCG_C11(0x004, 0x001), /* reduce current, power down */
UCG_CS(1), /* disable chip */
/* delay of 100ms is suggested here for full power down */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ic_seps225_16(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, 50, 200); /* adjusted for SEPS225 */
case UCG_MSG_DEV_POWER_DOWN:
ucg_com_SendCmdSeq(ucg, ucg_seps225_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_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
c[0] = ucg_seps225_get_color_high_byte(ucg);
c[1] = ucg_seps225_get_color_low_byte(ucg);
ucg_com_SendRepeat2Bytes(ucg, 1, c);
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
}
return 1;
case UCG_MSG_DRAW_L90FX:
//ucg_handle_l90fx(ucg, ucg_dev_ic_seps225_16);
ucg_handle_seps225_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
ucg_handle_l90tc(ucg, ucg_dev_ic_seps225_18);
return 1;
#endif /* UCG_MSG_DRAW_L90TC */
#ifdef UCG_MSG_DRAW_L90BF
case UCG_MSG_DRAW_L90BF:
ucg_handle_l90bf(ucg, ucg_dev_ic_seps225_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_seps225_16(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
//ucg_handle_l90se(ucg, ucg_dev_ic_seps225_16);
ucg_handle_seps225_l90se(ucg);
break;
}
return 1;
}
/*
ucg_dev_ic_ssd1289.c
Specific code for the ssd1289 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"
#ifdef NOT_YET_IMPLEMENTED
static const ucg_pgm_uint8_t ucg_ssd1289_set_pos_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x04e), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x04f), 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_ssd1289_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, 0x011, 0x048, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
UCG_C10(0x04e), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x04f), 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_ssd1289_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, 0x011, 0x048, 0x038), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1, set TRI (Bit 15) and DFM (Bit 14) --> three byte transfer */
UCG_C10(0x04e), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x04f), 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()
};
const ucg_pgm_uint8_t ucg_ssd1289_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, 0x011, 0x048, 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()
};
const ucg_pgm_uint8_t ucg_ssd1289_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, 0x011, 0x048, 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()
};
ucg_int_t ucg_handle_ssd1289_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_ssd1289_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_ssd1289_set_pos_dir1_seq);
break;
case 2:
ucg_com_SendCmdSeq(ucg, ucg_ssd1289_set_pos_dir2_seq);
break;
case 3:
default:
ucg_com_SendCmdSeq(ucg, ucg_ssd1289_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_ssd1289_set_pos_for_y_seq" are identical to avoid changes of the x position
*/
const ucg_pgm_uint8_t ucg_ssd1289_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()
};
const ucg_pgm_uint8_t ucg_ssd1289_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_ssd1289_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_ssd1289_set_pos_seq);
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
seq = ucg_ssd1289_set_x_pos_seq;
break;
case 1:
dx = 0; dy = 1;
seq = ucg_ssd1289_set_y_pos_seq;
break;
case 2:
dx = -1; dy = 0;
seq = ucg_ssd1289_set_x_pos_seq;
break;
case 3:
default:
dx = 0; dy = -1;
seq = ucg_ssd1289_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 */
ucg_int_t ucg_handle_ssd1289_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_com_SendCmdSeq(ucg, ucg_ssd1289_set_pos_seq);
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
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
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[0] = 0x001; // change to 0 (cmd mode)
buf[1] = 0x020; // set y
buf[2] = 0x002; // change to 1 (arg mode)
buf[3] = 0x000; // upper part y
buf[4] = 0x000; // no change
buf[5] = 0x000; // will be overwritten by y value
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 2:
dx = -1; dy = 0;
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
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[0] = 0x001; // change to 0 (cmd mode)
buf[1] = 0x020; // set y
buf[2] = 0x002; // change to 1 (arg mode)
buf[3] = 0x000; // upper part y
buf[4] = 0x000; // no change
buf[5] = 0x000; // will be overwritten by y value
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;
}
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);
}
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_ssd1289_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_ssd1289_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_ssd1289_set_pos_dir1_seq);
break;
case 2:
ucg_com_SendCmdSeq(ucg, ucg_ssd1289_set_pos_dir2_seq);
break;
case 3:
default:
ucg_com_SendCmdSeq(ucg, ucg_ssd1289_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_ssd1289_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_ssd1289_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_ssd1289_18);
//ucg_handle_ssd1289_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
ucg_handle_l90tc(ucg, ucg_dev_ic_ssd1289);
//ucg_handle_ssd1289_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_ssd1289);
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_ssd1289_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
ucg_handle_l90se(ucg, ucg_dev_ic_ssd1289);
//ucg_handle_ssd1289_l90se(ucg);
break;
}
return 1;
}
#endif
\ No newline at end of file
/*
ucg_dev_ic_ssd1331.c
Specific code for the SSD1331 controller (OLED displays)
96x64x16 display buffer, however 3-byte 18 bit mode is used
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"
//ucg_int_t u8g_dev_ic_ssd1331(ucg_t *ucg, ucg_int_t msg, void *data);
const ucg_pgm_uint8_t ucg_ssd1331_set_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_A1(0x07f), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ssd1331_set_pos_dir1_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_A1(0x07f), /* set y position */
UCG_DATA(), /* change to data mode */
UCG_END()
};
ucg_int_t ucg_handle_ssd1331_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_ssd1331_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir1_seq);
break;
case 2:
ucg->arg.pixel.pos.x -= ucg->arg.len;
ucg->arg.pixel.pos.x++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir0_seq);
break;
case 3:
default:
ucg->arg.pixel.pos.y -= ucg->arg.len;
ucg->arg.pixel.pos.y++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir1_seq);
break;
}
c[0] = ucg->arg.pixel.rgb.color[0]>>2;
c[1] = ucg->arg.pixel.rgb.color[1]>>2;
c[2] = ucg->arg.pixel.rgb.color[2]>>2;
ucg_com_SendRepeat3Bytes(ucg, ucg->arg.len, c);
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
/*
L2TC (Bitmap Output)
Because of this for vertical lines the x min and max values in
"ucg_ssd1331_set_pos_for_y_seq" are identical to avoid changes of the x position
*/
const ucg_pgm_uint8_t ucg_ssd1331_set_pos_for_x_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_A1(0x07f), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ssd1331_set_pos_for_y_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_A1(0x07f), /* set y position */
UCG_END()
};
ucg_int_t ucg_handle_ssd1331_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 */
buf[0] = 0x001; // change to 0 (cmd mode)
buf[1] = 0x015; // set x
buf[2] = 0x002; // change to 1 (arg mode)
buf[3] = 0x000; // will be overwritten by x/y value
buf[4] = 0x000; // no change
buf[5] = 0x07f; // max value
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x05c; // 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
buf[14] = 0x001; // change to 0 (cmd mode)
buf[15] = 0x05c; // change to 0 (cmd mode)
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
buf[1] = 0x015;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_for_x_seq);
break;
case 1:
dx = 0; dy = 1;
buf[1] = 0x075;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_for_y_seq);
break;
case 2:
dx = -1; dy = 0;
buf[1] = 0x015;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_for_x_seq);
break;
case 3:
default:
dx = 0; dy = -1;
buf[1] = 0x075;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_for_y_seq);
break;
}
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
buf[9] = ucg->arg.pixel.rgb.color[0]>>2;
buf[11] = ucg->arg.pixel.rgb.color[1]>>2;
buf[13] = ucg->arg.pixel.rgb.color[2]>>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[3] = ucg->arg.pixel.pos.x;
}
else
{
buf[3] = ucg->arg.pixel.pos.y;
}
//ucg_com_SendCmdSeq(ucg, seq);
//buf[0] = ucg->arg.pixel.rgb.color[0]>>2;
//buf[1] = ucg->arg.pixel.rgb.color[1]>>2;
//buf[2] = ucg->arg.pixel.rgb.color[2]>>2;
//ucg_com_SendRepeat3Bytes(ucg, 1, buf);
ucg_com_SendCmdDataSequence(ucg, 7, buf, 1);
//ucg_com_SetCDLineStatus(ucg, 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;
}
ucg_int_t ucg_handle_ssd1331_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 */
switch(ucg->arg.dir)
{
case 0:
case 1:
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);
}
break;
default:
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg->arg.ccs_line+i, ucg->arg.rgb[1].color[i], ucg->arg.rgb[0].color[i], ucg->arg.len);
}
break;
}
/* 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;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir0_seq);
break;
case 1: dx = 0; dy = 1;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir1_seq);
break;
case 2: dx = 1; dy = 0;
ucg->arg.pixel.pos.x -= ucg->arg.len;
ucg->arg.pixel.pos.x++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir0_seq);
break;
case 3: dx = 0; dy = 1;
ucg->arg.pixel.pos.y -= ucg->arg.len;
ucg->arg.pixel.pos.y++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir1_seq);
break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
for( i = 0; i < ucg->arg.len; i++ )
{
c[0] = ucg->arg.ccs_line[0].current >> 2;
c[1] = ucg->arg.ccs_line[1].current >> 2;
c[2] = ucg->arg.ccs_line[2].current >> 2;
ucg_com_SendRepeat3Bytes(ucg, 1, c);
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);
}
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
static const ucg_pgm_uint8_t ucg_ssd1331_power_down_seq[] = {
UCG_CS(0), /* enable chip */
UCG_C10(0x0a6), /* Set display: All pixel off */
UCG_C10(0x0ae), /* Set display off: sleep mode */
//UCG_C11(0x0b0, 0x01a), /* Power Save Mode */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ic_ssd1331_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, 50, 300);
case UCG_MSG_DEV_POWER_DOWN:
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_power_down_seq);
return 1;
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 96;
((ucg_wh_t *)data)->h = 64;
return 1;
case UCG_MSG_DRAW_PIXEL:
if ( ucg_clip_is_pixel_visible(ucg) !=0 )
{
uint8_t c[3];
ucg_com_SendCmdSeq(ucg, ucg_ssd1331_set_pos_dir0_seq);
c[0] = ucg->arg.pixel.rgb.color[0]>>2;
c[1] = ucg->arg.pixel.rgb.color[1]>>2;
c[2] = ucg->arg.pixel.rgb.color[2]>>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_ssd1331_18);
ucg_handle_ssd1331_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
//ucg_handle_l90tc(ucg, ucg_dev_ic_ssd1331_18);
ucg_handle_ssd1331_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_ssd1331_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_ssd1331_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
//ucg_handle_l90se(ucg, ucg_dev_ic_ssd1331_18);
ucg_handle_ssd1331_l90se(ucg);
break;
}
return 1;
}
\ No newline at end of file
/*
ucg_dev_ic_ssd1351.c
Specific code for the SSD1351 controller (OLED 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"
//ucg_int_t u8g_dev_ic_ssd1351(ucg_t *ucg, ucg_int_t msg, void *data);
const ucg_pgm_uint8_t ucg_ssd1351_set_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_D1(0x07f), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_C10(0x05c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ssd1351_set_pos_dir1_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_D1(0x07f), /* set y position */
UCG_C10(0x05c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
ucg_int_t ucg_handle_ssd1351_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_ssd1351_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir1_seq);
break;
case 2:
ucg->arg.pixel.pos.x -= ucg->arg.len;
ucg->arg.pixel.pos.x++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir0_seq);
break;
case 3:
default:
ucg->arg.pixel.pos.y -= ucg->arg.len;
ucg->arg.pixel.pos.y++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir1_seq);
break;
}
c[0] = ucg->arg.pixel.rgb.color[0]>>2;
c[1] = ucg->arg.pixel.rgb.color[1]>>2;
c[2] = ucg->arg.pixel.rgb.color[2]>>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_ssd1351_set_pos_for_y_seq" are identical to avoid changes of the x position
*/
const ucg_pgm_uint8_t ucg_ssd1351_set_pos_for_x_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_D1(0x07f), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_VARY(0,0x0ff, 0), /* set y position */
UCG_END()
};
const ucg_pgm_uint8_t ucg_ssd1351_set_pos_for_y_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C10(0x015), UCG_VARX(0,0x0ff, 0), UCG_VARX(0,0x0ff, 0), /* set x position */
UCG_C10(0x075), UCG_VARY(0,0x0ff, 0), UCG_D1(0x07f), /* set y position */
UCG_END()
};
ucg_int_t ucg_handle_ssd1351_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 */
buf[0] = 0x001; // change to 0 (cmd mode)
buf[1] = 0x015; // set x
buf[2] = 0x002; // change to 1 (arg mode)
buf[3] = 0x000; // will be overwritten by x/y value
buf[4] = 0x000; // no change
buf[5] = 0x07f; // max value
buf[6] = 0x001; // change to 0 (cmd mode)
buf[7] = 0x05c; // 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
buf[14] = 0x001; // change to 0 (cmd mode)
buf[15] = 0x05c; // change to 0 (cmd mode)
switch(ucg->arg.dir)
{
case 0:
dx = 1; dy = 0;
buf[1] = 0x015;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_for_x_seq);
break;
case 1:
dx = 0; dy = 1;
buf[1] = 0x075;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_for_y_seq);
break;
case 2:
dx = -1; dy = 0;
buf[1] = 0x015;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_for_x_seq);
break;
case 3:
default:
dx = 0; dy = -1;
buf[1] = 0x075;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_for_y_seq);
break;
}
pixmap = ucg_pgm_read(ucg->arg.bitmap);
bitcnt = ucg->arg.pixel_skip;
pixmap <<= bitcnt;
buf[9] = ucg->arg.pixel.rgb.color[0]>>2;
buf[11] = ucg->arg.pixel.rgb.color[1]>>2;
buf[13] = ucg->arg.pixel.rgb.color[2]>>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[3] = ucg->arg.pixel.pos.x;
}
else
{
buf[3] = ucg->arg.pixel.pos.y;
}
//ucg_com_SendCmdSeq(ucg, seq);
//buf[0] = ucg->arg.pixel.rgb.color[0]>>2;
//buf[1] = ucg->arg.pixel.rgb.color[1]>>2;
//buf[2] = ucg->arg.pixel.rgb.color[2]>>2;
//ucg_com_SendRepeat3Bytes(ucg, 1, buf);
ucg_com_SendCmdDataSequence(ucg, 7, buf, 1);
//ucg_com_SetCDLineStatus(ucg, 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;
}
ucg_int_t ucg_handle_ssd1351_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 */
switch(ucg->arg.dir)
{
case 0:
case 1:
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);
}
break;
default:
for ( i = 0; i < 3; i++ )
{
ucg_ccs_init(ucg->arg.ccs_line+i, ucg->arg.rgb[1].color[i], ucg->arg.rgb[0].color[i], ucg->arg.len);
}
break;
}
/* 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;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir0_seq);
break;
case 1: dx = 0; dy = 1;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir1_seq);
break;
case 2: dx = 1; dy = 0;
ucg->arg.pixel.pos.x -= ucg->arg.len;
ucg->arg.pixel.pos.x++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir0_seq);
break;
case 3: dx = 0; dy = 1;
ucg->arg.pixel.pos.y -= ucg->arg.len;
ucg->arg.pixel.pos.y++;
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir1_seq);
break;
default: dx = 1; dy = 0; break; /* avoid compiler warning */
}
for( i = 0; i < ucg->arg.len; i++ )
{
c[0] = ucg->arg.ccs_line[0].current >> 2;
c[1] = ucg->arg.ccs_line[1].current >> 2;
c[2] = ucg->arg.ccs_line[2].current >> 2;
ucg_com_SendRepeat3Bytes(ucg, 1, c);
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);
}
}
ucg_com_SetCSLineStatus(ucg, 1); /* disable chip */
return 1;
}
return 0;
}
static const ucg_pgm_uint8_t ucg_ssd1351_power_down_seq[] = {
UCG_CS(0), /* enable chip */
UCG_C11(0x0c7, 0x000), /* Set Master Contrast (0..15), reset default: 0x05 */
UCG_C10(0x0ae), /* Set Display Off */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ic_ssd1351_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, 50, 300);
case UCG_MSG_DEV_POWER_DOWN:
ucg_com_SendCmdSeq(ucg, ucg_ssd1351_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_com_SendCmdSeq(ucg, ucg_ssd1351_set_pos_dir0_seq);
c[0] = ucg->arg.pixel.rgb.color[0]>>2;
c[1] = ucg->arg.pixel.rgb.color[1]>>2;
c[2] = ucg->arg.pixel.rgb.color[2]>>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_ssd1351_18);
ucg_handle_ssd1351_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
//ucg_handle_l90tc(ucg, ucg_dev_ic_ssd1351_18);
ucg_handle_ssd1351_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_ssd1351_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_ssd1351_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
//ucg_handle_l90se(ucg, ucg_dev_ic_ssd1351_18);
ucg_handle_ssd1351_l90se(ucg);
break;
}
return 1;
}
\ No newline at end of file
/*
ucg_dev_ic_st7735.c
Specific code for the st7735 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"
const ucg_pgm_uint8_t ucg_st7735_set_pos_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C11( 0x036, 0x000),
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_A2(0x000, 0x07f), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_A2(0x000, 0x09f), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_st7735_set_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x000 horizontal increment (dir = 0) */
/* 0x000 vertical increment (dir = 1) */
/* 0x040 horizontal deccrement (dir = 2) */
/* 0x080 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x000),
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_A2(0x000, 0x07f), /* set x position */
UCG_C10(0x02b), UCG_VARY(0,0x00, 0), UCG_VARY(0,0x0ff, 0), UCG_A2(0x000, 0x09f), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_st7735_set_pos_dir1_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x000 horizontal increment (dir = 0) */
/* 0x000 vertical increment (dir = 1) */
/* 0x040 horizontal deccrement (dir = 2) */
/* 0x080 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x000),
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_A2(0x000, 0x09f), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_st7735_set_pos_dir2_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x000 horizontal increment (dir = 0) */
/* 0x000 vertical increment (dir = 1) */
/* 0x040 horizontal deccrement (dir = 2) */
/* 0x080 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x040),
UCG_C11( 0x036, 0x040), /* it seems that this command needs to be sent twice */
UCG_C10(0x02a), UCG_VARX(0,0x00, 0), UCG_VARX(0,0x0ff, 0), UCG_A2(0x000, 0x07f), /* set x position */
UCG_C10(0x02b), UCG_VARY(8,0x01, 0), UCG_VARY(0,0x0ff, 0), UCG_A2(0x000, 0x09f), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
const ucg_pgm_uint8_t ucg_st7735_set_pos_dir3_seq[] =
{
UCG_CS(0), /* enable chip */
/* 0x000 horizontal increment (dir = 0) */
/* 0x000 vertical increment (dir = 1) */
/* 0x0c0 horizontal deccrement (dir = 2) */
/* 0x0c0 vertical deccrement (dir = 3) */
UCG_C11( 0x036, 0x080),
UCG_C11( 0x036, 0x080), /* 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_A2(0x000, 0x09f), /* set y position */
UCG_C10(0x02c), /* write to RAM */
UCG_DATA(), /* change to data mode */
UCG_END()
};
ucg_int_t ucg_handle_st7735_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_com_SendCmdSeq(ucg, ucg_st7735_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_st7735_set_pos_dir1_seq);
break;
case 2:
tmp = ucg->arg.pixel.pos.x;
ucg->arg.pixel.pos.x = 127-tmp;
ucg_com_SendCmdSeq(ucg, ucg_st7735_set_pos_dir2_seq);
ucg->arg.pixel.pos.x = tmp;
break;
case 3:
default:
tmp = ucg->arg.pixel.pos.y;
ucg->arg.pixel.pos.y = 159-tmp;
ucg_com_SendCmdSeq(ucg, ucg_st7735_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_st7735_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_com_SendCmdSeq(ucg, ucg_st7735_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_st7735_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_com_SendCmdSeq(ucg, ucg_st7735_set_pos_dir0_seq);
break;
case 1:
ucg_com_SendCmdSeq(ucg, ucg_st7735_set_pos_dir1_seq);
break;
case 2:
tmp = ucg->arg.pixel.pos.x;
ucg->arg.pixel.pos.x = 127-tmp;
ucg_com_SendCmdSeq(ucg, ucg_st7735_set_pos_dir2_seq);
ucg->arg.pixel.pos.x = tmp;
break;
case 3:
default:
tmp = ucg->arg.pixel.pos.y;
ucg->arg.pixel.pos.y = 159-tmp;
ucg_com_SendCmdSeq(ucg, ucg_st7735_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_st7735_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_st7735_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_st7735_power_down_seq);
return 1;
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 160;
return 1;
case UCG_MSG_DRAW_PIXEL:
if ( ucg_clip_is_pixel_visible(ucg) !=0 )
{
uint8_t c[3];
ucg_com_SendCmdSeq(ucg, ucg_st7735_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_st7735_18);
ucg_handle_st7735_l90fx(ucg);
return 1;
#ifdef UCG_MSG_DRAW_L90TC
case UCG_MSG_DRAW_L90TC:
//ucg_handle_l90tc(ucg, ucg_dev_ic_st7735_18);
ucg_handle_st7735_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_st7735_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_st7735_18(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DRAW_L90SE:
//ucg_handle_l90se(ucg, ucg_dev_ic_st7735_18);
ucg_handle_st7735_l90se(ucg);
break;
}
return 1;
}
\ No newline at end of file
/*
ucg_dev_msg_api.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"
#include <stddef.h>
void ucg_PowerDown(ucg_t *ucg)
{
if ( ucg->is_power_up != 0 )
{
ucg->device_cb(ucg, UCG_MSG_DEV_POWER_DOWN, NULL);
ucg->is_power_up = 0;
}
}
ucg_int_t ucg_PowerUp(ucg_t *ucg)
{
ucg_int_t r;
/* power down first. will do nothing if power is already down */
ucg_PowerDown(ucg);
/* now try to power up the display */
r = ucg->device_cb(ucg, UCG_MSG_DEV_POWER_UP, NULL);
if ( r != 0 )
{
ucg->is_power_up = 1;
}
return r;
}
void ucg_SetClipBox(ucg_t *ucg, ucg_box_t *clip_box)
{
ucg->device_cb(ucg, UCG_MSG_SET_CLIP_BOX, (void *)(clip_box));
}
void ucg_SetClipRange(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
{
ucg_box_t clip_box;
clip_box.ul.x = x;
clip_box.ul.y = y;
clip_box.size.w = w;
clip_box.size.h = h;
ucg_SetClipBox(ucg, &clip_box);
}
void ucg_SetMaxClipRange(ucg_t *ucg)
{
ucg_box_t new_clip_box;
new_clip_box.size = ucg->dimension;
new_clip_box.ul.x = 0;
new_clip_box.ul.y = 0;
ucg_SetClipBox(ucg, &new_clip_box);
}
/*
Query the display dimension from the driver, reset clip window to maximum
new dimension
*/
void ucg_GetDimension(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_GET_DIMENSION, &(ucg->dimension));
ucg_SetMaxClipRange(ucg);
}
void ucg_DrawPixelWithArg(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_DRAW_PIXEL, NULL);
}
void ucg_DrawL90FXWithArg(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_DRAW_L90FX, &(ucg->arg));
}
#ifdef UCG_MSG_DRAW_L90TC
void ucg_DrawL90TCWithArg(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_DRAW_L90TC, &(ucg->arg));
}
#endif /* UCG_MSG_DRAW_L90TC */
#ifdef UCG_MSG_DRAW_L90BF
void ucg_DrawL90BFWithArg(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_DRAW_L90BF, &(ucg->arg));
}
#endif /* UCG_MSG_DRAW_L90BF */
void ucg_DrawL90SEWithArg(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_DRAW_L90SE, &(ucg->arg));
}
/*
void ucg_DrawL90RLWithArg(ucg_t *ucg)
{
ucg->device_cb(ucg, UCG_MSG_DRAW_L90RL, &(ucg->arg));
}
*/
/*
ucg_dev_oled_128x128_ft.c
Specific code for the FREETRONIC 128x128 OLED module
(differs from the ILSOFT only by GPIO output)
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 uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_ft_ssd1351_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(1),
UCG_RST(0),
UCG_DLY_MS(1),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
//UCG_C11(0x0fd, 0x012), /* Unlock normal commands, reset default: unlocked */
UCG_C11(0x0fd, 0x0b1), /* Unlock extra commands, reset default: locked */
//UCG_C10(0x0ae), /* Set Display Off */
UCG_C10(0x0af), /* Set Display On */
UCG_C10(0x0a6), /* Set Display Mode Reset */
UCG_C11(0x0a0, 0x0b4), /* Set Colour Depth */
UCG_C11(0x0a1, 0x000), /* Set Display Start Line */
UCG_C11(0x0a2, 0x000), /* Set Display Offset */
UCG_C12(0x015, 0x000, 0x07f), /* Set Column Address */
UCG_C12(0x075, 0x000, 0x07f), /* Set Row Address */
UCG_C11(0x0b3, 0x0f1), /* Front Clock Div */
//UCG_C11(0x0ca, 0x07f), /* Set Multiplex Ratio, reset default: 0x7f */
UCG_C11(0x0b5, 0x003), /* Set GPIO for Freetronics OLED Module */
//UCG_C11(0x0ab, 0x001), /* Set Function Selection, reset default: 0x01 */
UCG_C11(0x0b1, 0x032), /* Set Phase Length, reset default: 0x82 */
UCG_C13(0x0b4, 0xa0,0xb5,0x55), /* Set Segment Low Voltage, reset default: 0xa2 0xb5 0x55 */
//UCG_C11(0x0bb, 0x017), /* Set Precharge Voltage, reset default: 0x17 */
//UCG_C11(0x0be, 0x005), /* Set VComH Voltage, reset default: 0x05 */
UCG_C13(0x0c1, 0xc8, 0x80, 0xc8), /* Set Contrast */
UCG_C11(0x0c7, 0x00f), /* Set Master Contrast (0..15), reset default: 0x05 */
UCG_C11(0x0b6, 0x001), /* Set Second Precharge Period */
// UCG_C10(0x0b8), /* Set CMD Grayscale Lookup, 63 Bytes follow */
// UCG_A8(0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c),
// UCG_A8(0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14),
// UCG_A8(0x15,0x16,0x18,0x1a,0x1b,0x1C,0x1D,0x1F),
// UCG_A8(0x21,0x23,0x25,0x27,0x2A,0x2D,0x30,0x33),
// UCG_A8(0x36,0x39,0x3C,0x3F,0x42,0x45,0x48,0x4C),
// UCG_A8(0x50,0x54,0x58,0x5C,0x60,0x64,0x68,0x6C),
// UCG_A8(0x70,0x74,0x78,0x7D,0x82,0x87,0x8C,0x91),
// UCG_A7(0x96,0x9B,0xA0,0xA5,0xAA,0xAF,0xB4),
UCG_C10(0x05c), /* Write RAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ssd1351_18x128x128_ft(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ssd1351_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_ft_ssd1351_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ssd1351_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 128;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ssd1351_18(ucg, msg, data);
}
/*
ucg_dev_oled_128x128_ilsoft.c
Specific code for the ILSOFT 128x128 OLED module
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 uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_ilsoft_ssd1351_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(1),
UCG_RST(0),
UCG_DLY_MS(1),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
//UCG_C11(0x0fd, 0x012), /* Unlock normal commands, reset default: unlocked */
UCG_C11(0x0fd, 0x0b1), /* Unlock extra commands, reset default: locked */
//UCG_C10(0x0ae), /* Set Display Off */
UCG_C10(0x0af), /* Set Display On */
UCG_C10(0x0a6), /* Set Display Mode Reset */
UCG_C11(0x0a0, 0x0b4), /* Set Colour Depth */
UCG_C11(0x0a1, 0x000), /* Set Display Start Line */
UCG_C11(0x0a2, 0x000), /* Set Display Offset */
UCG_C12(0x015, 0x000, 0x07f), /* Set Column Address */
UCG_C12(0x075, 0x000, 0x07f), /* Set Row Address */
UCG_C11(0x0b3, 0x0f1), /* Front Clock Div */
//UCG_C11(0x0ca, 0x07f), /* Set Multiplex Ratio, reset default: 0x7f */
UCG_C11(0x0b5, 0x000), /* Set GPIO */
//UCG_C11(0x0ab, 0x001), /* Set Function Selection, reset default: 0x01 */
UCG_C11(0x0b1, 0x032), /* Set Phase Length, reset default: 0x82 */
UCG_C13(0x0b4, 0xa0,0xb5,0x55), /* Set Segment Low Voltage, reset default: 0xa2 0xb5 0x55 */
//UCG_C11(0x0bb, 0x017), /* Set Precharge Voltage, reset default: 0x17 */
//UCG_C11(0x0be, 0x005), /* Set VComH Voltage, reset default: 0x05 */
UCG_C13(0x0c1, 0xc8, 0x80, 0xc8), /* Set Contrast */
UCG_C11(0x0c7, 0x00f), /* Set Master Contrast (0..15), reset default: 0x05 */
UCG_C11(0x0b6, 0x001), /* Set Second Precharge Period */
// UCG_C10(0x0b8), /* Set CMD Grayscale Lookup, 63 Bytes follow */
// UCG_A8(0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c),
// UCG_A8(0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14),
// UCG_A8(0x15,0x16,0x18,0x1a,0x1b,0x1C,0x1D,0x1F),
// UCG_A8(0x21,0x23,0x25,0x27,0x2A,0x2D,0x30,0x33),
// UCG_A8(0x36,0x39,0x3C,0x3F,0x42,0x45,0x48,0x4C),
// UCG_A8(0x50,0x54,0x58,0x5C,0x60,0x64,0x68,0x6C),
// UCG_A8(0x70,0x74,0x78,0x7D,0x82,0x87,0x8C,0x91),
// UCG_A7(0x96,0x9B,0xA0,0xA5,0xAA,0xAF,0xB4),
UCG_C10(0x05c), /* Write RAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ssd1351_18x128x128_ilsoft(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ssd1351_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_ilsoft_ssd1351_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ssd1351_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 128;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ssd1351_18(ucg, msg, data);
}
/*
ucg_dev_oled_128x128_univision.c
Specific code for the Univision 1.5" OLED (UG2828, 128x128 pixel, 65K Colors, SEPS225)
Note: Only 65K color support, because 262K mode is not possible with 8 Bit SPI.
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"
/* the following code is from the UG2828GDEAF02 Datasheet */
static const ucg_pgm_uint8_t aaa_ucg_univision_seps225_init_seq[] = {
UCG_CFG_CD(0,1), /* First arg: level for commands, Second arg: level for command arguments */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(1),
UCG_RST(0),
UCG_DLY_MS(1),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C11(0x002, 0x001), /* OSC_CTL: external resistor, internal OSC */
UCG_C11(0x004, 0x000), /* REDUCE_CURRENT: normal operation, no current reduction */
UCG_C11(0x003, 0x030), /* CLK_DIV: 90Hz, ratio 1 */
UCG_C11(0x008, 0x000), /* Precharge time red */
UCG_C11(0x009, 0x000), /* Precharge time green */
UCG_C11(0x00a, 0x000), /* Precharge time blue */
UCG_C11(0x00b, 0x000), /* Precharge current red */
UCG_C11(0x00c, 0x000), /* Precharge current green */
UCG_C11(0x00d, 0x000), /* Precharge current blue */
UCG_C11(0x010, 0x04a), /* Driving current red */
UCG_C11(0x011, 0x025), /* Driving current green, original value 0x011 replaced by 0x025 */
UCG_C11(0x012, 0x02f), /* Driving current blue */
UCG_C11(0x013, 0x000), /* Display mode: RGB,column=0..127,column data display control=Normal Dispaly */
UCG_C11(0x014, 0x001), /* External interface: 18 bit, MPU, Bit size does not matter if MPU is selected*/
//UCG_C11(0x016, 0x076), /* Memory Mode: 6bits triple transfer (would require 6bit words on SPI, 262K support, horizontal inc., vertical inc., data continuously written horizontally */
UCG_C11(0x016, 0x066), /* Memory Mode: dual transfer (2x 8Bit), 65K support, horizontal inc., vertical inc., data continuously written horizontally */
/* memory window */
UCG_C11(0x017, 0x000), /* x0 */
UCG_C11(0x018, 0x07f), /* x1 */
UCG_C11(0x019, 0x000), /* y0 */
UCG_C11(0x01a, 0x07f), /* y1 */
/* memory start */
UCG_C11(0x020, 0x000), /* x */
UCG_C11(0x021, 0x000), /* y */
UCG_C11(0x028, 0x07f), /* Duty */
UCG_C11(0x029, 0x000), /* Display start line */
/* DDRAM start */
UCG_C11(0x02e, 0x000), /* x */
UCG_C11(0x02f, 0x000), /* y */
UCG_C11(0x033, 0x000), /* Display Screen Saver x0 */
UCG_C11(0x034, 0x07f), /* Display Screen Saver x1 */
UCG_C11(0x035, 0x000), /* Display Screen Saver y0 */
UCG_C11(0x036, 0x07f), /* Display Screen Saver y1 */
UCG_C11(0x080, 0x000), /* IREF: External */
UCG_DLY_MS(100), /* as suggested in the Univision manual */
UCG_C11(0x006, 0x001), /* Display on */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
/* init seq. from the .ino example from ZhangFeng, PRC. http://vfdclock.jimdo.com */
static const ucg_pgm_uint8_t ucg_univision_seps225_init_seq[] = {
UCG_CFG_CD(0,1), /* First arg: level for commands, Second arg: level for command arguments */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(1),
UCG_RST(0),
UCG_DLY_MS(1),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C11(0x006, 0x000), /* Display off */
UCG_C11(0x002, 0x001), /* OSC_CTL: external resistor, internal OSC */
UCG_C11(0x004, 0x000), /* REDUCE_CURRENT: normal operation, no current reduction */
UCG_C11(0x003, 0x030), /* CLK_DIV: 90Hz, ratio 1 */
UCG_C11(0x005, 0x000), /* Software Reset */
UCG_C11(0x008, 0x003), /* Precharge time red */
UCG_C11(0x009, 0x004), /* Precharge time green */
UCG_C11(0x00a, 0x005), /* Precharge time blue */
UCG_C11(0x00b, 0x00b), /* Precharge current red */
UCG_C11(0x00c, 0x00b), /* Precharge current green */
UCG_C11(0x00d, 0x00e), /* Precharge current blue */
UCG_C11(0x010, 0x03e), /* Driving current red */
UCG_C11(0x011, 0x032), /* Driving current green, original value 0x011 replaced by 0x025 */
UCG_C11(0x012, 0x03d), /* Driving current blue */
UCG_C11(0x013, 0x000), /* Display mode: RGB,column=0..127,column data display control=Normal Dispaly */
UCG_C11(0x014, 0x001), /* External interface: 18 bit, MPU, Bit size does not matter if MPU is selected*/
//UCG_C11(0x016, 0x076), /* Memory Mode: 6bits triple transfer (would require 6bit words on SPI, 262K support, horizontal inc., vertical inc., data continuously written horizontally */
UCG_C11(0x015, 0x000),
UCG_C11(0x016, 0x066), /* Memory Mode: dual transfer (2x 8Bit), 65K support, horizontal inc., vertical inc., data continuously written horizontally */
/* memory window */
UCG_C11(0x017, 0x000), /* x0 */
UCG_C11(0x018, 0x07f), /* x1 */
UCG_C11(0x019, 0x000), /* y0 */
UCG_C11(0x01a, 0x07f), /* y1 */
/* memory start */
UCG_C11(0x020, 0x000), /* x */
UCG_C11(0x021, 0x000), /* y */
UCG_C11(0x028, 0x07f), /* Duty */
UCG_C11(0x029, 0x000), /* Display start line */
/* DDRAM start */
UCG_C11(0x02e, 0x000), /* x */
UCG_C11(0x02f, 0x000), /* y */
UCG_C11(0x031, 0x000),
UCG_C11(0x032, 0x000),
UCG_C11(0x033, 0x000), /* Display Screen Saver x0 */
UCG_C11(0x034, 0x07f), /* Display Screen Saver x1 */
UCG_C11(0x035, 0x000), /* Display Screen Saver y0 */
UCG_C11(0x036, 0x07f), /* Display Screen Saver y1 */
UCG_C11(0x080, 0x000), /* IREF: External */
UCG_DLY_MS(100), /* as suggested in the Univision manual */
UCG_C11(0x006, 0x001), /* Display on */
//UCG_C10(0x022),
UCG_CS(1), /* disable chip */
//UCG_DATA(),
UCG_END(), /* end of sequence */
};
static const ucg_pgm_uint8_t ucg_seps255_pos_dir0_seq[] =
{
UCG_CS(0), /* enable chip */
UCG_C11(0x016, 0x066), /* Memory Mode */
UCG_C11(0x020, 0), /* set x position */
UCG_C11(0x021, 0), /* set y position */
UCG_C10(0x022), /* prepare for data */
UCG_DATA(), /* change to data mode */
UCG_END()
};
ucg_int_t ucg_dev_seps225_16x128x128_univision(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_seps225_16(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_univision_seps225_init_seq);
/* demonstration of the OLED error */
/*
{
uint8_t r,g,b, i;
uint8_t c[3];
ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
r = 0;
g = 0;
b = 80;
c[0] = (r&0x0f8) | (((g) >>5));
c[1] = ((((g))<<3)&0x0e0) | (((b) >>3));
ucg_com_SendRepeat2Bytes(ucg, 128, c);
r = 0;
g = 0;
b = 0;
c[0] = (r&0x0f8) | (((g) >>5));
c[1] = ((((g))<<3)&0x0e0) | (((b) >>3));
for( i = 0; i < 126; i++ )
{
ucg_com_SendRepeat2Bytes(ucg, 128, c);
}
r = 0;
g = 0;
b = 255;
c[0] = (r&0x0f8) | (((g) >>5));
c[1] = ((((g))<<3)&0x0e0) | (((b) >>3));
ucg_com_SendRepeat2Bytes(ucg, 40, c);
for(;;)
;
}
*/
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the controller procedures */
return ucg_dev_ic_seps225_16(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 128;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_seps225_16(ucg, msg, data);
}
/*
ucg_dev_oled_160x128_samsung.c
Specific code for the Samsung 160x128 OLED (LD50T6160 Controller)
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"
/*
Samsung 1.8" OLED
VCC_R (4) connected to 4.7uF
VCC_R1 (41) connected to 4.7uF
VCC connected to 18V
VCC3 connected to 18V
==> Internal regulator mit be enabled
==> DC-DC must be switched off
From the Samsung 1.8" OLED datasheet:
PREC_WIDTH = 06h, (pre charge width?)
PEAKDELAY = 01h,
Frame Freq.(*1)) = 02h(90Hz)
Red : PEAKWIDTH = 03h,
Green : PEAKWIDTH = 05h,
Blue : PEAKWIDTH = 03h
Red : DOT CURRENT = 9Ah,
Green : DOT CURRENT = 5Ch,
Blue : DOT CURRENT = B1h
*/
static const ucg_pgm_uint8_t ucg_samsung_160x128_init_seq[] = {
/* init sequence for the Samsung OLED with LD50T6160 controller */
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(1),
UCG_RST(0),
UCG_DLY_MS(1),
UCG_RST(1),
UCG_DLY_MS(150),
UCG_CS(0), /* enable chip */
UCG_C10(0x01), /* software reset */
UCG_C11(0x02, 0x00), /* display on/off: display off */
UCG_C11(0x03, 0x00), /* standby off, OSCA start */
UCG_C11(0x04, 0x02), /* set frame rate: 0..7, 60Hz to 150Hz, default is 2=90Hz */
UCG_C11(0x05, 0x00), /* write dir, bit 3: RGB/BGR */
UCG_C11(0x06, 0x00), /* row scan dir (0=default) */
UCG_C11(0x06, 0x00), /* row scan dir (0=default) */
UCG_C10(0x07), /* set screen size */
UCG_A2(0x00, 0x00), /* x min = 0 */
UCG_A2(0x07, 0x0f), /* x max = 127 */
UCG_A2(0x00, 0x00), /* y min = 0 */
UCG_A2(0x09, 0x0f), /* y max = 159 */
UCG_C11(0x08, 0x00), /* interface bus width: 6 bit */
UCG_C11(0x09, 0x07), /* no data (RGB) masking (default) */
UCG_C10(0x0a), /* write box (probably not req. during init */
UCG_A2(0x00, 0x00), /* x min = 0 */
UCG_A2(0x07, 0x0f), /* x max = 127 */
UCG_A2(0x00, 0x00), /* y min = 0 */
UCG_A2(0x09, 0x0f), /* y max = 159 */
UCG_C10(0x0e), /* set some minimal dot current first */
UCG_A2(0x00, 0x03), /* red */
UCG_A2(0x00, 0x03), /* green */
UCG_A2(0x00, 0x03), /* blue */
UCG_C11(0x1b, 0x03), /* Pre-Charge Mode Select:Enable Pre-Charge and Peakboot for the Samsung OLED */
UCG_C12(0x1c, 0x00, 0x06), /* Pre-Charge Width, Samsung OLED: 0x06, controller default is 0x08 */
UCG_C10(0x1d), /* Peak Pulse Width Set */
UCG_A2(0x00, 0x03), /* red */
UCG_A2(0x00, 0x05), /* green */
UCG_A2(0x00, 0x03), /* blue */
UCG_C11(0x1e, 0x01), /* Peak Pulse Delay Set, Samsung OLED: 0x01, controller default is 0x05 */
/*
Row Scan Operation Set (cmd 0x1f)
bits 0, 1: scan mode
mode 00: alternate scan mode (Oliver: not sure if this is true, prob. this is seq. mode)
mode 01: seq. scan mode (Oliver: could be mode 00)
mode 10: simultaneous scan mode (Oliver: No idea what this is)
Samsung OLED: probably mode 00
bit 3:
if set to 1, then all rows are connected to GND
Samsung OLED: must be 0 for normal operation
bit 4,5: row timing setting
00: none
01: pre charge
10: pre charge + peak delay
11: pre charge + peak delay + peak boot
Samsung OLED: No idea, maybe 11 must be set here
*/
UCG_C11(0x1f, 0x30), /* Samsung OLED: pre charge + peak delay + peak boot */
UCG_C11(0x2d, 0x00), /* Write data through system interface (bit 4 = 0) */
/*
ICON Display control
bit 0/1 = 01: ALL ICON ON
bit 0/1 = 10: normal display mode (depends on ICON data)
*/
UCG_C11(0x20, 0x01), /* ICON Display control */
UCG_C11(0x21, 0x00), /* ICON Stand-by Setting, bit 0 = 0: no standby, start OSCB */
UCG_C11(0x29, 0x00), /* DC-DC Control for ICON: bit 0&1 = 01: stop DC-DC, use VICON (Samsung OLED has external 18V) */
UCG_C11(0x2a, 0x04), /* ICON Frame Frequency Set: 89Hz */
UCG_C11(0x30, 0x13), /* Internal Regulator for Row Scan, value taken from Samsung OLED flow chart */
/*
Set full dot current
Red : DOT CURRENT = 9Ah,
Green : DOT CURRENT = 5Ch,
Blue : DOT CURRENT = B1h
*/
UCG_DLY_MS(10),
UCG_C10(0x0e), /* set dot current */
UCG_A2(0x09, 0x0a), /* red */
UCG_A2(0x05, 0x0c), /* green */
UCG_A2(0x0b, 0x01), /* blue */
UCG_DLY_MS(10),
UCG_C11(0x02, 0x01), /* Display on */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ld50t6160_18x160x128_samsung(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ld50t6160_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_samsung_160x128_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the controller procedures */
return ucg_dev_ic_ld50t6160_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 160;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ld50t6160_18(ucg, msg, data);
}
/*
ucg_dev_oled_96x64_univision.c
Specific code for the Univision 0.95" OLED (UG-9664, 96x94 pixel, 65536 Colors, SSD1331)
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"
static const ucg_pgm_uint8_t ucg_univision_ssd1331_init_seq[] = {
UCG_CFG_CD(0,0), /* First arg: level for commands, Second arg: level for command arguments */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(1),
UCG_RST(0),
UCG_DLY_MS(1),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
//UCG_C11(0x0fd, 0x012), /* Unlock normal commands, reset default: unlocked */
UCG_C10(0x0ae), /* Set Display Off */
//UCG_C10(0x0af), /* Set Display On */
UCG_C11(0x0a0, 0x0b2), /* 65k format 2, RGB Mode */
UCG_C11(0x0a1, 0x000), /* Set Display Start Line */
UCG_C11(0x0a2, 0x000), /* Set Display Offset */
UCG_C11(0x0a8, 0x03f), /* Multiplex, reset value = 0x03f */
UCG_C11(0x0ad, 0x08e), /* select supply (must be set before 0x0af) */
UCG_C11(0x0b0, 0x00b), /* Disable power save mode */
UCG_C11(0x0b1, 0x031), /* Set Phase Length, reset default: 0x74 */
UCG_C11(0x0b3, 0x0f0), /* Display Clock Divider/Osc, reset value=0x0d0 */
UCG_C12(0x015, 0x000, 0x05f), /* Set Column Address */
UCG_C12(0x075, 0x000, 0x03f), /* Set Row Address */
UCG_C11(0x081, 0x080), /* contrast red, Adafruit: 0x091, UC9664: 0x080 */
UCG_C11(0x082, 0x080), /* contrast green, Adafruit: 0x050, UC9664: 0x080 */
UCG_C11(0x083, 0x080), /* contrast blue, Adafruit: 0x07d, UC9664: 0x080 */
UCG_C11(0x087, 0x00f), /* master current/contrast 0x00..0x0f UG-9664: 0x0f, Adafruit: 0x06 */
UCG_C11(0x08a, 0x064), /* second precharge speed red */
UCG_C11(0x08b, 0x078), /* second precharge speed green */
UCG_C11(0x08c, 0x064), /* second precharge speed blue */
UCG_C11(0x0bb, 0x03c), /* set shared precharge level, default = 0x03e */
UCG_C11(0x0be, 0x03e), /* voltage select, default = 0x03e */
UCG_C10(0x0b9), /* Reset internal grayscale lookup */
// UCG_C10(0x0b8), /* Set CMD Grayscale Lookup, 63 Bytes follow */
// UCG_A8(0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c),
// UCG_A8(0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14),
// UCG_A8(0x15,0x16,0x18,0x1a,0x1b,0x1C,0x1D,0x1F),
// UCG_A8(0x21,0x23,0x25,0x27,0x2A,0x2D,0x30,0x33),
// UCG_A8(0x36,0x39,0x3C,0x3F,0x42,0x45,0x48,0x4C),
// UCG_A8(0x50,0x54,0x58,0x5C,0x60,0x64,0x68,0x6C),
// UCG_A8(0x70,0x74,0x78,0x7D,0x82,0x87,0x8C,0x91),
// UCG_A7(0x96,0x9B,0xA0,0xA5,0xAA,0xAF,0xB4),
UCG_C10(0x0a4), /* Normal display mode */
UCG_C10(0x0af), /* Set Display On */
//UCG_C12(0x015, 0x030, 0x05f), /* Set Column Address */
//UCG_C12(0x075, 0x010, 0x03f), /* Set Row Address */
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
//UCG_D3(0x0ff, 0, 0),
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ssd1331_18x96x64_univision(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ssd1331_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_univision_ssd1331_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the controller procedures */
return ucg_dev_ic_ssd1331_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 96;
((ucg_wh_t *)data)->h = 64;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ssd1331_18(ucg, msg, data);
}
/*
ucg_dev_tft_128x128_ili9163.c
ILI9341 with 4-Wire SPI (SCK, SDI, CS, D/C and optional reset)
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"
static const ucg_pgm_uint8_t ucg_tft_128x128_ili9163_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C10(0x011), /* sleep out */
UCG_DLY_MS(10),
//UCG_C10(0x038), /* idle mode off */
UCG_C10(0x013), /* normal display on */
//UCG_C14(0x0ed, 0x055, 0x001, 0x023, 0x001), /* power on sequence control (POR values) */
//UCG_C11(0x0f7, 0x020), /* pump ratio control (POR value) */
UCG_C10(0x20), /* not inverted */
//UCG_C10(0x21), /* inverted */
UCG_C11(0x03a, 0x066), /* set pixel format to 18 bit */
//UCG_C11(0x03a, 0x055), /* set pixel format to 16 bit */
//UCG_C12(0x0b1, 0x000, 0x01b), /* frame rate control (POR values) */
//UCG_C14(0x0b6, 0x00a, 0x082 | (1<<5), 0x027, 0x000), /* display function control (POR values, except for shift direction bit) */
//UCG_C11(0x0b7, 0x006), /* entry mode, bit 0: Low voltage detection control (0=off) */
UCG_C12(0x0c0, 0x00a, 0x002), /* power control 1 */
UCG_C11(0x0c1, 0x002), /* power control 2 (step up factor), POR=2 */
UCG_C11(0x0c7, 0x0d0), /* VCOM control 2, enable VCOM control 1 */
UCG_C12(0x0c5, 0x040, 0x04a), /* VCOM control 1, POR=31,3C */
// UCG_C15(0x0cb, 0x039, 0x02c, 0x000, 0x034, 0x002), /* power control A (POR values) */
// UCG_C13(0x0cf, 0x000, 0x081, 0x030), /* power control B (POR values) */
// UCG_C13(0x0e8, 0x084, 0x011, 0x07a), /* timer driving control A (POR values) */
// UCG_C12(0x0ea, 0x066, 0x000), /* timer driving control B (POR values) */
//UCG_C12(0x0ea, 0x000, 0x000), /* timer driving control B */
//UCG_C10(0x28), /* display off */
//UCG_C11(0x0bf, 0x003), /* backlight control 8 */
UCG_C10(0x029), /* display on */
//UCG_C11(0x051, 0x07f), /* brightness */
//UCG_C11(0x053, 0x02c), /* control brightness */
//UCG_C10(0x028), /* display off */
UCG_C11( 0x036, 0x008),
UCG_C14( 0x02a, 0x000, 0x000, 0x000, 0x07f), /* Horizontal GRAM Address Set */
UCG_C14( 0x02b, 0x000, 0x000, 0x000, 0x07f), /* Vertical GRAM Address Set */
UCG_C10( 0x02c), /* Write Data to GRAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ili9163_18x128x128(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ili9163_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_128x128_ili9163_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ili9163_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 128;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ili9163_18(ucg, msg, data);
}
/*
ucg_dev_tft_128x160_st7735.c
ST7735 with 4-Wire SPI (SCK, SDI, CS, D/C and optional reset)
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 uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_tft_128x160_st7735_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C10(0x011), /* sleep out */
UCG_DLY_MS(10),
//UCG_C10(0x038), /* idle mode off */
UCG_C10(0x013), /* normal display on */
UCG_C10(0x20), /* not inverted */
//UCG_C10(0x21), /* inverted */
UCG_C11(0x03a, 0x006), /* set pixel format to 18 bit */
//UCG_C11(0x03a, 0x005), /* set pixel format to 16 bit */
//UCG_C12(0x0b1, 0x000, 0x01b), /* frame rate control (POR values) */
//UCG_C10(0x28), /* display off */
//UCG_C11(0x0bf, 0x003), /* backlight control 8 */
UCG_C10(0x029), /* display on */
//UCG_C11(0x051, 0x07f), /* brightness */
//UCG_C11(0x053, 0x02c), /* control brightness */
//UCG_C10(0x028), /* display off */
UCG_C11( 0x036, 0x000), /* memory control */
UCG_C14( 0x02a, 0x000, 0x000, 0x000, 0x07f), /* Horizontal GRAM Address Set */
UCG_C14( 0x02b, 0x000, 0x000, 0x000, 0x09f), /* Vertical GRAM Address Set */
UCG_C10( 0x02c), /* Write Data to GRAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_st7735_18x128x160(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_st7735_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_128x160_st7735_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_st7735_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 128;
((ucg_wh_t *)data)->h = 160;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_st7735_18(ucg, msg, data);
}
/*
ucg_dev_tft_132x132_pcf8833.c
pcf8833 with 3-Wire SPI (SCK, SDI, CS and optional reset)
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 uint8_t ucg_dev_ssd1351_132x132_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_tft_132x132_pcf8833_init_seq_OBSOLETE[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C10(0x01), /* reset */
UCG_DLY_MS(199),
UCG_C10(0x011), /* sleep out */
UCG_DLY_MS(10),
UCG_C10(0x038), /* idle mode off */
//UCG_C10(0x0b5), /* mirror */
//UCG_C10(0x0b7), /* mirror */
UCG_C10(0x013), /* normal display on */
UCG_C10(0x020), /* not inverted */
UCG_C10(0x029), /* display on */
UCG_C11(0x025, 0x03f), /* set contrast -64 ... 63 */
//UCG_C11(0x03a, 0x003), /* set pixel format to 12 bit per pixel */
UCG_C11(0x03a, 0x005),
//UCG_C10(0x003), /* booster on */
UCG_C10(0x023), /* all pixel on */
UCG_DLY_MS(199),
UCG_C10(0x013), /* normal display on */
UCG_C11( 0x036, 0x000), /* memory control */
UCG_C12( 0x02a, 0x000, 0x07f), /* Horizontal GRAM Address Set */
UCG_C12( 0x02b, 0x000, 0x07f), /* Vertical GRAM Address Set */
UCG_C10( 0x02c), /* Write Data to GRAM */
UCG_DLY_MS(10),
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
static const ucg_pgm_uint8_t ucg_tft_132x132_pcf8833_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C10(0x01), /* reset */
UCG_DLY_MS(199),
UCG_C10(0x011), /* sleep out */
UCG_C10(0x013), /* normal display on */
UCG_C10(0x020), /* not inverted */
UCG_C10(0x029), /* display on */
UCG_C11(0x025, 0x03f), /* set contrast -64 ... 63 */
//UCG_C11(0x03a, 0x003), /* set pixel format to 12 bit per pixel */
UCG_C11(0x03a, 0x005), /* set pixel format to 16 bit per pixel */
UCG_C11( 0x036, 0x000), /* memory control */
UCG_C12( 0x02a, 0x000, 0x07f), /* Horizontal GRAM Address Set */
UCG_C12( 0x02b, 0x000, 0x07f), /* Vertical GRAM Address Set */
UCG_C10( 0x02c), /* Write Data to GRAM */
// UCG_DLY_MS(10),
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_pcf8833_16x132x132(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_pcf8833_16(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_132x132_pcf8833_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_pcf8833_16(ucg, msg, data);
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_pcf8833_16(ucg, msg, data);
}
/*
ucg_dev_tft_240x320_ili9325_spi.c
Device for the ILI9325 in 8 bit SPI mode (IM3=0, IM2=1, IM1=1, IM0=1)
All commands are 8 bit width only.
1 May 2014: Currently, this is not working
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 uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_tft_240x320_ili9325_spi_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_DLY_MS(1), /* delay 1 ms */
UCG_C12(0x001,0x001, 0x000), /* Driver Output Control, bits 8 & 10 */
UCG_C12(0x002, 0x007, 0x000), /* LCD Driving Wave Control, bit 9: Set line inversion */
//UCG_C12(0x003, 0x010, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1 (16 bit transfer, 65K Mode)*/
UCG_C12(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_C12(0x004, 0x000, 0x000), /* Resize register, all 0: no resize */
UCG_C12(0x008, 0x002, 0x007), /* Display Control 2: set the back porch and front porch */
//UCG_C12(0x009, 0x000, 0x000), /* Display Control 3: normal scan */
//UCG_C12(0x00a, 0x000, 0x000), /* Display Control 4: set to "no FMARK output" */
UCG_C12(0x00c, 0x000, 0x000), /* RGB Display Interface Control 1, RIM=10 (3x6 Bit), 12 Jan 14: RIM=00 */
//UCG_C12(0x00d, 0x000, 0x000), /* Frame Maker Position */
//UCG_C12(0x00f, 0x000, 0x000), /* RGB Display Interface Control 2 */
UCG_C12(0x010, 0x000, 0x000), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB, actual setting is done below */
UCG_C12(0x011, 0x000, 0x007), /* Power Control 2: DC1[2:0], DC0[2:0], VC[2:0] */
UCG_C12(0x012, 0x000, 0x000), /* Power Control 3: VREG1OUT voltage */
UCG_C12(0x013, 0x000, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
//UCG_C12(0x007, 0x000, 0x001), /* Display Control 1: Operate, but do not display */
UCG_C12( 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
UCG_DLY_MS(100), /* delay 100 ms */ /* ITDB02 none D verion: 50ms */
UCG_C12( 0x010, 0x010, 0x090), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
/* 12. Jan 14. Prev value: 0x016, 0x090 */
/* ITDB02 none D verion: 0x010, 0x090 */
//UCG_C12( 0x010, 0x017, 0x0f0), /* Power Control 1: Setting for max quality & power consumption: SAP(Bit 12)=1, BT[3:0]=7 (max), APE (Bit 8)=1, AP=7 (max), disable sleep: SLP=0, STB=0 */
UCG_C12( 0x011, 0x002, 0x027), /* Power Control 2 VCI ration, step up circuits 1 & 2 */
UCG_DLY_MS(50), /* delay 50 ms */
UCG_C12( 0x012, 0x000, 0x01f), /* Power Control 3: VCI: External, VCI*1.80 */
/* 12. Jan 14. Prev value: 0x000, 0x00d */
UCG_DLY_MS(50), /* delay 50 ms */
UCG_C12( 0x013, 0x015, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
/* 12. Jan 14. Prev value: 0x012, 0x009 */
UCG_C12( 0x029, 0x000, 0x027), /* Power Control 7 */
/* 12. Jan 14. Prev value: 0x000, 0x00a */
UCG_C12( 0x02b, 0x000, 0x00d), /* Frame Rate: 93 */
//UCG_C12( 0x02b, 0x000, 0x00b), /* Frame Rate: 70, too less, some flicker visible */
UCG_DLY_MS(50), /* delay 50 ms */
/* Gamma Control, values from iteadstudio.com reference software on google code */
/*
UCG_C12(0x30,0x00,0x00),
UCG_C12(0x31,0x07,0x07),
UCG_C12(0x32,0x03,0x07),
UCG_C12(0x35,0x02,0x00),
UCG_C12(0x36,0x00,0x08),
UCG_C12(0x37,0x00,0x04),
UCG_C12(0x38,0x00,0x00),
UCG_C12(0x39,0x07,0x07),
UCG_C12(0x3C,0x00,0x02),
UCG_C12(0x3D,0x1D,0x04),
*/
UCG_C12( 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
UCG_C12( 0x021, 0x000, 0x000), /* Vertical GRAM Address Set */
UCG_C12( 0x050, 0x000, 0x000), /* Horizontal GRAM Start Address */
UCG_C12( 0x051, 0x000, 0x0EF), /* Horizontal GRAM End Address: 239 */
UCG_C12( 0x052, 0x000, 0x000), /* Vertical GRAM Start Address */
UCG_C12( 0x053, 0x001, 0x03F), /* Vertical GRAM End Address: 319 */
UCG_C12( 0x060, 0x0a7, 0x000), /* Driver Output Control 2, NL = 0x027 = 320 lines, GS (bit 15) = 1 */
UCG_C12( 0x061, 0x000, 0x001), /* Base Image Display Control: NDL,VLE = 0 (Disbale Vertical Scroll), REV */
//UCG_C12( 0x06a, 0x000, 0x000), /* Vertical Scroll Control */
//UCG_C12( 0x080, 0x000, 0x000), /* Partial Image 1 Display Position */
//UCG_C12( 0x081, 0x000, 0x000), /* Partial Image 1 RAM Start Address */
//UCG_C12( 0x082, 0x000, 0x000), /* Partial Image 1 RAM End Address */
//UCG_C12( 0x083, 0x000, 0x000), /* Partial Image 2 Display Position */
//UCG_C12( 0x084, 0x000, 0x000), /* Partial Image 2 RAM Start Address */
//UCG_C12( 0x085, 0x000, 0x000), /* Partial Image 2 RAM End Address */
UCG_C12( 0x090, 0x000, 0x010), /* Panel Interface Control 1 */
UCG_C12( 0x092, 0x000, 0x000), /* Panel Interface Control 2 */
/* 0x006, 0x000 */
UCG_C12( 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
UCG_DLY_MS(10), /* delay 10 ms */
/* write test pattern */
//UCG_C12( 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
//UCG_C12( 0x021, 0x000, 0x011), /* Vertical GRAM Address Set */
UCG_C10( 0x022), /* Write Data to GRAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ili9325_spi_18x240x320(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ili9325_spi_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_240x320_ili9325_spi_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ili9325_spi_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 240;
((ucg_wh_t *)data)->h = 320;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ili9325_spi_18(ucg, msg, data);
}
/*
ucg_dev_tft_240x320_ili9341.c
ILI9341 with 4-Wire SPI (SCK, SDI, CS, D/C and optional reset)
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 uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_tft_240x320_ili9341_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C10(0x011), /* sleep out */
UCG_DLY_MS(10),
//UCG_C10(0x038), /* idle mode off */
UCG_C10(0x013), /* normal display on */
//UCG_C14(0x0ed, 0x055, 0x001, 0x023, 0x001), /* power on sequence control (POR values) */
//UCG_C11(0x0f7, 0x020), /* pump ratio control (POR value) */
UCG_C10(0x20), /* not inverted */
//UCG_C10(0x21), /* inverted */
UCG_C11(0x03a, 0x066), /* set pixel format to 18 bit */
//UCG_C11(0x03a, 0x055), /* set pixel format to 16 bit */
//UCG_C12(0x0b1, 0x000, 0x01b), /* frame rate control (POR values) */
UCG_C14(0x0b6, 0x00a, 0x082 | (1<<5), 0x027, 0x000), /* display function control (POR values, except for shift direction bit) */
//UCG_C11(0x0b7, 0x006), /* entry mode, bit 0: Low voltage detection control (0=off) */
UCG_C11(0x0c0, 0x021), /* power control 1 (reference voltage level), POR=21 */
UCG_C11(0x0c1, 0x002), /* power control 2 (step up factor), POR=2 */
UCG_C11(0x0c7, 0x0c0), /* VCOM control 2, enable VCOM control 1 */
UCG_C12(0x0c5, 0x031, 0x03c), /* VCOM control 1, POR=31,3C */
UCG_C15(0x0cb, 0x039, 0x02c, 0x000, 0x034, 0x002), /* power control A (POR values) */
UCG_C13(0x0cf, 0x000, 0x081, 0x030), /* power control B (POR values) */
UCG_C13(0x0e8, 0x084, 0x011, 0x07a), /* timer driving control A (POR values) */
UCG_C12(0x0ea, 0x066, 0x000), /* timer driving control B (POR values) */
//UCG_C12(0x0ea, 0x000, 0x000), /* timer driving control B */
//UCG_C10(0x28), /* display off */
//UCG_C11(0x0bf, 0x003), /* backlight control 8 */
UCG_C10(0x029), /* display on */
//UCG_C11(0x051, 0x07f), /* brightness */
//UCG_C11(0x053, 0x02c), /* control brightness */
//UCG_C10(0x028), /* display off */
UCG_C11( 0x036, 0x008),
UCG_C14( 0x02a, 0x000, 0x000, 0x000, 0x0ef), /* Horizontal GRAM Address Set */
UCG_C14( 0x02b, 0x000, 0x000, 0x001, 0x03f), /* Vertical GRAM Address Set */
UCG_C10( 0x02c), /* Write Data to GRAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ili9341_18x240x320(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ili9341_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_240x320_ili9341_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ili9341_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 240;
((ucg_wh_t *)data)->h = 320;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ili9341_18(ucg, msg, data);
}
/*
ucg_dev_tft_240x320_itdb02.c
ITDB02 Module Shield
Documentation: code.google.com/p/itdb02/
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 uint8_t ucg_dev_ssd1351_128x128_init_seq[] PROGMEM = {
static const ucg_pgm_uint8_t ucg_tft_240x320_ili9325_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
//UCG_C22(0x000, 0x001,0x001, 0x000), /* Driver Output Control, bits 8 & 10 */
//UCG_C22( 0x000, 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
//UCG_CS(1), /* disable chip */
//UCG_END(), /* end of sequence */
UCG_C22(0x000, 0x001,0x001, 0x000), /* Driver Output Control, bits 8 & 10 */
UCG_C22(0x000, 0x002, 0x007, 0x000), /* LCD Driving Wave Control, bit 9: Set line inversion */
//UCG_C22(0x000, 0x003, 0x010, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1 (16 bit transfer, 65K Mode)*/
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_C22(0x000, 0x004, 0x000, 0x000), /* Resize register, all 0: no resize */
UCG_C22(0x000, 0x008, 0x002, 0x007), /* Display Control 2: set the back porch and front porch */
//UCG_C22(0x000, 0x009, 0x000, 0x000), /* Display Control 3: normal scan */
//UCG_C22(0x000, 0x00a, 0x000, 0x000), /* Display Control 4: set to "no FMARK output" */
UCG_C22(0x000, 0x00c, 0x000, 0x000), /* RGB Display Interface Control 1, RIM=10 (3x6 Bit), 12 Jan 14: RIM=00 */
//UCG_C22(0x000, 0x00d, 0x000, 0x000), /* Frame Maker Position */
//UCG_C22(0x000, 0x00f, 0x000, 0x000), /* RGB Display Interface Control 2 */
UCG_C22(0x000, 0x010, 0x000, 0x000), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB, actual setting is done below */
UCG_C22(0x000, 0x011, 0x000, 0x007), /* Power Control 2: DC1[2:0], DC0[2:0], VC[2:0] */
UCG_C22(0x000, 0x012, 0x000, 0x000), /* Power Control 3: VREG1OUT voltage */
UCG_C22(0x000, 0x013, 0x000, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
UCG_C22(0x000, 0x007, 0x000, 0x001), /* Display Control 1: Operate, but do not display */
UCG_DLY_MS(100), /* delay 100 ms */ /* ITDB02 none D verion: 50ms */
UCG_C22( 0x000, 0x010, 0x010, 0x090), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
/* 12. Jan 14. Prev value: 0x016, 0x090 */
/* ITDB02 none D verion: 0x010, 0x090 */
//UCG_C22( 0x000, 0x010, 0x017, 0x0f0), /* Power Control 1: Setting for max quality & power consumption: SAP(Bit 12)=1, BT[3:0]=7 (max), APE (Bit 8)=1, AP=7 (max), disable sleep: SLP=0, STB=0 */
UCG_C22( 0x000, 0x011, 0x002, 0x027), /* Power Control 2 VCI ration, step up circuits 1 & 2 */
UCG_DLY_MS(50), /* delay 50 ms */
UCG_C22( 0x000, 0x012, 0x000, 0x01f), /* Power Control 3: VCI: External, VCI*1.80 */
/* 12. Jan 14. Prev value: 0x000, 0x00d */
UCG_DLY_MS(50), /* delay 50 ms */
UCG_C22( 0x000, 0x013, 0x015, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
/* 12. Jan 14. Prev value: 0x012, 0x009 */
UCG_C22( 0x000, 0x029, 0x000, 0x027), /* Power Control 7 */
/* 12. Jan 14. Prev value: 0x000, 0x00a */
UCG_C22( 0x000, 0x02b, 0x000, 0x00d), /* Frame Rate: 93 */
//UCG_C22( 0x000, 0x02b, 0x000, 0x00b), /* Frame Rate: 70, too less, some flicker visible */
UCG_DLY_MS(50), /* delay 50 ms */
/* Gamma Control, values from iteadstudio.com reference software on google code */
/*
UCG_C22(0x00,0x30,0x00,0x00),
UCG_C22(0x00,0x31,0x07,0x07),
UCG_C22(0x00,0x32,0x03,0x07),
UCG_C22(0x00,0x35,0x02,0x00),
UCG_C22(0x00,0x36,0x00,0x08),
UCG_C22(0x00,0x37,0x00,0x04),
UCG_C22(0x00,0x38,0x00,0x00),
UCG_C22(0x00,0x39,0x07,0x07),
UCG_C22(0x00,0x3C,0x00,0x02),
UCG_C22(0x00,0x3D,0x1D,0x04),
*/
UCG_C22( 0x000, 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
UCG_C22( 0x000, 0x021, 0x000, 0x000), /* Vertical GRAM Address Set */
UCG_C22( 0x000, 0x050, 0x000, 0x000), /* Horizontal GRAM Start Address */
UCG_C22( 0x000, 0x051, 0x000, 0x0EF), /* Horizontal GRAM End Address: 239 */
UCG_C22( 0x000, 0x052, 0x000, 0x000), /* Vertical GRAM Start Address */
UCG_C22( 0x000, 0x053, 0x001, 0x03F), /* Vertical GRAM End Address: 319 */
UCG_C22( 0x000, 0x060, 0x0a7, 0x000), /* Driver Output Control 2, NL = 0x027 = 320 lines, GS (bit 15) = 1 */
UCG_C22( 0x000, 0x061, 0x000, 0x001), /* Base Image Display Control: NDL,VLE = 0 (Disbale Vertical Scroll), REV */
//UCG_C22( 0x000, 0x06a, 0x000, 0x000), /* Vertical Scroll Control */
//UCG_C22( 0x000, 0x080, 0x000, 0x000), /* Partial Image 1 Display Position */
//UCG_C22( 0x000, 0x081, 0x000, 0x000), /* Partial Image 1 RAM Start Address */
//UCG_C22( 0x000, 0x082, 0x000, 0x000), /* Partial Image 1 RAM End Address */
//UCG_C22( 0x000, 0x083, 0x000, 0x000), /* Partial Image 2 Display Position */
//UCG_C22( 0x000, 0x084, 0x000, 0x000), /* Partial Image 2 RAM Start Address */
//UCG_C22( 0x000, 0x085, 0x000, 0x000), /* Partial Image 2 RAM End Address */
UCG_C22( 0x000, 0x090, 0x000, 0x010), /* Panel Interface Control 1 */
UCG_C22( 0x000, 0x092, 0x000, 0x000), /* Panel Interface Control 2 */
/* 0x006, 0x000 */
UCG_C22( 0x000, 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
UCG_DLY_MS(10), /* delay 10 ms */
/* write test pattern */
//UCG_C22( 0x000, 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
//UCG_C22( 0x000, 0x021, 0x000, 0x011), /* Vertical GRAM Address Set */
UCG_C20( 0x000, 0x022), /* Write Data to GRAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ili9325_18x240x320_itdb02(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ili9325_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_240x320_ili9325_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ili9325_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 240;
((ucg_wh_t *)data)->h = 320;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ili9325_18(ucg, msg, data);
}
/*
ucg_dev_tft_240x320_ssd1289.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"
#ifdef NOT_YET_IMPLEMENTED
static const ucg_pgm_uint8_t ucg_tft_240x320_ssd1289_init_seq[] = {
UCG_CFG_CD(0,1), /* DC=0 for command mode, DC=1 for data and args */
UCG_RST(1),
UCG_CS(1), /* disable chip */
UCG_DLY_MS(5),
UCG_RST(0),
UCG_DLY_MS(5),
UCG_RST(1),
UCG_DLY_MS(50),
UCG_CS(0), /* enable chip */
UCG_C22(0x000, 0x000, 0x000, 0x001), /* enable oscilator */
UCG_C22(0x000, 0x003, 0x066, 0x064), /* Power control 1 (POR value) */
//UCG_C22(0x000, 0x002, 0x007, 0x000), /* LCD Driving Wave Control, bit 9: Set line inversion */
//UCG_C22(0x000, 0x003, 0x010, 0x030), /* Entry Mode, GRAM write direction and BGR (Bit 12)=1 (16 bit transfer, 65K Mode)*/
//UCG_C22(0x000, 0x004, 0x000, 0x000), /* Resize register, all 0: no resize */
UCG_C22(0x000, 0x008, 0x002, 0x007), /* Display Control 2: set the back porch and front porch */
//UCG_C22(0x000, 0x009, 0x000, 0x000), /* Display Control 3: normal scan */
//UCG_C22(0x000, 0x00a, 0x000, 0x000), /* Display Control 4: set to "no FMARK output" */
UCG_C22(0x000, 0x00c, 0x000, 0x000), /* RGB Display Interface Control 1, RIM=10 (3x6 Bit), 12 Jan 14: RIM=00 */
//UCG_C22(0x000, 0x00d, 0x000, 0x000), /* Frame Maker Position */
//UCG_C22(0x000, 0x00f, 0x000, 0x000), /* RGB Display Interface Control 2 */
UCG_C22(0x000, 0x010, 0x000, 0x000), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB, actual setting is done below */
UCG_C22(0x000, 0x011, 0x000, 0x007), /* Power Control 2: DC1[2:0], DC0[2:0], VC[2:0] */
UCG_C22(0x000, 0x012, 0x000, 0x000), /* Power Control 3: VREG1OUT voltage */
UCG_C22(0x000, 0x013, 0x000, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
UCG_C22(0x000, 0x007, 0x000, 0x001), /* Display Control 1: Operate, but do not display */
UCG_DLY_MS(100), /* delay 100 ms */ /* ITDB02 none D verion: 50ms */
UCG_C22( 0x000, 0x010, 0x010, 0x090), /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
/* 12. Jan 14. Prev value: 0x016, 0x090 */
/* ITDB02 none D verion: 0x010, 0x090 */
//UCG_C22( 0x000, 0x010, 0x017, 0x0f0), /* Power Control 1: Setting for max quality & power consumption: SAP(Bit 12)=1, BT[3:0]=7 (max), APE (Bit 8)=1, AP=7 (max), disable sleep: SLP=0, STB=0 */
UCG_C22( 0x000, 0x011, 0x002, 0x027), /* Power Control 2 VCI ration, step up circuits 1 & 2 */
UCG_DLY_MS(50), /* delay 50 ms */
UCG_C22( 0x000, 0x012, 0x000, 0x01f), /* Power Control 3: VCI: External, VCI*1.80 */
/* 12. Jan 14. Prev value: 0x000, 0x00d */
UCG_DLY_MS(50), /* delay 50 ms */
UCG_C22( 0x000, 0x013, 0x015, 0x000), /* Power Control 4: VDV[4:0] for VCOM amplitude */
/* 12. Jan 14. Prev value: 0x012, 0x009 */
UCG_C22( 0x000, 0x029, 0x000, 0x027), /* Power Control 7 */
/* 12. Jan 14. Prev value: 0x000, 0x00a */
UCG_C22( 0x000, 0x02b, 0x000, 0x00d), /* Frame Rate: 93 */
//UCG_C22( 0x000, 0x02b, 0x000, 0x00b), /* Frame Rate: 70, too less, some flicker visible */
UCG_DLY_MS(50), /* delay 50 ms */
/* Gamma Control, values from iteadstudio.com reference software on google code */
/*
UCG_C22(0x00,0x30,0x00,0x00),
UCG_C22(0x00,0x31,0x07,0x07),
UCG_C22(0x00,0x32,0x03,0x07),
UCG_C22(0x00,0x35,0x02,0x00),
UCG_C22(0x00,0x36,0x00,0x08),
UCG_C22(0x00,0x37,0x00,0x04),
UCG_C22(0x00,0x38,0x00,0x00),
UCG_C22(0x00,0x39,0x07,0x07),
UCG_C22(0x00,0x3C,0x00,0x02),
UCG_C22(0x00,0x3D,0x1D,0x04),
*/
UCG_C22( 0x000, 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
UCG_C22( 0x000, 0x021, 0x000, 0x000), /* Vertical GRAM Address Set */
UCG_C22( 0x000, 0x050, 0x000, 0x000), /* Horizontal GRAM Start Address */
UCG_C22( 0x000, 0x051, 0x000, 0x0EF), /* Horizontal GRAM End Address: 239 */
UCG_C22( 0x000, 0x052, 0x000, 0x000), /* Vertical GRAM Start Address */
UCG_C22( 0x000, 0x053, 0x001, 0x03F), /* Vertical GRAM End Address: 319 */
UCG_C22( 0x000, 0x060, 0x0a7, 0x000), /* Driver Output Control 2, NL = 0x027 = 320 lines, GS (bit 15) = 1 */
UCG_C22( 0x000, 0x061, 0x000, 0x001), /* Base Image Display Control: NDL,VLE = 0 (Disbale Vertical Scroll), REV */
//UCG_C22( 0x000, 0x06a, 0x000, 0x000), /* Vertical Scroll Control */
//UCG_C22( 0x000, 0x080, 0x000, 0x000), /* Partial Image 1 Display Position */
//UCG_C22( 0x000, 0x081, 0x000, 0x000), /* Partial Image 1 RAM Start Address */
//UCG_C22( 0x000, 0x082, 0x000, 0x000), /* Partial Image 1 RAM End Address */
//UCG_C22( 0x000, 0x083, 0x000, 0x000), /* Partial Image 2 Display Position */
//UCG_C22( 0x000, 0x084, 0x000, 0x000), /* Partial Image 2 RAM Start Address */
//UCG_C22( 0x000, 0x085, 0x000, 0x000), /* Partial Image 2 RAM End Address */
UCG_C22( 0x000, 0x090, 0x000, 0x010), /* Panel Interface Control 1 */
UCG_C22( 0x000, 0x092, 0x000, 0x000), /* Panel Interface Control 2 */
/* 0x006, 0x000 */
UCG_C22( 0x000, 0x007, 0x001, 0x033), /* Display Control 1: Operate, display ON, Partial image off */
UCG_DLY_MS(10), /* delay 10 ms */
/* write test pattern */
//UCG_C22( 0x000, 0x020, 0x000, 0x000), /* Horizontal GRAM Address Set */
//UCG_C22( 0x000, 0x021, 0x000, 0x011), /* Vertical GRAM Address Set */
UCG_C20( 0x000, 0x022), /* Write Data to GRAM */
UCG_CS(1), /* disable chip */
UCG_END(), /* end of sequence */
};
ucg_int_t ucg_dev_ssd1289_18x240x320_itdb02(ucg_t *ucg, ucg_int_t msg, void *data)
{
switch(msg)
{
case UCG_MSG_DEV_POWER_UP:
/* 1. Call to the controller procedures to setup the com interface */
if ( ucg_dev_ic_ssd1289_18(ucg, msg, data) == 0 )
return 0;
/* 2. Send specific init sequence for this display module */
ucg_com_SendCmdSeq(ucg, ucg_tft_240x320_ssd1289_init_seq);
return 1;
case UCG_MSG_DEV_POWER_DOWN:
/* let do power down by the conroller procedures */
return ucg_dev_ic_ssd1289_18(ucg, msg, data);
case UCG_MSG_GET_DIMENSION:
((ucg_wh_t *)data)->w = 240;
((ucg_wh_t *)data)->h = 320;
return 1;
}
/* all other messages are handled by the controller procedures */
return ucg_dev_ic_ssd1289_18(ucg, msg, data);
}
#endif
\ No newline at end of file
/*
ucg_font.c
UCG Font High Level Interface; mostly taken over from U8glib
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"
/* font api */
/* pointer to the start adress of the glyph, points to progmem area on avr uC */
typedef void * ucg_glyph_t;
/*=================================================*/
/* OLD FONT FORMAT */
/* size of the font data structure, there is no struct or class... */
/* this is the size for the new font format */
#define UCG_FONT_DATA_STRUCT_SIZE 21
/*
OLD Font Data Struct
... instead the fields of the font data structure are accessed directly by offset
font information
offset
0 font format
1 FONTBOUNDINGBOX width unsigned
2 FONTBOUNDINGBOX height unsigned
3 FONTBOUNDINGBOX x-offset signed
4 FONTBOUNDINGBOX y-offset signed
5 capital A height unsigned
6 start 'A'
8 start 'a'
10 encoding start
11 encoding end
12 descent 'g' negative: below baseline
13 font max ascent
14 font min decent negative: below baseline
15 font xascent
16 font xdecent negative: below baseline
new font data:
offset bytes description
0 1 glyph_cnt number of glyphs
1 1 bbx_mode 0: proportional, 1: common height, 2: monospace, 3: multiple of 8
2 1 bits_per_0 glyph rle parameter
3 1 bits_per_1 glyph rle parameter
4 1 bits_per_char_width glyph rle parameter
5 1 bits_per_char_height glyph rle parameter
6 1 bits_per_char_x glyph rle parameter
7 1 bits_per_char_y glyph rle parameter
8 1 bits_per_delta_x glyph rle parameter
9 1 max_char_width
10 1 max_char_height
11 1 x offset
12 1 y offset (descent)
13 1 ascent (capital A)
14 1 descent (lower g)
15 1 ascent '('
16 1 descent ')'
17 1 start pos 'A' high byte
18 1 start pos 'A' low byte
19 1 start pos 'a' high byte
20 1 start pos 'a' low byte
Font build mode, 0: proportional, 1: common height, 2: monospace, 3: multiple of 8
Font build mode 0:
- "t"
- Ref height mode: UCG_FONT_HEIGHT_MODE_TEXT, UCG_FONT_HEIGHT_MODE_XTEXT or UCG_FONT_HEIGHT_MODE_ALL
- use in transparent mode only (does not look good in solid mode)
- most compact format
- different font heights possible
Font build mode 1:
- "h"
- Ref height mode: UCG_FONT_HEIGHT_MODE_ALL
- transparent or solid mode
- The height of the glyphs depend on the largest glyph in the font. This means font height depends on postfix "r", "f" and "n".
*/
/* use case: What is the width and the height of the minimal box into which string s fints? */
void ucg_font_GetStrSize(const void *font, const char *s, ucg_int_t *width, ucg_int_t *height);
void ucg_font_GetStrSizeP(const void *font, const char *s, ucg_int_t *width, ucg_int_t *height);
/* use case: lower left edge of a minimal box is known, what is the correct x, y position for the string draw procedure */
void ucg_font_AdjustXYToDraw(const void *font, const char *s, ucg_int_t *x, ucg_int_t *y);
void ucg_font_AdjustXYToDrawP(const void *font, const char *s, ucg_int_t *x, ucg_int_t *y);
/* use case: Baseline origin known, return minimal box */
void ucg_font_GetStrMinBox(ucg_t *ucg, const void *font, const char *s, ucg_int_t *x, ucg_int_t *y, ucg_int_t *width, ucg_int_t *height);
/* procedures */
/*========================================================================*/
/* low level byte and word access */
/* removed NOINLINE, because it leads to smaller code, might also be faster */
//static uint8_t ucg_font_get_byte(const ucg_fntpgm_uint8_t *font, uint8_t offset) UCG_NOINLINE;
static uint8_t ucg_font_get_byte(const ucg_fntpgm_uint8_t *font, uint8_t offset)
{
font += offset;
return ucg_pgm_read( (ucg_pgm_uint8_t *)font );
}
static uint16_t ucg_font_get_word(const ucg_fntpgm_uint8_t *font, uint8_t offset) UCG_NOINLINE;
static uint16_t ucg_font_get_word(const ucg_fntpgm_uint8_t *font, uint8_t offset)
{
uint16_t pos;
font += offset;
pos = ucg_pgm_read( (ucg_pgm_uint8_t *)font );
font++;
pos <<= 8;
pos += ucg_pgm_read( (ucg_pgm_uint8_t *)font);
return pos;
}
/*========================================================================*/
/* new font format */
void ucg_read_font_info(ucg_font_info_t *font_info, const ucg_fntpgm_uint8_t *font)
{
/* offset 0 */
font_info->glyph_cnt = ucg_font_get_byte(font, 0);
font_info->bbx_mode = ucg_font_get_byte(font, 1);
font_info->bits_per_0 = ucg_font_get_byte(font, 2);
font_info->bits_per_1 = ucg_font_get_byte(font, 3);
/* offset 4 */
font_info->bits_per_char_width = ucg_font_get_byte(font, 4);
font_info->bits_per_char_height = ucg_font_get_byte(font, 5);
font_info->bits_per_char_x = ucg_font_get_byte(font, 6);
font_info->bits_per_char_y = ucg_font_get_byte(font, 7);
font_info->bits_per_delta_x = ucg_font_get_byte(font, 8);
/* offset 9 */
font_info->max_char_width = ucg_font_get_byte(font, 9);
font_info->max_char_height = ucg_font_get_byte(font, 10);
font_info->x_offset = ucg_font_get_byte(font, 11);
font_info->y_offset = ucg_font_get_byte(font, 12);
/* offset 13 */
font_info->ascent_A = ucg_font_get_byte(font, 13);
font_info->descent_g = ucg_font_get_byte(font, 14);
font_info->ascent_para = ucg_font_get_byte(font, 15);
font_info->descent_para = ucg_font_get_byte(font, 16);
/* offset 17 */
font_info->start_pos_upper_A = ucg_font_get_word(font, 17);
font_info->start_pos_lower_a = ucg_font_get_word(font, 19);
}
/*========================================================================*/
/* direct access on the font */
// OBSOLETE
// static uint8_t ucg_font_GetFormat(const ucg_fntpgm_uint8_t *font) UCG_NOINLINE;
// static uint8_t ucg_font_GetFormat(const ucg_fntpgm_uint8_t *font)
// {
// return ucg_font_get_byte(font, 0);
// }
// OBSOLETE
// static uint8_t ucg_font_GetFontGlyphStructureSize(const ucg_fntpgm_uint8_t *font) UCG_NOINLINE;
// static uint8_t ucg_font_GetFontGlyphStructureSize(const ucg_fntpgm_uint8_t *font)
// {
// switch(ucg_font_GetFormat(font))
// {
// case 0: return 6;
// case 1: return 3;
// case 2: return 6;
// }
// return 3;
// }
// static uint8_t ucg_font_GetBBXWidth(const void *font)
// {
// return ucg_font_get_byte(font, 1);
// }
// static uint8_t ucg_font_GetBBXHeight(const void *font)
// {
// return ucg_font_get_byte(font, 2);
// }
// static int8_t ucg_font_GetBBXOffX(const void *font)
// {
// return ucg_font_get_byte(font, 3);
// }
// static int8_t ucg_font_GetBBXOffY(const void *font)
// {
// return ucg_font_get_byte(font, 4);
// }
uint8_t ucg_font_GetCapitalAHeight(const void *font)
{
return ucg_font_get_byte(font, 13);
}
/*
uint16_t ucg_font_GetEncoding65Pos(const void *font) UCG_NOINLINE;
uint16_t ucg_font_GetEncoding65Pos(const void *font)
{
return ucg_font_get_word(font, 6);
}
uint16_t ucg_font_GetEncoding97Pos(const void *font) UCG_NOINLINE;
uint16_t ucg_font_GetEncoding97Pos(const void *font)
{
return ucg_font_get_word(font, 8);
}
*/
uint8_t ucg_font_GetFontStartEncoding(const void *font_arg)
{
const uint8_t *font = font_arg;
font += UCG_FONT_DATA_STRUCT_SIZE;
return ucg_pgm_read( ((ucg_pgm_uint8_t *)font) );
}
uint8_t ucg_font_GetFontEndEncoding(const void *font_arg)
{
uint8_t encoding = 0;
const uint8_t *font = font_arg;
font += UCG_FONT_DATA_STRUCT_SIZE;
for(;;)
{
if ( ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 ) == 0 )
break;
encoding = ucg_pgm_read( ((ucg_pgm_uint8_t *)font) );
font += ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 );
}
return encoding;
}
int8_t ucg_font_GetLowerGDescent(const void *font)
{
return ucg_font_get_byte(font, 14);
}
/*
int8_t ucg_font_GetFontAscent(const void *font)
{
return ucg_font_get_byte(font, 13);
}
int8_t ucg_font_GetFontDescent(const void *font)
{
return ucg_font_get_byte(font, 14);
}
int8_t ucg_font_GetFontXAscent(const void *font)
{
return ucg_font_get_byte(font, 15);
}
int8_t ucg_font_GetFontXDescent(const void *font)
{
return ucg_font_get_byte(font, 16);
}
*/
/* return the data start for a font and the glyph pointer */
// static uint8_t *ucg_font_GetGlyphDataStart(const void *font, ucg_glyph_t g)
// {
// return ((ucg_fntpgm_uint8_t *)g) + ucg_font_GetFontGlyphStructureSize(font);
// }
/* calculate the overall length of the font, only used to create the picture for the google wiki */
size_t ucg_font_GetSize(const void *font_arg)
{
const uint8_t *font = font_arg;
font += UCG_FONT_DATA_STRUCT_SIZE;
for(;;)
{
if ( ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 ) == 0 )
break;
font += ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 );
}
return (font - (const uint8_t *)font_arg) + 2;
}
/*========================================================================*/
/* u8g interface, font access */
uint8_t ucg_GetFontBBXWidth(ucg_t *ucg)
{
// OBSOLETE return ucg_font_GetBBXWidth(ucg->font);
return ucg->font_info.max_char_width; /* new font info structure */
}
uint8_t ucg_GetFontBBXHeight(ucg_t *ucg)
{
// OBSOLETE return ucg_font_GetBBXHeight(ucg->font);
return ucg->font_info.max_char_height; /* new font info structure */
}
int8_t u8g_GetFontBBXOffX(ucg_t *ucg) UCG_NOINLINE;
int8_t u8g_GetFontBBXOffX(ucg_t *ucg)
{
// OBSOLETE return ucg_font_GetBBXOffX(ucg->font);
return ucg->font_info.x_offset; /* new font info structure */
}
int8_t ucg_GetFontBBXOffY(ucg_t *ucg) UCG_NOINLINE;
int8_t ucg_GetFontBBXOffY(ucg_t *ucg)
{
// OBSOLETE return ucg_font_GetBBXOffY(ucg->font);
return ucg->font_info.y_offset; /* new font info structure */
}
uint8_t ucg_GetFontCapitalAHeight(ucg_t *ucg) UCG_NOINLINE;
uint8_t ucg_GetFontCapitalAHeight(ucg_t *ucg)
{
// OBSOLETE return ucg_font_GetCapitalAHeight(ucg->font);
return ucg->font_info.ascent_A; /* new font info structure */
}
/*========================================================================*/
/* glyph handling */
/* optimized */
uint8_t ucg_font_decode_get_unsigned_bits(ucg_font_decode_t *f, uint8_t cnt)
{
uint8_t val;
uint8_t bit_pos = f->decode_bit_pos;
uint8_t bit_pos_plus_cnt;
//val = *(f->decode_ptr);
val = ucg_pgm_read( (ucg_pgm_uint8_t *)(f->decode_ptr) );
val >>= bit_pos;
bit_pos_plus_cnt = bit_pos;
bit_pos_plus_cnt += cnt;
if ( bit_pos_plus_cnt >= 8 )
{
uint8_t s = 8;
s -= bit_pos;
f->decode_ptr++;
//val |= *(f->decode_ptr) << (8-bit_pos);
val |= ucg_pgm_read( (ucg_pgm_uint8_t *)(f->decode_ptr) ) << (s);
//bit_pos -= 8;
bit_pos_plus_cnt -= 8;
}
val &= (1U<<cnt)-1;
//bit_pos += cnt;
f->decode_bit_pos = bit_pos_plus_cnt;
return val;
}
/*
2 bit --> cnt = 2
-2,-1,0. 1
3 bit --> cnt = 3
-2,-1,0. 1
-4,-3,-2,-1,0,1,2,3
if ( x < 0 )
r = bits(x-1)+1;
else
r = bits(x)+1;
*/
/* optimized */
int8_t ucg_font_decode_get_signed_bits(ucg_font_decode_t *f, uint8_t cnt)
{
int8_t v, d;
v = (int8_t)ucg_font_decode_get_unsigned_bits(f, cnt);
d = 1;
cnt--;
d <<= cnt;
v -= d;
return v;
//return (int8_t)ucg_font_decode_get_unsigned_bits(f, cnt) - ((1<<cnt)>>1);
}
/* OLD CODE
static void ucg_add_vector(ucg_int_t *dest_x, ucg_int_t *dest_y, int8_t x, int8_t y, uint8_t dir) UCG_NOINLINE;
static void ucg_add_vector(ucg_int_t *dest_x, ucg_int_t *dest_y, int8_t x, int8_t y, uint8_t dir)
{
switch(dir)
{
case 0:
*dest_x += x;
*dest_y += y;
break;
case 1:
*dest_y += x;
*dest_x -= y;
break;
case 2:
*dest_x -= x;
*dest_y -= y;
break;
default:
*dest_y -= x;
*dest_x += y;
break;
}
}
*/
static ucg_int_t ucg_add_vector_y(ucg_int_t dy, int8_t x, int8_t y, uint8_t dir) UCG_NOINLINE;
static ucg_int_t ucg_add_vector_y(ucg_int_t dy, int8_t x, int8_t y, uint8_t dir)
{
switch(dir)
{
case 0:
dy += y;
break;
case 1:
dy += x;
break;
case 2:
dy -= y;
break;
default:
dy -= x;
break;
}
return dy;
}
static ucg_int_t ucg_add_vector_x(ucg_int_t dx, int8_t x, int8_t y, uint8_t dir) UCG_NOINLINE;
static ucg_int_t ucg_add_vector_x(ucg_int_t dx, int8_t x, int8_t y, uint8_t dir)
{
switch(dir)
{
case 0:
dx += x;
break;
case 1:
dx -= y;
break;
case 2:
dx -= x;
break;
default:
dx += y;
break;
}
return dx;
}
#ifdef OBSOLETE
/*
Description:
Draw a line with "cnt" pixel as fore- or background color.
Args:
cnt: Length of the line
is_foreground foreground/background?
ucg->font_decode.target_x X position
ucg->font_decode.target_y Y position
ucg->font_decode.is_transparent Transparent mode
Return:
-
Calls:
ucg_font_decode_draw_pixel()
Called by:
ucg_font_decode_len()
*/
void ucg_font_decode_draw_pixel(ucg_t *ucg, uint8_t lx, uint8_t ly, uint8_t cnt, uint8_t is_foreground)
{
ucg_int_t x, y;
ucg_font_decode_t *decode = &(ucg->font_decode);
x = decode->target_x;
y = decode->target_y;
x = ucg_add_vector_x(x, lx, ly, decode->dir);
y = ucg_add_vector_y(y, lx, ly, decode->dir);
//ucg_add_vector(&x, &y, ucg->font_decode.x, ucg->font_decode.y, ucg->font_decode.dir);
if ( is_foreground )
{
ucg_Draw90Line(ucg,
x,
y,
cnt,
/* dir */ decode->dir,
/* col_idx */ 0);
}
else if ( decode->is_transparent == 0 )
{
ucg_Draw90Line(ucg,
x,
y,
cnt,
/* dir */ decode->dir,
/* col_idx */ 1);
}
}
#endif
/*
Description:
Draw a run-length area of the glyph. "len" can have any size and the line
length has to be wrapped at the glyph border.
Args:
len: Length of the line
is_foreground foreground/background?
ucg->font_decode.target_x X position
ucg->font_decode.target_y Y position
ucg->font_decode.is_transparent Transparent mode
Return:
-
Calls:
ucg_Draw90Line()
Called by:
ucg_font_decode_glyph()
*/
/* optimized */
void ucg_font_decode_len(ucg_t *ucg, uint8_t len, uint8_t is_foreground)
{
uint8_t cnt; /* total number of remaining pixels, which have to be drawn */
uint8_t rem; /* remaining pixel to the right edge of the glyph */
uint8_t current; /* number of pixels, which need to be drawn for the draw procedure */
/* current is either equal to cnt or equal to rem */
/* local coordinates of the glyph */
uint8_t lx,ly;
/* target position on the screen */
ucg_int_t x, y;
ucg_font_decode_t *decode = &(ucg->font_decode);
cnt = len;
/* get the local position */
lx = decode->x;
ly = decode->y;
for(;;)
{
/* calculate the number of pixel to the right edge of the glyph */
rem = decode->glyph_width;
rem -= lx;
/* calculate how many pixel to draw. This is either to the right edge */
/* or lesser, if not enough pixel are left */
current = rem;
if ( cnt < rem )
current = cnt;
/* now draw the line, but apply the rotation around the glyph target position */
//ucg_font_decode_draw_pixel(ucg, lx,ly,current, is_foreground);
/* get target position */
x = decode->target_x;
y = decode->target_y;
/* apply rotation */
x = ucg_add_vector_x(x, lx, ly, decode->dir);
y = ucg_add_vector_y(y, lx, ly, decode->dir);
/* draw foreground and background (if required) */
if ( is_foreground )
{
ucg_Draw90Line(ucg,
x,
y,
current,
/* dir */ decode->dir,
/* col_idx */ 0);
}
else if ( decode->is_transparent == 0 )
{
ucg_Draw90Line(ucg,
x,
y,
current,
/* dir */ decode->dir,
/* col_idx */ 1);
}
/* check, whether the end of the run length code has been reached */
if ( cnt < rem )
break;
cnt -= rem;
lx = 0;
ly++;
}
//ucg_font_decode_draw_pixel(ucg, x,y, cnt, is_foreground);
lx += cnt;
decode->x = lx;
decode->y = ly;
}
static void ucg_font_setup_decode(ucg_t *ucg, const uint8_t *glyph_data)
{
ucg_font_decode_t *decode = &(ucg->font_decode);
decode->decode_ptr = glyph_data;
decode->decode_bit_pos = 0;
decode->decode_ptr += 1;
decode->decode_ptr += 1;
decode->glyph_width = ucg_font_decode_get_unsigned_bits(decode, ucg->font_info.bits_per_char_width);
decode->glyph_height = ucg_font_decode_get_unsigned_bits(decode,ucg->font_info.bits_per_char_height);
}
/*
Description:
Decode and draw a glyph.
Args:
glyph_data: Pointer to the compressed glyph data of the font
ucg->font_decode.target_x X position
ucg->font_decode.target_y Y position
ucg->font_decode.is_transparent Transparent mode
Return:
Width (delta x advance) of the glyph.
Calls:
ucg_font_decode_len()
*/
/* optimized */
int8_t ucg_font_decode_glyph(ucg_t *ucg, const uint8_t *glyph_data)
{
uint8_t a, b;
int8_t x, y;
int8_t d;
int8_t h;
ucg_font_decode_t *decode = &(ucg->font_decode);
ucg_font_setup_decode(ucg, glyph_data);
h = ucg->font_decode.glyph_height;
x = ucg_font_decode_get_signed_bits(decode, ucg->font_info.bits_per_char_x);
y = ucg_font_decode_get_signed_bits(decode, ucg->font_info.bits_per_char_y);
d = ucg_font_decode_get_signed_bits(decode, ucg->font_info.bits_per_delta_x);
if ( decode->glyph_width > 0 )
{
decode->target_x = ucg_add_vector_x(decode->target_x, x, -(h+y), decode->dir);
decode->target_y = ucg_add_vector_y(decode->target_y, x, -(h+y), decode->dir);
//ucg_add_vector(&(decode->target_x), &(decode->target_y), x, -(h+y), decode->dir);
/* reset local x/y position */
decode->x = 0;
decode->y = 0;
/* decode glyph */
for(;;)
{
a = ucg_font_decode_get_unsigned_bits(decode, ucg->font_info.bits_per_0);
b = ucg_font_decode_get_unsigned_bits(decode, ucg->font_info.bits_per_1);
do
{
ucg_font_decode_len(ucg, a, 0);
ucg_font_decode_len(ucg, b, 1);
} while( ucg_font_decode_get_unsigned_bits(decode, 1) != 0 );
if ( decode->y >= h )
break;
}
}
return d;
}
/*
Description:
Find the starting point of the glyph data.
Args:
encoding: Encoding (ASCII code) of the glyph
Return:
Address of the glyph data or NULL, if the encoding is not avialable in the font.
*/
const uint8_t *ucg_font_get_glyph_data(ucg_t *ucg, uint8_t encoding)
{
const uint8_t *font = ucg->font;
font += UCG_FONT_DATA_STRUCT_SIZE;
if ( encoding >= 'a' )
{
font += ucg->font_info.start_pos_lower_a;
}
else if ( encoding >= 'A' )
{
font += ucg->font_info.start_pos_upper_A;
}
for(;;)
{
if ( ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 ) == 0 )
break;
if ( ucg_pgm_read( (ucg_pgm_uint8_t *)font ) == encoding )
{
return font;
}
font += ucg_pgm_read( ((ucg_pgm_uint8_t *)font) + 1 );
}
return NULL;
}
ucg_int_t ucg_font_draw_glyph(ucg_t *ucg, ucg_int_t x, ucg_int_t y, uint8_t dir, uint8_t encoding)
{
ucg_int_t dx = 0;
ucg->font_decode.target_x = x;
ucg->font_decode.target_y = y;
//ucg->font_decode.is_transparent = is_transparent; this is already set
ucg->font_decode.dir = dir;
const uint8_t *glyph_data = ucg_font_get_glyph_data(ucg, encoding);
if ( glyph_data != NULL )
{
dx = ucg_font_decode_glyph(ucg, glyph_data);
}
return dx;
}
uint8_t ucg_IsGlyph(ucg_t *ucg, uint8_t requested_encoding)
{
/* updated to new code */
if ( ucg_font_get_glyph_data(ucg, requested_encoding) != NULL )
return 1;
return 0;
}
/*
int8_t ucg_GetGlyphDeltaX(ucg_t *ucg, uint8_t requested_encoding)
{
if ( ucg_GetGlyph(ucg, requested_encoding) == NULL )
return 0;
return ucg->glyph_dx;
}
*/
int8_t ucg_GetGlyphWidth(ucg_t *ucg, uint8_t requested_encoding)
{
const uint8_t *glyph_data = ucg_font_get_glyph_data(ucg, requested_encoding);
if ( glyph_data == NULL )
return 0;
ucg_font_setup_decode(ucg, glyph_data);
ucg_font_decode_get_signed_bits(&(ucg->font_decode), ucg->font_info.bits_per_char_x);
ucg_font_decode_get_signed_bits(&(ucg->font_decode), ucg->font_info.bits_per_char_y);
//return ucg->font_decode.glyph_width;
return ucg_font_decode_get_signed_bits(&(ucg->font_decode), ucg->font_info.bits_per_delta_x);
}
/*
set one of:
UCG_FONT_MODE_TRANSPARENT
UCG_FONT_MODE_SOLID
UCG_FONT_MODE_NONE
This has been changed for the new font procedures
*/
void ucg_SetFontMode(ucg_t *ucg, uint8_t is_transparent)
{
ucg->font_decode.is_transparent = is_transparent; // new font procedures
}
ucg_int_t ucg_DrawGlyph(ucg_t *ucg, ucg_int_t x, ucg_int_t y, uint8_t dir, uint8_t encoding)
{
switch(dir)
{
case 0:
y += ucg->font_calc_vref(ucg);
break;
case 1:
x -= ucg->font_calc_vref(ucg);
break;
case 2:
y -= ucg->font_calc_vref(ucg);
break;
case 3:
x += ucg->font_calc_vref(ucg);
break;
}
return ucg_font_draw_glyph(ucg, x, y, dir, encoding);
}
ucg_int_t ucg_DrawString(ucg_t *ucg, ucg_int_t x, ucg_int_t y, uint8_t dir, const char *str)
{
ucg_int_t delta, sum;
sum = 0;
while( *str != '\0' )
{
delta = ucg_DrawGlyph(ucg, x, y, dir, (uint8_t)*str);
switch(dir)
{
case 0:
x += delta;
break;
case 1:
y += delta;
break;
case 2:
x -= delta;
break;
case 3:
y -= delta;
break;
}
sum += delta;
str++;
}
return sum;
}
/*===============================================*/
/* set ascent/descent for reference point calculation */
void ucg_UpdateRefHeight(ucg_t *ucg)
{
if ( ucg->font == NULL )
return;
ucg->font_ref_ascent = ucg->font_info.ascent_A;
ucg->font_ref_descent = ucg->font_info.descent_g;
if ( ucg->font_height_mode == UCG_FONT_HEIGHT_MODE_TEXT )
{
}
else if ( ucg->font_height_mode == UCG_FONT_HEIGHT_MODE_XTEXT )
{
if ( ucg->font_ref_ascent < ucg->font_info.ascent_para )
ucg->font_ref_ascent = ucg->font_info.ascent_para;
if ( ucg->font_ref_descent > ucg->font_info.descent_para )
ucg->font_ref_descent = ucg->font_info.descent_para;
}
else
{
if ( ucg->font_ref_ascent < ucg->font_info.max_char_height+ucg->font_info.y_offset )
ucg->font_ref_ascent = ucg->font_info.max_char_height+ucg->font_info.y_offset;
if ( ucg->font_ref_descent > ucg->font_info.y_offset )
ucg->font_ref_descent = ucg->font_info.y_offset;
}
}
void ucg_SetFontRefHeightText(ucg_t *ucg)
{
ucg->font_height_mode = UCG_FONT_HEIGHT_MODE_TEXT;
ucg_UpdateRefHeight(ucg);
}
void ucg_SetFontRefHeightExtendedText(ucg_t *ucg)
{
ucg->font_height_mode = UCG_FONT_HEIGHT_MODE_XTEXT;
ucg_UpdateRefHeight(ucg);
}
void ucg_SetFontRefHeightAll(ucg_t *ucg)
{
ucg->font_height_mode = UCG_FONT_HEIGHT_MODE_ALL;
ucg_UpdateRefHeight(ucg);
}
/*===============================================*/
/* callback procedures to correct the y position */
ucg_int_t ucg_font_calc_vref_font(ucg_t *ucg)
{
return 0;
}
void ucg_SetFontPosBaseline(ucg_t *ucg)
{
ucg->font_calc_vref = ucg_font_calc_vref_font;
}
ucg_int_t ucg_font_calc_vref_bottom(ucg_t *ucg)
{
return (ucg_int_t)(ucg->font_ref_descent);
}
void ucg_SetFontPosBottom(ucg_t *ucg)
{
ucg->font_calc_vref = ucg_font_calc_vref_bottom;
}
ucg_int_t ucg_font_calc_vref_top(ucg_t *ucg)
{
ucg_int_t tmp;
/* reference pos is one pixel above the upper edge of the reference glyph */
tmp = (ucg_int_t)(ucg->font_ref_ascent);
tmp++;
return tmp;
}
void ucg_SetFontPosTop(ucg_t *ucg)
{
ucg->font_calc_vref = ucg_font_calc_vref_top;
}
ucg_int_t ucg_font_calc_vref_center(ucg_t *ucg)
{
int8_t tmp;
tmp = ucg->font_ref_ascent;
tmp -= ucg->font_ref_descent;
tmp /= 2;
tmp += ucg->font_ref_descent;
return tmp;
}
void ucg_SetFontPosCenter(ucg_t *ucg)
{
ucg->font_calc_vref = ucg_font_calc_vref_center;
}
/*===============================================*/
void ucg_SetFont(ucg_t *ucg, const ucg_fntpgm_uint8_t *font)
{
if ( ucg->font != font )
{
ucg->font = font;
ucg_read_font_info(&(ucg->font_info), font);
ucg_UpdateRefHeight(ucg);
//ucg_SetFontPosBaseline(ucg);
}
}
/*===============================================*/
ucg_int_t ucg_GetStrWidth(ucg_t *ucg, const char *s)
{
ucg_int_t w;
uint8_t encoding;
/* reset the total width to zero, this will be expanded during calculation */
w = 0;
for(;;)
{
encoding = *s;
if ( encoding == 0 )
break;
/* load glyph information */
// OBSOLETE ucg_GetGlyph(ucg, encoding);
// OBSOLETE w += ucg->glyph_dx;
// replaced by this:
w += ucg_GetGlyphWidth(ucg, encoding);
/* goto next char */
s++;
}
return w;
}
/*
ucg_init.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"
#include <string.h> /* memset */
#ifdef __AVR__
uint8_t global_SREG_backup; // used by the atomic macros
#endif
void ucg_init_struct(ucg_t *ucg)
{
//memset(ucg, 0, sizeof(ucg_t));
ucg->is_power_up = 0;
ucg->rotate_chain_device_cb = 0;
ucg->arg.scale = 1;
//ucg->display_offset.x = 0;
//ucg->display_offset.y = 0;
ucg->font = 0;
//ucg->font_mode = UCG_FONT_MODE_NONE; Old font procedures
ucg->font_decode.is_transparent = 1; // new font procedures
ucg->com_initial_change_sent = 0;
ucg->com_status = 0;
ucg->com_cfg_cd = 0;
}
ucg_int_t ucg_Init(ucg_t *ucg, ucg_dev_fnptr device_cb, ucg_dev_fnptr ext_cb, ucg_com_fnptr com_cb)
{
ucg_int_t r;
ucg_init_struct(ucg);
if ( ext_cb == (ucg_dev_fnptr)0 )
ucg->ext_cb = ucg_ext_none;
else
ucg->ext_cb = ext_cb;
ucg->device_cb = device_cb;
ucg->com_cb = com_cb;
ucg_SetFontPosBaseline(ucg);
r = ucg_PowerUp(ucg);
ucg_GetDimension(ucg);
return r;
}
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