示例#1
0
/*---------------------------------------------------------------------------*/
void UEZWAVConfig(TUInt8 onBoardSpeakerVolume)
{
    T_uezError error;

    if(UEZAudioAmpOpen("AMP0", &amp) == UEZ_ERROR_NONE){
        UEZAudioAmpSetLevel(amp, onBoardSpeakerVolume);
        G_AudioAmpOpen = ETrue;
    }
    
    volume = onBoardSpeakerVolume;
    error = UEZDeviceTableFind("AudioCodec0", &p_ac);
    error = UEZDeviceTableGetWorkspace(p_ac, (T_uezDeviceWorkspace **)&ac);

    (*ac)->UseConfiguration((void*)ac, 1);
    if(error != UEZ_ERROR_NONE){
        (*ac)->UseConfiguration((void*)ac, 1);
    }

    wav = UEZMemAlloc(DATA_TO_READ);
    wav2 = UEZMemAlloc(DATA_TO_READ);

    error = UEZDeviceTableFind("I2S", &p_i2s);
    error = UEZDeviceTableGetWorkspace(p_i2s, (T_uezDeviceWorkspace **)&i2s);

    (*i2s)->Configure((void*)i2s, (HAL_I2S_Callback_Transmit_Low) i2sCallBack);
    
    UEZSemaphoreCreateBinary(&wavSem);
    playStatus = EFalse;
}
示例#2
0
/*---------------------------------------------------------------------------*/
T_uezError UEZTSOpen(
            const char * const aName,
            T_uezDevice *aDevice,
            T_uezQueue *aEventQueue)
{
    T_uezError error;
    DEVICE_TOUCHSCREEN **p;

    if (!G_tsDidInit)
        IUEZTSInitialize();

    error = UEZDeviceTableFind(aName, aDevice);
    if (error)
        return error;

    error = UEZDeviceTableGetWorkspace(*aDevice, (T_uezDeviceWorkspace **)&p);
    if (error)
        return error;

    error = (*p)->Open((void *)p);
    if (error)
        return error;

    if (aEventQueue)
        UEZTSAddQueue(*aDevice, *aEventQueue);

    return error;
}
示例#3
0
/*---------------------------------------------------------------------------*
 * Routine:  UEZPlatform_Speaker_Require
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the Speaker device driver
 *---------------------------------------------------------------------------*/
