2017-02-02 16:07:59 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
|
|
|
* http://ugfx.org/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gfx.h"
|
|
|
|
|
|
|
|
#if GFX_USE_GDISP
|
|
|
|
|
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_UC8173
|
|
|
|
#include "gdisp_lld_config.h"
|
|
|
|
#include "../../../src/gdisp/gdisp_driver.h"
|
|
|
|
|
2017-06-30 09:43:51 +00:00
|
|
|
#if defined(GDISP_SCREEN_HEIGHT) || defined(GDISP_SCREEN_HEIGHT)
|
|
|
|
#if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
|
|
|
|
#warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
|
|
|
|
#elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
|
|
|
|
COMPILER_WARNING("GDISP: This low level driver does not support setting a screen size. It is being ignored.")
|
|
|
|
#endif
|
|
|
|
#undef GDISP_SCREEN_WIDTH
|
|
|
|
#undef GDISP_SCREEN_HEIGHT
|
2017-02-02 16:07:59 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
/*------------------ Load the board file ------------------*/
|
|
|
|
typedef struct UC8173Lut {
|
|
|
|
uint8_t const *lutVCOM; // 32 bytes
|
|
|
|
uint8_t const *lutFW; // 512 bytes
|
|
|
|
uint8_t const *lutFT; // 128 bytes
|
2018-06-23 03:02:07 +00:00
|
|
|
gBool regal;
|
2017-08-13 10:07:39 +00:00
|
|
|
} UC8173Lut;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
#include "board_UC8173.h"
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
/*------------------ Default UC8173 parameters ------------------*/
|
|
|
|
#ifndef UC8173_REVERSEAXIS_Y
|
2018-02-27 07:44:21 +00:00
|
|
|
#define UC8173_REVERSEAXIS_Y GFXOFF
|
2017-08-13 10:07:39 +00:00
|
|
|
#endif
|
|
|
|
#ifndef UC8173_REVERSEAXIS_X
|
2018-02-27 07:44:21 +00:00
|
|
|
#define UC8173_REVERSEAXIS_X GFXOFF
|
2017-08-13 10:07:39 +00:00
|
|
|
#endif
|
|
|
|
#ifndef UC8173_DEFAULT_MODE
|
|
|
|
#define UC8173_DEFAULT_MODE 0
|
|
|
|
#endif
|
|
|
|
#ifndef UC8173_USE_OTP_LUT
|
2018-02-27 07:44:21 +00:00
|
|
|
#define UC8173_USE_OTP_LUT GFXOFF
|
2017-08-13 10:07:39 +00:00
|
|
|
#endif
|
|
|
|
#ifndef UC8173_CAN_READ
|
2018-02-27 07:44:21 +00:00
|
|
|
#define UC8173_CAN_READ GFXOFF
|
2017-08-13 10:07:39 +00:00
|
|
|
#endif
|
|
|
|
#ifdef UC8173_VCOM_VOLTAGE
|
|
|
|
#define UC8173_VCOM_VOLTAGEBYTE (((UC8173_VCOM_VOLTAGE) + 0.1)/-0.05)
|
|
|
|
#endif
|
|
|
|
#ifndef UC8171_BORDER
|
|
|
|
#define UC8171_BORDER 0 /* 0 = Hi-Z, 1 = Black, 2 = White */
|
|
|
|
#endif
|
|
|
|
#ifndef UC8173_INIT_REAL_LUT
|
2018-02-27 07:44:21 +00:00
|
|
|
#define UC8173_INIT_REAL_LUT GFXON
|
2017-08-13 10:07:39 +00:00
|
|
|
#endif
|
|
|
|
#define UC8173_HEIGHT 240
|
|
|
|
#define UC8173_WIDTH 240
|
|
|
|
|
|
|
|
/*------------------ Set FB parameters ------------------*/
|
|
|
|
#define FB_REVERSEAXIS_Y UC8173_REVERSEAXIS_Y
|
|
|
|
#define FB_REVERSEAXIS_X UC8173_REVERSEAXIS_X
|
|
|
|
#define FB_WIDTH UC8173_WIDTH
|
|
|
|
#define FB_HEIGHT UC8173_HEIGHT
|
|
|
|
#define FB_PAGES 1
|
2018-02-27 07:44:21 +00:00
|
|
|
#define FB_PIXELORDER_MSB GFXON
|
2017-08-13 10:07:39 +00:00
|
|
|
|
|
|
|
/*------------------ Include Generic FB Code ------------------*/
|
|
|
|
// This FB is for 1,2 or 4 bits per pixel packed along the x-axis
|
|
|
|
#define FB_TYPE_PIXELS (LLDCOLOR_TYPE_BITS/LLDCOLOR_BITS)
|
|
|
|
#define FB_AXIS_MASK (FB_TYPE_PIXELS-1)
|
|
|
|
#define FB_LINE_TYPES ((FB_WIDTH+FB_TYPE_PIXELS-1)/FB_TYPE_PIXELS)
|
|
|
|
#define FB_PAGE_TYPES (FB_LINE_TYPES*FB_HEIGHT)
|
|
|
|
#define FB_ADDR(fbp, pg, px, py) ((fbp)->fb + ((px)/FB_TYPE_PIXELS + (py)*FB_LINE_TYPES + (pg)*FB_PAGE_TYPES))
|
|
|
|
#if FB_PIXELORDER_MSB
|
|
|
|
#define FB_COLOR(px, py, c) ((c) << ((LLDCOLOR_TYPE_BITS-LLDCOLOR_BITS)-(((px) & FB_AXIS_MASK)<<(LLDCOLOR_BITS-1))))
|
|
|
|
#else
|
|
|
|
#define FB_COLOR(px, py, c) ((c) << (((px) & FB_AXIS_MASK)<<(LLDCOLOR_BITS-1)))
|
|
|
|
#endif
|
|
|
|
#define FB_FLUSH_REQUIRED(fbp) ((fbp)->fa0.x < (fbp)->fa1.x)
|
|
|
|
#define FB_FLUSH_WIDTH(fbp) ((fbp)->fa1.x - (fbp)->fa0.x + 1)
|
|
|
|
#define FB_FLUSH_HEIGHT(fbp) ((fbp)->fa1.y - (fbp)->fa0.y + 1)
|
|
|
|
#define FB_FLUSH_ALL(fbp) { (fbp)->fa0.x = (fbp)->fa0.y = 0; (fbp)->fa1.x = FB_WIDTH-1; (fbp)->fa1.y = FB_HEIGHT-1; }
|
|
|
|
#define FB_FLUSH_NONE(fbp) { (fbp)->fa0.x = FB_WIDTH; (fbp)->fa0.y = FB_HEIGHT; (fbp)->fa1.x = (fbp)->fa1.y = -1; }
|
|
|
|
#define FB_FLUSH_POINT(fbp, px, py) { \
|
|
|
|
if ((px) < (fbp)->fa0.x) (fbp)->fa0.x = (px) & ~FB_AXIS_MASK; \
|
|
|
|
if ((px) > (fbp)->fa1.x) (fbp)->fa1.x = (px) | FB_AXIS_MASK; \
|
|
|
|
if ((py) < (fbp)->fa0.y) (fbp)->fa0.y = (py); \
|
|
|
|
if ((py) > (fbp)->fa1.y) (fbp)->fa1.y = (py); \
|
|
|
|
}
|
|
|
|
#define FB_SETPIXEL(fbp, pg, px, py, c) { \
|
|
|
|
LLDCOLOR_TYPE *p, oc; \
|
|
|
|
p = FB_ADDR((fbp), (pg), (px), (py)); \
|
|
|
|
oc = (*p & ~FB_COLOR((px), (py), LLDCOLOR_MASK())) | FB_COLOR((px), (py), (c)); \
|
|
|
|
if (oc != *p) { *p = oc; FB_FLUSH_POINT((fbp), (px), (py)); } \
|
|
|
|
}
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
typedef struct FBpriv {
|
|
|
|
point_t fa0, fa1;
|
|
|
|
LLDCOLOR_TYPE fb[FB_PAGE_TYPES * FB_PAGES];
|
|
|
|
} FBpriv;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
/*------------------ UC8173 Driver Code ------------------*/
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
#include "UC8173.h"
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// UC8173 Inernal Macros & types
|
|
|
|
typedef struct UC8173_Private {
|
|
|
|
UC8173Lut *lut;
|
|
|
|
FBpriv fb;
|
|
|
|
} UC8173_Private;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
#if !UC8173_INIT_REAL_LUT
|
|
|
|
static uint8_t const UC8173_LUT_None[] = {
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
|
|
0x00,0x00
|
|
|
|
};
|
2017-03-02 06:10:14 +00:00
|
|
|
#endif
|
2017-08-13 10:07:39 +00:00
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
LLDSPEC gBool gdisp_lld_init(GDisplay* g)
|
2017-02-02 16:07:59 +00:00
|
|
|
{
|
2017-08-13 10:07:39 +00:00
|
|
|
UC8173_Private *priv;
|
|
|
|
|
|
|
|
// Allocate the private area
|
|
|
|
g->priv = gfxAlloc(sizeof(UC8173_Private));
|
|
|
|
if (!g->priv)
|
2018-06-23 03:02:07 +00:00
|
|
|
return gFalse;
|
2017-08-13 10:07:39 +00:00
|
|
|
priv = (UC8173_Private *)g->priv;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Initialize the private area
|
2017-08-13 10:07:39 +00:00
|
|
|
// As the display is non-volatile we need to ensure a full flush on the first draw
|
|
|
|
priv->lut = &UC8173_ModeTable[UC8173_DEFAULT_MODE];
|
|
|
|
FB_FLUSH_ALL(&priv->fb);
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Initialise the board interface
|
2017-08-13 10:07:39 +00:00
|
|
|
if (!init_board(g))
|
2018-06-23 03:02:07 +00:00
|
|
|
return gFalse;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Hardware reset
|
2018-06-23 03:02:07 +00:00
|
|
|
setpin_reset(g, gTrue);
|
2017-02-02 16:07:59 +00:00
|
|
|
gfxSleepMilliseconds(100);
|
2018-06-23 03:02:07 +00:00
|
|
|
setpin_reset(g, gFalse);
|
2017-08-13 10:07:39 +00:00
|
|
|
gfxSleepMilliseconds(300);
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Acquire the bus
|
|
|
|
acquire_bus(g);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Booster soft-start - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, BTST);
|
2017-08-13 10:07:39 +00:00
|
|
|
write_data(g, 0x17); // data: PhaseA: Bits76=StartupTime [10ms+n*10ms def=0x00], Bits543=Strength, Bits210=MinGDROffTime
|
|
|
|
write_data(g, 0x97); // data: PhaseB: Bits76=StartupTime [10ms+n*10ms def=0x00], Bits543=Strength, Bits210=MinGDROffTime
|
|
|
|
write_data(g, 0x20); // data: PhaseC: Bits543=Strength, Bits210=MinGDROffTime [def=0x07]
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Power settings - Values from datasheet default values
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, PWR);
|
2017-08-13 10:07:39 +00:00
|
|
|
write_data(g, 0x03); // data: 0x02=Internal VDH/VDL, 0x01=Internal VGH/VGL
|
|
|
|
write_data(g, 0x00); // data: Always 0x00
|
|
|
|
write_data(g, 0x26); // data: 0x00->0x3F VSH Voltage 2.4V -> 11.0V step 0.2V - default=10V (0x26)
|
|
|
|
write_data(g, 0x26); // data: 0x00->0x3F VSL Voltage 2.4V -> 11.0V step 0.2V - default=10V (0x26)
|
|
|
|
write_data(g, 0x03); // data: 0x00->0x3F Red Voltage 2.4V -> 11.0V step 0.2V - default= 3V (0x03)
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Power-on
|
|
|
|
write_cmd(g, PON);
|
2017-08-13 10:07:39 +00:00
|
|
|
while (!getpin_busy(g));
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Panel setting register - Values from datasheet (OTP untested)
|
|
|
|
write_cmd(g, PSR); // data: 0x08 + ..., 0x04=Shift Right, 0x02=Booster On, 0x01=Reset Off
|
|
|
|
write_data(g, 0x0F);
|
|
|
|
#if UC8173_USE_OTP_LUT
|
|
|
|
write_cmd(g, 0x86); // data: Always 0x86, write_data=Register LUT, write_cmd=OTP LUT
|
|
|
|
#else
|
|
|
|
write_data(g, 0x86);
|
|
|
|
#endif
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Power-off sequence - Values from example code
|
|
|
|
write_cmd(g, PFS); // data: Shutdown frames - 0x00=1, 0x10=2, 0x20=3, 0x30=4
|
2017-02-02 16:07:59 +00:00
|
|
|
write_data(g, 0x00);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// PLL control - Values from example code
|
|
|
|
write_cmd(g, LPRD); // data: PLL Clock Freq = 1MHz/(n+1) Min=0x04 (=200kHz)
|
2017-02-02 16:07:59 +00:00
|
|
|
write_data(g, 0x25);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Internal temperature sensor enable - Values from example code
|
|
|
|
write_cmd(g, TSE); // data: 0x00=Use internal temperature sensor, 0x80=external, Bits0-4=signed degrees to add eg 0x0F = -1
|
|
|
|
write_data(g, 0x00);
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// VCOM settings - Values from datasheet
|
|
|
|
write_cmd(g, CDI); // data: 0x80=Border Hi-Z, 0x40=Border Output DC enabled, 0x30=BorderColor, 0x01=Normal/Inverted
|
|
|
|
#if UC8171_BORDER == 0
|
|
|
|
write_data(g, 0x81);
|
|
|
|
#elif UC8171_BORDER == 1
|
|
|
|
write_data(g, 0x41);
|
|
|
|
#elif UC8171_BORDER == 2
|
|
|
|
write_data(g, 0x71);
|
|
|
|
#else
|
|
|
|
#error "UC8173: UC8173_BORDER must be 0..2"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// More VCOM data - Values from example code
|
|
|
|
write_data(g, 0x20); // data: 0xX0=Src->VCOM interval (n+1 HSync, Def=0011), 0b0000-00XX=VCOM->Src interval (top 2 bits)
|
|
|
|
write_data(g, 0x10); // data: 0xXX=VCOM->Src interval (bottom 8 bits) Def=0x18
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Set display panel resolution - from datasheet: should always be 240x240 for this chip
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, TRES);
|
2017-08-13 10:07:39 +00:00
|
|
|
write_data(g, (UC8173_WIDTH-1));
|
|
|
|
write_data(g, ((UC8173_HEIGHT-1)>>8));
|
|
|
|
write_data(g, ((UC8173_HEIGHT-1) & 0xFF));
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Undocumented register - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, GDS);
|
|
|
|
write_data(g, 0xA9);
|
|
|
|
write_data(g, 0xA9);
|
|
|
|
write_data(g, 0xEB);
|
|
|
|
write_data(g, 0xEB);
|
|
|
|
write_data(g, 0x02);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Auto measure VCOM - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, AMV);
|
2017-08-13 10:07:39 +00:00
|
|
|
write_data(g, 0x11);
|
|
|
|
while (!getpin_busy(g));
|
|
|
|
|
|
|
|
// Get current VCOM value and write it
|
|
|
|
#if defined(UC8173_VCOM_VOLTAGEBYTE)
|
|
|
|
// VCM_DC setting
|
|
|
|
write_cmd(g, VDCS);
|
|
|
|
write_data(g, UC8173_VCOM_VOLTAGEBYTE); // was 0x12 in example code = -1.0V
|
|
|
|
#elif UC8173_CAN_READ
|
|
|
|
{
|
|
|
|
uint8_t vc;
|
|
|
|
|
|
|
|
write_cmd(g, VV);
|
|
|
|
vc = read_data(g);
|
|
|
|
write_cmd(g, VDCS);
|
|
|
|
write_data(g, vc);
|
|
|
|
}
|
|
|
|
#else
|
2018-02-27 07:44:21 +00:00
|
|
|
#error "UC8173: Either UC8173_VCOM_VOLTAGE or UC8173_VCOM_VOLTAGEBYTE must be defined or UC8173_CAN_READ must be GFXON"
|
2017-08-13 10:07:39 +00:00
|
|
|
#endif
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Undocumented register - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, VBDS);
|
|
|
|
write_data(g, 0x22);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Undocumented register - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, LVSEL);
|
|
|
|
write_data(g, 0x02);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Undocumented register - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, GBS);
|
|
|
|
write_data(g, 0x02);
|
|
|
|
write_data(g, 0x02);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Undocumented register - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, GSS);
|
|
|
|
write_data(g, 0x02);
|
|
|
|
write_data(g, 0x02);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Undocumented register - Values from example code
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, DF); // For REGAL (???)
|
|
|
|
write_data(g, 0x1F);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
write_cmd(g, PON);
|
|
|
|
while (!getpin_busy(g));
|
|
|
|
|
|
|
|
#if UC8173_INIT_REAL_LUT
|
|
|
|
// Load the real LUT's
|
|
|
|
write_cmd(g, LUT_KWVCOM);
|
|
|
|
write_data_burst(g, priv->lut->lutVCOM, 32);
|
|
|
|
write_cmd(g, LUT_KW);
|
|
|
|
write_data_burst(g, priv->lut->lutFW, 512);
|
|
|
|
write_cmd(g, LUT_FT);
|
|
|
|
write_data_burst(g, priv->lut->lutFT, 128);
|
|
|
|
#else
|
|
|
|
// Clear the LUT's - Values from example code
|
|
|
|
write_cmd(g, LUT_KW);
|
|
|
|
write_data_burst(g, UC8173_LUT_None, sizeof(UC8173_LUT_None));
|
|
|
|
write_cmd(g, LUT_KWVCOM);
|
|
|
|
write_data_burst(g, UC8173_LUT_None, sizeof(UC8173_LUT_None));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
write_cmd(g, POF);
|
|
|
|
while (getpin_busy(g));
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Finish Init
|
|
|
|
post_init_board(g);
|
|
|
|
|
|
|
|
// Release the bus
|
|
|
|
release_bus(g);
|
|
|
|
|
|
|
|
// Initialise the GDISP structure
|
2017-08-13 10:07:39 +00:00
|
|
|
g->g.Width = UC8173_WIDTH;
|
|
|
|
g->g.Height = UC8173_HEIGHT;
|
2017-02-02 16:07:59 +00:00
|
|
|
g->g.Orientation = GDISP_ROTATE_0;
|
|
|
|
g->g.Powermode = powerOn;
|
|
|
|
g->g.Backlight = 0;
|
|
|
|
g->g.Contrast = 0;
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
return gTrue;
|
2017-02-02 16:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if GDISP_HARDWARE_FLUSH
|
|
|
|
LLDSPEC void gdisp_lld_flush(GDisplay* g)
|
|
|
|
{
|
2017-08-13 10:07:39 +00:00
|
|
|
coord_t cy, cx, dx, dy;
|
|
|
|
LLDCOLOR_TYPE *fb;
|
|
|
|
UC8173_Private *priv;
|
|
|
|
|
|
|
|
priv = (UC8173_Private *)g->priv;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
if (!FB_FLUSH_REQUIRED(&priv->fb))
|
2017-02-02 16:07:59 +00:00
|
|
|
return;
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
#if 0
|
|
|
|
FB_FLUSH_ALL(&priv->fb);
|
|
|
|
#endif
|
|
|
|
|
2017-02-02 16:07:59 +00:00
|
|
|
// Acquire the bus to communicate with the display controller
|
|
|
|
acquire_bus(g);
|
|
|
|
|
|
|
|
// Upload the new temperature LUT
|
2017-08-13 10:07:39 +00:00
|
|
|
write_cmd(g, LUT_KWVCOM);
|
|
|
|
write_data_burst(g, priv->lut->lutVCOM, 32);
|
|
|
|
write_cmd(g, LUT_KW);
|
|
|
|
write_data_burst(g, priv->lut->lutFW, 512);
|
|
|
|
write_cmd(g, LUT_FT);
|
|
|
|
write_data_burst(g, priv->lut->lutFT, 128);
|
|
|
|
|
|
|
|
// Calculate the width, height
|
|
|
|
cx = FB_FLUSH_WIDTH(&priv->fb);
|
|
|
|
cy = FB_FLUSH_HEIGHT(&priv->fb);
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Setup the window
|
2017-08-13 10:07:39 +00:00
|
|
|
// Datasheet says x,y,w,h but in practice it needs to be x,y,w-1,h-1
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, DTMW);
|
2017-08-13 10:07:39 +00:00
|
|
|
write_data(g, (uint8_t)((priv->fb.fa0.x >> 0) & 0xFF));
|
|
|
|
write_data(g, (uint8_t)((priv->fb.fa0.y >> 8) & 0x03));
|
|
|
|
write_data(g, (uint8_t)((priv->fb.fa0.y >> 0) & 0xFF));
|
|
|
|
write_data(g, (uint8_t)(((cx-1) >> 0) & 0xFF));
|
|
|
|
write_data(g, (uint8_t)(((cy-1) >> 8) & 0x03));
|
|
|
|
write_data(g, (uint8_t)(((cy-1) >> 0) & 0xFF));
|
|
|
|
|
|
|
|
// Transfer the buffer
|
|
|
|
#if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_MONO
|
|
|
|
write_cmd(g, DTM4);
|
|
|
|
#elif GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_GRAY4
|
|
|
|
write_cmd(g, DTM2);
|
|
|
|
#else
|
|
|
|
#error "UC8173: Unsupported driver color format"
|
|
|
|
#endif
|
|
|
|
dx = (cx+FB_TYPE_PIXELS-1)/FB_TYPE_PIXELS * (LLDCOLOR_TYPE_BITS/8);
|
|
|
|
for (fb = FB_ADDR(&priv->fb, 0, priv->fb.fa0.x, priv->fb.fa0.y), dy = cy; dy; dy--, fb += FB_LINE_TYPES)
|
|
|
|
write_data_burst(g, (uint8_t *)fb, dx);
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Power-up the DC/DC converter to update the display panel
|
|
|
|
write_cmd(g, PON);
|
2017-08-13 10:07:39 +00:00
|
|
|
while (!getpin_busy(g));
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Refresh the panel contents
|
2017-08-13 10:07:39 +00:00
|
|
|
// Datasheet says x,y,w,h but in practice it needs to be x,y,w-1,h-1
|
|
|
|
write_cmd(g, DRF); // data: Partial Scan = 0x10, REGAL = 0x08, VCOM_DoNothing = 0x04 (GC4/A2 = 0x00, GU4 = 0x08)
|
|
|
|
write_data(g, (priv->lut->regal ? 0x08 : 0x00));
|
|
|
|
write_data(g, (uint8_t)((priv->fb.fa0.x >> 0) & 0xFF));
|
|
|
|
write_data(g, (uint8_t)((priv->fb.fa0.y >> 8) & 0x03));
|
|
|
|
write_data(g, (uint8_t)((priv->fb.fa0.y >> 0) & 0xFF));
|
|
|
|
write_data(g, (uint8_t)(((cx-1) >> 0) & 0xFF));
|
|
|
|
write_data(g, (uint8_t)(((cy-1) >> 8) & 0x03));
|
|
|
|
write_data(g, (uint8_t)(((cy-1) >> 0) & 0xFF));
|
|
|
|
while (!getpin_busy(g));
|
|
|
|
|
|
|
|
// Power-down the DC/DC converter
|
2017-02-02 16:07:59 +00:00
|
|
|
write_cmd(g, POF);
|
2017-08-13 10:07:39 +00:00
|
|
|
while (getpin_busy(g));
|
2017-02-02 16:07:59 +00:00
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Release the bus
|
2017-02-02 16:07:59 +00:00
|
|
|
release_bus(g);
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Mark as flushed
|
|
|
|
FB_FLUSH_NONE(&priv->fb);
|
2017-02-02 16:07:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GDISP_HARDWARE_DRAWPIXEL
|
|
|
|
LLDSPEC void gdisp_lld_draw_pixel(GDisplay* g)
|
|
|
|
{
|
|
|
|
coord_t x, y;
|
2017-08-13 10:07:39 +00:00
|
|
|
UC8173_Private *priv;
|
|
|
|
|
|
|
|
priv = (UC8173_Private *)g->priv;
|
2017-02-02 16:07:59 +00:00
|
|
|
|
|
|
|
// Handle the different possible orientations
|
2017-08-13 10:07:39 +00:00
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
|
|
|
switch(g->g.Orientation) {
|
|
|
|
default:
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
#if FB_REVERSEAXIS_X
|
|
|
|
x = FB_WIDTH-1 - g->p.x;
|
|
|
|
#else
|
|
|
|
x = g->p.x;
|
|
|
|
#endif
|
|
|
|
#if FB_REVERSEAXIS_Y
|
|
|
|
y = FB_HEIGHT-1 - g->p.y;
|
|
|
|
#else
|
|
|
|
y = g->p.y;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
#if FB_REVERSEAXIS_X
|
|
|
|
x = FB_WIDTH-1 - g->p.y;
|
|
|
|
#else
|
|
|
|
x = g->p.y;
|
|
|
|
#endif
|
|
|
|
#if FB_REVERSEAXIS_Y
|
|
|
|
y = g->p.x;
|
|
|
|
#else
|
|
|
|
y = FB_HEIGHT-1 - g->p.x;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
#if FB_REVERSEAXIS_X
|
|
|
|
x = g->p.x;
|
|
|
|
#else
|
|
|
|
x = FB_WIDTH-1 - g->p.x;
|
|
|
|
#endif
|
|
|
|
#if FB_REVERSEAXIS_Y
|
|
|
|
y = g->p.y;
|
|
|
|
#else
|
|
|
|
y = FB_HEIGHT-1 - g->p.y;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_270:
|
|
|
|
#if FB_REVERSEAXIS_X
|
|
|
|
x = g->p.y;
|
|
|
|
#else
|
|
|
|
x = FB_WIDTH-1 - g->p.y;
|
|
|
|
#endif
|
|
|
|
#if FB_REVERSEAXIS_Y
|
|
|
|
y = FB_HEIGHT-1 - g->p.x;
|
|
|
|
#else
|
|
|
|
y = g->p.x;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#if FB_REVERSEAXIS_X
|
|
|
|
x = FB_WIDTH-1 - g->p.x;
|
|
|
|
#else
|
|
|
|
x = g->p.x;
|
|
|
|
#endif
|
|
|
|
#if FB_REVERSEAXIS_Y
|
|
|
|
y = FB_HEIGHT-1 - g->p.y;
|
|
|
|
#else
|
|
|
|
y = g->p.y;
|
|
|
|
#endif
|
|
|
|
#endif
|
2017-03-02 06:10:14 +00:00
|
|
|
|
2017-02-02 16:07:59 +00:00
|
|
|
// Modify the framebuffer content
|
2017-08-13 10:07:39 +00:00
|
|
|
FB_SETPIXEL(&priv->fb, 0, x, y, gdispColor2Native(g->p.color));
|
2017-02-02 16:07:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay* g) {
|
2017-08-13 10:07:39 +00:00
|
|
|
UC8173_Private *priv;
|
|
|
|
|
|
|
|
priv = (UC8173_Private *)g->priv;
|
|
|
|
|
2017-02-02 16:07:59 +00:00
|
|
|
switch(g->p.x) {
|
2017-08-13 10:07:39 +00:00
|
|
|
|
|
|
|
// Custom gdispControl() to invert the framebuffer
|
2017-02-02 16:07:59 +00:00
|
|
|
case GDISP_CONTROL_INVERT:
|
2017-08-13 10:07:39 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
LLDCOLOR_TYPE *fb;
|
|
|
|
|
|
|
|
// Invert the framebuffer
|
|
|
|
for (fb = priv->fb.fb, i = FB_PAGE_TYPES; i ; i--, fb++)
|
|
|
|
fb[0] = ~fb[0];
|
|
|
|
|
|
|
|
// We should flush these changes to the display controller framebuffer at some point
|
|
|
|
FB_FLUSH_ALL(&priv->fb);
|
|
|
|
}
|
2017-02-02 16:07:59 +00:00
|
|
|
break;
|
|
|
|
|
2017-08-13 10:07:39 +00:00
|
|
|
// Custom gdispControl() to set which EINK Mode (waveform) to use
|
|
|
|
case GDISP_CONTROL_SETMODE:
|
|
|
|
if ((unsigned)g->p.ptr < sizeof(UC8173_ModeTable)/sizeof(UC8173_ModeTable[0]))
|
|
|
|
priv->lut = &UC8173_ModeTable[(unsigned)g->p.ptr];
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Custom gdispControl() to set the EINK border
|
|
|
|
case GDISP_CONTROL_SETBORDER:
|
|
|
|
if ((unsigned)g->p.ptr > 2)
|
|
|
|
break;
|
|
|
|
acquire_bus(g);
|
|
|
|
write_cmd(g, PON);
|
|
|
|
while (!getpin_busy(g));
|
|
|
|
write_cmd(g, CDI);
|
|
|
|
switch((unsigned)g->p.ptr) {
|
|
|
|
case 0:
|
|
|
|
write_data(g, 0x81); // Border Hi-Z
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
write_data(g, 0x41); // Border Black
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
write_data(g, 0x71); // Border White
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
write_cmd(g, POF);
|
|
|
|
while (getpin_busy(g));
|
|
|
|
release_bus(g);
|
|
|
|
break;
|
|
|
|
|
2017-02-02 16:07:59 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // GFX_USE_GDISP
|