示例#1
0
/*---------------------------------------------------------------------------*
 * Routine: SetLevel
 *---------------------------------------------------------------------------*
 * Description: 
 *      Set the gain of the audio amp to the desired level
 * Inputs:
 *      void *aWorkspace
 *      TUInt8 aLevel             --new level to set the amp to
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_WM8731_SetLevel(void *aWorkSpace, TUInt8 aLevel)
{
    T_AudioAmp_WM8731_Workspace *p = (T_AudioAmp_WM8731_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    TUInt8 data[4];
    TUInt8 setLevel;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    p->iLevel = aLevel;
    setLevel = ((p->iLevel * (p->iMaxLevel - p->iMinLevel))/0xFF) + p->iMinLevel;
    if(!p->iIsMuted){
        if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
            data[0] = WM8731_LOUT1V;
            data[1] = (0 << 7) |  //RZCEN
                    setLevel; //VOL
            UEZI2CWrite(i2c, WM8731_ADDR, WM8731_I2C_Speed, data, 2, 100);
            data[0] = WM8731_ROUT1V;
            data[1] = (0 << 7) |  //RZCEN
                    setLevel; //VOL
            UEZI2CWrite(i2c, WM8731_ADDR, WM8731_I2C_Speed, data, 3, 100);
            UEZI2CClose(i2c);
        }
    }
    UEZSemaphoreRelease(p->iSem);
    return UEZ_ERROR_NONE;
}
示例#2
0
void TestVCNL4010Start(const char *aI2CName, TUInt8 aI2CAddr)
{
    UEZI2COpen(aI2CName, &G_i2cBus);
    G_i2cAddr = aI2CAddr;
    UEZTaskCreate(TestVCNL4010Task, "VCNL4010", UEZ_TASK_STACK_BYTES(512), 0,
        UEZ_PRIORITY_NORMAL, 0);
}
示例#3
0
/*---------------------------------------------------------------------------*
 * Routine: SetLevel
 *---------------------------------------------------------------------------*
 * Description: 
 *      Set the gain of the audio amp to the desired level
 * Inputs:
 *      void *aWorkspace
 *      TUInt8 aLevel             --new level to set the amp to
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_LM48110_SetLevel(void *aWorkSpace, TUInt8 aLevel)
{
    T_AudioAmp_LM48110_Workspace *p = (T_AudioAmp_LM48110_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    TUInt8 data[5] = { 0x1C, //Turn on both inputs
                       0x20, //Mask for Diagnostic
                       0x40, //Mask for Fault
    };
    TUInt8 setLevel;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    p->iLevel = aLevel;
    setLevel = ((p->iLevel * (p->iMaxLevel - p->iMinLevel))/0xFF) + p->iMinLevel;

    data[3] = (VOLUME_1_MASK | setLevel);
    data[4] = (VOLUME_2_MASK | setLevel);

    if(!p->iIsMuted){
        if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
            UEZI2CWrite(i2c, LM48100_ADDR, LM48100_SPEED, data, 5, 100);//UEZ_TIMEOUT_INFINITE);
            UEZI2CClose(i2c);
        }
    }

    UEZSemaphoreRelease(p->iSem);
    return UEZ_ERROR_NONE;
}
示例#4
0
/*---------------------------------------------------------------------------*
 * Routine:  UEZGUI_EXP_DK_Detect
 *---------------------------------------------------------------------------*
 * Description:
 *      Determine if the EXP_DK is plugged in.  In this case, we'll use
 *      the I2C Mux and see if we can read it with a raw I2C read.
 * Outputs:
 *      TBool                     -- ETrue if found, else EFalse
 *---------------------------------------------------------------------------*/
TBool UEZGUI_EXP_DK_Detect(void)
{
    T_uezError error = UEZ_ERROR_NOT_FOUND;
    T_uezDevice i2c;
    TUInt8 data;

    // Determine if the EXP_DK is plugged in.
    UEZPlatform_ExpansionPrimary_I2C_A_Require();
    error = UEZI2COpen(PRIMARY_EXPANSION_I2C_A, &i2c);
    if (error)
        return EFalse;
    error = UEZI2CRead(i2c, UEZGUI_EXP_DK_I2CMUX_I2C_ADDRESS, 400, &data, 1, 200);
    UEZI2CClose(i2c);

    return (error == UEZ_ERROR_NONE)?ETrue:EFalse;
}
示例#5
0
/*-------------------------------------------------------------------------*
 * Prototypes:
 *-------------------------------------------------------------------------*/
