hw/drivers/sensors/lps22hb/src/lps22hb.c
int
lps22hb_write8(struct lps22hb *dev, uint8_t reg, uint32_t value)
{
    int rc;
    struct sensor_itf *itf = SENSOR_GET_ITF(&dev->sensor);
    uint8_t payload[2] = { reg, value & 0xFF };

#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
    rc = bus_node_simple_write(itf->si_dev, payload, sizeof(payload));
#else
    os_error_t err = 0;

    struct hal_i2c_master_data data_struct = {
        .address = itf->si_addr,
        .len = 2,
        .buffer = payload
    };

    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, 1);

    if (rc) {
        LPS22HB_STATS_INC(write_errors);
    }

    if (dev->i2c_mutex) {
        err = os_mutex_release(dev->i2c_mutex);
        assert(err == OS_OK);
    }
#endif
    return rc;
}
/**
 * Writes a single byte to the specified register
 *
 * @param The sensor interface
 * @param The register address to write to
 * @param The value to write
 *
 * @return 0 on success, non-zero error on failure.
 */
Writes a single byte to the specified register
@param The sensor interface
@param The register address to write to
@param The value to write

@return 0 on success, non-zero error on failure.
Writes a single byte to the specified register @param The sensor interface @param The register address to write to @param The value to write @return 0 on success non - zero error on failure .
int
lps22hb_write8(struct lps22hb *dev, uint8_t reg, uint32_t value)
{
    int rc;
    struct sensor_itf *itf = SENSOR_GET_ITF(&dev->sensor);
    uint8_t payload[2] = { reg, value & 0xFF };
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
    rc = bus_node_simple_write(itf->si_dev, payload, sizeof(payload));
#else
    os_error_t err = 0;
    struct hal_i2c_master_data data_struct = {
        .address = itf->si_addr,
        .len = 2,
        .buffer = payload
    };
    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, 1);
    if (rc) {
        LPS22HB_STATS_INC(write_errors);
    }
    if (dev->i2c_mutex) {
        err = os_mutex_release(dev->i2c_mutex);
        assert(err == OS_OK);
    }
#endif
    return rc;
}
int lps22hb_write8 ( struct lps22hb * dev , uint8_t reg , uint32_t value ) { int rc ; struct sensor_itf * itf = SENSOR_GET_ITF ( & dev -> sensor ) ; uint8_t payload [ 2 ] = { reg , value & 0xFF } ; #if MYNEWT_VAL ( BUS_DRIVER_PRESENT ) rc = bus_node_simple_write ( itf -> si_dev , payload , sizeof ( payload ) ) ; #else os_error_t err = 0 ; struct hal_i2c_master_data data_struct = { . address = itf -> si_addr , . len = 2 , . buffer = payload } ; 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 , 1 ) ; if ( rc ) { LPS22HB_STATS_INC ( write_errors ) ; } if ( dev -> i2c_mutex ) { err = os_mutex_release ( dev -> i2c_mutex ) ; assert ( err == OS_OK ) ; } #endif return rc ; }
Writes a single byte to the specified register
 @param The sensor interface
 @param The register address to write to
 @param The value to write
Writes a single byte to the specified register @param The sensor interface @param The register address to write to @param The value to write