Exemplo n.º 1
0
/**************************************************************************//**
 * @brief  TFT initialize or reinitialize to Address Mapped Mode
 *         Assumes EBI has been configured correctly in BSP_Init()
 *
 * @return true if we should redraw into buffer, false if BC has control
 *         over display
 *****************************************************************************/
bool TFT_AddressMappedInit(void)
{
  bool     ret;
  EMSTATUS status;

  /* If we are in BC_UIF_AEM_EFM state, we can redraw graphics */
  if (BSP_RegisterRead(BC_AEMSTATE) == 1)
  {
    /* If we're not BC_ARB_CTRL_EBI state, we need to reconfigure display controller */
    if ((BSP_RegisterRead(BC_BUS_CFG) == BC_BUS_CFG_FSMC) || runOnce)
    {
      /* Initialize graphics - abort on failure */
      status = DMDIF_init(BC_SSD2119_BASE, BC_SSD2119_BASE + 2);
      if (status == DMD_OK) status = DMD_init(0);
      if ((status != DMD_OK) && (status != DMD_ERROR_DRIVER_ALREADY_INITIALIZED)) while (1) ;
      /* Make sure display is configured with correct rotation */
      if ((status == DMD_OK)) DMD_flipDisplay(1, 1);

      runOnce = false;
    }
    ret = true;
  }
  else
  {
    ret = false;
  }
  return ret;
}
Exemplo n.º 2
0
/* Initialize LCD in memory mapped mode and touch panel */
void LCD_InitializeLCD(void)
{ TOUCH_Config_TypeDef touch_init = TOUCH_INIT_DEFAULT;
  int      i;

  /* 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)
    {
      /* Configure for EBI mode and reset display */
      BSP_DisplayControl(BSP_Display_EBI);
      BSP_DisplayControl(BSP_Display_ResetAssert);
      BSP_DisplayControl(BSP_Display_PowerDisable);
      /* Short delay */
      for (i = 0; i < 10000; i++) ;
      /* Configure display for Direct Drive + SPI mode */
      BSP_DisplayControl(BSP_Display_Mode8080);
      BSP_DisplayControl(BSP_Display_PowerEnable);
      BSP_DisplayControl(BSP_Display_ResetRelease);

      runOnce = false;
    }
  }

  touch_init.oversampling = adcOvsRateSel32;
  TOUCH_Init(&touch_init);
  TOUCH_RegisterUpcall(LCD_TOUCH_Upcall);
}
Exemplo n.º 3
0
/**************************************************************************//**
 * @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;
}
Exemplo n.º 4
0
/**************************************************************************//**
 * @brief Transmit single byte to the TFT
 * @param c Character to transmit
 * @return Transmitted character
 *****************************************************************************/
int RETARGET_WriteChar(char c)
{
  if ((BSP_RegisterRead(&BC_REGISTER->UIF_AEM) == BC_UIF_AEM_EFM))
  {
    if ((BSP_RegisterRead(&BC_REGISTER->ARB_CTRL) != BC_ARB_CTRL_EBI) || (initialized == false))
    {
      if (initialized)
      {
        bufferReset = false;
        tftReset    = true;
        RETARGET_SerialInit();
      }
      else
      {
        bufferReset = true;
        tftReset    = true;
        RETARGET_SerialInit();
      }
      fullUpdate = true;
    }
  }

  /* Check for form feed - clear screen */
  if (c == '\f')
  {
    bufferReset = true;
    tftReset    = false;
    RETARGET_SerialInit();
    fullUpdate = true;
    return c;
  }

  /* Add CR or LF to CRLF if enabled */
  if (LFtoCRLF && (c == '\n'))
  {
    RETARGET_TFTTX('\r');
  }
  RETARGET_TFTTX(c);

  if (LFtoCRLF && (c == '\r'))
  {
    RETARGET_TFTTX('\n');
  }

  /* Update display */
  RETARGET_TFTUpdate(fullUpdate);
  fullUpdate = false;
  return c;
}
Exemplo n.º 5
0
/**************************************************************************//**
 * @brief  Get status of PB1,...,PB4 buttons and the AEM state
 * @return Bitmap button status, AEM state in bit position EXIT_LOOP
 *****************************************************************************/
static uint32_t readButtons( void )
{
  if ( BSP_RegisterRead(&BC_REGISTER->UIF_AEM) == BC_UIF_AEM_BC )
    return EXIT_LOOP | BSP_PushButtonsGet();

  return BSP_PushButtonsGet();
}
/**************************************************************************//**
 * @brief Initialize board support package functionality.
 *
 * @param[in] flags
 *   DK3x50:  Initialize in EBI or SPI mode using @ref BSP_INIT_DK_EBI or
 *            @ref BSP_INIT_DK_SPI.
 *   Gxxx_DK: Use 0.
 *   STK:     Use @ref BSP_INIT_BCC to initialize board controller UART, 0
 *            otherwise.
 *
 *   The value BSP_INIT_DEFAULT is defined and is: @ref BSP_INIT_DK_EBI on DK3x50,
 *             0 on all other kits.
 *
 * @return @ref BSP_STATUS_OK
 *****************************************************************************/