TUInt32 TestVCNL4010FCT(const char *aI2CName, TUInt8 aI2CAddr,
                        TUInt32 * const ambient, TUInt32 * const proximity)
{
    TUInt8 cmd[2];
    TUInt8 data[4];
	UEZI2COpen(aI2CName, &G_i2cBus);
    G_i2cAddr = aI2CAddr;
 
// Set Current to 20
    cmd[0] = REGISTER_PROX_CURRENT;
    cmd[1] = 20; // 20 x 10 = 200 mA, max
    UEZI2CWrite(G_i2cBus, G_i2cAddr, I2C_SPEED, cmd, 2, 1000);

    printf("Reading ... ");
    // Request to trigger both ALS and Proximity
        cmd[0] = REGISTER_COMMAND;
        cmd[1] = 0x18;
        UEZI2CWrite(G_i2cBus, G_i2cAddr, I2C_SPEED, cmd, 2, 1000);

        do {
            printf("?");
            // Now read back the status (after writing command index)
            cmd[0] = REGISTER_COMMAND;
            UEZI2CWrite(G_i2cBus, G_i2cAddr, I2C_SPEED, cmd, 1, 1000);
            UEZI2CRead(G_i2cBus, G_i2cAddr, I2C_SPEED, data, 1, 1000);

            // Is it ready?
            if (data[0] & (COMMAND_MASK_PROX_DATA_READY | COMMAND_MASK_AMBI_DATA_READY))
                break;

            // Not ready yet, pause and try again in a moment
            UEZTaskDelay(10);
        } while (1);

        // Now read the data
        cmd[0] = REGISTER_AMBI_VALUE;
        UEZI2CWrite(G_i2cBus, G_i2cAddr, I2C_SPEED, cmd, 1, 1000);
        UEZI2CRead(G_i2cBus, G_i2cAddr, I2C_SPEED, data, 4, 1000);

       *ambient = (data[0] << 8) | data[1];
       *proximity = (data[2] << 8) | data[3];
        printf("Ambient: %04X, Proximity: %04X\n", *ambient, *proximity);

        UEZTaskDelay(100);
    return UEZ_ERROR_NONE;
}
示例#6
0
/*---------------------------------------------------------------------------*/
int UEZCmdI2CProbe(void *aWorkspace, int argc, char *argv[])
{
    T_uezDevice i2c;
    T_uezError error;
    TUInt8 addr;
    TUInt8 data[10];
    char busName[] = "I2C0";

    if (argc == 2) {
        busName[3] = argv[1][0];
        error = UEZI2COpen(busName, &i2c);
        if (error) {
            FDICmdPrintf(aWorkspace, "I2C Bus %s not found!\n", busName);
            return UEZ_ERROR_NOT_FOUND;
        }

        // Probe all 127 addresses
        FDICmdPrintf(aWorkspace, "Probing all 127 I2C addresses on %s:\n",
            busName);
        for (addr = 1; addr <= 127; addr++) {
            // Give it 1 second each (way too much time)
            error = UEZI2CRead(i2c, addr, 100, data, 1, 100);
            if (error == UEZ_ERROR_NONE) {
                FDICmdPrintf(aWorkspace, "  Device @ 0x%02X\n", addr);
            } else if (error == UEZ_ERROR_TIMEOUT) {
                FDICmdPrintf(aWorkspace, "  Timeout at device 0x%02X!", addr);
                break;
            }
        }

        UEZI2CClose(i2c);
        if (addr >= 127) {
            FDICmdSendString(aWorkspace, "PASS: OK\n");
        }
    } else {
        FDICmdSendString(aWorkspace,
            "FAIL: Incorrect parameters.\nI2CPROBE <bus number>\n");
    }

    return UEZ_ERROR_NONE;
}
示例#7
0
/*---------------------------------------------------------------------------*
 * Routine:  Mute
 *---------------------------------------------------------------------------*
 * Description:
 *     Sets the amp to standby so no sound is played
 * Inputs:
 *      void *aWorkSpace
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_LM48110_Mute(void *aWorkSpace)
{
    T_AudioAmp_LM48110_Workspace *p = (T_AudioAmp_LM48110_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    TUInt8 data[5] = { 0x1C, //Turn on both inputs
                       0x20, //Mask for Diagnostic
                       0x40, //Mask for Fault
    };

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    data[3] = (VOLUME_1_MASK | 0);
    data[4] = (VOLUME_2_MASK | 0);
    p->iIsMuted = ETrue;

    if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
        UEZI2CWrite(i2c, LM48100_ADDR, LM48100_SPEED, data, 5, 100);//UEZ_TIMEOUT_INFINITE);
        UEZI2CClose(i2c);
    }
    UEZSemaphoreRelease(p->iSem);

    return UEZ_ERROR_NONE;
}
示例#8
0
/*---------------------------------------------------------------------------*
 * Routine:  TS_EXC7200_Configure
 *---------------------------------------------------------------------------*
 * Description:
 *      The SPI bus and GPIO device are being declared.
 * Inputs:
 *      void *aW                    -- Particular SPI workspace
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError TS_EXC7200_Configure(T_uezDeviceWorkspace *aW)
{
    T_EXC7200Workspace *p = (T_EXC7200Workspace *)aW;

    UEZSemaphoreGrab(p->iSemWaitForTouch, 0);

    UEZGPIOSetMux(p->iResetPin, 0);//Set to GPIO
    UEZGPIOOutput(p->iResetPin);
    UEZGPIOClear(p->iResetPin);

    UEZTaskDelay(1);
    UEZGPIOConfigureInterruptCallback(
        UEZ_GPIO_PORT_FROM_PORT_PIN(p->iInteruptPin),
        TS_EXC7200_InterruptISR,
        p);
    UEZGPIOEnableIRQ(p->iInteruptPin, GPIO_INTERRUPT_FALLING_EDGE);

    UEZGPIOSet(p->iResetPin);
    
    T_uezDevice i2c;
    I2C_Request request;
    T_uezError error;
    TUInt8 dataIn[10];
    TUInt8 dataOut[10] = { 0x03, 0x06, 0x0A, 0x04, 0x36, 0x3f, 0x01, 9, 0, 0};

    request.iAddr = EXC7200_I2C_ADDRESS;
    request.iSpeed = EXC7200_I2C_SPEED;
    request.iReadData = dataIn;
    request.iReadLength = 10;
    request.iWriteData = dataOut;
    request.iWriteLength = 10;

    UEZI2COpen(p->iI2CBus, &i2c);
    error = UEZI2CTransaction(i2c, &request);
                      

    return UEZ_ERROR_NONE;
}
示例#9
0
/*---------------------------------------------------------------------------*
 * Routine:  Mute
 *---------------------------------------------------------------------------*
 * Description:
 *     Sets the amp to standby so no sound is played
 * Inputs:
 *      void *aWorkSpace
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_WM8731_Mute(void *aWorkSpace)
{
    T_AudioAmp_WM8731_Workspace *p = (T_AudioAmp_WM8731_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    TUInt8 data[4];

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
        data[0] = WM8731_LOUT1V;
        data[1] = (0 << 7) |  //RZCEN
                  (0x00); //VOL
        UEZI2CWrite(i2c, WM8731_ADDR, WM8731_I2C_Speed, data, 2, 100);
        data[0] = WM8731_ROUT1V;
        data[1] = (0 << 7) |  //RZCEN
                  (0x00); //VOL
        UEZI2CWrite(i2c, WM8731_ADDR, WM8731_I2C_Speed, data, 3, 100);
        UEZI2CClose(i2c);
    }
    UEZSemaphoreRelease(p->iSem);

    return UEZ_ERROR_NONE;
}
示例#10
0
/*---------------------------------------------------------------------------*
 * Routine:  Open
 *---------------------------------------------------------------------------*
 * Description:
 *     Initalizes pins for the audio amp 
 *     turns it on
 *     sets the level to the default
 * Inputs:
 *      void *aWorkSpace
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_LM48110_Open(void *aWorkSpace)
{
    T_AudioAmp_LM48110_Workspace *p = (T_AudioAmp_LM48110_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    T_uezError error = UEZ_ERROR_NONE;
    TUInt8 data[5] = { 0x1C, //Turn on both inputs
                       0x20, //Mask for Diagnostic
                       0x40, //Mask for Fault
                       (VOLUME_1_MASK | 0x00), //Set the volume to 0
                       (VOLUME_2_MASK | 0x00)}; // Set the volume to 0

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    if(p->iNumOpen == 0){
        p->iIsOn = ETrue;
        if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
            p->iNumOpen++;
            error = UEZI2CWrite(i2c, LM48100_ADDR, LM48100_SPEED, data, 5, 100);//UEZ_TIMEOUT_INFINITE);
            UEZI2CClose(i2c);
        }
        p->iLevel = 0;
    }
    UEZSemaphoreRelease(p->iSem);
    return error;
}
示例#11
0
/*---------------------------------------------------------------------------*/
int UEZCmdI2CRead(void *aWorkspace, int argc, char *argv[])
{
    T_uezDevice i2c;
    T_uezError error;
    TUInt8 addr;
    TUInt32 num;
    TUInt8 data[128];
    char busName[] = "I2C0";
    int i;

    if (argc == 4) {
        busName[3] = argv[1][0];

        // Open up the bus
        error = UEZI2COpen(busName, &i2c);
        if (error) {
            FDICmdPrintf(aWorkspace, "I2C Bus %s not found!\n", busName);
            return UEZ_ERROR_NOT_FOUND;
        }

        // Get the address
        addr = FDICmdUValue(argv[2]);
        if (addr >= 128) {
            FDICmdPrintf(aWorkspace, "Address must be 7-bit (0-127)\n");
            UEZI2CClose(i2c);
            return UEZ_ERROR_INVALID_PARAMETER;
        }

        // Get the number of bytes to read
        num = FDICmdUValue(argv[3]);
        if (num > sizeof(data)) {
            FDICmdPrintf(aWorkspace, "Out of space. Limited read buffer of %d bytes\n", sizeof(data));
            UEZI2CClose(i2c);
            return UEZ_ERROR_INVALID_PARAMETER;
        }

        // Write the data
        FDICmdPrintf(aWorkspace, "Reading bus %s, addr 0x%02X, %d bytes:\n",
            busName, addr, num);

        // For now, assume 100 kHz is valid
        error = UEZI2CRead(i2c, addr, 100, data, num, 1000);
        if (error == UEZ_ERROR_NONE) {
            for (i=0; i<num; i++) {
                FDICmdPrintf(aWorkspace, "%02X ", data[i]);
                if ((i%15)==7)
                    FDICmdPrintf(aWorkspace, "- ");
                if ((i%15)==15)
                    FDICmdPrintf(aWorkspace, "\n");
            }
            if ((num%15)!=15)
                FDICmdPrintf(aWorkspace, "\n");
            FDICmdSendString(aWorkspace, "PASS: OK\n");
        } else if (error == UEZ_ERROR_NAK) {
            FDICmdSendString(aWorkspace, "FAIL: NAK\n");
        } else if (error == UEZ_ERROR_TIMEOUT) {
            FDICmdSendString(aWorkspace, "FAIL: Timeout!\n");
        } else {
            FDICmdPrintf(aWorkspace, "FAIL: Error #%d\n", error);
        }

        UEZI2CClose(i2c);
    } else {
        FDICmdSendString(aWorkspace,
            "FAIL: Incorrect parameters.\nI2CREAD <bus number> <addr> <num>\n");
    }

    return UEZ_ERROR_NONE;
}
示例#12
0
/*---------------------------------------------------------------------------*/
int UEZCmdI2CWrite(void *aWorkspace, int argc, char *argv[])
{
    T_uezDevice i2c;
    T_uezError error;
    TUInt8 addr;
    TUInt32 v;
    TUInt8 data[128];
    char busName[] = "I2C0";
    int i;

    if (argc >= 4) {
        busName[3] = argv[1][0];

        // Open up the bus
        error = UEZI2COpen(busName, &i2c);
        if (error) {
            FDICmdPrintf(aWorkspace, "I2C Bus %s not found!\n", busName);
            return UEZ_ERROR_NOT_FOUND;
        }

        // Get the address
        addr = FDICmdUValue(argv[2]);
        if (addr >= 128) {
            FDICmdPrintf(aWorkspace, "Address must be 7-bit (0-127)\n");
            UEZI2CClose(i2c);
            return UEZ_ERROR_INVALID_PARAMETER;
        }

        // Setup the data to be written
        for (i = 3; (i < argc) && (i < sizeof(data)); i++) {
            v = FDICmdUValue(argv[i]);
            if (v >= 256) {
                FDICmdPrintf(aWorkspace,
                    "Values in write must be bytes (0-255).  %d is out of range.\n",
                    v);
                UEZI2CClose(i2c);
                return UEZ_ERROR_INVALID_PARAMETER;
            }
            data[i-3] = v;
        }

        // Write the data
        FDICmdPrintf(aWorkspace, "Writing to bus %s, addr 0x%02X:\n",
            busName, addr);

        // For now, assume 100 kHz is valid
        error = UEZI2CWrite(i2c, addr, 100, data, argc-3, 1000);
        if (error == UEZ_ERROR_NONE) {
            FDICmdSendString(aWorkspace, "PASS: OK\n");
        } else if (error == UEZ_ERROR_NAK) {
            FDICmdSendString(aWorkspace, "FAIL: NAK\n");
        } else if (error == UEZ_ERROR_TIMEOUT) {
            FDICmdSendString(aWorkspace, "FAIL: Timeout!\n");
        } else {
            FDICmdPrintf(aWorkspace, "FAIL: Error #%d\n", error);
        }

        UEZI2CClose(i2c);
    } else {
        FDICmdSendString(aWorkspace,
            "FAIL: Incorrect parameters.\nI2CWRITE <bus number> <addr> [<byte> ...]\n");
    }

    return UEZ_ERROR_NONE;
}
/*---------------------------------------------------------------------------*
 * Routine:  TS_MC_AR1020_Poll
 *---------------------------------------------------------------------------*
 * Description:
 *      Take a reading from the TSC2406 and put in reading structure.
 * Inputs:
 *      void *aW                    -- Workspace
 *      T_uezTSReading *aReading     -- Pointer to final reading
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError TS_MC_AR1020_Poll(void *aWorkspace, T_uezTSReading *aReading)
{
    T_MC_AR1020Workspace *p =
        (T_MC_AR1020Workspace *) aWorkspace;
    T_uezError error;
    I2C_Request r;
    T_uezDevice i2c2;
    TUInt8 data[5] = {0,0,0,0,0};
    HAL_GPIOPort **p_gpio;
    const TUInt32 pin = 15;
    TUInt32 Read = 0;
    TUInt32 x;
    TUInt32 y;

    HALInterfaceFind("GPIO2", (T_halWorkspace **)&p_gpio);

    (*p_gpio)->SetInputMode(p_gpio, 1<<pin);
    (*p_gpio)->SetMux(p_gpio, pin, 0); // set to GPIO
    (*p_gpio)->Read(p_gpio, 1<<pin, &Read);

    if ( Read == 0)
    {
        (aReading->iFlags) = (p->iLastTouch) ;
        return UEZ_ERROR_NONE;
    }
    else
    {
        r.iAddr = AR1020_I2C_ADDRESS;
        r.iSpeed = AR1020_I2C_SPEED;
        r.iWriteData = 0;
        r.iWriteLength = 0;
        r.iWriteTimeout = UEZ_TIMEOUT_INFINITE;
        r.iReadData = data;
        r.iReadLength = 5;
        r.iReadTimeout = UEZ_TIMEOUT_INFINITE;

        error = UEZI2COpen("I2C2", &i2c2);

        UEZI2CTransaction(i2c2, &r);

        UEZI2CClose(i2c2);

        x = data[4];
        x = (x <<7);
        x = x | data[3];

        y = data[2];
        y = (y <<7);
        y = y | data[1];

        //if(p->iIsCalibrating)
        //for testing printf("%04x _ %04X\r\n", x, y);

        if((data[0] & 0x01)== 0x01)
        {
            (aReading->iFlags) = (p->iLastTouch) = TSFLAG_PEN_DOWN;
            (aReading->iX) = (p->iLastX)= x;
            (aReading->iY) = (p->iLastY)= y;
            if ((!p->iIsCalibrating) && (p->iHaveCalibration)) {
                // Convert X & Y coordinates
                TS_MC_AR1020_ApplyCalibration(
                    p, x, y,
                    (TUInt32 *) &aReading->iX,
                    (TUInt32 *) &aReading->iY);
            }
        }
        else
        {
            (aReading->iFlags) = (p->iLastTouch)= 0;
            (aReading->iX) = (p->iLastX);
            (aReading->iY) = (p->iLastY);

            TS_MC_AR1020_ApplyCalibration(
                p, (p->iLastX), (p->iLastY),
                (TUInt32 *) &aReading->iX,
                (TUInt32 *) &aReading->iY);
        }

        return error;
    }
}
/*---------------------------------------------------------------------------*
 * Routine:  TS_MC_AR1020_Open
 *---------------------------------------------------------------------------*
 * Description:
 *      The TI TSC2046 is being opened.
 * Inputs:
 *      void *aW                    -- Particular SPI workspace
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError TS_MC_AR1020_Open(void *aW)
{
    T_MC_AR1020Workspace *p = (T_MC_AR1020Workspace *)aW;
    T_uezError error = UEZ_ERROR_NONE;
    I2C_Request r;
    T_uezDevice i2c2;
    TUInt8 dataout[4] = {0x00, 0x55,0x01,EnableTouch};
    TUInt8 datain[4] = {0xff, 0xff, 0xff, 0xff};
    TUInt8 commandToSend[8] = {0x00, 0x55,0x05,RegisterWrite,0x00, 0x00, 0x01,0x60 };
    TUInt8 regstart[6];

    HAL_GPIOPort **p_gpio;
    const TUInt32 pin = 15;
    TUInt32 Read = 0;

    HALInterfaceFind("GPIO2", (T_halWorkspace **)&p_gpio);

    (*p_gpio)->SetInputMode(p_gpio, 1<<pin);
    (*p_gpio)->SetMux(p_gpio, pin, 0); // set to GPIO
    (*p_gpio)->Read(p_gpio, 1<<pin, &Read);

    if(p->aNumOpen == 0)
    {

        error = UEZI2COpen("I2C2", &i2c2);


        error = UEZI2CWrite(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, dataout, 4, UEZ_TIMEOUT_INFINITE);

        while(Read == 0)
        {
            (*p_gpio)->Read(p_gpio, 1<<pin, &Read);
        }
        error = UEZI2CRead(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, datain, 5, UEZ_TIMEOUT_INFINITE);

        //send command to change TouchThreshold to 0x60
//      to write a register first send RegisterStartAddressRequest     0x22
//      calculate the address by adding the offset of the register to the start address TouchThreshold 0x02
//      issue the register write command RegisterWrite 0x21

        dataout[0] = 0;
        dataout[3] = RegisterStartAddressRequest;
//get start address
        error = UEZI2CWrite(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, dataout, 4, UEZ_TIMEOUT_INFINITE);

        while(Read == 0)
        {
            (*p_gpio)->Read(p_gpio, 1<<pin, &Read);
        }
        error = UEZI2CRead(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, regstart, 6, UEZ_TIMEOUT_INFINITE);
//

        commandToSend[5] = regstart[4]+ TouchThreshold;
        error = UEZI2CWrite(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, commandToSend, 8, UEZ_TIMEOUT_INFINITE);

        while(Read == 0)
        {
            (*p_gpio)->Read(p_gpio, 1<<pin, &Read);
        }
        error = UEZI2CRead(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, datain, 4, UEZ_TIMEOUT_INFINITE);

        commandToSend[5] = SensitivityFilter;
        commandToSend[6] = 1;
        commandToSend[7] = 10;
        Read = 0;

        error = UEZI2CWrite(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, commandToSend, 8, UEZ_TIMEOUT_INFINITE);

//      while(Read == 0)
//      {
//        (*p_gpio)->Read(p_gpio, 1<<pin, &Read);
//      }
//      error = UEZI2CRead(i2c2, AR1020_I2C_ADDRESS, AR1020_I2C_SPEED, datain, 4, UEZ_TIMEOUT_INFINITE);

        UEZI2CClose(i2c2);
    }
    p->aNumOpen++;

    return error;
}
示例#15
0
/*---------------------------------------------------------------------------*
 * Routine:  TS_EXC7200_Poll
 *---------------------------------------------------------------------------*
 * Description:
 *      Take a reading from the TSC2406 and put in reading structure.
 * Inputs:
 *      void *aW                    -- Workspace
 *      T_uezTSReading *aReading     -- Pointer to final reading
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError TS_EXC7200_Poll(void *aWorkspace, T_uezTSReading *aReading)
{
    T_EXC7200Workspace *p = (T_EXC7200Workspace *)aWorkspace;
    T_uezError error;
    I2C_Request r;
    T_uezDevice i2c0;
    TUInt8 dataIn[11];
    TUInt8 dataOut[5];
    TUInt32 Read = 0;
    TUInt32 x;
    TUInt32 y;
    static TBool loop = EFalse;
    TUInt32 start = UEZTickCounterGet();
    TUInt8 i;

    error = UEZI2COpen(p->iI2CBus, &i2c0);

    //while (UEZTickCounterGetDelta(start) < 2) {
    for(i = 0; i < 10; i++){
        // Try to grab the semaphore -- do we have new data?
        if (UEZSemaphoreGrab(p->iSemWaitForTouch, 0) == UEZ_ERROR_NONE) {
            // Got new data!
            Read = 1;
        } else {
            Read = 0;
        }

        if (Read == 0 && !loop) {
            aReading->iFlags = p->iLastTouch;
            aReading->iX = p->iLastX;
            aReading->iY = p->iLastY;

            TS_EXC7200_ApplyCalibration(p, (p->iLastX), (p->iLastY),
                    (TUInt32 *)&aReading->iX, (TUInt32 *)&aReading->iY);
            return UEZ_ERROR_NONE;
        } else {
//            dataOut[0] = 0x00;
//            error = UEZI2CWrite(i2c0,
//                    EXC7200_I2C_ADDRESS,
//                    EXC7200_I2C_SPEED,
//                    dataOut,
//                    1,
//                    50);

            memset((void*)dataIn, 0, sizeof(dataIn));
            error = UEZI2CRead(i2c0, EXC7200_I2C_ADDRESS, EXC7200_I2C_SPEED,
                    dataIn, 0x0A, 50);

            x = (((dataIn[3] & 0xFF) << 8) | dataIn[2]) / 51;

            y = (((dataIn[5] & 0xFF) << 8) | dataIn[4]) / 70;

            if ((dataIn[1] & 0x81) == 0x81 && (dataIn[0] == 0x04) && ((dataIn[1] & 0x7C) == 0)) {
                loop = ETrue;
                (aReading->iFlags) = (p->iLastTouch) = TSFLAG_PEN_DOWN;
                (aReading->iX) = (p->iLastX) = x;
                (aReading->iY) = (p->iLastY) = y;
                if ((!p->iIsCalibrating) && (p->iHaveCalibration)) {
                    // Convert X & Y coordinates
                    TS_EXC7200_ApplyCalibration(p, x, y,
                            (TUInt32 *)&aReading->iX, (TUInt32 *)&aReading->iY);
                }
            } else if (((dataIn[1] & 0x81) == 0x80) && (dataIn[0] == 0x04) && ((dataIn[1] & 0x7C) == 0)) {
                (aReading->iFlags) = (p->iLastTouch) = 0;
                (aReading->iX) = (p->iLastX);
                (aReading->iY) = (p->iLastY);
                UEZGPIOClearIRQ(p->iInteruptPin);
            } else { //if ((dataIn[3] & 0xC0) == 0x40){
                (aReading->iFlags) = (p->iLastTouch);
                (aReading->iX) = (p->iLastX);
                (aReading->iY) = (p->iLastY);

                TS_EXC7200_ApplyCalibration(p, (p->iLastX), (p->iLastY),
                        (TUInt32 *)&aReading->iX, (TUInt32 *)&aReading->iY);
            }

            if (!UEZGPIORead(p->iInteruptPin)) {
                loop = ETrue;
            } else {
                loop = EFalse;
                break;
            }

            if (((dataIn[1] & 0x81) == 0x80) && (dataIn[0] == 0x04)) {
              i = i + 1;
              i = i -1;
                break;
            }
        }
#if 0
        TUInt32 count = 0;
        while (!UEZGPIORead(p->iInteruptPin)) {
            error = UEZI2CRead(i2c0,
                    EXC7200_I2C_ADDRESS,
                    EXC7200_I2C_SPEED,
                    dataIn,
                    0x0A,
                    50);
            count++;
        }
#endif

    }
    return error;
}