i2c_presence_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_presence.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 "i2c_application_system.h"
23 #include "i2c_presence_detector.h"
24 #include "presence_reg_protocol.h"
25 
26 #define SENSOR_ID (1U)
27 #define SENSOR_TIMEOUT_MS (1000U)
28 
29 typedef struct
30 {
37  void *buffer;
38  uint32_t buffer_size;
40 
42 static uint32_t i2c_detector_command = 0U;
43 static uint32_t i2c_detector_status = 0U;
44 static bool presence_detector_active = false;
45 static bool presence_detected = false;
46 static bool presence_detected_sticky = false;
47 static bool presence_detection_gpio = false;
48 static bool presence_detector_error = false;
49 static float presence_distance = 0.0f;
50 static uint32_t presence_frame_counter = 0U;
51 static float intra_presence_score = 0.0f;
52 static float inter_presence_score = 0.0f;
53 static bool uart_logs_enabed = false;
54 
55 #define UART_LOG_BUFFER_SIZE 100
56 
57 /**
58  * @brief Get the i2c_detector_command values
59  *
60  * The i2c_detector_command is cleared during this read
61  * The read and clear are protected by a critical section
62  *
63  * @return The command sent from the host
64  */
65 static uint32_t get_command(void);
66 
67 
68 /**
69  * @brief Execute the command sent from the host
70  *
71  * @param[in] command The command to execute
72  */
73 static void command_handler(uint32_t command);
74 
75 
76 /**
77  * @brief Set bits in the i2c_detector_status
78  *
79  * The i2c_detector_status is protected by a critical section
80  *
81  * @param[in] bit_mask The bit_mask to set
82  */
83 static void detector_status_set_bits(uint32_t bit_mask);
84 
85 
86 /**
87  * @brief Clear bits in the i2c_detector_status
88  *
89  * The i2c_detector_status is protected by a critical section
90  *
91  * @param[in] bit_mask The bit_mask to clear
92  */
93 static void detector_status_clr_bits(uint32_t bit_mask);
94 
95 
96 /**
97  * @brief Test bits in the i2c_detector_status
98  *
99  * The i2c_detector_status is protected by a critical section
100  *
101  * @param[in] bit_mask The bit_mask to test
102  * @return true if all the bits in bit_mask is set in i2c_detector_status
103  */
104 static bool detector_status_test_bits(uint32_t bit_mask);
105 
106 
107 /**
108  * @brief Create sensor
109  *
110  * @param[in] resources presence detector resources struct
111  */
112 static void create_sensor(presence_detector_resources_t *resources);
113 
114 
115 /**
116  * @brief Calibrate sensor
117  *
118  * @param[in] resources presence detector resources struct
119  * @return true if successful
120  */
121 static bool calibrate_sensor(presence_detector_resources_t *resources);
122 
123 
124 /**
125  * @brief Apply detector config
126  *
127  * This function will create the presence detector and
128  * allocate the needed memory
129  *
130  * @param[in] resources presence detector resources struct
131  */
133 
134 
135 /**
136  * @brief Activate detector
137  *
138  * This function will activate the detector
139  *
140  * @param[in] resources presence detector resources struct
141  * @param[in] enable set to true to enable the detector
142  * @return true if successful
143  */
144 static bool detector_activate(presence_detector_resources_t *resources, bool enable);
145 
146 
147 /**
148  * @brief Get next presence measurement
149  *
150  * @param[in] resources presence detector resources struct
151  * @return true if successful
152  */
153 static bool detector_get_next(presence_detector_resources_t *resources);
154 
155 
156 /**
157  * @brief Handle detector GPIO output
158  */
159 static void detector_gpio_output(void);
160 
161 
162 /**
163  * @brief Try to set module in low power mode
164  */
165 static void module_low_power(void);
166 
167 
168 /**
169  * @brief Enter sensor hibernation state
170  */
171 static bool enter_hibernate(acc_sensor_t *sensor);
172 
173 
174 /**
175  * @brief Exit sensor hibernation state
176  */
177 static bool exit_hibernate(acc_sensor_t *sensor);
178 
179 
180 /**
181  * @brief Print the presence detector result
182  *
183  * Only available when the UART logs have been enabled with ENABLE_UART_LOGS
184  *
185  * @param[in] result The presence detector result
186  */
188 
189 
190 /**
191  * @brief UART logging function (can be enabled/disabled by command)
192  */
193 static void uart_log(const char *format, ...);
194 
195 
196 //
197 // PUBLIC FUNCTIONS
198 //
199 
200 
202 {
203  return detector_resources.config;
204 }
205 
206 
207 bool i2c_presence_detector_command(uint32_t command)
208 {
209  bool status = false;
210 
211  /* Make sure we do not have a race for i2c_detector_command/i2c_detector_status */
213 
214  if (i2c_detector_command == 0U)
215  {
216  /* Set Ready PIN to LOW while processing the command */
218 
219  /* Set status BUSY bit */
221  i2c_detector_command = command;
222  status = true;
223  }
224 
226  return status;
227 }
228 
229 
231 {
232  /* Make sure we do not have a race for i2c_detector_status */
234 
235  uint32_t status = i2c_detector_status;
236 
238 
239  return status;
240 }
241 
242 
244 {
245  uint32_t value = 0;
246 
247  /* Make sure we do not have a race for results */
249 
250  if (presence_detected)
251  {
253  }
254 
256  {
258 
259  presence_detected_sticky = false;
260  }
261 
263  {
265  }
266 
267  /* Add temperature */
268  uint32_t temp = (uint32_t)detector_resources.result.processing_result.temperature;
269 
271  value |= temp;
272 
274 
275  return value;
276 }
277 
278 
280 {
281  /* Make sure we do not have a race for presence_distance */
283 
284  float value = presence_distance;
285 
287 
288  return value;
289 }
290 
291 
293 {
294  /* Make sure we do not have a race for intra_presence_score */
296 
297  float value = intra_presence_score;
298 
300 
301  return value;
302 }
303 
304 
306 {
307  /* Make sure we do not have a race for inter_presence_score */
309 
310  float value = inter_presence_score;
311 
313 
314  return value;
315 }
316 
317 
319 {
320  /* Make sure we do not have a race for presence_frame_counter */
322 
323  uint32_t counter = presence_frame_counter;
324 
326 
327  return counter;
328 }
329 
330 
332 {
333  /* Make sure we do not have a race for presence_detection_gpio */
335 
336  presence_detection_gpio = enable;
337 
339 }
340 
341 
343 {
344  /* Make sure we do not have a race for presence_detection_gpio */
346 
347  bool value = presence_detection_gpio;
348 
350 
351  return value;
352 }
353 
354 
355 //
356 // MAIN
357 //
358 
359 
360 int acconeer_main(int argc, char *argv[]);
361 
362 
363 int acconeer_main(int argc, char *argv[])
364 {
365  (void)argc;
366  (void)argv;
367 
368  bool setup_status = true;
369  bool get_next_frame = false;
370 
371  printf("I2C Presence Detector\n");
372  printf("Acconeer software version %s\n", acc_version_get());
373 
375 
376  if (acc_rss_hal_register(hal))
377  {
379  }
380  else
381  {
382  printf("ERROR: acc_rss_hal_register() failed\n\n");
385  setup_status = false;
386  }
387 
388  if (setup_status)
389  {
391  if (detector_resources.config != NULL)
392  {
393  /* Config is created, write default values to registers */
395 
397  }
398  else
399  {
402  printf("ERROR: acc_detector_presence_config_create() failed\n\n");
403  setup_status = false;
404  }
405  }
406 
407  /* Turn the sensor on */
409 
410  if (setup_status)
411  {
412  /* Create sensor */
414  }
415 
417 
418  /* Setup i2c register protocol */
420 
421  while (true)
422  {
423  /* Handle Presence Detector */
425  get_next_frame &&
427  {
428  get_next_frame = false;
430  {
432  }
433  else
434  {
435  printf("ERROR: Could not get next result\n");
439  }
440  }
441 
442  /* Handle Generic GPIO output */
444 
445  /* Handle Commands */
446  uint32_t command = get_command();
447 
448  if (command == 0)
449  {
450  /* Try to set module in low power mode */
452 
453  /* Test if a periodic wakeup was the wakeup reason */
454  get_next_frame = i2c_application_is_periodic_wakeup();
455 
456  continue;
457  }
458 
459  /* Special command, always handle reset module command, even if error has occured */
461  {
462  /* Reset system */
464  continue;
465  }
466 
468  {
469  /* Do not process commands after error state */
470  continue;
471  }
472 
473  /* Handle command */
474  command_handler(command);
475 
476  /* Command handler done, clear busy bit */
478 
479  /* Set Ready PIN to HIGH when command processing is done */
481  }
482 
483  return EXIT_FAILURE;
484 }
485 
486 
487 //
488 // PRIVATE HELPER FUNCTIONS
489 //
490 
491 
492 static uint32_t get_command(void)
493 {
494  /* Make sure we do not have a race for i2c_detector_command */
496 
497  uint32_t command = i2c_detector_command;
498 
500 
502 
503  return command;
504 }
505 
506 
507 static void command_handler(uint32_t command)
508 {
509  switch (command)
510  {
513  {
514  // Apply configuration
516  }
517 
518  break;
521  {
523  {
525  }
526  else
527  {
528  printf("ERROR: Could not start detector\n");
531  }
532  }
533 
534  break;
537  {
539  {
540  presence_detector_active = false;
541  }
542  else
543  {
544  printf("ERROR: Could not stop detector\n");
547  }
548  }
549 
550  break;
552  uart_logs_enabed = true;
553  uart_log("UART logs enabled\n");
554  break;
556  uart_log("UART logs disabled\n");
557  uart_logs_enabed = false;
558  break;
560  // Print the configuration
562  break;
563  default:
564  printf("ERROR: Unknown command: %" PRIu32 "", command);
565  break;
566  }
567 }
568 
569 
570 static void detector_status_set_bits(uint32_t bit_mask)
571 {
572  /* Make sure we do not have a race for i2c_detector_status */
574 
575  i2c_detector_status |= bit_mask;
576  uint32_t temp_detector_status = i2c_detector_status;
577 
579 
580  uart_log("Detector Status = 0x%" PRIx32 "\n", temp_detector_status);
581 }
582 
583 
584 static void detector_status_clr_bits(uint32_t bit_mask)
585 {
586  /* Make sure we do not have a race for i2c_detector_status */
588 
589  i2c_detector_status &= ~bit_mask;
590  uint32_t temp_detector_status = i2c_detector_status;
591 
593 
594  uart_log("Detector Status = 0x%" PRIx32 "\n", temp_detector_status);
595 }
596 
597 
598 static bool detector_status_test_bits(uint32_t bit_mask)
599 {
600  /* Make sure we do not have a race for i2c_detector_status */
602 
603  bool status = (i2c_detector_status & bit_mask) == bit_mask;
604 
606 
607  return status;
608 }
609 
610 
612 {
614 
615  resources->sensor = acc_sensor_create(SENSOR_ID);
616 
618 
619  if (resources->sensor != NULL)
620  {
622  }
623  else
624  {
628  );
629  printf("ERROR: acc_sensor_create() failed\n");
630  }
631 }
632 
633 
635 {
637 
641  );
642 
643  bool status;
644  bool cal_complete = false;
645 
646  do
647  {
648  status = acc_sensor_calibrate(resources->sensor,
649  &cal_complete,
650  &resources->sensor_cal_result,
651  resources->buffer,
652  resources->buffer_size);
653  } while (status && !cal_complete && acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS));
654 
655  if (status)
656  {
658  }
659  else
660  {
662  printf("ERROR: acc_sensor_calibrate() failed\n");
663  }
664 
665  /* Reset sensor after calibration by disabling it */
667 
668  return status;
669 }
670 
671 
673 {
674  bool status = true;
675 
677 
678  /* Always use DEEP_SLEEP for inter_frame_idle_state to save power */
680 
681  resources->handle = acc_detector_presence_create(resources->config, &(resources->metadata));
682  if (resources->handle != NULL)
683  {
685  }
686  else
687  {
691  );
692  printf("ERROR: acc_detector_presence_create() failed\n");
693  status = false;
694  }
695 
696  if (status)
697  {
698  if (acc_detector_presence_get_buffer_size(resources->handle, &(resources->buffer_size)))
699  {
701  }
702  else
703  {
707  );
708  printf("ERROR: acc_detector_presence_get_buffer_size() failed\n");
709  status = false;
710  }
711  }
712 
713  if (status)
714  {
715  resources->buffer = acc_integration_mem_alloc(resources->buffer_size);
716  if (resources->buffer != NULL)
717  {
719  }
720  else
721  {
725  );
726  printf("ERROR: sensor buffer allocation failed\n");
727  status = false;
728  }
729  }
730 
731  if (status)
732  {
734  }
735 
736  if (status)
737  {
739  }
740  else
741  {
742  printf("ERROR: apply detector config failed\n");
746  );
747  }
748 }
749 
750 
751 static bool detector_activate(presence_detector_resources_t *resources, bool enable)
752 {
753  bool status = true;
754 
755  if (enable)
756  {
757  uart_log("Start presence detector\n");
759 
760  if (!acc_detector_presence_prepare(resources->handle,
761  resources->config,
762  resources->sensor,
763  &resources->sensor_cal_result,
764  resources->buffer,
765  resources->buffer_size))
766  {
767  status = false;
768  printf("ERROR: acc_detector_presence_prepare() failed\n");
769  }
770 
771  if (status)
772  {
773  status = enter_hibernate(resources->sensor);
774  }
775 
776  if (status)
777  {
778  uint32_t sleep_time_ms = (uint32_t)(1000.0f / acc_detector_presence_config_frame_rate_get(resources->config));
780  }
781  }
782  else
783  {
784  uart_log("Stop presence detector\n");
785 
786  status = exit_hibernate(resources->sensor);
787 
790  }
791 
792  return status;
793 }
794 
795 
797 {
798  bool status = true;
799 
800  /* Exit from hibernation */
801  status = exit_hibernate(resources->sensor);
802 
803  if (status)
804  {
805  if (!acc_sensor_measure(resources->sensor))
806  {
807  printf("ERROR: acc_sensor_measure() failed\n");
808  status = false;
809  }
810  }
811 
812  if (status)
813  {
815  {
816  printf("ERROR: Sensor interrupt timeout\n");
817  status = false;
818  }
819  }
820 
821  if (status)
822  {
823  if (!acc_sensor_read(resources->sensor,
824  resources->buffer,
825  resources->buffer_size))
826  {
827  printf("ERROR: acc_sensor_read() failed\n");
828  status = false;
829  }
830  }
831 
832  if (status)
833  {
834  /* Enter hibernation */
835  status = enter_hibernate(resources->sensor);
836  }
837 
838  if (status)
839  {
840  if (!acc_detector_presence_process(resources->handle,
841  resources->buffer,
842  &resources->result))
843  {
844  printf("ERROR: acc_detector_presence_process() failed\n");
845  status = false;
846  }
847  }
848 
849  if (status)
850  {
851  /* Make sure we do not have a race for presence_frame_counter */
853 
855 
857 
859  {
860  uart_log("Recalibration\n");
861 
862  status = detector_activate(resources, false);
863 
864  if (status && calibrate_sensor(resources))
865  {
866  status = detector_activate(resources, true);
867  }
868  }
869  }
870 
871  if (status)
872  {
873  /* Make sure we do not have a race for results */
875 
876  /* Copy result if a presence was detected */
877  if (resources->result.presence_detected)
878  {
879  presence_detected = true;
884  }
885  else
886  {
887  presence_detected = false;
888  }
889 
891  }
892 
893  return status;
894 }
895 
896 
897 static void detector_gpio_output(void)
898 {
899  /* Make sure we do not have a race for presence_detection_gpio */
901  bool detection_gpio = presence_detection_gpio;
903 
904  if (detection_gpio)
905  {
906  /* Setup generic gpio as output */
908 
910  {
911  /* Drive high signal if presence is detected */
913  }
914  else
915  {
916  /* Drive low signal on generic gpio */
918  }
919  }
920  else
921  {
922  /* Disable generic gpio */
924  }
925 }
926 
927 
928 static void module_low_power(void)
929 {
931  {
933  }
934  else
935  {
936  /* Set ready pin LOW, we are about to power down */
938 
939  uart_log("Enter low power state\n");
941  uart_log("Exit low power state\n");
942  }
943 
945  {
946  /* Set ready pin HIGH, we are ready for a command */
948  }
949 }
950 
951 
952 static bool enter_hibernate(acc_sensor_t *sensor)
953 {
954  bool status = true;
955 
956  if (!acc_sensor_hibernate_on(sensor))
957  {
958  printf("ERROR: acc_sensor_hibernate_on failed\n");
959  status = false;
960  }
961 
963  return status;
964 }
965 
966 
967 static bool exit_hibernate(acc_sensor_t *sensor)
968 {
969  bool status = true;
970 
972  if (!acc_sensor_hibernate_off(sensor))
973  {
974  printf("ERROR: acc_sensor_hibernate_off failed\n");
975  status = false;
976  }
977 
978  return status;
979 }
980 
981 
983 {
984  uart_log("Presence detected: %s ", result->presence_detected ? "True" : "False");
985  if (result->presence_detected)
986  {
987  uint32_t distance_mm = (uint32_t)(1000 * result->presence_distance);
988  uart_log("(%" PRIu32 "mm)\n", distance_mm);
989  }
990  else
991  {
992  uart_log("\n");
993  }
994 }
995 
996 
997 static void uart_log(const char *format, ...)
998 {
999  char log_buffer[UART_LOG_BUFFER_SIZE];
1000 
1001  va_list ap;
1002 
1003  va_start(ap, format);
1004 
1005  if (uart_logs_enabed)
1006  {
1007  int ret = vsnprintf(log_buffer, UART_LOG_BUFFER_SIZE, format, ap);
1008 
1009  if (ret >= UART_LOG_BUFFER_SIZE)
1010  {
1011  log_buffer[UART_LOG_BUFFER_SIZE - 4] = '.';
1012  log_buffer[UART_LOG_BUFFER_SIZE - 3] = '.';
1013  log_buffer[UART_LOG_BUFFER_SIZE - 2] = '.';
1014  log_buffer[UART_LOG_BUFFER_SIZE - 1] = 0;
1015  }
1016 
1017  printf("%s", log_buffer);
1018  }
1019 
1020  va_end(ap);
1021 }
acc_detector_presence_result_t::inter_presence_score
float inter_presence_score
Definition: acc_detector_presence.h:63
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
Definition: presence_reg_protocol.h:101
uart_log
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
Definition: i2c_presence_detector.c:997
PRESENCE_REG_PRESENCE_RESULT_FIELD_DETECTOR_ERROR_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_DETECTOR_ERROR_MASK
Definition: presence_reg_protocol.h:111
inter_presence_score
static float inter_presence_score
Definition: i2c_presence_detector.c:52
PRESENCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
#define PRESENCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
Definition: presence_reg_protocol.h:126
acc_rss_a121.h
acc_detector_presence_prepare
bool acc_detector_presence_prepare(acc_detector_presence_handle_t *presence_handle, acc_detector_presence_config_t *presence_config, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare the detector to do a measurement.
i2c_presence_detector_get_counter
uint32_t i2c_presence_detector_get_counter(void)
Get presence detector measure counter.
Definition: i2c_presence_detector.c:318
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
i2c_application_system_set_generic_gpio_pin
void i2c_application_system_set_generic_gpio_pin(bool enable)
Set the generic gpio pin output state.
Definition: i2c_application_system_stm32.c:184
PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
Definition: presence_reg_protocol.h:71
acc_detector_presence_config_log
void acc_detector_presence_config_log(const acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
presence_detector_resources_t
Definition: i2c_presence_detector.c:29
acc_sensor_read
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK
Definition: presence_reg_protocol.h:83
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
presence_distance
static float presence_distance
Definition: i2c_presence_detector.c:49
SENSOR_TIMEOUT_MS
#define SENSOR_TIMEOUT_MS
Definition: i2c_presence_detector.c:27
acc_detector_presence_result_t::processing_result
acc_processing_result_t processing_result
Definition: acc_detector_presence.h:86
PRESENCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
#define PRESENCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
Definition: presence_reg_protocol.h:123
acc_cal_result_t
Definition: acc_definitions_a121.h:19
SENSOR_ID
#define SENSOR_ID
Definition: i2c_presence_detector.c:26
acc_integration_critical_section_exit
void acc_integration_critical_section_exit(void)
Definition: acc_integration_cortex.c:18
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
Definition: presence_reg_protocol.h:93
get_command
static uint32_t get_command(void)
Get the i2c_detector_command values.
Definition: i2c_presence_detector.c:492
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
Definition: presence_reg_protocol.h:75
detector_gpio_output
static void detector_gpio_output(void)
Handle detector GPIO output.
Definition: i2c_presence_detector.c:897
i2c_presence_detector_get_status
uint32_t i2c_presence_detector_get_status(void)
Get presence detector status.
Definition: i2c_presence_detector.c:230
presence_detected
static bool presence_detected
Definition: i2c_presence_detector.c:45
presence_detection_gpio
static bool presence_detection_gpio
Definition: i2c_presence_detector.c:47
i2c_presence_detector_get_result
uint32_t i2c_presence_detector_get_result(void)
Get presence detector result.
Definition: i2c_presence_detector.c:243
acc_integration.h
acc_detector_presence_get_buffer_size
bool acc_detector_presence_get_buffer_size(const acc_detector_presence_handle_t *presence_handle, uint32_t *buffer_size)
Get the buffer size needed for the provided presence detector handle.
PRESENCE_REG_COMMAND_ENUM_RESET_MODULE
#define PRESENCE_REG_COMMAND_ENUM_RESET_MODULE
Definition: presence_reg_protocol.h:129
i2c_detector_command
static uint32_t i2c_detector_command
Definition: i2c_presence_detector.c:42
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
acc_detector_presence_result_t::presence_detected
bool presence_detected
Definition: acc_detector_presence.h:55
PRESENCE_REG_COMMAND_ENUM_STOP_DETECTOR
#define PRESENCE_REG_COMMAND_ENUM_STOP_DETECTOR
Definition: presence_reg_protocol.h:125
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:632
print_presence_result
static void print_presence_result(acc_detector_presence_result_t *result)
Print the presence detector result.
Definition: i2c_presence_detector.c:982
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
Definition: presence_reg_protocol.h:77
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
PRESENCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK
Definition: presence_reg_protocol.h:103
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
acc_detector_presence_result_t
Presence detector results container.
Definition: acc_detector_presence.h:50
detector_get_next
static bool detector_get_next(presence_detector_resources_t *resources)
Get next presence measurement.
Definition: i2c_presence_detector.c:796
detector_activate
static bool detector_activate(presence_detector_resources_t *resources, bool enable)
Activate detector.
Definition: i2c_presence_detector.c:751
PRESENCE_REG_COMMAND_ENUM_START_DETECTOR
#define PRESENCE_REG_COMMAND_ENUM_START_DETECTOR
Definition: presence_reg_protocol.h:124
uart_logs_enabed
static bool uart_logs_enabed
Definition: i2c_presence_detector.c:53
presence_detector_resources_t::buffer
void * buffer
Definition: i2c_presence_detector.c:37
PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK
Definition: presence_reg_protocol.h:87
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
Definition: presence_reg_protocol.h:79
acc_detector_presence_metadata_t
Definition: acc_detector_presence.h:93
PRESENCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
#define PRESENCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
Definition: presence_reg_protocol.h:127
presence_detector_resources_t::sensor_cal_result
acc_cal_result_t sensor_cal_result
Definition: i2c_presence_detector.c:36
calibrate_sensor
static bool calibrate_sensor(presence_detector_resources_t *resources)
Calibrate sensor.
Definition: i2c_presence_detector.c:634
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_presence_detector_presence_detected_gpio
void i2c_presence_detector_presence_detected_gpio(bool enable)
Enable/Disable gpio output for presence detected.
Definition: i2c_presence_detector.c:331
i2c_presence_detector_get_distance
float i2c_presence_detector_get_distance(void)
Get presence detector distance.
Definition: i2c_presence_detector.c:279
acc_hal_integration_a121.h
i2c_application_system.h
exit_hibernate
static bool exit_hibernate(acc_sensor_t *sensor)
Exit sensor hibernation state.
Definition: i2c_presence_detector.c:967
acc_sensor_hibernate_off
bool acc_sensor_hibernate_off(const acc_sensor_t *sensor)
Restore sensor after exiting hibernation.
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
Definition: presence_reg_protocol.h:81
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
printf
#define printf
Definition: printf.h:60
acc_detector_presence_result_t::intra_presence_score
float intra_presence_score
Definition: acc_detector_presence.h:59
presence_detector_resources_t::handle
acc_detector_presence_handle_t * handle
Definition: i2c_presence_detector.c:33
detector_status_test_bits
static bool detector_status_test_bits(uint32_t bit_mask)
Test bits in the i2c_detector_status.
Definition: i2c_presence_detector.c:598
i2c_presence_detector_command
bool i2c_presence_detector_command(uint32_t command)
Send command to be executed to i2c presence detector.
Definition: i2c_presence_detector.c:207
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
acc_detector_presence_config_inter_frame_idle_state_set
void acc_detector_presence_config_inter_frame_idle_state_set(acc_detector_presence_config_t *presence_config, acc_config_idle_state_t idle_state)
Set inter frame idle state.
command_handler
static void command_handler(uint32_t command)
Execute the command sent from the host.
Definition: i2c_presence_detector.c:507
detector_resources
static presence_detector_resources_t detector_resources
Definition: i2c_presence_detector.c:41
i2c_presence_detector.h
acc_hal_definitions_a121.h
presence_detector_resources_t::config
acc_detector_presence_config_t * config
Definition: i2c_presence_detector.c:32
acc_detector_presence_process
bool acc_detector_presence_process(acc_detector_presence_handle_t *presence_handle, void *buffer, acc_detector_presence_result_t *result)
Process the data according to the configuration used in acc_detector_presence_config_create.
detector_status_set_bits
static void detector_status_set_bits(uint32_t bit_mask)
Set bits in the i2c_detector_status.
Definition: i2c_presence_detector.c:570
UART_LOG_BUFFER_SIZE
#define UART_LOG_BUFFER_SIZE
Definition: i2c_presence_detector.c:55
presence_frame_counter
static uint32_t presence_frame_counter
Definition: i2c_presence_detector.c:50
apply_detector_config
static void apply_detector_config(presence_detector_resources_t *resources)
Apply detector config.
Definition: i2c_presence_detector.c:672
ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
@ ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
Definition: acc_definitions_a121.h:64
i2c_application_system_setup_generic_gpio_pin
void i2c_application_system_setup_generic_gpio_pin(bool enable)
Setup the generic gpio pin.
Definition: i2c_application_system_stm32.c:163
PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_MASK
Definition: presence_reg_protocol.h:107
presence_reg_protocol.h
enter_hibernate
static bool enter_hibernate(acc_sensor_t *sensor)
Enter sensor hibernation state.
Definition: i2c_presence_detector.c:952
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
PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_STICKY_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_STICKY_MASK
Definition: presence_reg_protocol.h:109
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
PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
Definition: presence_reg_protocol.h:69
acc_detector_presence_config_t
struct acc_detector_presence_config acc_detector_presence_config_t
Definition: acc_detector_presence.h:44
presence_reg_protocol_write_default
void presence_reg_protocol_write_default(void)
Definition: presence_reg_protocol.c:188
intra_presence_score
static float intra_presence_score
Definition: i2c_presence_detector.c:51
i2c_application_set_periodic_wakeup
void i2c_application_set_periodic_wakeup(uint32_t period_ms)
Set up a periodic timer used to wake up the system from sleep.
Definition: i2c_application_system_stm32.c:216
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
Definition: presence_reg_protocol.h:73
acc_sensor_hibernate_on
bool acc_sensor_hibernate_on(acc_sensor_t *sensor)
Prepare sensor for entering hibernation.
i2c_application_system_init
void i2c_application_system_init(void)
Init the system.
Definition: i2c_application_system_stm32.c:110
presence_detector_error
static bool presence_detector_error
Definition: i2c_presence_detector.c:48
presence_detected_sticky
static bool presence_detected_sticky
Definition: i2c_presence_detector.c:46
acc_reg_protocol.h
i2c_application_is_periodic_wakeup
bool i2c_application_is_periodic_wakeup(void)
Test if a periodic wake up has occurred.
Definition: i2c_application_system_stm32.c:223
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: i2c_presence_detector.c:363
presence_detector_resources_t::buffer_size
uint32_t buffer_size
Definition: i2c_presence_detector.c:38
acc_detector_presence_config_frame_rate_get
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
i2c_presence_detector_get_intra_presence_score
float i2c_presence_detector_get_intra_presence_score(void)
Get intra presence score.
Definition: i2c_presence_detector.c:292
i2c_presence_detector_get_inter_presence_score
float i2c_presence_detector_get_inter_presence_score(void)
Get inter presence score.
Definition: i2c_presence_detector.c:305
presence_detector_resources_t::metadata
acc_detector_presence_metadata_t metadata
Definition: i2c_presence_detector.c:34
presence_detector_active
static bool presence_detector_active
Definition: i2c_presence_detector.c:44
acc_detector_presence_result_t::presence_distance
float presence_distance
Definition: acc_detector_presence.h:67
acc_integration_critical_section_enter
void acc_integration_critical_section_enter(void)
Definition: acc_integration_cortex.c:10
i2c_presence_detector_get_config
acc_detector_presence_config_t * i2c_presence_detector_get_config(void)
Get presence detector configuration handle.
Definition: i2c_presence_detector.c:201
PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
Definition: presence_reg_protocol.h:99
acc_detector_presence_create
acc_detector_presence_handle_t * acc_detector_presence_create(acc_detector_presence_config_t *presence_config, acc_detector_presence_metadata_t *metadata)
Create a presence detector with the provided configuration.
module_low_power
static void module_low_power(void)
Try to set module in low power mode.
Definition: i2c_presence_detector.c:928
acc_processing_result_t::temperature
int16_t temperature
Definition: acc_processing.h:89
presence_detector_resources_t::result
acc_detector_presence_result_t result
Definition: i2c_presence_detector.c:35
i2c_presence_detector_get_presence_detected_gpio
bool i2c_presence_detector_get_presence_detected_gpio(void)
Get gpio output for presence detected state.
Definition: i2c_presence_detector.c:342
PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_POS
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_POS
Definition: presence_reg_protocol.h:112
detector_status_clr_bits
static void detector_status_clr_bits(uint32_t bit_mask)
Clear bits in the i2c_detector_status.
Definition: i2c_presence_detector.c:584
PRESENCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
#define PRESENCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
Definition: presence_reg_protocol.h:128
acc_detector_presence_handle_t
struct acc_detector_presence_handle acc_detector_presence_handle_t
Definition: acc_detector_presence.h:36
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.
acc_detector_presence_config_create
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_MASK
Definition: presence_reg_protocol.h:113
acc_processing_result_t::calibration_needed
bool calibration_needed
Definition: acc_processing.h:84
create_sensor
static void create_sensor(presence_detector_resources_t *resources)
Create sensor.
Definition: i2c_presence_detector.c:611
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
Definition: presence_reg_protocol.h:89
acc_detector_presence.h
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
Definition: presence_reg_protocol.h:91
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
Definition: presence_reg_protocol.h:97
acc_sensor_measure
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
i2c_detector_status
static uint32_t i2c_detector_status
Definition: i2c_presence_detector.c:43
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
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
Definition: presence_reg_protocol.h:95
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
presence_detector_resources_t::sensor
acc_sensor_t * sensor
Definition: i2c_presence_detector.c:31
presence_reg_protocol_setup
void presence_reg_protocol_setup(void)
Definition: presence_reg_protocol.c:182
PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
Definition: presence_reg_protocol.h:85
acc_definitions_a121.h
acc_detector_presence_config_frame_rate_app_driven_set
void acc_detector_presence_config_frame_rate_app_driven_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the application should maintain the requested frame rate.
acc_sensor_create
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.