Example #1
0
/**************************************************************************//**
 * @brief  Clear the display.
 *
 * @detail  This function clears the display.
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
void Display_clear(void) {
  uint16_t cmd;

  /* Set SCS */
  PAL_GpioPinOutSet(LCD_PORT_SCS, LCD_PIN_SCS);

  /* SCS setup time: min 6us */
  PAL_TimerMicroSecondsDelay(6);

  /* Send command */
  cmd = LS013B7DH03_CMD_ALL_CLEAR;
  PAL_SpiTransmit((uint8_t *)&cmd, 2);

  /* SCS hold time: min 2us */
  PAL_TimerMicroSecondsDelay(2);

  /* Clear SCS */
  PAL_GpioPinOutClear( LCD_PORT_SCS, LCD_PIN_SCS );
}
/**************************************************************************//**
 * @brief  Clear the display.
 *
 * @detail  This function clears the display.
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
static EMSTATUS DisplayClear ( void )
{
  uint16_t cmd;

  spi_select(lcd_spi_handle);

  /* SCS setup time: min 6us */
  PAL_TimerMicroSecondsDelay(6);

  /* Send command */
  cmd = LS013B7DH03_CMD_ALL_CLEAR | lcdPolarity;
  spi_exchange_bytes(lcd_spi_handle, (uint8_t*)&cmd, NULL, 2);

  /* SCS hold time: min 2us */
  PAL_TimerMicroSecondsDelay(2);

  spi_deselect(lcd_spi_handle);
  return DISPLAY_EMSTATUS_OK;
}
Example #3
0
/* send horizontal pixel array to the display.
* The pixel array has the full width of the display
* and height [in pixels] specified by 'h'
*
* @par pa  - pointer to the pixel array
* @par y   - start row
* @par h   - height of the pixel array
*/
void Display_sendPA(uint32_t const *pa,
                    uint8_t y, uint8_t h)
{
    uint32_t i;
    uint8_t const *p = (uint8_t const *)pa;
    uint16_t cmd;

    /* Need to adjust start row by one because LS013B7DH03 starts
    * counting lines from 1, while the DISPLAY interface starts from 0.
    */
    ++y;

    /* Assert SCS */
    PAL_GpioPinOutSet( LCD_PORT_SCS, LCD_PIN_SCS );

    /* SCS setup time: min 6us */
    PAL_TimerMicroSecondsDelay(6);

    /* Send update command and first line address */
    cmd = LS013B7DH03_CMD_UPDATE | (y << 8);
    PAL_SpiTransmit((uint8_t *)&cmd, 2);

    /* send pixels for all lines except the last... */
    for (i = 0; i < h - 1; ++i) {
        PAL_SpiTransmit((uint8_t *)p, LS013B7DH03_WIDTH/8);
        p += (LS013B7DH03_WIDTH/8);
        cmd = 0xFFU | ((y + i + 1) << 8);
        PAL_SpiTransmit((uint8_t *)&cmd, 2);
    }
    /* send pixels for the last line */
    PAL_SpiTransmit((uint8_t *)p, LS013B7DH03_WIDTH/8);
    cmd = 0xFFFFU;
    PAL_SpiTransmit((uint8_t *)&cmd, 2);

    /* SCS hold time: min 2us */
    PAL_TimerMicroSecondsDelay(2);

    /* De-assert SCS */
    PAL_GpioPinOutClear( LCD_PORT_SCS, LCD_PIN_SCS );
}
/**************************************************************************//**
 * @brief  Clear the display.
 *
 * @detail  This function clears the display.
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
static EMSTATUS DisplayClear ( void )
{
  uint16_t cmd;

  /* Set SCS */
  PAL_GpioPinOutSet( LCD_PORT_SCS, LCD_PIN_SCS );

  /* SCS setup time: min 6us */
  PAL_TimerMicroSecondsDelay(6);

  /* Send command */
  cmd = LS013B7DH03_CMD_ALL_CLEAR | lcdPolarity;
  PAL_SpiTransmit ((uint8_t*) &cmd, 2 );

  /* SCS hold time: min 2us */
  PAL_TimerMicroSecondsDelay(2);

  /* Clear SCS */
  PAL_GpioPinOutClear( LCD_PORT_SCS, LCD_PIN_SCS );

  return DISPLAY_EMSTATUS_OK;
}
/**************************************************************************//**
 * @brief   Inverse polarity across the Liquid Crystal cells in the display.
 *
 * @detail  This function inverses the polarity across the Liquid Crystal cells
 *          in the LCD. Must be called at least every second.
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
static EMSTATUS DisplayPolarityInverse (void)
{
#ifdef POLARITY_INVERSION_EXTCOMIN

  /* Toggle extcomin gpio */
  PAL_GpioPinOutToggle( LCD_PORT_EXTCOMIN, LCD_PIN_EXTCOMIN );

