tftdirect.c

Go to the documentation of this file.
00001 /**************************************************************************/
00017 #include <stdbool.h>
00018 #include "em_device.h"
00019 #include "em_gpio.h"
00020 #include "em_ebi.h"
00021 #include "bsp.h"
00022 #include "tftdirect.h"
00023 /* DMD init from dmd_ssd2119_direct.c */
00024 #include "glib/glib.h"
00025 
00027 static bool runOnce = true;
00028 
00029 /**************************************************************************/
00032 void TFT_DirectGPIOConfig(void)
00033 {
00034   /* EBI TFT DCLK/Dot Clock */
00035   GPIO_PinModeSet(gpioPortA, 8, gpioModePushPull, 0);
00036   /* EBI TFT DATAEN */
00037   GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 0);
00038   /* EBI TFT VSYNC  */
00039   GPIO_PinModeSet(gpioPortA, 10, gpioModePushPull, 0);
00040   /* EBI TFT HSYNC */
00041   GPIO_PinModeSet(gpioPortA, 11, gpioModePushPull, 0);
00042 }
00043 
00044 
00045 /**************************************************************************/
00054 bool TFT_DirectInit(const EBI_TFTInit_TypeDef *tftInit)
00055 {
00056   bool     ret;
00057   uint32_t i, freq;
00058   EMSTATUS stat;
00059 
00060   /* If we are in BC_UIF_AEM_EFM state, we can redraw graphics */
00061   if (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) == BC_UIF_AEM_EFM)
00062   {
00063     /* If we're not BC_ARB_CTRL_EBI state, we need to reconfigure display controller */
00064     if ((BSP_RegisterRead(&BC_REGISTER->ARB_CTRL) != BC_ARB_CTRL_EBI) || runOnce)
00065     {
00066       /* Enable SSD2119 Serial Port Interface */
00067       BSP_PeripheralAccess(BSP_TFT, true);
00068 
00069       /* Enable EBI mode of operation on SSD2119 controller */
00070       BSP_DisplayControl(BSP_Display_EBI);
00071       BSP_DisplayControl(BSP_Display_ResetAssert);
00072       BSP_DisplayControl(BSP_Display_PowerDisable);
00073       freq = SystemCoreClockGet();
00074       for (i = 0; i < (freq / 100); i++)
00075       {
00076         __NOP();
00077       }
00078       /* Configure display for Direct Drive "Mode Generic" + 3-wire SPI mode */
00079       BSP_DisplayControl(BSP_Display_ModeGeneric);
00080       BSP_DisplayControl(BSP_Display_PowerEnable);
00081       BSP_DisplayControl(BSP_Display_ResetRelease);
00082 
00083       /* Configure GPIO for EBI and TFT */
00084       TFT_DirectGPIOConfig();
00085 
00086       /* Initialize display */
00087       stat = DMD_init(0);
00088       if (DMD_OK == stat) stat = DMD_selectFramebuffer((void*)EBI_BankAddress(EBI_BANK2));
00089       if (DMD_OK != stat) while (1) ;
00090 
00091       /* Configure EBI TFT direct drive */
00092       EBI_TFTInit(tftInit);
00093 
00094       runOnce = false;
00095     }
00096     ret = true;
00097   }
00098   else
00099   {
00100     ret = false;
00101   }
00102 
00103   return ret;
00104 }