/*******************************************************************************
 * @fn      SensorTagDisplay_suspend
 *
 * @brief   Releases the SPI driver for use by other devices. Power to the LCD
 *          is retained.
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagDisplay_suspend(void)
{
    Display_clear(handle);
    Display_print0(handle, DISPLAY_LINE_DEFAULT, 2, "Display off");

    Display_control(handle, DISPLAY_CMD_TRANSPORT_CLOSE, NULL);
}
Exemplo n.º 2
0
/**************************************************************************//**
 * @brief  Initialize the LS013B7DH03 display driver
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
bool Display_init(void) {
    /* Initialize the Platform Abstraction Layer (PAL) interface.  */
    PAL_TimerInit();
    PAL_SpiInit();
    PAL_GpioInit();

    /* Setup GPIOs */
    PAL_GpioPinModeSet(LCD_PORT_SCLK, LCD_PIN_SCLK, palGpioModePushPull, 0);
    PAL_GpioPinModeSet(LCD_PORT_SI,   LCD_PIN_SI,   palGpioModePushPull, 0);
    PAL_GpioPinModeSet(LCD_PORT_SCS,  LCD_PIN_SCS,  palGpioModePushPull, 0);

    PAL_GpioPinModeSet(LCD_PORT_DISP_PWR,LCD_PIN_DISP_PWR,palGpioModePushPull,0);

    PAL_GpioPinModeSet(LCD_PORT_EXTCOMIN,LCD_PIN_EXTCOMIN,palGpioModePushPull,0);

    /* Setup system (via PAL) to toggle the EXTCOMIN pin every second. */
    if (PAL_GpioPinAutoToggle(LCD_PORT_EXTCOMIN, LCD_PIN_EXTCOMIN,
                              LS013B7DH03_POLARITY_INVERSION_FREQUENCY)
        != PAL_EMSTATUS_OK)
    {
        return false;
    }

    Display_enable(true);
    Display_clear();

    return true;
}
/*******************************************************************************
 * @fn      SensorTagDisplay_resume
 *
 * @brief   Reconnects the SPI driver for use by this devices.
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagDisplay_resume(void)
{
    Display_control(handle, DISPLAY_CMD_TRANSPORT_OPEN, NULL);
    Display_clear(handle);
    Display_print0(handle, DISPLAY_LINE_DEFAULT, 2, "Display on");
}
/*******************************************************************************
 * @fn      SensorTagDisplay_showStatus
 *
 * @brief   Display main status parameters on the display.
 *
 *          - device name
 *          - device address
 *          - firmware revision
 *          - GAP connection status
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagDisplay_showStatus(void)
{
    if (handle != NULL)
    {
        uint8_t buf[24];
        char *gapStatusStr;

        // Make sure display is blank
        Display_clear(handle);

        // Line 0: device info
        DevInfo_GetParameter(DEVINFO_MODEL_NUMBER, buf);
        Display_print0(handle, DISPLAY_LINE_DEV_INFO, 0, (const char*)buf);

        // Line 1: board address
        GAPRole_GetParameter(GAPROLE_BD_ADDR, buf);
        Display_print0(handle, DISPLAY_LINE_BOARD_ADDR,
                       1, Util_convertBdAddr2Str(buf));

        // Line 2: firmware revision
        DevInfo_GetParameter(DEVINFO_FIRMWARE_REV, buf);
        Display_print0(handle, DISPLAY_LINE_FWREV, 1, "FW rev.");
        buf[5] = '\0'; // Display max 5 characters (leave out date part)
        Display_print0(handle, DISPLAY_LINE_FWREV, 10, (const char*)buf);

        // Line 11: GAP connection status
        switch (gapProfileState)
        {
        case GAPROLE_INIT:
            gapStatusStr = "Init";
            break;
        case GAPROLE_STARTED:
            gapStatusStr = "Started";
            break;
        case GAPROLE_ADVERTISING:
            gapStatusStr = "Advertising";
            break;
        case GAPROLE_ADVERTISING_NONCONN:
            gapStatusStr = "Advertising-nc";
            break;
        case GAPROLE_WAITING:
            gapStatusStr = "Waiting";
            break;
        case GAPROLE_WAITING_AFTER_TIMEOUT:
            gapStatusStr = "Waiting-tout";
            break;
        case GAPROLE_CONNECTED:
            gapStatusStr = "Connected";
            break;
        case GAPROLE_CONNECTED_ADV:
            gapStatusStr = "Connected-adv";
            break;
        case GAPROLE_ERROR:
            gapStatusStr = "Error";
            break;
        default:
            gapStatusStr = "Unknown";
            break;
        }
        Display_print0(handle, DISPLAY_LINE_GAP, 2, gapStatusStr);
    }
}
/*********************************************************************
 * @fn      SensorTagDisplay_processCharChangeEvt
 *
 * @brief   Process a change in the IO characteristics
 *
 * @return  none
 */
void SensorTagDisplay_processCharChangeEvt(uint8_t paramID)
{
    if (paramID == DISPLAY_CONF)
    {
        uint8_t config[DISPLAY_CONF_LEN];

        Display_getParameter(DISPLAY_CONF, config);

        // Execute the control sequence
        switch (config[DISPLAY_CMD_OFFSET])
        {
        case DISPLAY_CONF_OFF:
            if (handle != NULL)
            {
                // NB! Has no effect on SensorTag because LCD_ENABLE pin is
                // shared with UART_TX, causing the LCD to get enabled again
                // as soon as the PINs used by the LCD are released.
                Display_clear(handle);
                Display_print0(handle, DISPLAY_LINE_DEFAULT, 2, "Display off");

                Display_close(handle);
                handle = NULL;
            }
            break;

        case DISPLAY_CONF_ON:
            // Initialize LCD
            if (handle == NULL)
            {
                Display_Params params;
                Display_Params_init(&params);
                params.lineClearMode = DISPLAY_CLEAR_NONE;
                handle = Display_open(Display_Type_LCD, &params);

                // Update status
                SensorTagDisplay_showStatus();
            }
            break;

        case DISPLAY_CONF_CLR:
            // Clear display
            if (handle != NULL)
            {
                Display_clear(handle);
            }
            break;

        case DISPLAY_CONF_CLR_LINE:
            // Clear line
            pos.line = config[DISPLAY_LINE_OFFSET];
            if (handle != NULL)
            {
                Display_clearLines(handle, pos.line, pos.line);
            }
            break;

        case DISPLAY_CONF_INV:
            if (handle != NULL)
            {
                uint8_t tmp;

                // Swap foreground and background colors
                tmp = color.fg;
                color.fg = color.bg;
                color.bg = tmp;

                Display_control(handle, DISPLAYSHARP_CMD_SET_COLORS, &color);

                // Update status
                SensorTagDisplay_showStatus();
            }
            break;

        case DISPLAY_CONF_MOV:
            // Store active "cursor" position
            pos.line = config[DISPLAY_LINE_OFFSET];
            pos.column = config[DISPLAY_COL_OFFSET];

            break;

        default:
            break;
        }
    }

    if (paramID == DISPLAY_DATA && handle != NULL)
    {
        uint8_t data[DISPLAY_BUFFER_LEN];

        Display_getParameter(DISPLAY_DATA, data);
        Display_print0(handle, pos.line, pos.column, (const char*)data);
    }
}