/*
 * Copyright (c) 2020 TDK Invensense
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_DRIVERS_SENSOR_ICP20100_ICP20100_H_
#define ZEPHYR_DRIVERS_SENSOR_ICP20100_ICP20100_H_

#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <zephyr/types.h>

#include "icp20100_reg.h"

struct icp20100_data {
	uint8_t fifo_data[HARDWARE_FIFO_SIZE];

	int32_t temperature;
	int32_t pressure;

	uint8_t operation_mode;

	bool temperature_en;
	bool pressure_en;
	
	bool sensor_started;

	const struct device *dev;
	struct gpio_callback gpio_cb;

	struct sensor_trigger data_ready_trigger;
	sensor_trigger_handler_t data_ready_handler;

#ifdef CONFIG_ICP20100_TRIGGER
	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ICP20100_THREAD_STACK_SIZE);
	struct k_thread thread;
	struct k_sem gpio_sem;
#endif
};

struct icp20100_config {
	struct spi_dt_spec spi;
	struct gpio_dt_spec gpio_int;
	uint8_t operation_mode;
};

int icp20100_trigger_set(const struct device *dev,
			 const struct sensor_trigger *trig,
			 sensor_trigger_handler_t handler);

int icp20100_init_interrupt(const struct device *dev);

#endif /* __SENSOR_ICP20100__ */