int BSP_Init(uint32_t flags)
{
  bool ret = false;

  if (flags & BSP_INIT_DK_EBI)
  {
    bspOperationMode = BSP_INIT_DK_EBI;
    BSP_BusControlModeSet(BSP_BusControl_EBI);
    ret = EbiInit();
  }
  if (flags & BSP_INIT_DK_SPI)
  {
    bspOperationMode = BSP_INIT_DK_SPI;
    BSP_BusControlModeSet(BSP_BusControl_SPI);
    ret = SpiInit();
  }

  if (ret == false)
  {
    /* Unable to access board control, this is an abornomal situation. */
    /* Try to restart kit and reprogram EFM32 with a standard example */
    /* as this is most likely caused by a peripheral misconfiguration. */
    while (1) ;
  }

  /* Inform AEM application that we are in Energy Mode 0 by default */
  BSP_RegisterWrite(&BC_REGISTER->EM, 0);
  
  /* Read out BC firmware version */
  bcFwVersion = BSP_RegisterRead(&BC_REGISTER->FW_VERSION);

  return BSP_STATUS_OK;
}
Exemplo n.º 7
0
/***************************************************************************//**
*     @brief
*        is used to stop code execution for specified time
*     @param[in] ms
*        contains number of miliseconds to suspend program. Maximum allowed
*        value is 10000 (10 seconds).
*     @details
*        This routine could enter into EM1 or EM2 mode to reduce power
*        consumption. If touch panel is not pressed EM2 is executed, otherwise
*        due to fact that ADC requires HF clock, only EM1 is enabled. This
*        function is also used to handle joystick state and move cursor
*        according to it. In addition it could also reinitialize LCD if
*        previously Advanced Energy Monitor screen was active.
 ******************************************************************************/
void GUI_X_Delay(int ms)
{
  volatile uint32_t now;
  uint32_t startTime, waitTime;

  if ( BSP_RegisterRead( &BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Switched to Advanced Energy Monitor, LCD will need to be reinitialized */
    aemMode = true;
  }
  else if( aemMode )
  {
    /* Switched back from Advanced Energy Monitor, reinitialize LCD  */
    aemMode = false;
    PLOT_DisplayInit();
  }

  if ( ms > 0 )
  {
    waitTime = ms * (CMU_ClockFreqGet(cmuClock_CORE) / 1000);

    /* Enable DWT and make sure CYCCNT is running. */
    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    DWT->CTRL        |= 1;

    startTime = DWT->CYCCNT;
    do
    {
      now = DWT->CYCCNT;
    } while ( ( now - startTime ) < waitTime );
  }
}
Exemplo n.º 8
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint16_t *frameBuffer;
  bool     redraw;

  /* Configure for 48MHz HFXO operation of core clock */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
  {
    while (1) ;
  }

  /* Initialize EBI banks (Board Controller, external PSRAM, ..) */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Indicate we are waiting for AEM button state enable EFM32GG */
  BSP_LedsSet(0x8001);
  while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Show a short "strobe light" on DK LEDs, indicating wait */
    BSP_LedsSet(0x8001);
    Delay(200);
    BSP_LedsSet(0x4002);
    Delay(50);
  }

  /* Set frame buffer start address */
  frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2);

  /* Loop demo forever */
  while (1)
  {
    redraw = TFT_DirectInit(&tftInit);
    if (redraw)
    {
      /* Inidicate that we are in active drawing mode */
      BSP_LedsSet(0x0000);

      /* Update frame buffer */
      TFT_DrawScreen(frameBuffer);

      /* Wait slightly before next update */
      Delay(100);
    }
    else
    {
      /* Sleep - no need to update display */
      BSP_LedsSet(0x8001);
      Delay(200);
    }
  }
}
Exemplo n.º 9
0
/**************************************************************************//**
 * @brief  TFT initialize or reinitialize to Address Mapped Mode
 *         Assumes EBI has been configured correctly in BSP_Init(BSP_INIT_DK_EBI)
 *
 * @return true if we should redraw into buffer, false if BC has control
 *         over display
 *****************************************************************************/
