示例#1
0
static int
mraa_ftdi_ft4222_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
{
    if (mraa_ftdi_ft4222_i2c_context_write(dev, &command, 1) != 1)
        return 0;
    return mraa_ftdi_ft4222_i2c_context_read(dev, data, length);
}
示例#2
0
static uint8_t
mraa_ftdi_ft4222_i2c_read_byte(mraa_i2c_context dev)
{
    uint8_t data;
    if (mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1) == 1)
        return data;
    else
        return 0;
}
示例#3
0
static uint8_t
mraa_ftdi_ft4222_i2c_read_byte(mraa_i2c_context dev)
{
    uint8_t data;
    pthread_mutex_lock(&ft4222_lock);
    int bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1);
    pthread_mutex_unlock(&ft4222_lock);
    return bytes_read == 1 ? data : 0;
}
示例#4
0
static int
mraa_ftdi_ft4222_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
{
    int bytes_read = 0;
    pthread_mutex_lock(&ft4222_lock);
    int bytes_written = mraa_ftdi_ft4222_i2c_context_write(dev, &command, 1);
    if (bytes_written == 1)
       bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, data, length);
    pthread_mutex_unlock(&ft4222_lock);
    return bytes_read;
}
示例#5
0
static uint16_t
mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
    uint8_t buf[2];
    uint16_t data;
    if (mraa_ftdi_ft4222_i2c_context_write(dev, &command, 1) != 1)
        return 0;
    if (mraa_ftdi_ft4222_i2c_context_read(dev, buf, 2) != 2)
        return 0;
    data = *(uint16_t*)buf;
    return data;
}
示例#6
0
static uint8_t
mraa_ftdi_ft4222_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
    uint8_t data;
    int bytes_read = 0;
    pthread_mutex_lock(&ft4222_lock);
    uint16 bytesWritten = mraa_ftdi_ft4222_i2c_context_write(dev, &command, 1);
    if  (bytesWritten == 1)
       bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1);
    pthread_mutex_unlock(&ft4222_lock);
    return (bytes_read == 1) ? data : 0;
}
示例#7
0
static uint16_t
mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
    uint8_t buf[2];
    uint16_t data;
    int bytes_read = 0;
    pthread_mutex_lock(&ft4222_lock);
    int bytes_written = mraa_ftdi_ft4222_i2c_context_write(dev, &command, 1);
    if (bytes_written == 1)
       bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, buf, 2);
    pthread_mutex_unlock(&ft4222_lock);
    data = (bytes_read == 2) ? *(uint16_t*)buf : 0;
    return data;
}