/**************************************************************************//** * @brief TFT initialize or reinitialize * Assumes EBI has been configured correctly in BSP_Init(BSP_INIT_DK_EBI) * * @param[in] tftInit Pointer to EBI TFT initialization structure * * @return true if we should redraw into buffer, false if BC has control * over display *****************************************************************************/ bool TFT_DirectInit(const EBI_TFTInit_TypeDef *tftInit) { bool ret; uint32_t i, freq; EMSTATUS stat; /* If we are in BC_UIF_AEM_EFM state, we can redraw graphics */ if (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) == BC_UIF_AEM_EFM) { /* If we're not BC_ARB_CTRL_EBI state, we need to reconfigure display controller */ if ((BSP_RegisterRead(&BC_REGISTER->ARB_CTRL) != BC_ARB_CTRL_EBI) || runOnce) { /* Enable SSD2119 Serial Port Interface */ BSP_PeripheralAccess(BSP_TFT, true); /* Enable EBI mode of operation on SSD2119 controller */ BSP_DisplayControl(BSP_Display_EBI); BSP_DisplayControl(BSP_Display_ResetAssert); BSP_DisplayControl(BSP_Display_PowerDisable); freq = SystemCoreClockGet(); for (i = 0; i < (freq / 100); i++) { __NOP(); } /* Configure display for Direct Drive "Mode Generic" + 3-wire SPI mode */ BSP_DisplayControl(BSP_Display_ModeGeneric); BSP_DisplayControl(BSP_Display_PowerEnable); BSP_DisplayControl(BSP_Display_ResetRelease); /* Configure GPIO for EBI and TFT */ TFT_DirectGPIOConfig(); /* Initialize display */ stat = DMD_init(0); if (DMD_OK == stat) stat = DMD_selectFramebuffer((void*)EBI_BankAddress(EBI_BANK2)); if (DMD_OK != stat) while (1) ; /* Configure EBI TFT direct drive */ EBI_TFTInit(tftInit); runOnce = false; } ret = true; } else { ret = false; } return ret; }
/***************************************************************************//** * @brief * Initialize LCD device * * @details * * @note * ******************************************************************************/ void efm32_spiLcd_init(void) { struct efm32_usart_device_t *usart; rt_uint32_t flag; DMD_DisplayGeometry *geometry; rt_uint32_t ret; do { USART_InitSync_TypeDef init = USART_INITSYNC_DEFAULT; /* Find SPI device */ lcd = rt_device_find(LCD_USING_DEVICE_NAME); if (lcd == RT_NULL) { lcd_debug("LCD err: Can't find %s!\n", LCD_USING_DEVICE_NAME); break; } lcd_debug("LCD: Find device %s\n", LCD_USING_DEVICE_NAME); /* Config CS pin */ usart = (struct efm32_usart_device_t *)(lcd->user_data); if (!(usart->state & USART_STATE_AUTOCS)) { GPIO_PinModeSet(LCD_CS_PORT, LCD_CS_PIN, gpioModePushPull, 1); lcdAutoCs = false; } /* TFT initialize or reinitialize. Assumes EBI has been configured correctly in DVK_init(DVK_Init_EBI) */ rt_uint32_t freq = SystemCoreClockGet(); rt_uint32_t i; rt_bool_t warning = RT_FALSE; /* If we are in BC_UIF_AEM_EFM state, we can redraw graphics */ while (DVK_readRegister(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM) { if (!warning) { lcd_debug("LCD: Please press AEM button!!!\n"); warning = RT_TRUE; } } lcd_debug("LCD: Got LCD control\n"); /* If we're not BC_ARB_CTRL_EBI state, we need to reconfigure display controller */ if (DVK_readRegister(&BC_REGISTER->ARB_CTRL) != BC_ARB_CTRL_EBI) { lcd_debug("LCD: Set to EBI mode\n"); /* Configure for EBI mode and reset display */ DVK_displayControl(DVK_Display_EBI); DVK_displayControl(DVK_Display_ResetAssert); DVK_displayControl(DVK_Display_PowerDisable); /* Short delay */ freq = SystemCoreClockGet(); for(i = 0; i < (freq / 100); i++) { __NOP(); } #if defined(LCD_MAPPED) /* Configure display for address mapped method + 3-wire SPI mode */ DVK_displayControl(DVK_Display_Mode8080); DVK_displayControl(DVK_Display_PowerEnable); DVK_displayControl(DVK_Display_ResetRelease); /* Initialize graphics - abort on failure */ ret = DMD_init(BC_SSD2119_BASE, BC_SSD2119_BASE + 2); if (ret == DMD_OK) { /* Make sure display is configured with correct rotation */ DMD_flipDisplay(1, 1); } else if (ret != DMD_ERROR_DRIVER_ALREADY_INITIALIZED) { lcd_debug("LCD err: driver init failed %x\n", ret); break; } #elif defined(LCD_DIRECT) /* Configure TFT direct drive method from EBI BANK2 */ const EBI_TFTInit_TypeDef tftInit = { ebiTFTBank2, /* Select EBI Bank 2 */ ebiTFTWidthHalfWord, /* Select 2-byte (16-bit RGB565) increments */ ebiTFTColorSrcMem, /* Use memory as source for mask/blending */ ebiTFTInterleaveUnlimited, /* Unlimited interleaved accesses */ ebiTFTFrameBufTriggerVSync, /* VSYNC as frame buffer update trigger */ false, /* Drive DCLK from negative edge of internal clock */ ebiTFTMBDisabled, /* No masking and alpha blending enabled */ ebiTFTDDModeExternal, /* Drive from external memory */ ebiActiveLow, /* CS Active Low polarity */ ebiActiveHigh, /* DCLK Active High polarity */ ebiActiveLow, /* DATAEN Active Low polarity */ ebiActiveLow, /* HSYNC Active Low polarity */ ebiActiveLow, /* VSYNC Active Low polarity */ 320, /* Horizontal size in pixels */ 1, /* Horizontal Front Porch */ 30, /* Horizontal Back Porch */ 2, /* Horizontal Synchronization Pulse Width */ 240, /* Vertical size in pixels */ 1, /* Vertical Front Porch */ 4, /* Vertical Back Porch */ 2, /* Vertical Synchronization Pulse Width */ 0x0000, /* Frame Address pointer offset to EBI memory base */ 4, /* DCLK Period */ 0, /* DCLK Start cycles */ 0, /* DCLK Setup cycles */ 0, /* DCLK Hold cycles */ }; DVK_enablePeripheral(DVK_TFT); /* Configure display for Direct Drive + 3-wire SPI mode */ DVK_displayControl(DVK_Display_ModeGeneric); DVK_displayControl(DVK_Display_PowerEnable); DVK_displayControl(DVK_Display_ResetRelease); /* Configure GPIO for EBI and TFT */ /* EBI TFT DCLK/Dot Clock */ GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 0); /* EBI TFT DATAEN */ GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 0); /* EBI TFT VSYNC */ GPIO_PinModeSet(gpioPortA, 10, gpioModePushPull, 0); /* EBI TFT HSYNC */ GPIO_PinModeSet(gpioPortA, 11, gpioModePushPull, 0); /* Initialize display */ DMD_init(0, (rt_uint32_t)EBI_BankAddress(EBI_BANK2)); /* Configure EBI TFT direct drive */ EBI_TFTInit(&tftInit); #endif } /* Get LCD geometry */ ret = DMD_getDisplayGeometry(&geometry); if (ret != DMD_OK) { lcd_debug("LCD err: get geometry failed!\n"); break; } /* Init LCD info */ flag = RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_DMA_TX; lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; lcd_info.bits_per_pixel = 16; lcd_info.width = geometry->xSize; lcd_info.height = geometry->ySize; #if defined(LCD_MAPPED) lcd_info.framebuffer = RT_NULL; efm32_spiLcd_register(&lcd_device, LCD_DEVICE_NAME, flag, (void *)&lcd_ops); #elif defined(LCD_DIRECT) lcd_info.framebuffer = (rt_uint8_t *)EBI_BankAddress(EBI_BANK2); efm32_spiLcd_register(&lcd_device, LCD_DEVICE_NAME, flag, RT_NULL); #endif /* Set clipping area */ ret = DMD_setClippingArea(0, 0, geometry->xSize, geometry->ySize); if (ret != DMD_OK) { lcd_debug("LCD err: set clipping area failed!\n"); break; } /* Read device code */ rt_uint16_t code = 0xFFFF; #if defined(LCD_MAPPED) code = DMDIF_readDeviceCode(); #endif /* Set as rtgui graphic driver */ rtgui_graphic_set_device(&lcd_device); lcd_debug("LCD: H/W init OK!\n"); return; } while(0); lcd_debug("LCD err: H/W init failed!\n"); }