bool TFT_AddressMappedInit(void)
{
    bool     ret;
    EMSTATUS status;
    uint32_t i, freq;

    /* 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)
        {
            /* Configure for EBI mode and reset display */
            BSP_DisplayControl(BSP_Display_EBI);
            BSP_DisplayControl(BSP_Display_ResetAssert);
            BSP_DisplayControl(BSP_Display_PowerDisable);
            /* Short reset delay */
            freq = SystemCoreClockGet();
            for (i = 0; i < (freq / 100); i++)
            {
                __NOP();
            }
            /* Configure display for Direct Drive + SPI mode */
            BSP_DisplayControl(BSP_Display_Mode8080);
            BSP_DisplayControl(BSP_Display_PowerEnable);
            BSP_DisplayControl(BSP_Display_ResetRelease);

            /* Initialize graphics - abort on failure */
            status = DMDIF_init(BC_SSD2119_BASE, BC_SSD2119_BASE + 2);
            if (status == DMD_OK) status = DMD_init(0);
            if ((status != DMD_OK) && (status != DMD_ERROR_DRIVER_ALREADY_INITIALIZED)) while (1) ;
            /* Make sure display is configured with correct rotation */
            if ((status == DMD_OK)) DMD_flipDisplay(1, 1);

            runOnce = false;
        }
        ret = true;
    }
    else
    {
        ret = false;
    }
    return ret;
}
/**************************************************************************//**
 * @brief Enable interrupts from board controller.
 *
 * @param[in] flags A bitmask defining which interrupt sources to enable.
 *
 * @return @ref BSP_STATUS_OK
 *****************************************************************************/
int BSP_InterruptEnable(uint16_t flags)
{
  uint16_t tmp;

  /* Add flags to interrupt enable register */
  tmp  = BSP_RegisterRead(&BC_REGISTER->INTEN);
  tmp |= flags;
  BSP_RegisterWrite(&BC_REGISTER->INTEN, tmp);
  return BSP_STATUS_OK;
}
Exemplo n.º 11
0
/**************************************************************************//**
 * @brief Get current status of a single LED.
 * @param[in] ledNo The number of the LED (counting from zero) to check.
 * @return
 *   1 if LED is on, 0 if LED is off, @ref BSP_STATUS_ILLEGAL_PARAM if illegal
 *   LED number.
 *****************************************************************************/
int BSP_LedGet(int ledNo)
{
  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
  {
    if ( BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK & (1 << ledNo) )
      return 1;

    return 0;
  }
  return BSP_STATUS_ILLEGAL_PARAM;
}
/**************************************************************************//**
 * @brief Disable interrupts from board controller.
 *
 * @param[in] flags A bitmask defining which interrupt sources to disable.
 *
 * @return @ref BSP_STATUS_OK
 *****************************************************************************/
int BSP_InterruptDisable(uint16_t flags)
{
  uint16_t tmp;

  /* Clear flags from interrupt enable register */
  tmp   = BSP_RegisterRead(&BC_REGISTER->INTEN);
  flags = ~(flags);
  tmp  &= flags;
  BSP_RegisterWrite(&BC_REGISTER->INTEN, tmp);
  return BSP_STATUS_OK;
}
Exemplo n.º 13
0
/**************************************************************************//**
 * @brief Turn off a single LED.
 * @param[in] ledNo The number of the LED (counting from zero) to turn off.
 * @return
 *   @ref BSP_STATUS_OK or @ref BSP_STATUS_ILLEGAL_PARAM if illegal LED number.
 *****************************************************************************/
int BSP_LedClear(int ledNo)
{
  uint32_t tmp;

  if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS))
  {
    tmp = BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
    tmp &= ~( 1 << ledNo );
    BSP_RegisterWrite(BSP_LED_PORT, tmp);
    return BSP_STATUS_OK;
  }
  return BSP_STATUS_ILLEGAL_PARAM;
}
/**************************************************************************//**
 * @brief Clear board controller interrupt flags.
 *
 * @param[in] flags A bitmask defining which interrupt sources to clear.
 *
 * @return @ref BSP_STATUS_OK
 *****************************************************************************/
int BSP_InterruptFlagsClear(uint16_t flags)
{ 
  uint16_t intFlags;
  
  /* Board control firmware version 257 and higher has a new interrupt architecture */
  if (bcFwVersion < 257)
  {      
    intFlags  = BSP_RegisterRead(&BC_REGISTER->INTFLAG);
    intFlags &= ~(flags);
    BSP_RegisterWrite(&BC_REGISTER->INTFLAG, intFlags);    
  }
  else
  {  
    BSP_RegisterWrite(&BC_REGISTER->INTCLEAR, flags);
  }
  return BSP_STATUS_OK;
}
/**************************************************************************//**
 * @brief Get board controller interrupt flags.
 *
 * @return A bitmask defining which interrupt sources have their flaf set.
 *****************************************************************************/
