summaryrefslogtreecommitdiff
path: root/src/driver/bme680_util.cc
blob: 7993778e17c381452a090c7cd5097a3d97a5ba61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "arch.h"
#if defined(CONFIG_meta_driver_hardware_i2c)
#include "driver/i2c.h"
#elif defined(CONFIG_driver_softi2c)
#include "driver/soft_i2c.h"
#endif
#include <stdint.h>

void bme680_delay_ms(uint32_t const period)
{
	arch.delay_ms(period);
}

void bme680_sleep_ms(uint32_t const period)
{
#if defined(CONFIG_arch_posix)
	arch.delay_ms(period);
#else
	arch.sleep_ms(period);
#endif
}

int8_t bme680_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
	int8_t ret = i2c.xmit(dev_id, 1, &reg_addr, 0, 0);
	if (ret) {
		return ret;
	}
	return i2c.xmit(dev_id, 0, 0, len, reg_data);
}

int8_t bme680_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
	unsigned char txbuf[len+1];
	txbuf[0] = reg_addr;
	for (uint16_t i = 0; i < len; i++) {
		txbuf[i+1] = reg_data[i];
	}
	return i2c.xmit(dev_id, len + 1, txbuf, 0, 0);
}