@@ -41,13 +41,20 @@ struct afbr_s50_data {
4141 struct afbr_s50_platform_data platform ;
4242};
4343
44- /* Only used to get DTS bindings, otherwise passed onto platform struct */
4544struct afbr_s50_config {
46- struct gpio_dt_spec cs ;
47- struct gpio_dt_spec clk ;
48- struct gpio_dt_spec mosi ;
49- struct gpio_dt_spec miso ;
50- struct gpio_dt_spec irq ;
45+ /* GPIOs only used to get DTS bindings, otherwise passed onto platform struct */
46+ struct {
47+ struct gpio_dt_spec cs ;
48+ struct gpio_dt_spec clk ;
49+ struct gpio_dt_spec mosi ;
50+ struct gpio_dt_spec miso ;
51+ struct gpio_dt_spec irq ;
52+ } gpio ;
53+ struct {
54+ uint32_t odr ;
55+ uint8_t dual_freq_mode ;
56+ uint8_t measurement_mode ;
57+ } settings ;
5158};
5259
5360static void data_ready_work_handler (struct rtio_iodev_sqe * iodev_sqe )
@@ -265,6 +272,7 @@ int afbr_s50_platform_init(struct afbr_s50_platform_data *platform_data)
265272static int afbr_s50_init (const struct device * dev )
266273{
267274 struct afbr_s50_data * data = dev -> data ;
275+ const struct afbr_s50_config * cfg = dev -> config ;
268276 status_t status ;
269277 int err ;
270278
@@ -280,16 +288,28 @@ static int afbr_s50_init(const struct device *dev)
280288 return - ENOMEM ;
281289 }
282290
283- status = Argus_Init (data -> platform .argus .handle , data -> platform .argus .id );
291+ /** InitMode */
292+ status = Argus_InitMode (data -> platform .argus .handle ,
293+ data -> platform .argus .id ,
294+ cfg -> settings .measurement_mode );
284295 if (status != STATUS_OK ) {
285296 LOG_ERR ("Failed to initialize device" );
286297 return - EIO ;
287298 }
288299
300+ status = Argus_SetConfigurationDFMMode (data -> platform .argus .handle ,
301+ cfg -> settings .dual_freq_mode );
302+ if (status != STATUS_OK ) {
303+ LOG_ERR ("Failed to set DFM mode: %d" , status );
304+ return - EIO ;
305+ }
306+
307+ uint32_t period_us = USEC_PER_SEC / cfg -> settings .odr ;
308+
289309 status = Argus_SetConfigurationFrameTime (data -> platform .argus .handle ,
290- 100000 );
310+ period_us );
291311 if (status != STATUS_OK ) {
292- LOG_ERR ("Failed to set frame time" );
312+ LOG_ERR ("Failed to set frame time: %d" , status );
293313 return - EIO ;
294314 }
295315
@@ -340,6 +360,16 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
340360
341361#define AFBR_S50_INIT (inst ) \
342362 \
363+ BUILD_ASSERT(DT_INST_PROP(inst, odr) > 0, "Please set valid ODR"); \
364+ BUILD_ASSERT((DT_INST_PROP(inst, dual_freq_mode) != 0) ^ \
365+ ((DT_INST_PROP(inst, measurement_mode) & ARGUS_MODE_FLAG_HIGH_SPEED) != 0), \
366+ "High Speed mode is not compatible with Dual-Frequency mode enabled. " \
367+ "Please disable it on device-tree or change measurement modes"); \
368+ BUILD_ASSERT((DT_INST_PROP(inst, dual_freq_mode) != 0) ^ \
369+ (DT_INST_PROP(inst, odr) > 100), \
370+ "ODR is too high for Dual-Frequency mode. Please reduce it to " \
371+ "100Hz or less"); \
372+ \
343373 RTIO_DEFINE(afbr_s50_rtio_ctx_##inst, 8, 8); \
344374 SPI_DT_IODEV_DEFINE(afbr_s50_bus_##inst, \
345375 DT_DRV_INST(inst), \
@@ -348,10 +378,17 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
348378 0U); \
349379 \
350380 static const struct afbr_s50_config afbr_s50_cfg_##inst = { \
351- .irq = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
352- .clk = GPIO_DT_SPEC_INST_GET_OR(inst, spi_sck_gpios, {0}), \
353- .miso = GPIO_DT_SPEC_INST_GET_OR(inst, spi_miso_gpios, {0}), \
354- .mosi = GPIO_DT_SPEC_INST_GET_OR(inst, spi_mosi_gpios, {0}), \
381+ .gpio = { \
382+ .irq = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
383+ .clk = GPIO_DT_SPEC_INST_GET_OR(inst, spi_sck_gpios, {0}), \
384+ .miso = GPIO_DT_SPEC_INST_GET_OR(inst, spi_miso_gpios, {0}), \
385+ .mosi = GPIO_DT_SPEC_INST_GET_OR(inst, spi_mosi_gpios, {0}), \
386+ }, \
387+ .settings = { \
388+ .odr = DT_INST_PROP(inst, odr), \
389+ .dual_freq_mode = DT_INST_PROP(inst, dual_freq_mode), \
390+ .measurement_mode = DT_INST_PROP(inst, measurement_mode), \
391+ }, \
355392 }; \
356393 \
357394 PINCTRL_DT_DEV_CONFIG_DECLARE(DT_INST_PARENT(inst)); \
@@ -369,11 +406,11 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
369406 .spi = { \
370407 .cs = \
371408 &_spi_dt_spec_##afbr_s50_bus_##inst.config.cs.gpio,\
372- .clk = &afbr_s50_cfg_##inst.clk, \
373- .mosi = &afbr_s50_cfg_##inst.mosi, \
374- .miso = &afbr_s50_cfg_##inst.miso, \
409+ .clk = &afbr_s50_cfg_##inst.gpio. clk, \
410+ .mosi = &afbr_s50_cfg_##inst.gpio. mosi, \
411+ .miso = &afbr_s50_cfg_##inst.gpio. miso, \
375412 }, \
376- .irq = &afbr_s50_cfg_##inst.irq, \
413+ .irq = &afbr_s50_cfg_##inst.gpio. irq, \
377414 }, \
378415 }, \
379416 }, \
0 commit comments