uint16_t BSP_InterruptFlagsGet(void)
{
  return BSP_RegisterRead(&BC_REGISTER->INTFLAG);
}
Exemplo n.º 16
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint32_t buttons;
  POINT P[ 3 ];
  TOUCH_Config_TypeDef touch_config = TOUCH_INIT_DEFAULT;
  const char readmeText[] = \
    "USB Bitmap transfer using USB drive functionality.\r\n\r\n"\
    "This example demonstrate use several functionalities:\r\n"\
    "1. Creation of virtual drive in system with FAT FS,\r\n"\
    "2. Mounting the drive on PC and file transfer,\r\n"\
    "3. Bitmap file creation based on TFT frame buffer content,\r\n"\
    "4. Resistive touch panel interaction.\r\n\r\n"\
    "On system startup initial drive is created and\r\n"\
    "formatted using FAT FS then simple readme.txt file\r\n"\
    "is put on file system. Every time user press PB4 key\r\n"\
    "new file, containing TFT frame buffer in bitmap format\r\n"\
    "is added. All files could be retrieved after connecting\r\n"\
    "board to PC by means of USB. For this connection use\r\n"\
    "small USB socket located on Leopard Gecko CPU board, not\r\n"\
    "the big one on development kit.\r\n\r\n"\
    "If new files doesn't appear on drive after pressing PB4,\r\n"\
    "try to reconnect the board to PC.\r\n\r\n"\
    "Board:  Energy Micro EFM32LG-DK3650 Development Kit\r\n"\
    "Device: EFM32LG990F256\r\n";


  /* Configure for 48MHz HFXO operation of core clock */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  CMU_ClockEnable(cmuClock_GPIO, true);

  CMU_ClockEnable( cmuClock_ADC0, true);

  /* Set frame buffer start address */
  frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2);

  /* Make sure CYCCNT is running, needed by delay functions. */
  DWT_CTRL |= 1;

  /* Initialize USB subsystem and prepare for taking pictures */
  BITMAP_Init();
  /* Create our first file on disk - simple readme */
  BITMAP_CreateFileAndSaveData("README.TXT", readmeText, sizeof(readmeText));

  /* Indicate we are waiting for AEM button state enabling EFM */
  while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Show a short "strobe light" on DK LEDs, indicating wait */
    BSP_LedsSet(0x8001);
    delayMs(100);
    BSP_LedsSet(0x4002);
    delayMs(100);
  }

  touch_config.frequency = 13000000; /* use max ADC frequency */
  touch_config.ignore = 0;           /* notice every move, even 1 pixel */
  TOUCH_Init(&touch_config);

  /* Initialize touch screen calibration factor matrix with approx. values  */
  setCalibrationMatrix( (POINT*)&lcdCalibPoints,   /* Display coordinates   */
                        (POINT*)&touchCalibPoints, /* Touch coordinates     */
                        &calibFactors );      /* Calibration factor matrix  */
  while (1)
  {
    delayMs(100);
    if ( TFT_DirectInit(&tftInit) )
    {
      delayMs(100);
      displayHelpScreen();
      BSP_LedsSet(0x0000);
      BSP_PeripheralAccess(BSP_TOUCH, true);
      GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);

      do
      {
        delayMs(25);
        buttons = readButtons();

        /* Draw on screen */
        if ( buttons & BC_UIF_PB1 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */

          do
          { TOUCH_Pos_TypeDef *pos = TOUCH_GetPos();
            if ( pos->pen )
              drawPixel( pos->x, pos->y, COLOR );
              delayMs(1);

            buttons = readButtons() & ~BC_UIF_PB1;
            if(buttons == BC_UIF_PB4)
            {
              getNicePicture();
              buttons &= ~BC_UIF_PB4;
            }
          } while ( buttons == 0 );
        }

        /* Calibrate touch screen */
        else if ( buttons & BC_UIF_PB2 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR );
          TFT_DrawString(30, 35, "Tap green marker" );
          P[ 0 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR );
          TFT_DrawString(40, 130, "Tap green marker" );
          P[ 1 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR );
          TFT_DrawString(20, 180, "Tap green marker" );
          P[ 2 ] = getTouchTapSample10bit();

          TOUCH_CalibrationTable((POINT*)&lcdCalibPoints,/* Display coordinates*/
                                &P[0]);                  /* Touch coordinates  */

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          TFT_DrawString(10, 100, "The touch screen is" );
          TFT_DrawString(30, 130, "now calibrated !" );
        }

        /* Display help screen */
        else if ( buttons & BC_UIF_PB3 )
        {
          displayHelpScreen();
          while ( readButtons() & BC_UIF_PB3 )
             delayMs(50);
        } else if( buttons & BC_UIF_PB4 )
        {
          getNicePicture();
        }
      } while ( ( buttons & EXIT_LOOP ) == 0 );
    }
    else
    {
      BSP_LedsSet(0x8001);
      delayMs(100);
      BSP_LedsSet(0x4002);
    }
  }
}
Exemplo n.º 17
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  bool redraw;

  /* Configure for 48MHz HFXO operation of core clock */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
  {
    while (1) ;
  }

  /* Initialize EBI banks (Board Controller, external PSRAM, ..) */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Indicate we are waiting for AEM button state enable EFM32WG */
  BSP_LedsSet(0x8001);
  while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Show a short "strobe light" on DK LEDs, indicating wait */
    BSP_LedsSet(0x8001);
    Delay(200);
    BSP_LedsSet(0x4002);
    Delay(50);
  }

  /* Initialize scroll text pointer */
  scrollptr = scrolltext;

  /* Initial initialization, enables clocks etc */
  redraw = TFT_DirectInit(&tftInit);

  /* Configure common settings */
  EBI_TFTHStrideSet((V_WIDTH - D_WIDTH) * 2);
  TFT_IRQEnable(EBI_IF_VFPORCH | EBI_IF_HSYNC);
  TFT_DisplayClear();

  /* Loop demo forever */
  while (1)
  {
    /* If necessary, reinitalize display and report back if we are active */
    redraw = TFT_DirectInit(&tftInit);
    if (redraw)
    {
      /* Inidicate that we are in active drawing mode */
      BSP_LedsSet(0x0000);

      /* Update frame buffer - do a simple block copy */
      TFT_DrawString(0, 10, "    Regular copy    ");
      TFT_DrawRectangle(0, 50, D_WIDTH, 140, DARKGREEN);
      TFT_DrawGraphics();
      EBI_TFTMaskBlendMode(ebiTFTMBDisabled);
      Delay(1000);

      /* Update frame buffer - enable masking */
      TFT_DrawString(0, 10, "      Masking       ");
      TFT_DrawRectangle(0, 50, D_WIDTH, 140, DARKGREEN);
      EBI_TFTMaskSet(0x0000);
      EBI_TFTMaskBlendMode(ebiTFTMBEMask);
      TFT_DrawGraphics();
      EBI_TFTMaskBlendMode(ebiTFTMBDisabled);
      Delay(1000);

      /* Update frame buffer - enable masking and blending */
      TFT_DrawString(0, 10, " Masking & Blending ");
      TFT_DrawRectangle(0, 50, D_WIDTH, 140, DARKGREEN);
      EBI_TFTMaskBlendMode(ebiTFTMBEMaskAlpha);
      TFT_DrawGraphics();
      EBI_TFTMaskBlendMode(ebiTFTMBDisabled);
      Delay(1000);
    }
    else
    {
      /* Sleep - no need to update display */
      BSP_LedsSet(0x8001);

      /* Instead of this, we could go into energy mode 3 */
      /* waiting for an interrupt on GPIO/keypress */
      Delay(200);
    }
  }
}
/**************************************************************************//**
 * @brief Configure display control.
 *
 * @param[in] option Configure using enum @ref BSP_Display_TypeDef.
 *                 On Gxxx_DK's this functions is a dummy.
 *
 * @return @ref BSP_STATUS_OK or @ref BSP_STATUS_NOT_IMPLEMENTED on Gxxx_DK's.
 *****************************************************************************/
