@@ -41,13 +41,20 @@ struct afbr_s50_data {
41
41
struct afbr_s50_platform_data platform ;
42
42
};
43
43
44
- /* Only used to get DTS bindings, otherwise passed onto platform struct */
45
44
struct 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 ;
51
58
};
52
59
53
60
static 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)
265
272
static int afbr_s50_init (const struct device * dev )
266
273
{
267
274
struct afbr_s50_data * data = dev -> data ;
275
+ const struct afbr_s50_config * cfg = dev -> config ;
268
276
status_t status ;
269
277
int err ;
270
278
@@ -280,16 +288,28 @@ static int afbr_s50_init(const struct device *dev)
280
288
return - ENOMEM ;
281
289
}
282
290
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 );
284
295
if (status != STATUS_OK ) {
285
296
LOG_ERR ("Failed to initialize device" );
286
297
return - EIO ;
287
298
}
288
299
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
+
289
309
status = Argus_SetConfigurationFrameTime (data -> platform .argus .handle ,
290
- 100000 );
310
+ period_us );
291
311
if (status != STATUS_OK ) {
292
- LOG_ERR ("Failed to set frame time" );
312
+ LOG_ERR ("Failed to set frame time: %d" , status );
293
313
return - EIO ;
294
314
}
295
315
@@ -340,6 +360,16 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
340
360
341
361
#define AFBR_S50_INIT (inst ) \
342
362
\
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
+ \
343
373
RTIO_DEFINE(afbr_s50_rtio_ctx_##inst, 8, 8); \
344
374
SPI_DT_IODEV_DEFINE(afbr_s50_bus_##inst, \
345
375
DT_DRV_INST(inst), \
@@ -348,10 +378,17 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
348
378
0U); \
349
379
\
350
380
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
+ }, \
355
392
}; \
356
393
\
357
394
PINCTRL_DT_DEV_CONFIG_DECLARE(DT_INST_PARENT(inst)); \
@@ -369,11 +406,11 @@ BUILD_ASSERT(CONFIG_MAIN_STACK_SIZE >= 4096,
369
406
.spi = { \
370
407
.cs = \
371
408
&_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, \
375
412
}, \
376
- .irq = &afbr_s50_cfg_##inst.irq, \
413
+ .irq = &afbr_s50_cfg_##inst.gpio. irq, \
377
414
}, \
378
415
}, \
379
416
}, \
0 commit comments