#ifndef ZEPHYR_DRIVERS_SENSOR_SPS30_H_
#define ZEPHYR_DRIVERS_SENSOR_SPS30_H_

#include <zephyr/types.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>

#define SPS30_BUS_I2C DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)

union sps30_bus_config {
#if SPS30_BUS_I2C
	uint16_t i2c_addr;
#endif
};

#define SPS30_MAX_SERIAL_LEN 32
/* 1s measurement intervals */
#define SPS30_MEASUREMENT_DURATION_USEC 1000000 /* 1s */
/* 100ms delay after resetting the sensor */
#define SPS30_RESET_DELAY_USEC 100000
/** The fan is switched on but not running */
#define SPS30_DEVICE_STATUS_FAN_ERROR_MASK (1 << 4)
/** The laser current is out of range */
#define SPS30_DEVICE_STATUS_LASER_ERROR_MASK (1 << 5)
/** The fan speed is out of range */
#define SPS30_DEVICE_STATUS_FAN_SPEED_WARNING (1 << 21)
/** Time waiting during sensor proibing*/
#define SPS30_PROIBING_WAIT_TIME 1000000
/** Number of samples to collect during a measurement, then driver provides average*/
#define SPS30_MEASUREMENT_SAMPLES_NUM_DEFAULT	30

#define SPS30_SET_BITS(reg_data, bitname, data)		  \
	((reg_data & ~(bitname##_MSK)) | ((data << bitname##_POS) \
					  & bitname##_MSK))
#define BMI270_SET_BITS_POS_0(reg_data, bitname, data) \
	((reg_data & ~(bitname##_MSK)) | (data & bitname##_MSK))


struct sps30_dev_config {
	const char *i2c_master_name;
	uint16_t i2c_addr;
};

typedef int (*sps30_bus_check_fn)(const struct device *bus,
                                  const union sps30_bus_config *bus_config);
typedef int (*sps30_read_fn)( const struct device *bus,
                              const union sps30_bus_config *bus_config,
                              uint8_t *buf, uint32_t len);
typedef int (*sps30_write_fn)(const struct device *bus,
                              const union sps30_bus_config *bus_config,
                              uint8_t *buf, uint32_t len);

struct sps30_bus_io {
	sps30_bus_check_fn check;
	sps30_read_fn read;
	sps30_write_fn write;
};

/* i2c specific API extern */
extern const struct sps30_bus_io sps30_bus_io_i2c;

#endif /* ZEPHYR_DRIVERS_SENSOR_SPS30_H_ */