void UEZPlatform_Speaker_Require(void)
{
    const T_ToneGenerator_Generic_PWM_Settings settings = {
            "PWM_TPU0",
            1,
            GPIO_NONE,
            0,
            0,
    };
	T_uezDevice pwmDevice;
	
    DEVICE_CREATE_ONCE();

	UEZPlatform_PWM_TPU0_Require();
	UEZDeviceTableFind("PWM_TPU0", &pwmDevice);
	
	// The PWM Speaker is output by setting and clearing a GPIO pin
	// through software by using Callback routines.
	UEZGPIOClear(GPIO_P17);	// AUD_R
	UEZGPIOOutput(GPIO_P17);
	
	UEZGPIOClear(GPIO_PA0);	// AUD_L
	UEZGPIOOutput(GPIO_PA0);
	
	UEZGPIOSet(GPIO_PA2);	// AMP
	UEZGPIOOutput(GPIO_PA2);
	
	UEZPWMSetMatchCallback(pwmDevice, 0, UEZPlatform_SpeakerMasterCallback, 0);
	UEZPWMSetMatchCallback(pwmDevice, 1, UEZPlatform_SpeakerMatchCallback, 0);

    ToneGenerator_Generic_PWM_Create("Speaker", &settings);
}
示例#4
0
/******************************************************************************
* ID : 60.0
* Outline : Glyph_uEZ_Open
* Include : Glyph_uEZ_0.h
* Function Name: Glyph_uEZ_Open
* Description : Open and setup the communications channel 0.
* Argument : aHandle - the Glyph handle to setup for the LCD and Communications.
* Return Value : 0=success, not 0= error
* Calling Functions : GlyphCommOpen
******************************************************************************/
T_glyphError Glyph_uEZ_Open(T_glyphHandle aHandle)
{
    int i = 0 ;
    T_uezDevice dev;
    T_uezDeviceWorkspace *G_gpioC;
    
    if (G_spi == 0)  {
        UEZDeviceTableFind("SPI0", &dev);
        UEZDeviceTableGetWorkspace(dev, (T_uezDeviceWorkspace **)&G_spi);
        HALInterfaceFind("GPIOC", (T_halWorkspace **)&G_gpioC);

        G_request.iBitsPerTransfer = 8;
        // Chip select on Port C2 (high true)
        G_request.iCSGPIOPort = (HAL_GPIOPort **)G_gpioC;
        G_request.iCSGPIOBit = (1<<2);
        G_request.iCSPolarity = EFalse;
        G_request.iClockOutPhase = EFalse;
        G_request.iClockOutPolarity = EFalse;
        G_request.iDataMISO = 0;
        G_request.iDataMOSI = 0;
        G_request.iNumTransfers = 0;
        G_request.iRate = 12000; // 12 MHz for now

        /* Set data direction for this bit to output */
        PORTC.DDR.BIT.B3 = 1 ;   // LCD GPIO for Reset LCD
        PORT5.DDR.BIT.B1 = 1 ;   // LCD RS A0

        StartResetLCD() ;
        for (i=0;i<1000000;i++){}
        EndResetLCD() ;
        for (i=0;i<1000000;i++){}
    }

    return GLYPH_ERROR_NONE ;
}
T_uezError Keypad_NXP_PCA9555_Create(
        const char *aName,
        const char *aI2CBusName,
        TUInt8 aI2CAddr,
        const char *aExternalInterruptsName,
        TUInt8 aExternalInterruptChannel)
{
    T_Keypad_NXP_I2C_PCA9555_Workspace *p;
    T_uezDevice i2c;
    DEVICE_I2C_BUS **p_i2c;
    T_uezError error;

    UEZDeviceTableRegister(aName,
            (T_uezDeviceInterface *)&Keypad_NXP_PCA9555_Interface, 0,
            (T_uezDeviceWorkspace **)&p);

    error = UEZDeviceTableFind(aI2CBusName, &i2c);
    if (error)
        return error;
    UEZDeviceTableGetWorkspace(i2c, (T_uezDeviceWorkspace **)&p_i2c);

    error = Keypad_NXP_PCA9555_Configure(p, p_i2c, aI2CAddr, aExternalInterruptsName,
        aExternalInterruptChannel);
    return error;
}
示例#6
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;
}
示例#7
0
/*---------------------------------------------------------------------------*
 * Routine:  UEZPlatform_FileSystem_Require
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the File System using FATFS
 *---------------------------------------------------------------------------*/
void UEZPlatform_FileSystem_Require(void)
{
    T_uezDevice dev_fs;

    DEVICE_CREATE_ONCE();

    FileSystem_FATFS_Create("FATFS");
    UEZDeviceTableFind("FATFS", &dev_fs);
    UEZFileSystemInit();
    UEZFileSystemMount(dev_fs, "/");
}
示例#8
0
/*---------------------------------------------------------------------------*
 * Routine:  UEZGUI_EXP_DK_AudioCodec_Require
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the WM8731 AudioCodec for directing audio in and out.
 *---------------------------------------------------------------------------*/
void UEZGUI_EXP_DK_AudioCodec_Require(void)
{
    T_uezDevice p_ac;
    DEVICE_AudioCodec **ac;

    DEVICE_CREATE_ONCE();

    AudioCodec_WM8731_ADXL345_Create("EXP_AudioCodec0", EXPDK_AUDIO_I2C);
    UEZDeviceTableFind("EXP_AudioCodec0", &p_ac);
    UEZDeviceTableGetWorkspace(p_ac, (T_uezDeviceWorkspace **)&ac);

    // Configure so that both audio inputs are output to the headphones.
    (*ac)->UseConfiguration((void*)ac, 0);
}
示例#9
0
/*---------------------------------------------------------------------------*/
T_uezError UEZStreamOpen(const char * const aName, T_uezDevice *aDevice) {
    T_uezError error;
    DEVICE_STREAM **p;

    error = UEZDeviceTableFind(aName, aDevice);
    if (error)
        return error;

    error = UEZDeviceTableGetWorkspace(*aDevice, (T_uezDeviceWorkspace **) &p);
    if (error)
        return error;

    return (*p)->Open((void *) p);
}
示例#10
0
/*---------------------------------------------------------------------------*/
T_uezError UEZEEPROMOpen(const char * const aName, T_uezDevice *aDevice)
{
    DEVICE_EEPROM **p_eeprom;
    T_uezError error;

    // Find the eeprom0 device
    error = UEZDeviceTableFind(aName, aDevice);
    if (error)
        return error;

    // look up the workspace, return any errors
    return UEZDeviceTableGetWorkspace(*aDevice,
        (T_uezDeviceWorkspace **)&p_eeprom);
}
示例#11
0
/*---------------------------------------------------------------------------*
 * Routine:  UEZPlatform_SDCard_Drive_Require
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the SDCard drive using MS1 on the given drive number
 *---------------------------------------------------------------------------*/
