Bagir Posted February 23, 2018 Report Share Posted February 23, 2018 Greetings, I am trying to integrate ugfx for my home project based on STM32F303 and ST7789V based LCD Display. ST7789V connected by SPI 9 bit. 1 last extra bit for D/C used. I started the display itself and with raw HAL functions the full fill was working. Now I am trying to integrate UGFX. IDE is Keil. Problem is: By calling gfxInit(); no calls to functions like gdisp_lld_init(GDisplay *g) and others. The display is not initializing. Is it missconfiguration of project/makefiles/include paths or something else? Looking to examples and documentation I wrote board file: #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H static GFXINLINE void setpin_reset(GDisplay *g, bool_t state); static GFXINLINE void init_board(GDisplay *g); static GFXINLINE void write_data(GDisplay *g, uint16_t data); static GFXINLINE void write_index(GDisplay *g, uint16_t data); static GFXINLINE void send_data( uint16_t data); static GFXINLINE void init_board(GDisplay *g) { // As we are not using multiple displays we set g->board to NULL as we don't use it. // g->board = 0; setpin_reset(g, TRUE); HAL_Delay(30); write_index(g, 0x011); HAL_Delay(30); write_index(g, 0x036); write_data(g, 0x000); write_index(g, 0x3A); write_data(g, 0x06); write_index(g, 0xB2); write_data(g, 0x00C); write_data(g, 0x00C); write_data(g, 0x000); write_data(g, 0x033); write_data(g, 0x033); write_index(g, 0xBB); //? write_data(g, 0x1A); //? write_index(g, 0xC0); write_data(g, 0x2C); write_index(g, 0xC2); write_data(g, 0x01); write_index(g, 0xC3); write_data(g, 0x0F); write_index(g, 0xC4); write_data(g, 0x20); write_index(g, 0xC6); write_data(g, 0x0F); write_index(g, 0xD0); write_data(g, 0xA4); write_data(g, 0xA1); write_index(g, 0xE0); write_data(g, 0xD0); write_data(g, 0x13); write_data(g, 0x1A); write_data(g, 0x0A); write_data(g, 0x0A); write_data(g, 0x26); write_data(g, 0x3F); write_data(g, 0x54); write_data(g, 0x54); write_data(g, 0x18); write_data(g, 0x14); write_data(g, 0x14); write_data(g, 0x30); write_data(g, 0x33); write_index(g, 0xE1); write_data(g, 0xD0); write_data(g, 0x13); write_data(g, 0x1A); write_data(g, 0x0A); write_data(g, 0x0A); write_data(g, 0x26); write_data(g, 0x3F); write_data(g, 0x54); write_data(g, 0x54); write_data(g, 0x1A); write_data(g, 0x16); write_data(g, 0x16); write_data(g, 0x32); write_data(g, 0x35); write_index(g, 0x29); HAL_Delay(30); write_index(g, 0x21); write_index(g, 0x2A); write_data(g, 0x00); write_data(g, 0x00); write_data(g, 0x00); write_data(g, 0xEF); write_index(g, 0x2B); write_data(g, 0x00); write_data(g, 0x00); write_data(g, 0x00); write_data(g, 0xEF); } static GFXINLINE void post_init_board(GDisplay *g) { (void) g; } static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) { (void) g; HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); HAL_Delay(120); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); } static GFXINLINE void set_backlight(GDisplay *g, uint8_t percent) { (void) g; (void) percent; } static GFXINLINE void acquire_bus(GDisplay *g) { (void) g; } static GFXINLINE void release_bus(GDisplay *g) { (void) g; } static GFXINLINE void write_index(GDisplay *g, uint16_t index) { (void) g; HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); uint16_t DC; DC = index; HAL_SPI_Transmit(&hspi2, (uint8_t *)&DC, 1, 100); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); } static GFXINLINE void send_data( uint16_t data) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); uint16_t DC; // = 0x0001; DC = data | 0x100; HAL_SPI_Transmit(&hspi2, (uint8_t *)&DC, 1, 100); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); } static GFXINLINE void write_data(GDisplay *g, uint16_t data) { (void) g; send_data(data); } static GFXINLINE void setreadmode(GDisplay *g) { (void) g; } static GFXINLINE void setwritemode(GDisplay *g) { (void) g; } static GFXINLINE uint16_t read_data(GDisplay *g) { (void) g; return 0; } #endif /* _GDISP_LLD_BOARD_H */ My GDISP LLD file: #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_ST7789V #include "gdisp_lld_config.h" #include "src/gdisp/gdisp_driver.h" #ifndef GDISP_SCREEN_HEIGHT #define GDISP_SCREEN_HEIGHT 240 #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 /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ // Some common routines and macros #define dummy_read(g) { volatile uint16_t 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, (uint8_t)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, (uint8_t) g->p.x); write_data(g, (g->p.x + g->p.cx - 1) >> 8); write_data(g, (uint8_t) (g->p.x + g->p.cx - 1)); write_index(g, 0x2B); write_data(g, (g->p.y >> 8)); write_data(g, (uint8_t) g->p.y); write_data(g, (g->p.y + g->p.cy - 1) >> 8); write_data(g, (uint8_t) (g->p.y + g->p.cy - 1)); } /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ LLDSPEC bool_t 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, TRUE); gfxSleepMilliseconds(20); setpin_reset(g, FALSE); gfxSleepMilliseconds(20); // Get the bus for the following initialisation commands acquire_bus(g); // 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 = GDISP_ROTATE_0; g->g.Powermode = powerOn; g->g.Backlight = GDISP_INITIAL_BACKLIGHT; g->g.Contrast = GDISP_INITIAL_CONTRAST; return TRUE; } #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, 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 color_t gdisp_lld_read_color(GDisplay *g) { uint16_t 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 == (powermode_t)g->p.ptr) return; switch((powermode_t)g->p.ptr) { case powerOff: case powerSleep: case powerDeepSleep: acquire_bus(g); write_reg(g, 0x0010, 0x0001); /* enter sleep mode */ release_bus(g); break; case powerOn: acquire_bus(g); write_reg(g, 0x0010, 0x0000); /* leave sleep mode */ release_bus(g); break; default: return; } 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: 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 GDISP_ROTATE_90: 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 GDISP_ROTATE_180: 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 GDISP_ROTATE_270: 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 = (orientation_t)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 */ gfxconf.h file: #ifndef _GFXCONF_H #define _GFXCONF_H #define GFX_USE_OS_RAW32 TRUE #define GFX_OS_HEAP_SIZE 10000 #define GFX_USE_GDISP TRUE #define GDISP_DRIVER_LIST GDISPVMT_ST7789V #define GDISP_HARDWARE_STREAM_WRITE TRUE #define GDISP_HARDWARE_CONTROL TRUE #define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 #endif /* _GFXCONF_H */ Link to comment Share on other sites More sharing options...
inmarket Posted February 23, 2018 Report Share Posted February 23, 2018 My guess is that the include path does not contain the driver directory (the directory containing the gdisp_lld_ST7789V.c file). Check that first. Don't forget to do a rebuild all afterwards if it wasn't there. If that is fine, the next step would be to debug into the gfxInit call to get some idea on why you are not getting to the gdisp_lld_init call. Link to comment Share on other sites More sharing options...
inmarket Posted February 24, 2018 Report Share Posted February 24, 2018 You also don't need to add GDISP_DRIVER_LIST to your gfxconf.h as the ST7789V driver is the only driver in the system Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now