hw/drivers/sensors/hts221/src/hts221.c
int
hts221_read8(struct hts221 *dev, uint8_t reg, uint8_t *value)
{
    int rc;
    os_error_t err = 0;
    struct sensor_itf *itf = &dev->sensor.s_itf;

    struct hal_i2c_master_data data_struct = {
        .address = itf->si_addr,
        .len = 1,
        .buffer = &reg
    };

    if (dev->i2c_mutex) {
        err = os_mutex_pend(dev->i2c_mutex, OS_WAIT_FOREVER);
        if (err != OS_OK) {
            log_err(reg);
            HTS221_STATS_INC(mutex_errors);
            return err;
        }
    }

    /* Register write */
    rc = hal_i2c_master_write(itf->si_num, &data_struct,
                              OS_TICKS_PER_SEC / 10, 0);
    if (rc) {
        log_err(reg);
        HTS221_STATS_INC(write_errors);
        goto exit;
    }

    /* Read one byte back */
    data_struct.buffer = value;
    rc = hal_i2c_master_read(itf->si_num, &data_struct,
                             OS_TICKS_PER_SEC / 10, 1);

    if (rc) {
        log_err(reg);
        HTS221_STATS_INC(read_errors);
    }

    exit:
    if (dev->i2c_mutex) {
        err = os_mutex_release(dev->i2c_mutex);
        assert(err == OS_OK);
    }

    return rc;
}
/**
 * Reads a single byte from the specified register
 *
 * @param The sensor interface
 * @param The register address to read from
 * @param Pointer to where the register value should be written
 *
 * @return 0 on success, non-zero error on failure.
 */
Reads a single byte from the specified register
@param The sensor interface
@param The register address to read from
@param Pointer to where the register value should be written

@return 0 on success, non-zero error on failure.
Reads a single byte from the specified register @param The sensor interface @param The register address to read from @param Pointer to where the register value should be written @return 0 on success non - zero error on failure .
int
hts221_read8(struct hts221 *dev, uint8_t reg, uint8_t *value)
{
    int rc;
    os_error_t err = 0;
    struct sensor_itf *itf = &dev->sensor.s_itf;
    struct hal_i2c_master_data data_struct = {
        .address = itf->si_addr,
        .len = 1,
        .buffer = &reg
    };
    if (dev->i2c_mutex) {
        err = os_mutex_pend(dev->i2c_mutex, OS_WAIT_FOREVER);
        if (err != OS_OK) {
            log_err(reg);
            HTS221_STATS_INC(mutex_errors);
            return err;
        }
    }
    rc = hal_i2c_master_write(itf->si_num, &data_struct,
                              OS_TICKS_PER_SEC / 10, 0);
    if (rc) {
        log_err(reg);
        HTS221_STATS_INC(write_errors);
        goto exit;
    }
    data_struct.buffer = value;
    rc = hal_i2c_master_read(itf->si_num, &data_struct,
                             OS_TICKS_PER_SEC / 10, 1);
    if (rc) {
        log_err(reg);
        HTS221_STATS_INC(read_errors);
    }
    exit:
    if (dev->i2c_mutex) {
        err = os_mutex_release(dev->i2c_mutex);
        assert(err == OS_OK);
    }
    return rc;
}
int hts221_read8 ( struct hts221 * dev , uint8_t reg , uint8_t * value ) { int rc ; os_error_t err = 0 ; struct sensor_itf * itf = & dev -> sensor . s_itf ; struct hal_i2c_master_data data_struct = { . address = itf -> si_addr , . len = 1 , . buffer = & reg } ; if ( dev -> i2c_mutex ) { err = os_mutex_pend ( dev -> i2c_mutex , OS_WAIT_FOREVER ) ; if ( err != OS_OK ) { log_err ( reg ) ; HTS221_STATS_INC ( mutex_errors ) ; return err ; } } rc = hal_i2c_master_write ( itf -> si_num , & data_struct , OS_TICKS_PER_SEC / 10 , 0 ) ; if ( rc ) { log_err ( reg ) ; HTS221_STATS_INC ( write_errors ) ; goto exit ; } data_struct . buffer = value ; rc = hal_i2c_master_read ( itf -> si_num , & data_struct , OS_TICKS_PER_SEC / 10 , 1 ) ; if ( rc ) { log_err ( reg ) ; HTS221_STATS_INC ( read_errors ) ; } exit : if ( dev -> i2c_mutex ) { err = os_mutex_release ( dev -> i2c_mutex ) ; assert ( err == OS_OK ) ; } return rc ; }
Reads a single byte from the specified register
 @param The sensor interface
 @param The register address to read from
 @param Pointer to where the register value should be written
Reads a single byte from the specified register @param The sensor interface @param The register address to read from @param Pointer to where the register value should be written
/* Register write */ /* Read one byte back */