示例#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_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;
}
示例#2
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;
}
示例#3
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;
}
示例#4
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;
}
示例#5
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;
}
示例#6
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;
}
示例#7
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;
}
示例#8
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;
}
示例#9
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;
}