/*
	Versione driver sensirion adattata a nordic zephyr sdk 1.6.1
	Davide Alessandrini
	08/09/2021
*/

#include "sps30.h"

#define DELAY_USEC (SENSIRION_I2C_CLOCK_PERIOD_USEC / 2)

#if SPS30_BUS_I2C
static int sps30_bus_check_i2c(const struct device *bus,
				const union sps30_bus_config *bus_config)
{
	return device_is_ready(bus) ? 0 : -ENODEV;
}

static int sps30_reg_read_i2c(const struct device *bus,
			       const union sps30_bus_config *bus_config,
			       uint8_t *buf, uint32_t size)
{
	return i2c_read(bus, buf, size, bus_config->i2c_addr);
}

static int sps30_reg_write_i2c(const struct device *bus,
				const union sps30_bus_config *bus_config,
				uint8_t *buf, uint32_t num_bytes)
{
        return i2c_write(bus, buf, num_bytes, bus_config->i2c_addr);
}

const struct sps30_bus_io sps30_bus_io_i2c = {
	.check = sps30_bus_check_i2c,
	.read = sps30_reg_read_i2c,
	.write = sps30_reg_write_i2c,
};
#endif	/* SPS30_BUS_I2C */
