2013-05-01 23:53:28 +00:00
|
|
|
/*
|
2013-06-15 11:37:22 +00:00
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
2013-05-03 14:36:17 +00:00
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/license.html
|
2013-05-03 14:36:17 +00:00
|
|
|
*/
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file drivers/gdisp/Nokia6610GE12/gdisp_lld.c
|
|
|
|
* @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 GE12 display.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gfx.h"
|
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
#if GFX_USE_GDISP
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
#if defined(GDISP_SCREEN_HEIGHT)
|
|
|
|
#warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
|
|
|
|
#undef GDISP_SCREEN_HEIGHT
|
|
|
|
#endif
|
|
|
|
#if defined(GDISP_SCREEN_WIDTH)
|
|
|
|
#warning "GDISP: This low level driver does not support setting a screen size. It is being ignored."
|
|
|
|
#undef GDISP_SCREEN_WIDTH
|
|
|
|
#endif
|
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_Nokia6610GE12
|
2014-02-18 14:36:52 +00:00
|
|
|
#include "drivers/gdisp/Nokia6610GE12/gdisp_lld_config.h"
|
|
|
|
#include "src/gdisp/driver.h"
|
2013-10-19 05:38:00 +00:00
|
|
|
|
|
|
|
#include "board_Nokia6610GE12.h"
|
2013-10-01 11:11:42 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2014-02-18 14:36:52 +00:00
|
|
|
#include "drivers/gdisp/Nokia6610GE12/GE12.h"
|
2013-10-01 11:11:42 +00:00
|
|
|
|
|
|
|
#define GDISP_SCAN_LINES 132
|
|
|
|
#define GDISP_SLEEP_SIZE 32 /* Sleep mode window lines - this must be 32 on this controller */
|
|
|
|
|
|
|
|
// Set parameters if they are not already set
|
|
|
|
#ifndef GDISP_SCREEN_HEIGHT
|
|
|
|
#define GDISP_SCREEN_HEIGHT 130
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_SCREEN_WIDTH
|
|
|
|
#define GDISP_SCREEN_WIDTH 130
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_RAM_X_OFFSET
|
|
|
|
#define GDISP_RAM_X_OFFSET 0 /* Offset in RAM of visible area */
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_RAM_Y_OFFSET
|
|
|
|
#define GDISP_RAM_Y_OFFSET 2 /* Offset in RAM of visible area */
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_SLEEP_POS
|
|
|
|
#define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2 & ~3)
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_CONTRAST
|
|
|
|
#define GDISP_INITIAL_CONTRAST 50
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_BACKLIGHT
|
|
|
|
#define GDISP_INITIAL_BACKLIGHT 100
|
|
|
|
#endif
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-10-21 05:13:10 +00:00
|
|
|
// Use the priv pointer itself to save our color. This save allocating ram for it
|
2013-11-05 09:34:12 +00:00
|
|
|
// and works provided sizeof(uint16_t) <= sizeof(void *)
|
|
|
|
#define savecolor(g) (*(uint16_t *)&g->priv)
|
2013-10-01 11:11:42 +00:00
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
#define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0)
|
2013-10-01 11:11:42 +00:00
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
// Some macros just to make reading the code easier
|
2013-10-19 05:38:00 +00:00
|
|
|
#define delayms(ms) gfxSleepMilliseconds(ms)
|
|
|
|
#define write_data2(g, d1, d2) { write_data(g, d1); write_data(g, d2); }
|
|
|
|
#define write_data3(g, d1, d2, d3) { write_data(g, d1); write_data(g, d2); write_data(g, d3); }
|
|
|
|
#define write_reg(g, cmd, d1) { write_index(g, cmd); write_data(g, d1); }
|
|
|
|
#define write_reg2(g, cmd, d1, d2) { write_index(g, cmd); write_data2(g, d1, d2); }
|
|
|
|
#define write_reg3(g, cmd, d1, d2, d3) { write_index(g, cmd); write_data3(g, d1, d2, d3); }
|
|
|
|
|
|
|
|
static inline void set_viewport(GDisplay* g) {
|
|
|
|
write_reg2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x+g->p.cx-1); // Column address set
|
|
|
|
write_reg2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y+g->p.cy-1); // Page address set
|
|
|
|
write_index(g, RAMWR);
|
|
|
|
}
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
2013-10-21 05:13:10 +00:00
|
|
|
// No private area for this controller
|
|
|
|
g->priv = 0;
|
|
|
|
|
|
|
|
// Initialise the board interface
|
2013-10-19 05:38:00 +00:00
|
|
|
init_board(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
// Hardware reset
|
2013-10-19 05:38:00 +00:00
|
|
|
setpin_reset(g, TRUE);
|
2013-02-18 07:29:08 +00:00
|
|
|
delayms(20);
|
2013-10-19 05:38:00 +00:00
|
|
|
setpin_reset(g, FALSE);
|
2013-02-18 07:29:08 +00:00
|
|
|
delayms(20);
|
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
2013-10-19 06:33:13 +00:00
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
write_index(g, SLEEPOUT); // Sleep out
|
|
|
|
write_reg(g, COLMOD, 0x03); // Color Interface Pixel Format - 0x03 = 12 bits-per-pixel
|
|
|
|
write_reg(g, MADCTL, 0x00); // Memory access controller
|
2013-10-21 07:11:46 +00:00
|
|
|
write_reg(g, SETCON, 128*GDISP_INITIAL_CONTRAST/101-64); // Write contrast
|
2013-10-01 11:11:42 +00:00
|
|
|
delayms(20);
|
2013-10-19 06:33:13 +00:00
|
|
|
|
|
|
|
// Finish Init
|
|
|
|
post_init_board(g);
|
|
|
|
|
2013-10-19 05:38:00 +00:00
|
|
|
release_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/* Turn on the back-light */
|
2013-10-19 05:38:00 +00:00
|
|
|
set_backlight(g, GDISP_INITIAL_BACKLIGHT);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/* Initialise the GDISP structure to match */
|
2013-10-01 11:11:42 +00:00
|
|
|
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 = GDISP_INITIAL_BACKLIGHT;
|
|
|
|
g->g.Contrast = GDISP_INITIAL_CONTRAST;
|
2013-02-18 07:29:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-10-01 11:11:42 +00:00
|
|
|
#if GDISP_HARDWARE_STREAM_WRITE
|
2013-10-19 05:38:00 +00:00
|
|
|
LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
|
|
|
|
acquire_bus(g);
|
|
|
|
set_viewport(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->flags &= ~GDISP_FLG_ODDBYTE;
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-10-19 05:38:00 +00:00
|
|
|
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
|
2013-11-05 09:34:12 +00:00
|
|
|
uint16_t c;
|
|
|
|
|
2013-11-17 13:32:19 +00:00
|
|
|
c = gdispColor2Native(g->p.color);
|
2013-10-01 11:11:42 +00:00
|
|
|
if ((g->flags & GDISP_FLG_ODDBYTE)) {
|
|
|
|
// Write the pair of pixels to the display
|
2013-10-21 05:13:10 +00:00
|
|
|
write_data3(g, ((savecolor(g) >> 4) & 0xFF),
|
2013-11-05 09:34:12 +00:00
|
|
|
(((savecolor(g) << 4) & 0xF0)|((c >> 8) & 0x0F)),
|
|
|
|
(c & 0xFF));
|
2013-10-01 11:11:42 +00:00
|
|
|
g->flags &= ~GDISP_FLG_ODDBYTE;
|
|
|
|
} else {
|
2013-11-05 09:34:12 +00:00
|
|
|
savecolor(g) = c;
|
2013-10-01 11:11:42 +00:00
|
|
|
g->flags |= GDISP_FLG_ODDBYTE;
|
|
|
|
}
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-10-19 05:38:00 +00:00
|
|
|
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
|
2013-10-01 11:11:42 +00:00
|
|
|
if ((g->flags & GDISP_FLG_ODDBYTE)) {
|
2013-10-21 05:13:10 +00:00
|
|
|
write_data2(g, ((savecolor(g) >> 4) & 0xFF), ((savecolor(g) << 4) & 0xF0));
|
2013-10-19 05:38:00 +00:00
|
|
|
write_index(g, NOP);
|
2013-10-01 11:11:42 +00:00
|
|
|
}
|
2013-10-19 05:38:00 +00:00
|
|
|
release_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-01 11:11:42 +00:00
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
2013-10-19 05:38:00 +00:00
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay *g) {
|
2013-02-18 07:29:08 +00:00
|
|
|
/* The hardware is capable of supporting...
|
2013-10-01 11:11:42 +00:00
|
|
|
* GDISP_CONTROL_POWER - supported
|
|
|
|
* GDISP_CONTROL_ORIENTATION - supported
|
|
|
|
* GDISP_CONTROL_BACKLIGHT - supported
|
2013-02-18 07:29:08 +00:00
|
|
|
* GDISP_CONTROL_CONTRAST - supported
|
|
|
|
*/
|
2013-10-01 11:11:42 +00:00
|
|
|
switch(g->p.x) {
|
2013-02-18 07:29:08 +00:00
|
|
|
case GDISP_CONTROL_POWER:
|
2013-10-01 11:11:42 +00:00
|
|
|
if (g->g.Powermode == (powermode_t)g->p.ptr)
|
|
|
|
return;
|
|
|
|
switch((powermode_t)g->p.ptr) {
|
|
|
|
case powerOff:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_index(g, SLEEPIN);
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
break;
|
|
|
|
case powerOn:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_index(g, SLEEPOUT);
|
2013-10-01 11:11:42 +00:00
|
|
|
delayms(20);
|
2013-10-19 05:38:00 +00:00
|
|
|
write_index(g, NORON); // Set Normal mode (my)
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
break;
|
|
|
|
case powerSleep:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_index(g, SLEEPOUT);
|
2013-10-01 11:11:42 +00:00
|
|
|
delayms(20);
|
2013-10-19 05:38:00 +00:00
|
|
|
write_reg2(g, PTLAR, GDISP_SLEEP_POS, GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)
|
|
|
|
write_index(g, PTLON);
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Powermode = (powermode_t)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
2013-10-01 11:11:42 +00:00
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
2013-10-01 11:11:42 +00:00
|
|
|
if (g->g.Orientation == (orientation_t)g->p.ptr)
|
|
|
|
return;
|
|
|
|
switch((orientation_t)g->p.ptr) {
|
|
|
|
case GDISP_ROTATE_0:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_reg(g, MADCTL, 0x00);
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_90:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_reg(g, MADCTL, 0xA0); // MY, MX, V, LAO, RGB, X, X, X
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_180:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_reg(g, MADCTL, 0xC0);
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_270:
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
write_reg(g, MADCTL, 0x60);
|
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Orientation = (orientation_t)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
2013-10-01 11:11:42 +00:00
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
case GDISP_CONTROL_BACKLIGHT:
|
2013-10-01 11:11:42 +00:00
|
|
|
if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
|
2013-10-19 05:38:00 +00:00
|
|
|
set_backlight(g, (unsigned)g->p.ptr);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Backlight = (unsigned)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
case GDISP_CONTROL_CONTRAST:
|
2013-10-01 11:11:42 +00:00
|
|
|
if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
|
2013-10-19 05:38:00 +00:00
|
|
|
acquire_bus(g);
|
2013-10-26 12:59:52 +00:00
|
|
|
write_reg(g, SETCON,(unsigned)128*(unsigned)g->p.ptr/101-64);
|
2013-10-19 05:38:00 +00:00
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Contrast = (unsigned)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GFX_USE_GDISP */
|