void UEZPlatform_SDCard_Drive_Require(TUInt8 aDriveNum)
{
    T_uezDevice ms1;
    T_uezDeviceWorkspace *p_ms1;

    DEVICE_CREATE_ONCE();

    UEZPlatform_MS1_Require();
    UEZPlatform_FileSystem_Require();

    UEZDeviceTableFind("MS1", &ms1);
    UEZDeviceTableGetWorkspace(ms1, (T_uezDeviceWorkspace **)&p_ms1);
    FATFS_RegisterMassStorageDevice(aDriveNum, (DEVICE_MassStorage **)p_ms1);
}
示例#12
0
void LCD_LQ104V1DG28_Create(char* aName,
                            T_uezGPIOPortPin aStandByControlPin)
{
    T_LQ104V1DG28Workspace *p;
    T_uezDevice lcd;
    T_uezDeviceWorkspace *p_lcd;

    UEZDeviceTableFind(aName, &lcd);
    UEZDeviceTableGetWorkspace(lcd, &p_lcd);

    p = (T_LQ104V1DG28Workspace*)p_lcd;

    p->iStandByControlPin;

    UEZGPIOClear(p->iStandByControlPin);
}
示例#13
0
/*---------------------------------------------------------------------------*/
T_uezError UEZAccelerometerOpen(const char * const aName, T_uezDevice *aDevice)
{
    T_uezError error;
    DEVICE_Accelerometer **p;

    error = UEZDeviceTableFind(aName, aDevice);
    if (error)
        return error;

    error = UEZDeviceTableGetWorkspace(*aDevice, (T_uezDeviceWorkspace **)&p);
    if (error)
        return error;

    // Nothing special done here
    return UEZ_ERROR_NONE;
}
示例#14
0
void RTC_PCF8563_Create(const char *aName, const char *aI2CBusName)
{
    T_uezDeviceWorkspace *p_rtcdev;
    T_uezDevice i2c;
    T_uezDeviceWorkspace *p_i2c;

    // Setup with exteranl RTC
    UEZDeviceTableRegister(
            aName,
            (T_uezDeviceInterface *)&RTC_NXP_PCF8563_Interface,
            0,
            &p_rtcdev);
    UEZDeviceTableFind(aI2CBusName, &i2c);
    UEZDeviceTableGetWorkspace(i2c, &p_i2c);
    RTC_PCF8563_Configure(p_rtcdev, (DEVICE_I2C_BUS **)p_i2c);
}
示例#15
0
/*---------------------------------------------------------------------------*/
T_uezError UEZNetworkOpen(
        const char * const aName,
        T_uezDevice *aNetworkDevice)
{
    T_uezError error;
    DEVICE_Network **p;

    error = UEZDeviceTableFind(aName, aNetworkDevice);
    if (error)
        return error;

    error = UEZDeviceTableGetWorkspace(*aNetworkDevice, (T_uezDeviceWorkspace **)&p);
    if (error)
        return error;

    return (*p)->Open((void *)p);
}
示例#16
0
void LCD_43WQW1T_Create(char* aName,
                        char* aSPIBus,
                        T_uezGPIOPortPin aSPICSPin)
{
    T_43WQW1TWorkspace *p;

    T_uezDevice lcd;
    T_uezDeviceWorkspace *p_lcd;

    UEZDeviceTableFind(aName, &lcd);
    UEZDeviceTableGetWorkspace(lcd, &p_lcd);

    p = (T_43WQW1TWorkspace *)p_lcd;

    strcpy(p->iSPIBus, aSPIBus);
    p->iCSGPIOPin = aSPICSPin;
}
void Temp_NXP_SA56004X_Remote_Create(
        const char *aName,
        const char *aI2CBusName,
        TUInt8 aI2CAddr)
{
    T_uezDeviceWorkspace *p_temp0;
    T_uezDevice i2c;
    T_uezDeviceWorkspace *p_i2c;

    // Setup the temperature 0 device
    UEZDeviceTableRegister(aName,
        (T_uezDeviceInterface *)&Temperature_NXP_SA56004X_Remote_Interface, 0,
        &p_temp0);
    UEZDeviceTableFind(aI2CBusName, &i2c);
    UEZDeviceTableGetWorkspace(i2c, (T_uezDeviceWorkspace **)&p_i2c);
    Temp_NXP_SA56004X_Configure(p_temp0, (DEVICE_I2C_BUS **)p_i2c, aI2CAddr);
}
示例#18
0
/*---------------------------------------------------------------------------*/
T_uezError UEZLEDBankOpen(
            const char *const aName, 
            T_uezDevice *aDevice)
{
    T_uezError error;
    DEVICE_LEDBank **p;
    
    error = UEZDeviceTableFind(aName, aDevice);
    if (error)
        return error;

    error = UEZDeviceTableGetWorkspace(*aDevice, (T_uezDeviceWorkspace **)&p);
    if (error)
        return error;

    return error;
}
/*---------------------------------------------------------------------------*
 * Routine:  Keypad_NXP_I2C_PCA9555_Configure
 *---------------------------------------------------------------------------*
 * Description:
 *      Configure the PCA9555's I2C setting.
 * Inputs:
 *      void *aW                    -- Workspace
 *      DEVICE_I2C_BUS **aI2C       -- I2C interface
 *---------------------------------------------------------------------------*/
