123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- /*
- * 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.io/license.html
- */
- #include "gfx.h"
- #if GFX_USE_GDISP
- #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
- #endif
- #define GDISP_DRIVER_VMT GDISPVMT_ILI9341
- #include "gdisp_lld_config.h"
- #include "src/gdisp/gdisp_driver.h"
- #include "board_ILI9341.h"
- /*===========================================================================*/
- /* Driver local definitions. */
- /*===========================================================================*/
- #ifndef GDISP_SCREEN_HEIGHT
- #define GDISP_SCREEN_HEIGHT 320
- #endif
- #ifndef GDISP_SCREEN_WIDTH
- #define GDISP_SCREEN_WIDTH 240
- #endif
- #ifndef GDISP_INITIAL_CONTRAST
- #define GDISP_INITIAL_CONTRAST 50
- #endif
- #ifndef GDISP_INITIAL_BACKLIGHT
- #define GDISP_INITIAL_BACKLIGHT 100
- #endif
- #include "ILI9341.h"
- /*===========================================================================*/
- /* Driver local functions. */
- /*===========================================================================*/
- // Some common routines and macros
- #define dummy_read(g) { volatile gU16 dummy; dummy = read_data(g); (void) dummy; }
- #define write_reg(g, reg, data) { write_index(g, reg); write_data(g, data); }
- #define write_data16(g, data) { write_data(g, data >> 8); write_data(g, (gU8)data); }
- #define delay(us) gfxSleepMicroseconds(us)
- #define delayms(ms) gfxSleepMilliseconds(ms)
- static void set_viewport(GDisplay *g) {
- write_index(g, 0x2A);
- write_data(g, (g->p.x >> 8));
- write_data(g, (gU8) g->p.x);
- write_data(g, (g->p.x + g->p.cx - 1) >> 8);
- write_data(g, (gU8) (g->p.x + g->p.cx - 1));
- write_index(g, 0x2B);
- write_data(g, (g->p.y >> 8));
- write_data(g, (gU8) g->p.y);
- write_data(g, (g->p.y + g->p.cy - 1) >> 8);
- write_data(g, (gU8) (g->p.y + g->p.cy - 1));
- }
- /*===========================================================================*/
- /* Driver exported functions. */
- /*===========================================================================*/
- LLDSPEC gBool gdisp_lld_init(GDisplay *g) {
- // No private area for this controller
- g->priv = 0;
- // Initialise the board interface
- init_board(g);
- // Hardware reset
- setpin_reset(g, gTrue);
- gfxSleepMilliseconds(20);
- setpin_reset(g, gFalse);
- gfxSleepMilliseconds(20);
- // Get the bus for the following initialisation commands
- acquire_bus(g);
- write_index(g, 0x01); //software reset
- gfxSleepMilliseconds(5);
- write_index(g, 0x28);
- // display off
- //---------------------------------------------------------
- write_index(g, 0xcf); //Power control B
- write_data(g, 0x00);
- __NOP();
- write_data(g, 0xc1); // 0x83 + PCEQ (Power Saving)
- write_data(g, 0x30);
- write_index(g, 0xed); //Power on sequence control
- write_data(g, 0x64);
- write_data(g, 0x03);
- write_data(g, 0x12);
- write_data(g, 0x81);
- write_index(g, 0xe8); //Driver timing control A
- write_data(g, 0x85);
- write_data(g, 0x10); // 01
- write_data(g, 0x7a); // 79
- write_index(g, 0xf7); //Pump ratio control
- write_data(g, 0x20);
- write_index(g, 0xea); //Driver timing control B
- write_data(g, 0x00);
- write_data(g, 0x00);
- write_index(g, 0xc0); //Power control 1
- write_data(g, 0x1b); // 26
- write_index(g, 0xc1); //Power control 2
- write_data(g, 0x01); // 11
- write_index(g, 0xc5); //Vcom control 1
- write_data(g, 0x30); // 35
- write_data(g, 0x30); // 3E
- write_index(g, 0xc7); //Vcom control 2
- write_data(g, 0xb7); // 0xbe
- write_index(g, 0x36); //Memory access control
- write_data(g, 0x48); // 0048 my,mx,mv,ml,BGR,mh,0.0
- write_index(g, 0x3a); //Pixel format set
- write_data(g, 0x55); // 16 bit/pixel
- write_index(g, 0xb1); //Frame Rate Control
- write_data(g, 0x00);
- write_data(g, 0x1a); // 1b
- write_index(g, 0xb6); //Display function control
- write_data(g, 0x0a);
- write_data(g, 0x82);
- write_index(g, 0xf2); //3Gamma Function Disable
- write_data(g, 0x00); // 08
- write_index(g, 0xE0); //Positive Gamma Correction
- write_data(g, 0x0f); // 1a
- write_data(g, 0x2a); // 1f
- write_data(g, 0x28); // 18
- write_data(g, 0x08); // 0a
- write_data(g, 0x0e); // 0f
- write_data(g, 0x08); // 06
- write_data(g, 0x54); // 45
- write_data(g, 0xa9); // 87
- write_data(g, 0x43); // 32
- write_data(g, 0x0a); // 0a
- write_data(g, 0x0f); // 07
- write_data(g, 0x00); // 02
- write_data(g, 0x00); // 07
- write_data(g, 0x00); // 05
- write_data(g, 0x00);
- write_index(g, 0xE1); //Negative Gamma Correction
- write_data(g, 0x00);
- write_data(g, 0x15); // 25
- write_data(g, 0x17); // 27
- write_data(g, 0x07); // 05
- write_data(g, 0x11); // 10
- write_data(g, 0x06); // 09
- write_data(g, 0x2b); // 3a
- write_data(g, 0x56); // 78
- write_data(g, 0x3c); // 4d
- write_data(g, 0x05);
- write_data(g, 0x10); // 18
- write_data(g, 0x0f); // 0d
- write_data(g, 0x3f); // 38
- write_data(g, 0x3f); // 3a
- write_data(g, 0x0f); // 1f
- write_index(g, 0x2b); //Page Address Set, size = 319
- write_data(g, 0x00);
- write_data(g, 0x00);
- write_data(g, 0x01);
- write_data(g, 0x3F);
- write_index(g, 0x2a); //Column Address Set, size = 239
- write_data(g, 0x00);
- write_data(g, 0x00);
- write_data(g, 0x00);
- write_data(g, 0xEF);
- write_index(g, 0x11); //Sleep Out
- gfxSleepMilliseconds(5);
- write_index(g, 0x29); //Display ON
- // Finish Init
- post_init_board(g);
- // Release the bus
- release_bus(g);
-
- /* Turn on the back-light */
- set_backlight(g, GDISP_INITIAL_BACKLIGHT);
- /* Initialise the GDISP structure */
- g->g.Width = GDISP_SCREEN_WIDTH;
- g->g.Height = GDISP_SCREEN_HEIGHT;
- g->g.Orientation = gOrientation0;
- g->g.Powermode = gPowerOn;
- g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
- g->g.Contrast = GDISP_INITIAL_CONTRAST;
- return gTrue;
- }
- #if GDISP_HARDWARE_STREAM_WRITE
- LLDSPEC void gdisp_lld_write_start(GDisplay *g) {
- acquire_bus(g);
- set_viewport(g);
- write_index(g, 0x2C);
- }
- LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
- //write_data16(g, gdispColor2Native(g->p.color));
- write_data(g, gdispColor2Native(g->p.color));
- }
- LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
- release_bus(g);
- }
- #endif
- #if GDISP_HARDWARE_STREAM_READ
- LLDSPEC void gdisp_lld_read_start(GDisplay *g) {
- acquire_bus(g);
- set_viewport(g);
- write_index(g, 0x2E);
- setreadmode(g);
- dummy_read(g);
- }
- LLDSPEC gColor gdisp_lld_read_color(GDisplay *g) {
- gU16 data;
- data = read_data(g);
- return gdispNative2Color(data);
- }
- LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
- setwritemode(g);
- release_bus(g);
- }
- #endif
- #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
- LLDSPEC void gdisp_lld_control(GDisplay *g) {
- switch(g->p.x) {
- case GDISP_CONTROL_POWER:
- if (g->g.Powermode == (gPowermode)g->p.ptr)
- return;
- switch((gPowermode)g->p.ptr) {
- case gPowerOff:
- case gPowerSleep:
- case gPowerDeepSleep:
- acquire_bus(g);
- write_reg(g, 0x0010, 0x0001); /* enter sleep mode */
- release_bus(g);
- break;
- case gPowerOn:
- acquire_bus(g);
- write_reg(g, 0x0011, 0x0000); /* leave sleep mode */
- gfxSleepMilliseconds(5);
- release_bus(g);
- break;
- default:
- return;
- }
- g->g.Powermode = (gPowermode)g->p.ptr;
- return;
- case GDISP_CONTROL_ORIENTATION:
- if (g->g.Orientation == (gOrientation)g->p.ptr)
- return;
- switch((gOrientation)g->p.ptr) {
- case gOrientation0:
- acquire_bus(g);
- write_reg(g, 0x36, 0x48); /* X and Y axes non-inverted */
- release_bus(g);
- g->g.Height = GDISP_SCREEN_HEIGHT;
- g->g.Width = GDISP_SCREEN_WIDTH;
- break;
- case gOrientation90:
- acquire_bus(g);
- write_reg(g, 0x36, 0xE8); /* Invert X and Y axes */
- release_bus(g);
- g->g.Height = GDISP_SCREEN_WIDTH;
- g->g.Width = GDISP_SCREEN_HEIGHT;
- break;
- case gOrientation180:
- acquire_bus(g);
- write_reg(g, 0x36, 0x88); /* X and Y axes non-inverted */
- release_bus(g);
- g->g.Height = GDISP_SCREEN_HEIGHT;
- g->g.Width = GDISP_SCREEN_WIDTH;
- break;
- case gOrientation270:
- acquire_bus(g);
- write_reg(g, 0x36, 0x28); /* Invert X and Y axes */
- release_bus(g);
- g->g.Height = GDISP_SCREEN_WIDTH;
- g->g.Width = GDISP_SCREEN_HEIGHT;
- break;
- default:
- return;
- }
- g->g.Orientation = (gOrientation)g->p.ptr;
- return;
- case GDISP_CONTROL_BACKLIGHT:
- if ((unsigned)g->p.ptr > 100)
- g->p.ptr = (void *)100;
- set_backlight(g, (unsigned)g->p.ptr);
- g->g.Backlight = (unsigned)g->p.ptr;
- return;
- //case GDISP_CONTROL_CONTRAST:
- default:
- return;
- }
- }
- #endif
- #endif /* GFX_USE_GDISP */
|