#else /* POLARITY_INVERSION_EXTCOMIN */

  /* Send a packet with inverted com */
  PAL_GpioPinOutSet( LCD_PORT_SCS, LCD_PIN_SCS );

  /* SCS setup time: min 6us */
  PAL_TimerMicroSecondsDelay(6);

  /* Send polarity command including dummy bits */
  PAL_SpiTransmit ((uint8_t*) &lcdPolarity, 2 );

  /* SCS hold time: min 2us */
  PAL_TimerMicroSecondsDelay(2);

  PAL_GpioPinOutClear( LCD_PORT_SCS, LCD_PIN_SCS );

  /* Invert com polarity */
  if (lcdPolarity == 0x00)
  {
    lcdPolarity = 0x02;
  }
  else
  {
    lcdPolarity = 0x00;
  }

#endif /* POLARITY_INVERSION_EXTCOMIN */

  return DISPLAY_EMSTATUS_OK;
}
/**************************************************************************//**
 * @brief Move and show the contents of a pixel matrix buffer onto the display.
 *
 * @param[in] device       Display device pointer.
 * @param[in] pixelMatrix  Pointer to the pixel matrix buffer to draw.
 * @param[in] startColumn  Start column on the display where to start
 *                         drawing the pixel matrix. Must be 0 if addressing
 *                         mode is DISPLAY_ADDRESSING_BY_ROWS_ONLY.
 * @param[in] width        Width in pixel columns of the pixel matrix to draw
 *                         Must be max width of display if the addresssing
 *                         mode is DISPLAY_ADDRESSING_BY_ROWS_ONLY.
 * @param[in] startRow     Start row on the display where to start drawing
 *                         the pizel matrix.
 * @param[in] height       Height in pixel rows/lines of the pixel matrix.
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
static EMSTATUS PixelMatrixDraw( DISPLAY_Device_t*      device,
                                 DISPLAY_PixelMatrix_t  pixelMatrix,
                                 unsigned int           startColumn,
                                 unsigned int           width,
#ifdef EMWIN_WORKAROUND
                                 unsigned int           userStride,
#endif
                                 unsigned int           startRow,
                                 unsigned int           height )
{
  unsigned int i;
  uint16_t*    p = (uint16_t *)pixelMatrix;
  uint16_t     cmd;
#ifdef EMWIN_WORKAROUND
  int          strideGap =
    (userStride-width-(LS013B7DH03_CONTROL_BYTES*8)) / 8 / sizeof(uint16_t);
  if ((userStride-width) % sizeof(uint16_t))
    return DISPLAY_EMSTATUS_INVALID_PARAMETER;
#else
  (void) width;  /* Suppress compiler warning: unused parameter. */
#endif
  (void) startColumn;  /* Suppress compiler warning: unused parameter. */
  (void) device; /* Suppress compiler warning: unused parameter. */

  /* Need to adjust start row by one because LS013B7DH03 starts counting lines
     from 1, while the DISPLAY interface starts from 0. */
  startRow++;

#ifdef USE_CONTROL_BYTES
  /* Setup line addressing in control words. */
  pixelMatrixSetup(pixelMatrix, startRow, height
#ifdef EMWIN_WORKAROUND
                   , userStride
#endif
                   );
#endif

  /* Assert SCS */
  PAL_GpioPinOutSet( LCD_PORT_SCS, LCD_PIN_SCS );

  /* SCS setup time: min 6us */
  PAL_TimerMicroSecondsDelay(6);

  /* Send update command and first line address */
  cmd = LS013B7DH03_CMD_UPDATE | (startRow << 8);
  PAL_SpiTransmit((uint8_t*) &cmd, 2 );

  /* Get start address to draw from */
  for ( i=0; i<height; i++ ) {

    /* Send pixels for this line */
    PAL_SpiTransmit((uint8_t*) p,
                    LS013B7DH03_WIDTH/8 + LS013B7DH03_CONTROL_BYTES);
    p+=(LS013B7DH03_WIDTH/8 + LS013B7DH03_CONTROL_BYTES) / sizeof(uint16_t);

#ifndef USE_CONTROL_BYTES
    if (i==height-1)
    {
      cmd = 0xffff;
    }
    else
    {
      cmd = 0xff | ((startRow+i+1) << 8);
    }
    PAL_SpiTransmit((uint8_t*) &cmd, 2 );
#endif

#ifdef EMWIN_WORKAROUND
    p += strideGap;
#endif

  }

  /* SCS hold time: min 2us */
  PAL_TimerMicroSecondsDelay(2);

  /* De-assert SCS */
  PAL_GpioPinOutClear( LCD_PORT_SCS, LCD_PIN_SCS );

  return DISPLAY_EMSTATUS_OK;
}