i2c_distance_detector.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2023-2024
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6
7 #include <stdarg.h>
8 #include <stdbool.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <string.h>
12
13 #include "acc_definitions_a121.h"
14 #include "acc_detector_distance.h"
15 #include "acc_hal_definitions_a121.h"
16 #include "acc_hal_integration_a121.h"
17 #include "acc_integration.h"
18 #include "acc_rss_a121.h"
19 #include "acc_version.h"
20
21 #include "acc_reg_protocol.h"
22 #include "distance_reg_protocol.h"
23 #include "i2c_application_system.h"
24 #include "i2c_distance_detector.h"
25
26 #define SENSOR_ID (1U)
27 #define SENSOR_TIMEOUT_MS (10000U)
28
29 typedef struct
30 {
31 acc_sensor_t *sensor;
32 acc_cal_result_t sensor_cal_result;
33 acc_detector_distance_config_t *config;
34 acc_detector_distance_handle_t *handle;
35 acc_detector_distance_result_t result;
36 void *buffer;
37 uint32_t buffer_size;
38 uint8_t *detector_cal_result_static;
39 uint32_t detector_cal_result_static_size;
40 acc_detector_cal_result_dynamic_t detector_cal_result_dynamic;
41 } distance_detector_resources_t;
42
43 static distance_detector_resources_t detector_resources = {0};
44 static uint32_t i2c_detector_command = 0U;
45 static uint32_t i2c_detector_status = 0U;
46 static uint32_t measure_distance_counter = 0U;
47 static bool measure_distance_error = false;
48 static bool measure_on_wakeup = false;
49 static bool uart_logs_enabed = false;
50
51 #define UART_LOG_BUFFER_SIZE 100
52
53 /**
54 * @brief Get the i2c_detector_command values
55 *
56 * The i2c_detector_command is cleared during this read
57 * The read and clear are protected by a critical section
58 *
59 * @return The command sent from the host
60 */
61 static uint32_t get_command(void);
62
63 /**
64 * @brief Execute the command sent from the host
65 *
66 * @param[in] command The command to execute
67 */
68 static void command_handler(uint32_t command);
69
70 /**
71 * @brief Set bits in the i2c_detector_status
72 *
73 * The i2c_detector_status is protected by a critical section
74 *
75 * @param[in] bit_mask The bit_mask to set
76 */
77 static void detector_status_set_bits(uint32_t bit_mask);
78
79 /**
80 * @brief Clear bits in the i2c_detector_status
81 *
82 * The i2c_detector_status is protected by a critical section
83 *
84 * @param[in] bit_mask The bit_mask to clear
85 */
86 static void detector_status_clr_bits(uint32_t bit_mask);
87
88 /**
89 * @brief Test bits in the i2c_detector_status
90 *
91 * The i2c_detector_status is protected by a critical section
92 *
93 * @param[in] bit_mask The bit_mask to test
94 * @return true if all the bits in bit_mask is set in i2c_detector_status
95 */
96 static bool detector_status_test_bits(uint32_t bit_mask);
97
98 /**
99 * @brief Create sensor
100 *
101 * @param[in] resources distance detector resources struct
102 */
103 static void create_sensor(distance_detector_resources_t *resources);
104
105 /**
106 * @brief Apply detector config
107 *
108 * This function will create the distance detector and
109 * allocate the needed memory
110 *
111 * @param[in] resources distance detector resources struct
112 */
113 static void apply_detector_config(distance_detector_resources_t *resources);
114
115 /**
116 * @brief Calibrate sensor
117 *
118 * @param[in] resources distance detector resources struct
119 */
120 static void calibrate_sensor(distance_detector_resources_t *resources);
121
122 /**
123 * @brief Calibrate detector
124 *
125 * @param[in] resources distance detector resources struct
126 * @param[in] update_calibration Set to false for first calibration, true for calibration update
127 */
128 static void calibrate_detector(distance_detector_resources_t *resources, bool update_calibration);
129
130 /**
131 * @brief Test if detector is ready
132 * @return true if detector is ready to do distance measurements
133 */
134 static bool is_detector_ready(void);
135
136 /**
137 * @brief Get next distance measurement
138 *
139 * @param[in] resources distance detector resources struct
140 */
141 static bool detector_get_next(distance_detector_resources_t *resources);
142
143 /**
144 * @brief Print the distance detector result
145 *
146 * Only available when the UART logs have been enabled with ENABLE_UART_LOGS
147 *
148 * @param[in] result The distance detector result
149 */
150 static void print_distance_result(const acc_detector_distance_result_t *result);
151
152 /**
153 * @brief UART logging function (can be enabled/disabled by command)
154 */
155 static void uart_log(const char *format, ...);
156
157 //
158 // PUBLIC FUNCTIONS
159 //
160
161 acc_detector_distance_config_t *i2c_distance_detector_get_config(void)
162 {
163 return detector_resources.config;
164 }
165
166 bool i2c_distance_detector_command(uint32_t command)
167 {
168 bool status = false;
169
170 /* Make sure we do not have a race for i2c_detector_command/i2c_detector_status */
171 acc_integration_critical_section_enter();
172
173 if (i2c_detector_command == 0U)
174 {
175 /* Set Ready PIN to LOW while processing the command */
176 i2c_application_system_set_ready_pin(false);
177
178 /* Set status BUSY bit */
179 i2c_detector_status |= DISTANCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK;
180 i2c_detector_command = command;
181 status = true;
182 }
183
184 acc_integration_critical_section_exit();
185 return status;
186 }
187
188 uint32_t i2c_distance_detector_get_status(void)
189 {
190 /* Make sure we do not have a race for i2c_detector_status */
191 acc_integration_critical_section_enter();
192
193 uint32_t status = i2c_detector_status;
194
195 acc_integration_critical_section_exit();
196
197 return status;
198 }
199
200 uint32_t i2c_distance_detector_get_result(void)
201 {
202 uint32_t value = 0;
203
204 /* Add number of distances */
205 value = (detector_resources.result.num_distances << DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_POS) &
206 DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_MASK;
207
208 /* Add near start edge boolean */
209 if (detector_resources.result.near_start_edge_status)
210 {
211 value |= DISTANCE_REG_DISTANCE_RESULT_FIELD_NEAR_START_EDGE_MASK;
212 }
213
214 /* Add calibration needed boolean */
215 if (detector_resources.result.calibration_needed)
216 {
217 value |= DISTANCE_REG_DISTANCE_RESULT_FIELD_CALIBRATION_NEEDED_MASK;
218 }
219
220 if (measure_distance_error)
221 {
222 value |= DISTANCE_REG_DISTANCE_RESULT_FIELD_MEASURE_DISTANCE_ERROR_MASK;
223 }
224
225 /* Add temperature */
226 uint32_t temp = (uint32_t)detector_resources.result.temperature;
227
228 temp = (temp << DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_POS) & DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_MASK;
229 value |= temp;
230
231 return value;
232 }
233
234 uint32_t i2c_distance_detector_get_counter(void)
235 {
236 /* Make sure we do not have a race for measure_distance_counter */
237 acc_integration_critical_section_enter();
238
239 uint32_t counter = measure_distance_counter;
240
241 acc_integration_critical_section_exit();
242
243 return counter;
244 }
245
246 float i2c_distance_detector_get_peak_distance(uint16_t peak_id)
247 {
248 float peak_distance = 0.0f;
249
250 if (peak_id < ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES)
251 {
252 peak_distance = detector_resources.result.distances[peak_id];
253 }
254
255 return peak_distance;
256 }
257
258 float i2c_distance_detector_get_peak_strength(uint16_t peak_id)
259 {
260 float peak_strength = 0.0f;
261
262 if (peak_id < ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES)
263 {
264 peak_strength = detector_resources.result.strengths[peak_id];
265 }
266
267 return peak_strength;
268 }
269
270 void i2c_distance_detector_measure_on_wakeup(bool enable)
271 {
272 /* Make sure we do not have a race for measure_on_wakeup */
273 acc_integration_critical_section_enter();
274
275 measure_on_wakeup = enable;
276
277 acc_integration_critical_section_exit();
278 }
279
280 bool i2c_distance_detector_get_measure_on_wakeup(void)
281 {
282 /* Make sure we do not have a race for measure_on_wakeup */
283 acc_integration_critical_section_enter();
284
285 bool value = measure_on_wakeup;
286
287 acc_integration_critical_section_exit();
288
289 return value;
290 }
291
292 //
293 // MAIN
294 //
295
296 int acconeer_main(int argc, char *argv[]);
297
298 int acconeer_main(int argc, char *argv[])
299 {
300 (void)argc;
301 (void)argv;
302
303 bool setup_status = true;
304
305 printf("I2C Distance Detector\n");
306 printf("Acconeer software version %s\n", acc_version_get());
307
308 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
309
310 if (acc_rss_hal_register(hal))
311 {
312 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK);
313 }
314 else
315 {
316 printf("ERROR: acc_rss_hal_register() failed\n\n");
317 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK | DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK);
318 setup_status = false;
319 }
320
321 if (setup_status)
322 {
323 detector_resources.config = acc_detector_distance_config_create();
324 if (detector_resources.config != NULL)
325 {
326 /* Config is created, write default values to registers */
327 distance_reg_protocol_write_default();
328
329 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK);
330 }
331 else
332 {
333 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK |
334 DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK);
335 printf("ERROR: acc_detector_distance_config_create() failed\n\n");
336 setup_status = false;
337 }
338 }
339
340 /* Turn the sensor on */
341 acc_hal_integration_sensor_supply_on(SENSOR_ID);
342
343 if (setup_status)
344 {
345 /* Create sensor */
346 create_sensor(&detector_resources);
347 }
348
349 i2c_application_system_init();
350
351 /* Setup i2c register protocol */
352 distance_reg_protocol_setup();
353
354 while (true)
355 {
356
357 uint32_t command = get_command();
358
359 if (command == 0)
360 {
361 if (i2c_application_system_test_wakeup_pin())
362 {
363 i2c_application_system_wait_for_interrupt();
364 }
365 else
366 {
367 /* Set ready pin LOW, we are about to power down */
368 i2c_application_system_set_ready_pin(false);
369
370 uart_log("Enter low power state\n");
371 i2c_application_enter_low_power_state();
372 uart_log("Exit low power state\n");
373
374 /**
375 * Test if measure on wake up is enable
376 * Do a measurement if the the detector is ready (configured and calibrated)
377 */
378 if (is_detector_ready() && i2c_distance_detector_get_measure_on_wakeup())
379 {
380 uart_log("Measure on wakeup\n");
381 command = DISTANCE_REG_COMMAND_ENUM_MEASURE_DISTANCE;
382 }
383 }
384
385 /* Do an extra check on command, are we in measure on wakeup mode? */
386 if (command == 0)
387 {
388 /* Set ready pin HIGH, we are ready for communication */
389 i2c_application_system_set_ready_pin(true);
390
391 /* No command to process */
392 continue;
393 }
394 }
395
396 /* Special command, always handle reset module command, even if error has occured */
397 if (command == DISTANCE_REG_COMMAND_ENUM_RESET_MODULE)
398 {
399 /* Reset system */
400 i2c_application_system_reset();
401 continue;
402 }
403
404 if (detector_status_test_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK))
405 {
406 /* Do not process commands after error state */
407 continue;
408 }
409
410 /* Handle command */
411 command_handler(command);
412
413 /* Command handler done, clear busy bit */
414 detector_status_clr_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK);
415
416 /* Set Ready PIN to HIGH when command processing is done */
417 i2c_application_system_set_ready_pin(true);
418 }
419
420 return EXIT_FAILURE;
421 }
422
423 //
424 // PRIVATE HELPER FUNCTIONS
425 //
426
427 static uint32_t get_command(void)
428 {
429 /* Make sure we do not have a race for i2c_detector_command */
430 acc_integration_critical_section_enter();
431
432 uint32_t command = i2c_detector_command;
433
434 i2c_detector_command = 0U;
435
436 acc_integration_critical_section_exit();
437
438 return command;
439 }
440
441 static void command_handler(uint32_t command)
442 {
443 bool do_apply_config = false;
444 bool do_calibrate = false;
445 bool do_recalibrate = false;
446
447 switch (command)
448 {
449 case DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION:
450 if (!detector_status_test_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK))
451 {
452 do_apply_config = true;
453 }
454
455 break;
456 case DISTANCE_REG_COMMAND_ENUM_CALIBRATE:
457 if (detector_status_test_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK))
458 {
459 do_calibrate = true;
460 }
461
462 break;
463 case DISTANCE_REG_COMMAND_ENUM_RECALIBRATE:
464 if (detector_status_test_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK))
465 {
466 do_recalibrate = true;
467 }
468
469 break;
470 case DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIG_AND_CALIBRATE:
471 if (!detector_status_test_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK))
472 {
473 do_apply_config = true;
474 do_calibrate = true;
475 }
476
477 break;
478 case DISTANCE_REG_COMMAND_ENUM_MEASURE_DISTANCE:
479 memset(&detector_resources.result, 0, sizeof(detector_resources.result));
480
481 /* Increase counter - Make sure we do not have a race for measure_distance_counter */
482 acc_integration_critical_section_enter();
483 measure_distance_counter++;
484 acc_integration_critical_section_exit();
485
486 if (detector_get_next(&detector_resources))
487 {
488 print_distance_result(&detector_resources.result);
489 measure_distance_error = false;
490 }
491 else
492 {
493 printf("ERROR: Could not get next result\n");
494 measure_distance_error = true;
495 }
496
497 break;
498 case DISTANCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS:
499 uart_logs_enabed = true;
500 uart_log("UART logs enabled\n");
501 break;
502 case DISTANCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS:
503 uart_log("UART logs disabled\n");
504 uart_logs_enabed = false;
505 break;
506 case DISTANCE_REG_COMMAND_ENUM_LOG_CONFIGURATION:
507 // Print the configuration
508 acc_detector_distance_config_log(detector_resources.handle, detector_resources.config);
509 break;
510 default:
511 printf("ERROR: Unknown command: %" PRIu32 "", command);
512 break;
513 }
514
515 /* Apply config is activated by APPLY_CONFIGURATION or APPLY_CONFIG_AND_CALIBRATE */
516 if (do_apply_config)
517 {
518 apply_detector_config(&detector_resources);
519 }
520
521 if (do_calibrate || do_recalibrate)
522 {
523 calibrate_sensor(&detector_resources);
524 calibrate_detector(&detector_resources, do_recalibrate);
525 }
526 }
527
528 static void detector_status_set_bits(uint32_t bit_mask)
529 {
530 /* Make sure we do not have a race for i2c_detector_status */
531 acc_integration_critical_section_enter();
532
533 i2c_detector_status |= bit_mask;
534 uint32_t temp_detector_status = i2c_detector_status;
535
536 acc_integration_critical_section_exit();
537
538 uart_log("Detector Status = 0x%" PRIx32 "\n", temp_detector_status);
539 }
540
541 static void detector_status_clr_bits(uint32_t bit_mask)
542 {
543 /* Make sure we do not have a race for i2c_detector_status */
544 acc_integration_critical_section_enter();
545
546 i2c_detector_status &= ~bit_mask;
547 uint32_t temp_detector_status = i2c_detector_status;
548
549 acc_integration_critical_section_exit();
550
551 uart_log("Detector Status = 0x%" PRIx32 "\n", temp_detector_status);
552 }
553
554 static bool detector_status_test_bits(uint32_t bit_mask)
555 {
556 /* Make sure we do not have a race for i2c_detector_status */
557 acc_integration_critical_section_enter();
558
559 bool status = (i2c_detector_status & bit_mask) == bit_mask;
560
561 acc_integration_critical_section_exit();
562
563 return status;
564 }
565
566 static void create_sensor(distance_detector_resources_t *resources)
567 {
568 acc_hal_integration_sensor_enable(SENSOR_ID);
569
570 resources->sensor = acc_sensor_create(SENSOR_ID);
571
572 acc_hal_integration_sensor_disable(SENSOR_ID);
573
574 if (resources->sensor != NULL)
575 {
576 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK);
577 }
578 else
579 {
580 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK |
581 DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK);
582 printf("ERROR: acc_sensor_create() failed\n");
583 }
584 }
585
586 static void apply_detector_config(distance_detector_resources_t *resources)
587 {
588 bool status = true;
589
590 resources->handle = acc_detector_distance_create(resources->config);
591 if (resources->handle != NULL)
592 {
593 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK);
594 }
595 else
596 {
597 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK |
598 DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK);
599 printf("ERROR: acc_detector_distance_create() failed\n");
600 status = false;
601 }
602
603 if (status)
604 {
605 if (acc_detector_distance_get_sizes(resources->handle, &(resources->buffer_size), &(resources->detector_cal_result_static_size)))
606 {
607 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK);
608 }
609 else
610 {
611 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK |
612 DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK);
613 printf("ERROR: acc_detector_distance_get_sizes() failed\n");
614 status = false;
615 }
616 }
617
618 if (status)
619 {
620 resources->buffer = acc_integration_mem_alloc(resources->buffer_size);
621 if (resources->buffer != NULL)
622 {
623 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK);
624 }
625 else
626 {
627 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK |
628 DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK);
629 printf("ERROR: sensor buffer allocation failed\n");
630 status = false;
631 }
632 }
633
634 if (status)
635 {
636 resources->detector_cal_result_static = acc_integration_mem_alloc(resources->detector_cal_result_static_size);
637 if (resources->detector_cal_result_static != NULL)
638 {
639 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_OK_MASK);
640 }
641 else
642 {
643 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK |
644 DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_ERROR_MASK);
645 printf("ERROR: calibration buffer allocation failed\n");
646 status = false;
647 }
648 }
649
650 if (status)
651 {
652 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK);
653 }
654 else
655 {
656 printf("ERROR: apply detector config failed\n");
657 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK | DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK);
658 }
659 }
660
661 static void calibrate_sensor(distance_detector_resources_t *resources)
662 {
663 acc_hal_integration_sensor_enable(SENSOR_ID);
664
665 detector_status_clr_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK |
666 DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK);
667
668 bool status;
669 bool cal_complete = false;
670
671 do
672 {
673 status = acc_sensor_calibrate(resources->sensor, &cal_complete, &resources->sensor_cal_result, resources->buffer, resources->buffer_size);
674
675 if (cal_complete)
676 {
677 break;
678 }
679
680 if (status)
681 {
682 status = acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS);
683 }
684 } while (status);
685
686 if (status)
687 {
688 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK);
689 }
690 else
691 {
692 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK);
693 printf("ERROR: acc_sensor_calibrate() failed\n");
694 }
695
696 /* Reset sensor after calibration by disabling it */
697 acc_hal_integration_sensor_disable(SENSOR_ID);
698 }
699
700 static void calibrate_detector(distance_detector_resources_t *resources, bool update_calibration)
701 {
702 bool done = false;
703 bool status;
704
705 acc_hal_integration_sensor_enable(SENSOR_ID);
706
707 detector_status_clr_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_OK_MASK |
708 DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_ERROR_MASK);
709
710 do
711 {
712 if (update_calibration)
713 {
714 status = acc_detector_distance_update_calibration(resources->sensor,
715 resources->handle,
716 &resources->sensor_cal_result,
717 resources->buffer,
718 resources->buffer_size,
719 &resources->detector_cal_result_dynamic,
720 &done);
721 }
722 else
723 {
724 status = acc_detector_distance_calibrate(resources->sensor,
725 resources->handle,
726 &resources->sensor_cal_result,
727 resources->buffer,
728 resources->buffer_size,
729 resources->detector_cal_result_static,
730 resources->detector_cal_result_static_size,
731 &resources->detector_cal_result_dynamic,
732 &done);
733 }
734
735 if (done)
736 {
737 break;
738 }
739
740 if (status)
741 {
742 status = acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS);
743 }
744 } while (status);
745
746 if (status)
747 {
748 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_OK_MASK);
749 }
750 else
751 {
752 if (update_calibration)
753 {
754 printf("ERROR: acc_detector_distance_update_calibration() failed\n");
755 }
756 else
757 {
758 printf("ERROR: acc_detector_distance_calibrate() failed\n");
759 }
760
761 detector_status_set_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_ERROR_MASK);
762 }
763
764 acc_hal_integration_sensor_disable(SENSOR_ID);
765 }
766
767 static bool is_detector_ready(void)
768 {
769 return detector_status_test_bits(DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK |
770 DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK |
771 DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_OK_MASK);
772 }
773
774 static bool detector_get_next(distance_detector_resources_t *resources)
775 {
776 bool result_available = false;
777 bool status = true;
778
779 acc_hal_integration_sensor_enable(SENSOR_ID);
780
781 do
782 {
783 if (!acc_detector_distance_prepare(resources->handle,
784 resources->config,
785 resources->sensor,
786 &resources->sensor_cal_result,
787 resources->buffer,
788 resources->buffer_size))
789 {
790 printf("ERROR: acc_detector_distance_prepare() failed\n");
791 status = false;
792 break;
793 }
794
795 if (!acc_sensor_measure(resources->sensor))
796 {
797 printf("ERROR: acc_sensor_measure() failed\n");
798 status = false;
799 break;
800 }
801
802 if (!acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS))
803 {
804 printf("ERROR: Sensor interrupt timeout\n");
805 status = false;
806 break;
807 }
808
809 if (!acc_sensor_read(resources->sensor, resources->buffer, resources->buffer_size))
810 {
811 printf("ERROR: acc_sensor_read() failed\n");
812 status = false;
813 break;
814 }
815
816 if (!acc_detector_distance_process(resources->handle,
817 resources->buffer,
818 resources->detector_cal_result_static,
819 &resources->detector_cal_result_dynamic,
820 &result_available,
821 &resources->result))
822 {
823 printf("ERROR: acc_detector_distance_process() failed\n");
824 status = false;
825 break;
826 }
827 } while (!result_available);
828
829 /* Disable sensor in between measurements to save power */
830 acc_hal_integration_sensor_disable(SENSOR_ID);
831
832 return status;
833 }
834
835 static void print_distance_result(const acc_detector_distance_result_t *result)
836 {
837 uart_log("%d detected distances", result->num_distances);
838 if (result->num_distances > 0)
839 {
840 uart_log(": ");
841 for (uint8_t i = 0; i < result->num_distances; i++)
842 {
843 uint32_t distance_mm = (uint32_t)(1000 * result->distances[i]);
844 uart_log("%" PRIu32 "mm, ", distance_mm);
845 }
846 }
847
848 uart_log("\n");
849 }
850
851 static void uart_log(const char *format, ...)
852 {
853 char log_buffer[UART_LOG_BUFFER_SIZE];
854
855 va_list ap;
856
857 va_start(ap, format);
858
859 if (uart_logs_enabed)
860 {
861 int ret = vsnprintf(log_buffer, UART_LOG_BUFFER_SIZE, format, ap);
862
863 if (ret >= UART_LOG_BUFFER_SIZE)
864 {
865 log_buffer[UART_LOG_BUFFER_SIZE - 4] = '.';
866 log_buffer[UART_LOG_BUFFER_SIZE - 3] = '.';
867 log_buffer[UART_LOG_BUFFER_SIZE - 2] = '.';
868 log_buffer[UART_LOG_BUFFER_SIZE - 1] = 0;
869 }
870
871 printf("%s", log_buffer);
872 }
873
874 va_end(ap);
875 }
uart_log
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
Definition: i2c_distance_detector.c:851
acc_rss_a121.h
acc_detector_distance_get_sizes
bool acc_detector_distance_get_sizes(const acc_detector_distance_handle_t *handle, uint32_t *buffer_size, uint32_t *detector_cal_result_static_size)
Get the memory size needed to use the Distance Detector API functions.
DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
Definition: distance_reg_protocol.h:82
i2c_distance_detector_measure_on_wakeup
void i2c_distance_detector_measure_on_wakeup(bool enable)
Enable/Disable measure on wake up.
Definition: i2c_distance_detector.c:270
DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_MASK
Definition: distance_reg_protocol.h:132
DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
Definition: distance_reg_protocol.h:114
acc_hal_integration_sensor_supply_on
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:99
DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
Definition: distance_reg_protocol.h:80
i2c_detector_status
static uint32_t i2c_detector_status
Definition: i2c_distance_detector.c:45
distance_detector_resources_t::detector_cal_result_static_size
uint32_t detector_cal_result_static_size
Definition: i2c_distance_detector.c:39
acc_sensor_read
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
acc_detector_distance_result_t::temperature
int16_t temperature
Definition: acc_detector_distance.h:95
UART_LOG_BUFFER_SIZE
#define UART_LOG_BUFFER_SIZE
Definition: i2c_distance_detector.c:51
vsnprintf
#define vsnprintf
Definition: printf.h:85
acc_version.h
i2c_application_system_reset
void i2c_application_system_reset(void)
Reset the system.
Definition: i2c_application_system_stm32.c:158
get_command
static uint32_t get_command(void)
Get the i2c_detector_command values.
Definition: i2c_distance_detector.c:427
DISTANCE_REG_DISTANCE_RESULT_FIELD_NEAR_START_EDGE_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_NEAR_START_EDGE_MASK
Definition: distance_reg_protocol.h:126
i2c_detector_command
static uint32_t i2c_detector_command
Definition: i2c_distance_detector.c:44
i2c_distance_detector_get_status
uint32_t i2c_distance_detector_get_status(void)
Get distance detector status.
Definition: i2c_distance_detector.c:188
distance_detector_resources_t::result
acc_detector_distance_result_t result
Definition: i2c_distance_detector.c:35
distance_detector_resources_t::buffer_size
uint32_t buffer_size
Definition: i2c_distance_detector.c:37
i2c_distance_detector_get_measure_on_wakeup
bool i2c_distance_detector_get_measure_on_wakeup(void)
Get measure on wake up state.
Definition: i2c_distance_detector.c:280
acc_cal_result_t
The result from a completed calibration.
Definition: acc_definitions_a121.h:30
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_OK_MASK
Definition: distance_reg_protocol.h:96
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: i2c_distance_detector.c:298
acc_integration_critical_section_exit
void acc_integration_critical_section_exit(void)
Definition: acc_integration_cortex.c:16
DISTANCE_REG_COMMAND_ENUM_MEASURE_DISTANCE
#define DISTANCE_REG_COMMAND_ENUM_MEASURE_DISTANCE
Definition: distance_reg_protocol.h:157
distance_detector_resources_t::sensor_cal_result
acc_cal_result_t sensor_cal_result
Definition: i2c_distance_detector.c:32
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
Definition: distance_reg_protocol.h:104
distance_reg_protocol.h
DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
Definition: distance_reg_protocol.h:102
acc_integration.h
acc_detector_distance_result_t::num_distances
uint8_t num_distances
Definition: acc_detector_distance.h:70
acc_detector_distance_create
acc_detector_distance_handle_t * acc_detector_distance_create(const acc_detector_distance_config_t *config)
Create Distance Detector handle using the provided Distance Detector configuration.
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
Definition: distance_reg_protocol.h:84
acc_hal_rss_integration_get_implementation
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
Definition: acc_hal_integration_stm32cube_xm.c:152
detector_status_set_bits
static void detector_status_set_bits(uint32_t bit_mask)
Set bits in the i2c_detector_status.
Definition: i2c_distance_detector.c:528
detector_get_next
static bool detector_get_next(distance_detector_resources_t *resources)
Get next distance measurement.
Definition: i2c_distance_detector.c:774
acc_detector_distance_calibrate
bool acc_detector_distance_calibrate(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, uint8_t *detector_cal_result_static, uint32_t detector_cal_result_static_size, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *calibration_complete)
Calibrate detector.
distance_detector_resources_t::detector_cal_result_dynamic
acc_detector_cal_result_dynamic_t detector_cal_result_dynamic
Definition: i2c_distance_detector.c:40
acc_detector_distance_process
bool acc_detector_distance_process(acc_detector_distance_handle_t *handle, void *buffer, uint8_t *detector_cal_result_static, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *result_available, acc_detector_distance_result_t *result)
Process sensor data into a Detector result.
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:592
DISTANCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
#define DISTANCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
Definition: distance_reg_protocol.h:162
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
distance_reg_protocol_write_default
void distance_reg_protocol_write_default(void)
Definition: distance_reg_protocol.c:233
acc_rss_hal_register
bool acc_rss_hal_register(const acc_hal_a121_t *hal)
Register an integration.
i2c_application_system_wait_for_interrupt
void i2c_application_system_wait_for_interrupt(void)
Wait for interrupt to occur.
Definition: i2c_application_system_stm32.c:169
is_detector_ready
static bool is_detector_ready(void)
Test if detector is ready.
Definition: i2c_distance_detector.c:767
i2c_distance_detector_get_result
uint32_t i2c_distance_detector_get_result(void)
Get distance detector result.
Definition: i2c_distance_detector.c:200
acc_detector_cal_result_dynamic_t
The result from a completed calibration update.
Definition: acc_detector_distance_definitions.h:23
distance_detector_resources_t::detector_cal_result_static
uint8_t * detector_cal_result_static
Definition: i2c_distance_detector.c:38
detector_status_clr_bits
static void detector_status_clr_bits(uint32_t bit_mask)
Clear bits in the i2c_detector_status.
Definition: i2c_distance_detector.c:541
DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_POS
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_POS
Definition: distance_reg_protocol.h:131
distance_detector_resources_t
Definition: i2c_distance_detector.c:29
measure_distance_error
static bool measure_distance_error
Definition: i2c_distance_detector.c:47
acc_hal_integration_wait_for_sensor_interrupt
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
Definition: acc_hal_integration_stm32cube_xm.c:130
i2c_distance_detector.h
i2c_distance_detector_get_counter
uint32_t i2c_distance_detector_get_counter(void)
Get distance detector measure counter.
Definition: i2c_distance_detector.c:234
DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
Definition: distance_reg_protocol.h:88
DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK
Definition: distance_reg_protocol.h:92
acc_hal_integration_a121.h
detector_resources
static distance_detector_resources_t detector_resources
Definition: i2c_distance_detector.c:43
i2c_application_system.h
result
cargo_result_t result
Definition: i2c_example_cargo.c:43
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
printf
#define printf
Definition: printf.h:60
create_sensor
static void create_sensor(distance_detector_resources_t *resources)
Create sensor.
Definition: i2c_distance_detector.c:566
i2c_application_enter_low_power_state
void i2c_application_enter_low_power_state(void)
Make the MCU enter its low power state.
Definition: i2c_application_system_stm32.c:215
acc_hal_integration_sensor_enable
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:109
DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIG_AND_CALIBRATE
#define DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIG_AND_CALIBRATE
Definition: distance_reg_protocol.h:156
acc_hal_definitions_a121.h
acc_detector_distance_result_t::calibration_needed
bool calibration_needed
Definition: acc_detector_distance.h:87
DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_POS
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_POS
Definition: distance_reg_protocol.h:123
acc_detector_distance_config_log
void acc_detector_distance_config_log(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config)
Log Distance configuration, typically through printf.
detector_status_test_bits
static bool detector_status_test_bits(uint32_t bit_mask)
Test bits in the i2c_detector_status.
Definition: i2c_distance_detector.c:554
DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
Definition: distance_reg_protocol.h:108
DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
Definition: distance_reg_protocol.h:112
acc_detector_distance_prepare
bool acc_detector_distance_prepare(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
Prepare the Detector for measurements.
DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_MASK
Definition: distance_reg_protocol.h:124
acc_detector_distance_result_t
Distance Detector result returned from acc_detector_distance_process.
Definition: acc_detector_distance.h:48
DISTANCE_REG_COMMAND_ENUM_RECALIBRATE
#define DISTANCE_REG_COMMAND_ENUM_RECALIBRATE
Definition: distance_reg_protocol.h:160
distance_reg_protocol_setup
void distance_reg_protocol_setup(void)
Definition: distance_reg_protocol.c:227
i2c_application_system_set_ready_pin
void i2c_application_system_set_ready_pin(bool enable)
Set the ready pin state.
Definition: i2c_application_system_stm32.c:181
distance_detector_resources_t::config
acc_detector_distance_config_t * config
Definition: i2c_distance_detector.c:33
acc_hal_integration_sensor_disable
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:119
acc_detector_distance_result_t::strengths
float strengths[(10U)]
Definition: acc_detector_distance.h:62
acc_detector_distance_handle_t
struct acc_detector_distance_handle acc_detector_distance_handle_t
Distance Detector handle.
Definition: acc_detector_distance.h:36
DISTANCE_REG_COMMAND_ENUM_CALIBRATE
#define DISTANCE_REG_COMMAND_ENUM_CALIBRATE
Definition: distance_reg_protocol.h:159
i2c_application_system_init
void i2c_application_system_init(void)
Init the system.
Definition: i2c_application_system_stm32.c:130
i2c_distance_detector_get_peak_distance
float i2c_distance_detector_get_peak_distance(uint16_t peak_id)
Get the peak distance for a specific peak id.
Definition: i2c_distance_detector.c:246
measure_on_wakeup
static bool measure_on_wakeup
Definition: i2c_distance_detector.c:48
i2c_distance_detector_get_peak_strength
float i2c_distance_detector_get_peak_strength(uint16_t peak_id)
Get the peak strength for a specific peak id.
Definition: i2c_distance_detector.c:258
DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
Definition: distance_reg_protocol.h:78
acc_detector_distance_update_calibration
bool acc_detector_distance_update_calibration(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *calibration_complete)
Perform a subset of the full Detector calibration.
DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
#define DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
Definition: distance_reg_protocol.h:158
acc_detector_distance_result_t::near_start_edge_status
bool near_start_edge_status
Definition: acc_detector_distance.h:75
command_handler
static void command_handler(uint32_t command)
Execute the command sent from the host.
Definition: i2c_distance_detector.c:441
ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES
#define ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES
The maximum number of estimated distances that is returned in the Detector result.
Definition: acc_detector_distance.h:29
acc_reg_protocol.h
DISTANCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
#define DISTANCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
Definition: distance_reg_protocol.h:161
DISTANCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
#define DISTANCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
Definition: distance_reg_protocol.h:163
DISTANCE_REG_COMMAND_ENUM_RESET_MODULE
#define DISTANCE_REG_COMMAND_ENUM_RESET_MODULE
Definition: distance_reg_protocol.h:164
DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_ERROR_MASK
Definition: distance_reg_protocol.h:110
apply_detector_config
static void apply_detector_config(distance_detector_resources_t *resources)
Apply detector config.
Definition: i2c_distance_detector.c:586
measure_distance_counter
static uint32_t measure_distance_counter
Definition: i2c_distance_detector.c:46
acc_integration_critical_section_enter
void acc_integration_critical_section_enter(void)
Definition: acc_integration_cortex.c:9
distance_detector_resources_t::sensor
acc_sensor_t * sensor
Definition: i2c_distance_detector.c:31
i2c_distance_detector_command
bool i2c_distance_detector_command(uint32_t command)
Send command to be executed to i2c distance detector.
Definition: i2c_distance_detector.c:166
acc_detector_distance_config_create
acc_detector_distance_config_t * acc_detector_distance_config_create(void)
Create a Distance Detector configuration.
DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK
Definition: distance_reg_protocol.h:100
SENSOR_TIMEOUT_MS
#define SENSOR_TIMEOUT_MS
Definition: i2c_distance_detector.c:27
DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
Definition: distance_reg_protocol.h:94
acc_detector_distance_result_t::distances
float distances[(10U)]
Definition: acc_detector_distance.h:55
DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_OK_MASK
Definition: distance_reg_protocol.h:90
acc_detector_distance.h
DISTANCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK
Definition: distance_reg_protocol.h:120
acc_sensor_calibrate
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
calibrate_sensor
static void calibrate_sensor(distance_detector_resources_t *resources)
Calibrate sensor.
Definition: i2c_distance_detector.c:661
distance_detector_resources_t::handle
acc_detector_distance_handle_t * handle
Definition: i2c_distance_detector.c:34
i2c_distance_detector_get_config
acc_detector_distance_config_t * i2c_distance_detector_get_config(void)
Get distance detector configuration handle.
Definition: i2c_distance_detector.c:161
distance_detector_resources_t::buffer
void * buffer
Definition: i2c_distance_detector.c:36
acc_detector_distance_config_t
struct acc_detector_distance_config acc_detector_distance_config_t
Distance Detector configuration.
Definition: acc_detector_distance.h:43
calibrate_detector
static void calibrate_detector(distance_detector_resources_t *resources, bool update_calibration)
Calibrate detector.
Definition: i2c_distance_detector.c:700
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
Definition: distance_reg_protocol.h:86
DISTANCE_REG_DISTANCE_RESULT_FIELD_MEASURE_DISTANCE_ERROR_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_MEASURE_DISTANCE_ERROR_MASK
Definition: distance_reg_protocol.h:130
acc_sensor_measure
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
i2c_application_system_test_wakeup_pin
bool i2c_application_system_test_wakeup_pin(void)
Check if wakeup pin is high.
Definition: i2c_application_system_stm32.c:174
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_ERROR_MASK
Definition: distance_reg_protocol.h:116
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
print_distance_result
static void print_distance_result(const acc_detector_distance_result_t *result)
Print the distance detector result.
Definition: i2c_distance_detector.c:835
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
Definition: distance_reg_protocol.h:106
DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
Definition: distance_reg_protocol.h:98
DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
Definition: distance_reg_protocol.h:118
DISTANCE_REG_DISTANCE_RESULT_FIELD_CALIBRATION_NEEDED_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_CALIBRATION_NEEDED_MASK
Definition: distance_reg_protocol.h:128
acc_definitions_a121.h
SENSOR_ID
#define SENSOR_ID
Definition: i2c_distance_detector.c:26
uart_logs_enabed
static bool uart_logs_enabed
Definition: i2c_distance_detector.c:49
acc_sensor_create
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.