hw/drivers/sensors/lps22hb/src/lps22hb.c
int
lps22hb_read_bytes(struct lps22hb *dev, uint8_t reg, uint8_t *buffer, uint32_t length)
{
    int rc;
    struct sensor_itf *itf = SENSOR_GET_ITF(&dev->sensor);

#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
    rc = bus_node_simple_write_read_transact(itf->si_dev, &reg, 1, buffer, length);
#else
    os_error_t err = 0;
    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)
        {
            LPS22HB_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) {
        LPS22HB_STATS_INC(write_errors);
        goto exit;
    }

    /* Read n bytes back */
    data_struct.len = length;
    data_struct.buffer = buffer;
    rc = hal_i2c_master_read(itf->si_num, &data_struct,
                             OS_TICKS_PER_SEC / 10, 1);

    if (rc) {
         LPS22HB_STATS_INC(read_errors);
    }

exit:
    if (dev->i2c_mutex)
    {
        err = os_mutex_release(dev->i2c_mutex);
        assert(err == OS_OK);
    }
#endif
    return rc;
}
/**
 * Reads n bytes 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
 * @param number of bytes to read
 *
 * @return 0 on success, non-zero error on failure.
 */
Reads n bytes 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
@param number of bytes to read

@return 0 on success, non-zero error on failure.
Reads n bytes 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 @param number of bytes to read @return 0 on success non - zero error on failure .
int
lps22hb_read_bytes(struct lps22hb *dev, uint8_t reg, uint8_t *buffer, uint32_t length)
{
    int rc;
    struct sensor_itf *itf = SENSOR_GET_ITF(&dev->sensor);
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
    rc = bus_node_simple_write_read_transact(itf->si_dev, &reg, 1, buffer, length);
#else
    os_error_t err = 0;
    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)
        {
            LPS22HB_STATS_INC(mutex_errors);
            return err;
        }
    }
    rc = hal_i2c_master_write(itf->si_num, &data_struct,
                              OS_TICKS_PER_SEC / 10, 0);
    if (rc) {
        LPS22HB_STATS_INC(write_errors);
        goto exit;
    }
    data_struct.len = length;
    data_struct.buffer = buffer;
    rc = hal_i2c_master_read(itf->si_num, &data_struct,
                             OS_TICKS_PER_SEC / 10, 1);
    if (rc) {
         LPS22HB_STATS_INC(read_errors);
    }
exit:
    if (dev->i2c_mutex)
    {
        err = os_mutex_release(dev->i2c_mutex);
        assert(err == OS_OK);
    }
#endif
    return rc;
}
int lps22hb_read_bytes ( struct lps22hb * dev , uint8_t reg , uint8_t * buffer , uint32_t length ) { int rc ; struct sensor_itf * itf = SENSOR_GET_ITF ( & dev -> sensor ) ; #if MYNEWT_VAL ( BUS_DRIVER_PRESENT ) rc = bus_node_simple_write_read_transact ( itf -> si_dev , & reg , 1 , buffer , length ) ; #else os_error_t err = 0 ; 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 ) { LPS22HB_STATS_INC ( mutex_errors ) ; return err ; } } rc = hal_i2c_master_write ( itf -> si_num , & data_struct , OS_TICKS_PER_SEC / 10 , 0 ) ; if ( rc ) { LPS22HB_STATS_INC ( write_errors ) ; goto exit ; } data_struct . len = length ; data_struct . buffer = buffer ; rc = hal_i2c_master_read ( itf -> si_num , & data_struct , OS_TICKS_PER_SEC / 10 , 1 ) ; if ( rc ) { LPS22HB_STATS_INC ( read_errors ) ; } exit : if ( dev -> i2c_mutex ) { err = os_mutex_release ( dev -> i2c_mutex ) ; assert ( err == OS_OK ) ; } #endif return rc ; }
Reads n bytes 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
 @param number of bytes to read
Reads n bytes 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 @param number of bytes to read
/* Register write */ /* Read n bytes back */