T_uezError Keypad_NXP_PCA9555_Configure(
        void *aWorkspace, 
        DEVICE_I2C_BUS **aI2C,
        TUInt8 aI2CAddr,
        const char *aExternalInterruptsName,
        TUInt8 aExternalInterruptChannel)
{
    T_Keypad_NXP_I2C_PCA9555_Workspace *p = 
        (T_Keypad_NXP_I2C_PCA9555_Workspace *)aWorkspace;
    
    T_uezError error;

    // Set the I2C bus
    p->iI2C = aI2C;
    p->iI2CAddr = aI2CAddr;

#if KEYPAD_USES_EXTERNAL_IRQ
    // Setup the external interrupt
    error = UEZDeviceTableFind(aExternalInterruptsName, (T_uezDevice *)&p->eintDevice);
    if (error)
        return error;
    UEZDeviceTableGetWorkspace(p->eintDevice, (T_uezDeviceWorkspace **)&p->iEINT);

    error = (*p->iEINT)->Set(
                p->iEINT,
                KEYPAD_EINT2_CHANNEL,
                EINT_TRIGGER_EDGE_FALLING,
                Keypad_NXP_PCA9555_Callback,
                (void *)p,
                INTERRUPT_PRIORITY_HIGH,
                "EINT2n:KEYPAD_IRQ");
    if (error)
        return error;
#endif

    error = UEZTaskCreate(
                (T_uezTaskFunction)Keypad_NXP_I2C_PCA9555_Monitor,
                "Keypad",
                128,
                aWorkspace,
                UEZ_PRIORITY_HIGH,
                &p->iMonitorTask);

    return error;
}
/*---------------------------------------------------------------------------*
 * Routine:  ST_Accelo_LIS3LV02DQ_I2C_Create
 *---------------------------------------------------------------------------*
 * Description:
 *      Create an accelerometer driver for the Freescale MMA7455.
 * Inputs:
 *      const char *aName -- Name of this created driver
 *      const char *aI2CBusName -- Name of I2C bus device driver used by this
 *          accelerometer.
 * Outputs:
 *      T_uezError -- Error code.
 *---------------------------------------------------------------------------*/
T_uezError ST_Accelo_LIS3LV02DQ_I2C_Create(
        const char *aName,
        const char *aI2CBusName)
{
    T_uezDeviceWorkspace *p_accel;
    T_uezDevice i2c;
    T_uezDeviceWorkspace *p_i2c;

    // Setup the accelerator device
    UEZDeviceTableRegister(
            aName,
            (T_uezDeviceInterface *)&Accelerometer_ST_LIS3LV02DQ_via_I2C_Interface,
            0, &p_accel);
    UEZDeviceTableFind(aI2CBusName, &i2c);
    UEZDeviceTableGetWorkspace(i2c, (T_uezDeviceWorkspace **)&p_i2c);
    return ST_Accelo_LIS3LV02DQ_Configure(p_accel,
            (DEVICE_I2C_BUS **)p_i2c);
}
/*---------------------------------------------------------------------------*
 * Routine:  Accelerometer_Freescale_MMA7455_I2C_Create
 *---------------------------------------------------------------------------*
 * Description:
 *      Create an accelerometer driver for the Freescale MMA7455.
 * Inputs:
 *      const char *aName -- Name of this created driver
 *      const char *aI2CBusName -- Name of I2C bus device driver used by this
 *          accelerometer.
 *      TUInt8 aI2CAddr -- 7-bit address (lower 7 bits) of I2C address of
 *          accelerometer.
 * Outputs:
 *      T_uezError -- Error code.
 *---------------------------------------------------------------------------*/
