2013-09-24 19:15:55 +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
|
|
|
|
*/
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
/**
|
|
|
|
* @file drivers/gdisp/ED060SC4/gdisp_lld.c
|
|
|
|
* @brief GDISP Graphics Driver for the E-ink panel ED060SC4.
|
|
|
|
*/
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
#include "gfx.h"
|
|
|
|
|
|
|
|
#if GFX_USE_GDISP
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_ED060SC4
|
2014-02-18 14:36:52 +00:00
|
|
|
#include "drivers/gdisp/ED060SC4/gdisp_lld_config.h"
|
|
|
|
#include "src/gdisp/driver.h"
|
2013-10-22 15:34:56 +00:00
|
|
|
|
|
|
|
#include "board_ED060SC4.h"
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
#ifndef GDISP_SCREEN_HEIGHT
|
2013-10-22 15:34:56 +00:00
|
|
|
#define GDISP_SCREEN_HEIGHT 600
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
#ifndef GDISP_SCREEN_WIDTH
|
2013-10-22 15:34:56 +00:00
|
|
|
#define GDISP_SCREEN_WIDTH 800
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number of pixels per byte */
|
|
|
|
#ifndef EINK_PPB
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_PPB 4
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Delay for generating clock pulses.
|
|
|
|
* Unit is approximate clock cycles of the CPU (0 to 15).
|
|
|
|
* This should be atleast 50 ns.
|
|
|
|
*/
|
|
|
|
#ifndef EINK_CLOCKDELAY
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_CLOCKDELAY 0
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Width of one framebuffer block.
|
|
|
|
* Must be divisible by EINK_PPB and evenly divide GDISP_SCREEN_WIDTH. */
|
|
|
|
#ifndef EINK_BLOCKWIDTH
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_BLOCKWIDTH 20
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Height of one framebuffer block.
|
|
|
|
* Must evenly divide GDISP_SCREEN_WIDTH. */
|
|
|
|
#ifndef EINK_BLOCKHEIGHT
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_BLOCKHEIGHT 20
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number of block buffers to use for framebuffer emulation. */
|
|
|
|
#ifndef EINK_NUMBUFFERS
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_NUMBUFFERS 40
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Do a "blinking" clear, i.e. clear to opposite polarity first.
|
|
|
|
* This reduces the image persistence. */
|
|
|
|
#ifndef EINK_BLINKCLEAR
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_BLINKCLEAR TRUE
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number of passes to use when clearing the display */
|
|
|
|
#ifndef EINK_CLEARCOUNT
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_CLEARCOUNT 10
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number of passes to use when writing to the display */
|
|
|
|
#ifndef EINK_WRITECOUNT
|
2013-10-22 15:34:56 +00:00
|
|
|
#define EINK_WRITECOUNT 4
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#define PRIV(g) ((drvPriv *)g->priv)
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/** Delay between signal changes, to give time for IO pins to change state. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static inline void clockdelay(void)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
#if EINK_CLOCKDELAY & 1
|
|
|
|
asm("nop");
|
|
|
|
#endif
|
|
|
|
#if EINK_CLOCKDELAY & 2
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
#endif
|
|
|
|
#if EINK_CLOCKDELAY & 4
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
#endif
|
|
|
|
#if EINK_CLOCKDELAY & 8
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
asm("nop");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Fast vertical clock pulse for gate driver, used during initializations */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void vclock_quick(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(1);
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Horizontal clock pulse for clocking data into source driver */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void hclock(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
clockdelay();
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_cl(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
clockdelay();
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_cl(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Start a new vertical gate driver scan from top.
|
|
|
|
* Note: Does not clear any previous bits in the shift register,
|
|
|
|
* so you should always scan through the whole display before
|
|
|
|
* starting a new scan.
|
|
|
|
*/
|
2013-10-22 15:34:56 +00:00
|
|
|
static void vscan_start(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_gmode(g, TRUE);
|
|
|
|
vclock_quick(g);
|
|
|
|
setpin_spv(g, FALSE);
|
|
|
|
vclock_quick(g);
|
|
|
|
setpin_spv(g, TRUE);
|
|
|
|
vclock_quick(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Waveform for strobing a row of data onto the display.
|
|
|
|
* Attempts to minimize the leaking of color to other rows by having
|
|
|
|
* a long idle period after a medium-length strobe period.
|
|
|
|
*/
|
2013-10-22 15:34:56 +00:00
|
|
|
static void vscan_write(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, TRUE);
|
|
|
|
setpin_oe(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(5);
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_oe(g, FALSE);
|
|
|
|
setpin_ckv(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Waveform used when clearing the display. Strobes a row of data to the
|
|
|
|
* screen, but does not mind some of it leaking to other rows.
|
|
|
|
*/
|
2013-10-22 15:34:56 +00:00
|
|
|
static void vscan_bulkwrite(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(20);
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Waveform for skipping a vertical row without writing anything.
|
|
|
|
* Attempts to minimize the amount of change in any row.
|
|
|
|
*/
|
2013-10-22 15:34:56 +00:00
|
|
|
static void vscan_skip(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(1);
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_ckv(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
eink_delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Stop the vertical scan. The significance of this escapes me, but it seems
|
|
|
|
* necessary or the next vertical scan may be corrupted.
|
|
|
|
*/
|
2013-10-22 15:34:56 +00:00
|
|
|
static void vscan_stop(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_gmode(g, FALSE);
|
|
|
|
vclock_quick(g);
|
|
|
|
vclock_quick(g);
|
|
|
|
vclock_quick(g);
|
|
|
|
vclock_quick(g);
|
|
|
|
vclock_quick(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Start updating the source driver data (from left to right). */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void hscan_start(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
/* Disable latching and output enable while we are modifying the row. */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_le(g, FALSE);
|
|
|
|
setpin_oe(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* The start pulse should remain low for the duration of the row. */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_sph(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Write data to the horizontal row. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void hscan_write(GDisplay *g, const uint8_t *data, int count)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
/* Set the next byte on the data pins */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpins_data(g, *data++);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Give a clock pulse to the shift register */
|
2013-10-22 15:34:56 +00:00
|
|
|
hclock(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Finish and transfer the row to the source drivers.
|
|
|
|
* Does not set the output enable, so the drivers are not yet active. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void hscan_stop(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
/* End the scan */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_sph(g, TRUE);
|
|
|
|
hclock(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Latch the new data */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_le(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
clockdelay();
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_le(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn on the power to the E-Ink panel, observing proper power sequencing. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void power_on(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* First the digital power supply and signal levels. */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpower_vdd(g, TRUE);
|
|
|
|
setpin_le(g, FALSE);
|
|
|
|
setpin_oe(g, FALSE);
|
|
|
|
setpin_cl(g, FALSE);
|
|
|
|
setpin_sph(g, TRUE);
|
|
|
|
setpins_data(g, 0);
|
|
|
|
setpin_ckv(g, FALSE);
|
|
|
|
setpin_gmode(g, FALSE);
|
|
|
|
setpin_spv(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Min. 100 microsecond delay after digital supply */
|
|
|
|
gfxSleepMicroseconds(100);
|
|
|
|
|
|
|
|
/* Then negative voltages and min. 1000 microsecond delay. */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpower_vneg(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
gfxSleepMicroseconds(1000);
|
|
|
|
|
|
|
|
/* Finally the positive voltages. */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpower_vpos(g, TRUE);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Clear the vscan shift register */
|
2013-10-22 15:34:56 +00:00
|
|
|
vscan_start(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
for (i = 0; i < GDISP_SCREEN_HEIGHT; i++)
|
2013-10-22 15:34:56 +00:00
|
|
|
vclock_quick(g);
|
|
|
|
vscan_stop(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn off the power, observing proper power sequencing. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void power_off(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
/* First the high voltages */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpower_vpos(g, FALSE);
|
|
|
|
setpower_vneg(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Wait for any capacitors to drain */
|
|
|
|
gfxSleepMilliseconds(100);
|
|
|
|
|
|
|
|
/* Then put all signals and digital supply to ground. */
|
2013-10-22 15:34:56 +00:00
|
|
|
setpin_le(g, FALSE);
|
|
|
|
setpin_oe(g, FALSE);
|
|
|
|
setpin_cl(g, FALSE);
|
|
|
|
setpin_sph(g, FALSE);
|
|
|
|
setpins_data(g, 0);
|
|
|
|
setpin_ckv(g, FALSE);
|
|
|
|
setpin_gmode(g, FALSE);
|
|
|
|
setpin_spv(g, FALSE);
|
|
|
|
setpower_vdd(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ====================================
|
|
|
|
* Framebuffer emulation layer
|
|
|
|
* ==================================== */
|
|
|
|
|
|
|
|
#if EINK_PPB == 4
|
2013-10-22 15:34:56 +00:00
|
|
|
#define PIXELMASK 3
|
|
|
|
#define PIXEL_WHITE 2
|
|
|
|
#define PIXEL_BLACK 1
|
|
|
|
#define BYTE_WHITE 0xAA
|
|
|
|
#define BYTE_BLACK 0x55
|
2013-09-24 19:15:55 +00:00
|
|
|
#else
|
2013-10-22 15:34:56 +00:00
|
|
|
#error Unsupported EINK_PPB value.
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GDISP_SCREEN_HEIGHT % EINK_BLOCKHEIGHT != 0
|
2013-10-22 15:34:56 +00:00
|
|
|
#error GDISP_SCREEN_HEIGHT must be evenly divisible by EINK_BLOCKHEIGHT
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GDISP_SCREEN_WIDTH % EINK_BLOCKWIDTH != 0
|
2013-10-22 15:34:56 +00:00
|
|
|
#error GDISP_SCREEN_WIDTH must be evenly divisible by EINK_BLOCKWIDTH
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if EINK_BLOCKWIDTH % EINK_PPB != 0
|
2013-10-22 15:34:56 +00:00
|
|
|
#error EINK_BLOCKWIDTH must be evenly divisible by EINK_PPB
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if EINK_NUMBUFFERS > 254
|
2013-10-22 15:34:56 +00:00
|
|
|
#error EINK_NUMBUFFERS must be at most 254.
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#define BLOCKS_Y (GDISP_SCREEN_HEIGHT / EINK_BLOCKHEIGHT)
|
|
|
|
#define BLOCKS_X (GDISP_SCREEN_WIDTH / EINK_BLOCKWIDTH)
|
|
|
|
#define WIDTH_BYTES (EINK_BLOCKWIDTH / EINK_PPB)
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Buffers that store the data for a small area of the display. */
|
|
|
|
typedef struct {
|
|
|
|
uint8_t data[EINK_BLOCKHEIGHT][WIDTH_BYTES];
|
|
|
|
} block_t;
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
typedef struct drvPriv {
|
|
|
|
uint8_t g_next_block; /* Index of the next free block buffer. */
|
|
|
|
block_t g_blocks[EINK_NUMBUFFERS];
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
/* Map that stores the buffers associated to each area of the display.
|
|
|
|
* Value of 0 means that the block is not allocated.
|
|
|
|
* Other values are the index in g_blocks + 1.
|
|
|
|
*/
|
|
|
|
uint8_t g_blockmap[BLOCKS_Y][BLOCKS_X];
|
|
|
|
} drvPriv;
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/** Check if the row contains any allocated blocks. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static bool_t blocks_on_row(GDisplay *g, unsigned by)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
unsigned bx;
|
|
|
|
for (bx = 0; bx < BLOCKS_X; bx++)
|
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
if (PRIV(g)->g_blockmap[by][bx] != 0)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Write out a block row. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void write_block_row(GDisplay *g, unsigned by)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
unsigned bx, dy, dx;
|
|
|
|
for (dy = 0; dy < EINK_BLOCKHEIGHT; dy++)
|
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
hscan_start(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
for (bx = 0; bx < BLOCKS_X; bx++)
|
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
if (PRIV(g)->g_blockmap[by][bx] == 0)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
for (dx = 0; dx < WIDTH_BYTES; dx++)
|
|
|
|
{
|
|
|
|
const uint8_t dummy = 0;
|
2013-10-22 15:34:56 +00:00
|
|
|
hscan_write(g, &dummy, 1);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
block_t *block = &PRIV(g)->g_blocks[PRIV(g)->g_blockmap[by][bx] - 1];
|
|
|
|
hscan_write(g, &block->data[dy][0], WIDTH_BYTES);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-22 15:34:56 +00:00
|
|
|
hscan_stop(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
vscan_write(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Clear the block map, i.e. deallocate all blocks */
|
2013-10-22 15:34:56 +00:00
|
|
|
static void clear_block_map(GDisplay *g)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
unsigned bx, by;
|
|
|
|
for (by = 0; by < BLOCKS_Y; by++)
|
|
|
|
{
|
|
|
|
for (bx = 0; bx < BLOCKS_X; bx++)
|
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
PRIV(g)->g_blockmap[by][bx] = 0;
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
PRIV(g)->g_next_block = 0;
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize a newly allocated block. */
|
|
|
|
static void zero_block(block_t *block)
|
|
|
|
{
|
|
|
|
unsigned dx, dy;
|
|
|
|
for (dy = 0; dy < EINK_BLOCKHEIGHT; dy++)
|
|
|
|
{
|
|
|
|
for (dx = 0; dx < WIDTH_BYTES; dx++)
|
|
|
|
{
|
|
|
|
block->data[dy][dx] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Allocate a buffer
|
|
|
|
* Automatically flushes if all buffers are full. */
|
2013-10-22 15:34:56 +00:00
|
|
|
static block_t *alloc_buffer(GDisplay *g, unsigned bx, unsigned by)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
|
|
|
block_t *result;
|
2013-10-22 15:34:56 +00:00
|
|
|
drvPriv *priv;
|
|
|
|
|
|
|
|
priv = PRIV(g);
|
|
|
|
if (priv->g_blockmap[by][bx] == 0)
|
2013-09-24 19:15:55 +00:00
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
if (priv->g_next_block >= EINK_NUMBUFFERS)
|
|
|
|
gdisp_lld_flush(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
result = &priv->g_blocks[priv->g_next_block];
|
|
|
|
priv->g_blockmap[by][bx] = priv->g_next_block + 1;
|
|
|
|
priv->g_next_block++;
|
2013-09-24 19:15:55 +00:00
|
|
|
zero_block(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-22 15:34:56 +00:00
|
|
|
result = &priv->g_blocks[priv->g_blockmap[by][bx] - 1];
|
2013-09-24 19:15:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
|
|
|
g->priv = gfxAlloc(sizeof(drvPriv));
|
|
|
|
|
|
|
|
init_board(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* Make sure that all the pins are in "off" state.
|
|
|
|
* Having any pin high could cause voltage leaking to the
|
|
|
|
* display, which in turn causes the image to leak slowly away.
|
|
|
|
*/
|
2013-10-22 15:34:56 +00:00
|
|
|
power_off(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
clear_block_map(g);
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
/* Initialise the GDISP structure */
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Orientation = GDISP_ROTATE_0;
|
|
|
|
g->g.Powermode = powerOn;
|
|
|
|
g->g.Backlight = 100;
|
|
|
|
g->g.Contrast = 100;
|
2013-09-24 19:15:55 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#if GDISP_HARDWARE_FLUSH
|
|
|
|
LLDSPEC void gdisp_lld_flush(GDisplay *g) {
|
|
|
|
unsigned by, dy, i;
|
|
|
|
|
|
|
|
for (i = 0; i < EINK_WRITECOUNT; i++) {
|
|
|
|
vscan_start(g);
|
|
|
|
|
|
|
|
for (by = 0; by < BLOCKS_Y; by++) {
|
|
|
|
if (!blocks_on_row(g, by)) {
|
|
|
|
/* Skip the whole row of blocks. */
|
|
|
|
for (dy = 0; dy < EINK_BLOCKHEIGHT; dy++)
|
|
|
|
vscan_skip(g);
|
|
|
|
} else {
|
|
|
|
/* Write out the blocks. */
|
|
|
|
write_block_row(g, by);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vscan_stop(g);
|
|
|
|
}
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
clear_block_map(g);
|
|
|
|
}
|
2013-09-24 19:15:55 +00:00
|
|
|
#endif
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#if GDISP_HARDWARE_DRAWPIXEL
|
|
|
|
void gdisp_lld_draw_pixel(GDisplay *g) {
|
|
|
|
block_t *block;
|
|
|
|
uint8_t byte;
|
|
|
|
unsigned bx, by, dx, dy;
|
|
|
|
uint8_t bitpos;
|
|
|
|
|
|
|
|
switch(g->g.Orientation) {
|
2013-11-17 13:32:19 +00:00
|
|
|
default:
|
2013-10-22 15:34:56 +00:00
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
bx = g->p.x / EINK_BLOCKWIDTH;
|
|
|
|
dx = g->p.x % EINK_BLOCKWIDTH;
|
|
|
|
by = g->p.y / EINK_BLOCKHEIGHT;
|
|
|
|
dy = g->p.y % EINK_BLOCKHEIGHT;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
bx = g->p.y / EINK_BLOCKWIDTH;
|
|
|
|
dx = g->p.y % EINK_BLOCKWIDTH;
|
|
|
|
by = (GDISP_SCREEN_HEIGHT-1 - g->p.x) / EINK_BLOCKHEIGHT;
|
|
|
|
dy = (GDISP_SCREEN_HEIGHT-1 - g->p.x) % EINK_BLOCKHEIGHT;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
bx = (GDISP_SCREEN_WIDTH-1 - g->p.x) / EINK_BLOCKWIDTH;
|
|
|
|
dx = (GDISP_SCREEN_WIDTH-1 - g->p.x) % EINK_BLOCKWIDTH;
|
|
|
|
by = (GDISP_SCREEN_HEIGHT-1 - g->p.y) / EINK_BLOCKHEIGHT;
|
|
|
|
dy = (GDISP_SCREEN_HEIGHT-1 - g->p.y) % EINK_BLOCKHEIGHT;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_270:
|
|
|
|
bx = (GDISP_SCREEN_WIDTH-1 - g->p.y) / EINK_BLOCKWIDTH;
|
|
|
|
dx = (GDISP_SCREEN_WIDTH-1 - g->p.y) % EINK_BLOCKWIDTH;
|
|
|
|
by = g->p.x / EINK_BLOCKHEIGHT;
|
|
|
|
dy = g->p.x % EINK_BLOCKHEIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
block = alloc_buffer(g, bx, by);
|
|
|
|
|
|
|
|
bitpos = (6 - 2 * (dx % EINK_PPB));
|
|
|
|
byte = block->data[dy][dx / EINK_PPB];
|
|
|
|
byte &= ~(PIXELMASK << bitpos);
|
2013-11-17 13:32:19 +00:00
|
|
|
if (gdispColor2Native(g->p.color) != Black)
|
2013-10-22 15:34:56 +00:00
|
|
|
byte |= PIXEL_WHITE << bitpos;
|
|
|
|
else
|
|
|
|
byte |= PIXEL_BLACK << bitpos;
|
|
|
|
block->data[dy][dx / EINK_PPB] = byte;
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay *g) {
|
|
|
|
switch(g->p.x) {
|
2013-09-24 19:15:55 +00:00
|
|
|
case GDISP_CONTROL_POWER:
|
2013-10-22 15:34:56 +00:00
|
|
|
if (g->g.Powermode == (powermode_t)g->p.ptr)
|
|
|
|
return;
|
|
|
|
switch((powermode_t)g->p.ptr) {
|
|
|
|
case powerOff:
|
|
|
|
case powerSleep:
|
|
|
|
case powerDeepSleep:
|
|
|
|
gdisp_lld_flush(g);
|
|
|
|
power_off(g);
|
|
|
|
break;
|
|
|
|
case powerOn:
|
|
|
|
power_on(g);
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-24 19:15:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-22 15:34:56 +00:00
|
|
|
g->g.Powermode = (powermode_t)g->p.ptr;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
|
|
|
if (g->g.Orientation == (orientation_t)g->p.ptr)
|
|
|
|
return;
|
|
|
|
switch((orientation_t)g->p.ptr) {
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
case GDISP_ROTATE_270:
|
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
2013-10-22 15:34:56 +00:00
|
|
|
g->g.Orientation = (orientation_t)g->p.ptr;
|
|
|
|
return;
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
2013-10-22 15:34:56 +00:00
|
|
|
#endif
|
2013-09-24 19:15:55 +00:00
|
|
|
|
|
|
|
/* ===============================
|
|
|
|
* Accelerated routines
|
|
|
|
* =============================== */
|
|
|
|
|
|
|
|
#if GDISP_HARDWARE_CLEARS
|
2013-10-22 15:34:56 +00:00
|
|
|
static void subclear(GDisplay *g, color_t color) {
|
|
|
|
unsigned x, y;
|
|
|
|
uint8_t byte;
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
hscan_start(g);
|
|
|
|
byte = color ? BYTE_WHITE : BYTE_BLACK;
|
|
|
|
for (x = 0; x < GDISP_SCREEN_WIDTH; x++)
|
|
|
|
{
|
|
|
|
hscan_write(g, &byte, 1);
|
|
|
|
}
|
|
|
|
hscan_stop(g);
|
|
|
|
|
|
|
|
setpin_oe(g, TRUE);
|
|
|
|
vscan_start(g);
|
|
|
|
for (y = 0; y < GDISP_SCREEN_HEIGHT; y++)
|
|
|
|
vscan_bulkwrite(g);
|
|
|
|
vscan_stop(g);
|
|
|
|
setpin_oe(g, FALSE);
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
void gdisp_lld_clear(GDisplay *g) {
|
|
|
|
unsigned i;
|
2013-09-24 19:15:55 +00:00
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
clear_block_map(g);
|
|
|
|
|
|
|
|
if (EINK_BLINKCLEAR) {
|
|
|
|
subclear(g, !g->p.color);
|
|
|
|
gfxSleepMilliseconds(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < EINK_CLEARCOUNT; i++) {
|
|
|
|
subclear(g, g->p.color);
|
|
|
|
gfxSleepMilliseconds(10);
|
|
|
|
}
|
2013-09-24 19:15:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-22 15:34:56 +00:00
|
|
|
#endif // GFX_USE_GDISP
|