library - U8glib upgrade to v1.17
This commit is contained in:
@ -72,7 +72,7 @@
|
||||
- Castling: Need to check for fields under attack
|
||||
--> done
|
||||
|
||||
- Check for WIN / LOSE situation, perhaps call ce_Eval() once on the top-level board setup
|
||||
- Check for WIN / LOOSE situation, perhaps call ce_Eval() once on the top-level board setup
|
||||
just after the real move
|
||||
- cleanup cu_Move
|
||||
--> almost done
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,382 +1,382 @@
|
||||
/*
|
||||
|
||||
u8g_circle.c
|
||||
|
||||
Utility to draw empty and filled circles.
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, bjthom@gmail.com
|
||||
u8g_DrawCircle & u8g_DrawDisc by 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.
|
||||
|
||||
Addition to the U8G Library 02/25/12
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#ifdef OLD_CODE
|
||||
|
||||
void circ_upperRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 - x);
|
||||
}
|
||||
|
||||
void circ_upperLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 - x);
|
||||
}
|
||||
|
||||
void circ_lowerRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 + x);
|
||||
}
|
||||
|
||||
void circ_lowerLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 + x);
|
||||
}
|
||||
|
||||
void circ_all(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
circ_upperRight(u8g, x, y, x0, y0);
|
||||
circ_upperLeft(u8g, x, y, x0, y0);
|
||||
circ_lowerRight(u8g, x, y, x0, y0);
|
||||
circ_lowerLeft(u8g, x, y, x0, y0);
|
||||
}
|
||||
|
||||
void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
|
||||
return;
|
||||
|
||||
int f = 1 - rad;
|
||||
int ddF_x = 1;
|
||||
int ddF_y = -2*rad;
|
||||
uint8_t x = 0;
|
||||
uint8_t y = rad;
|
||||
|
||||
void ( *circ_util )(u8g_t *, u8g_uint_t, u8g_uint_t, u8g_uint_t, u8g_uint_t);
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case U8G_CIRC_UPPER_RIGHT:
|
||||
u8g_DrawPixel(u8g, x0, y0 - rad);
|
||||
u8g_DrawPixel(u8g, x0 + rad, y0);
|
||||
circ_util = circ_upperRight;
|
||||
break;
|
||||
case U8G_CIRC_UPPER_LEFT:
|
||||
u8g_DrawPixel(u8g, x0, y0 - rad);
|
||||
u8g_DrawPixel(u8g, x0 - rad, y0);
|
||||
circ_util = circ_upperLeft;
|
||||
break;
|
||||
case U8G_CIRC_LOWER_RIGHT:
|
||||
u8g_DrawPixel(u8g, x0, y0 + rad);
|
||||
u8g_DrawPixel(u8g, x0 + rad, y0);
|
||||
circ_util = circ_lowerRight;
|
||||
break;
|
||||
case U8G_CIRC_LOWER_LEFT:
|
||||
u8g_DrawPixel(u8g, x0, y0 + rad);
|
||||
u8g_DrawPixel(u8g, x0 - rad, y0);
|
||||
circ_util = circ_lowerLeft;
|
||||
break;
|
||||
default:
|
||||
case U8G_CIRC_ALL:
|
||||
u8g_DrawPixel(u8g, x0, y0 + rad);
|
||||
u8g_DrawPixel(u8g, x0, y0 - rad);
|
||||
u8g_DrawPixel(u8g, x0 + rad, y0);
|
||||
u8g_DrawPixel(u8g, x0 - rad, y0);
|
||||
circ_util = circ_all;
|
||||
break;
|
||||
}
|
||||
|
||||
while( x < y )
|
||||
{
|
||||
if(f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
circ_util(u8g, x, y, x0, y0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
|
||||
return;
|
||||
|
||||
int f = 1 - rad;
|
||||
int ddF_x = 1;
|
||||
int ddF_y = -2*rad;
|
||||
uint8_t x = 0;
|
||||
uint8_t y = rad;
|
||||
|
||||
// Draw vertical diameter at the horiz. center
|
||||
// u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
|
||||
|
||||
if (option == U8G_CIRC_UPPER_LEFT || option == U8G_CIRC_UPPER_RIGHT) {
|
||||
u8g_DrawVLine(u8g, x0, y0 - rad, rad+1);
|
||||
}
|
||||
else if (option == U8G_CIRC_LOWER_LEFT || option == U8G_CIRC_LOWER_RIGHT) {
|
||||
u8g_DrawVLine(u8g, x0, y0, rad+1);
|
||||
}
|
||||
else {
|
||||
u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
|
||||
}
|
||||
|
||||
while( x < y )
|
||||
{
|
||||
if(f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
//Draw vertical lines from one point to another
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case U8G_CIRC_UPPER_RIGHT:
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
|
||||
break;
|
||||
case U8G_CIRC_UPPER_LEFT:
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
|
||||
break;
|
||||
case U8G_CIRC_LOWER_RIGHT:
|
||||
u8g_DrawVLine(u8g, x0+x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0, x+1);
|
||||
break;
|
||||
case U8G_CIRC_LOWER_LEFT:
|
||||
u8g_DrawVLine(u8g, x0-x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0, x+1);
|
||||
break;
|
||||
case U8G_CIRC_ALL:
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, 2*y+1);
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, 2*y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0-x, 2*x+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0-x, 2*x+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
|
||||
|
||||
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 - x);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 - x);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 + x);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 + x);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g_int_t f;
|
||||
u8g_int_t ddF_x;
|
||||
u8g_int_t ddF_y;
|
||||
u8g_uint_t x;
|
||||
u8g_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g_draw_circle_section(u8g, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g_draw_circle_section(u8g, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
{
|
||||
u8g_uint_t radp, radp2;
|
||||
|
||||
radp = rad;
|
||||
radp++;
|
||||
radp2 = radp;
|
||||
radp2 *= 2;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* draw circle */
|
||||
u8g_draw_circle(u8g, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
|
||||
|
||||
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0+x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0, x+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0-x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0, x+1);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g_int_t f;
|
||||
u8g_int_t ddF_x;
|
||||
u8g_int_t ddF_y;
|
||||
u8g_uint_t x;
|
||||
u8g_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g_draw_disc_section(u8g, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g_draw_disc_section(u8g, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
{
|
||||
u8g_uint_t radp, radp2;
|
||||
|
||||
radp = rad;
|
||||
radp++;
|
||||
radp2 = radp;
|
||||
radp2 *= 2;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* draw disc */
|
||||
u8g_draw_disc(u8g, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
u8g_circle.c
|
||||
|
||||
Utility to draw empty and filled circles.
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, bjthom@gmail.com
|
||||
u8g_DrawCircle & u8g_DrawDisc by 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.
|
||||
|
||||
Addition to the U8G Library 02/25/12
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#ifdef OLD_CODE
|
||||
|
||||
void circ_upperRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 - x);
|
||||
}
|
||||
|
||||
void circ_upperLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 - x);
|
||||
}
|
||||
|
||||
void circ_lowerRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 + x);
|
||||
}
|
||||
|
||||
void circ_lowerLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 + x);
|
||||
}
|
||||
|
||||
void circ_all(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
|
||||
circ_upperRight(u8g, x, y, x0, y0);
|
||||
circ_upperLeft(u8g, x, y, x0, y0);
|
||||
circ_lowerRight(u8g, x, y, x0, y0);
|
||||
circ_lowerLeft(u8g, x, y, x0, y0);
|
||||
}
|
||||
|
||||
void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
|
||||
return;
|
||||
|
||||
int f = 1 - rad;
|
||||
int ddF_x = 1;
|
||||
int ddF_y = -2*rad;
|
||||
uint8_t x = 0;
|
||||
uint8_t y = rad;
|
||||
|
||||
void ( *circ_util )(u8g_t *, u8g_uint_t, u8g_uint_t, u8g_uint_t, u8g_uint_t);
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case U8G_CIRC_UPPER_RIGHT:
|
||||
u8g_DrawPixel(u8g, x0, y0 - rad);
|
||||
u8g_DrawPixel(u8g, x0 + rad, y0);
|
||||
circ_util = circ_upperRight;
|
||||
break;
|
||||
case U8G_CIRC_UPPER_LEFT:
|
||||
u8g_DrawPixel(u8g, x0, y0 - rad);
|
||||
u8g_DrawPixel(u8g, x0 - rad, y0);
|
||||
circ_util = circ_upperLeft;
|
||||
break;
|
||||
case U8G_CIRC_LOWER_RIGHT:
|
||||
u8g_DrawPixel(u8g, x0, y0 + rad);
|
||||
u8g_DrawPixel(u8g, x0 + rad, y0);
|
||||
circ_util = circ_lowerRight;
|
||||
break;
|
||||
case U8G_CIRC_LOWER_LEFT:
|
||||
u8g_DrawPixel(u8g, x0, y0 + rad);
|
||||
u8g_DrawPixel(u8g, x0 - rad, y0);
|
||||
circ_util = circ_lowerLeft;
|
||||
break;
|
||||
default:
|
||||
case U8G_CIRC_ALL:
|
||||
u8g_DrawPixel(u8g, x0, y0 + rad);
|
||||
u8g_DrawPixel(u8g, x0, y0 - rad);
|
||||
u8g_DrawPixel(u8g, x0 + rad, y0);
|
||||
u8g_DrawPixel(u8g, x0 - rad, y0);
|
||||
circ_util = circ_all;
|
||||
break;
|
||||
}
|
||||
|
||||
while( x < y )
|
||||
{
|
||||
if(f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
circ_util(u8g, x, y, x0, y0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
|
||||
return;
|
||||
|
||||
int f = 1 - rad;
|
||||
int ddF_x = 1;
|
||||
int ddF_y = -2*rad;
|
||||
uint8_t x = 0;
|
||||
uint8_t y = rad;
|
||||
|
||||
// Draw vertical diameter at the horiz. center
|
||||
// u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
|
||||
|
||||
if (option == U8G_CIRC_UPPER_LEFT || option == U8G_CIRC_UPPER_RIGHT) {
|
||||
u8g_DrawVLine(u8g, x0, y0 - rad, rad+1);
|
||||
}
|
||||
else if (option == U8G_CIRC_LOWER_LEFT || option == U8G_CIRC_LOWER_RIGHT) {
|
||||
u8g_DrawVLine(u8g, x0, y0, rad+1);
|
||||
}
|
||||
else {
|
||||
u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
|
||||
}
|
||||
|
||||
while( x < y )
|
||||
{
|
||||
if(f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
//Draw vertical lines from one point to another
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case U8G_CIRC_UPPER_RIGHT:
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
|
||||
break;
|
||||
case U8G_CIRC_UPPER_LEFT:
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
|
||||
break;
|
||||
case U8G_CIRC_LOWER_RIGHT:
|
||||
u8g_DrawVLine(u8g, x0+x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0, x+1);
|
||||
break;
|
||||
case U8G_CIRC_LOWER_LEFT:
|
||||
u8g_DrawVLine(u8g, x0-x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0, x+1);
|
||||
break;
|
||||
case U8G_CIRC_ALL:
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, 2*y+1);
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, 2*y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0-x, 2*x+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0-x, 2*x+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
|
||||
|
||||
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 - x);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 - y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 - x);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 + y, y0 + x);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 + y);
|
||||
u8g_DrawPixel(u8g, x0 - y, y0 + x);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g_int_t f;
|
||||
u8g_int_t ddF_x;
|
||||
u8g_int_t ddF_y;
|
||||
u8g_uint_t x;
|
||||
u8g_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g_draw_circle_section(u8g, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g_draw_circle_section(u8g, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
{
|
||||
u8g_uint_t radp, radp2;
|
||||
|
||||
radp = rad;
|
||||
radp++;
|
||||
radp2 = radp;
|
||||
radp2 *= 2;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* draw circle */
|
||||
u8g_draw_circle(u8g, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
|
||||
|
||||
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0+x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0+y, y0, x+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0-x, y0, y+1);
|
||||
u8g_DrawVLine(u8g, x0-y, y0, x+1);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g_int_t f;
|
||||
u8g_int_t ddF_x;
|
||||
u8g_int_t ddF_y;
|
||||
u8g_uint_t x;
|
||||
u8g_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g_draw_disc_section(u8g, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g_draw_disc_section(u8g, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
{
|
||||
u8g_uint_t radp, radp2;
|
||||
|
||||
radp = rad;
|
||||
radp++;
|
||||
radp2 = radp;
|
||||
radp2 *= 2;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* draw disc */
|
||||
u8g_draw_disc(u8g, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
||||
uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
|
||||
However, this is slower than a decision tree version:
|
||||
static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
|
||||
Also suprising is, that he the macro implementation is slower than the inlined version.
|
||||
Also suprising is, that the macro implementation is slower than the inlined version.
|
||||
|
||||
The decision tree is based on the expansion of the truth table.
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
#include "u8g.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define U8G_ALWAYS_INLINE __attribute__((always_inline))
|
||||
#define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline))
|
||||
#else
|
||||
#define U8G_ALWAYS_INLINE
|
||||
#endif
|
||||
@ -94,8 +94,8 @@ static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uin
|
||||
|
||||
#define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) ))
|
||||
|
||||
static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE;
|
||||
static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
|
||||
//static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE;
|
||||
static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
|
||||
{
|
||||
/* surprisingly the macro leads to larger code */
|
||||
/* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */
|
||||
|
@ -36,9 +36,9 @@
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev)
|
||||
uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time)
|
||||
{
|
||||
return dev->com_fn(u8g, U8G_COM_MSG_INIT, 0, NULL);
|
||||
return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL);
|
||||
}
|
||||
|
||||
void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev)
|
||||
|
@ -0,0 +1,160 @@
|
||||
/*
|
||||
|
||||
u8g_arduino_ATtiny85_std_hw_spi.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
// Uses code from tinySPI Written by Nick Gammon
|
||||
// March 2013
|
||||
|
||||
// ATMEL ATTINY45 / ARDUINO pin mappings
|
||||
//
|
||||
// +-\/-+
|
||||
// RESET Ain0 (D 5) PB5 1| |8 Vcc
|
||||
// CLK1 Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 SCK / USCK / SCL
|
||||
// CLK0 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 MISO / DO
|
||||
// GND 4| |5 PB0 (D 0) pwm0 MOSI / DI / SDA
|
||||
// +----+
|
||||
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
|
||||
#if defined(ARDUINO) && defined(__AVR_ATtiny85__)
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
const byte DI = 0; // D0, pin 5 Data In
|
||||
const byte DO = 1; // D1, pin 6 Data Out (this is *not* MOSI)
|
||||
const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock
|
||||
|
||||
uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val)
|
||||
{
|
||||
USIDR = val; // byte to output
|
||||
USISR = _BV (USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero
|
||||
do
|
||||
{
|
||||
USICR = _BV (USIWM0) // 3-wire mode
|
||||
| _BV (USICS1) | _BV (USICLK) // Software clock strobe
|
||||
| _BV (USITC); // Toggle Clock Port Pin
|
||||
}
|
||||
while ((USISR & _BV (USIOIF)) == 0); // until Counter Overflow Interrupt Flag set
|
||||
|
||||
return USIDR; // return read data
|
||||
}
|
||||
|
||||
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed
|
||||
pinMode (USCK, OUTPUT);
|
||||
pinMode (DO, OUTPUT);
|
||||
pinMode (u8g->pin_list[U8G_PI_CS], OUTPUT);
|
||||
pinMode (u8g->pin_list[U8G_PI_A0], OUTPUT);
|
||||
USICR = _BV (USIWM0); // 3-wire mode
|
||||
u8g_MicroDelay();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
/* disable */
|
||||
u8g_MicroDelay();
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* enable */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
u8g_arduino_ATtiny85_spi_out(arg_val);
|
||||
u8g_MicroDelay();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_arduino_ATtiny85_spi_out(*ptr++);
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr));
|
||||
ptr++;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
|
||||
u8g_MicroDelay();
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* ARDUINO */
|
||||
|
||||
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* ARDUINO */
|
@ -49,6 +49,12 @@
|
||||
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
|
||||
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
@ -114,7 +120,8 @@ static void u8g_com_arduino_fast_parallel_init(u8g_t *u8g)
|
||||
u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]);
|
||||
}
|
||||
|
||||
void u8g_com_arduino_fast_write_data_pin(uint8_t pin, uint8_t val)
|
||||
/* atomic protection must be done by calling function */
|
||||
static void u8g_com_arduino_fast_write_data_pin(uint8_t pin, uint8_t val)
|
||||
{
|
||||
if ( val != 0 )
|
||||
*u8g_data_port[pin] |= u8g_data_mask[pin];
|
||||
@ -125,6 +132,7 @@ void u8g_com_arduino_fast_write_data_pin(uint8_t pin, uint8_t val)
|
||||
|
||||
void u8g_com_arduino_fast_parallel_write(u8g_t *u8g, uint8_t val)
|
||||
{
|
||||
U8G_ATOMIC_START();
|
||||
u8g_com_arduino_fast_write_data_pin( 0, val&1 );
|
||||
val >>= 1;
|
||||
u8g_com_arduino_fast_write_data_pin( 1, val&1 );
|
||||
@ -142,6 +150,7 @@ void u8g_com_arduino_fast_parallel_write(u8g_t *u8g, uint8_t val)
|
||||
val >>= 1;
|
||||
u8g_com_arduino_fast_write_data_pin( 7, val&1 );
|
||||
val >>= 1;
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
/* EN cycle time must be 1 micro second */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH);
|
||||
|
@ -30,7 +30,99 @@
|
||||
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.
|
||||
|
||||
SPI Clock Cycle Type
|
||||
|
||||
SSD1351 50ns 20 MHz
|
||||
SSD1322 300ns 3.3 MHz
|
||||
SSD1327 300ns
|
||||
SSD1306 300ns
|
||||
ST7565 400ns 2.5 MHz
|
||||
ST7920 400ns
|
||||
|
||||
Arduino DUE
|
||||
|
||||
PA25 MISO
|
||||
PA26 MOSI 75
|
||||
PA27 SCLK 76
|
||||
|
||||
|
||||
typedef struct {
|
||||
WoReg SPI_CR; (Spi Offset: 0x00) Control Register
|
||||
RwReg SPI_MR; (Spi Offset: 0x04) Mode Register
|
||||
RoReg SPI_RDR; (Spi Offset: 0x08) Receive Data Register
|
||||
WoReg SPI_TDR; (Spi Offset: 0x0C) Transmit Data Register
|
||||
RoReg SPI_SR; (Spi Offset: 0x10) Status Register
|
||||
WoReg SPI_IER; (Spi Offset: 0x14) Interrupt Enable Register
|
||||
WoReg SPI_IDR; (Spi Offset: 0x18) Interrupt Disable Register
|
||||
RoReg SPI_IMR; (Spi Offset: 0x1C) Interrupt Mask Register
|
||||
RoReg Reserved1[4];
|
||||
RwReg SPI_CSR[4]; (Spi Offset: 0x30) Chip Select Register
|
||||
RoReg Reserved2[41];
|
||||
RwReg SPI_WPMR; (Spi Offset: 0xE4) Write Protection Control Register
|
||||
RoReg SPI_WPSR; (Spi Offset: 0xE8) Write Protection Status Register
|
||||
} Spi;
|
||||
|
||||
Power Management Controller (PMC)
|
||||
arduino-1.5.2/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/instance/instance_pmc.h
|
||||
- enable PIO
|
||||
|
||||
REG_PMC_PCER0 = 1UL << ID_PIOA
|
||||
- enable SPI
|
||||
REG_PMC_PCER0 = 1UL << ID_SPI0
|
||||
|
||||
|
||||
- enable PIOA and SPI0
|
||||
REG_PMC_PCER0 = (1UL << ID_PIOA) | (1UL << ID_SPI0);
|
||||
|
||||
Parallel Input/Output Controller (PIO)
|
||||
arduino-1.5.2/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/instance/instance_pioa.h
|
||||
- enable special function of the pin: disable PIO on A26 and A27:
|
||||
REG_PIOA_PDR = 0x0c000000
|
||||
PIOA->PIO_PDR = 0x0c000000
|
||||
|
||||
SPI
|
||||
SPI0->SPI_CR = SPI_CR_SPIDIS
|
||||
SPI0->SPI_CR = SPI_CR_SWRST ;
|
||||
SPI0->SPI_CR = SPI_CR_SWRST ;
|
||||
SPI0->SPI_CR = SPI_CR_SPIEN
|
||||
|
||||
Bit 0: Master Mode = 1 (active)
|
||||
Bit 1: Peripheral Select = 0 (fixed)
|
||||
Bit 2: Chip Select Decode Mode = 1 (4 to 16)
|
||||
Bit 4: Mode Fault Detection = 1 (disabled)
|
||||
Bit 5: Wait Data Read = 0 (disabled)
|
||||
Bit 7: Loop Back Mode = 0 (disabled)
|
||||
Bit 16-19: Peripheral Chip Select = 0 (chip select 0)
|
||||
SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PCSDEC | SPI_MR_MODFDIS
|
||||
|
||||
Bit 0: Clock Polarity = 0
|
||||
Bit 1: Clock Phase = 0
|
||||
Bit 4-7: Bits = 0 (8 Bit)
|
||||
Bit 8-15: SCBR = 1
|
||||
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(x) Serial Baud Rate
|
||||
SCBR / 84000000 > 50 / 1000000000
|
||||
SCBR / 84 > 5 / 100
|
||||
SCBR > 50 *84 / 1000 --> SCBR=5
|
||||
SCBR > 300*84 / 1000 --> SCBR=26
|
||||
SCBR > 400*84 / 1000 --> SCBR=34
|
||||
|
||||
Arduino Due test code:
|
||||
REG_PMC_PCER0 = (1UL << ID_PIOA) | (1UL << ID_SPI0);
|
||||
REG_PIOA_PDR = 0x0c000000;
|
||||
SPI0->SPI_CR = SPI_CR_SPIDIS;
|
||||
SPI0->SPI_CR = SPI_CR_SWRST;
|
||||
SPI0->SPI_CR = SPI_CR_SWRST;
|
||||
SPI0->SPI_CR = SPI_CR_SPIEN;
|
||||
SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PCSDEC | SPI_MR_MODFDIS;
|
||||
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(30);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
while( (SPI0->SPI_SR & SPI_SR_TDRE) == 0 )
|
||||
;
|
||||
SPI0->SPI_TDR = 0x050;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@ -39,6 +131,17 @@
|
||||
#if defined(ARDUINO)
|
||||
|
||||
#if defined(__AVR__)
|
||||
#define U8G_ARDUINO_ATMEGA_HW_SPI
|
||||
/* remove the definition for attiny */
|
||||
#if __AVR_ARCH__ == 2
|
||||
#undef U8G_ARDUINO_ATMEGA_HW_SPI
|
||||
#endif
|
||||
#if __AVR_ARCH__ == 25
|
||||
#undef U8G_ARDUINO_ATMEGA_HW_SPI
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(U8G_ARDUINO_ATMEGA_HW_SPI)
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
@ -115,11 +218,17 @@ uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
1 1 fclk/128
|
||||
*/
|
||||
SPCR = 0;
|
||||
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(1<<SPR0)|(0<<CPOL)|(0<<CPHA);
|
||||
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(0<<CPOL)|(0<<CPHA);
|
||||
#ifdef U8G_HW_SPI_2X
|
||||
SPSR = (1 << SPI2X); /* double speed, issue 89 */
|
||||
#else
|
||||
if ( arg_val <= U8G_SPI_CLK_CYCLE_50NS )
|
||||
{
|
||||
SPSR = (1 << SPI2X); /* double speed, issue 89 */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
@ -176,9 +285,147 @@ uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
|
||||
/* #elif defined(__18CXX) || defined(__PIC32MX) */
|
||||
|
||||
#else /* __AVR__ */
|
||||
#elif defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__
|
||||
|
||||
#endif /* __AVR__ */
|
||||
#include <Arduino.h>
|
||||
|
||||
/* use Arduino pin definitions */
|
||||
#define PIN_SCK SCK
|
||||
#define PIN_MISO MISO
|
||||
#define PIN_MOSI MOSI
|
||||
#define PIN_CS SS
|
||||
|
||||
|
||||
static uint8_t u8g_spi_out(uint8_t data)
|
||||
{
|
||||
/* wait until tx register is empty */
|
||||
while( (SPI0->SPI_SR & SPI_SR_TDRE) == 0 )
|
||||
;
|
||||
/* send data */
|
||||
SPI0->SPI_TDR = (uint32_t)data;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_com_arduino_assign_pin_output_high(u8g);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
|
||||
/* Arduino Due specific code */
|
||||
|
||||
/* enable PIOA and SPI0 */
|
||||
REG_PMC_PCER0 = (1UL << ID_PIOA) | (1UL << ID_SPI0);
|
||||
|
||||
/* disable PIO on A26 and A27 */
|
||||
REG_PIOA_PDR = 0x0c000000;
|
||||
|
||||
/* reset SPI0 (from sam lib) */
|
||||
SPI0->SPI_CR = SPI_CR_SPIDIS;
|
||||
SPI0->SPI_CR = SPI_CR_SWRST;
|
||||
SPI0->SPI_CR = SPI_CR_SWRST;
|
||||
SPI0->SPI_CR = SPI_CR_SPIEN;
|
||||
u8g_MicroDelay();
|
||||
|
||||
/* master mode, no fault detection, chip select 0 */
|
||||
SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_PCSDEC | SPI_MR_MODFDIS;
|
||||
|
||||
/* Polarity, Phase, 8 Bit data transfer, baud rate */
|
||||
/* x * 1000 / 84 --> clock cycle in ns
|
||||
5 * 1000 / 84 = 58 ns
|
||||
SCBR > 50 *84 / 1000 --> SCBR=5
|
||||
SCBR > 300*84 / 1000 --> SCBR=26
|
||||
SCBR > 400*84 / 1000 --> SCBR=34
|
||||
*/
|
||||
|
||||
if ( arg_val <= U8G_SPI_CLK_CYCLE_50NS )
|
||||
{
|
||||
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(5) | 1;
|
||||
}
|
||||
else if ( arg_val <= U8G_SPI_CLK_CYCLE_300NS )
|
||||
{
|
||||
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(26) | 1;
|
||||
}
|
||||
else if ( arg_val <= U8G_SPI_CLK_CYCLE_400NS )
|
||||
{
|
||||
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(34) | 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SPI0->SPI_CSR[0] = SPI_CSR_SCBR(84) | 1;
|
||||
}
|
||||
|
||||
u8g_MicroDelay();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
|
||||
u8g_MicroDelay();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
/* disable */
|
||||
u8g_MicroDelay(); /* this delay is required to avoid that the display is switched off too early --> DOGS102 with DUE */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* enable */
|
||||
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
u8g_spi_out(arg_val);
|
||||
u8g_MicroDelay();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_spi_out(*ptr++);
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_spi_out(u8g_pgm_read(ptr));
|
||||
ptr++;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else /* U8G_ARDUINO_ATMEGA_HW_SPI */
|
||||
|
||||
#endif /* U8G_ARDUINO_ATMEGA_HW_SPI */
|
||||
|
||||
#else /* ARDUINO */
|
||||
|
||||
|
@ -0,0 +1,159 @@
|
||||
/*
|
||||
|
||||
u8g_com_arduino_hw_usart_spi.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
SPI Clock Cycle Type
|
||||
|
||||
SSD1351 50ns 20 MHz
|
||||
SSD1322 300ns 3.3 MHz
|
||||
SSD1327 300ns
|
||||
SSD1306 300ns
|
||||
ST7565 400ns 2.5 MHz
|
||||
ST7920 400ns
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#if defined(ARDUINO)
|
||||
|
||||
#if defined(__AVR_ATmega32U4__ )
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static uint8_t u8g_usart_spi_out(uint8_t data)
|
||||
{
|
||||
/* send data */
|
||||
UDR1 = data;
|
||||
/* wait for empty transmit buffer */
|
||||
while(!(UCSR1A & (1 << UDRE1)));
|
||||
|
||||
return UDR1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_INIT:
|
||||
/* SCK is already an output as we overwrite TXLED */
|
||||
u8g_com_arduino_assign_pin_output_high(u8g);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
|
||||
// Init interface at 2MHz
|
||||
UBRR1 = 0x00;
|
||||
UCSR1C = (1 << UMSEL11) | (1 << UMSEL10);
|
||||
UCSR1B = (1 << TXEN1);
|
||||
UBRR1 = 3;
|
||||
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
/* disable */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* enable */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
u8g_usart_spi_out(arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_usart_spi_out(*ptr++);
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_usart_spi_out(u8g_pgm_read(ptr));
|
||||
ptr++;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* #elif defined(__18CXX) || defined(__PIC32MX) */
|
||||
/* #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ */
|
||||
|
||||
#else /* __AVR_ATmega32U4__ */
|
||||
|
||||
#endif /* __AVR_ATmega32U4__ */
|
||||
|
||||
#else /* ARDUINO */
|
||||
|
||||
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* ARDUINO */
|
||||
|
@ -48,6 +48,12 @@
|
||||
|
||||
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
|
||||
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
*/
|
||||
|
||||
@ -97,17 +103,23 @@ static void u8g_com_arduino_no_en_parallel_init(u8g_t *u8g)
|
||||
u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]);
|
||||
}
|
||||
|
||||
void u8g_com_arduino_no_en_write_data_pin(uint8_t pin, uint8_t val)
|
||||
/* No atomic protcetion. This is done by caller */
|
||||
static void u8g_com_arduino_no_en_write_data_pin(uint8_t pin, uint8_t val)
|
||||
{
|
||||
if ( val != 0 )
|
||||
*u8g_data_port[pin] |= u8g_data_mask[pin];
|
||||
{
|
||||
*u8g_data_port[pin] |= u8g_data_mask[pin];
|
||||
}
|
||||
else
|
||||
{
|
||||
*u8g_data_port[pin] &= ~u8g_data_mask[pin];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void u8g_com_arduino_no_en_parallel_write(u8g_t *u8g, uint8_t val)
|
||||
{
|
||||
U8G_ATOMIC_START();
|
||||
u8g_com_arduino_no_en_write_data_pin( 0, val&1 );
|
||||
val >>= 1;
|
||||
u8g_com_arduino_no_en_write_data_pin( 1, val&1 );
|
||||
@ -125,6 +137,7 @@ void u8g_com_arduino_no_en_parallel_write(u8g_t *u8g, uint8_t val)
|
||||
val >>= 1;
|
||||
u8g_com_arduino_no_en_write_data_pin( 7, val&1 );
|
||||
val >>= 1;
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
/* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */
|
||||
if ( u8g->pin_list[U8G_PI_CS_STATE] == 1 )
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
u8g_arduino_parallel.c
|
||||
u8g_com_arduino_parallel.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
@ -87,13 +87,10 @@ void u8g_com_arduino_parallel_write(u8g_t *u8g, uint8_t val)
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_D7, val&1);
|
||||
|
||||
/* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */
|
||||
//u8g_Delay(1);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH);
|
||||
//u8g_Delay(1);
|
||||
u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW);
|
||||
u8g_10MicroDelay(); /* ST7920 commands: 72us */
|
||||
//u8g_Delay(2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,6 +42,13 @@
|
||||
u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
|
||||
u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
|
||||
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
@ -80,8 +87,10 @@ uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, v
|
||||
#ifdef UCSR0B
|
||||
UCSR0B = 0; // disable USART 0
|
||||
#endif
|
||||
U8G_ATOMIC_START();
|
||||
DDRD = 0x0ff;
|
||||
PORTD = 0x0ff;
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
/* setup the RW pin as output and force it to low */
|
||||
if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE )
|
||||
|
@ -54,18 +54,20 @@
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define I2C_SLA (0x3c*2)
|
||||
//#define I2C_CMD_MODE 0x080
|
||||
#define I2C_CMD_MODE 0x000
|
||||
#define I2C_DATA_MODE 0x040
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
|
||||
|
||||
#define I2C_SLA (0x3c*2)
|
||||
//#define I2C_CMD_MODE 0x080
|
||||
#define I2C_CMD_MODE 0x000
|
||||
#define I2C_DATA_MODE 0x040
|
||||
|
||||
uint8_t u8g_com_arduino_ssd_start_sequence(u8g_t *u8g)
|
||||
{
|
||||
/* are we requested to set the a0 state? */
|
||||
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
|
||||
return 1;
|
||||
|
||||
return 1;
|
||||
|
||||
/* setup bus, might be a repeated start */
|
||||
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||
return 0;
|
||||
@ -79,8 +81,7 @@ uint8_t u8g_com_arduino_ssd_start_sequence(u8g_t *u8g)
|
||||
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 0;
|
||||
return 1;
|
||||
}
|
||||
@ -199,3 +200,13 @@ uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* defined(U8G_WITH_PINLIST) */
|
||||
|
||||
uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* defined(U8G_WITH_PINLIST) */
|
||||
|
||||
|
@ -0,0 +1,330 @@
|
||||
/*
|
||||
|
||||
u8g_com_arduino_st7920_custom.c
|
||||
|
||||
Additional COM device, initially introduced for 3D Printer community
|
||||
Implements a fast SW SPI com subsystem
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
A special SPI interface for ST7920 controller
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#if defined(ARDUINO)
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#include "wiring_private.h"
|
||||
#include "pins_arduino.h"
|
||||
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#include "wiring_private.h"
|
||||
#endif
|
||||
|
||||
#if defined(__AVR__)
|
||||
|
||||
static uint8_t u8g_bitData, u8g_bitNotData;
|
||||
static uint8_t u8g_bitClock, u8g_bitNotClock;
|
||||
static volatile uint8_t *u8g_outData;
|
||||
static volatile uint8_t *u8g_outClock;
|
||||
|
||||
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
{
|
||||
u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
|
||||
u8g_outClock = portOutputRegister(digitalPinToPort(clockPin));
|
||||
u8g_bitData = digitalPinToBitMask(dataPin);
|
||||
u8g_bitClock = digitalPinToBitMask(clockPin);
|
||||
|
||||
u8g_bitNotClock = u8g_bitClock;
|
||||
u8g_bitNotClock ^= 0x0ff;
|
||||
|
||||
u8g_bitNotData = u8g_bitData;
|
||||
u8g_bitNotData ^= 0x0ff;
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) U8G_NOINLINE;
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
{
|
||||
uint8_t cnt = 8;
|
||||
uint8_t bitData = u8g_bitData;
|
||||
uint8_t bitNotData = u8g_bitNotData;
|
||||
uint8_t bitClock = u8g_bitClock;
|
||||
uint8_t bitNotClock = u8g_bitNotClock;
|
||||
volatile uint8_t *outData = u8g_outData;
|
||||
volatile uint8_t *outClock = u8g_outClock;
|
||||
|
||||
|
||||
U8G_ATOMIC_START();
|
||||
bitData |= *outData;
|
||||
bitNotData &= *outData;
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
*outData = bitData;
|
||||
else
|
||||
*outData = bitNotData;
|
||||
|
||||
/*
|
||||
*outClock |= bitClock;
|
||||
val <<= 1;
|
||||
cnt--;
|
||||
*outClock &= bitNotClock;
|
||||
*/
|
||||
|
||||
val <<= 1;
|
||||
*outClock &= bitNotClock;
|
||||
cnt--;
|
||||
// removed micro delays, because AVRs are too slow and the delay is not required
|
||||
//u8g_MicroDelay();
|
||||
*outClock |= bitClock;
|
||||
//u8g_MicroDelay();
|
||||
} while( cnt != 0 );
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
#elif defined(__18CXX) || defined(__PIC32MX)
|
||||
|
||||
uint16_t dog_bitData, dog_bitNotData;
|
||||
uint16_t dog_bitClock, dog_bitNotClock;
|
||||
volatile uint32_t *dog_outData;
|
||||
volatile uint32_t *dog_outClock;
|
||||
volatile uint32_t dog_pic32_spi_tmp;
|
||||
|
||||
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
{
|
||||
dog_outData = portOutputRegister(digitalPinToPort(dataPin));
|
||||
dog_outClock = portOutputRegister(digitalPinToPort(clockPin));
|
||||
dog_bitData = digitalPinToBitMask(dataPin);
|
||||
dog_bitClock = digitalPinToBitMask(clockPin);
|
||||
|
||||
dog_bitNotClock = dog_bitClock;
|
||||
dog_bitNotClock ^= 0x0ffff;
|
||||
|
||||
dog_bitNotData = dog_bitData;
|
||||
dog_bitNotData ^= 0x0ffff;
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
{
|
||||
uint8_t cnt = 8;
|
||||
U8G_ATOMIC_START();
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
*dog_outData |= dog_bitData;
|
||||
else
|
||||
*dog_outData &= dog_bitNotData;
|
||||
val <<= 1;
|
||||
//u8g_MicroDelay();
|
||||
//*dog_outClock |= dog_bitClock;
|
||||
*dog_outClock &= dog_bitNotClock;
|
||||
cnt--;
|
||||
u8g_MicroDelay();
|
||||
//*dog_outClock &= dog_bitNotClock;
|
||||
*dog_outClock |= dog_bitClock;
|
||||
u8g_MicroDelay();
|
||||
|
||||
} while( cnt != 0 );
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* default interface, Arduino DUE (__arm__) */
|
||||
|
||||
uint8_t u8g_data_custom_pin;
|
||||
uint8_t u8g_clock_custom_pin;
|
||||
|
||||
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
{
|
||||
u8g_data_custom_pin = dataPin;
|
||||
u8g_clock_custom_pin = clockPin;
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
{
|
||||
uint8_t cnt = 8;
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
digitalWrite(u8g_data_custom_pin, HIGH);
|
||||
else
|
||||
digitalWrite(u8g_data_custom_pin, LOW);
|
||||
val <<= 1;
|
||||
//u8g_MicroDelay();
|
||||
digitalWrite(u8g_clock_custom_pin, LOW);
|
||||
cnt--;
|
||||
u8g_MicroDelay();
|
||||
digitalWrite(u8g_clock_custom_pin, HIGH);
|
||||
u8g_MicroDelay();
|
||||
} while( cnt != 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static void u8g_com_arduino_st7920_write_byte_seq(uint8_t rs, uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if ( rs == 0 )
|
||||
{
|
||||
/* command */
|
||||
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
|
||||
}
|
||||
else if ( rs == 1 )
|
||||
{
|
||||
/* data */
|
||||
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
|
||||
}
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
u8g_com_arduino_do_shift_out_msb_first(*ptr & 0x0f0);
|
||||
u8g_com_arduino_do_shift_out_msb_first(*ptr << 4);
|
||||
ptr++;
|
||||
len--;
|
||||
u8g_10MicroDelay();
|
||||
}
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
u8g_10MicroDelay();
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if ( rs == 0 )
|
||||
{
|
||||
/* command */
|
||||
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
|
||||
}
|
||||
else if ( rs == 1 )
|
||||
{
|
||||
/* data */
|
||||
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
|
||||
}
|
||||
|
||||
u8g_com_arduino_do_shift_out_msb_first(val & 0x0f0);
|
||||
u8g_com_arduino_do_shift_out_msb_first(val << 4);
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
u8g_10MicroDelay();
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_com_arduino_assign_pin_output_high(u8g);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
// u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW);
|
||||
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
|
||||
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
/* disable, note: the st7920 has an active high chip select */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* enable */
|
||||
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
u8g_com_arduino_st7920_write_byte( u8g->pin_list[U8G_PI_A0_STATE], arg_val);
|
||||
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
|
||||
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
u8g_com_arduino_st7920_write_byte_seq(u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_com_arduino_st7920_write_byte(u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr) );
|
||||
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
|
||||
ptr++;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* ARDUINO */
|
||||
|
||||
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* ARDUINO */
|
||||
|
@ -54,10 +54,10 @@
|
||||
|
||||
/* remove the definition for attiny */
|
||||
#if __AVR_ARCH__ == 2
|
||||
#undef U8G_ATMEGA_HW_SPI
|
||||
#undef U8G_ARDUINO_ATMEGA_HW_SPI
|
||||
#endif
|
||||
#if __AVR_ARCH__ == 25
|
||||
#undef U8G_ATMEGA_HW_SPI
|
||||
#undef U8G_ARDUINO_ATMEGA_HW_SPI
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -68,6 +68,33 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
#if ARDUINO < 100
|
||||
|
||||
/* fixed pins */
|
||||
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) // Sanguino.cc board
|
||||
#define PIN_SCK 7
|
||||
#define PIN_MISO 6
|
||||
#define PIN_MOSI 5
|
||||
#define PIN_CS 4
|
||||
#else // Arduino Board
|
||||
#define PIN_SCK 13
|
||||
#define PIN_MISO 12
|
||||
#define PIN_MOSI 11
|
||||
#define PIN_CS 10
|
||||
#endif // (__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
|
||||
|
||||
#else
|
||||
|
||||
/* use Arduino pin definitions */
|
||||
#define PIN_SCK SCK
|
||||
#define PIN_MISO MISO
|
||||
#define PIN_MOSI MOSI
|
||||
#define PIN_CS SS
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static uint8_t u8g_arduino_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE;
|
||||
static uint8_t u8g_arduino_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val)
|
||||
{
|
||||
@ -81,6 +108,34 @@ static uint8_t u8g_arduino_st7920_hw_spi_shift_out(u8g_t *u8g, uint8_t val)
|
||||
}
|
||||
|
||||
|
||||
static void u8g_com_arduino_st7920_write_byte_hw_spi_seq(u8g_t *u8g, uint8_t rs, uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if ( rs == 0 )
|
||||
{
|
||||
/* command */
|
||||
u8g_arduino_st7920_hw_spi_shift_out(u8g, 0x0f8);
|
||||
}
|
||||
else if ( rs == 1 )
|
||||
{
|
||||
/* data */
|
||||
u8g_arduino_st7920_hw_spi_shift_out(u8g, 0x0fa);
|
||||
}
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
u8g_arduino_st7920_hw_spi_shift_out(u8g, *ptr & 0x0f0);
|
||||
u8g_arduino_st7920_hw_spi_shift_out(u8g, *ptr << 4);
|
||||
ptr++;
|
||||
len--;
|
||||
u8g_10MicroDelay();
|
||||
}
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
u8g_10MicroDelay();
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_st7920_write_byte_hw_spi(u8g_t *u8g, uint8_t rs, uint8_t val) U8G_NOINLINE;
|
||||
static void u8g_com_arduino_st7920_write_byte_hw_spi(u8g_t *u8g, uint8_t rs, uint8_t val)
|
||||
{
|
||||
@ -115,14 +170,29 @@ uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
{
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_com_arduino_assign_pin_output_high(u8g);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
|
||||
|
||||
/* code from u8g_com-arduino_hw_spi.c */
|
||||
pinMode(PIN_SCK, OUTPUT);
|
||||
digitalWrite(PIN_SCK, LOW);
|
||||
pinMode(PIN_MOSI, OUTPUT);
|
||||
digitalWrite(PIN_MOSI, LOW);
|
||||
/* pinMode(PIN_MISO, INPUT); */
|
||||
|
||||
pinMode(PIN_CS, OUTPUT); /* system chip select for the atmega board */
|
||||
digitalWrite(PIN_CS, HIGH);
|
||||
|
||||
|
||||
//u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
DDRB |= _BV(3); /* D0, MOSI */
|
||||
DDRB |= _BV(5); /* SCK */
|
||||
DDRB |= _BV(2); /* slave select */
|
||||
|
||||
PORTB &= ~_BV(3); /* D0, MOSI = 0 */
|
||||
PORTB &= ~_BV(5); /* SCK = 0 */
|
||||
#endif
|
||||
|
||||
/*
|
||||
SPR1 SPR0
|
||||
@ -170,15 +240,18 @@ uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
u8g_com_arduino_st7920_write_byte_hw_spi_seq(u8g, u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
|
||||
/*
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_com_arduino_st7920_write_byte_hw_spi(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
|
||||
// u8g->pin_list[U8G_PI_A0_STATE] = 2;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
|
@ -33,6 +33,13 @@
|
||||
|
||||
A special SPI interface for ST7920 controller
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
@ -51,10 +58,10 @@
|
||||
|
||||
#if defined(__AVR__)
|
||||
|
||||
uint8_t u8g_bitData, u8g_bitNotData;
|
||||
uint8_t u8g_bitClock, u8g_bitNotClock;
|
||||
volatile uint8_t *u8g_outData;
|
||||
volatile uint8_t *u8g_outClock;
|
||||
static uint8_t u8g_bitData, u8g_bitNotData;
|
||||
static uint8_t u8g_bitClock, u8g_bitNotClock;
|
||||
static volatile uint8_t *u8g_outData;
|
||||
static volatile uint8_t *u8g_outClock;
|
||||
|
||||
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
{
|
||||
@ -80,12 +87,17 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
uint8_t bitNotClock = u8g_bitNotClock;
|
||||
volatile uint8_t *outData = u8g_outData;
|
||||
volatile uint8_t *outClock = u8g_outClock;
|
||||
|
||||
|
||||
U8G_ATOMIC_START();
|
||||
bitData |= *outData;
|
||||
bitNotData &= *outData;
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
*outData |= bitData;
|
||||
*outData = bitData;
|
||||
else
|
||||
*outData &= bitNotData;
|
||||
*outData = bitNotData;
|
||||
|
||||
/*
|
||||
*outClock |= bitClock;
|
||||
@ -102,6 +114,7 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
*outClock |= bitClock;
|
||||
//u8g_MicroDelay();
|
||||
} while( cnt != 0 );
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
#elif defined(__18CXX) || defined(__PIC32MX)
|
||||
@ -129,6 +142,7 @@ static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
{
|
||||
uint8_t cnt = 8;
|
||||
U8G_ATOMIC_START();
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
@ -146,6 +160,7 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
u8g_MicroDelay();
|
||||
|
||||
} while( cnt != 0 );
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
#else
|
||||
@ -183,7 +198,33 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
#endif
|
||||
|
||||
|
||||
static void u8g_com_arduino_st7920_write_byte_seq(uint8_t rs, uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if ( rs == 0 )
|
||||
{
|
||||
/* command */
|
||||
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
|
||||
}
|
||||
else if ( rs == 1 )
|
||||
{
|
||||
/* data */
|
||||
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
|
||||
}
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
u8g_com_arduino_do_shift_out_msb_first(*ptr & 0x0f0);
|
||||
u8g_com_arduino_do_shift_out_msb_first(*ptr << 4);
|
||||
ptr++;
|
||||
len--;
|
||||
u8g_10MicroDelay();
|
||||
}
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
u8g_10MicroDelay();
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val)
|
||||
{
|
||||
@ -209,7 +250,6 @@ static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val)
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
@ -243,6 +283,9 @@ uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
|
||||
/* enable */
|
||||
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||
/* 28 Dec 2013 reassign pins, fixes issue with more than one display */
|
||||
/* issue 227 */
|
||||
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -253,15 +296,7 @@ uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val,
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
u8g_com_arduino_st7920_write_byte(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
|
||||
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
u8g_com_arduino_st7920_write_byte_seq(u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
|
@ -31,7 +31,6 @@
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
@ -31,6 +31,12 @@
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@ -48,6 +54,9 @@
|
||||
#include "wiring_private.h"
|
||||
#endif
|
||||
|
||||
/*=========================================================*/
|
||||
/* Arduino, AVR */
|
||||
|
||||
#if defined(__AVR__)
|
||||
|
||||
uint8_t u8g_bitData, u8g_bitNotData;
|
||||
@ -79,6 +88,7 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
uint8_t bitNotClock = u8g_bitNotClock;
|
||||
volatile uint8_t *outData = u8g_outData;
|
||||
volatile uint8_t *outClock = u8g_outClock;
|
||||
U8G_ATOMIC_START();
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
@ -91,8 +101,11 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
cnt--;
|
||||
*outClock &= bitNotClock;
|
||||
} while( cnt != 0 );
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
/*=========================================================*/
|
||||
/* Arduino, Chipkit */
|
||||
#elif defined(__18CXX) || defined(__PIC32MX)
|
||||
|
||||
uint16_t dog_bitData, dog_bitNotData;
|
||||
@ -118,6 +131,7 @@ static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
{
|
||||
uint8_t cnt = 8;
|
||||
U8G_ATOMIC_START();
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
@ -142,8 +156,54 @@ static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
dog_pic32_spi_tmp = *dog_outClock;
|
||||
dog_pic32_spi_tmp = *dog_outClock;
|
||||
} while( cnt != 0 );
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
/*=========================================================*/
|
||||
/* Arduino Due */
|
||||
#elif defined(__SAM3X8E__)
|
||||
|
||||
/* Due */
|
||||
|
||||
void u8g_digital_write_sam_high(uint8_t pin)
|
||||
{
|
||||
PIO_Set( g_APinDescription[pin].pPort, g_APinDescription[pin].ulPin) ;
|
||||
}
|
||||
|
||||
void u8g_digital_write_sam_low(uint8_t pin)
|
||||
{
|
||||
PIO_Clear( g_APinDescription[pin].pPort, g_APinDescription[pin].ulPin) ;
|
||||
}
|
||||
|
||||
static uint8_t u8g_sam_data_pin;
|
||||
static uint8_t u8g_sam_clock_pin;
|
||||
|
||||
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||
{
|
||||
u8g_sam_data_pin = dataPin;
|
||||
u8g_sam_clock_pin = clockPin;
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||
{
|
||||
uint8_t i = 8;
|
||||
do
|
||||
{
|
||||
if ( val & 128 )
|
||||
u8g_digital_write_sam_high(u8g_sam_data_pin);
|
||||
else
|
||||
u8g_digital_write_sam_low(u8g_sam_data_pin);
|
||||
val <<= 1;
|
||||
//u8g_MicroDelay();
|
||||
u8g_digital_write_sam_high(u8g_sam_clock_pin);
|
||||
u8g_MicroDelay();
|
||||
u8g_digital_write_sam_low(u8g_sam_clock_pin);
|
||||
u8g_MicroDelay();
|
||||
i--;
|
||||
} while( i != 0 );
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
/* empty interface */
|
||||
|
||||
@ -188,6 +248,8 @@ uint8_t u8g_com_arduino_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
/* enable */
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||
/* issue 227 */
|
||||
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -50,6 +50,13 @@
|
||||
u8g_InitRW8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset)
|
||||
u8g_InitRW8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16)
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
@ -123,8 +130,10 @@ static void u8g_com_arduino_t6963_init(u8g_t *u8g)
|
||||
u8g_data_mask[7] = digitalPinToBitMask(u8g->pin_list[U8G_PI_D7]);
|
||||
}
|
||||
|
||||
|
||||
static void u8g_com_arduino_t6963_write_data_pin(uint8_t pin, uint8_t val)
|
||||
{
|
||||
/* no ATOMIC protection required here, this is done by calling procedure */
|
||||
if ( val != 0 )
|
||||
*u8g_output_data_port[pin] |= u8g_data_mask[pin];
|
||||
else
|
||||
@ -134,6 +143,7 @@ static void u8g_com_arduino_t6963_write_data_pin(uint8_t pin, uint8_t val)
|
||||
static void u8g_com_arduino_t6963_set_port_output(void)
|
||||
{
|
||||
uint8_t i;
|
||||
U8G_ATOMIC_START();
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
#if defined(__PIC32MX)
|
||||
@ -147,11 +157,13 @@ static void u8g_com_arduino_t6963_set_port_output(void)
|
||||
#endif
|
||||
|
||||
}
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
static void u8g_com_arduino_t6963_set_port_input(void)
|
||||
{
|
||||
uint8_t i;
|
||||
U8G_ATOMIC_START();
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
#if defined(__PIC32MX)
|
||||
@ -167,11 +179,14 @@ static void u8g_com_arduino_t6963_set_port_input(void)
|
||||
*u8g_output_data_port[i] &= ~u8g_data_mask[i]; // no pullup
|
||||
#endif
|
||||
}
|
||||
U8G_ATOMIC_END();
|
||||
}
|
||||
|
||||
|
||||
static void u8g_com_arduino_t6963_write(u8g_t *u8g, uint8_t val)
|
||||
{
|
||||
U8G_ATOMIC_START();
|
||||
|
||||
u8g_com_arduino_t6963_write_data_pin( 0, val&1 );
|
||||
val >>= 1;
|
||||
u8g_com_arduino_t6963_write_data_pin( 1, val&1 );
|
||||
@ -189,6 +204,7 @@ static void u8g_com_arduino_t6963_write(u8g_t *u8g, uint8_t val)
|
||||
val >>= 1;
|
||||
u8g_com_arduino_t6963_write_data_pin( 7, val&1 );
|
||||
val >>= 1;
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_WR, 0);
|
||||
u8g_MicroDelay(); /* 80ns, reference: t6963 datasheet */
|
||||
@ -203,6 +219,7 @@ static uint8_t u8g_com_arduino_t6963_read(u8g_t *u8g)
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_RD, 0);
|
||||
u8g_MicroDelay(); /* 150ns, reference: t6963 datasheet */
|
||||
|
||||
U8G_ATOMIC_START();
|
||||
/* only read bits 0, 1 and 3 */
|
||||
if ( (*u8g_input_data_port[3] & u8g_data_mask[3]) != 0 )
|
||||
val++;
|
||||
@ -213,7 +230,8 @@ static uint8_t u8g_com_arduino_t6963_read(u8g_t *u8g)
|
||||
val <<= 1;
|
||||
if ( (*u8g_input_data_port[0] & u8g_data_mask[0]) != 0 )
|
||||
val++;
|
||||
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
u8g_com_arduino_digital_write(u8g, U8G_PI_RD, 1);
|
||||
u8g_MicroDelay(); /* 10ns, reference: t6963 datasheet */
|
||||
|
||||
|
@ -0,0 +1,206 @@
|
||||
/*
|
||||
|
||||
u8g_com_arduino_uc_i2c.c
|
||||
|
||||
com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant
|
||||
I2C protocol
|
||||
|
||||
ToDo: Rename this to u8g_com_avr_ssd_i2c.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2012, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Special pin usage:
|
||||
U8G_PI_I2C_OPTION additional options
|
||||
U8G_PI_A0_STATE used to store the last value of the command/data register selection
|
||||
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
|
||||
U8G_PI_SCL clock line (NOT USED)
|
||||
U8G_PI_SDA data line (NOT USED)
|
||||
|
||||
U8G_PI_RESET reset line (currently disabled, see below)
|
||||
|
||||
Protocol:
|
||||
SLA, Cmd/Data Selection, Arguments
|
||||
The command/data register is selected by a special instruction byte, which is sent after SLA
|
||||
|
||||
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
|
||||
#define DOGM240_SLA_CMD (0x38*2)
|
||||
#define DOGM240_SLA_DATA (0x39*2)
|
||||
|
||||
uint8_t u8g_com_arduino_uc_start_sequence(u8g_t *u8g)
|
||||
{
|
||||
/* are we requested to set the a0 state? */
|
||||
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
|
||||
return 1;
|
||||
|
||||
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
|
||||
{
|
||||
if ( u8g_i2c_start(DOGM240_SLA_CMD) == 0 )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( u8g_i2c_start(DOGM240_SLA_DATA) == 0 )
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_INIT:
|
||||
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
|
||||
//u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
|
||||
//u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
|
||||
|
||||
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
|
||||
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
/* Currently disabled, but it could be enable. Previous restrictions have been removed */
|
||||
/* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
u8g->pin_list[U8G_PI_A0_STATE] = 0;
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
/* disable chip, send stop condition */
|
||||
u8g_i2c_stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* enable, do nothing: any byte writing will trigger the i2c start */
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
if ( u8g_i2c_send_byte(arg_val) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
// u8g_i2c_stop();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
if ( u8g_i2c_send_byte(*ptr++) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
// u8g_i2c_stop();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
{
|
||||
register uint8_t *ptr = arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
|
||||
return 0;
|
||||
ptr++;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
// u8g_i2c_stop();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
|
||||
|
||||
#ifdef OLD_CODE
|
||||
if ( i2c_state != 0 )
|
||||
{
|
||||
u8g_i2c_stop();
|
||||
i2c_state = 0;
|
||||
}
|
||||
|
||||
if ( u8g_com_arduino_uc_start_sequence(arg_val) == 0 )
|
||||
return 0;
|
||||
|
||||
/* setup bus, might be a repeated start */
|
||||
/*
|
||||
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||
return 0;
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
i2c_state = 1;
|
||||
|
||||
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
i2c_state = 2;
|
||||
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* defined(U8G_WITH_PINLIST) */
|
||||
|
||||
uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* defined(U8G_WITH_PINLIST) */
|
||||
|
@ -37,6 +37,14 @@
|
||||
and
|
||||
SCK is at PORTB, Pin 5
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START()
|
||||
U8G_ATOMIC_END()
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
@ -85,6 +93,9 @@ uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
|
||||
u8g_SetPIOutput(u8g, U8G_PI_CS);
|
||||
u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||
|
||||
U8G_ATOMIC_START();
|
||||
|
||||
DDRB |= _BV(3); /* D0, MOSI */
|
||||
DDRB |= _BV(5); /* SCK */
|
||||
@ -92,6 +103,9 @@ uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
|
||||
PORTB &= ~_BV(3); /* D0, MOSI = 0 */
|
||||
PORTB &= ~_BV(5); /* SCK = 0 */
|
||||
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
|
||||
|
||||
/*
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
u8g_atmega_parallel.c
|
||||
u8g_com_atmega_parallel.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
|
@ -38,6 +38,12 @@
|
||||
and
|
||||
SCK is at PORTB, Pin 5
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START()
|
||||
U8G_ATOMIC_END()
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@ -106,12 +112,16 @@ uint8_t u8g_com_atmega_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val
|
||||
u8g_SetPIOutput(u8g, U8G_PI_CS);
|
||||
//u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||
|
||||
U8G_ATOMIC_START();
|
||||
|
||||
DDRB |= _BV(3); /* D0, MOSI */
|
||||
DDRB |= _BV(5); /* SCK */
|
||||
DDRB |= _BV(2); /* slave select */
|
||||
|
||||
PORTB &= ~_BV(3); /* D0, MOSI = 0 */
|
||||
PORTB &= ~_BV(5); /* SCK = 0 */
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
u8g_SetPILevel(u8g, U8G_PI_CS, 1);
|
||||
|
||||
/*
|
||||
@ -125,7 +135,8 @@ uint8_t u8g_com_atmega_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val
|
||||
|
||||
/* maybe set CPOL and CPHA to 1 */
|
||||
/* 20 Dez 2012: did set CPOL and CPHA to 1 in Arduino variant! */
|
||||
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(0<<CPOL)|(0<<CPHA);
|
||||
/* 24 Jan 2014: implemented, see also issue 221 */
|
||||
SPCR = (1<<SPE) | (1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(1<<CPOL)|(1<<CPHA);
|
||||
#ifdef U8G_HW_SPI_2X
|
||||
SPSR = (1 << SPI2X); /* double speed, issue 89 */
|
||||
#endif
|
||||
|
@ -35,10 +35,13 @@
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
static uint8_t u8g_i2c_err_code;
|
||||
//#define U8G_I2C_WITH_NO_ACK
|
||||
|
||||
static uint8_t u8g_i2c_err_code;
|
||||
static uint8_t u8g_i2c_opt; /* U8G_I2C_OPT_NO_ACK, SAM: U8G_I2C_OPT_DEV_1 */
|
||||
/*
|
||||
position values
|
||||
1: start condition
|
||||
@ -115,10 +118,22 @@ void u8g_i2c_init(uint8_t options)
|
||||
TWSR = 0;
|
||||
--> 100KHz
|
||||
|
||||
TWBR = 12;
|
||||
TWSR = 0;
|
||||
--> 400KHz
|
||||
|
||||
F_CPU/(2*100000)-8 --> calculate TWBR value for 100KHz
|
||||
*/
|
||||
u8g_i2c_opt = options;
|
||||
TWSR = 0;
|
||||
TWBR = F_CPU/(2*100000)-8;
|
||||
if ( options & U8G_I2C_OPT_FAST )
|
||||
{
|
||||
TWBR = F_CPU/(2*400000)-8;
|
||||
}
|
||||
else
|
||||
{
|
||||
TWBR = F_CPU/(2*100000)-8;
|
||||
}
|
||||
u8g_i2c_clear_error();
|
||||
}
|
||||
|
||||
@ -129,8 +144,15 @@ uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
|
||||
{
|
||||
if ( cnt == 0 )
|
||||
{
|
||||
u8g_i2c_set_error(U8G_I2C_ERR_TIMEOUT, pos);
|
||||
return 0; /* error */
|
||||
if ( u8g_i2c_opt & U8G_I2C_OPT_NO_ACK )
|
||||
{
|
||||
return 1; /* all ok */
|
||||
}
|
||||
else
|
||||
{
|
||||
u8g_i2c_set_error(U8G_I2C_ERR_TIMEOUT, pos);
|
||||
return 0; /* error */
|
||||
}
|
||||
}
|
||||
cnt--;
|
||||
}
|
||||
@ -167,13 +189,20 @@ uint8_t u8g_i2c_start(uint8_t sla)
|
||||
/* wait */
|
||||
if ( u8g_i2c_wait(_BV(TWINT), 2) == 0 )
|
||||
return 0;
|
||||
status = TW_STATUS;
|
||||
|
||||
/* check status after sla */
|
||||
if ( status != TW_MT_SLA_ACK )
|
||||
if ( u8g_i2c_opt & U8G_I2C_OPT_NO_ACK )
|
||||
{
|
||||
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 2);
|
||||
return 0;
|
||||
/* do not check for ACK */
|
||||
}
|
||||
else
|
||||
{
|
||||
status = TW_STATUS;
|
||||
/* check status after sla */
|
||||
if ( status != TW_MT_SLA_ACK )
|
||||
{
|
||||
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 2);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -186,14 +215,21 @@ uint8_t u8g_i2c_send_byte(uint8_t data)
|
||||
TWCR = _BV(TWINT) | _BV(TWEN);
|
||||
if ( u8g_i2c_wait(_BV(TWINT), 3) == 0 )
|
||||
return 0;
|
||||
status = TW_STATUS;
|
||||
|
||||
if ( status != TW_MT_DATA_ACK )
|
||||
|
||||
if ( u8g_i2c_opt & U8G_I2C_OPT_NO_ACK )
|
||||
{
|
||||
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 3);
|
||||
return 0;
|
||||
/* do not check for ACK */
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
status = TW_STATUS;
|
||||
if ( status != TW_MT_DATA_ACK )
|
||||
{
|
||||
u8g_i2c_set_error(U8G_I2C_ERR_BUS, 3);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -217,6 +253,363 @@ void twi_send(uint8_t adr, uint8_t data1, uint8_t data2)
|
||||
}
|
||||
*/
|
||||
|
||||
#elif defined(ARDUINO) && defined(__SAM3X8E__)
|
||||
/* Arduino Due */
|
||||
#include "Arduino.h"
|
||||
#include "sam.h"
|
||||
|
||||
/*
|
||||
|
||||
Controller
|
||||
|
||||
TWI0 TWCK0 PA18 A DUE PCB: SCL1
|
||||
TWI0 TWD0 PA17 A DUE PCB: SDA1
|
||||
TWI1 TWCK1 PB13 A DUE PCB: SCL 21
|
||||
TWI1 TWD1 PB12 A DUE PCB: SDA 20
|
||||
|
||||
Arduino definitions
|
||||
|
||||
#define PIN_WIRE_SDA (20u)
|
||||
#define PIN_WIRE_SCL (21u)
|
||||
#define WIRE_INTERFACE TWI1
|
||||
#define WIRE_INTERFACE_ID ID_TWI1
|
||||
#define WIRE_ISR_HANDLER TWI1_Handler
|
||||
|
||||
#define PIN_WIRE1_SDA (70u)
|
||||
#define PIN_WIRE1_SCL (71u)
|
||||
#define WIRE1_INTERFACE TWI0
|
||||
#define WIRE1_INTERFACE_ID ID_TWI0
|
||||
#define WIRE1_ISR_HANDLER TWI0_Handler
|
||||
|
||||
|
||||
*/
|
||||
|
||||
static void i2c_400KHz_delay(void)
|
||||
{
|
||||
/* should be at least 4 */
|
||||
/* should be 5 for 100KHz transfer speed */
|
||||
|
||||
|
||||
/*
|
||||
Arduino Due
|
||||
0x NOP: 470KHz
|
||||
4x NOP: 450KHz
|
||||
8x NOP: 430KHz
|
||||
16x NOP: 400KHz
|
||||
*/
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
__NOP();
|
||||
}
|
||||
|
||||
static void i2c_100KHz_delay(void)
|
||||
{
|
||||
/*
|
||||
1x u8g_MicroDelay() ca. 130KHz
|
||||
2x u8g_MicroDelay() ca. 80KHz
|
||||
*/
|
||||
u8g_MicroDelay();
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
|
||||
|
||||
uint32_t i2c_started = 0;
|
||||
uint32_t i2c_scl_pin = 0;
|
||||
uint32_t i2c_sda_pin = 0;
|
||||
void (*i2c_delay)(void) = i2c_100KHz_delay;
|
||||
|
||||
const PinDescription *i2c_scl_pin_desc;
|
||||
const PinDescription *i2c_sda_pin_desc;
|
||||
|
||||
|
||||
/* maybe this can be optimized */
|
||||
static void i2c_init(void)
|
||||
{
|
||||
i2c_sda_pin_desc = &(g_APinDescription[i2c_sda_pin]);
|
||||
i2c_scl_pin_desc = &(g_APinDescription[i2c_scl_pin]);
|
||||
pinMode(i2c_sda_pin, OUTPUT);
|
||||
digitalWrite(i2c_sda_pin, HIGH);
|
||||
pinMode(i2c_scl_pin, OUTPUT);
|
||||
digitalWrite(i2c_scl_pin, HIGH);
|
||||
PIO_Configure( i2c_sda_pin_desc->pPort, PIO_OUTPUT_0, i2c_sda_pin_desc->ulPin, PIO_OPENDRAIN );
|
||||
PIO_Configure( i2c_scl_pin_desc->pPort, PIO_OUTPUT_0, i2c_scl_pin_desc->ulPin, PIO_OPENDRAIN );
|
||||
PIO_Clear( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin) ;
|
||||
PIO_Clear( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin) ;
|
||||
PIO_Configure( i2c_sda_pin_desc->pPort, PIO_INPUT, i2c_sda_pin_desc->ulPin, PIO_DEFAULT ) ;
|
||||
PIO_Configure( i2c_scl_pin_desc->pPort, PIO_INPUT, i2c_scl_pin_desc->ulPin, PIO_DEFAULT ) ;
|
||||
i2c_delay();
|
||||
}
|
||||
|
||||
/* actually, the scl line is not observed, so this procedure does not return a value */
|
||||
static void i2c_read_scl_and_delay(void)
|
||||
{
|
||||
uint32_t dwMask = i2c_scl_pin_desc->ulPin;
|
||||
//PIO_Configure( i2c_scl_pin_desc->pPort, PIO_INPUT, i2c_scl_pin_desc->ulPin, PIO_DEFAULT ) ;
|
||||
//PIO_SetInput( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin, PIO_DEFAULT ) ;
|
||||
|
||||
/* set as input */
|
||||
i2c_scl_pin_desc->pPort->PIO_ODR = dwMask ;
|
||||
i2c_scl_pin_desc->pPort->PIO_PER = dwMask ;
|
||||
|
||||
i2c_delay();
|
||||
}
|
||||
|
||||
static void i2c_clear_scl(void)
|
||||
{
|
||||
uint32_t dwMask = i2c_scl_pin_desc->ulPin;
|
||||
|
||||
/* set open collector and drive low */
|
||||
//PIO_Configure( i2c_scl_pin_desc->pPort, PIO_OUTPUT_0, i2c_scl_pin_desc->ulPin, PIO_OPENDRAIN );
|
||||
//PIO_SetOutput( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin, 0, 1, 0);
|
||||
|
||||
/* open drain, zero default output */
|
||||
i2c_scl_pin_desc->pPort->PIO_MDER = dwMask;
|
||||
i2c_scl_pin_desc->pPort->PIO_CODR = dwMask;
|
||||
i2c_scl_pin_desc->pPort->PIO_OER = dwMask;
|
||||
i2c_scl_pin_desc->pPort->PIO_PER = dwMask;
|
||||
|
||||
//PIO_Clear( i2c_scl_pin_desc->pPort, i2c_scl_pin_desc->ulPin) ;
|
||||
}
|
||||
|
||||
static uint8_t i2c_read_sda(void)
|
||||
{
|
||||
uint32_t dwMask = i2c_sda_pin_desc->ulPin;
|
||||
//PIO_Configure( i2c_sda_pin_desc->pPort, PIO_INPUT, i2c_sda_pin_desc->ulPin, PIO_DEFAULT ) ;
|
||||
//PIO_SetInput( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin, PIO_DEFAULT ) ;
|
||||
|
||||
/* set as input */
|
||||
i2c_sda_pin_desc->pPort->PIO_ODR = dwMask ;
|
||||
i2c_sda_pin_desc->pPort->PIO_PER = dwMask ;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void i2c_clear_sda(void)
|
||||
{
|
||||
uint32_t dwMask = i2c_sda_pin_desc->ulPin;
|
||||
|
||||
/* set open collector and drive low */
|
||||
//PIO_Configure( i2c_sda_pin_desc->pPort, PIO_OUTPUT_0, i2c_sda_pin_desc->ulPin, PIO_OPENDRAIN );
|
||||
//PIO_SetOutput( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin, 0, 1, 0);
|
||||
|
||||
/* open drain, zero default output */
|
||||
i2c_sda_pin_desc->pPort->PIO_MDER = dwMask ;
|
||||
i2c_sda_pin_desc->pPort->PIO_CODR = dwMask ;
|
||||
i2c_sda_pin_desc->pPort->PIO_OER = dwMask ;
|
||||
i2c_sda_pin_desc->pPort->PIO_PER = dwMask ;
|
||||
|
||||
//PIO_Clear( i2c_sda_pin_desc->pPort, i2c_sda_pin_desc->ulPin) ;
|
||||
}
|
||||
|
||||
static void i2c_start(void)
|
||||
{
|
||||
if ( i2c_started != 0 )
|
||||
{
|
||||
/* if already started: do restart */
|
||||
i2c_read_sda(); /* SDA = 1 */
|
||||
i2c_delay();
|
||||
i2c_read_scl_and_delay();
|
||||
}
|
||||
i2c_read_sda();
|
||||
/*
|
||||
if (i2c_read_sda() == 0)
|
||||
{
|
||||
// do something because arbitration is lost
|
||||
}
|
||||
*/
|
||||
/* send the start condition, both lines go from 1 to 0 */
|
||||
i2c_clear_sda();
|
||||
i2c_delay();
|
||||
i2c_clear_scl();
|
||||
i2c_started = 1;
|
||||
}
|
||||
|
||||
|
||||
static void i2c_stop(void)
|
||||
{
|
||||
/* set SDA to 0 */
|
||||
i2c_clear_sda();
|
||||
i2c_delay();
|
||||
|
||||
/* now release all lines */
|
||||
i2c_read_scl_and_delay();
|
||||
|
||||
/* set SDA to 1 */
|
||||
i2c_read_sda();
|
||||
i2c_delay();
|
||||
i2c_started = 0;
|
||||
}
|
||||
|
||||
static void i2c_write_bit(uint8_t val)
|
||||
{
|
||||
if (val)
|
||||
i2c_read_sda();
|
||||
else
|
||||
i2c_clear_sda();
|
||||
|
||||
i2c_delay();
|
||||
i2c_read_scl_and_delay();
|
||||
i2c_clear_scl();
|
||||
}
|
||||
|
||||
static uint8_t i2c_read_bit(void)
|
||||
{
|
||||
uint8_t val;
|
||||
/* do not drive SDA */
|
||||
i2c_read_sda();
|
||||
i2c_delay();
|
||||
i2c_read_scl_and_delay();
|
||||
val = i2c_read_sda();
|
||||
i2c_delay();
|
||||
i2c_clear_scl();
|
||||
return val;
|
||||
}
|
||||
|
||||
static uint8_t i2c_write_byte(uint8_t b)
|
||||
{
|
||||
i2c_write_bit(b & 128);
|
||||
i2c_write_bit(b & 64);
|
||||
i2c_write_bit(b & 32);
|
||||
i2c_write_bit(b & 16);
|
||||
i2c_write_bit(b & 8);
|
||||
i2c_write_bit(b & 4);
|
||||
i2c_write_bit(b & 2);
|
||||
i2c_write_bit(b & 1);
|
||||
|
||||
/* read ack from client */
|
||||
/* 0: ack was given by client */
|
||||
/* 1: nothing happend during ack cycle */
|
||||
return i2c_read_bit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void u8g_i2c_init(uint8_t options)
|
||||
{
|
||||
u8g_i2c_opt = options;
|
||||
u8g_i2c_clear_error();
|
||||
|
||||
if ( u8g_i2c_opt & U8G_I2C_OPT_FAST )
|
||||
{
|
||||
i2c_delay = i2c_400KHz_delay;
|
||||
}
|
||||
else
|
||||
{
|
||||
i2c_delay = i2c_100KHz_delay;
|
||||
}
|
||||
|
||||
|
||||
if ( u8g_i2c_opt & U8G_I2C_OPT_DEV_1 )
|
||||
{
|
||||
i2c_scl_pin = PIN_WIRE1_SCL;
|
||||
i2c_sda_pin = PIN_WIRE1_SDA;
|
||||
|
||||
//REG_PIOA_PDR = PIO_PB12A_TWD1 | PIO_PB13A_TWCK1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
i2c_scl_pin = PIN_WIRE_SCL;
|
||||
i2c_sda_pin = PIN_WIRE_SDA;
|
||||
|
||||
//REG_PIOA_PDR = PIO_PA17A_TWD0 | PIO_PA18A_TWCK0;
|
||||
}
|
||||
|
||||
i2c_init();
|
||||
|
||||
}
|
||||
|
||||
/* sla includes also the r/w bit */
|
||||
uint8_t u8g_i2c_start(uint8_t sla)
|
||||
{
|
||||
i2c_start();
|
||||
i2c_write_byte(sla);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8g_i2c_send_byte(uint8_t data)
|
||||
{
|
||||
return i2c_write_byte(data);
|
||||
}
|
||||
|
||||
void u8g_i2c_stop(void)
|
||||
{
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
|
||||
#elif defined(U8G_RASPBERRY_PI)
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringPiI2C.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define I2C_SLA 0x3c
|
||||
|
||||
static int fd=-1;
|
||||
static uint8_t i2cMode = 0;
|
||||
|
||||
void u8g_i2c_init(uint8_t options) {
|
||||
u8g_i2c_clear_error();
|
||||
u8g_i2c_opt = options;
|
||||
|
||||
if (wiringPiSetup() == -1) {
|
||||
printf("wiringPi-Error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fd = wiringPiI2CSetup(I2C_SLA);
|
||||
if (fd < 0) {
|
||||
printf ("Unable to open I2C device 0: %s\n", strerror (errno)) ;
|
||||
exit (1) ;
|
||||
}
|
||||
//u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||
//u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||
}
|
||||
uint8_t u8g_i2c_start(uint8_t sla) {
|
||||
u8g_i2c_send_mode(0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void u8g_i2c_stop(void) {
|
||||
}
|
||||
|
||||
uint8_t u8g_i2c_send_mode(uint8_t mode) {
|
||||
i2cMode = mode;
|
||||
}
|
||||
|
||||
uint8_t u8g_i2c_send_byte(uint8_t data) {
|
||||
wiringPiI2CWriteReg8(fd, i2cMode, data);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* empty interface */
|
||||
|
@ -32,7 +32,19 @@
|
||||
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.
|
||||
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START();
|
||||
U8G_ATOMIC_END();
|
||||
|
||||
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos) Convert to internal number: AVR: port*8+bitpos, ARM: port*16+bitpos
|
||||
void u8g_SetPinOutput(uint8_t internal_pin_number)
|
||||
void u8g_SetPinInput(uint8_t internal_pin_number)
|
||||
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
|
||||
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@ -159,9 +171,16 @@ void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
|
||||
volatile uint8_t * tmp = u8g_get_avr_io_ptr(u8g_avr_port_P, internal_pin_number>>3);
|
||||
|
||||
if ( level == 0 )
|
||||
*tmp &= ~_BV(internal_pin_number&7);
|
||||
{
|
||||
U8G_ATOMIC_AND(tmp, ~_BV(internal_pin_number&7));
|
||||
// *tmp &= ~_BV(internal_pin_number&7);
|
||||
}
|
||||
else
|
||||
*tmp |= _BV(internal_pin_number&7);
|
||||
{
|
||||
U8G_ATOMIC_OR(tmp, _BV(internal_pin_number&7));
|
||||
//*tmp |= _BV(internal_pin_number&7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
|
||||
@ -172,8 +191,31 @@ uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(U8G_RASPBERRY_PI)
|
||||
|
||||
#include <wiringPi.h>
|
||||
//#include "/usr/local/include/wiringPi.h"
|
||||
|
||||
void u8g_SetPinOutput(uint8_t internal_pin_number) {
|
||||
pinMode(internal_pin_number, OUTPUT);
|
||||
}
|
||||
|
||||
void u8g_SetPinInput(uint8_t internal_pin_number) {
|
||||
pinMode(internal_pin_number, INPUT);
|
||||
}
|
||||
|
||||
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level) {
|
||||
digitalWrite(internal_pin_number, level);
|
||||
}
|
||||
|
||||
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number) {
|
||||
return digitalRead(internal_pin_number);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/* convert "port" and "bitpos" to internal pin number */
|
||||
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)
|
||||
{
|
||||
port <<= 3;
|
||||
@ -201,6 +243,8 @@ uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
|
||||
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi)
|
||||
{
|
||||
uint8_t pin;
|
||||
@ -216,3 +260,14 @@ void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level)
|
||||
if ( pin != U8G_PIN_NONE )
|
||||
u8g_SetPinLevel(pin, level);
|
||||
}
|
||||
|
||||
#else /* defined(U8G_WITH_PINLIST) */
|
||||
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi)
|
||||
{
|
||||
}
|
||||
|
||||
void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* defined(U8G_WITH_PINLIST) */
|
||||
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
|
||||
u8g_com_raspberrypi_hw_spi.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2012, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Assumes, that
|
||||
MOSI is at PORTB, Pin 3
|
||||
and
|
||||
SCK is at PORTB, Pin 5
|
||||
|
||||
Update for ATOMIC operation done (01 Jun 2013)
|
||||
U8G_ATOMIC_OR(ptr, val)
|
||||
U8G_ATOMIC_AND(ptr, val)
|
||||
U8G_ATOMIC_START()
|
||||
U8G_ATOMIC_END()
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
|
||||
|
||||
#if defined(U8G_RASPBERRY_PI)
|
||||
|
||||
#include <wiringPiSPI.h>
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_INIT:
|
||||
// check wiringPi setup
|
||||
if (wiringPiSetup() == -1)
|
||||
{
|
||||
printf("wiringPi-Error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (wiringPiSPISetup (0, 100000) < 0)
|
||||
{
|
||||
printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||
u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
/* Done by the SPI hardware */
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
wiringPiSPIDataRW (0, &arg_val, 1) ;
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
wiringPiSPIDataRW (0, arg_ptr, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
wiringPiSPIDataRW (0, arg_ptr, arg_val);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,176 @@
|
||||
/*
|
||||
Special pin usage:
|
||||
U8G_PI_I2C_OPTION additional options
|
||||
U8G_PI_A0_STATE used to store the last value of the command/data register selection
|
||||
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
|
||||
U8G_PI_SCL clock line (NOT USED)
|
||||
U8G_PI_SDA data line (NOT USED)
|
||||
|
||||
U8G_PI_RESET reset line (currently disabled, see below)
|
||||
|
||||
Protocol:
|
||||
SLA, Cmd/Data Selection, Arguments
|
||||
The command/data register is selected by a special instruction byte, which is sent after SLA
|
||||
|
||||
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#if defined(U8G_RASPBERRY_PI)
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringPiI2C.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define I2C_SLA 0x3c
|
||||
#define I2C_CMD_MODE 0x000
|
||||
#define I2C_DATA_MODE 0x040
|
||||
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
|
||||
uint8_t u8g_com_raspberrypi_ssd_start_sequence(u8g_t *u8g)
|
||||
{
|
||||
/* are we requested to set the a0 state? */
|
||||
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
|
||||
return 1;
|
||||
|
||||
/* setup bus, might be a repeated start */
|
||||
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||
return 0;
|
||||
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
|
||||
{
|
||||
if ( u8g_i2c_send_mode(I2C_CMD_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( u8g_i2c_send_mode(I2C_DATA_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
|
||||
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||
u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_CHIP_SELECT:
|
||||
u8g->pin_list[U8G_PI_A0_STATE] = 0;
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
/* disable chip, send stop condition */
|
||||
u8g_i2c_stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* enable, do nothing: any byte writing will trigger the i2c start */
|
||||
}
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
if ( u8g_i2c_send_byte(arg_val) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
// u8g_i2c_stop();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
{
|
||||
register uint8_t *ptr = (uint8_t *)arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
if ( u8g_i2c_send_byte(*ptr++) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
// u8g_i2c_stop();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
|
||||
return u8g_i2c_stop(), 0;
|
||||
{
|
||||
register uint8_t *ptr = (uint8_t *)arg_ptr;
|
||||
while( arg_val > 0 )
|
||||
{
|
||||
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
|
||||
return 0;
|
||||
ptr++;
|
||||
arg_val--;
|
||||
}
|
||||
}
|
||||
// u8g_i2c_stop();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
||||
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
|
||||
|
||||
#ifdef OLD_CODE
|
||||
if ( i2c_state != 0 )
|
||||
{
|
||||
u8g_i2c_stop();
|
||||
i2c_state = 0;
|
||||
}
|
||||
|
||||
if ( u8g_com_raspberrypi_ssd_start_sequence(arg_val) == 0 )
|
||||
return 0;
|
||||
|
||||
/* setup bus, might be a repeated start */
|
||||
/*
|
||||
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||
return 0;
|
||||
if ( arg_val == 0 )
|
||||
{
|
||||
i2c_state = 1;
|
||||
|
||||
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
i2c_state = 2;
|
||||
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* defined(U8G_WITH_PINLIST) */
|
||||
|
||||
uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* defined(U8G_WITH_PINLIST) */
|
||||
#endif
|
@ -30,7 +30,12 @@
|
||||
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.
|
||||
|
||||
|
||||
|
||||
void u8g_Delay(uint16_t val) Delay by "val" milliseconds
|
||||
void u8g_MicroDelay(void) Delay be one microsecond
|
||||
void u8g_10MicroDelay(void) Delay by 10 microseconds
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@ -40,19 +45,37 @@
|
||||
/*==== Part 1: Derive suitable delay procedure ====*/
|
||||
|
||||
#if defined(ARDUINO)
|
||||
|
||||
# if ARDUINO < 100
|
||||
# include <WProgram.h>
|
||||
# else
|
||||
# include <Arduino.h>
|
||||
# endif
|
||||
|
||||
# if defined(__AVR__)
|
||||
# define USE_AVR_DELAY
|
||||
# elif defined(__PIC32MX)
|
||||
# define USE_PIC32_DELAY
|
||||
# elif defined(__arm__) /* Arduino Due */
|
||||
# elif defined(__arm__) /* Arduino Due & Teensy */
|
||||
# define USE_ARDUINO_DELAY
|
||||
# else
|
||||
# define USE_ARDUINO_DELAY
|
||||
# endif
|
||||
#elif defined(U8G_RASPBERRY_PI)
|
||||
# define USE_RASPBERRYPI_DELAY
|
||||
#elif defined(__AVR__)
|
||||
# define USE_AVR_DELAY
|
||||
#elif defined(__18CXX)
|
||||
# define USE_PIC18_DELAY
|
||||
#elif defined(__arm__)
|
||||
/* do not define anything, all procedures are expected to be defined outside u8glib */
|
||||
|
||||
/*
|
||||
void u8g_Delay(uint16_t val);
|
||||
void u8g_MicroDelay(void);
|
||||
void u8g_10MicroDelay(void);
|
||||
*/
|
||||
|
||||
#else
|
||||
# define USE_DUMMY_DELAY
|
||||
#endif
|
||||
@ -61,6 +84,26 @@
|
||||
|
||||
/*==== Part 2: Definition of the delay procedures ====*/
|
||||
|
||||
/*== Raspberry Pi Delay ==*/
|
||||
#if defined (USE_RASPBERRYPI_DELAY)
|
||||
#include <wiringPi.h>
|
||||
//#include "/usr/local/include/wiringPi.h"
|
||||
void u8g_Delay(uint16_t val) {
|
||||
//delay(val);
|
||||
//usleep((uint32_t)val*(uint32_t)1000);
|
||||
delayMicroseconds((uint32_t)val*(uint32_t)1000);
|
||||
}
|
||||
void u8g_MicroDelay(void)
|
||||
{
|
||||
usleep(1);
|
||||
}
|
||||
void u8g_10MicroDelay(void)
|
||||
{
|
||||
usleep(10);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*== AVR Delay ==*/
|
||||
|
||||
#if defined(USE_AVR_DELAY)
|
||||
@ -144,7 +187,11 @@ void u8g_10MicroDelay(void)
|
||||
#if defined(USE_ARDUINO_DELAY)
|
||||
void u8g_Delay(uint16_t val)
|
||||
{
|
||||
#if defined(__arm__)
|
||||
delayMicroseconds((uint32_t)val*(uint32_t)1000);
|
||||
#else
|
||||
delay(val);
|
||||
#endif
|
||||
}
|
||||
void u8g_MicroDelay(void)
|
||||
{
|
||||
|
@ -0,0 +1,199 @@
|
||||
/*
|
||||
|
||||
u8g_dev_a2_micro_printer_ds.c
|
||||
|
||||
Use DC2 bitmap command of the A2 Micro panel termal printer
|
||||
double stroke
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define LINE_DELAY 40
|
||||
|
||||
|
||||
uint8_t u8g_dev_a2_micro_printer_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
uint8_t y, i, j;
|
||||
uint8_t *ptr;
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
y = pb->p.page_y0;
|
||||
ptr = pb->buf;
|
||||
|
||||
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||
u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||
u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||
|
||||
u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||
u8g_WriteByte(u8g, dev, 42 ); /* * */
|
||||
u8g_WriteByte(u8g, dev, pb->p.page_height );
|
||||
u8g_WriteByte(u8g, dev, pb->width/8 );
|
||||
|
||||
for( i = 0; i < pb->p.page_height; i ++ )
|
||||
{
|
||||
for( j = 0; j < pb->width/8; j++ )
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, *ptr);
|
||||
ptr++;
|
||||
}
|
||||
u8g_Delay(LINE_DELAY);
|
||||
y++;
|
||||
}
|
||||
|
||||
/* set parameters back to their default values */
|
||||
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||
u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||
u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
static uint8_t u8g_dev_expand4(uint8_t val)
|
||||
{
|
||||
uint8_t a,b,c,d;
|
||||
a = val&1;
|
||||
b = (val&2)<<1;
|
||||
c = (val&4)<<2;
|
||||
d = (val&8)<<3;
|
||||
a |=b;
|
||||
a |=c;
|
||||
a |=d;
|
||||
a |= a<<1;
|
||||
return a;
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_a2_micro_printer_double_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
{
|
||||
//u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
//u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||
//u8g_WriteByte(u8g, dev, 42 ); /* * */
|
||||
//u8g_WriteByte(u8g, dev, pb->p.total_height*2 );
|
||||
//u8g_WriteByte(u8g, dev, pb->width/8*2 );
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
uint8_t y, i, j;
|
||||
uint8_t *ptr;
|
||||
uint8_t *p2;
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
y = pb->p.page_y0;
|
||||
ptr = pb->buf;
|
||||
//u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||
//u8g_WriteByte(u8g, dev, 35 ); /* # */
|
||||
//u8g_WriteByte(u8g, dev, 0x0ff ); /* max */
|
||||
|
||||
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||
u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||
u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||
|
||||
u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||
u8g_WriteByte(u8g, dev, 42 ); /* * */
|
||||
u8g_WriteByte(u8g, dev, pb->p.page_height*2 );
|
||||
u8g_WriteByte(u8g, dev, pb->width/8*2 );
|
||||
|
||||
for( i = 0; i < pb->p.page_height; i ++ )
|
||||
{
|
||||
p2 = ptr;
|
||||
for( j = 0; j < pb->width/8; j++ )
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
|
||||
p2++;
|
||||
}
|
||||
u8g_Delay(LINE_DELAY);
|
||||
p2 = ptr;
|
||||
for( j = 0; j < pb->width/8; j++ )
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
|
||||
p2++;
|
||||
}
|
||||
u8g_Delay(LINE_DELAY);
|
||||
ptr += pb->width/8;
|
||||
y++;
|
||||
}
|
||||
|
||||
/* set parameters back to their default values */
|
||||
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||
u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||
u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
#if defined(U8G_16BIT)
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 384, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 360, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 720, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||
#else
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 240, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||
#endif
|
||||
|
||||
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x120_ds, 192, 120, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
@ -78,7 +78,7 @@ uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
/* current page: pb->p.page */
|
||||
/* ptr to the buffer: pb->buf */
|
||||
|
||||
(*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, pb->buf+WIDTH);
|
||||
(*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
|
@ -121,7 +121,7 @@ uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
case U8G_DEV_MSG_GET_PAGE_BOX:
|
||||
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -0,0 +1,281 @@
|
||||
/*
|
||||
|
||||
u8g_dev_ht1632.c
|
||||
|
||||
1-Bit (BW) Driver for HT1632 controller
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
|
||||
U8G_PIN_NONE can be used as argument
|
||||
|
||||
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
|
||||
{
|
||||
...
|
||||
u8g->pin_list[U8G_PI_SCK] = sck;
|
||||
u8g->pin_list[U8G_PI_MOSI] = mosi;
|
||||
u8g->pin_list[U8G_PI_CS] = cs;
|
||||
u8g->pin_list[U8G_PI_A0] = a0;
|
||||
u8g->pin_list[U8G_PI_RESET] = reset;
|
||||
|
||||
mapping
|
||||
|
||||
#define DATA_PIN --> U8G_PI_MOSI
|
||||
#define WR_PIN --> U8G_PI_SCK
|
||||
#define CS_PIN --> U8G_PI_CS
|
||||
U8G_PI_A0 --> not used
|
||||
U8G_PI_RESET --> not used
|
||||
|
||||
Usage:
|
||||
|
||||
u8g_InitSPI(&u8g, &u8g_dev_ht1632_24x16, WR_PIN, DATA_IN, CS_PIN, U8G_PIN_NONE, U8G_PIN_NONE)
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 24
|
||||
#define HEIGHT 16
|
||||
#define PAGE_HEIGHT 16
|
||||
|
||||
/* http://forum.arduino.cc/index.php?topic=168537.0 */
|
||||
|
||||
#define HT1632_CMD_SYSDIS 0x00 // CMD= 0000-0000-x Turn off oscil
|
||||
#define HT1632_CMD_SYSON 0x01 // CMD= 0000-0001-x Enable system oscil
|
||||
#define HT1632_CMD_LEDOFF 0x02 // CMD= 0000-0010-x LED duty cycle gen off
|
||||
#define HT1632_CMD_LEDON 0x03 // CMD= 0000-0011-x LEDs ON
|
||||
#define HT1632_CMD_BLOFF 0x08 // CMD= 0000-1000-x Blink OFF
|
||||
#define HT1632_CMD_BLON 0x09 // CMD= 0000-1001-x Blink On
|
||||
#define HT1632_CMD_SLVMD 0x10 // CMD= 0001-00xx-x Slave Mode
|
||||
#define HT1632_CMD_MSTMD 0x14 // CMD= 0001-01xx-x Master Mode
|
||||
#define HT1632_CMD_RCCLK 0x18 // CMD= 0001-10xx-x Use on-chip clock
|
||||
#define HT1632_CMD_EXTCLK 0x1C // CMD= 0001-11xx-x Use external clock
|
||||
#define HT1632_CMD_COMS00 0x20 // CMD= 0010-ABxx-x commons options
|
||||
#define HT1632_CMD_COMS01 0x24 // CMD= 0010-ABxx-x commons options
|
||||
#define HT1632_CMD_COMS10 0x28 // CMD= 0010-ABxx-x commons options
|
||||
#define HT1632_CMD_COMS11 0x2C // P-MOS OUTPUT AND 16COMMON OPTION
|
||||
#define HT1632_CMD_PWM 0xA0 // CMD= 101x-PPPP-x PWM duty cycle
|
||||
|
||||
#define HT1632_ID_CMD 4 /* ID = 100 - Commands */
|
||||
#define HT1632_ID_RD 6 /* ID = 110 - Read RAM */
|
||||
#define HT1632_ID_WR 5 /* ID = 101 - Write RAM */
|
||||
|
||||
#define HT1632_ID_LEN 3 // IDs are 3 bits
|
||||
#define HT1632_CMD_LEN 8 // CMDs are 8 bits
|
||||
#define HT1632_DATA_LEN 8 // Data are 4*2 bits
|
||||
#define HT1632_ADDR_LEN 7 // Address are 7 bits
|
||||
|
||||
#if defined(ARDUINO)
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
//#define WR_PIN 3
|
||||
//#define DATA_PIN 2
|
||||
//#define CS_PIN 4
|
||||
|
||||
void ht1632_write_data_MSB(u8g_t *u8g, uint8_t cnt, uint8_t data, uint8_t extra)
|
||||
{
|
||||
int8_t i;
|
||||
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
|
||||
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
|
||||
|
||||
for(i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
if ((data >> i) & 1)
|
||||
{
|
||||
digitalWrite(data_pin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(data_pin, LOW);
|
||||
}
|
||||
|
||||
digitalWrite(wr_pin, LOW);
|
||||
u8g_MicroDelay();
|
||||
digitalWrite(wr_pin, HIGH);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
|
||||
// Send an extra bit
|
||||
if (extra)
|
||||
{
|
||||
digitalWrite(data_pin, HIGH);
|
||||
digitalWrite(wr_pin, LOW);
|
||||
u8g_MicroDelay();
|
||||
digitalWrite(wr_pin, HIGH);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
}
|
||||
|
||||
void ht1632_write_data(u8g_t *u8g, uint8_t cnt, uint8_t data)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
|
||||
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
|
||||
for (i = 0; i < cnt; i++)
|
||||
{
|
||||
|
||||
if ((data >> i) & 1) {
|
||||
digitalWrite(data_pin, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(data_pin, LOW);
|
||||
}
|
||||
|
||||
digitalWrite(wr_pin, LOW);
|
||||
u8g_MicroDelay();
|
||||
digitalWrite(wr_pin, HIGH);
|
||||
u8g_MicroDelay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ht1632_init(u8g_t *u8g)
|
||||
{
|
||||
//uint8_t i;
|
||||
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
|
||||
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
|
||||
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
|
||||
pinMode(data_pin, OUTPUT);
|
||||
pinMode(wr_pin, OUTPUT);
|
||||
pinMode(cs_pin, OUTPUT);
|
||||
|
||||
digitalWrite(data_pin, HIGH);
|
||||
digitalWrite(wr_pin, HIGH);
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
|
||||
digitalWrite(cs_pin, LOW);
|
||||
/* init display once after startup */
|
||||
ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false); // IDs are 3 bits
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSDIS, true); // 8 bits
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSON, true); // 8 bits
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_COMS11, true); // 8 bits
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_LEDON, true); // 8 bits
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_BLOFF, true); // 8 bits
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM+15, true); // 8 bits
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
|
||||
/* removed following (debug) code */
|
||||
/*
|
||||
digitalWrite(cs_pin, LOW);
|
||||
ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
|
||||
ht1632_write_data_MSB(u8g, 7, 0, false);
|
||||
for(i = 0; i<48; ++i)
|
||||
{
|
||||
ht1632_write_data(u8g, 8, 0xFF);
|
||||
}
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
page: 0=data contain lines 0..16, 1=data contain lines 16..32 (a 24x16 display will only have page 0)
|
||||
cnt: width of the display
|
||||
data: pointer to a buffer with 2*cnt bytes.
|
||||
*/
|
||||
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
uint8_t addr;
|
||||
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
|
||||
/* send data to the ht1632 */
|
||||
digitalWrite(cs_pin, LOW);
|
||||
ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
|
||||
ht1632_write_data_MSB(u8g, 7, page*2*cnt, false);
|
||||
|
||||
// Operating in progressive addressing mode
|
||||
for (addr = 0; addr < cnt; addr++)
|
||||
{
|
||||
ht1632_write_data(u8g, 8, data[addr]);
|
||||
ht1632_write_data(u8g, 8, data[addr+cnt]);
|
||||
}
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
}
|
||||
|
||||
/* value is between 0...15 */
|
||||
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
|
||||
{
|
||||
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
|
||||
digitalWrite(cs_pin, LOW);
|
||||
ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false);
|
||||
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM + value, false);
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
}
|
||||
|
||||
#else
|
||||
void ht1632_init(u8g_t *u8g)
|
||||
{
|
||||
}
|
||||
|
||||
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
}
|
||||
|
||||
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* ARDUINO */
|
||||
|
||||
|
||||
uint8_t u8g_dev_ht1632_24x16_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
ht1632_init(u8g);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
/* current page: pb->p.page */
|
||||
/* ptr to the buffer: pb->buf */
|
||||
ht1632_transfer_data(u8g, pb->p.page, WIDTH, pb->buf);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
/* values passed to SetContrast() are between 0 and 255, scale down to 0...15 */
|
||||
ht1632_set_contrast(u8g, (*(uint8_t *)arg) >> 4);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_ht1632_24x16_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_ht1632_24x16_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ht1632_24x16_buf};
|
||||
u8g_dev_t u8g_dev_ht1632_24x16 = { u8g_dev_ht1632_24x16_fn, &u8g_dev_ht1632_24x16_pb, u8g_com_null_fn };
|
||||
|
@ -272,7 +272,7 @@ uint8_t u8g_dev_ili9325d_320x240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||
//for(;;)
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ili9325d_320x240_init_seq);
|
||||
|
||||
|
@ -73,7 +73,7 @@ uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -98,7 +98,7 @@ uint8_t u8g_dev_lc7981_160x80_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_160x80_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -96,7 +96,7 @@ uint8_t u8g_dev_lc7981_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -96,7 +96,7 @@ uint8_t u8g_dev_lc7981_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -40,7 +40,12 @@
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#ifdef U8G_16BIT
|
||||
#define WIDTH 320
|
||||
#else
|
||||
#define WIDTH 240
|
||||
#endif
|
||||
|
||||
#define HEIGHT 64
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
@ -98,7 +103,7 @@ uint8_t u8g_dev_lc7981_320x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_320x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -143,3 +148,4 @@ uint8_t u8g_dev_lc7981_320x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_lc7981_320x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_320x64_fn, U8G_COM_FAST_PARALLEL);
|
||||
|
||||
|
@ -0,0 +1,232 @@
|
||||
/*
|
||||
|
||||
u8g_dev_ld7032_60x32.c
|
||||
|
||||
60x32 OLED display
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
/* define width as 64, so that it is a multiple of 8 */
|
||||
#define WIDTH 64
|
||||
#define HEIGHT 32
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
static const uint8_t u8g_dev_ld7032_60x32_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_DLY(1), /* delay 1 ms */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x002, /* Dot Matrix Display ON/OFF */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x001, /* ON */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x014, /* Dot Matrix Display Stand-by ON/OFF */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* ON */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x01a, /* Dot Matrix Frame Rate */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x004, /* special value for this OLED from manual */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x01d, /* Graphics Memory Writing Direction */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* reset default (right down, horizontal) */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x009, /* Display Direction */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* reset default (x,y: min --> max) */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x030, /* Display Size X */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* Column Start Output */
|
||||
0x03b, /* Column End Output */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x032, /* Display Size Y */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* Row Start Output */
|
||||
0x01f, /* Row End Output */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x010, /* Peak Pulse Width Set */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* 0 SCLK */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x016, /* Peak Pulse Delay Set */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* 0 SCLK */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x012, /* Dot Matrix Current Level Set */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x050, /* 0x050 * 1 uA = 80 uA */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x018, /* Pre-Charge Pulse Width */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x003, /* 3 SCLK */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x044, /* Pre-Charge Mode */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x002, /* Every Time */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x048, /* Row overlap timing */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x003, /* Pre-Charge + Peak Delay + Peak boot Timing */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x03f, /* VCC_R_SEL */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x011, /* ??? */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x03d, /* VSS selection */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* 2.8V */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x002, /* Dot Matrix Display ON/OFF */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x001, /* ON */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x008, /* write data */
|
||||
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
/* use box commands to set start adr */
|
||||
static const uint8_t u8g_dev_ld7032_60x32_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x034, /* box x start */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x000, /* 0 */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x035, /* box x end */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x007, /* */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x037, /* box y end */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
0x01f, /* */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x036, /* box y start */
|
||||
U8G_ESC_ADR(1), /* data mode */
|
||||
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_ld7032_60x32_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
/* ... */
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_ld7032_60x32_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
/* ... */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_ld7032_60x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_data_start);
|
||||
u8g_WriteByte(u8g, dev, pb->p.page_y0); /* y start */
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x008);
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ld7032_60x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ld7032_60x32_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_PARALLEL);
|
||||
U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_usart_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_USART_SPI);
|
||||
|
@ -58,7 +58,7 @@ uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
#endif
|
||||
case U8G_DEV_MSG_GET_PAGE_BOX:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -69,12 +69,36 @@ static const uint8_t u8g_dev_pcd8544_init_seq[] PROGMEM = {
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
static const uint8_t u8g_dev_pcd8544_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
|
||||
0x00c, /* display on, normal */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_pcd8544_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
|
||||
0x008, /* display blank */
|
||||
0x024, /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
|
||||
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
uint8_t u8g_dev_pcd8544_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -101,10 +125,17 @@ uint8_t u8g_dev_pcd8544_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) );
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
|
||||
U8G_PB_DEV(u8g_dev_pcd8544_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_pcd8544_84x48_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_HW_SPI);
|
||||
|
||||
|
@ -88,7 +88,7 @@ uint8_t u8g_dev_pcf8812_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcf8812_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -104,6 +104,20 @@ uint8_t u8g_dev_pcf8812_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
|
||||
/* mirrored output, not tested*/
|
||||
/*
|
||||
{
|
||||
uint8_t i = pb->width;
|
||||
while( i > 0 )
|
||||
{
|
||||
i--;
|
||||
u8g_WriteByte(u8g, dev, ((unsigned char *)pb->buf)[i] );
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
@ -121,3 +135,4 @@ uint8_t u8g_dev_pcf8812_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
|
||||
/* u8g_com_arduino_sw_spi_fn does not work, too fast??? */
|
||||
U8G_PB_DEV(u8g_dev_pcf8812_96x65_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcf8812_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_pcf8812_96x65_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcf8812_fn, U8G_COM_HW_SPI);
|
||||
|
@ -70,7 +70,7 @@ uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -123,7 +123,7 @@ static const uint8_t u8g_dev_ssd1306_128x32_adafruit3_init_seq[] PROGMEM = {
|
||||
|
||||
0x0ae, /* display off, sleep mode */
|
||||
0x0d5, 0x080, /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
|
||||
0x0a8, 0x01f, /* Feb 23, 2013: 128x32 OLED: 0x01f, 128x64 OLED 0x03f */
|
||||
0x0a8, 0x01f, /* Feb 23, 2013: 128x32 OLED: 0x01f, 128x32 OLED 0x03f */
|
||||
|
||||
0x0d3, 0x000, /* */
|
||||
|
||||
@ -131,7 +131,7 @@ static const uint8_t u8g_dev_ssd1306_128x32_adafruit3_init_seq[] PROGMEM = {
|
||||
|
||||
0x08d, 0x014, /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
|
||||
|
||||
0x020, 0x002, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), Feb 23, 2013: 128x32 OLED: 0x002, 128x64 OLED 0x012 */
|
||||
0x020, 0x002, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), Feb 23, 2013: 128x32 OLED: 0x002, 128x32 OLED 0x012 */
|
||||
0x0a1, /* segment remap a0/a1*/
|
||||
0x0c8, /* c0: scan dir normal, c8: reverse */
|
||||
0x0da, 0x002, /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
|
||||
@ -196,7 +196,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -205,7 +205,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -214,7 +214,7 @@ uint8_t u8g_dev_ssd1306_128x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -241,7 +241,49 @@ uint8_t u8g_dev_ssd1306_128x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_ssd1306_128x32_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x32_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_128x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x32_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_128x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x32_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_128x32_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x32_fn, U8G_COM_SSD_I2C);
|
||||
|
||||
uint8_t u8g_dev_ssd1306_128x32_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_ssd1306_128x32_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x32_2x_buf};
|
||||
u8g_dev_t u8g_dev_ssd1306_128x32_2x_sw_spi = { u8g_dev_ssd1306_128x32_2x_fn, &u8g_dev_ssd1306_128x32_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1306_128x32_2x_hw_spi = { u8g_dev_ssd1306_128x32_2x_fn, &u8g_dev_ssd1306_128x32_2x_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1306_128x32_2x_i2c = { u8g_dev_ssd1306_128x32_2x_fn, &u8g_dev_ssd1306_128x32_2x_pb, U8G_COM_SSD_I2C };
|
||||
|
@ -172,7 +172,10 @@ static const uint8_t u8g_dev_ssd1306_128x64_univision_init_seq[] PROGMEM = {
|
||||
/* select one init sequence here */
|
||||
//#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_univision_init_seq
|
||||
//#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit1_init_seq
|
||||
// 26. Apr 2014: in this thead: http://forum.arduino.cc/index.php?topic=234930.msg1696754;topicseen#msg1696754
|
||||
// it is mentiond, that adafruit2_init_seq works better --> this will be used by the ssd1306_adafruit device
|
||||
//#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit2_init_seq
|
||||
|
||||
#define u8g_dev_ssd1306_128x64_init_seq u8g_dev_ssd1306_128x64_adafruit3_init_seq
|
||||
|
||||
|
||||
@ -180,7 +183,16 @@ static const uint8_t u8g_dev_ssd1306_128x64_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 */
|
||||
0x000, /* set lower 4 bit of the col adr to 4 */
|
||||
0x000, /* set lower 4 bit of the col adr to 0 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
/* the sh1106 is compatible to the ssd1306, but is 132x64. display seems to be centered */
|
||||
static const uint8_t u8g_dev_sh1106_128x64_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 */
|
||||
0x002, /* set lower 4 bit of the col adr to 2 (centered display with sh1106) */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -188,7 +200,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -197,7 +209,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -206,7 +218,38 @@ uint8_t u8g_dev_ssd1306_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_adafruit2_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_ssd1306_adafruit_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -232,6 +275,138 @@ uint8_t u8g_dev_ssd1306_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_sh1106_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_dev_ssd1306_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_sh1106_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_sh1106_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2+1)); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SSD_I2C);
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1306_adafruit_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_adafruit_128x64_fn, U8G_COM_SSD_I2C);
|
||||
|
||||
|
||||
uint8_t u8g_dev_ssd1306_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_ssd1306_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x64_2x_buf};
|
||||
u8g_dev_t u8g_dev_ssd1306_128x64_2x_sw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1306_128x64_2x_hw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SSD_I2C };
|
||||
|
||||
|
||||
U8G_PB_DEV(u8g_dev_sh1106_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_sh1106_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_sh1106_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sh1106_128x64_fn, U8G_COM_SSD_I2C);
|
||||
|
||||
uint8_t u8g_dev_sh1106_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_sh1106_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_sh1106_128x64_2x_buf};
|
||||
u8g_dev_t u8g_dev_sh1106_128x64_2x_sw_spi = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_sh1106_128x64_2x_hw_spi = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c = { u8g_dev_sh1106_128x64_2x_fn, &u8g_dev_sh1106_128x64_2x_pb, U8G_COM_SSD_I2C };
|
||||
|
||||
|
@ -1,144 +1,144 @@
|
||||
/*
|
||||
|
||||
u8g_dev_ssd1309_128x64.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2012, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 64
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
|
||||
/* ssd1309 ini sequence*/
|
||||
static const uint8_t u8g_dev_ssd1309_128x64_init_seq[] PROGMEM={
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
0xfd,0x12, /*Command Lock */
|
||||
0xae, /*Set Display Off */
|
||||
0xd5,0xa0, /*set Display Clock Divide Ratio/Oscillator Frequency */
|
||||
0xa8,0x3f, /*Set Multiplex Ratio */
|
||||
0x3d,0x00, /*Set Display Offset*/
|
||||
0x40, /*Set Display Start Line*/
|
||||
0xa1, /*Set Segment Re-Map*/
|
||||
0xc8, /*Set COM Output Scan Direction*/
|
||||
0xda,0x12, /*Set COM Pins Hardware Configuration*/
|
||||
0x81,0xdf, /*Set Current Control */
|
||||
0xd9,0x82, /*Set Pre-Charge Period */
|
||||
0xdb,0x34, /*Set VCOMH Deselect Level */
|
||||
0xa4, /*Set Entire Display On/Off */
|
||||
0xa6, /*Set Normal/Inverse Display*/
|
||||
U8G_ESC_VCC(1), /*Power up VCC & Stabilized */
|
||||
U8G_ESC_DLY(50),
|
||||
0xaf, /*Set Display On */
|
||||
U8G_ESC_DLY(50),
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
/* select one init sequence here */
|
||||
#define u8g_dev_ssd1309_128x64_init_seq u8g_dev_ssd1309_128x64_init_seq
|
||||
|
||||
|
||||
static const uint8_t u8g_dev_ssd1309_128x64_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 */
|
||||
0x000, /* set lower 4 bit of the col adr to 4 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1309_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1309_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1309_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SSD_I2C);
|
||||
|
||||
/*
|
||||
|
||||
u8g_dev_ssd1309_128x64.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2012, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 64
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
|
||||
/* ssd1309 ini sequence*/
|
||||
static const uint8_t u8g_dev_ssd1309_128x64_init_seq[] PROGMEM={
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
0xfd,0x12, /*Command Lock */
|
||||
0xae, /*Set Display Off */
|
||||
0xd5,0xa0, /*set Display Clock Divide Ratio/Oscillator Frequency */
|
||||
0xa8,0x3f, /*Set Multiplex Ratio */
|
||||
0x3d,0x00, /*Set Display Offset*/
|
||||
0x40, /*Set Display Start Line*/
|
||||
0xa1, /*Set Segment Re-Map*/
|
||||
0xc8, /*Set COM Output Scan Direction*/
|
||||
0xda,0x12, /*Set COM Pins Hardware Configuration*/
|
||||
0x81,0xdf, /*Set Current Control */
|
||||
0xd9,0x82, /*Set Pre-Charge Period */
|
||||
0xdb,0x34, /*Set VCOMH Deselect Level */
|
||||
0xa4, /*Set Entire Display On/Off */
|
||||
0xa6, /*Set Normal/Inverse Display*/
|
||||
U8G_ESC_VCC(1), /*Power up VCC & Stabilized */
|
||||
U8G_ESC_DLY(50),
|
||||
0xaf, /*Set Display On */
|
||||
U8G_ESC_DLY(50),
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
/* select one init sequence here */
|
||||
#define u8g_dev_ssd1309_128x64_init_seq u8g_dev_ssd1309_128x64_init_seq
|
||||
|
||||
|
||||
static const uint8_t u8g_dev_ssd1309_128x64_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 */
|
||||
0x000, /* set lower 4 bit of the col adr to 4 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1309_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1309_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1309_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SSD_I2C);
|
||||
|
||||
|
@ -199,7 +199,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -208,7 +208,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -218,7 +218,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_1bit_nhd_312_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -244,6 +244,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
u8g_WriteByte(u8g, dev, 0x0ff);
|
||||
u8g_WriteByte(u8g, dev, 0x0ff);
|
||||
#endif
|
||||
u8g_MicroDelay(); // for DUE?
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
p+=cnt;
|
||||
}
|
||||
@ -255,6 +256,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
|
||||
u8g_MicroDelay(); // for DUE?
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
@ -273,7 +275,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_1bit_nhd_312_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -299,6 +301,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
u8g_WriteByte(u8g, dev, 0x0ff);
|
||||
u8g_WriteByte(u8g, dev, 0x0ff);
|
||||
#endif
|
||||
u8g_MicroDelay(); // for DUE?
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
p+=cnt;
|
||||
}
|
||||
@ -307,7 +310,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, 0x0c1); /* 21 May 2013, fixed contrast command */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
@ -325,6 +328,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_bw_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_bw_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_bw_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_bw_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_bw_parallel , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_bw_fn, U8G_COM_FAST_PARALLEL);
|
||||
|
||||
#define DWIDTH (WIDTH*2)
|
||||
uint8_t u8g_dev_ssd1322_nhd31oled_2x_bw_buf[DWIDTH] U8G_NOCOMMON ;
|
||||
|
@ -50,7 +50,7 @@
|
||||
#define WIDTH 248
|
||||
#endif
|
||||
#define HEIGHT 64
|
||||
#define PAGE_HEIGHT 8
|
||||
//#define PAGE_HEIGHT 8
|
||||
|
||||
/*
|
||||
http://www.newhavendisplay.com/app_notes/OLED_25664.txt
|
||||
@ -199,7 +199,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -208,7 +208,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -217,7 +217,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_2bit_nhd_312_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -243,6 +243,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
u8g_WriteByte(u8g, dev, 0x00);
|
||||
u8g_WriteByte(u8g, dev, 0x00);
|
||||
#endif
|
||||
u8g_MicroDelay(); // for DUE?
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
p+=cnt;
|
||||
}
|
||||
@ -254,6 +255,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 1);
|
||||
u8g_MicroDelay(); // for DUE?
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
break;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
@ -272,7 +274,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1322_2bit_nhd_312_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -284,7 +286,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
uint8_t *p = pb->buf;
|
||||
u8g_uint_t cnt;
|
||||
cnt = pb->width;
|
||||
cnt >>= 3;
|
||||
cnt >>= 2; /* 23 Oct 2013, changed to 2 */
|
||||
|
||||
for( i = 0; i < pb->p.page_height; i++ )
|
||||
{
|
||||
@ -298,6 +300,7 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
u8g_WriteByte(u8g, dev, 0x00);
|
||||
u8g_WriteByte(u8g, dev, 0x00);
|
||||
#endif
|
||||
u8g_MicroDelay(); // for DUE?
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
p+=cnt;
|
||||
}
|
||||
@ -322,12 +325,14 @@ uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
}
|
||||
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_sw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_hw_spi , WIDTH, HEIGHT, 4, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1322_nhd31oled_gr_parallel , WIDTH, HEIGHT, 4, u8g_dev_ssd1322_nhd31oled_gr_fn, U8G_COM_FAST_PARALLEL);
|
||||
|
||||
|
||||
#define DWIDTH (WIDTH*2)
|
||||
uint8_t u8g_dev_ssd1322_nhd31oled_2x_gr_buf[DWIDTH] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_ssd1322_nhd31oled_2x_gr_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1322_nhd31oled_2x_gr_buf};
|
||||
u8g_pb_t u8g_dev_ssd1322_nhd31oled_2x_gr_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1322_nhd31oled_2x_gr_buf};
|
||||
u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_sw_spi = { u8g_dev_ssd1322_nhd31oled_2x_gr_fn, &u8g_dev_ssd1322_nhd31oled_2x_gr_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_hw_spi = { u8g_dev_ssd1322_nhd31oled_2x_gr_fn, &u8g_dev_ssd1322_nhd31oled_2x_gr_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
@ -191,7 +191,7 @@ uint8_t u8g_dev_ssd1325_nhd27oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -219,7 +219,7 @@ uint8_t u8g_dev_ssd1325_nhd27oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t m
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_1bit_nhd_27_12864ucy3_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -112,7 +112,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -121,7 +121,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -133,7 +133,7 @@ static uint8_t u8g_dev_ssd1325_nhd27oled_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8
|
||||
//case U8G_DEV_MSG_IS_BBX_INTERSECTION:
|
||||
// return u8g_pb_IsIntersection((u8g_pb_t *)(dev->dev_mem), (u8g_dev_arg_bbx_t *)arg);
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_nhd_27_12864_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -178,7 +178,7 @@ static uint8_t u8g_dev_ssd1325_nhd27oled_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, ui
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_nhd_27_12864_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -190,7 +190,7 @@ static uint8_t u8g_dev_ssd1325_nhd27oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -218,7 +218,7 @@ static uint8_t u8g_dev_ssd1325_nhd27oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, ui
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -111,7 +111,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ae, /* display off */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -120,7 +120,7 @@ static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -131,7 +131,7 @@ static uint8_t u8g_dev_ssd1325_nhd27oled_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -178,7 +178,7 @@ static uint8_t u8g_dev_ssd1325_nhd27oled_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, ui
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1325_2bit_nhd_27_12864ucy3_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -233,7 +233,7 @@ uint8_t u8g_dev_ssd1327_96x96_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1327_2bit_96x96_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -261,7 +261,7 @@ uint8_t u8g_dev_ssd1327_96x96_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg,
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1327_2bit_96x96_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -0,0 +1,787 @@
|
||||
/*
|
||||
|
||||
u8g_dev_ssd1351_128x128.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, jamjardavies@gmail.com
|
||||
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.
|
||||
|
||||
History:
|
||||
Initial version 20 May 2013 jamjardavies@gmail.com
|
||||
indexed device 22 May 2013 olikraus@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 128
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
static const uint8_t u8g_dev_ssd1351_128x128_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_DLY(50),
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
U8G_ESC_DLY(50),
|
||||
|
||||
0xfd, /* Command Lock */
|
||||
U8G_ESC_ADR(1),
|
||||
0x12,
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xfd,
|
||||
U8G_ESC_ADR(1),
|
||||
0xb1, /* Command Lock */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xae, /* Set Display Off */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb3,
|
||||
U8G_ESC_ADR(1),
|
||||
0xf1, /* Front Clock Div */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xca,
|
||||
U8G_ESC_ADR(1),
|
||||
0x7f, /* Set Multiplex Ratio */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa0,
|
||||
U8G_ESC_ADR(1),
|
||||
0xb4, /* Set Colour Depth */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x15,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, 0x7f, /* Set Column Address */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x75,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, 0x7f, /* Set Row Address */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa1,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, /* Set Display Start Line */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa2,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, /* Set Display Offset */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb5,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, /* Set GPIO */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xab,
|
||||
U8G_ESC_ADR(1),
|
||||
0x01, /* Set Function Selection */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb1,
|
||||
U8G_ESC_ADR(1),
|
||||
0x32, /* Set Phase Length */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb4,
|
||||
U8G_ESC_ADR(1),
|
||||
0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xbb,
|
||||
U8G_ESC_ADR(1),
|
||||
0x17, /* Set Precharge Voltage */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xbe,
|
||||
U8G_ESC_ADR(1),
|
||||
0x05, /* Set VComH Voltage */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xc1,
|
||||
U8G_ESC_ADR(1),
|
||||
0xc8, 0x80, 0xc8, /* Set Contrast */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xc7,
|
||||
U8G_ESC_ADR(1),
|
||||
0x0f, /* Set Master Contrast */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb6,
|
||||
U8G_ESC_ADR(1),
|
||||
0x01, /* Set Second Precharge Period */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa6, /* Set Display Mode Reset */
|
||||
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb8, /* Set CMD Grayscale Lookup */
|
||||
U8G_ESC_ADR(1),
|
||||
0x05,
|
||||
0x06,
|
||||
0x07,
|
||||
0x08,
|
||||
0x09,
|
||||
0x0a,
|
||||
0x0b,
|
||||
0x0c,
|
||||
0x0D,
|
||||
0x0E,
|
||||
0x0F,
|
||||
0x10,
|
||||
0x11,
|
||||
0x12,
|
||||
0x13,
|
||||
0x14,
|
||||
0x15,
|
||||
0x16,
|
||||
0x18,
|
||||
0x1a,
|
||||
0x1b,
|
||||
0x1C,
|
||||
0x1D,
|
||||
0x1F,
|
||||
0x21,
|
||||
0x23,
|
||||
0x25,
|
||||
0x27,
|
||||
0x2A,
|
||||
0x2D,
|
||||
0x30,
|
||||
0x33,
|
||||
0x36,
|
||||
0x39,
|
||||
0x3C,
|
||||
0x3F,
|
||||
0x42,
|
||||
0x45,
|
||||
0x48,
|
||||
0x4C,
|
||||
0x50,
|
||||
0x54,
|
||||
0x58,
|
||||
0x5C,
|
||||
0x60,
|
||||
0x64,
|
||||
0x68,
|
||||
0x6C,
|
||||
0x70,
|
||||
0x74,
|
||||
0x78,
|
||||
0x7D,
|
||||
0x82,
|
||||
0x87,
|
||||
0x8C,
|
||||
0x91,
|
||||
0x96,
|
||||
0x9B,
|
||||
0xA0,
|
||||
0xA5,
|
||||
0xAA,
|
||||
0xAF,
|
||||
0xB4,
|
||||
|
||||
U8G_ESC_ADR(0),
|
||||
0xaf, /* Set Display On */
|
||||
0x5c,
|
||||
U8G_ESC_DLY(50),
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(1),
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
/* set gpio to high */
|
||||
static const uint8_t u8g_dev_ssd1351_128x128gh_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_DLY(50),
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
U8G_ESC_DLY(50),
|
||||
|
||||
0xfd, /* Command Lock */
|
||||
U8G_ESC_ADR(1),
|
||||
0x12,
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xfd,
|
||||
U8G_ESC_ADR(1),
|
||||
0xb1, /* Command Lock */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xae, /* Set Display Off */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb3,
|
||||
U8G_ESC_ADR(1),
|
||||
0xf1, /* Front Clock Div */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xca,
|
||||
U8G_ESC_ADR(1),
|
||||
0x7f, /* Set Multiplex Ratio */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa0,
|
||||
U8G_ESC_ADR(1),
|
||||
0xb4, /* Set Colour Depth */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x15,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, 0x7f, /* Set Column Address */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0x75,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, 0x7f, /* Set Row Address */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa1,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, /* Set Display Start Line */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa2,
|
||||
U8G_ESC_ADR(1),
|
||||
0x00, /* Set Display Offset */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb5,
|
||||
U8G_ESC_ADR(1),
|
||||
0x03, /* Set GPIO to High Level */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xab,
|
||||
U8G_ESC_ADR(1),
|
||||
0x01, /* Set Function Selection */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb1,
|
||||
U8G_ESC_ADR(1),
|
||||
0x32, /* Set Phase Length */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb4,
|
||||
U8G_ESC_ADR(1),
|
||||
0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xbb,
|
||||
U8G_ESC_ADR(1),
|
||||
0x17, /* Set Precharge Voltage */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xbe,
|
||||
U8G_ESC_ADR(1),
|
||||
0x05, /* Set VComH Voltage */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xc1,
|
||||
U8G_ESC_ADR(1),
|
||||
0xc8, 0x80, 0xc8, /* Set Contrast */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xc7,
|
||||
U8G_ESC_ADR(1),
|
||||
0x0f, /* Set Master Contrast */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb6,
|
||||
U8G_ESC_ADR(1),
|
||||
0x01, /* Set Second Precharge Period */
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xa6, /* Set Display Mode Reset */
|
||||
|
||||
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
0xb8, /* Set CMD Grayscale Lookup */
|
||||
U8G_ESC_ADR(1),
|
||||
0x05,
|
||||
0x06,
|
||||
0x07,
|
||||
0x08,
|
||||
0x09,
|
||||
0x0a,
|
||||
0x0b,
|
||||
0x0c,
|
||||
0x0D,
|
||||
0x0E,
|
||||
0x0F,
|
||||
0x10,
|
||||
0x11,
|
||||
0x12,
|
||||
0x13,
|
||||
0x14,
|
||||
0x15,
|
||||
0x16,
|
||||
0x18,
|
||||
0x1a,
|
||||
0x1b,
|
||||
0x1C,
|
||||
0x1D,
|
||||
0x1F,
|
||||
0x21,
|
||||
0x23,
|
||||
0x25,
|
||||
0x27,
|
||||
0x2A,
|
||||
0x2D,
|
||||
0x30,
|
||||
0x33,
|
||||
0x36,
|
||||
0x39,
|
||||
0x3C,
|
||||
0x3F,
|
||||
0x42,
|
||||
0x45,
|
||||
0x48,
|
||||
0x4C,
|
||||
0x50,
|
||||
0x54,
|
||||
0x58,
|
||||
0x5C,
|
||||
0x60,
|
||||
0x64,
|
||||
0x68,
|
||||
0x6C,
|
||||
0x70,
|
||||
0x74,
|
||||
0x78,
|
||||
0x7D,
|
||||
0x82,
|
||||
0x87,
|
||||
0x8C,
|
||||
0x91,
|
||||
0x96,
|
||||
0x9B,
|
||||
0xA0,
|
||||
0xA5,
|
||||
0xAA,
|
||||
0xAF,
|
||||
0xB4,
|
||||
|
||||
U8G_ESC_ADR(0),
|
||||
0xaf, /* Set Display On */
|
||||
0x5c,
|
||||
U8G_ESC_DLY(50),
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(1),
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
#define u8g_dev_ssd1351_128x128_init_seq u8g_dev_ssd1351_128x128_init_seq
|
||||
|
||||
static const uint8_t u8g_dev_ssd1351_128x128_column_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(1),
|
||||
U8G_ESC_ADR(0), 0x15,
|
||||
U8G_ESC_ADR(1), 0x00, 0x7f,
|
||||
U8G_ESC_ADR(0), 0x75,
|
||||
U8G_ESC_ADR(1), 0x00, 0x7f,
|
||||
U8G_ESC_ADR(0), 0x5c,
|
||||
U8G_ESC_ADR(1),
|
||||
U8G_ESC_CS(0),
|
||||
U8G_ESC_END
|
||||
};
|
||||
|
||||
#define RGB332_STREAM_BYTES 8
|
||||
static uint8_t u8g_ssd1351_stream_bytes[RGB332_STREAM_BYTES*3];
|
||||
|
||||
void u8g_ssd1351_to_stream(uint8_t *ptr)
|
||||
{
|
||||
uint8_t cnt = RGB332_STREAM_BYTES;
|
||||
uint8_t val;
|
||||
uint8_t *dest = u8g_ssd1351_stream_bytes;
|
||||
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
|
||||
{
|
||||
val = *ptr++;
|
||||
*dest++ = ((val & 0xe0) >> 2);
|
||||
*dest++ = ((val & 0x1c) << 1);
|
||||
*dest++ = ((val & 0x03) << 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef OBSOLETE
|
||||
// Convert the internal RGB 332 to R
|
||||
static uint8_t u8g_ssd1351_get_r(uint8_t colour)
|
||||
{
|
||||
//return ((colour & 0xe0) >> 5) * 9;
|
||||
//return ((colour & 0xe0) >> 5) * 8;
|
||||
return ((colour & 0xe0) >> 2) ;
|
||||
}
|
||||
|
||||
// Convert the internal RGB 332 to G
|
||||
static uint8_t u8g_ssd1351_get_g(uint8_t colour)
|
||||
{
|
||||
//return ((colour & 0x1c) >> 2) * 9;
|
||||
//return ((colour & 0x1c) >> 2) * 8;
|
||||
return ((colour & 0x1c) << 1);
|
||||
}
|
||||
|
||||
// Convert the internal RGB 332 to B
|
||||
static uint8_t u8g_ssd1351_get_b(uint8_t colour)
|
||||
{
|
||||
//return (colour & 0x03) * 21;
|
||||
return (colour & 0x03) * 16;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_uint_t x;
|
||||
uint8_t page_height;
|
||||
uint8_t i;
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
uint8_t *ptr = pb->buf;
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
|
||||
page_height = pb->p.page_y1;
|
||||
page_height -= pb->p.page_y0;
|
||||
page_height++;
|
||||
for( i = 0; i < page_height; i++ )
|
||||
{
|
||||
|
||||
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
|
||||
{
|
||||
u8g_ssd1351_to_stream(ptr);
|
||||
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||
ptr += RGB332_STREAM_BYTES;
|
||||
}
|
||||
}
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_R3G3B2;
|
||||
}
|
||||
|
||||
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128gh_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_uint_t x;
|
||||
uint8_t page_height;
|
||||
uint8_t i;
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
uint8_t *ptr = pb->buf;
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
|
||||
page_height = pb->p.page_y1;
|
||||
page_height -= pb->p.page_y0;
|
||||
page_height++;
|
||||
for( i = 0; i < page_height; i++ )
|
||||
{
|
||||
|
||||
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
|
||||
{
|
||||
u8g_ssd1351_to_stream(ptr);
|
||||
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||
ptr += RGB332_STREAM_BYTES;
|
||||
}
|
||||
}
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_R3G3B2;
|
||||
}
|
||||
|
||||
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
static uint8_t u8g_dev_ssd1351_128x128_r[256];
|
||||
static uint8_t u8g_dev_ssd1351_128x128_g[256];
|
||||
static uint8_t u8g_dev_ssd1351_128x128_b[256];
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128_idx_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
u8g_dev_ssd1351_128x128_r[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->r;
|
||||
u8g_dev_ssd1351_128x128_g[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->g;
|
||||
u8g_dev_ssd1351_128x128_b[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->b;
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
int x;
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
uint8_t *ptr = pb->buf;
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
|
||||
for (x = 0; x < pb->width; x++)
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_r[(*ptr)>>2]);
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_g[(*ptr)>>2]);
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_b[(*ptr)>>2]);
|
||||
|
||||
ptr++;
|
||||
}
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_INDEX;
|
||||
}
|
||||
|
||||
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
void u8g_ssd1351_hicolor_to_stream(uint8_t *ptr)
|
||||
{
|
||||
register uint8_t cnt = RGB332_STREAM_BYTES;
|
||||
register uint8_t low, high, r, g, b;
|
||||
uint8_t *dest = u8g_ssd1351_stream_bytes;
|
||||
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
|
||||
{
|
||||
low = *ptr++;
|
||||
high = *ptr++;
|
||||
|
||||
r = high & ~7;
|
||||
r >>= 2;
|
||||
b = low & 31;
|
||||
b <<= 1;
|
||||
g = high & 7;
|
||||
g <<= 3;
|
||||
g |= (low>>5)&7;
|
||||
|
||||
*dest++ = r;
|
||||
*dest++ = g;
|
||||
*dest++ = b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
uint8_t i, j;
|
||||
uint8_t page_height;
|
||||
uint8_t *ptr = pb->buf;
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
|
||||
page_height = pb->p.page_y1;
|
||||
page_height -= pb->p.page_y0;
|
||||
page_height++;
|
||||
for( j = 0; j < page_height; j++ )
|
||||
{
|
||||
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
|
||||
{
|
||||
u8g_ssd1351_hicolor_to_stream(ptr);
|
||||
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||
ptr += RGB332_STREAM_BYTES*2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
}
|
||||
break; /* continue to base fn */
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_HICOLOR;
|
||||
}
|
||||
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128gh_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
uint8_t i, j;
|
||||
uint8_t page_height;
|
||||
uint8_t *ptr = pb->buf;
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
|
||||
page_height = pb->p.page_y1;
|
||||
page_height -= pb->p.page_y0;
|
||||
page_height++;
|
||||
for( j = 0; j < page_height; j++ )
|
||||
{
|
||||
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
|
||||
{
|
||||
u8g_ssd1351_hicolor_to_stream(ptr);
|
||||
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||
ptr += RGB332_STREAM_BYTES*2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
}
|
||||
break; /* continue to base fn */
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_HICOLOR;
|
||||
}
|
||||
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128_byte_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||
|
||||
u8g_pb_t u8g_dev_ssd1351_128x128_byte_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
|
||||
|
||||
//u8g_dev_t u8g_dev_ssd1351_128x128_idx_sw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
|
||||
//u8g_dev_t u8g_dev_ssd1351_128x128_idx_hw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
||||
/* only half of the height, because two bytes are needed for one pixel */
|
||||
u8g_pb_t u8g_dev_ssd1351_128x128_hicolor_byte_pb = { {PAGE_HEIGHT/2, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
||||
uint8_t u8g_dev_ssd1351_128x128_4x_byte_buf[WIDTH*PAGE_HEIGHT*4] U8G_NOCOMMON ;
|
||||
|
||||
u8g_pb_t u8g_dev_ssd1351_128x128_4x_332_byte_pb = { {PAGE_HEIGHT*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
|
||||
|
||||
u8g_pb_t u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb = { {PAGE_HEIGHT/2*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
||||
/*
|
||||
U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_HW_SPI);
|
||||
|
||||
U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_HW_SPI);
|
||||
*/
|
||||
|
@ -96,7 +96,7 @@ static const uint8_t u8g_dev_st7565_64128n_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -106,7 +106,7 @@ static const uint8_t u8g_dev_st7565_64128n_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -115,7 +115,7 @@ uint8_t u8g_dev_st7565_64128n_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -148,6 +148,56 @@ uint8_t u8g_dev_st7565_64128n_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_st7565_64128n_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_st7565_64128n_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_64128n_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_64128n_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_PARALLEL);
|
||||
|
||||
uint8_t u8g_dev_st7565_64128n_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_st7565_64128n_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_64128n_2x_buf};
|
||||
u8g_dev_t u8g_dev_st7565_64128n_2x_sw_spi = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_64128n_2x_hw_spi = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_64128n_2x_hw_parallel = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_PARALLEL };
|
||||
|
@ -82,7 +82,7 @@ static const uint8_t u8g_dev_st7565_dogm128_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -92,7 +92,7 @@ static const uint8_t u8g_dev_st7565_dogm128_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -101,7 +101,7 @@ uint8_t u8g_dev_st7565_dogm128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -134,7 +134,57 @@ uint8_t u8g_dev_st7565_dogm128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_st7565_dogm128_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm128_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_st7565_dogm128_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm128_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_dogm128_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm128_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_dogm128_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_dogm128_fn, U8G_COM_PARALLEL);
|
||||
|
||||
|
||||
uint8_t u8g_dev_st7565_dogm128_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_st7565_dogm128_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_dogm128_2x_buf};
|
||||
u8g_dev_t u8g_dev_st7565_dogm128_2x_sw_spi = { u8g_dev_st7565_dogm128_2x_fn, &u8g_dev_st7565_dogm128_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_dogm128_2x_hw_spi = { u8g_dev_st7565_dogm128_2x_fn, &u8g_dev_st7565_dogm128_2x_pb, U8G_COM_HW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_dogm128_2x_parallel = { u8g_dev_st7565_dogm128_2x_fn, &u8g_dev_st7565_dogm128_2x_pb, U8G_COM_PARALLEL };
|
||||
|
@ -101,7 +101,7 @@ static const uint8_t u8g_dev_st7565_dogm132_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -111,7 +111,7 @@ static const uint8_t u8g_dev_st7565_dogm132_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -120,7 +120,7 @@ uint8_t u8g_dev_st7565_dogm132_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_dogm132_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -98,7 +98,7 @@ static const uint8_t u8g_dev_st7565_lm6059_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -108,7 +108,7 @@ static const uint8_t u8g_dev_st7565_lm6059_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -118,7 +118,7 @@ uint8_t u8g_dev_st7565_lm6059_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -151,7 +151,55 @@ uint8_t u8g_dev_st7565_lm6059_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_st7565_lm6059_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6059_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_st7565_lm6059_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6059_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_lm6059_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6059_fn, U8G_COM_HW_SPI);
|
||||
|
||||
|
||||
uint8_t u8g_dev_st7565_lm6059_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_st7565_lm6059_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_lm6059_2x_buf};
|
||||
u8g_dev_t u8g_dev_st7565_lm6059_2x_sw_spi = { u8g_dev_st7565_lm6059_2x_fn, &u8g_dev_st7565_lm6059_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_lm6059_2x_hw_spi = { u8g_dev_st7565_lm6059_2x_fn, &u8g_dev_st7565_lm6059_2x_pb, U8G_COM_HW_SPI };
|
||||
|
@ -129,7 +129,7 @@ static const uint8_t u8g_dev_st7565_st7565_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -139,7 +139,7 @@ static const uint8_t u8g_dev_st7565_st7565_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -149,7 +149,7 @@ uint8_t u8g_dev_st7565_lm6063_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -182,7 +182,55 @@ uint8_t u8g_dev_st7565_lm6063_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_st7565_lm6063_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_lm6063_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_st7565_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_st7565_lm6063_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6063_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_lm6063_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_lm6063_fn, U8G_COM_HW_SPI);
|
||||
|
||||
uint8_t u8g_dev_st7565_lm6063_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_st7565_lm6063_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_lm6063_2x_buf};
|
||||
u8g_dev_t u8g_dev_st7565_lm6063_2x_sw_spi = { u8g_dev_st7565_lm6063_2x_fn, &u8g_dev_st7565_lm6063_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_lm6063_2x_hw_spi = { u8g_dev_st7565_lm6063_2x_fn, &u8g_dev_st7565_lm6063_2x_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
@ -86,7 +86,7 @@ static const uint8_t u8g_dev_st7565_c12832_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -96,7 +96,7 @@ static const uint8_t u8g_dev_st7565_c12832_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -105,7 +105,7 @@ uint8_t u8g_dev_st7565_c12832_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12832_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -141,3 +141,5 @@ uint8_t u8g_dev_st7565_c12832_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_PARALLEL);
|
||||
U8G_PB_DEV(u8g_dev_st7565_nhd_c12832_hw_usart_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_c12832_fn, U8G_COM_HW_USART_SPI);
|
||||
|
||||
|
@ -87,7 +87,7 @@ static const uint8_t u8g_dev_st7565_c12864_sleep_on[] PROGMEM = {
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -97,7 +97,7 @@ static const uint8_t u8g_dev_st7565_c12864_sleep_off[] PROGMEM = {
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_CS(0), /* disable chip, bugfix 12 nov 2014 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
@ -106,7 +106,7 @@ uint8_t u8g_dev_st7565_nhd_c12864_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -139,7 +139,56 @@ uint8_t u8g_dev_st7565_nhd_c12864_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_st7565_nhd_c12864_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_nhd_c12864_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_c12864_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_st7565_nhd_c12864_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_nhd_c12864_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7565_nhd_c12864_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_nhd_c12864_fn, U8G_COM_HW_SPI);
|
||||
|
||||
|
||||
uint8_t u8g_dev_st7565_nhd_c12864_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_st7565_nhd_c12864_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_nhd_c12864_2x_buf};
|
||||
u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_sw_spi = { u8g_dev_st7565_nhd_c12864_2x_fn, &u8g_dev_st7565_nhd_c12864_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_hw_spi = { u8g_dev_st7565_nhd_c12864_2x_fn, &u8g_dev_st7565_nhd_c12864_2x_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
@ -363,7 +363,7 @@ uint8_t u8g_dev_st7687_c144mvgd_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7687_c144mvgd_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
u8g_dev_st7565_128x64.c
|
||||
u8g_dev_st7920_128x64.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
@ -66,7 +66,7 @@ uint8_t u8g_dev_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -114,7 +114,7 @@ uint8_t u8g_dev_st7920_128x64_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -160,6 +160,9 @@ uint8_t u8g_dev_st7920_128x64_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
U8G_PB_DEV(u8g_dev_st7920_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_ST7920_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7920_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_ST7920_HW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_st7920_128x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, U8G_COM_FAST_PARALLEL);
|
||||
U8G_PB_DEV(u8g_dev_st7920_128x64_custom, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7920_128x64_fn, u8g_com_arduino_st7920_custom_fn);
|
||||
|
||||
|
||||
|
||||
#define QWIDTH (WIDTH*4)
|
||||
uint8_t u8g_dev_st7920_128x64_4x_buf[QWIDTH] U8G_NOCOMMON ;
|
||||
@ -167,5 +170,6 @@ u8g_pb_t u8g_dev_st7920_128x64_4x_pb = { {32, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_
|
||||
u8g_dev_t u8g_dev_st7920_128x64_4x_sw_spi = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_ST7920_SW_SPI };
|
||||
u8g_dev_t u8g_dev_st7920_128x64_4x_hw_spi = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_ST7920_HW_SPI };
|
||||
u8g_dev_t u8g_dev_st7920_128x64_4x_8bit = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, U8G_COM_FAST_PARALLEL };
|
||||
u8g_dev_t u8g_dev_st7920_128x64_4x_custom = { u8g_dev_st7920_128x64_4x_fn, &u8g_dev_st7920_128x64_4x_pb, u8g_com_arduino_st7920_custom_fn };
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ uint8_t u8g_dev_st7920_192x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_192x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -103,7 +103,7 @@ uint8_t u8g_dev_st7920_192x32_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_192x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -68,7 +68,7 @@ uint8_t u8g_dev_st7920_202x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_202x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -106,7 +106,7 @@ uint8_t u8g_dev_st7920_202x32_4x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7920_202x32_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -0,0 +1,193 @@
|
||||
/*
|
||||
|
||||
u8g_dev_t6963_128x128.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Application Notes for the MGLS 128x128
|
||||
www.baso.no/content/pdf/T6963C_Application.pdf
|
||||
|
||||
Hitachi App Notes:
|
||||
https://www.sparkfun.com/datasheets/LCD/Monochrome/AN-029-Toshiba_T6963C.pdf
|
||||
|
||||
Notes:
|
||||
The font selection pins should generate the 8x8 font.
|
||||
For the MGLS240128TZ only FS1 is available on pin 18.
|
||||
FS1 must be low to generate the 8x8 font.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 128
|
||||
#define PAGE_HEIGHT 16
|
||||
|
||||
|
||||
/*
|
||||
http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format
|
||||
*/
|
||||
|
||||
/* text is not used, so settings are not relevant */
|
||||
static const uint8_t u8g_dev_t6963_128x128_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
|
||||
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
0x000, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x021, /* set cursor position */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
0x000, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x022, /* set offset */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
0x000, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x040, /* text home */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
WIDTH/8, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x041, /* text columns */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
0x000, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x042, /* graphics home */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
WIDTH/8, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x043, /* graphics columns */
|
||||
|
||||
// mode set
|
||||
// 0x080: Internal CG, OR Mode
|
||||
// 0x081: Internal CG, EXOR Mode
|
||||
// 0x083: Internal CG, AND Mode
|
||||
// 0x088: External CG, OR Mode
|
||||
// 0x089: External CG, EXOR Mode
|
||||
// 0x08B: External CG, AND Mode
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x080, /* mode register: OR Mode, Internal Character Mode */
|
||||
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
// display mode
|
||||
// 0x090: Display off
|
||||
// 0x094: Graphic off, text on, cursor off, blink off
|
||||
// 0x096: Graphic off, text on, cursor on, blink off
|
||||
// 0x097: Graphic off, text on, cursor on, blink on
|
||||
// 0x098: Graphic on, text off, cursor off, blink off
|
||||
// 0x09a: Graphic on, text off, cursor on, blink off
|
||||
// ...
|
||||
// 0x09c: Graphic on, text on, cursor off, blink off
|
||||
// 0x09f: Graphic on, text on, cursor on, blink on
|
||||
0x098, /* mode register: Display Mode, Graphics on, Text off, Cursor off */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
0x000, /* low byte */
|
||||
0x000, /* height byte */
|
||||
U8G_ESC_ADR(1), /* instruction mode */
|
||||
0x024, /* set adr pointer */
|
||||
|
||||
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
|
||||
U8G_ESC_ADR(0), /* data mode */
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_t6963_128x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_t6963_128x128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
uint8_t y, i;
|
||||
uint16_t disp_ram_adr;
|
||||
uint8_t *ptr;
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
|
||||
u8g_SetAddress(u8g, dev, 0); /* data mode */
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
y = pb->p.page_y0;
|
||||
ptr = pb->buf;
|
||||
disp_ram_adr = WIDTH/8;
|
||||
disp_ram_adr *= y;
|
||||
for( i = 0; i < PAGE_HEIGHT; i ++ )
|
||||
{
|
||||
u8g_SetAddress(u8g, dev, 0); /* data mode */
|
||||
u8g_WriteByte(u8g, dev, disp_ram_adr&255 ); /* address low byte */
|
||||
u8g_WriteByte(u8g, dev, disp_ram_adr>>8 ); /* address hight byte */
|
||||
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
|
||||
u8g_WriteByte(u8g, dev, 0x024 ); /* set adr ptr */
|
||||
|
||||
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
|
||||
|
||||
ptr += WIDTH/8;
|
||||
disp_ram_adr += WIDTH/8;
|
||||
}
|
||||
u8g_SetAddress(u8g, dev, 0); /* data mode */
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
// U8G_PB_DEV(u8g_dev_t6963_128x128_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_t6963_128x128_fn, U8G_COM_T6963);
|
||||
|
||||
uint8_t u8g_dev_t6963_128x128_2x_bw_buf[WIDTH/8*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_t6963_128x128_2x_bw_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_t6963_128x128_2x_bw_buf};
|
||||
u8g_dev_t u8g_dev_t6963_128x128_8bit = { u8g_dev_t6963_128x128_fn, &u8g_dev_t6963_128x128_2x_bw_pb, U8G_COM_T6963 };
|
||||
|
||||
|
@ -142,7 +142,7 @@ uint8_t u8g_dev_t6963_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *a
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_t6963_128x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -146,7 +146,7 @@ uint8_t u8g_dev_t6963_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_t6963_240x128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -146,7 +146,7 @@ uint8_t u8g_dev_t6963_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *a
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_t6963_240x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -78,7 +78,7 @@ uint8_t u8g_dev_tls8204_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_tls8204_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
|
@ -0,0 +1,201 @@
|
||||
/*
|
||||
|
||||
u8g_dev_uc1601_c128032.c
|
||||
|
||||
LCD-AG-C128032R-DIW W/KK E6 PBF from http://www.artronic.pl/o_produkcie.php?id=1343
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 32
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
/* init sequence */
|
||||
static const uint8_t u8g_dev_uc1601_c128032_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
|
||||
|
||||
0x0a3, /* 0x0a3: LCD bias 1/7 , 0x0a2: LCD bias 1/9 */
|
||||
0x0a0, /* 0x0a0: ADC set to normal, 0x0a1 ADC set to inverted */
|
||||
0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
|
||||
0x0c2, /* 22 May 2013: mirror x */
|
||||
|
||||
0x040, /* set display start line */
|
||||
|
||||
0x028 | 0x04, /* power control: turn on voltage converter */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
|
||||
0x028 | 0x06, /* power control: turn on voltage regulator */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
|
||||
0x028 | 0x07, /* power control: turn on voltage follower */
|
||||
U8G_ESC_DLY(10), /* delay 10 ms */
|
||||
|
||||
0x020| 0x06, /* set V0 voltage resistor ratio to 6 */
|
||||
|
||||
0x0af, /* display on */
|
||||
|
||||
//0x081, /* set contrast */
|
||||
//0x018, /* contrast value*/
|
||||
|
||||
0x0a6, /* display normal, bit val 0: LCD pixel off. */
|
||||
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
U8G_ESC_CS(0), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_uc1601_c128032_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 */
|
||||
0x004, /* set lower 4 bit of the col adr */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_uc1601_c128032_sleep_on[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0ac, /* static indicator off */
|
||||
0x000, /* indicator register set (not sure if this is required) */
|
||||
0x0ae, /* display off */
|
||||
0x0a5, /* all points on */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_uc1601_c128032_sleep_off[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x0a4, /* all points off */
|
||||
0x0af, /* display on */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
uint8_t u8g_dev_uc1601_c128032_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1601) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_uc1601_c128032_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (UC1601) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (UC1601) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_ON:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_on);
|
||||
return 1;
|
||||
case U8G_DEV_MSG_SLEEP_OFF:
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_off);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1601_c128032_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1601_c128032_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1601_c128032_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1601_c128032_fn, U8G_COM_HW_SPI);
|
||||
|
||||
uint8_t u8g_dev_uc1601_c128032_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_uc1601_c128032_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1601_c128032_2x_buf};
|
||||
u8g_dev_t u8g_dev_uc1601_c128032_2x_sw_spi = { u8g_dev_uc1601_c128032_2x_fn, &u8g_dev_uc1601_c128032_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_uc1601_c128032_2x_hw_spi = { u8g_dev_uc1601_c128032_2x_fn, &u8g_dev_uc1601_c128032_2x_pb, U8G_COM_HW_SPI };
|
||||
|
@ -0,0 +1,200 @@
|
||||
/*
|
||||
|
||||
|
||||
|
||||
u8g_dev_uc1608_240x128.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com (original 240x64 library)
|
||||
Modified by thieringpeti@gmail.com for Raystar rx240128 family displays
|
||||
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.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Display: http://www.tme.eu/en/details/rx240128a-ghw/lcd-graphic-displays/raystar-optronics/
|
||||
Connection: HW / SW SPI.
|
||||
To get this display working, You need some extra capacitors:
|
||||
|
||||
connect 4.7uF caps between:
|
||||
PIN1 & PIN2 VB1 +-
|
||||
PIN3 & PIN4 VB0 -+
|
||||
connect 0.1uF caps between:
|
||||
VLCD and VSS
|
||||
VBIAS and VSS
|
||||
You can find some schematics with a 10M resistor parallellized with the VLCD capacitor.
|
||||
|
||||
Select 4-bit SPI mode.
|
||||
|
||||
Connect D7 (PIN9) To VDD (+3.3V)
|
||||
Connect D1, D2, D4, D5, D6 to GND (PINS 10,11,12,14,15)
|
||||
Connect WR0, WR1, BM0, BM1 to GND (PINS 17,18,22,23)
|
||||
|
||||
D0: (PIN16) AVR's SCK pin (HW SPI)
|
||||
D3: (PIN13) AVR's MOSI pin (HW SPI)
|
||||
CD: (PIN19) used as A0 in the library
|
||||
CS: (PIN21) Connect to the defined CS pin, and You can re-use the HW SPI in different routines.
|
||||
RST: (PIN20) optional reset, can be defined in the function, resets on initialization.
|
||||
|
||||
Adjust contrast if necessary. Default: 0x072.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 240
|
||||
#define HEIGHT 128
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
/* see also ERC24064-1 for init sequence example */
|
||||
static const uint8_t u8g_dev_uc1608_240x128_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* disable chip (UC1608 has positive logic for CS) */
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (15*16)+2 milliseconds */
|
||||
|
||||
|
||||
U8G_ESC_CS(0), /* enable chip */
|
||||
0x0e2, /* soft reset */
|
||||
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
0x026, /* MUX rate and temperature compensation */
|
||||
|
||||
0x0c8, /* Map control, Bit 3: MY=1, Bit 2: MX=0, Bit 0: MSF =0 */
|
||||
|
||||
0x0eb, /* LCD bias Bits 0/1: 00=10.7 01=10.3, 10=12.0, 11=12.7*/
|
||||
/* default 0x0ea for 240x128 */
|
||||
0x081, /* set contrast (bits 0..5) and gain (bits 6/7) */
|
||||
0x072, /* default for 240x128 displays: 0x072*/
|
||||
|
||||
0x02f, /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
|
||||
0x040, /* set display start line to 0 */
|
||||
0x090, /* no fixed lines */
|
||||
0x089, /* RAM access control */
|
||||
|
||||
0x0af, /* disable sleep mode */
|
||||
0x0a4, /* normal display */
|
||||
0x0a5, /* display all points, ST7565, UC1610 */
|
||||
// 0x0a7, /* inverse display */
|
||||
0x0a6, /* normal display */
|
||||
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
0x0a4, /* normal display */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_uc1608_240x128_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(0), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 (UC1608) */
|
||||
0x000, /* set lower 4 bit of the col adr to 0 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_uc1608_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1608) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_uc1608_240x128_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1608_240x128_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x128_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1608_240x128_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x128_fn, U8G_COM_HW_SPI);
|
||||
|
||||
uint8_t u8g_dev_uc1608_240x128_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_uc1608_240x128_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1608_240x128_2x_buf};
|
||||
u8g_dev_t u8g_dev_uc1608_240x128_2x_sw_spi = { u8g_dev_uc1608_240x128_2x_fn, &u8g_dev_uc1608_240x128_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_uc1608_240x128_2x_hw_spi = { u8g_dev_uc1608_240x128_2x_fn, &u8g_dev_uc1608_240x128_2x_pb, U8G_COM_HW_SPI };
|
||||
|
@ -0,0 +1,168 @@
|
||||
/*
|
||||
|
||||
u8g_dev_uc1608_240x64.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
#define WIDTH 240
|
||||
#define HEIGHT 64
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
/* see also ERC24064-1 for init sequence example */
|
||||
static const uint8_t u8g_dev_uc1608_240x64_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(1), /* disable chip (UC1608 has positive logic for CS) */
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (15*16)+2 milliseconds */
|
||||
|
||||
|
||||
U8G_ESC_CS(0), /* enable chip */
|
||||
0x0e2, /* soft reset */
|
||||
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
#if HEIGHT <= 96
|
||||
0x023, /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
|
||||
#else
|
||||
/* 30 Nov 2013: not tested */
|
||||
0x027, /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
|
||||
#endif
|
||||
0x0c8, /* Map control, Bit 3: MY=1, Bit 2: MX=0, Bit 0: MSF =0 */
|
||||
0x0e8, /* LCD bias Bits 0/1: 00=10.7 01=10.3, 10=12.0, 11=12.7*/
|
||||
|
||||
0x081, /* set contrast (bits 0..5) and gain (bits 6/7) */
|
||||
0x014, /* ECR24064-1 default: 0x040*/
|
||||
|
||||
0x02f, /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
|
||||
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||
|
||||
0x040, /* set display start line to 0 */
|
||||
0x090, /* no fixed lines */
|
||||
0x089, /* RAM access control */
|
||||
|
||||
0x0af, /* disable sleep mode */
|
||||
0x0a4, /* normal display */
|
||||
0x0a5, /* display all points, ST7565, UC1610 */
|
||||
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||
0x0a4, /* normal display */
|
||||
U8G_ESC_CS(1), /* disable chip */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8g_dev_uc1608_240x64_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(0), /* enable chip */
|
||||
0x010, /* set upper 4 bit of the col adr to 0 (UC1608) */
|
||||
0x000, /* set lower 4 bit of the col adr to 0 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_uc1608_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1608) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_uc1608_240x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1608_240x64_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x64_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1608_240x64_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x64_fn, U8G_COM_HW_SPI);
|
||||
|
||||
uint8_t u8g_dev_uc1608_240x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_uc1608_240x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1608_240x64_2x_buf};
|
||||
u8g_dev_t u8g_dev_uc1608_240x64_2x_sw_spi = { u8g_dev_uc1608_240x64_2x_fn, &u8g_dev_uc1608_240x64_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_uc1608_240x64_2x_hw_spi = { u8g_dev_uc1608_240x64_2x_fn, &u8g_dev_uc1608_240x64_2x_pb, U8G_COM_HW_SPI };
|
||||
|
@ -101,7 +101,7 @@ uint8_t u8g_dev_uc1610_dogxl160_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, v
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1610_dogxl160_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -145,7 +145,7 @@ uint8_t u8g_dev_uc1610_dogxl160_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, v
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1610_dogxl160_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -177,7 +177,7 @@ uint8_t u8g_dev_uc1610_dogxl160_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1610_dogxl160_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -208,7 +208,7 @@ uint8_t u8g_dev_uc1610_dogxl160_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
for( i = 0; i < WIDTH; i++ )
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_1to2( ((uint8_t *)(pb->buf+WIDTH))[i] ) );
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_1to2( ((uint8_t *)((uint8_t *)(pb->buf)+WIDTH))[i] ) );
|
||||
}
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1610_dogxl160_data_start);
|
||||
@ -216,7 +216,7 @@ uint8_t u8g_dev_uc1610_dogxl160_2x_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
for( i = 0; i < WIDTH; i++ )
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_1to2( ((uint8_t *)(pb->buf+WIDTH))[i] >> 4 ) );
|
||||
u8g_WriteByte(u8g, dev, u8g_dev_1to2( ((uint8_t *)((uint8_t *)(pb->buf)+WIDTH))[i] >> 4 ) );
|
||||
}
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
@ -238,7 +238,7 @@ uint8_t u8g_dev_uc1610_dogxl160_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1610_dogxl160_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -256,7 +256,7 @@ uint8_t u8g_dev_uc1610_dogxl160_2x_gr_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1610_dogxl160_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x060 | (pb->p.page*2+1) ); /* select current page (UC1610) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_WriteSequence(u8g, dev, WIDTH, pb->buf+WIDTH) == 0 )
|
||||
if ( u8g_WriteSequence(u8g, dev, WIDTH, (uint8_t *)(pb->buf)+WIDTH) == 0 )
|
||||
return 0;
|
||||
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
|
||||
u8g_dev_uc1611_dogm240.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2014, dev.menges.jonas@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
|
||||
#define WIDTH 240
|
||||
#define HEIGHT 64
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
|
||||
static const uint8_t u8g_dev_uc1611_dogm240_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(1), // enable chip
|
||||
U8G_ESC_ADR(0), // instruction mode
|
||||
0xF1, // set last COM electrode
|
||||
0x3F, // 64-1=63
|
||||
0xF2, // set display start line
|
||||
0x00, // 0
|
||||
0xF3, // set display end line
|
||||
0x3F, // 64-1=63
|
||||
0x81, // set contrast (0-255)
|
||||
0xB7, // 183
|
||||
0xC0, // set view
|
||||
//0x04, // topview
|
||||
0x02, // bottomview
|
||||
0xA3, // set line rate (9.4k)
|
||||
0xE9, // set bias ratio (10)
|
||||
0xA9, // enable display
|
||||
0xD1, // set black and white mode
|
||||
U8G_ESC_CS(0), // disable chip
|
||||
U8G_ESC_END // end of sequence
|
||||
};
|
||||
|
||||
static void setPage(u8g_t *u8g, u8g_dev_t *dev, unsigned char page)
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, 0x70);
|
||||
u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F));
|
||||
}
|
||||
|
||||
static const uint8_t u8g_dev_uc1611_dogm240_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x10, /* set upper 4 bit of the col adr to 0 */
|
||||
0x00, /* set lower 4 bit of the col adr to 0 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
uint8_t u8g_dev_uc1611_dogm240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_data_start);
|
||||
setPage(u8g, dev, pb->p.page); /* select current page (uc1611) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x81);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1611_dogm240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_UC_I2C);
|
||||
U8G_PB_DEV(u8g_dev_uc1611_dogm240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1611_dogm240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_HW_SPI);
|
||||
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
|
||||
u8g_dev_uc1611_dogxl240.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2014, dev.menges.jonas@gmail.com, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
|
||||
#define WIDTH 240
|
||||
#define HEIGHT 128
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
|
||||
static const uint8_t u8g_dev_uc1611_dogxl240_init_seq[] PROGMEM = {
|
||||
U8G_ESC_CS(1), // enable chip
|
||||
U8G_ESC_ADR(0), // instruction mode
|
||||
0xF1, // set last COM electrode
|
||||
0x7F, // DOGXL240
|
||||
0xF2, // set display start line
|
||||
0x00, // 0
|
||||
0xF3, // set display end line
|
||||
0x7F, // DOGXL240
|
||||
0x81, // set contrast (0-255)
|
||||
0xAA, // DOGXL240
|
||||
0xC0, // set view
|
||||
//0x04, // topview
|
||||
0x02, // bottomview
|
||||
0xA3, // set line rate (9.4k)
|
||||
0xE9, // set bias ratio (10)
|
||||
0xA9, // enable display
|
||||
0xD1, // set black and white mode
|
||||
U8G_ESC_CS(0), // disable chip
|
||||
U8G_ESC_END // end of sequence
|
||||
};
|
||||
|
||||
static void u8g_dev_dogxl240_set_page(u8g_t *u8g, u8g_dev_t *dev, unsigned char page)
|
||||
{
|
||||
u8g_WriteByte(u8g, dev, 0x70);
|
||||
u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F));
|
||||
}
|
||||
|
||||
static const uint8_t u8g_dev_uc1611_dogxl240_data_start[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
0x10, /* set upper 4 bit of the col adr to 0 */
|
||||
0x00, /* set lower 4 bit of the col adr to 0 */
|
||||
U8G_ESC_END /* end of sequence */
|
||||
};
|
||||
|
||||
static uint8_t u8g_dev_uc1611_dogxl240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_data_start);
|
||||
u8g_dev_dogxl240_set_page(u8g, dev, pb->p.page); /* select current page (uc1611) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||
return 0;
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x81);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1611_dogxl240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_UC_I2C);
|
||||
U8G_PB_DEV(u8g_dev_uc1611_dogxl240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1611_dogxl240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_HW_SPI);
|
||||
|
@ -45,6 +45,8 @@ static const uint8_t u8g_dev_dogs102_init_seq[] PROGMEM = {
|
||||
U8G_ESC_ADR(0), /* instruction mode */
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
0x0e2, /* soft reset */
|
||||
0x040, /* set display start line to 0 */
|
||||
0x0a1, /* ADC set to reverse */
|
||||
0x0c0, /* common output mode */
|
||||
@ -80,7 +82,7 @@ uint8_t u8g_dev_dogs102_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_dogs102_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -107,7 +109,49 @@ uint8_t u8g_dev_dogs102_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_uc1701_dogs102_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_dogs102_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_dogs102_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_dogs102_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1701_dogs102_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_dogs102_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1701_dogs102_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_dogs102_fn, U8G_COM_HW_SPI);
|
||||
|
||||
uint8_t u8g_dev_uc1701_dogs102_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_uc1701_dogs102_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1701_dogs102_2x_buf};
|
||||
u8g_dev_t u8g_dev_uc1701_dogs102_2x_sw_spi = { u8g_dev_uc1701_dogs102_2x_fn, &u8g_dev_uc1701_dogs102_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_uc1701_dogs102_2x_hw_spi = { u8g_dev_uc1701_dogs102_2x_fn, &u8g_dev_uc1701_dogs102_2x_pb, U8G_COM_HW_SPI };
|
||||
|
||||
|
@ -46,6 +46,7 @@ static const uint8_t u8g_dev_uc1701_mini12864_init_seq[] PROGMEM = {
|
||||
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||
U8G_ESC_CS(1), /* enable chip */
|
||||
|
||||
0x0e2, /* soft reset */
|
||||
0x040, /* set display start line to 0 */
|
||||
0x0a0, /* ADC set to reverse */
|
||||
0x0c8, /* common output mode */
|
||||
@ -83,7 +84,7 @@ uint8_t u8g_dev_uc1701_mini12864_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev);
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
@ -110,5 +111,48 @@ uint8_t u8g_dev_uc1701_mini12864_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, voi
|
||||
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
uint8_t u8g_dev_uc1701_mini12864_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_INIT:
|
||||
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_init_seq);
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
|
||||
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_data_start);
|
||||
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page */
|
||||
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_CONTRAST:
|
||||
u8g_SetChipSelect(u8g, dev, 1);
|
||||
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||
u8g_WriteByte(u8g, dev, 0x081);
|
||||
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||
u8g_SetChipSelect(u8g, dev, 0);
|
||||
return 1;
|
||||
}
|
||||
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_uc1701_mini12864_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1701_mini12864_fn, U8G_COM_SW_SPI);
|
||||
U8G_PB_DEV(u8g_dev_uc1701_mini12864_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1701_mini12864_fn, U8G_COM_HW_SPI);
|
||||
|
||||
uint8_t u8g_dev_uc1701_mini12864_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_dev_uc1701_mini12864_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1701_mini12864_2x_buf};
|
||||
u8g_dev_t u8g_dev_uc1701_mini12864_2x_sw_spi = { u8g_dev_uc1701_mini12864_2x_fn, &u8g_dev_uc1701_mini12864_2x_pb, U8G_COM_SW_SPI };
|
||||
u8g_dev_t u8g_dev_uc1701_mini12864_2x_hw_spi = { u8g_dev_uc1701_mini12864_2x_fn, &u8g_dev_uc1701_mini12864_2x_pb, U8G_COM_HW_SPI };
|
||||
|
@ -98,3 +98,296 @@ void u8g_DrawEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t xr, u8
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(U8G_16BIT)
|
||||
typedef int32_t u8g_long_t;
|
||||
#else
|
||||
typedef int16_t u8g_long_t;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Source:
|
||||
ftp://pc.fk0.name/pub/books/programming/bezier-ellipse.pdf
|
||||
Foley, Computer Graphics, p 90
|
||||
*/
|
||||
static void u8g_draw_ellipse_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
|
||||
static void u8g_draw_ellipse_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 - y);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 - y);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 + x, y0 + y);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g_DrawPixel(u8g, x0 - x, y0 + y);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_draw_ellipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option)
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
u8g_long_t xchg, ychg;
|
||||
u8g_long_t err;
|
||||
u8g_long_t rxrx2;
|
||||
u8g_long_t ryry2;
|
||||
u8g_long_t stopx, stopy;
|
||||
|
||||
rxrx2 = rx;
|
||||
rxrx2 *= rx;
|
||||
rxrx2 *= 2;
|
||||
|
||||
ryry2 = ry;
|
||||
ryry2 *= ry;
|
||||
ryry2 *= 2;
|
||||
|
||||
x = rx;
|
||||
y = 0;
|
||||
|
||||
xchg = 1;
|
||||
xchg -= rx;
|
||||
xchg -= rx;
|
||||
xchg *= ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = ryry2;
|
||||
stopx *= rx;
|
||||
stopy = 0;
|
||||
|
||||
while( stopx >= stopy )
|
||||
{
|
||||
u8g_draw_ellipse_section(u8g, x, y, x0, y0, option);
|
||||
y++;
|
||||
stopy += rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
if ( 2*err+xchg > 0 )
|
||||
{
|
||||
x--;
|
||||
stopx -= ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = ry;
|
||||
|
||||
xchg = ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = 1;
|
||||
ychg -= ry;
|
||||
ychg -= ry;
|
||||
ychg *= rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = 0;
|
||||
|
||||
stopy = rxrx2;
|
||||
stopy *= ry;
|
||||
|
||||
|
||||
while( stopx <= stopy )
|
||||
{
|
||||
u8g_draw_ellipse_section(u8g, x, y, x0, y0, option);
|
||||
x++;
|
||||
stopx += ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
if ( 2*err+ychg > 0 )
|
||||
{
|
||||
y--;
|
||||
stopy -= rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8g_DrawEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
{
|
||||
u8g_uint_t rxp, rxp2;
|
||||
u8g_uint_t ryp, ryp2;
|
||||
|
||||
rxp = rx;
|
||||
rxp++;
|
||||
rxp2 = rxp;
|
||||
rxp2 *= 2;
|
||||
|
||||
ryp = ry;
|
||||
ryp++;
|
||||
ryp2 = ryp;
|
||||
ryp2 *= 2;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-rxp, y0-ryp, rxp2, ryp2) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
u8g_draw_ellipse(u8g, x0, y0, rx, ry, option);
|
||||
}
|
||||
|
||||
static void u8g_draw_filled_ellipse_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
|
||||
static void u8g_draw_filled_ellipse_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0+x, y0, y+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g_DrawVLine(u8g, x0-x, y0, y+1);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g_draw_filled_ellipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option)
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
u8g_long_t xchg, ychg;
|
||||
u8g_long_t err;
|
||||
u8g_long_t rxrx2;
|
||||
u8g_long_t ryry2;
|
||||
u8g_long_t stopx, stopy;
|
||||
|
||||
rxrx2 = rx;
|
||||
rxrx2 *= rx;
|
||||
rxrx2 *= 2;
|
||||
|
||||
ryry2 = ry;
|
||||
ryry2 *= ry;
|
||||
ryry2 *= 2;
|
||||
|
||||
x = rx;
|
||||
y = 0;
|
||||
|
||||
xchg = 1;
|
||||
xchg -= rx;
|
||||
xchg -= rx;
|
||||
xchg *= ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = ryry2;
|
||||
stopx *= rx;
|
||||
stopy = 0;
|
||||
|
||||
while( stopx >= stopy )
|
||||
{
|
||||
u8g_draw_filled_ellipse_section(u8g, x, y, x0, y0, option);
|
||||
y++;
|
||||
stopy += rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
if ( 2*err+xchg > 0 )
|
||||
{
|
||||
x--;
|
||||
stopx -= ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = ry;
|
||||
|
||||
xchg = ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = 1;
|
||||
ychg -= ry;
|
||||
ychg -= ry;
|
||||
ychg *= rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = 0;
|
||||
|
||||
stopy = rxrx2;
|
||||
stopy *= ry;
|
||||
|
||||
|
||||
while( stopx <= stopy )
|
||||
{
|
||||
u8g_draw_filled_ellipse_section(u8g, x, y, x0, y0, option);
|
||||
x++;
|
||||
stopx += ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
if ( 2*err+ychg > 0 )
|
||||
{
|
||||
y--;
|
||||
stopy -= rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8g_DrawFilledEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
{
|
||||
u8g_uint_t rxp, rxp2;
|
||||
u8g_uint_t ryp, ryp2;
|
||||
|
||||
rxp = rx;
|
||||
rxp++;
|
||||
rxp2 = rxp;
|
||||
rxp2 *= 2;
|
||||
|
||||
ryp = ry;
|
||||
ryp++;
|
||||
ryp2 = ryp;
|
||||
ryp2 *= 2;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x0-rxp, y0-ryp, rxp2, ryp2) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
u8g_draw_filled_ellipse(u8g, x0, y0, rx, ry, option);
|
||||
}
|
||||
|
@ -33,7 +33,6 @@
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
@ -120,6 +119,7 @@ static uint8_t u8g_font_GetFontGlyphStructureSize(const u8g_fntpgm_uint8_t *font
|
||||
{
|
||||
case 0: return 6;
|
||||
case 1: return 3;
|
||||
case 2: return 6;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
@ -281,6 +281,7 @@ static void u8g_CopyGlyphDataToCache(u8g_t *u8g, u8g_glyph_t g)
|
||||
switch( u8g_font_GetFormat(u8g->font) )
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
/*
|
||||
format 0
|
||||
glyph information
|
||||
@ -961,6 +962,7 @@ int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir,
|
||||
x -= u8g_GetFontBBXOffX(u8g);
|
||||
y += u8g_GetFontBBXOffY(u8g);
|
||||
u8g_draw_glyph(u8g, x, y, encoding);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1420,3 +1422,79 @@ void u8g_SetFont(u8g_t *u8g, const u8g_fntpgm_uint8_t *font)
|
||||
}
|
||||
}
|
||||
|
||||
/*========================================================================*/
|
||||
/* anti aliasing fonts */
|
||||
|
||||
int8_t u8g_draw_aa_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
|
||||
{
|
||||
const u8g_pgm_uint8_t *data;
|
||||
uint8_t w, h;
|
||||
uint8_t i, j;
|
||||
u8g_uint_t ix, iy;
|
||||
|
||||
{
|
||||
u8g_glyph_t g = u8g_GetGlyph(u8g, encoding);
|
||||
if ( g == NULL )
|
||||
return 0;
|
||||
data = u8g_font_GetGlyphDataStart(u8g->font, g);
|
||||
}
|
||||
|
||||
w = u8g->glyph_width;
|
||||
h = u8g->glyph_height;
|
||||
|
||||
x += u8g->glyph_x;
|
||||
y -= u8g->glyph_y;
|
||||
y--;
|
||||
|
||||
if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 )
|
||||
return u8g->glyph_dx;
|
||||
|
||||
/* now, w is reused as bytes per line */
|
||||
w += 3;
|
||||
w /= 4;
|
||||
|
||||
iy = y;
|
||||
iy -= h;
|
||||
iy++;
|
||||
|
||||
for( j = 0; j < h; j++ )
|
||||
{
|
||||
ix = x;
|
||||
for( i = 0; i < w; i++ )
|
||||
{
|
||||
u8g_Draw4TPixel(u8g, ix, iy, 0, u8g_pgm_read(data));
|
||||
data++;
|
||||
ix+=4;
|
||||
}
|
||||
iy++;
|
||||
}
|
||||
return u8g->glyph_dx;
|
||||
}
|
||||
|
||||
int8_t u8g_DrawAAGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
|
||||
{
|
||||
y += u8g->font_calc_vref(u8g);
|
||||
return u8g_draw_aa_glyph(u8g, x, y, encoding);
|
||||
}
|
||||
|
||||
u8g_uint_t u8g_DrawAAStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s)
|
||||
{
|
||||
u8g_uint_t t = 0;
|
||||
int8_t d;
|
||||
|
||||
if ( u8g_font_GetFormat(u8g->font) != 2 )
|
||||
return 0;
|
||||
//u8g_uint_t u8g_GetStrWidth(u8g, s);
|
||||
//u8g_font_GetFontAscent(u8g->font)-u8g_font_GetFontDescent(u8g->font);
|
||||
|
||||
y += u8g->font_calc_vref(u8g);
|
||||
|
||||
while( *s != '\0' )
|
||||
{
|
||||
d = u8g_draw_aa_glyph(u8g, x, y, *s);
|
||||
x += d;
|
||||
t += d;
|
||||
s++;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -102,6 +102,17 @@ void u8g_Draw8PixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, ui
|
||||
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_8PIXEL, arg);
|
||||
}
|
||||
|
||||
void u8g_Draw4TPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
|
||||
{
|
||||
u8g_dev_arg_pixel_t *arg = &(u8g->arg_pixel);
|
||||
arg->x = x;
|
||||
arg->y = y;
|
||||
arg->dir = dir;
|
||||
arg->pixel = pixel;
|
||||
u8g_call_dev_fn(u8g, dev, U8G_DEV_MSG_SET_4TPIXEL, arg);
|
||||
}
|
||||
|
||||
|
||||
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
|
||||
uint8_t u8g_IsBBXIntersectionLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
|
||||
{
|
||||
@ -145,17 +156,21 @@ void u8g_UpdateDimension(u8g_t *u8g)
|
||||
|
||||
static void u8g_init_data(u8g_t *u8g)
|
||||
{
|
||||
uint8_t i;
|
||||
u8g->font = NULL;
|
||||
u8g->cursor_font = NULL;
|
||||
u8g->cursor_bg_color = 0;
|
||||
u8g->cursor_fg_color = 1;
|
||||
u8g->cursor_encoding = 34;
|
||||
u8g->cursor_fn = (u8g_draw_cursor_fn)0;
|
||||
|
||||
for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
|
||||
u8g->pin_list[i] = U8G_PIN_NONE;
|
||||
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
{
|
||||
uint8_t i;
|
||||
for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
|
||||
u8g->pin_list[i] = U8G_PIN_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
u8g_SetColorIndex(u8g, 1);
|
||||
|
||||
u8g_SetFontPosBaseline(u8g);
|
||||
@ -192,6 +207,33 @@ uint8_t u8g_Init(u8g_t *u8g, u8g_dev_t *dev)
|
||||
return u8g_Begin(u8g);
|
||||
}
|
||||
|
||||
/* special init for pure ARM systems */
|
||||
uint8_t u8g_InitComFn(u8g_t *u8g, u8g_dev_t *dev, u8g_com_fnptr com_fn)
|
||||
{
|
||||
u8g_init_data(u8g);
|
||||
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
{
|
||||
uint8_t i;
|
||||
for( i = 0; i < U8G_PIN_LIST_LEN; i++ )
|
||||
u8g->pin_list[i] = U8G_PIN_DUMMY;
|
||||
}
|
||||
#endif
|
||||
|
||||
u8g->dev = dev;
|
||||
|
||||
/* replace the device procedure with a custom communication procedure */
|
||||
u8g->dev->com_fn = com_fn;
|
||||
|
||||
/* On the Arduino Environment this will lead to two calls to u8g_Begin(), the following line will be called first (by U8glib constructors) */
|
||||
/* if - in future releases - this is removed, then still call u8g_UpdateDimension() */
|
||||
/* if Arduino call u8g_UpdateDimension else u8g_Begin */
|
||||
/* issue 146 */
|
||||
return u8g_Begin(u8g);
|
||||
}
|
||||
|
||||
|
||||
#if defined(U8G_WITH_PINLIST)
|
||||
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
|
||||
{
|
||||
|
||||
@ -336,6 +378,7 @@ uint8_t u8g_InitRW8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8
|
||||
|
||||
return u8g_Begin(u8g);
|
||||
}
|
||||
#endif /* defined(U8G_WITH_PINLIST) */
|
||||
|
||||
void u8g_FirstPage(u8g_t *u8g)
|
||||
{
|
||||
@ -377,6 +420,12 @@ void u8g_Draw8Pixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t
|
||||
u8g_Draw8PixelLL(u8g, u8g->dev, x, y, dir, pixel);
|
||||
}
|
||||
|
||||
void u8g_Draw4TPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel)
|
||||
{
|
||||
u8g_Draw4TPixelLL(u8g, u8g->dev, x, y, dir, pixel);
|
||||
}
|
||||
|
||||
|
||||
/* u8g_IsBBXIntersection() has been moved to u8g_clip.c */
|
||||
#ifdef OBSOLETE_CODE
|
||||
uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
|
||||
@ -394,12 +443,72 @@ uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
idx: index for the palette entry (0..255)
|
||||
r: value for red (0..255)
|
||||
g: value for green (0..255)
|
||||
b: value for blue (0..255)
|
||||
*/
|
||||
void u8g_SetColorEntry(u8g_t *u8g, uint8_t idx, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
u8g_dev_arg_irgb_t irgb;
|
||||
irgb.idx = idx;
|
||||
irgb.r = r;
|
||||
irgb.g = g;
|
||||
irgb.b = b;
|
||||
u8g_call_dev_fn(u8g, u8g->dev, U8G_DEV_MSG_SET_COLOR_ENTRY, &irgb);
|
||||
}
|
||||
|
||||
void u8g_SetColorIndex(u8g_t *u8g, uint8_t idx)
|
||||
{
|
||||
u8g->arg_pixel.color = idx;
|
||||
/*u8g->color_index = idx; */ /* must be removed */
|
||||
}
|
||||
|
||||
void u8g_SetHiColor(u8g_t *u8g, uint16_t rgb)
|
||||
{
|
||||
u8g->arg_pixel.color = rgb&255;
|
||||
u8g->arg_pixel.hi_color = rgb>>8;
|
||||
/*u8g->color_index = idx; */ /* must be removed */
|
||||
}
|
||||
|
||||
void u8g_SetHiColorByRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
|
||||
r &= ~7;
|
||||
g >>= 2;
|
||||
b >>= 3;
|
||||
u8g->arg_pixel.color = b;
|
||||
u8g->arg_pixel.color |= (g & 7) << 5;
|
||||
u8g->arg_pixel.hi_color = r;
|
||||
u8g->arg_pixel.hi_color |= (g>>3) & 7;
|
||||
|
||||
//u8g_SetHiColor(u8g, U8G_GET_HICOLOR_BY_RGB(r,g,b));
|
||||
}
|
||||
|
||||
void u8g_SetRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
if ( u8g->mode == U8G_MODE_R3G3B2 )
|
||||
{
|
||||
r &= 0x0e0;
|
||||
g &= 0x0e0;
|
||||
g >>= 3;
|
||||
b >>= 6;
|
||||
u8g->arg_pixel.color = r | g | b;
|
||||
}
|
||||
else if ( u8g->mode == U8G_MODE_HICOLOR )
|
||||
{
|
||||
u8g_SetHiColorByRGB(u8g, r,g,b);
|
||||
}
|
||||
else
|
||||
{
|
||||
u8g->arg_pixel.color = r;
|
||||
u8g->arg_pixel.hi_color = g;
|
||||
u8g->arg_pixel.blue = b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_GetColorIndex(u8g_t *u8g)
|
||||
{
|
||||
return u8g->arg_pixel.color;
|
||||
@ -420,7 +529,15 @@ uint8_t u8g_GetDefaultForegroundColor(u8g_t *u8g)
|
||||
|
||||
void u8g_SetDefaultForegroundColor(u8g_t *u8g)
|
||||
{
|
||||
u8g_SetColorIndex(u8g, u8g_GetDefaultForegroundColor(u8g));
|
||||
if ( u8g->mode == U8G_MODE_HICOLOR )
|
||||
{
|
||||
u8g->arg_pixel.color = 0x0ff;
|
||||
u8g->arg_pixel.hi_color = 0x0ff;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8g_SetColorIndex(u8g, u8g_GetDefaultForegroundColor(u8g));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t u8g_GetDefaultBackgroundColor(u8g_t *u8g)
|
||||
|
@ -187,7 +187,7 @@ uint8_t u8g_dev_pb14v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -200,7 +200,7 @@ uint8_t u8g_dev_pb16h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -62,8 +62,8 @@ void u8g_pb16h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
|
||||
u8g_pb16h2_Clear(b);
|
||||
}
|
||||
|
||||
static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
|
||||
static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
|
||||
static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index, uint8_t is_or) U8G_NOINLINE;
|
||||
static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index, uint8_t is_or)
|
||||
{
|
||||
register uint8_t mask;
|
||||
register uint16_t tmp;
|
||||
@ -84,18 +84,20 @@ static void u8g_pb16h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_
|
||||
tmp = x;
|
||||
tmp &= 3;
|
||||
tmp <<= 1;
|
||||
mask = 3;
|
||||
mask <<= tmp;
|
||||
mask = ~mask;
|
||||
if ( is_or == 0 )
|
||||
{
|
||||
mask = 3;
|
||||
mask <<= tmp;
|
||||
mask = ~mask;
|
||||
*ptr &= mask;
|
||||
}
|
||||
color_index &= 3;
|
||||
color_index <<= tmp;
|
||||
|
||||
*ptr &= mask;
|
||||
*ptr |= color_index;
|
||||
}
|
||||
|
||||
|
||||
void u8g_pb16h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
|
||||
void u8g_pb16h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel, uint8_t is_or)
|
||||
{
|
||||
if ( arg_pixel->y < b->p.page_y0 )
|
||||
return;
|
||||
@ -103,7 +105,7 @@ void u8g_pb16h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixe
|
||||
return;
|
||||
if ( arg_pixel->x >= b->width )
|
||||
return;
|
||||
u8g_pb16h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
|
||||
u8g_pb16h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, is_or);
|
||||
}
|
||||
|
||||
|
||||
@ -114,7 +116,7 @@ void u8g_pb16h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||
{
|
||||
if ( pixel & 128 )
|
||||
{
|
||||
u8g_pb16h2_SetPixel(b, arg_pixel);
|
||||
u8g_pb16h2_SetPixel(b, arg_pixel, 0);
|
||||
}
|
||||
switch( arg_pixel->dir )
|
||||
{
|
||||
@ -127,6 +129,24 @@ void u8g_pb16h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||
} while( pixel != 0 );
|
||||
}
|
||||
|
||||
void u8g_pb16h2_Or4PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||
{
|
||||
register uint8_t pixel = arg_pixel->pixel;
|
||||
do
|
||||
{
|
||||
arg_pixel->color = pixel & 0x0c0;
|
||||
arg_pixel->color >>= 6;
|
||||
u8g_pb16h2_SetPixel(b, arg_pixel, 1);
|
||||
switch( arg_pixel->dir )
|
||||
{
|
||||
case 0: arg_pixel->x++; break;
|
||||
case 1: arg_pixel->y++; break;
|
||||
case 2: arg_pixel->x--; break;
|
||||
case 3: arg_pixel->y--; break;
|
||||
}
|
||||
pixel <<= 2;
|
||||
} while( pixel != 0 );
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_dev_pb16h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
@ -141,7 +161,13 @@ uint8_t u8g_dev_pb16h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
}
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_PIXEL:
|
||||
u8g_pb16h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||
u8g_pb16h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg, 0);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_4TPIXEL:
|
||||
u8g_pb16h2_Or4PixelStd(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_TPIXEL:
|
||||
u8g_pb16h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg, 1);
|
||||
break;
|
||||
case U8G_DEV_MSG_INIT:
|
||||
break;
|
||||
@ -169,7 +195,7 @@ uint8_t u8g_dev_pb16h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -187,7 +187,7 @@ uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -159,7 +159,7 @@ uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -195,7 +195,7 @@ uint8_t u8g_dev_pb32h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -376,7 +376,7 @@ uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -181,7 +181,7 @@ uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *ar
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -154,7 +154,7 @@ uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
u8g_pb8h8.c
|
||||
|
||||
8 bits per pixel, horizontal
|
||||
8 lines per page, horizontal, 8 bits per pixel
|
||||
(22 May 2013: might also support any number of lines --> needs to be checked)
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
@ -51,21 +52,26 @@ u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn }
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
/*
|
||||
#define WIDTH_BITS 7
|
||||
#define WIDTH (1<<WIDTH_BITS)
|
||||
#define PAGE_HEIGHT_BITS 3
|
||||
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
|
||||
*/
|
||||
|
||||
void u8g_pb8h8_Clear(u8g_pb_t *b)
|
||||
{
|
||||
uint8_t *ptr = (uint8_t *)b->buf;
|
||||
uint8_t *end_ptr = ptr;
|
||||
uint8_t cnt = b->p.page_height;
|
||||
end_ptr += b->width*cnt;
|
||||
/*
|
||||
do
|
||||
{
|
||||
end_ptr += b->width;
|
||||
cnt--;
|
||||
} while( cnt > 0 );
|
||||
*/
|
||||
do
|
||||
{
|
||||
*ptr++ = 0;
|
||||
@ -167,7 +173,7 @@ uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -171,7 +171,7 @@ uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -140,7 +140,7 @@ uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
|
@ -0,0 +1,184 @@
|
||||
/*
|
||||
|
||||
u8g_pbxh16.c
|
||||
|
||||
x lines per page, horizontal, 16 bits per pixel (hi color modes)
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
struct _u8g_pb_t
|
||||
{
|
||||
u8g_page_t p;
|
||||
u8g_uint_t width;
|
||||
void *buf;
|
||||
};
|
||||
typedef struct _u8g_pb_t u8g_pb_t;
|
||||
|
||||
|
||||
uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
|
||||
u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
/*
|
||||
#define WIDTH_BITS 7
|
||||
#define WIDTH (1<<WIDTH_BITS)
|
||||
#define PAGE_HEIGHT_BITS 3
|
||||
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
|
||||
*/
|
||||
|
||||
void u8g_pbxh16_Clear(u8g_pb_t *b)
|
||||
{
|
||||
uint8_t *ptr = (uint8_t *)b->buf;
|
||||
uint8_t *end_ptr = ptr;
|
||||
uint8_t cnt = b->p.page_height;
|
||||
do
|
||||
{
|
||||
end_ptr += b->width*2;
|
||||
cnt--;
|
||||
} while( cnt > 0 );
|
||||
do
|
||||
{
|
||||
*ptr++ = 0;
|
||||
} while( ptr != end_ptr );
|
||||
}
|
||||
|
||||
|
||||
void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
|
||||
{
|
||||
b->buf = buf;
|
||||
b->width = width;
|
||||
u8g_pbxh16_Clear(b);
|
||||
}
|
||||
|
||||
static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high)
|
||||
{
|
||||
uint16_t tmp;
|
||||
uint8_t *ptr = b->buf;
|
||||
y -= b->p.page_y0;
|
||||
tmp = y;
|
||||
tmp *= b->width;
|
||||
tmp += x;
|
||||
tmp <<= 1;
|
||||
ptr += tmp;
|
||||
*ptr = low;
|
||||
ptr++;
|
||||
*ptr = high;
|
||||
}
|
||||
|
||||
void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
|
||||
{
|
||||
if ( arg_pixel->y < b->p.page_y0 )
|
||||
return;
|
||||
if ( arg_pixel->y > b->p.page_y1 )
|
||||
return;
|
||||
if ( arg_pixel->x >= b->width )
|
||||
return;
|
||||
u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color);
|
||||
}
|
||||
|
||||
|
||||
void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||
{
|
||||
register uint8_t pixel = arg_pixel->pixel;
|
||||
u8g_uint_t dx = 0;
|
||||
u8g_uint_t dy = 0;
|
||||
|
||||
switch( arg_pixel->dir )
|
||||
{
|
||||
case 0: dx++; break;
|
||||
case 1: dy++; break;
|
||||
case 2: dx--; break;
|
||||
case 3: dy--; break;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if ( pixel & 128 )
|
||||
u8g_pbxh16_SetPixel(b, arg_pixel);
|
||||
arg_pixel->x += dx;
|
||||
arg_pixel->y += dy;
|
||||
pixel <<= 1;
|
||||
} while( pixel != 0 );
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_SET_8PIXEL:
|
||||
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
|
||||
u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_PIXEL:
|
||||
u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_INIT:
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_pbxh16_Clear(pb);
|
||||
u8g_page_First(&(pb->p));
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
if ( u8g_page_Next(&(pb->p)) == 0 )
|
||||
return 0;
|
||||
u8g_pbxh16_Clear(pb);
|
||||
break;
|
||||
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
|
||||
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
|
||||
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
|
||||
#endif
|
||||
case U8G_DEV_MSG_GET_PAGE_BOX:
|
||||
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_WIDTH:
|
||||
*((u8g_uint_t *)arg) = pb->width;
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_HICOLOR;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -0,0 +1,287 @@
|
||||
/*
|
||||
|
||||
u8g_pbxh24.c
|
||||
|
||||
x lines per page, horizontal, 24 bits per pixel (true color modes)
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
struct _u8g_pb_t
|
||||
{
|
||||
u8g_page_t p;
|
||||
u8g_uint_t width;
|
||||
void *buf;
|
||||
};
|
||||
typedef struct _u8g_pb_t u8g_pb_t;
|
||||
|
||||
|
||||
uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||
u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
|
||||
u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
/*
|
||||
#define WIDTH_BITS 7
|
||||
#define WIDTH (1<<WIDTH_BITS)
|
||||
#define PAGE_HEIGHT_BITS 3
|
||||
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
|
||||
*/
|
||||
|
||||
void u8g_pbxh24_Clear(u8g_pb_t *b)
|
||||
{
|
||||
uint8_t *ptr = (uint8_t *)b->buf;
|
||||
uint8_t *end_ptr = ptr;
|
||||
uint8_t cnt = b->p.page_height;
|
||||
do
|
||||
{
|
||||
end_ptr += b->width*3;
|
||||
cnt--;
|
||||
} while( cnt > 0 );
|
||||
do
|
||||
{
|
||||
*ptr++ = 0;
|
||||
} while( ptr != end_ptr );
|
||||
}
|
||||
|
||||
|
||||
void u8g_pbxh24_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
|
||||
{
|
||||
b->buf = buf;
|
||||
b->width = width;
|
||||
u8g_pbxh24_Clear(b);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
static void u8g_pbxh24_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
uint16_t tmp;
|
||||
uint8_t *ptr = b->buf;
|
||||
y -= b->p.page_y0;
|
||||
tmp = y;
|
||||
tmp *= b->width;
|
||||
tmp += x;
|
||||
tmp *= 3;
|
||||
ptr += tmp;
|
||||
*ptr = r;
|
||||
ptr++;
|
||||
*ptr = g;
|
||||
ptr++;
|
||||
*ptr = b;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
intensity
|
||||
0..3 intensity value
|
||||
4 replace color
|
||||
*/
|
||||
static void u8g_pbxh24_set_tpixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t red, uint8_t green, uint8_t blue, uint8_t intensity)
|
||||
{
|
||||
uint16_t tmp;
|
||||
uint8_t *ptr = b->buf;
|
||||
|
||||
if ( intensity == 0 )
|
||||
return;
|
||||
|
||||
y -= b->p.page_y0;
|
||||
tmp = y;
|
||||
tmp *= b->width;
|
||||
tmp += x;
|
||||
tmp *= 3;
|
||||
ptr += tmp;
|
||||
|
||||
if ( intensity == 4 )
|
||||
{
|
||||
*ptr = red;
|
||||
ptr++;
|
||||
*ptr = green;
|
||||
ptr++;
|
||||
*ptr = blue;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( intensity == 2 )
|
||||
{
|
||||
/*
|
||||
red = red/4 + red/2;
|
||||
green = green/4 + green/2;
|
||||
blue = blue/4 + blue/2;
|
||||
*/
|
||||
red >>= 1;
|
||||
green >>= 1;
|
||||
blue >>= 1;
|
||||
}
|
||||
else if ( intensity == 1 )
|
||||
{
|
||||
red >>= 2;
|
||||
green >>= 2;
|
||||
blue >>= 2;
|
||||
}
|
||||
|
||||
if ( *ptr >= 255-red ) *ptr = 255;
|
||||
else *ptr += red;
|
||||
ptr++;
|
||||
|
||||
if ( *ptr >= 255-green ) *ptr = 255;
|
||||
else *ptr += green;
|
||||
ptr++;
|
||||
|
||||
if ( *ptr >= 255-blue ) *ptr = 255;
|
||||
else *ptr += blue;
|
||||
|
||||
/*
|
||||
if ( *ptr < red ) *ptr = red;
|
||||
ptr++;
|
||||
if ( *ptr < green ) *ptr = green;
|
||||
ptr++;
|
||||
if ( *ptr < blue ) *ptr = blue;
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
void u8g_pbxh24_SetTPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel, uint8_t intensity)
|
||||
{
|
||||
if ( arg_pixel->y < b->p.page_y0 )
|
||||
return;
|
||||
if ( arg_pixel->y > b->p.page_y1 )
|
||||
return;
|
||||
if ( arg_pixel->x >= b->width )
|
||||
return;
|
||||
u8g_pbxh24_set_tpixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color, arg_pixel->blue, intensity);
|
||||
}
|
||||
|
||||
|
||||
void u8g_pbxh24_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||
{
|
||||
register uint8_t pixel = arg_pixel->pixel;
|
||||
u8g_uint_t dx = 0;
|
||||
u8g_uint_t dy = 0;
|
||||
|
||||
switch( arg_pixel->dir )
|
||||
{
|
||||
case 0: dx++; break;
|
||||
case 1: dy++; break;
|
||||
case 2: dx--; break;
|
||||
case 3: dy--; break;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if ( pixel & 128 )
|
||||
u8g_pbxh24_SetTPixel(b, arg_pixel, 4);
|
||||
arg_pixel->x += dx;
|
||||
arg_pixel->y += dy;
|
||||
pixel <<= 1;
|
||||
} while( pixel != 0 );
|
||||
}
|
||||
|
||||
void u8g_pbxh24_Set4TPixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||
{
|
||||
register uint8_t pixel = arg_pixel->pixel;
|
||||
u8g_uint_t dx = 0;
|
||||
u8g_uint_t dy = 0;
|
||||
|
||||
switch( arg_pixel->dir )
|
||||
{
|
||||
case 0: dx++; break;
|
||||
case 1: dy++; break;
|
||||
case 2: dx--; break;
|
||||
case 3: dy--; break;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
u8g_pbxh24_SetTPixel(b, arg_pixel, pixel >> 6);
|
||||
arg_pixel->x += dx;
|
||||
arg_pixel->y += dy;
|
||||
pixel <<= 2;
|
||||
} while( pixel != 0 );
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8g_dev_pbxh24_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
switch(msg)
|
||||
{
|
||||
case U8G_DEV_MSG_SET_8PIXEL:
|
||||
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
|
||||
u8g_pbxh24_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_PIXEL:
|
||||
u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, 4);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_4TPIXEL:
|
||||
u8g_pbxh24_Set4TPixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_TPIXEL:
|
||||
u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, ((u8g_dev_arg_pixel_t *)arg)->pixel&3);
|
||||
break;
|
||||
case U8G_DEV_MSG_INIT:
|
||||
break;
|
||||
case U8G_DEV_MSG_STOP:
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
u8g_pbxh24_Clear(pb);
|
||||
u8g_page_First(&(pb->p));
|
||||
break;
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
if ( u8g_page_Next(&(pb->p)) == 0 )
|
||||
return 0;
|
||||
u8g_pbxh24_Clear(pb);
|
||||
break;
|
||||
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
|
||||
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
|
||||
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
|
||||
#endif
|
||||
case U8G_DEV_MSG_GET_PAGE_BOX:
|
||||
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_WIDTH:
|
||||
*((u8g_uint_t *)arg) = pb->width;
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_HEIGHT:
|
||||
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
break;
|
||||
case U8G_DEV_MSG_GET_MODE:
|
||||
return U8G_MODE_TRUECOLOR;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -0,0 +1,334 @@
|
||||
/*
|
||||
|
||||
u8g_polygon.c
|
||||
|
||||
Implementation of a polygon draw algorithm for "convex" polygons.
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2013, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
See also:
|
||||
http://www.angelfire.com/linux/myp/ConvexPolRas/ConvexPolRas.html
|
||||
Computer Graphics, Principles and Practice, Foley, van Dam, Feiner, Hughes (pp 92)
|
||||
Michael Abrash's Graphics Programming Black Book, Special Edition (Chapter 38 and 39)
|
||||
|
||||
Optimized for embedded systems
|
||||
- static memory usage only
|
||||
- consistent data types
|
||||
- low flash ROM consumption
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8g.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/*===========================================*/
|
||||
/* procedures, which should not be inlined (save as much flash ROM as possible */
|
||||
|
||||
static uint8_t pge_Next(struct pg_edge_struct *pge) PG_NOINLINE;
|
||||
static uint8_t pg_inc(pg_struct *pg, uint8_t i) PG_NOINLINE;
|
||||
static uint8_t pg_dec(pg_struct *pg, uint8_t i) PG_NOINLINE;
|
||||
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx) PG_NOINLINE;
|
||||
static void pg_line_init(pg_struct * const pg, uint8_t pge_index) PG_NOINLINE;
|
||||
|
||||
/*===========================================*/
|
||||
/* line draw algorithm */
|
||||
|
||||
static uint8_t pge_Next(struct pg_edge_struct *pge)
|
||||
{
|
||||
if ( pge->current_y >= pge->max_y )
|
||||
return 0;
|
||||
|
||||
pge->current_x += pge->current_x_offset;
|
||||
pge->error += pge->error_offset;
|
||||
if ( pge->error > 0 )
|
||||
{
|
||||
pge->current_x += pge->x_direction;
|
||||
pge->error -= pge->height;
|
||||
}
|
||||
|
||||
pge->current_y++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* assumes y2 > y1 */
|
||||
static void pge_Init(struct pg_edge_struct *pge, pg_word_t x1, pg_word_t y1, pg_word_t x2, pg_word_t y2)
|
||||
{
|
||||
pg_word_t dx = x2 - x1;
|
||||
pg_word_t width;
|
||||
|
||||
pge->height = y2 - y1;
|
||||
pge->max_y = y2;
|
||||
pge->current_y = y1;
|
||||
pge->current_x = x1;
|
||||
|
||||
if ( dx >= 0 )
|
||||
{
|
||||
pge->x_direction = 1;
|
||||
width = dx;
|
||||
pge->error = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pge->x_direction = -1;
|
||||
width = -dx;
|
||||
pge->error = 1 - pge->height;
|
||||
}
|
||||
|
||||
pge->current_x_offset = dx / pge->height;
|
||||
pge->error_offset = width % pge->height;
|
||||
}
|
||||
|
||||
/*===========================================*/
|
||||
/* convex polygon algorithm */
|
||||
|
||||
static uint8_t pg_inc(pg_struct *pg, uint8_t i)
|
||||
{
|
||||
i++;
|
||||
if ( i >= pg->cnt )
|
||||
i = 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
static uint8_t pg_dec(pg_struct *pg, uint8_t i)
|
||||
{
|
||||
i--;
|
||||
if ( i >= pg->cnt )
|
||||
i = pg->cnt-1;
|
||||
return i;
|
||||
}
|
||||
|
||||
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx)
|
||||
{
|
||||
uint8_t i = pg->pge[pge_idx].curr_idx;
|
||||
for(;;)
|
||||
{
|
||||
i = pg->pge[pge_idx].next_idx_fn(pg, i);
|
||||
if ( pg->list[i].y != min_y )
|
||||
break;
|
||||
pg->pge[pge_idx].curr_idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t pg_prepare(pg_struct *pg)
|
||||
{
|
||||
pg_word_t max_y;
|
||||
pg_word_t min_y;
|
||||
uint8_t i;
|
||||
|
||||
/* setup the next index procedures */
|
||||
pg->pge[PG_RIGHT].next_idx_fn = pg_inc;
|
||||
pg->pge[PG_LEFT].next_idx_fn = pg_dec;
|
||||
|
||||
/* search for highest and lowest point */
|
||||
max_y = pg->list[0].y;
|
||||
min_y = pg->list[0].y;
|
||||
pg->pge[PG_LEFT].curr_idx = 0;
|
||||
for( i = 1; i < pg->cnt; i++ )
|
||||
{
|
||||
if ( max_y < pg->list[i].y )
|
||||
{
|
||||
max_y = pg->list[i].y;
|
||||
}
|
||||
if ( min_y > pg->list[i].y )
|
||||
{
|
||||
pg->pge[PG_LEFT].curr_idx = i;
|
||||
min_y = pg->list[i].y;
|
||||
}
|
||||
}
|
||||
|
||||
/* calculate total number of scan lines */
|
||||
pg->total_scan_line_cnt = max_y;
|
||||
pg->total_scan_line_cnt -= min_y;
|
||||
|
||||
/* exit if polygon height is zero */
|
||||
if ( pg->total_scan_line_cnt == 0 )
|
||||
return 0;
|
||||
|
||||
/* if the minimum y side is flat, try to find the lowest and highest x points */
|
||||
pg->pge[PG_RIGHT].curr_idx = pg->pge[PG_LEFT].curr_idx;
|
||||
pg_expand_min_y(pg, min_y, PG_RIGHT);
|
||||
pg_expand_min_y(pg, min_y, PG_LEFT);
|
||||
|
||||
/* check if the min side is really flat (depends on the x values) */
|
||||
pg->is_min_y_not_flat = 1;
|
||||
if ( pg->list[pg->pge[PG_LEFT].curr_idx].x != pg->list[pg->pge[PG_RIGHT].curr_idx].x )
|
||||
{
|
||||
pg->is_min_y_not_flat = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pg->total_scan_line_cnt--;
|
||||
if ( pg->total_scan_line_cnt == 0 )
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void pg_hline(pg_struct *pg, u8g_t *u8g)
|
||||
{
|
||||
pg_word_t x1, x2, y;
|
||||
x1 = pg->pge[PG_LEFT].current_x;
|
||||
x2 = pg->pge[PG_RIGHT].current_x;
|
||||
y = pg->pge[PG_RIGHT].current_y;
|
||||
|
||||
if ( y < 0 )
|
||||
return;
|
||||
if ( y >= u8g_GetHeight(u8g) )
|
||||
return;
|
||||
if ( x1 < x2 )
|
||||
{
|
||||
if ( x2 < 0 )
|
||||
return;
|
||||
if ( x1 >= u8g_GetWidth(u8g) )
|
||||
return;
|
||||
if ( x1 < 0 )
|
||||
x1 = 0;
|
||||
if ( x2 >= u8g_GetWidth(u8g) )
|
||||
x2 = u8g_GetWidth(u8g);
|
||||
u8g_DrawHLine(u8g, x1, y, x2 - x1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( x1 < 0 )
|
||||
return;
|
||||
if ( x2 >= u8g_GetWidth(u8g) )
|
||||
return;
|
||||
if ( x2 < 0 )
|
||||
x1 = 0;
|
||||
if ( x1 >= u8g_GetWidth(u8g) )
|
||||
x1 = u8g_GetWidth(u8g);
|
||||
u8g_DrawHLine(u8g, x2, y, x1 - x2);
|
||||
}
|
||||
}
|
||||
|
||||
static void pg_line_init(pg_struct * pg, uint8_t pge_index)
|
||||
{
|
||||
struct pg_edge_struct *pge = pg->pge+pge_index;
|
||||
uint8_t idx;
|
||||
pg_word_t x1;
|
||||
pg_word_t y1;
|
||||
pg_word_t x2;
|
||||
pg_word_t y2;
|
||||
|
||||
idx = pge->curr_idx;
|
||||
y1 = pg->list[idx].y;
|
||||
x1 = pg->list[idx].x;
|
||||
idx = pge->next_idx_fn(pg, idx);
|
||||
y2 = pg->list[idx].y;
|
||||
x2 = pg->list[idx].x;
|
||||
pge->curr_idx = idx;
|
||||
|
||||
pge_Init(pge, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
static void pg_exec(pg_struct *pg, u8g_t *u8g)
|
||||
{
|
||||
pg_word_t i = pg->total_scan_line_cnt;
|
||||
|
||||
/* first line is skipped if the min y line is not flat */
|
||||
pg_line_init(pg, PG_LEFT);
|
||||
pg_line_init(pg, PG_RIGHT);
|
||||
|
||||
if ( pg->is_min_y_not_flat != 0 )
|
||||
{
|
||||
pge_Next(&(pg->pge[PG_LEFT]));
|
||||
pge_Next(&(pg->pge[PG_RIGHT]));
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
pg_hline(pg, u8g);
|
||||
while ( pge_Next(&(pg->pge[PG_LEFT])) == 0 )
|
||||
{
|
||||
pg_line_init(pg, PG_LEFT);
|
||||
}
|
||||
while ( pge_Next(&(pg->pge[PG_RIGHT])) == 0 )
|
||||
{
|
||||
pg_line_init(pg, PG_RIGHT);
|
||||
}
|
||||
i--;
|
||||
} while( i > 0 );
|
||||
}
|
||||
|
||||
/*===========================================*/
|
||||
/* API procedures */
|
||||
|
||||
void pg_ClearPolygonXY(pg_struct *pg)
|
||||
{
|
||||
pg->cnt = 0;
|
||||
}
|
||||
|
||||
void pg_AddPolygonXY(pg_struct *pg, u8g_t *u8g, int16_t x, int16_t y)
|
||||
{
|
||||
if ( pg->cnt < PG_MAX_POINTS )
|
||||
{
|
||||
pg->list[pg->cnt].x = x;
|
||||
pg->list[pg->cnt].y = y;
|
||||
pg->cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
void pg_DrawPolygon(pg_struct *pg, u8g_t *u8g)
|
||||
{
|
||||
if ( pg_prepare(pg) == 0 )
|
||||
return;
|
||||
pg_exec(pg, u8g);
|
||||
}
|
||||
|
||||
pg_struct u8g_pg;
|
||||
|
||||
void u8g_ClearPolygonXY(void)
|
||||
{
|
||||
pg_ClearPolygonXY(&u8g_pg);
|
||||
}
|
||||
|
||||
void u8g_AddPolygonXY(u8g_t *u8g, int16_t x, int16_t y)
|
||||
{
|
||||
pg_AddPolygonXY(&u8g_pg, u8g, x, y);
|
||||
}
|
||||
|
||||
void u8g_DrawPolygon(u8g_t *u8g)
|
||||
{
|
||||
pg_DrawPolygon(&u8g_pg, u8g);
|
||||
}
|
||||
|
||||
void u8g_DrawTriangle(u8g_t *u8g, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||
{
|
||||
u8g_ClearPolygonXY();
|
||||
u8g_AddPolygonXY(u8g, x0, y0);
|
||||
u8g_AddPolygonXY(u8g, x1, y1);
|
||||
u8g_AddPolygonXY(u8g, x2, y2);
|
||||
u8g_DrawPolygon(u8g);
|
||||
}
|
||||
|
@ -40,7 +40,12 @@ uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
|
||||
uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
|
||||
uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
|
||||
|
||||
u8g_dev_t u8g_dev_rot = { u8g_dev_rot90_fn, NULL, NULL };
|
||||
uint8_t u8g_dev_rot_dummy_fn(void *u8g, void *dev, uint8_t msg, void *arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8g_dev_t u8g_dev_rot = { u8g_dev_rot_dummy_fn, NULL, NULL };
|
||||
|
||||
|
||||
void u8g_UndoRotation(u8g_t *u8g)
|
||||
@ -95,7 +100,7 @@ uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
case U8G_DEV_MSG_STOP:
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
*/
|
||||
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
|
||||
@ -151,6 +156,7 @@ uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
*((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, rotation_chain);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_PIXEL:
|
||||
case U8G_DEV_MSG_SET_TPIXEL:
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
y = ((u8g_dev_arg_pixel_t *)arg)->x;
|
||||
@ -163,6 +169,7 @@ uint8_t u8g_dev_rot90_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_8PIXEL:
|
||||
case U8G_DEV_MSG_SET_4TPIXEL:
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
//uint16_t x,y;
|
||||
@ -192,7 +199,7 @@ uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
case U8G_DEV_MSG_STOP:
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
*/
|
||||
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
|
||||
@ -248,6 +255,7 @@ uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
*((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g, rotation_chain);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_PIXEL:
|
||||
case U8G_DEV_MSG_SET_TPIXEL:
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
|
||||
@ -265,6 +273,7 @@ uint8_t u8g_dev_rot180_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_8PIXEL:
|
||||
case U8G_DEV_MSG_SET_4TPIXEL:
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
|
||||
@ -298,7 +307,7 @@ uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
case U8G_DEV_MSG_STOP:
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
case U8G_DEV_MSG_SET_COLOR_INDEX:
|
||||
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||
case U8G_DEV_MSG_SET_XY_CB:
|
||||
*/
|
||||
return u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
|
||||
@ -353,6 +362,7 @@ uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
*((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, rotation_chain);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_PIXEL:
|
||||
case U8G_DEV_MSG_SET_TPIXEL:
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
x = ((u8g_dev_arg_pixel_t *)arg)->y;
|
||||
@ -372,6 +382,7 @@ uint8_t u8g_dev_rot270_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||
u8g_call_dev_fn(u8g, rotation_chain, msg, arg);
|
||||
break;
|
||||
case U8G_DEV_MSG_SET_8PIXEL:
|
||||
case U8G_DEV_MSG_SET_4TPIXEL:
|
||||
{
|
||||
u8g_uint_t x, y;
|
||||
x = ((u8g_dev_arg_pixel_t *)arg)->y;
|
||||
|
@ -63,6 +63,15 @@ void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb)
|
||||
}
|
||||
|
||||
|
||||
/*===============================================================*/
|
||||
/* register variable for restoring interrupt state */
|
||||
|
||||
#if defined(__AVR__)
|
||||
uint8_t global_SREG_backup;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*===============================================================*/
|
||||
/* AVR */
|
||||
|
||||
@ -82,7 +91,7 @@ void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb)
|
||||
#include <avr/interrupt.h>
|
||||
static uint8_t u8g_state_avr_spi_memory[2];
|
||||
|
||||
void u8g_backup_avr_spi(uint8_t msg)
|
||||
void u8g_backup_spi(uint8_t msg)
|
||||
{
|
||||
if ( U8G_STATE_MSG_IS_BACKUP(msg) )
|
||||
{
|
||||
@ -98,5 +107,52 @@ void u8g_backup_avr_spi(uint8_t msg)
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (U8G_RASPBERRY_PI)
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void u8g_backup_spi(uint8_t msg) {
|
||||
printf("u8g_backup_spi %d\r\n",msg);
|
||||
}
|
||||
|
||||
#elif defined(ARDUINO) && defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__
|
||||
|
||||
#include "sam.h"
|
||||
|
||||
struct sam_backup_struct
|
||||
{
|
||||
uint32_t mr;
|
||||
uint32_t sr;
|
||||
uint32_t csr[4];
|
||||
} sam_backup[2];
|
||||
|
||||
void u8g_backup_spi(uint8_t msg)
|
||||
{
|
||||
uint8_t idx = U8G_STATE_MSG_GET_IDX(msg);
|
||||
if ( U8G_STATE_MSG_IS_BACKUP(msg) )
|
||||
{
|
||||
sam_backup[idx].mr = SPI0->SPI_MR;
|
||||
sam_backup[idx].sr = SPI0->SPI_SR;
|
||||
sam_backup[idx].csr[0] = SPI0->SPI_CSR[0];
|
||||
sam_backup[idx].csr[1] = SPI0->SPI_CSR[1];
|
||||
sam_backup[idx].csr[2] = SPI0->SPI_CSR[2];
|
||||
sam_backup[idx].csr[3] = SPI0->SPI_CSR[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
SPI0->SPI_MR = sam_backup[idx].mr;
|
||||
SPI0->SPI_CSR[0] = sam_backup[idx].csr[0];
|
||||
SPI0->SPI_CSR[1] = sam_backup[idx].csr[1];
|
||||
SPI0->SPI_CSR[2] = sam_backup[idx].csr[2];
|
||||
SPI0->SPI_CSR[3] = sam_backup[idx].csr[3];
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void u8g_backup_spi(uint8_t msg)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user