adding #ifdef to driver config in zephyr macrobatics

hello Nordic

i am working with nrf52832, with ncs 1.7.1

i am writing my own driver which will be used by 2 baords 

one board have to raise 2 gpios to get power and on has to raise only one

i am not sure how to use the phandle array option to group the 2 or one gpios as a gpio array and read each of them so for now i am trying to use #ifdef in the device config which fails on compilation no matter how many different versions i have tried 

this is the init:

//the structs:
struct ads8866_chain_dev_config
{
    const char *bus_name;
    const int chain_length;
    struct gpio_dt_spec pm_mag_en_gpio;
#ifdef CONFIG_BOARD_HALO_EP1
    struct gpio_dt_spec pm_5v_en_gpio;
#endif
    struct gpio_dt_spec conv_gpio;
    const int default_sample_freq;
};

struct ads8866_chain_data
{
    int sample_frequency;
    augu_spi_data_t augu_spi;

    nrfx_timer_t const *conv_pullup_timer;
    nrfx_timer_t const *spi_xfer_timer;
    nrf_ppi_channel_t conv_pull_up_ppi_ch;
    augu_sensor_trigger_handler_t app_handler;
    struct augu_sensor_trigger curr_trig;

    K_THREAD_STACK_MEMBER(thread_stack, CONFIG_ADS8866_CHAIN_THREAD_STACK_SIZE);
    struct k_thread thread;
    struct k_sem thread_sem;
};

/// the init:

static const struct ads8866_chain_dev_config ads8866_chain_config_0 = {     \
    .bus_name = DT_BUS_LABEL(DT_DRV_INST(0)),                               \
    .chain_length = DT_INST_PROP(0, chain_length),                          \
    .conv_gpio = GPIO_DT_SPEC_INST_GET(0, conv_gpios),                      \
    .pm_mag_en_gpio = GPIO_DT_SPEC_INST_GET(0, pm_mag_en_gpios),            
#if defined(CONFIG_BOARD_HALO_EP1)
    .pm_5v_en_gpio = GPIO_DT_SPEC_INST_GET(0, pm_5v_en_gpios),              
#endif \
    .default_sample_freq = DT_INST_PROP(0, def_sample_freq),                \
};


static struct ads8866_chain_data ads8866_chain_data_0;

DEVICE_DT_INST_DEFINE(
    0, 
    ads8866_chain_init, 
    ads8866_chain_pm_control,
    &ads8866_chain_data_0, 
    &ads8866_chain_config_0, 
    APPLICATION,
    CONFIG_SENSOR_INIT_PRIORITY, 
    &ads8866_chain_driver_api
);

in case you will ask then, all .yaml properties are matching, different dts also matching .. i will actually add them here:

driver in dts 1:

&spi0 {
		status = "okay";
		sck-pin = <8>;	// gpio 0 pin 8
		mosi-pin = <0xFF>;
		miso-pin = <7>;	// gpio 0 pin 7
		compatible = "nordic,nrf-spim";
		ads8866_chain@0 {
			compatible = "ti,ads8866_chain";
			reg = <0>;
			chain_length = <1>;
			def_sample_freq = <10000>;
			conv_gpios = <&gpio0 6 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
			label = "ADS8866_CHAIN";
			pm_mag_en_gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
			spi-max-frequency = <8000000>;
		};
	};
	
	
driver in dts 2:
&spi0 {
	status = "okay";
	sck-pin = <8>;	// gpio 0 pin 8
	mosi-pin = <0xFF>;
	miso-pin = <7>;	// gpio 0 pin 7
	compatible = "nordic,nrf-spim";
	ads8866_chain@0 {
		compatible = "ti,ads8866_chain";
		reg = <0>;
		chain_length = <4>;
		def_sample_freq = <20833>;
		conv_gpios = <&gpio0 6 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
		str_gpios = <&gpio0 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		stbr_gpios = <&gpio0 10 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		label = "ADS8866_CHAIN";
		pm_mag_en_gpios = <&gpio0 22 GPIO_ACTIVE_LOW>;
		pm_5v_en_gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;

		spi-max-frequency = <8000000>;
	};
};

this is the compilation log:

eFiles/..__..__canary-ep__drivers__sensor__ads8866_chain__zephyr.dir/src/ads8866_chain.c.obj -MF modules/ads8866_chain/CMakeFiles/..__..__canary-ep__drivers__sensor__ads8866_chain__zephyr.dir/src/ads8866_chain.c.obj.d -o modules/ads8866_chain/CMakeFiles/..__..__canary-ep__drivers__sensor__ads8866_chain__zephyr.dir/src/ads8866_chain.c.obj -c /home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c: In function 'ads8866_chain_trigger_set':
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:238:49: warning: comparison between 'enum ads8866_chain_sensor_channel' and 'const enum augu_sensor_channel' [-Wenum-compare]
  238 |         if( SENSOR_CHAN_ADS8866_VIB_XYZ_AND_MAG == trig->chan ||
      |                                                 ^~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:239:49: warning: comparison between 'enum ads8866_chain_sensor_channel' and 'const enum augu_sensor_channel' [-Wenum-compare]
  239 |             SENSOR_CHAN_ADS8866_MAG             == trig->chan ||
      |                                                 ^~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:240:49: warning: comparison between 'enum ads8866_chain_sensor_channel' and 'const enum augu_sensor_channel' [-Wenum-compare]
  240 |             SENSOR_CHAN_ADS8866_VIB_Z           == trig->chan ||
      |                                                 ^~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:241:46: warning: comparison between 'enum ads8866_chain_sensor_channel' and 'const enum augu_sensor_channel' [-Wenum-compare]
  241 |          SENSOR_CHAN_ADS8866_VIB_Y           == trig->chan ||
      |                                              ^~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:242:49: warning: comparison between 'enum ads8866_chain_sensor_channel' and 'const enum augu_sensor_channel' [-Wenum-compare]
  242 |             SENSOR_CHAN_ADS8866_VIB_X           == trig->chan )
      |                                                 ^~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c: At top level:
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:535:5: warning: extra tokens at end of #endif directive [-Wendif-labels]
  535 |     .default_sample_freq = DT_INST_PROP(0, def_sample_freq),                \
      |     ^
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:538:1: error: expected expression before 'static'
  538 | static struct ads8866_chain_data ads8866_chain_data_0;
      | ^~~~~~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:527:46: warning: 'ads8866_chain_config_0' defined but not used [-Wunused-const-variable=]
  527 | static const struct ads8866_chain_dev_config ads8866_chain_config_0 = {     \
      |                                              ^~~~~~~~~~~~~~~~~~~~~~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:519:44: warning: 'ads8866_chain_driver_api' defined but not used [-Wunused-const-variable=]
  519 | static const struct augu_sensor_driver_api ads8866_chain_driver_api = {
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:474:12: warning: 'ads8866_chain_init' defined but not used [-Wunused-function]
  474 | static int ads8866_chain_init(const struct device *dev)
      |            ^~~~~~~~~~~~~~~~~~
/home/zhershkovitch/workspace/canary-ep/drivers/sensor/ads8866_chain/zephyr/src/ads8866_chain.c:402:12: warning: 'ads8866_chain_pm_control' defined but not used [-Wunused-function]
  402 | static int ads8866_chain_pm_control(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state)
      |            ^~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /home/zhershkovitch/.local/bin/cmake --build /home/zhershkovitch/workspace/canary-ep/augury_app/build_halo_ep1

hope you can help me understand what i am doing wrong

best regards

Ziv

Parents Reply Children
Related