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/Nokia6610GE8/gdisp_lld.c
|
|
|
|
* @brief GDISP Graphics Driver subsystem low level driver source for the Nokia6610 GE8 display.
|
|
|
|
*
|
|
|
|
* @addtogroup GDISP
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gfx.h"
|
|
|
|
|
2013-09-25 07:18:18 +00:00
|
|
|
#if GFX_USE_GDISP
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-09-25 07:18:18 +00:00
|
|
|
/**
|
|
|
|
* This is for the EPSON (GE8) controller driving a Nokia6610 color LCD display.
|
|
|
|
* Note that there is also a PHILIPS (GE12) controller for the same display that this code
|
|
|
|
* does not support.
|
|
|
|
*
|
|
|
|
* The controller drives a 132x132 display but a 1 pixel surround is not visible
|
|
|
|
* which gives a visible area of 130x130.
|
|
|
|
*
|
|
|
|
* This controller does not support reading back over the SPI interface.
|
|
|
|
* Additionally, the Olimex board doesn't even connect the pin.
|
|
|
|
*
|
|
|
|
* The hardware is capable of doing full width vertical scrolls aligned
|
|
|
|
* on a 4 line boundary however that is not sufficient to support general vertical scrolling.
|
|
|
|
* We also can't manually do read/modify scrolling because we can't read in SPI mode.
|
|
|
|
*
|
|
|
|
* The controller has some quirkyness when operating in other than rotation 0 mode.
|
|
|
|
* When any direction is decremented it starts at location 0 rather than the end of
|
2013-09-26 15:38:37 +00:00
|
|
|
* the area. Whilst this can be handled when we know the specific operation (pixel, fill, blit)
|
|
|
|
* it cannot be handled in a generic stream operation. So, when orientation support is turned
|
|
|
|
* on (and needed) we use complex operation specific routines instead of simple streaming
|
|
|
|
* routines. This has a (small) performance penalty and a significant code size penalty so
|
|
|
|
* don't turn on orientation support unless you really need it.
|
2013-09-25 07:18:18 +00:00
|
|
|
*
|
|
|
|
* Some of the more modern controllers have a broken command set. If you have one of these
|
|
|
|
* you will recognise it by the colors being off on anything drawn after an odd (as opposed to
|
|
|
|
* even) pixel count area being drawn. If so then set GDISP_GE8_BROKEN_CONTROLLER to TRUE
|
2013-09-26 15:38:37 +00:00
|
|
|
* on your gdisp_lld_board.h file. The price is that streaming calls that are completed
|
|
|
|
* without exactly the window size write operations and where the number of write operations
|
|
|
|
* is odd (rather than even), it will draw an extra pixel. If this is important to you, turn on
|
|
|
|
* orientation support and the streaming operations will be emulated (as described above).
|
2013-09-25 07:18:18 +00:00
|
|
|
*/
|
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-03-07 14:53:34 +00:00
|
|
|
|
2013-10-19 06:33:56 +00:00
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_Nokia6610GE8
|
2014-02-18 14:36:52 +00:00
|
|
|
#include "drivers/gdisp/Nokia6610GE8/gdisp_lld_config.h"
|
|
|
|
#include "src/gdisp/driver.h"
|
2013-10-19 06:33:56 +00:00
|
|
|
|
|
|
|
#include "board_Nokia6610GE8.h"
|
2013-09-30 07:04:13 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2014-02-18 14:36:52 +00:00
|
|
|
#include "drivers/gdisp/Nokia6610GE8/GE8.h"
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-09-25 07:18:18 +00:00
|
|
|
#define GDISP_SCAN_LINES 132
|
|
|
|
|
|
|
|
// Set parameters if they are not already set
|
|
|
|
#ifndef GDISP_GE8_BROKEN_CONTROLLER
|
|
|
|
#define GDISP_GE8_BROKEN_CONTROLLER TRUE
|
|
|
|
#endif
|
|
|
|
#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_SIZE
|
|
|
|
#define GDISP_SLEEP_SIZE 32 /* Sleep mode window lines */
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_SLEEP_POS
|
|
|
|
#define GDISP_SLEEP_POS ((GDISP_SCAN_LINES-GDISP_SLEEP_SIZE)/2)
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_CONTRAST
|
2013-10-01 14:56:57 +00:00
|
|
|
#define GDISP_INITIAL_CONTRAST 60
|
2013-09-25 07:18:18 +00:00
|
|
|
#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-09-29 14:05:07 +00:00
|
|
|
#if GDISP_HARDWARE_STREAM_WRITE
|
2013-10-21 05:13:10 +00:00
|
|
|
typedef struct dvrPriv {
|
2013-11-05 09:34:12 +00:00
|
|
|
uint16_t savecolor;
|
2013-10-21 05:13:10 +00:00
|
|
|
#if GDISP_GE8_BROKEN_CONTROLLER
|
2013-11-05 09:34:12 +00:00
|
|
|
uint16_t firstcolor;
|
2013-10-21 05:13:10 +00:00
|
|
|
#endif
|
|
|
|
} dvrPriv;
|
|
|
|
#define PRIV ((dvrPriv *)g->priv)
|
2013-09-25 07:18:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0)
|
|
|
|
#define GDISP_FLG_RUNBYTE (GDISP_FLG_DRIVER<<1)
|
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
// Some macros just to make reading the code easier
|
2013-10-19 06:33:56 +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_data4(g, d1, d2, d3, d4) { write_data(g, d1); write_data(g, d2); write_data(g, d3); write_data(g, d4); }
|
|
|
|
#define write_cmd1(g, cmd, d1) { write_index(g, cmd); write_data(g, d1); }
|
|
|
|
#define write_cmd2(g, cmd, d1, d2) { write_index(g, cmd); write_data2(g, d1, d2); }
|
|
|
|
#define write_cmd3(g, cmd, d1, d2, d3) { write_index(g, cmd); write_data3(g, d1, d2, d3); }
|
|
|
|
#define write_cmd4(g, cmd, d1, d2, d3, d4) { write_index(g, cmd); write_data4(g, d1, d2, d3, d4); }
|
|
|
|
|
|
|
|
static inline void set_viewport(GDisplay* g) {
|
|
|
|
#if GDISP_NOKIA_ORIENTATION && GDISP_NEED_CONTROL
|
|
|
|
switch(g->g.Orientation) {
|
2013-11-17 13:32:19 +00:00
|
|
|
default:
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
write_cmd2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x); // Column address set
|
|
|
|
write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y); // Page address set
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
write_cmd2(g, CASET, GDISP_RAM_X_OFFSET+g->p.y, GDISP_RAM_X_OFFSET+g->p.y);
|
|
|
|
write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET-1+g->g.Width-g->p.x, GDISP_RAM_Y_OFFSET-1+g->g.Width-g->p.x);
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
write_cmd2(g, CASET, GDISP_RAM_X_OFFSET-1+g->g.Width-g->p.x, GDISP_RAM_X_OFFSET-1+g->g.Width-g->p.x);
|
|
|
|
write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET-1+g->g.Height-g->p.y, GDISP_RAM_Y_OFFSET-1+g->g.Height-g->p.y);
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_270:
|
|
|
|
write_cmd2(g, CASET, GDISP_RAM_X_OFFSET-1+g->g.Height-g->p.y, GDISP_RAM_X_OFFSET-1+g->g.Height-g->p.y);
|
|
|
|
write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.x, GDISP_RAM_Y_OFFSET+g->p.x);
|
|
|
|
break;
|
2013-10-19 06:33:56 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
write_cmd2(g, CASET, GDISP_RAM_X_OFFSET+g->p.x, GDISP_RAM_X_OFFSET+g->p.x+g->p.cx-1); // Column address set
|
|
|
|
write_cmd2(g, PASET, GDISP_RAM_Y_OFFSET+g->p.y, GDISP_RAM_Y_OFFSET+g->p.y+g->p.cy-1); // Page address set
|
|
|
|
#endif
|
|
|
|
write_index(g, RAMWR);
|
|
|
|
}
|
2013-02-18 07:29:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
2013-10-21 05:13:10 +00:00
|
|
|
#if GDISP_HARDWARE_STREAM_WRITE
|
|
|
|
g->priv = gfxAlloc(sizeof(dvrPriv));
|
|
|
|
#else
|
|
|
|
g->priv = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initialise the board interface
|
2013-10-19 06:33:56 +00:00
|
|
|
init_board(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
// Hardware reset
|
2013-10-19 06:33:56 +00:00
|
|
|
setpin_reset(g, TRUE);
|
2013-02-18 07:29:08 +00:00
|
|
|
delayms(20);
|
2013-10-19 06:33:56 +00:00
|
|
|
setpin_reset(g, FALSE);
|
2013-02-18 07:29:08 +00:00
|
|
|
delayms(20);
|
|
|
|
|
|
|
|
// Get the bus for the following initialisation commands
|
2013-10-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-10-19 06:33:56 +00:00
|
|
|
write_cmd4(g, DISCTL, 0x00, GDISP_SCAN_LINES/4-1, 0x0A, 0x00); // Display control - How the controller drives the LCD
|
2013-02-18 07:29:08 +00:00
|
|
|
// P1: 0x00 = 2 divisions, switching period=8 (default)
|
|
|
|
// P2: 0x20 = nlines/4 - 1 = 132/4 - 1 = 32)
|
2013-03-07 14:53:34 +00:00
|
|
|
// P3: 0x0A = standard inverse highlight, inversion every frame
|
|
|
|
// P4: 0x00 = dispersion on
|
2013-10-19 06:33:56 +00:00
|
|
|
write_cmd1(g, COMSCN, 0x01); // COM scan - How the LCD is connected to the controller
|
2013-03-07 14:53:34 +00:00
|
|
|
// P1: 0x01 = Scan 1->80, 160<-81
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, OSCON); // Internal oscillator ON
|
|
|
|
write_index(g, SLPOUT); // Sleep out
|
|
|
|
write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
|
|
|
|
write_cmd3(g, DATCTL, 0x00, 0x00, 0x02); // Data control
|
2013-03-07 14:53:34 +00:00
|
|
|
// P1: 0x00 = page address normal, column address normal, address scan in column direction
|
2013-02-18 07:29:08 +00:00
|
|
|
// P2: 0x00 = RGB sequence (default value)
|
2013-03-07 14:53:34 +00:00
|
|
|
// P3: 0x02 = 4 bits per colour (Type A)
|
2013-10-21 07:11:46 +00:00
|
|
|
write_cmd2(g, VOLCTR, 64*GDISP_INITIAL_CONTRAST/101, 0x03); // Voltage control (contrast setting)
|
2013-10-01 14:56:57 +00:00
|
|
|
// P1 = Contrast (0..63)
|
2013-02-18 07:29:08 +00:00
|
|
|
// P2 = 3 resistance ratio (only value that works)
|
2013-03-07 14:53:34 +00:00
|
|
|
delayms(100); // Allow power supply to stabilise
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, DISON); // Turn on the display
|
|
|
|
|
|
|
|
// Finish Init
|
|
|
|
post_init_board(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
// Release the bus
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/* Turn on the back-light */
|
2013-10-19 06:33:56 +00:00
|
|
|
set_backlight(g, GDISP_INITIAL_BACKLIGHT);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
/* Initialise the GDISP structure to match */
|
2013-09-25 07:18:18 +00:00
|
|
|
g->g.Orientation = GDISP_ROTATE_0;
|
|
|
|
g->g.Powermode = powerOn;
|
|
|
|
g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
|
|
|
|
g->g.Contrast = GDISP_INITIAL_CONTRAST;
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
2013-02-18 07:29:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-29 14:05:07 +00:00
|
|
|
#if GDISP_HARDWARE_STREAM_WRITE
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
|
|
|
|
acquire_bus(g);
|
|
|
|
set_viewport(g);
|
2013-09-26 15:38:37 +00:00
|
|
|
g->flags &= ~(GDISP_FLG_ODDBYTE|GDISP_FLG_RUNBYTE);
|
|
|
|
}
|
2013-10-19 06:33:56 +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-09-26 15:38:37 +00:00
|
|
|
#if GDISP_GE8_BROKEN_CONTROLLER
|
|
|
|
if (!(g->flags & GDISP_FLG_RUNBYTE)) {
|
2013-11-05 09:34:12 +00:00
|
|
|
PRIV->firstcolor = c;
|
2013-09-26 15:38:37 +00:00
|
|
|
g->flags |= GDISP_FLG_RUNBYTE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
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, ((PRIV->savecolor >> 4) & 0xFF),
|
2013-11-05 09:34:12 +00:00
|
|
|
(((PRIV->savecolor << 4) & 0xF0)|((c >> 8) & 0x0F)),
|
|
|
|
(c & 0xFF));
|
2013-09-26 15:38:37 +00:00
|
|
|
g->flags &= ~GDISP_FLG_ODDBYTE;
|
|
|
|
} else {
|
2013-11-05 09:34:12 +00:00
|
|
|
PRIV->savecolor = c;
|
2013-09-26 15:38:37 +00:00
|
|
|
g->flags |= GDISP_FLG_ODDBYTE;
|
2013-09-25 07:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
|
2013-09-25 07:18:18 +00:00
|
|
|
if ((g->flags & GDISP_FLG_ODDBYTE)) {
|
|
|
|
#if GDISP_GE8_BROKEN_CONTROLLER
|
|
|
|
/**
|
|
|
|
* We have a real problem here - we need to write a singular pixel
|
|
|
|
* Methods that are supposed to work...
|
|
|
|
* 1/ Write the pixel (2 bytes) and then send a NOP command. This doesn't work, the pixel doesn't get written
|
|
|
|
* and it is maintained in the latch where it causes problems for the next window.
|
|
|
|
* 2/ Just write a dummy extra pixel as stuff beyond the window gets discarded. This doesn't work as contrary to
|
|
|
|
* the documentation the buffer wraps and the first pixel gets overwritten.
|
|
|
|
* 3/ Put the controller in 16 bits per pixel Type B mode where each pixel is performed by writing two bytes. This
|
|
|
|
* also doesn't work as the controller refuses to enter Type B mode (it stays in Type A mode).
|
|
|
|
*
|
|
|
|
* These methods might work on some controllers - just not on the one of the broken versions.
|
|
|
|
*
|
|
|
|
* For these broken controllers:
|
|
|
|
* We know we can wrap to the first byte (just overprint it) if we are at the end of the stream area.
|
|
|
|
* If not, we need to create a one pixel by one pixel window to fix this - Uuch. Fortunately this should only happen if the
|
|
|
|
* user application uses the streaming calls and then terminates the stream early or after buffer wrap.
|
|
|
|
* Since this is such an unlikely situation we just don't handle it.
|
|
|
|
*/
|
2013-10-21 05:13:10 +00:00
|
|
|
write_data3(g, ((PRIV->savecolor >> 4) & 0xFF),
|
|
|
|
(((PRIV->savecolor << 4) & 0xF0)|((PRIV->firstcolor >> 8) & 0x0F)),
|
|
|
|
(PRIV->firstcolor & 0xFF));
|
2013-09-25 07:18:18 +00:00
|
|
|
#else
|
2013-10-21 05:13:10 +00:00
|
|
|
write_data2(g, ((PRIV->savecolor >> 4) & 0xFF), ((PRIV->savecolor << 4) & 0xF0));
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, NOP);
|
2013-09-25 07:18:18 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-09-25 07:18:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
#if GDISP_HARDWARE_DRAWPIXEL
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC void gdisp_lld_draw_pixel(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-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
set_viewport(g);
|
2013-11-05 09:34:12 +00:00
|
|
|
write_data3(g, 0, (c>>8) & 0x0F, c & 0xFF);
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-09-25 07:18:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
/* ---- Optional Routines ---- */
|
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
#if GDISP_HARDWARE_FILLS
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
|
2013-11-05 09:34:12 +00:00
|
|
|
unsigned tuples;
|
|
|
|
uint16_t c;
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
tuples = (g->p.cx*g->p.cy+1)>>1; // With an odd sized area we over-print by one pixel.
|
2013-03-07 14:53:34 +00:00
|
|
|
// This extra pixel overwrites the first pixel (harmless as it is the same colour)
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-11-17 13:32:19 +00:00
|
|
|
c = gdispColor2Native(g->p.color);
|
2013-10-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
set_viewport(g);
|
2013-03-07 14:53:34 +00:00
|
|
|
while(tuples--)
|
2013-11-05 09:34:12 +00:00
|
|
|
write_data3(g, ((c >> 4) & 0xFF), (((c << 4) & 0xF0)|((c >> 8) & 0x0F)), (c & 0xFF));
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
#if GDISP_HARDWARE_BITFILLS
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
|
2013-09-26 15:38:37 +00:00
|
|
|
coord_t lg, x, y;
|
2013-11-05 09:34:12 +00:00
|
|
|
uint16_t c1, c2;
|
2013-09-26 15:38:37 +00:00
|
|
|
unsigned tuples;
|
|
|
|
const pixel_t *buffer;
|
2013-02-18 07:29:08 +00:00
|
|
|
#if GDISP_PACKED_PIXELS
|
2013-03-07 14:53:34 +00:00
|
|
|
unsigned pnum, pstart;
|
|
|
|
const uint8_t *p;
|
|
|
|
#else
|
|
|
|
const pixel_t *p;
|
2013-02-18 07:29:08 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
tuples = (g->p.cx * g->p.cy + 1)>>1;
|
|
|
|
buffer = (const pixel_t *)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-03-07 14:53:34 +00:00
|
|
|
/* Set up the data window to transfer */
|
2013-10-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
|
|
|
set_viewport(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-11-05 09:34:12 +00:00
|
|
|
/* to suppress compiler warnings */
|
2013-10-26 12:59:52 +00:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
|
2013-03-07 14:53:34 +00:00
|
|
|
/*
|
|
|
|
* Due to the way the Nokia6610 handles a decrementing column or page,
|
|
|
|
* we have to make adjustments as to where it is actually drawing from in the bitmap.
|
|
|
|
* For example, for 90 degree rotation the column is decremented on each
|
|
|
|
* memory write. The controller always starts with column 0 and then decrements
|
|
|
|
* to column cx-1, cx-2 etc. We therefore have to write-out the last bitmap line first.
|
|
|
|
*/
|
2013-09-26 15:38:37 +00:00
|
|
|
switch(g->g.Orientation) {
|
2013-11-17 13:32:19 +00:00
|
|
|
default:
|
2013-09-26 15:38:37 +00:00
|
|
|
case GDISP_ROTATE_0: x = 0; y = 0; break;
|
|
|
|
case GDISP_ROTATE_90: x = g->p.cx-1; y = 0; break;
|
|
|
|
case GDISP_ROTATE_180: x = g->p.cx-1; y = g->p.cy-1; break;
|
|
|
|
case GDISP_ROTATE_270: x = 0; y = g->p.cy-1; break;
|
2013-03-07 14:53:34 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
#if !GDISP_PACKED_PIXELS
|
|
|
|
// Although this controller uses packed pixels we support unpacked pixel
|
|
|
|
// formats in this blit by packing the data as we feed it to the controller.
|
2013-03-07 14:53:34 +00:00
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
lg = g->p.x2 - g->p.cx; // The buffer gap between lines
|
|
|
|
buffer += g->p.y1 * g->p.x2 + g->p.x1; // The buffer start position
|
|
|
|
p = buffer + g->p.x2*y + x; // Adjustment for controller craziness
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
while(tuples--) {
|
2013-02-18 07:29:08 +00:00
|
|
|
/* Get a pixel */
|
2013-11-17 13:32:19 +00:00
|
|
|
c1 = gdispColor2Native(*p++);
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* Check for line or buffer wrapping */
|
2013-09-26 15:38:37 +00:00
|
|
|
if (++x >= g->p.cx) {
|
2013-03-07 14:53:34 +00:00
|
|
|
x = 0;
|
|
|
|
p += lg;
|
2013-09-26 15:38:37 +00:00
|
|
|
if (++y >= g->p.cy) {
|
2013-03-07 14:53:34 +00:00
|
|
|
y = 0;
|
|
|
|
p = buffer;
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-07 14:53:34 +00:00
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
/* Get the next pixel */
|
2013-11-17 13:32:19 +00:00
|
|
|
c2 = gdispColor2Native(*p++);
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* Check for line or buffer wrapping */
|
2013-09-26 15:38:37 +00:00
|
|
|
if (++x >= g->p.cx) {
|
2013-03-07 14:53:34 +00:00
|
|
|
x = 0;
|
|
|
|
p += lg;
|
2013-09-26 15:38:37 +00:00
|
|
|
if (++y >= g->p.cy) {
|
2013-03-07 14:53:34 +00:00
|
|
|
y = 0;
|
|
|
|
p = buffer;
|
|
|
|
}
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* Write the pair of pixels to the display */
|
2013-10-19 06:33:56 +00:00
|
|
|
write_data3(g, ((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 09:34:12 +00:00
|
|
|
#elif GDISP_PIXELFORMAT == GDISP_LLD_PIXELFORMAT
|
2013-02-18 07:29:08 +00:00
|
|
|
|
|
|
|
// Although this controller uses packed pixels, we may have to feed it into
|
|
|
|
// the controller with different packing to the source bitmap
|
2013-03-07 14:53:34 +00:00
|
|
|
// There are 2 pixels per 3 bytes
|
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
#if !GDISP_PACKED_LINES
|
2013-09-26 15:38:37 +00:00
|
|
|
srccx = (g->p.x2 + 1) & ~1;
|
2013-02-18 07:29:08 +00:00
|
|
|
#endif
|
2013-09-26 15:38:37 +00:00
|
|
|
pstart = g->p.y1 * g->p.x2 + g->p.x1; // The starting pixel number
|
2013-03-07 14:53:34 +00:00
|
|
|
buffer = (const pixel_t)(((const uint8_t *)buffer) + ((pstart>>1) * 3)); // The buffer start position
|
2013-09-26 15:38:37 +00:00
|
|
|
lg = ((g->p.x2-g->p.cx)>>1)*3; // The buffer gap between lines
|
|
|
|
pnum = pstart + g->p.x2*y + x; // Adjustment for controller craziness
|
|
|
|
p = ((const uint8_t *)buffer) + (((g->p.x2*y + x)>>1)*3); // Adjustment for controller craziness
|
2013-02-18 07:29:08 +00:00
|
|
|
|
2013-03-07 14:53:34 +00:00
|
|
|
while (tuples--) {
|
2013-02-18 07:29:08 +00:00
|
|
|
/* Get a pixel */
|
2013-03-07 14:53:34 +00:00
|
|
|
switch(pnum++ & 1) {
|
|
|
|
case 0: c1 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
|
|
|
|
case 1: c1 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); p += 3; break;
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* Check for line or buffer wrapping */
|
2013-09-26 15:38:37 +00:00
|
|
|
if (++x >= g->p.cx) {
|
2013-03-07 14:53:34 +00:00
|
|
|
x = 0;
|
2013-02-18 07:29:08 +00:00
|
|
|
p += lg;
|
2013-09-26 15:38:37 +00:00
|
|
|
pnum += g->p.x2 - g->p.cx;
|
|
|
|
if (++y >= g->p.cy) {
|
2013-03-07 14:53:34 +00:00
|
|
|
y = 0;
|
|
|
|
p = (const uint8_t *)buffer;
|
|
|
|
pnum = pstart;
|
|
|
|
}
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-03-07 14:53:34 +00:00
|
|
|
|
2013-02-18 07:29:08 +00:00
|
|
|
/* Get the next pixel */
|
2013-03-07 14:53:34 +00:00
|
|
|
switch(pnum++ & 1) {
|
2013-09-25 07:18:18 +00:00
|
|
|
case 0: c2 = (((color_t)p[0]) << 4)|(((color_t)p[1])>>4); break;
|
|
|
|
case 1: c2 = (((color_t)p[1]&0x0F) << 8)|((color_t)p[1]); p += 3; break;
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* Check for line or buffer wrapping */
|
2013-09-26 15:38:37 +00:00
|
|
|
if (++x >= g->p.cx) {
|
2013-03-07 14:53:34 +00:00
|
|
|
x = 0;
|
2013-02-18 07:29:08 +00:00
|
|
|
p += lg;
|
2013-09-26 15:38:37 +00:00
|
|
|
pnum += g->p.x2 - g->p.cx;
|
|
|
|
if (++y >= g->p.cy) {
|
2013-03-07 14:53:34 +00:00
|
|
|
y = 0;
|
|
|
|
p = (const uint8_t *)buffer;
|
|
|
|
pnum = pstart;
|
|
|
|
}
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* Write the pair of pixels to the display */
|
2013-10-19 06:33:56 +00:00
|
|
|
write_data3(g, ((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
2013-11-05 09:34:12 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Packed pixels is broken if you are not running native pixel format"
|
2013-02-18 07:29:08 +00:00
|
|
|
#endif
|
2013-03-07 14:53:34 +00:00
|
|
|
|
|
|
|
/* All done */
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-26 15:38:37 +00:00
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
2013-10-19 06:33:56 +00:00
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay *g) {
|
2013-02-18 07:29:08 +00:00
|
|
|
/* The hardware is capable of supporting...
|
2013-03-07 14:53:34 +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-09-25 07:18:18 +00:00
|
|
|
switch(g->p.x) {
|
2013-02-18 07:29:08 +00:00
|
|
|
case GDISP_CONTROL_POWER:
|
2013-09-25 07:18:18 +00:00
|
|
|
if (g->g.Powermode == (powermode_t)g->p.ptr)
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
2013-10-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
2013-09-25 07:18:18 +00:00
|
|
|
switch((powermode_t)g->p.ptr) {
|
2013-02-18 07:29:08 +00:00
|
|
|
case powerOff:
|
2013-10-19 06:33:56 +00:00
|
|
|
set_backlight(g, 0); // Turn off the backlight
|
|
|
|
write_index(g, DISOFF); // Turn off the display
|
|
|
|
write_cmd1(g, PWRCTR, 0x00); // Power control - all off
|
|
|
|
write_index(g, SLPIN); // Sleep in
|
|
|
|
write_index(g, OSCOFF); // Internal oscillator off
|
2013-02-18 07:29:08 +00:00
|
|
|
break;
|
|
|
|
case powerOn:
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, OSCON); // Internal oscillator on
|
|
|
|
write_index(g, SLPOUT); // Sleep out
|
|
|
|
write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
|
|
|
|
write_cmd2(g, VOLCTR, g->g.Contrast, 0x03); // Voltage control (contrast setting)
|
2013-03-07 14:53:34 +00:00
|
|
|
delayms(100); // Allow power supply to stabilise
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, DISON); // Turn on the display
|
|
|
|
write_index(g, PTLOUT); // Remove sleep window
|
|
|
|
set_backlight(g, g->g.Backlight); // Turn on the backlight
|
2013-02-18 07:29:08 +00:00
|
|
|
break;
|
|
|
|
case powerSleep:
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, OSCON); // Internal oscillator on
|
|
|
|
write_index(g, SLPOUT); // Sleep out
|
|
|
|
write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
|
|
|
|
write_cmd2(g, VOLCTR, g->g.Contrast, 0x03); // Voltage control (contrast setting)
|
2013-03-07 14:53:34 +00:00
|
|
|
delayms(100); // Allow power supply to stabilise
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, DISON); // Turn on the display
|
|
|
|
write_cmd2(g, PTLIN, GDISP_SLEEP_POS/4, (GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)/4); // Sleep Window
|
|
|
|
set_backlight(g, g->g.Backlight); // Turn on the backlight
|
2013-03-07 14:53:34 +00:00
|
|
|
break;
|
|
|
|
case powerDeepSleep:
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, OSCON); // Internal oscillator on
|
|
|
|
write_index(g, SLPOUT); // Sleep out
|
|
|
|
write_cmd1(g, PWRCTR, 0x0F); // Power control - reference voltage regulator on, circuit voltage follower on, BOOST ON
|
|
|
|
write_cmd2(g, VOLCTR, g->g.Contrast, 0x03); // Voltage control (contrast setting)
|
2013-03-07 14:53:34 +00:00
|
|
|
delayms(100); // Allow power supply to stabilise
|
2013-10-19 06:33:56 +00:00
|
|
|
write_index(g, DISON); // Turn on the display
|
|
|
|
write_cmd2(g, PTLIN, GDISP_SLEEP_POS/4, (GDISP_SLEEP_POS+GDISP_SLEEP_SIZE)/4); // Sleep Window
|
|
|
|
set_backlight(g, 0); // Turn off the backlight
|
2013-02-18 07:29:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-09-25 07:18:18 +00:00
|
|
|
g->g.Powermode = (powermode_t)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
2013-09-26 15:38:37 +00:00
|
|
|
#if GDISP_NOKIA_ORIENTATION
|
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
|
|
|
if (g->g.Orientation == (orientation_t)g->p.ptr)
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
2013-10-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
2013-09-26 15:38:37 +00:00
|
|
|
switch((orientation_t)g->p.ptr) {
|
2013-10-01 11:11:42 +00:00
|
|
|
case GDISP_ROTATE_0:
|
2013-10-19 06:33:56 +00:00
|
|
|
write_cmd3(g, DATCTL, 0x00, 0x00, 0x02); // P1: page normal, column normal, scan in column direction
|
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 06:33:56 +00:00
|
|
|
write_cmd3(g, DATCTL, 0x05, 0x00, 0x02); // P1: page reverse, column normal, scan in page direction
|
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 06:33:56 +00:00
|
|
|
write_cmd3(g, DATCTL, 0x03, 0x00, 0x02); // P1: page reverse, column reverse, scan in column direction
|
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 06:33:56 +00:00
|
|
|
write_cmd3(g, DATCTL, 0x06, 0x00, 0x02); // P1: page normal, column reverse, scan in page direction
|
2013-10-01 11:11:42 +00:00
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-10-01 11:11:42 +00:00
|
|
|
return;
|
2013-09-26 15:38:37 +00:00
|
|
|
}
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-09-26 15:38:37 +00:00
|
|
|
g->g.Orientation = (orientation_t)g->p.ptr;
|
|
|
|
return;
|
|
|
|
#endif
|
2013-02-18 07:29:08 +00:00
|
|
|
case GDISP_CONTROL_BACKLIGHT:
|
2013-09-25 07:18:18 +00:00
|
|
|
if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
|
2013-10-19 06:33:56 +00:00
|
|
|
set_backlight(g, (unsigned)g->p.ptr);
|
2013-09-25 07:18:18 +00:00
|
|
|
g->g.Backlight = (unsigned)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
case GDISP_CONTROL_CONTRAST:
|
2013-09-26 15:38:37 +00:00
|
|
|
if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100;
|
2013-10-19 06:33:56 +00:00
|
|
|
acquire_bus(g);
|
2013-10-21 07:11:46 +00:00
|
|
|
write_cmd2(g, VOLCTR, 64*(unsigned)g->p.ptr/101, 0x03);
|
2013-10-19 06:33:56 +00:00
|
|
|
release_bus(g);
|
2013-09-25 07:18:18 +00:00
|
|
|
g->g.Contrast = (unsigned)g->p.ptr;
|
2013-02-18 07:29:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GFX_USE_GDISP */
|
|
|
|
/** @} */
|