本文整理汇总了C++中i2c_release函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_release函数的具体用法?C++ i2c_release怎么用?C++ i2c_release使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_release函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lps331ap_init
int lps331ap_init(lps331ap_t *dev, i2c_t i2c, uint8_t address, lps331ap_rate_t rate)
{
uint8_t tmp;
/* save device specifics */
dev->i2c = i2c;
dev->address = address;
/* Acquire exclusive access to the bus. */
i2c_acquire(dev->i2c);
/* initialize underlying I2C bus */
if (i2c_init_master(dev->i2c, BUS_SPEED) < 0) {
/* Release the bus for other threads. */
i2c_release(dev->i2c);
return -1;
}
/* configure device, for simple operation only CTRL_REG1 needs to be touched */
tmp = LPS331AP_CTRL_REG1_DBDU | LPS331AP_CTRL_REG1_PD |
(rate << LPS331AP_CTRL_REG1_ODR_POS);
if (i2c_write_reg(dev->i2c, dev->address, LPS331AP_REG_CTRL_REG1, tmp) != 1) {
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
return 0;
}
示例2: tcs37727_set_rgbc_standby
int tcs37727_set_rgbc_standby(tcs37727_t *dev)
{
uint8_t reg;
if (dev->initialized == false) {
return -1;
}
i2c_acquire(dev->i2c);
if (i2c_read_regs(dev->i2c, dev->addr, TCS37727_ENABLE, ®, 1) != 1) {
i2c_release(dev->i2c);
return -1;
}
reg &= ~TCS37727_ENABLE_AEN;
if (!(reg & TCS37727_ENABLE_PEN)) {
reg &= ~TCS37727_ENABLE_PON;
}
if (i2c_write_reg(dev->i2c, dev->addr, TCS37727_ENABLE, reg) != 1) {
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
return 0;
}
示例3: bh1750fvi_sample
uint16_t bh1750fvi_sample(const bh1750fvi_t *dev)
{
uint32_t tmp;
uint8_t raw[2];
/* power on the device and send single H-mode measurement command */
DEBUG("[bh1750fvi] sample: triggering a conversion\n");
i2c_acquire(dev->i2c);
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON, 0);
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1, 0);
i2c_release(dev->i2c);
/* wait for measurement to complete */
xtimer_usleep(DELAY_HMODE);
/* read the results */
DEBUG("[bh1750fvi] sample: reading the results\n");
i2c_acquire(dev->i2c);
i2c_read_bytes(dev->i2c, dev->addr, raw, 2, 0);
i2c_release(dev->i2c);
/* and finally we calculate the actual LUX value */
tmp = ((uint32_t)raw[0] << 24) | ((uint32_t)raw[1] << 16);
tmp /= RES_DIV;
return (uint16_t)(tmp);
}
示例4: srf02_init
int srf02_init(srf02_t *dev, i2c_t i2c, uint8_t addr)
{
dev->i2c = i2c;
dev->addr = (addr >> 1); /* internally we right align the 7-bit addr */
uint8_t rev;
/* Acquire exclusive access to the bus. */
i2c_acquire(dev->i2c);
/* initialize i2c interface */
if (i2c_init_master(dev->i2c, BUS_SPEED) < 0) {
DEBUG("[srf02] error initializing I2C bus\n");
return -1;
}
/* try to read the software revision (read the CMD reg) from the device */
i2c_read_reg(i2c, dev->addr, REG_CMD, &rev);
if (rev == 0 || rev == 255) {
i2c_release(dev->i2c);
DEBUG("[srf02] error reading the devices software revision\n");
return -1;
} else {
DEBUG("[srf02] software revision: 0x%02x\n", rev);
}
/* Release the bus for other threads. */
i2c_release(dev->i2c);
DEBUG("[srf02] initialization successful\n");
return 0;
}
示例5: isl29125_init
int isl29125_init(isl29125_t *dev, i2c_t i2c, gpio_t gpio,
isl29125_mode_t mode, isl29125_range_t range,
isl29125_resolution_t resolution)
{
DEBUG("isl29125_init\n");
/* initialize device descriptor */
dev->i2c = i2c;
dev->res = resolution;
dev->range = range;
dev->gpio = gpio;
/* configuration 1: operation mode, range, resolution */
uint8_t conf1 = 0x00;
conf1 |= mode;
conf1 |= range;
conf1 |= resolution;
conf1 |= ISL29125_CON1_SYNCOFF; /* TODO: implement SYNC mode configuration */
/* TODO: implement configuration 2: infrared compensation configuration */
/* acquire exclusive access to the bus */
DEBUG("isl29125_init: i2c_acquire\n");
(void) i2c_acquire(dev->i2c);
/* initialize the I2C bus */
DEBUG("isl29125_init: i2c_init_master\n");
(void) i2c_init_master(i2c, I2C_SPEED_NORMAL);
/* verify the device ID */
DEBUG("isl29125_init: i2c_read_reg\n");
uint8_t reg_id;
int ret = i2c_read_reg(dev->i2c, ISL29125_I2C_ADDRESS, ISL29125_REG_ID, ®_id);
if ((reg_id == ISL29125_ID) && (ret == 1)) {
DEBUG("isl29125_init: ID successfully verified\n");
}
else {
DEBUG("isl29125_init: ID could not be verified, ret: %i\n", ret);
(void) i2c_release(dev->i2c);
return -1;
}
/* configure and enable the sensor */
DEBUG("isl29125_init: i2c_write_reg(ISL29125_REG_RESET)\n");
(void) i2c_write_reg(dev->i2c, ISL29125_I2C_ADDRESS, ISL29125_REG_RESET, ISL29125_CMD_RESET);
DEBUG("isl29125_init: i2c_write_reg(ISL29125_REG_CONF1)\n");
(void) i2c_write_reg(dev->i2c, ISL29125_I2C_ADDRESS, ISL29125_REG_CONF1, conf1);
/* release the I2C bus */
DEBUG("isl29125_init: i2c_release\n");
(void) i2c_release(dev->i2c);
DEBUG("isl29125_init: success\n");
return 0;
}
示例6: mpu9150_init
int mpu9150_init(mpu9150_t *dev, i2c_t i2c, mpu9150_hw_addr_t hw_addr,
mpu9150_comp_addr_t comp_addr)
{
char temp;
dev->i2c_dev = i2c;
dev->hw_addr = hw_addr;
dev->comp_addr = comp_addr;
dev->conf = DEFAULT_STATUS;
/* Initialize I2C interface */
if (i2c_init_master(dev->i2c_dev, I2C_SPEED_FAST)) {
DEBUG("[Error] I2C device not enabled\n");
return -1;
}
/* Acquire exclusive access */
i2c_acquire(dev->i2c_dev);
/* Reset MPU9150 registers and afterwards wake up the chip */
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_RESET);
hwtimer_wait(HWTIMER_TICKS(MPU9150_RESET_SLEEP_US));
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP);
/* Release the bus, it is acquired again inside each function */
i2c_release(dev->i2c_dev);
/* Set default full scale ranges and sample rate */
mpu9150_set_gyro_fsr(dev, MPU9150_GYRO_FSR_2000DPS);
mpu9150_set_accel_fsr(dev, MPU9150_ACCEL_FSR_2G);
mpu9150_set_sample_rate(dev, MPU9150_DEFAULT_SAMPLE_RATE);
/* Disable interrupt generation */
i2c_acquire(dev->i2c_dev);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_ENABLE_REG, REG_RESET);
/* Initialize magnetometer */
if (compass_init(dev)) {
i2c_release(dev->i2c_dev);
return -2;
}
/* Release the bus, it is acquired again inside each function */
i2c_release(dev->i2c_dev);
mpu9150_set_compass_sample_rate(dev, 10);
/* Enable all sensors */
i2c_acquire(dev->i2c_dev);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_PLL);
i2c_read_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, &temp);
temp &= ~(MPU9150_PWR_ACCEL | MPU9150_PWR_GYRO);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, temp);
i2c_release(dev->i2c_dev);
hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US));
return 0;
}
示例7: jc42_get_register
static int jc42_get_register(const jc42_t* dev, uint8_t reg, uint16_t* data)
{
i2c_acquire(dev->i2c);
if (i2c_read_regs(dev->i2c, dev->addr, reg, data, 2, 0) != 0) {
DEBUG("[jc42] Problem reading register 0x%x\n", reg);
i2c_release(dev->i2c);
return JC42_NODEV;
}
i2c_release(dev->i2c);
return JC42_OK;
}
示例8: l3g4200d_init
int l3g4200d_init(l3g4200d_t *dev, i2c_t i2c, uint8_t address,
gpio_t int1_pin, gpio_t int2_pin,
l3g4200d_mode_t mode, l3g4200d_scale_t scale)
{
char tmp;
/* Acquire exclusive access to the bus. */
i2c_acquire(dev->i2c);
/* initialize the I2C bus */
if (i2c_init_master(i2c, I2C_SPEED) < 0) {
/* Release the bus for other threads. */
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
/* write device descriptor */
dev->i2c = i2c;
dev->addr = address;
dev->int1 = int1_pin;
dev->int2 = int2_pin;
/* set scale */
switch (scale) {
case L3G4200D_SCALE_250DPS:
dev->scale = 250;
break;
case L3G4200D_SCALE_500DPS:
dev->scale = 500;
break;
case L3G4200D_SCALE_2000DPS:
dev->scale = 2000;
break;
default:
dev->scale = 500;
break;
}
/* configure CTRL_REG1 */
tmp = ((mode & 0xf) << L3G4200D_CTRL1_MODE_POS) | L3G4200D_CTRL1_ALLON;
i2c_acquire(dev->i2c);
if (i2c_write_reg(dev->i2c, dev->addr, L3G4200D_REG_CTRL1, tmp) != 1) {
i2c_release(dev->i2c);
return -1;
}
tmp = ((scale & 0x3) << L3G4200D_CTRL4_FS_POS) | L3G4200D_CTRL4_BDU;
if (i2c_write_reg(dev->i2c, dev->addr, L3G4200D_REG_CTRL4, tmp) != 1) {
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
return 0;
}
示例9: tcs37727_read
int tcs37727_read(tcs37727_t *dev, tcs37727_data_t *data)
{
uint8_t buf[8];
if (dev->initialized == false) {
return -1;
}
i2c_acquire(dev->i2c);
if (i2c_read_regs(dev->i2c, dev->addr,
(TCS37727_INC_TRANS | TCS37727_CDATA), buf, 8) != 8) {
i2c_release(dev->i2c);
return -1;
}
i2c_release(dev->i2c);
int32_t tmpc = ((uint16_t)buf[1] << 8) | buf[0];
int32_t tmpr = ((uint16_t)buf[3] << 8) | buf[2];
int32_t tmpg = ((uint16_t)buf[5] << 8) | buf[4];
int32_t tmpb = ((uint16_t)buf[7] << 8) | buf[6];
DEBUG("rawr: %"PRIi32" rawg %"PRIi32" rawb %"PRIi32" rawc %"PRIi32"\n",
tmpr, tmpg, tmpb, tmpc);
/* Remove IR component as described in the DN40. */
int32_t ir = (tmpr + tmpg + tmpb - tmpc) >> 1;
tmpr -= ir;
tmpg -= ir;
tmpb -= ir;
/* Color temperature calculation as described in the DN40. */
int32_t ct = (CT_COEF_IF * tmpb) / tmpr + CT_OFFSET_IF;
/* Lux calculation as described in the DN40. */
int32_t gi = R_COEF_IF * tmpr + G_COEF_IF * tmpg + B_COEF_IF * tmpb;
/* TODO: add Glass Attenuation Factor GA compensation */
int32_t cpl = (dev->atime_us * dev->again) / DGF_IF;
int32_t lux = gi / cpl;
/* Autogain */
tcs37727_trim_gain(dev, tmpc);
data->red = (tmpr < 0) ? 0 : (tmpr * 1000) / cpl;
data->green = (tmpg < 0) ? 0 : (tmpg * 1000) / cpl;
data->blue = (tmpb < 0) ? 0 : (tmpb * 1000) / cpl;
data->clear = (tmpb < 0) ? 0 : (tmpc * 1000) / cpl;
data->lux = (lux < 0) ? 0 : lux;
data->ct = (ct < 0) ? 0 : ct;
return 0;
}
示例10: mma8652_init
int mma8652_init(mma8652_t *dev, i2c_t i2c, uint8_t address, uint8_t dr, uint8_t range, uint8_t type)
{
uint8_t reg;
/* write device descriptor */
dev->i2c = i2c;
dev->addr = address;
dev->initialized = false;
if (dr > MMA8652_DATARATE_1HZ56 || range > MMA8652_FS_RANGE_8G || type >= MMA8x5x_TYPE_MAX) {
return -1;
}
dev->type = type;
i2c_acquire(dev->i2c);
/* initialize the I2C bus */
if (i2c_init_master(i2c, I2C_SPEED) < 0) {
i2c_release(dev->i2c);
return -2;
}
i2c_release(dev->i2c);
if (mma8652_test(dev)) {
return -3;
}
if (mma8652_set_standby(dev) < 0) {
return -4;
}
reg = MMA8652_XYZ_DATA_CFG_FS(range);
i2c_acquire(dev->i2c);
if (i2c_write_regs(dev->i2c, dev->addr, MMA8652_XYZ_DATA_CFG, ®, 1) != 1) {
i2c_release(dev->i2c);
return -5;
}
reg = MMA8652_CTRL_REG1_DR(dr);
if (i2c_write_regs(dev->i2c, dev->addr, MMA8652_CTRL_REG1, ®, 1) != 1) {
i2c_release(dev->i2c);
return -5;
}
i2c_release(dev->i2c);
dev->initialized = true;
dev->scale = 1024 >> range;
return 0;
}
示例11: mpl3115a2_is_ready
int mpl3115a2_is_ready(const mpl3115a2_t *dev)
{
uint8_t reg;
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MPL3115A2_STATUS, ®, 1, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}
i2c_release(BUS);
return reg & MPL3115A2_STATUS_PTDR;
}
示例12: mpl3115a2_read_temp
int mpl3115a2_read_temp(const mpl3115a2_t *dev, int16_t *temp)
{
uint8_t buf[2];
i2c_acquire(BUS);
if (i2c_read_regs(BUS, ADDR, MPL3115A2_OUT_T_MSB, buf, 2, 0) < 0) {
i2c_release(BUS);
return -MPL3115A2_ERROR_I2C;
}
i2c_release(BUS);
*temp = ((int16_t)(((int16_t)buf[0] << 8) | buf[1]) * 10) / 256;
return MPL3115A2_OK;
}
示例13: mpl3115a2_reset
int mpl3115a2_reset(const mpl3115a2_t *dev)
{
uint8_t reg;
i2c_acquire(BUS);
reg = MPL3115A2_CTRL_REG1_RST;
if (i2c_write_regs(BUS, ADDR, MPL3115A2_CTRL_REG1, ®, 1, 0) < 0) {
i2c_release(BUS);
LOG_ERROR("mpl3115a2_reset: failed!\n");
return -MPL3115A2_ERROR_I2C;
}
i2c_release(BUS);
return MPL3115A2_OK;
}
示例14: exit_handler
static void exit_handler(int32_t signum)
{
IN(DEBUG_MODEL_MISC, "signum %d", signum);
if(_gExitFlag)
return;
_gExitFlag=1;
cmd_queue_release();
menu_release();
menu_queue_release();
i2c_release();
pipe_uninit();
#if(_DEBUG_ == 1 && _DEBUG_TO_FILE_ == 1)
if(gDebugToFile == 1)
util_debug_file_uninit();
#endif
if(SIGQUIT == signum && _gQuitHandler)
_gQuitHandler(signum);
else if(SIGKILL == signum && _gKillHandler)
_gKillHandler(signum);
else if(SIGTERM == signum && _gTermHandler)
_gTermHandler(signum);
else if(SIGINT == signum && _gIntHandler)
{
debug_print(DEBUG_MODEL_MISC, "kekeke\n");
_gIntHandler(signum);
}
exit(0);
}
示例15: i2c_init_port
static void i2c_init_port(unsigned int port)
{
const int i2c_clock_bit[] = {21, 22};
if (!(STM32_RCC_APB1ENR & (1 << i2c_clock_bit[port]))) {
/* Only unwedge the bus if the clock is off */
if (i2c_claim(port) == EC_SUCCESS) {
i2c_release(port);
}
/* enable I2C2 clock */
STM32_RCC_APB1ENR |= 1 << i2c_clock_bit[port];
}
/* force reset of the i2c peripheral */
STM32_I2C_CR1(port) = 0x8000;
STM32_I2C_CR1(port) = 0x0000;
/* set clock configuration : standard mode (100kHz) */
STM32_I2C_CCR(port) = I2C_CCR;
/* set slave address */
if (port == I2C2)
STM32_I2C_OAR1(port) = I2C_ADDRESS;
/* configuration : I2C mode / Periphal enabled, ACK enabled */
STM32_I2C_CR1(port) = (1 << 10) | (1 << 0);
/* error and event interrupts enabled / input clock is 16Mhz */
STM32_I2C_CR2(port) = (1 << 9) | (1 << 8) | 0x10;
/* clear status */
STM32_I2C_SR1(port) = 0;
board_i2c_post_init(port);
}