int BSP_DisplayControl(BSP_Display_TypeDef option)
{
  uint16_t tmp;

  switch (option)
  {
  case BSP_Display_EBI:
    BSP_RegisterWrite(&BC_REGISTER->ARB_CTRL, BC_ARB_CTRL_EBI);
    break;

  case BSP_Display_SPI:
    BSP_RegisterWrite(&BC_REGISTER->ARB_CTRL, BC_ARB_CTRL_SPI);
    break;

  case BSP_Display_BC:
    BSP_RegisterWrite(&BC_REGISTER->ARB_CTRL, BC_ARB_CTRL_BC);
    break;

  case BSP_Display_PowerEnable:
    tmp  = BSP_RegisterRead(&BC_REGISTER->DISPLAY_CTRL);
    tmp |= (BC_DISPLAY_CTRL_POWER_ENABLE);
    BSP_RegisterWrite(&BC_REGISTER->DISPLAY_CTRL, tmp);
    break;

  case BSP_Display_PowerDisable:
    tmp  = BSP_RegisterRead(&BC_REGISTER->DISPLAY_CTRL);
    tmp &= ~(BC_DISPLAY_CTRL_POWER_ENABLE);
    BSP_RegisterWrite(&BC_REGISTER->DISPLAY_CTRL, tmp);
    break;

  case BSP_Display_ResetAssert:
    tmp  = BSP_RegisterRead(&BC_REGISTER->DISPLAY_CTRL);
    tmp |= (BC_DISPLAY_CTRL_RESET);
    BSP_RegisterWrite(&BC_REGISTER->DISPLAY_CTRL, tmp);
    break;

  case BSP_Display_ResetRelease:
    tmp  = BSP_RegisterRead(&BC_REGISTER->DISPLAY_CTRL);
    tmp &= ~(BC_DISPLAY_CTRL_RESET);
    BSP_RegisterWrite(&BC_REGISTER->DISPLAY_CTRL, tmp);
    break;

  case BSP_Display_Mode8080:
    tmp  = BSP_RegisterRead(&BC_REGISTER->DISPLAY_CTRL);
    tmp &= ~(BC_DISPLAY_CTRL_MODE_GENERIC);
    BSP_RegisterWrite(&BC_REGISTER->DISPLAY_CTRL, tmp);
    break;

  case BSP_Display_ModeGeneric:
    tmp  = BSP_RegisterRead(&BC_REGISTER->DISPLAY_CTRL);
    tmp |= (BC_DISPLAY_CTRL_MODE_GENERIC);
    BSP_RegisterWrite(&BC_REGISTER->DISPLAY_CTRL, tmp);
    break;

  default:
    /* Unknown command */
    while (1);
  }

  return BSP_STATUS_OK;
}
/**************************************************************************//**
 * @brief Get status of the DIP switches on the DK.
 * @return Bitmask with a single bit for each DIP switch.
 *****************************************************************************/