T_uezError Accelerometer_Freescale_MMA7455_I2C_Create(
        const char *aName,
        const char *aI2CBusName,
        TUInt8 aI2CAddr)
{
    T_uezDeviceWorkspace *p_accel;
    T_uezDevice i2c;
    T_uezDeviceWorkspace *p_i2c;

    // Setup the accelerator device
    UEZDeviceTableRegister(
            aName,
            (T_uezDeviceInterface *)&Accelerometer_Freescale_MMA7455_I2C_Interface,
            0, &p_accel);
    UEZDeviceTableFind(aI2CBusName, &i2c);
    UEZDeviceTableGetWorkspace(i2c, (T_uezDeviceWorkspace **)&p_i2c);
    return Accelerometer_Freescale_MMA7455_I2C_Configure(p_accel,
            (DEVICE_I2C_BUS **)p_i2c, aI2CAddr);
}
示例#22
0
/*---------------------------------------------------------------------------*
 * Routine:
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the I2C GPIO LEDs on EXPDK_I2C-A
 *---------------------------------------------------------------------------*/
void UEZGUI_EXP_DK_LED_Require(void)
{
    T_uezDeviceWorkspace *p_led0;
    T_uezDevice i2c;
    T_uezDeviceWorkspace *p_i2c;

    DEVICE_CREATE_ONCE();
    UEZGUI_EXP_DK_I2CMux_Require();
    // In order to use this, it must use EXPDK_I2C-A provided by the I2C Mux
    UEZDeviceTableFind("EXPDK_I2C-A", &i2c);
    UEZDeviceTableGetWorkspace(i2c, (T_uezDeviceWorkspace **)&p_i2c);

    UEZDeviceTableRegister(
        "LEDBank0",
        (T_uezDeviceInterface *)&LEDBank_NXP_PCA9551_Interface,
        0,
        &p_led0);
    LED_NXP_PCA9551_Configure(p_led0, (DEVICE_I2C_BUS **)p_i2c, 0xC0>>1);
}
示例#23
0
/*---------------------------------------------------------------------------*/
T_uezError UEZKeypadOpen(
            const char *const aName, 
            T_uezDevice *aDevice,
            T_uezQueue *aEventQueue)
{
    T_uezError error;
    DEVICE_Keypad **p;
    
    error = UEZDeviceTableFind(aName, aDevice);

    if(!error)
        error = UEZDeviceTableGetWorkspace(*aDevice, (T_uezDeviceWorkspace **)&p);
    
    if(!error)
        error = (*p)->Open(p); 
    
    if((!error) || (error == UEZ_ERROR_ALREADY_EXISTS)) {
        error = (*p)->Register(p, *aEventQueue);
    }
    
    return error;
}
/*---------------------------------------------------------------------------*
 * Routine:  ButtonBank_NXP_PCA9551_Create
 *---------------------------------------------------------------------------*
 * Description:
 *      Create a PCA9551 Button Bank driver.
 * Inputs:
 *      const char *aName           -- Name of this created device driver
 *      const char *aI2CBusName     -- I2C Bus to use
 *      TUInt8 aI2CAddr             -- 7-bit I2C address of PCA9551
 *---------------------------------------------------------------------------*/
