Wrtting sensor driver in zephyr, DT_INST_FOREACH_STATUS_OKAY problem.

Hello,

I'm trying to writte a sensordriver for the nuvoton NAU7802 ADC in Zephyr using the drivers/sensor API. Here are the most important (I believe) parts of my code:

In nau7802.h:

struct nau7802_data {
	const struct device *dev;
	uint8_t resolution;
	uint8_t sample;
	uint8_t ldo;
	uint8_t sps;
	uint8_t gain;
};

struct nau7802_config {
	struct i2c_dt_spec bus;
	uint16_t config;
	uint8_t resolution;
	uint8_t sample;
	uint8_t ldo;
	uint8_t sps;
	uint8_t gain;
#ifdef CONFIG_NAU7802_TRIGGER
	const struct gpio_dt_spec gpio_drdy;
#endif /* CONFIG_NAU7802_TRIGGER */	
};

In nau7802.c:

#define DT_DRV_COMPAT nuvoton_nau7802

static const struct sensor_driver_api nau7802_driver_api = {
	.attr_set = nau7802_attr_set,
	.attr_get = nau7802_attr_get,
#ifdef CONFIG_NAU7802_TRIGGER
	.trigger_set = nau7802_trigger_set,
#endif
	.sample_fetch = nau7802_sample_fetch,
	.channel_get = nau7802_channel_get,
};

#define NAU7802_DEVICE_INIT(inst)								\
	static struct nau7802_data drv_data_##inst;		    		\
	static const struct nau7802_config drv_config_##inst = {    \
		.bus = I2C_DT_SPEC_INST_GET(inst),		    			\
		.config = DT_INST_PROP(inst, config),		    		\
		.resolution = DT_INST_PROP(inst, resolution),	    	\
		.sample = DT_INST_PROP(inst, sample),					\
		.ldo = DT_INST_PROP(inst, ldo),							\
		.sps = DT_INST_PROP(inst, sps),							\
		.gain = DT_INST_PROP(inst, gain),						\
		COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, gpio_drdy), 	\
						(NAU7802_CFG_IRQ(inst)), ())		    \
	};							   		 		\
	DEVICE_DT_INST_DEFINE(inst,					\
			    &nau7802_begin,					\
				NULL,							\
			    &drv_data_##inst,				\
			    &drv_config_##inst,				\
			    POST_KERNEL,					\
			    CONFIG_SENSOR_INIT_PRIORITY,	\
			    &nau7802_driver_api);

DT_INST_FOREACH_STATUS_OKAY(NAU7802_DEVICE_INIT)

And I've added the kconfig and yaml files too,and the device node in my overlay file. However, I'm getting an error when compiling:

devicetree_unfixed.h:11825:37: error: 'DT_N_S_soc_S_i2c_40004000_S_nau7802_2a_P_resolution' 
undeclared here (not in a function); did you mean 'DT_N_S_soc_S_i2c_40004000_S_nau7802_2a_P_reg_EXISTS'?
11825 | #define DT_N_INST_0_nuvoton_nau7802 DT_N_S_soc_S_i2c_40004000_S_nau7802_2a

I think the problem is in my data  and config structs but I can't find where is my mistake. Please, I would appreciate any insights.

Thanks in advance, bestr egards.

Parents Reply Children
No Data
Related