uint32_t BSP_DipSwitchGet(void)
{
  return BSP_RegisterRead(&BC_REGISTER->UIF_DIP) & 0x000f;
}
Exemplo n.º 20
0
/**************************************************************************//**
 * @brief Get status of all LED's.
 * @return
 *   Bitmask with current status for all LED's.
 *****************************************************************************/
uint32_t BSP_LedsGet(void)
{
  return BSP_RegisterRead(BSP_LED_PORT) & BSP_LED_MASK;
}
/**************************************************************************//**
 * @brief Get status of joystick on the DK.
 * @return The status of the 5 joystick switches. See @ref BC_JOYSTICK_MASK
 *         or @ref BC_UIF_JOYSTICK_MASK according to your kit.
 *****************************************************************************/
uint16_t BSP_JoystickGet(void)
{
  return ~(BSP_RegisterRead(&BC_REGISTER->UIF_JOYSTICK)) & 0x001f;
}
/**************************************************************************//**
 * @brief DK Peripheral Access Control
 *    Enable or disable access to on-board peripherals through switches
 *    and SPI switch where applicable. Turn off conflicting peripherals when
 *    enabling another.
 *
 * @param[in] perf
 *    Which peripheral to configure. Use enum @ref BSP_Peripheral_TypeDef or
 *    @ref BSP_Peripheral_Typedef according to DK type.
 *
 * @param[in] enable
 *    If true, set up access to peripheral, if false disable access.
 *
 * @return
 *   @ref BSP_STATUS_OK.
 *****************************************************************************/
