예제 #1
0
/*---------------------------------------------------------------------------*
 * Routine:  LCD_RH320240T_Configure
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the LCD to use a particular LCD controller.
 * Inputs:
 *      void *aW                -- Workspace
 * Outputs:
 *      T_uezError               -- If the device is successfully configured,
 *                                  returns UEZ_ERROR_NONE.
 *---------------------------------------------------------------------------*/
T_uezError LCD_RH320240T_Configure(
            void *aW,
            HAL_LCDController **aLCDController,
            TUInt32 aBaseAddress,
            DEVICE_Backlight **aBacklight)
{
    T_uezDevice spi;
    T_uezDeviceWorkspace *p_spi;
//    T_uezDeviceWorkspace *p_gpio2;

    T_RH320240TWorkspace *p = (T_RH320240TWorkspace *)aW;
    p->iLCDController = aLCDController;
    p->iBaseAddress = aBaseAddress;

    p->iBacklight = aBacklight;

    UEZDeviceTableFind(p->iSPIBus, &spi);
    UEZDeviceTableGetWorkspace(spi, (T_uezDeviceWorkspace **)&p_spi);

    p->iSPI = (DEVICE_SPI_BUS **)p_spi;

    p->r.iDataMOSI = p->iCmd;
    p->r.iDataMISO = p->iCmd;
    p->r.iNumTransfers = 0;
    p->r.iBitsPerTransfer = 8;
    p->r.iRate = 9000;
    p->r.iClockOutPolarity = ETrue;//EFalse;
    p->r.iClockOutPhase = ETrue;
    p->r.iCSGPIOPort = GPIO_TO_HAL_PORT(p->iCSGPIOPin);
    p->r.iCSGPIOBit = GPIO_TO_PIN_BIT(p->iCSGPIOPin);
    p->r.iCSPolarity = EFalse; // LOW true
    return UEZ_ERROR_NONE;
}
예제 #2
0
T_uezError RS485_Generic_Timer_Create(
    const char *aName,
    const T_RS485_Generic_Timer_Settings *aSettings)
{
    T_uezDeviceWorkspace *p;
    HAL_Serial **p_serial;
    HAL_Timer **p_timer;

    UEZDeviceTableRegister(aName,
        (T_uezDeviceInterface *)&RS485_Generic_Timer_Stream_Interface, 0, &p);
    HALInterfaceFind(aSettings->iSerialName, (T_halWorkspace **)&p_serial);
    HALInterfaceFind(aSettings->iTimerName, (T_halWorkspace **)&p_timer);
    return RS485_Generic_Timer_Configure(p, p_serial,
        aSettings->iQueueSendSize, aSettings->iQueueReceiveSize,
        GPIO_TO_HAL_PORT(aSettings->iDriveEnable),
        GPIO_TO_PIN_BIT(aSettings->iDriveEnable),
        aSettings->iDriveEnablePolarity,
        GPIO_TO_HAL_PORT(aSettings->iReceiveEnable),
        GPIO_TO_PIN_BIT(aSettings->iReceiveEnable),
        aSettings->iReceiveEnablePolarity, p_timer, aSettings->iReleaseTime,
        aSettings->iDriveTime);
}
예제 #3
0
static T_uezError SPIWriteCmd(
        T_LQ043T1DG28Workspace *p,
        const T_lcdSPICmd *aCmd)
{
    SPI_Request r;
    TUInt8 cmd[3];
    TUInt8 data[3];
    T_uezError error = UEZ_ERROR_NONE;

#define LCD_SPI_WRITE       (0<<0)
#define LCD_SPI_READ        (1<<0)
#define LCD_SPI_CMD         (0<<1)
#define LCD_SPI_DATA        (1<<1)
#define LCD_SPI_ID0         (0<<2)
#define LCD_SPI_ID1         (1<<2)

    cmd[0] = 0x74|LCD_SPI_ID0|LCD_SPI_WRITE|LCD_SPI_CMD; 
    cmd[1] = 0x00;
    cmd[2] = aCmd->iReg;
    r.iNumTransfers = 3;
    r.iBitsPerTransfer = 8;
    r.iRate = 1000; // spec says 12 MHz, but we'll start slow at 1 MHz
    r.iClockOutPolarity = ETrue; // rising edge
    r.iClockOutPhase = ETrue;
    r.iCSGPIOPort = GPIO_TO_HAL_PORT(p->iCSGPIOPin);
    r.iCSGPIOBit = GPIO_TO_PIN_BIT(p->iCSGPIOPin);
    r.iCSPolarity = EFalse;
    r.iDataMISO = cmd;
    r.iDataMOSI = cmd;
    error = UEZSPITransferPolled(p->iSPI, &r);

    if (!error) {
        data[0] = 0x74|LCD_SPI_ID0|LCD_SPI_WRITE|LCD_SPI_DATA;
        data[1] = aCmd->iData>>8;
        data[2] = aCmd->iData & 0xFF;
        r.iDataMOSI = data;
        r.iDataMISO = data;
        error = UEZSPITransferPolled(p->iSPI, &r);
    }
예제 #4
0
/*--------------------------------------------------------------------------*/
T_uezError GainSpan_CmdLib_ConfigureForSPI(
    const T_GainSpan_CmdLib_SPISettings *aSettings)
{
    T_uezError error;
    ATLIBGS_MSG_ID_E r;
    int i;

    G_GSCmdLibSettings = *aSettings;
    G_GSSPITemplate.iBitsPerTransfer = 8;
    G_GSSPITemplate.iCSPolarity = EFalse; // Falling edge
    G_GSSPITemplate.iClockOutPolarity = EFalse; // Falling edge
    G_GSSPITemplate.iClockOutPhase = EFalse; // ETrue;
    G_GSSPITemplate.iDataMISO = 0;
    G_GSSPITemplate.iDataMISO = 0;
    G_GSSPITemplate.iNumTransferredIn = 0;
    G_GSSPITemplate.iNumTransferredOut = 0;
    G_GSSPITemplate.iRate = aSettings->iRate / 1000;
    G_GSSPITemplate.iCSGPIOPort = GPIO_TO_HAL_PORT(aSettings->iSPIChipSelect);
    G_GSSPITemplate.iCSGPIOBit = GPIO_TO_PIN_BIT(aSettings->iSPIChipSelect);

    error = UEZSPIOpen(G_GSCmdLibSettings.iSPIDeviceName, &G_GSSPI);
    if (error)
        return error;

    // Ensure these pins are not configured elsewhere
    UEZGPIOLock(G_GSCmdLibSettings.iDataReadyIO);

    if (G_GSCmdLibSettings.iSRSTn != GPIO_NONE ){
        UEZGPIOLock(G_GSCmdLibSettings.iSRSTn);
        UEZGPIOOutput(G_GSCmdLibSettings.iSRSTn);       // WIFI_SRSTn
    }

    UEZGPIOInput(G_GSCmdLibSettings.iDataReadyIO);       // WIFI IRQ

    if (G_GSCmdLibSettings.iProgramMode != GPIO_NONE ) {
        UEZGPIOLock(G_GSCmdLibSettings.iProgramMode);
        UEZGPIOClear(G_GSCmdLibSettings.iProgramMode);       // WIFI PROGRAM OFF
        UEZGPIOOutput(G_GSCmdLibSettings.iProgramMode);      // WIFI PROGRAM OFF
    }

    if (G_GSCmdLibSettings.iSPIMode != GPIO_NONE ) {
        UEZGPIOLock(G_GSCmdLibSettings.iSPIMode);
        UEZGPIOSet(G_GSCmdLibSettings.iSPIMode);          // WIFI_MODE SPI
        UEZGPIOOutput(G_GSCmdLibSettings.iSPIMode);       // WIFI_MODE SPI
    }

    UEZTaskDelay(1250);

    if (G_GSCmdLibSettings.iSRSTn != GPIO_NONE )
        UEZGPIOSet(G_GSCmdLibSettings.iSRSTn);          // WIFI_SRSTn

    UEZTaskDelay(1000);

    // Initialize the GainSpan SPI routines
    GainSpan_SPI_Start();

    // Flush anything there
    AtLibGs_FlushIncomingMessage();

    /* Send command to check 5 times for module */
    for (i = 0; i < 5; i++){
        AtLibGs_FlushIncomingMessage();
        r = AtLibGs_Check(GAINSPAN_AT_DEFAULT_TIMEOUT);
        if(ATLIBGS_MSG_ID_OK == r){
        break;
        }
    }
    if(ATLIBGS_MSG_ID_RESPONSE_TIMEOUT == r){
         return UEZ_ERROR_NOT_FOUND;
    }

    /* Send command to DISABLE echo */
    do {
        r = AtLibGs_SetEcho(ATLIBGS_DISABLE);
    } while (ATLIBGS_MSG_ID_OK != r);

    // For now, just report it is not found
    if (r != ATLIBGS_MSG_ID_OK)
        return UEZ_ERROR_NOT_FOUND;

    return UEZ_ERROR_NONE;
}