T_uezError ButtonBank_NXP_PCA9551_Create(
    const char *aName,
    const char *aI2CBusName,
    TUInt8 aI2CAddr)
{
    void *p;
    T_uezDevice i2c;
    DEVICE_I2C_BUS **p_i2c;
    T_uezError error;

    UEZDeviceTableRegister(aName,
        (T_uezDeviceInterface *)&ButtonBank_NXP_PCA9551_Interface, 0,
        (T_uezDeviceWorkspace **)&p);

    error = UEZDeviceTableFind(aI2CBusName, &i2c);
    if (error)
        return error;

    UEZDeviceTableGetWorkspace(i2c, (T_uezDeviceWorkspace **)&p_i2c);

    ButtonBank_NXP_PCA9551_Configure(p, p_i2c, aI2CAddr);

    return UEZ_ERROR_NONE;
}
/*---------------------------------------------------------------------------*
 * Task:  FunctionalTestLoop
 *---------------------------------------------------------------------------*
 * Description:
 *      This enters loopback mode on the CAN and RS232 ports; This mode allows
 *      an ARM TS KIT to serve as counterparty for loopback of CAN and RS232
 *      traffic during functional test of ARM TS KITs and other devices
 *
 * Inputs:
 *---------------------------------------------------------------------------*/