int BSP_PeripheralAccess(BSP_Peripheral_TypeDef perf, bool enable)
{
  uint16_t perfControl;

  perfControl = BSP_RegisterRead(&BC_REGISTER->PERICON);

  /* Enable or disable the specified peripheral by setting board control switch */
  if (enable)
  {
    switch (perf)
    {
    case BSP_RS232_SHUTDOWN:
      perfControl |= (1 << BC_PERICON_RS232_SHUTDOWN_SHIFT);
      break;

    case BSP_RS232_UART:
      perfControl &= ~(1 << BC_PERICON_RS232_SHUTDOWN_SHIFT);
      perfControl &= ~(1 << BC_PERICON_RS232_LEUART_SHIFT);
      perfControl |= (1 << BC_PERICON_RS232_UART_SHIFT);
      break;

    case BSP_RS232_LEUART:
      perfControl &= ~(1 << BC_PERICON_RS232_SHUTDOWN_SHIFT);
      perfControl &= ~(1 << BC_PERICON_RS232_UART_SHIFT);
      perfControl |= (1 << BC_PERICON_RS232_LEUART_SHIFT);
      break;

    case BSP_I2C:
      perfControl |= (1 << BC_PERICON_I2C_SHIFT);
      break;

    case BSP_ETH:
      /* Enable SPI interface */
      SpiControl(BSP_SPI_Ethernet);

      /* Enable Ethernet analog switches */
      perfControl |= (1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl |= (1 << BC_PERICON_I2S_ETH_SEL_SHIFT);

      /* Disable Analog Diff Input - pins PD0 and PD1 is shared */
      perfControl &= ~(1 << BC_PERICON_ANALOG_DIFF_SHIFT);
      /* Disable Touch Inputs - pin PD3 is shared */
      perfControl &= ~(1 << BC_PERICON_TOUCH_SHIFT);
      /* Disable Analog SE Input - pin PD2 is shared */
      perfControl &= ~(1 << BC_PERICON_ANALOG_SE_SHIFT);
      break;

    case BSP_I2S:
      /* Direct SPI interface to I2S DAC */
      SpiControl(BSP_SPI_Audio);

      /* Also make surea Audio out is connected for I2S operation */
      perfControl |= (1 << BC_PERICON_AUDIO_OUT_SHIFT);
      perfControl |= (1 << BC_PERICON_AUDIO_OUT_SEL_SHIFT);
      perfControl |= (1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);

      /* Disable Analog Diff Input - pins PD0 and PD1 is shared */
      perfControl &= ~(1 << BC_PERICON_ANALOG_DIFF_SHIFT);
      /* Disable Touch Inputs - pin PD3 is shared */
      perfControl &= ~(1 << BC_PERICON_TOUCH_SHIFT);
      /* Disable Analog SE Input - pin PD2 is shared */
      perfControl &= ~(1 << BC_PERICON_ANALOG_SE_SHIFT);
      break;

    case BSP_TRACE:
      #if defined(ETM_PRESENT)
        perfControl |= (1 << BC_PERICON_TRACE_SHIFT);
        break;
      #else
        /* TRACE is not available on EFM32G890F128, application error */
        while (1) ;
      #endif

    case BSP_TOUCH:
      perfControl |= (1 << BC_PERICON_TOUCH_SHIFT);
      /* Disconnect SPI switch, pin PD3 is shared */
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);
      SpiControl(BSP_SPI_OFF);
      break;

    case BSP_AUDIO_IN:
      perfControl |= (1 << BC_PERICON_AUDIO_IN_SHIFT);
      break;

    case BSP_AUDIO_OUT:
      perfControl &= ~(1 << BC_PERICON_AUDIO_OUT_SEL_SHIFT);
      perfControl |= (1 << BC_PERICON_AUDIO_OUT_SHIFT);
      break;

    case BSP_ANALOG_DIFF:
      perfControl |= (1 << BC_PERICON_ANALOG_DIFF_SHIFT);
      /* Disconnect SPI switch, pin PD0 and PD1 is shared */
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);
      SpiControl(BSP_SPI_OFF);
      break;

    case BSP_ANALOG_SE:
      perfControl |= (1 << BC_PERICON_ANALOG_SE_SHIFT);
      /* Disconnect SPI switch, pin PD2 is shared */
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);
      SpiControl(BSP_SPI_OFF);
      break;

    case BSP_MICROSD:
      perfControl |= (1 << BC_PERICON_SPI_SHIFT);
      break;

    case BSP_TFT:
      /* Enable SPI to SSD2119 */
      SpiControl(BSP_SPI_Display);
      /* Enable SPI analog switch */
      perfControl |= (1 << BC_PERICON_I2S_ETH_SHIFT);
      /* Disable Analog Diff Input - pins D0 and D1 is shared */
      perfControl &= ~(1 << BC_PERICON_ANALOG_DIFF_SHIFT);
      /* Disable Touch Inputs - pin D3 is shared */
      perfControl &= ~(1 << BC_PERICON_TOUCH_SHIFT);
      /* Disable Analog SE Input - pin D2 is shared */
      perfControl &= ~(1 << BC_PERICON_ANALOG_SE_SHIFT);
      break;
    }
  }
  else
  {
    switch (perf)
    {
    case BSP_RS232_SHUTDOWN:
      perfControl &= ~(1 << BC_PERICON_RS232_SHUTDOWN_SHIFT);
      break;

    case BSP_RS232_UART:
      perfControl |= (1 << BC_PERICON_RS232_SHUTDOWN_SHIFT);
      perfControl &= ~(1 << BC_PERICON_RS232_UART_SHIFT);
      break;

    case BSP_RS232_LEUART:
      perfControl |= (1 << BC_PERICON_RS232_SHUTDOWN_SHIFT);
      perfControl &= ~(1 << BC_PERICON_RS232_LEUART_SHIFT);
      break;

    case BSP_I2C:
      perfControl &= ~(1 << BC_PERICON_I2C_SHIFT);
      break;

    case BSP_ETH:
      /* Disable SPI interface */
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);
      SpiControl(BSP_SPI_OFF);
      break;

    case BSP_I2S:
      /* Disable SPI interface and audio out */
      perfControl &= ~(1 << BC_PERICON_AUDIO_OUT_SHIFT);
      perfControl &= ~(1 << BC_PERICON_AUDIO_OUT_SEL_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);
      SpiControl(BSP_SPI_OFF);
      break;

    case BSP_TRACE:
      #if defined(ETM_PRESENT)
        perfControl &= ~(1 << BC_PERICON_TRACE_SHIFT);
        break;
      #else
        /* TRACE is not available on EFM32G890F128, application error */
        while (1) ;
      #endif

    case BSP_TOUCH:
      perfControl &= ~(1 << BC_PERICON_TOUCH_SHIFT);
      break;

    case BSP_AUDIO_IN:
      perfControl &= ~(1 << BC_PERICON_AUDIO_IN_SHIFT);
      break;

    case BSP_AUDIO_OUT:
      perfControl &= ~(1 << BC_PERICON_AUDIO_OUT_SEL_SHIFT);
      perfControl &= ~(1 << BC_PERICON_AUDIO_OUT_SHIFT);
      break;

    case BSP_ANALOG_DIFF:
      perfControl &= ~(1 << BC_PERICON_ANALOG_DIFF_SHIFT);
      break;

    case BSP_ANALOG_SE:
      perfControl &= ~(1 << BC_PERICON_ANALOG_SE_SHIFT);
      break;

    case BSP_MICROSD:
      perfControl &= ~(1 << BC_PERICON_SPI_SHIFT);
      break;

    case BSP_TFT:
      /* Disable SPI interface */
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SHIFT);
      perfControl &= ~(1 << BC_PERICON_I2S_ETH_SEL_SHIFT);
      SpiControl(BSP_SPI_OFF);
      break;
    }
  }
  /* Write back register */
  BSP_RegisterWrite(&BC_REGISTER->PERICON, perfControl);

  return BSP_STATUS_OK;
}
Exemplo n.º 23
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint32_t buttons;
  POINT touchSample, P[ 3 ];
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;

  /* Configure for 48MHz HFXO operation of core clock */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  CMU_ClockEnable(cmuClock_GPIO, true);

  CMU_ClockEnable( cmuClock_ADC0, true);
  /* Max ADC clock is 13MHz, use 14MHz/(1+1) or 48MHz/(5+1) */
  init.prescale = 5;
  ADC_Init(ADC0, &init);
  sInit.reference = adcRefVDD;

  /* Set frame buffer start address */
  frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2);

  /* Make sure CYCCNT is running, needed by delay functions. */
  DWT_CTRL |= 1;

  /* Indicate we are waiting for AEM button state enabling EFM */
  BSP_LedsSet(0x8001);
  while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Show a short "strobe light" on DK LEDs, indicating wait */
    BSP_LedsSet(0x8001);
    delayMs(200);
    BSP_LedsSet(0x4002);
    delayMs(50);
  }

  /* Initialize touch screen calibration factor matrix with approx. values  */
  setCalibrationMatrix( (POINT*)&lcdCalibPoints,   /* Display coordinates   */
                        (POINT*)&touchCalibPoints, /* Touch coordinates     */
                        &calibFactors );      /* Calibration factor matrix  */

  while (1)
  {
    if ( TFT_DirectInit(&tftInit) )
    {
      displayHelpScreen();
      BSP_LedsSet(0x0000);
      BSP_PeripheralAccess(BSP_TOUCH, true);
      GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);

      do
      {
        buttons = readButtons();

        /* Draw on screen */
        if ( buttons & BC_UIF_PB1 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */

          do
          {
            if ( touched() )
            {
              touchSample = getTouchSample();
              drawPixel( touchSample.x, touchSample.y, COLOR );
            }
            delayMs( 2 );

            buttons = readButtons() & ~BC_UIF_PB1;
          } while ( buttons == 0 );
        }

        /* Calibrate touch screen */
        else if ( buttons & BC_UIF_PB2 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR );
          TFT_DrawString(30, 35, "Tap green marker" );
          P[ 0 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR );
          TFT_DrawString(40, 130, "Tap green marker" );
          P[ 1 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR );
          TFT_DrawString(20, 180, "Tap green marker" );
          P[ 2 ] = getTouchTapSample10bit();

          setCalibrationMatrix( (POINT*)&lcdCalibPoints,/* Display coordinates*/
                                &P[0],                  /* Touch coordinates  */
                                &calibFactors );  /* Calibration factor matrix*/

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          TFT_DrawString(10, 100, "The touch screen is" );
          TFT_DrawString(30, 130, "now calibrated !" );
        }

        /* Display help screen */
        else if ( buttons & BC_UIF_PB3 )
        {
          displayHelpScreen();
          while ( readButtons() & BC_UIF_PB3 ) {}
        }

      } while ( ( buttons & EXIT_LOOP ) == 0 );
    }
    else
    {
      BSP_LedsSet(0x8001);
      delayMs(200);
    }
  }
}