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