void FunctionalTestLoop(const T_choice *aChoice)
{
//    unsigned int CANbyteA;
//    unsigned int CANbyteB;
//    unsigned int CANTXbyteA;
//    unsigned int CANTXbyteB;


    typedef struct {
        T_uezDevice iDevice;
        DEVICE_STREAM **iStream;
        char iReceived[5];
        TUInt32 iCount;
        TUInt32 iStart;
    } T_serialTest;

    T_serialTest testData;

    T_serialTest *p = &testData ;

    TUInt32 num;

    T_uezDevice lcd;
    T_uezDevice ts;
    T_uezError error;
    T_uezQueue queue;

    G_ttExit = EFalse;


    if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) {
        // Open up the touchscreen and pass in the queue to receive events
        if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE)  {
            // Open the LCD and get the pixel buffer
            if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE)  {

                error = UEZDeviceTableFind("Console", &p->iDevice);

                if (!error)
                    error = UEZDeviceTableGetWorkspace(p->iDevice, (T_uezDeviceWorkspace **)&p->iStream);
                if (error) {
                    return;
                }
                p->iCount = 0;


                // Flush the input buffer
                while ((*p->iStream)->Read(p->iStream, (TUInt8 *)p->iReceived, 5, &num, 500) != UEZ_ERROR_TIMEOUT) {
                }
                    // Put the draw screen up
                    FCTL_Screen(lcd);

                    // Sit here in a loop until we are done
                    while (!G_ttExit) {
                        ChoicesUpdate(&G_ttWin, G_ttChoices, queue, 500);
/*
                        if (CANReceive8(&CANbyteA, &CANbyteB)) // check for a couple of CAN bytes
                        {
                            CANTXbyteA = (CANbyteA + 0x01010101) ;
                            CANTXbyteB = (CANbyteB + 0x01010101) ;
                            CANSend8(CANTXbyteA, CANTXbyteB) ;
                        }
*/
                        // read a byte from the serial stream
                        num = 0;
                        (*p->iStream)->Read(p->iStream, (TUInt8 *)(p->iReceived + p->iCount), 1, &num, 100);
                        //p->iCount += num;
                        if (num == 1) {
                            if (memcmp(p->iReceived, "|", 1) == 0) {  // check to see if it's an or bar
                            // Send out "J.Ha" character string to the serial
                            error = (*p->iStream)->Write(p->iStream, "J.Ha", 4, &num, 400);  // reply
                                if (error) {
                                   return;
                                }
                            }
                        }
                  }
                  UEZLCDClose(lcd);
            }
            UEZTSClose(ts, queue);
        }
        UEZQueueDelete(queue);
      }
}
示例#26
0
void BrightnessControlMode(const T_choice *aChoice)
{
    T_uezDevice ts;
    static T_uezQueue queue = NULL;
    static T_brightnessControlWorkspace *G_ws = NULL;
    INT_32 winX, winY;
    T_uezInputEvent inputEvent;
#if ENABLE_UEZ_BUTTON
    T_uezDevice keypadDevice;
#endif
#if UEZ_ENABLE_LIGHT_SENSOR
    TUInt32 levelCurrent = 1, levelPrevious = 0;
    T_uezDevice ls;
    DEVICE_LightSensor **p;
    T_uezError error;
    char levelText[30];
    TBool lightSensorActive = EFalse;

    if( UEZDeviceTableFind("Light Sensor", &ls) == UEZ_ERROR_NONE) {
        if(UEZDeviceTableGetWorkspace(ls, (T_uezDeviceWorkspace **)&p) == UEZ_ERROR_NONE) {
            if((*p)->Open((void *)p, "I2C1") == UEZ_ERROR_NONE) {
                lightSensorActive = ETrue;
            }
        }
    }
#endif
#ifdef NO_DYNAMIC_MEMORY_ALLOC
    if (NULL == G_ws)
    {
        G_ws = UEZMemAlloc(sizeof(*G_ws));
    }
#else
    G_ws = UEZMemAlloc(sizeof(*G_ws));
#endif

#if UEZ_ENABLE_LIGHT_SENSOR
    UEZTaskSuspend(G_lightSensorTask);
#endif
    if (!G_ws)
        return;
    memset(G_ws, 0, sizeof(*G_ws));
    G_ws->iExit = EFalse;
    G_ws->iNeedUpdate = ETrue;

#ifdef NO_DYNAMIC_MEMORY_ALLOC
    if (NULL == queue)
    {
        if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) != UEZ_ERROR_NONE)
        {
            queue = NULL;
        }
    }

    if (NULL != queue) {
        /* Register the queue so that the IAR Stateviewer Plugin knows about it. */
        UEZQueueAddToRegistry( queue, "Brightness TS" );
#else
    if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) {
#if UEZ_REGISTER
        UEZQueueSetName(queue, "Brightness", "\0");
#endif
#endif
#if ENABLE_UEZ_BUTTON
        UEZKeypadOpen("BBKeypad", &keypadDevice, &queue);
#endif

        // Open up the touchscreen and pass in the queue to receive events
        if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE)  {

            // Open the LCD and get the pixel buffer
            if (UEZLCDOpen("LCD", &G_ws->iLCD) == UEZ_ERROR_NONE)  {
                UEZLCDGetBacklightLevel(G_ws->iLCD, &G_ws->iLevel, &G_ws->iNumLevels);

                // Put the screen up
                BCMScreen(G_ws);

                // Sit here in a loop until we are done
                while (!G_ws->iExit) {
                    // Do choices and updates
                    if (UEZQueueReceive(queue, &inputEvent, 500)==UEZ_ERROR_NONE) {
                        winX = inputEvent.iEvent.iXY.iX;
                        winY = inputEvent.iEvent.iXY.iY;
                        swim_get_virtual_xy(&G_win, &winX, &winY);
                        if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD)  {
                            // Are we in the panel?
                            if ((winY >= G_ws->iRSlidePanel.iTop) && (winY <= G_ws->iRSlidePanel.iBottom) &&
                                    (winX >= G_ws->iRSlidePanel.iLeft) && (winX <= G_ws->iRSlidePanel.iRight)) {
                                // Inside the panel and touching the screen, let's map this to an intensity
                                // of 0-255
                                if(winY > G_ws->iRGroove.iBottom)
                                    G_ws->iLevel = 0;
                                else
                                {
                                    G_ws->iLevel =
                                        (G_ws->iRGroove.iBottom - winY)*(G_ws->iNumLevels)/
                                        (1+G_ws->iRGroove.iBottom-G_ws->iRGroove.iTop);
                                }
                                UEZLCDSetBacklightLevel(G_ws->iLCD, G_ws->iLevel);
                                G_ws->iNeedUpdate = ETrue;
                            }
                        }
                        ChoicesUpdateByReading(&G_win, G_ws->iChoices, &inputEvent);
#if UEZ_ENABLE_LIGHT_SENSOR
                        if (lightSensorActive) {
                            levelCurrent = (*p)->GetLevel((void *)p);
                            if(levelCurrent == 0xFFFFFFFF) { //ligh sensor no longer resonding
                                lightSensorActive = EFalse;
                                break;
                            }
                            if( levelCurrent != levelPrevious) {
                                swim_set_font(&G_win, &APP_DEMO_DEFAULT_FONT);
                                swim_set_fill_color(&G_win, BLACK);
                                swim_set_pen_color(&G_win, BLACK);
                                sprintf(levelText, "Ambient Light Level: %04d lux\0", levelCurrent);
                                //erase old text
                                swim_put_box(&G_win,
                                             (UEZ_LCD_DISPLAY_WIDTH/2) - (swim_get_text_line_width(&G_win, levelText) /2),//x1
                                             BCM_SLIDE_PANEL_OUTER_PADDING,//y1
                                             (UEZ_LCD_DISPLAY_WIDTH/2) + (swim_get_text_line_width(&G_win, levelText) /2),//x2
                                             BCM_SLIDE_PANEL_OUTER_PADDING + swim_get_font_height(&G_win));//y2
                                //put new text
                                swim_set_pen_color(&G_win, YELLOW);
                                swim_put_text_xy(&G_win, levelText,
                                                 (UEZ_LCD_DISPLAY_WIDTH/2) - (swim_get_text_line_width(&G_win, levelText) /2),//x
                                                 (BCM_SLIDE_PANEL_OUTER_PADDING));//y
                                levelPrevious = levelCurrent;
                            }
                        }
#endif
                    }
                    if (G_ws->iNeedUpdate) {
                        BCMUpdate(G_ws);
                        G_ws->iNeedUpdate = EFalse;
                    }
                }
                UEZLCDClose(G_ws->iLCD);
            }
            UEZTSClose(ts, queue);
        }
