@@ -42,13 +42,20 @@ struct afbr_s50_data {
42
42
struct afbr_s50_platform_data platform ;
43
43
};
44
44
45
- /* Only used to get DTS bindings, otherwise passed onto platform struct */
46
45
struct afbr_s50_config {
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 ;
46
+ /* GPIOs only used to get DTS bindings, otherwise passed onto platform struct */
47
+ struct {
48
+ struct gpio_dt_spec cs ;
49
+ struct gpio_dt_spec clk ;
50
+ struct gpio_dt_spec mosi ;
51
+ struct gpio_dt_spec miso ;
52
+ struct gpio_dt_spec irq ;
53
+ } gpio ;
54
+ struct {
55
+ uint32_t odr ;
56
+ uint8_t dual_freq_mode ;
57
+ uint8_t measurement_mode ;
58
+ } settings ;
52
59
};
53
60
54
61
static void data_ready_work_handler (struct rtio_iodev_sqe * iodev_sqe )
@@ -266,6 +273,7 @@ int afbr_s50_platform_init(struct afbr_s50_platform_data *platform_data)
266
273
static int afbr_s50_init (const struct device * dev )
267
274
{
268
275
struct afbr_s50_data * data = dev -> data ;
276
+ const struct afbr_s50_config * cfg = dev -> config ;
269
277
status_t status ;
270
278
int err ;
271
279
@@ -281,16 +289,28 @@ static int afbr_s50_init(const struct device *dev)
281
289
return - ENOMEM ;
282
290
}
283
291
284
- status = Argus_Init (data -> platform .argus .handle , data -> platform .argus .id );
292
+ /** InitMode */
293
+ status = Argus_InitMode (data -> platform .argus .handle ,
294
+ data -> platform .argus .id ,
295
+ cfg -> settings .measurement_mode );
285
296
if (status != STATUS_OK ) {
286
297
LOG_ERR ("Failed to initialize device" );
287
298
return - EIO ;
288
299
}
289
300
301
+ status = Argus_SetConfigurationDFMMode (data -> platform .argus .handle ,
302
+ cfg -> settings .dual_freq_mode );
303
+ if (status != STATUS_OK ) {
304
+ LOG_ERR ("Failed to set DFM mode: %d" , status );
305
+ return - EIO ;
306
+ }
307
+
308
+ uint32_t period_us = USEC_PER_SEC / cfg -> settings .odr ;
309
+
290
310
status = Argus_SetConfigurationFrameTime (data -> platform .argus .handle ,
291
- 100000 );
311
+ period_us );
292
312
if (status != STATUS_OK ) {
293
- LOG_ERR ("Failed to set frame time" );
313
+ LOG_ERR ("Failed to set frame time: %d" , status );
294
314
return - EIO ;
295
315
}
296
316
@@ -341,6 +361,16 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
341
361
342
362
#define AFBR_S50_INIT (inst ) \
343
363
\
364
+ BUILD_ASSERT(DT_INST_PROP(inst, odr) > 0, "Please set valid ODR"); \
365
+ BUILD_ASSERT((DT_INST_PROP(inst, dual_freq_mode) != 0) ^ \
366
+ ((DT_INST_PROP(inst, measurement_mode) & ARGUS_MODE_FLAG_HIGH_SPEED) != 0), \
367
+ "High Speed mode is not compatible with Dual-Frequency mode enabled. " \
368
+ "Please disable it on device-tree or change measurement modes"); \
369
+ BUILD_ASSERT((DT_INST_PROP(inst, dual_freq_mode) != 0) ^ \
370
+ (DT_INST_PROP(inst, odr) > 100), \
371
+ "ODR is too high for Dual-Frequency mode. Please reduce it to " \
372
+ "100Hz or less"); \
373
+ \
344
374
RTIO_DEFINE(afbr_s50_rtio_ctx_##inst, 8, 8); \
345
375
SPI_DT_IODEV_DEFINE(afbr_s50_bus_##inst, \
346
376
DT_DRV_INST(inst), \
@@ -349,10 +379,17 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
349
379
0U); \
350
380
\
351
381
static const struct afbr_s50_config afbr_s50_cfg_##inst = { \
352
- .irq = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
353
- .clk = GPIO_DT_SPEC_INST_GET_OR(inst, spi_sck_gpios, {0}), \
354
- .miso = GPIO_DT_SPEC_INST_GET_OR(inst, spi_miso_gpios, {0}), \
355
- .mosi = GPIO_DT_SPEC_INST_GET_OR(inst, spi_mosi_gpios, {0}), \
382
+ .gpio = { \
383
+ .irq = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
384
+ .clk = GPIO_DT_SPEC_INST_GET_OR(inst, spi_sck_gpios, {0}), \
385
+ .miso = GPIO_DT_SPEC_INST_GET_OR(inst, spi_miso_gpios, {0}), \
386
+ .mosi = GPIO_DT_SPEC_INST_GET_OR(inst, spi_mosi_gpios, {0}), \
387
+ }, \
388
+ .settings = { \
389
+ .odr = DT_INST_PROP(inst, odr), \
390
+ .dual_freq_mode = DT_INST_PROP(inst, dual_freq_mode), \
391
+ .measurement_mode = DT_INST_PROP(inst, measurement_mode), \
392
+ }, \
356
393
}; \
357
394
\
358
395
PINCTRL_DT_DEV_CONFIG_DECLARE(DT_INST_PARENT(inst)); \
@@ -370,11 +407,11 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
370
407
.spi = { \
371
408
.cs = \
372
409
&_spi_dt_spec_##afbr_s50_bus_##inst.config.cs.gpio,\
373
- .clk = &afbr_s50_cfg_##inst.clk, \
374
- .mosi = &afbr_s50_cfg_##inst.mosi, \
375
- .miso = &afbr_s50_cfg_##inst.miso, \
410
+ .clk = &afbr_s50_cfg_##inst.gpio. clk, \
411
+ .mosi = &afbr_s50_cfg_##inst.gpio. mosi, \
412
+ .miso = &afbr_s50_cfg_##inst.gpio. miso, \
376
413
}, \
377
- .irq = &afbr_s50_cfg_##inst.irq, \
414
+ .irq = &afbr_s50_cfg_##inst.gpio. irq, \
378
415
}, \
379
416
}, \
380
417
}, \
0 commit comments