Example #1
0
File: v4pi.c Project: miellaby/v4p
Boolean v4pDisplaySlice(Coord y, Coord x0, Coord x1, Color c) {
 int l ;
 if (x1 <= x0) return success ;
 l = x1 - x0 ;
 //WinSetForeColor((IndexedColorType)c);
 //WinDrawLine(x0 + 10, y+10, x1+9, y+10);
 myMemSet(&buffer[iBuffer], l, (char)c) ;
 iBuffer+= l ;
 if (x1 == lineWidth)
    iBuffer+= bytesBetweenLines ;

 return success ;
}
Example #2
0
CyFx3BootErrorCode_t
testI2cRegMode (
    void )
{
    CyFx3BootI2cConfig_t i2cConfig;
    CyFx3BootI2cPreamble_t preamble;

    uint8_t size,i;
    uint16_t j = 0;
    uint8_t wr_buf[I2C_REG_XFER_SIZE];
    uint8_t rd_buf[I2C_REG_XFER_SIZE];
    CyFx3BootErrorCode_t status;

    uint8_t divider = (sizeof(i2c_bitrate)/sizeof(i2c_bitrate[0]));

    size = (uint8_t)I2C_REG_XFER_SIZE;

    status = CyFx3BootI2cInit();
    if (status != CY_FX3_BOOT_SUCCESS)
        return status;

    i2cConfig.busTimeout = 0xFFFFFFFF;
    i2cConfig.dmaTimeout = 0xFFFF;
    i2cConfig.isDma = CyFalse;

    for (j = 0; j < 250; j++)
    {
        /* Run at various bit rates. */
        i2cConfig.bitRate = i2c_bitrate[j % divider];

        status = CyFx3BootI2cSetConfig (&i2cConfig);
        if (status != CY_FX3_BOOT_SUCCESS)
        {
            return status;
        }

        /* The address at which read/write is to be performed */
        preamble.buffer[1] = j;
        preamble.buffer[2] = 0;

        /*For EEPROM 64 byte page allignment....*/
        if((preamble.buffer[2] % I2C_PAGE_SIZE) != 0)
        {
            preamble.buffer[2] = (preamble.buffer[2] / I2C_PAGE_SIZE) *
                                 I2C_PAGE_SIZE;
        }

        preamble.buffer[0] = 0xA0; /* Write to I2C */
        preamble.length = 3;
        preamble.ctrlMask = 0x0000;

        myMemSet (wr_buf, j, I2C_REG_XFER_SIZE);

        status = CyFx3BootI2cTransmitBytes (&preamble, wr_buf, size, 200);
        if (status != CY_FX3_BOOT_SUCCESS)
        {
            return status;
        }

        preamble.length = 1;
        status = CyFx3BootI2cWaitForAck (&preamble, 200);
        if (status != CY_FX3_BOOT_SUCCESS)
        {
            return status;
        }

        /* Read the written location */
        preamble.buffer[3] = 0xA1;
        preamble.buffer[0] = 0xA0;
        preamble.length = 4;
        preamble.ctrlMask = 0x0004;

        status = CyFx3BootI2cReceiveBytes (&preamble, rd_buf, size, 200);
        if (status != CY_FX3_BOOT_SUCCESS)
        {
            return status;
        }

        /* Compare the received data */
        for (i = 0; i < size; i++)
        {
            if(rd_buf[i] != wr_buf[i])
            {
                /* Compare Error. Return apt error code. */
                return CY_FX3_BOOT_ERROR_FAILURE;
            }
        }

        CyFx3BootBusyWait (10);
    }

    CyFx3BootI2cDeInit();
    return CY_FX3_BOOT_SUCCESS;
}