#if ENABLE_UEZ_BUTTON
        UEZKeypadClose(keypadDevice, &queue);
#endif
#ifndef NO_DYNAMIC_MEMORY_ALLOC
        UEZQueueDelete(queue);
#endif
#if UEZ_ENABLE_LIGHT_SENSOR
        (*p)->Close((void *)p);
        UEZTaskResume(G_lightSensorTask);
#endif
    }
    /* <<< WHIS >>> Potential memory leak in FreeRTOS version as G_ws is not
    free'd. */
}
示例#27
0
/*-------------------------------------------------------------------------*
 * Function:  GenericBulkInitialize
 *-------------------------------------------------------------------------*
 * Description:
 *      Initialize the Virtual Comm variables.
 *-------------------------------------------------------------------------*/
T_uezError GenericBulkInitialize(T_GenBulkCallbacks *aCallbacks)
{
    T_uezError error;

    // Copy over the callback information
    G_callbacks = *aCallbacks;

    // See if the USBDevice exists
    error = UEZDeviceTableFind(
                "USBDevice",
                &G_usbDev);
    if (error != UEZ_ERROR_NONE)
        return error;

    // Find the workspace for all the routines (we'll just make it
    // global for this cheap configuration).
    error = UEZDeviceTableGetWorkspace(
                G_usbDev,
                (T_uezDeviceWorkspace **)&G_ghDevice);
    if (error != UEZ_ERROR_NONE)
        return error;

    error = UEZQueueCreate(GENERIC_BULK_QUEUE_IN_SIZE, 1, &G_GenBulkFifoIn);
    if (error != UEZ_ERROR_NONE)
        return error;

    error = UEZQueueCreate(GENERIC_BULK_QUEUE_OUT_SIZE, 1, &G_GenBulkFifoOut);
    if (error != UEZ_ERROR_NONE) {
        UEZQueueDelete(G_GenBulkFifoIn);
        return error;
    }

    // Turn on Nak interrupts on bulk input
    // so it polls the BulkIn for data when there is none
//    ((*G_ghDevice)->InterruptNakEnable)(G_ghDevice, USB_DEVICE_SET_MODE_INAK_BI);

    // Configure the device driver
    // Tell it our descriptor table
    ((*G_ghDevice)->Configure)(G_ghDevice, G_GenericBulk_USBDescriptorTable);
    ((*G_ghDevice)->RegisterRequestTypeCallback)(
            G_ghDevice,
            USB_REQUEST_TYPE_CLASS,
            G_GenericBulkRequest,
            0,
            GenericBulkHandleClassRequest);
#if 0
    ((*G_ghDevice)->RegisterEndpointCallback)(
            G_ghDevice,
            ENDPOINT_IN(1),
            GenericBulkInterruptIn);
#endif
    ((*G_ghDevice)->RegisterEndpointCallback)(
            G_ghDevice,
            ENDPOINT_IN(1),
            GenericBulkBulkInComplete);
    ((*G_ghDevice)->RegisterEndpointCallback)(
            G_ghDevice,
            ENDPOINT_OUT(2),
            GenericBulkBulkOut);

    // We are ready, let's initialize it and connect
    ((*G_ghDevice)->Initialize)(G_ghDevice);
    ((*G_ghDevice)->Connect)(G_ghDevice);

    // Now create a task that constantly process the GenBulk buffers
    error = UEZTaskCreate(
                GenericBulkMonitor,
                "GenBulk",
                256,
                0,
                UEZ_PRIORITY_HIGH,
                &G_ghTask);

    return error;
}