i2c_presence_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_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 (10000U)
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 uint32_t presence_last_tick_ms = 0U;
52 static uint32_t presence_frame_rate_mhz = 0U;
53 static float intra_presence_score = 0.0f;
54 static float inter_presence_score = 0.0f;
55 static bool uart_logs_enabed = false;
56 
57 #define UART_LOG_BUFFER_SIZE 100
58 
59 /**
60  * @brief Get the i2c_detector_command values
61  *
62  * The i2c_detector_command is cleared during this read
63  * The read and clear are protected by a critical section
64  *
65  * @return The command sent from the host
66  */
67 static uint32_t get_command(void);
68 
69 /**
70  * @brief Execute the command sent from the host
71  *
72  * @param[in] command The command to execute
73  */
74 static void command_handler(uint32_t command);
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  * @brief Clear bits in the i2c_detector_status
87  *
88  * The i2c_detector_status is protected by a critical section
89  *
90  * @param[in] bit_mask The bit_mask to clear
91  */
92 static void detector_status_clr_bits(uint32_t bit_mask);
93 
94 /**
95  * @brief Test bits in the i2c_detector_status
96  *
97  * The i2c_detector_status is protected by a critical section
98  *
99  * @param[in] bit_mask The bit_mask to test
100  * @return true if all the bits in bit_mask is set in i2c_detector_status
101  */
102 static bool detector_status_test_bits(uint32_t bit_mask);
103 
104 /**
105  * @brief Create sensor
106  *
107  * @param[in] resources presence detector resources struct
108  */
109 static void create_sensor(presence_detector_resources_t *resources);
110 
111 /**
112  * @brief Calibrate sensor
113  *
114  * @param[in] resources presence detector resources struct
115  * @return true if successful
116  */
117 static bool calibrate_sensor(presence_detector_resources_t *resources);
118 
119 /**
120  * @brief Apply detector config
121  *
122  * This function will create the presence detector and
123  * allocate the needed memory
124  *
125  * @param[in] resources presence detector resources struct
126  */
128 
129 /**
130  * @brief Activate detector
131  *
132  * This function will activate the detector
133  *
134  * @param[in] resources presence detector resources struct
135  * @param[in] enable set to true to enable the detector
136  * @return true if successful
137  */
138 static bool detector_activate(presence_detector_resources_t *resources, bool enable);
139 
140 /**
141  * @brief Get next presence measurement
142  *
143  * @param[in] resources presence detector resources struct
144  * @return true if successful
145  */
146 static bool detector_get_next(presence_detector_resources_t *resources);
147 
148 /**
149  * @brief Handle detector GPIO output
150  */
151 static void detector_gpio_output(void);
152 
153 /**
154  * @brief Try to set module in low power mode
155  */
156 static void module_low_power(void);
157 
158 /**
159  * @brief Enter sensor hibernation state
160  */
161 static bool enter_hibernate(acc_sensor_t *sensor);
162 
163 /**
164  * @brief Exit sensor hibernation state
165  */
166 static bool exit_hibernate(acc_sensor_t *sensor);
167 
168 /**
169  * @brief Print the presence detector result
170  *
171  * Only available when the UART logs have been enabled with ENABLE_UART_LOGS
172  *
173  * @param[in] result The presence detector result
174  */
176 
177 /**
178  * @brief UART logging function (can be enabled/disabled by command)
179  */
180 static void uart_log(const char *format, ...);
181 
182 //
183 // PUBLIC FUNCTIONS
184 //
185 
187 {
188  return detector_resources.config;
189 }
190 
191 bool i2c_presence_detector_command(uint32_t command)
192 {
193  bool status = false;
194 
195  /* Make sure we do not have a race for i2c_detector_command/i2c_detector_status */
197 
198  if (i2c_detector_command == 0U)
199  {
200  /* Set Ready PIN to LOW while processing the command */
202 
203  /* Set status BUSY bit */
205  i2c_detector_command = command;
206  status = true;
207  }
208 
210  return status;
211 }
212 
214 {
215  /* Make sure we do not have a race for i2c_detector_status */
217 
218  uint32_t status = i2c_detector_status;
219 
221 
222  return status;
223 }
224 
226 {
227  uint32_t value = 0;
228 
229  /* Make sure we do not have a race for results */
231 
232  if (presence_detected)
233  {
235  }
236 
238  {
240 
241  presence_detected_sticky = false;
242  }
243 
245  {
247  }
248 
249  /* Add temperature */
250  uint32_t temp = (uint32_t)detector_resources.result.processing_result.temperature;
251 
253  value |= temp;
254 
256 
257  return value;
258 }
259 
261 {
262  /* Make sure we do not have a race for presence_distance */
264 
265  float value = presence_distance;
266 
268 
269  return value;
270 }
271 
273 {
274  /* Make sure we do not have a race for intra_presence_score */
276 
277  float value = intra_presence_score;
278 
280 
281  return value;
282 }
283 
285 {
286  /* Make sure we do not have a race for inter_presence_score */
288 
289  float value = inter_presence_score;
290 
292 
293  return value;
294 }
295 
297 {
298  /* Make sure we do not have a race for presence_frame_counter */
300 
301  uint32_t counter = presence_frame_counter;
302 
304 
305  return counter;
306 }
307 
309 {
310  /* Make sure we do not have a race for presence_detection_gpio */
312 
313  presence_detection_gpio = enable;
314 
316 }
317 
319 {
320  /* Make sure we do not have a race for presence_detection_gpio */
322 
323  bool value = presence_detection_gpio;
324 
326 
327  return value;
328 }
329 
331 {
333  uint32_t value = presence_frame_rate_mhz;
335  return value;
336 }
337 
338 //
339 // MAIN
340 //
341 
342 int acconeer_main(int argc, char *argv[]);
343 
344 int acconeer_main(int argc, char *argv[])
345 {
346  (void)argc;
347  (void)argv;
348 
349  bool setup_status = true;
350  bool get_next_frame = false;
351 
352  printf("I2C Presence Detector\n");
353  printf("Acconeer software version %s\n", acc_version_get());
354 
356 
357  if (acc_rss_hal_register(hal))
358  {
360  }
361  else
362  {
363  printf("ERROR: acc_rss_hal_register() failed\n\n");
365  setup_status = false;
366  }
367 
368  if (setup_status)
369  {
371  if (detector_resources.config != NULL)
372  {
373  /* Config is created, write default values to registers */
375 
377  }
378  else
379  {
382  printf("ERROR: acc_detector_presence_config_create() failed\n\n");
383  setup_status = false;
384  }
385  }
386 
387  /* Turn the sensor on */
389 
390  if (setup_status)
391  {
392  /* Create sensor */
394  }
395 
397 
398  /* Setup i2c register protocol */
400 
401  while (true)
402  {
403 
404  /* Handle Presence Detector */
406  {
407  get_next_frame = false;
409  {
411  }
412  else
413  {
414  printf("ERROR: Could not get next result\n");
418  }
419  }
420 
421  /* Handle Generic GPIO output */
423 
424  /* Handle Commands */
425  uint32_t command = get_command();
426 
427  if (command == 0)
428  {
429  /* Try to set module in low power mode */
431 
432  /* Test if a periodic wakeup was the wakeup reason */
433  get_next_frame = i2c_application_is_periodic_wakeup();
434  if (get_next_frame)
435  {
437  uint32_t time_ms = acc_integration_get_time();
438  uint32_t diff_ms = time_ms - presence_last_tick_ms;
439  presence_last_tick_ms = time_ms;
440  presence_frame_rate_mhz = (diff_ms > 0) ? (1000000 / diff_ms) : 0;
441 
443  }
444 
445  continue;
446  }
447 
448  /* Special command, always handle reset module command, even if error has occured */
450  {
451  /* Reset system */
453  continue;
454  }
455 
457  {
458  /* Do not process commands after error state */
459  continue;
460  }
461 
462  /* Handle command */
463  command_handler(command);
464 
465  /* Command handler done, clear busy bit */
467 
468  /* Set Ready PIN to HIGH when command processing is done */
470  }
471 
472  return EXIT_FAILURE;
473 }
474 
475 //
476 // PRIVATE HELPER FUNCTIONS
477 //
478 
479 static uint32_t get_command(void)
480 {
481  /* Make sure we do not have a race for i2c_detector_command */
483 
484  uint32_t command = i2c_detector_command;
485 
487 
489 
490  return command;
491 }
492 
493 static void command_handler(uint32_t command)
494 {
495  switch (command)
496  {
499  {
500  // Apply configuration
502  }
503 
504  break;
507  {
509  {
511  }
512  else
513  {
514  printf("ERROR: Could not start detector\n");
517  }
518  }
519 
520  break;
523  {
525  {
526  presence_detector_active = false;
527  }
528  else
529  {
530  printf("ERROR: Could not stop detector\n");
533  }
534  }
535 
536  break;
538  uart_logs_enabed = true;
539  uart_log("UART logs enabled\n");
540  break;
542  uart_log("UART logs disabled\n");
543  uart_logs_enabed = false;
544  break;
546  // Print the configuration
548  break;
549  default:
550  printf("ERROR: Unknown command: %" PRIu32 "", command);
551  break;
552  }
553 }
554 
555 static void detector_status_set_bits(uint32_t bit_mask)
556 {
557  /* Make sure we do not have a race for i2c_detector_status */
559 
560  i2c_detector_status |= bit_mask;
561  uint32_t temp_detector_status = i2c_detector_status;
562 
564 
565  uart_log("Detector Status = 0x%" PRIx32 "\n", temp_detector_status);
566 }
567 
568 static void detector_status_clr_bits(uint32_t bit_mask)
569 {
570  /* Make sure we do not have a race for i2c_detector_status */
572 
573  i2c_detector_status &= ~bit_mask;
574  uint32_t temp_detector_status = i2c_detector_status;
575 
577 
578  uart_log("Detector Status = 0x%" PRIx32 "\n", temp_detector_status);
579 }
580 
581 static bool detector_status_test_bits(uint32_t bit_mask)
582 {
583  /* Make sure we do not have a race for i2c_detector_status */
585 
586  bool status = (i2c_detector_status & bit_mask) == bit_mask;
587 
589 
590  return status;
591 }
592 
594 {
596 
597  resources->sensor = acc_sensor_create(SENSOR_ID);
598 
600 
601  if (resources->sensor != NULL)
602  {
604  }
605  else
606  {
609  printf("ERROR: acc_sensor_create() failed\n");
610  }
611 }
612 
614 {
616 
619 
620  bool status;
621  bool cal_complete = false;
622 
623  do
624  {
625  status = acc_sensor_calibrate(resources->sensor, &cal_complete, &resources->sensor_cal_result, resources->buffer, resources->buffer_size);
626 
627  if (cal_complete)
628  {
629  break;
630  }
631 
632  if (status)
633  {
635  }
636  } while (status);
637 
638  if (status)
639  {
641  }
642  else
643  {
645  printf("ERROR: acc_sensor_calibrate() failed\n");
646  }
647 
648  /* Reset sensor after calibration by disabling it */
650 
651  return status;
652 }
653 
655 {
656  bool status = true;
657 
659 
660  /* Always use DEEP_SLEEP for inter_frame_idle_state to save power */
662 
663  resources->handle = acc_detector_presence_create(resources->config, &(resources->metadata));
664  if (resources->handle != NULL)
665  {
667  }
668  else
669  {
672  printf("ERROR: acc_detector_presence_create() failed\n");
673  status = false;
674  }
675 
676  if (status)
677  {
678  if (acc_detector_presence_get_buffer_size(resources->handle, &(resources->buffer_size)))
679  {
681  }
682  else
683  {
686  printf("ERROR: acc_detector_presence_get_buffer_size() failed\n");
687  status = false;
688  }
689  }
690 
691  if (status)
692  {
693  resources->buffer = acc_integration_mem_alloc(resources->buffer_size);
694  if (resources->buffer != NULL)
695  {
697  }
698  else
699  {
702  printf("ERROR: sensor buffer allocation failed\n");
703  status = false;
704  }
705  }
706 
707  if (status)
708  {
710  }
711 
712  if (status)
713  {
715  }
716  else
717  {
718  printf("ERROR: apply detector config failed\n");
720  }
721 }
722 
723 static bool detector_activate(presence_detector_resources_t *resources, bool enable)
724 {
725  bool status = true;
726 
727  if (enable)
728  {
729  uart_log("Start presence detector\n");
731 
732  if (!acc_detector_presence_prepare(resources->handle,
733  resources->config,
734  resources->sensor,
735  &resources->sensor_cal_result,
736  resources->buffer,
737  resources->buffer_size))
738  {
739  status = false;
740  printf("ERROR: acc_detector_presence_prepare() failed\n");
741  }
742 
743  if (status)
744  {
745  status = enter_hibernate(resources->sensor);
746  }
747 
748  if (status)
749  {
750  uint32_t sleep_time_ms = (uint32_t)(1000.0f / acc_detector_presence_config_frame_rate_get(resources->config));
752  }
753  }
754  else
755  {
756  uart_log("Stop presence detector\n");
757 
758  status = exit_hibernate(resources->sensor);
759 
762  }
763 
764  return status;
765 }
766 
768 {
769  bool status = true;
770 
771  /* Exit from hibernation */
772  status = exit_hibernate(resources->sensor);
773 
774  if (status)
775  {
776  if (!acc_sensor_measure(resources->sensor))
777  {
778  printf("ERROR: acc_sensor_measure() failed\n");
779  status = false;
780  }
781  }
782 
783  if (status)
784  {
786  {
787  printf("ERROR: Sensor interrupt timeout\n");
788  status = false;
789  }
790  }
791 
792  if (status)
793  {
794  if (!acc_sensor_read(resources->sensor, resources->buffer, resources->buffer_size))
795  {
796  printf("ERROR: acc_sensor_read() failed\n");
797  status = false;
798  }
799  }
800 
801  if (status)
802  {
803  /* Enter hibernation */
804  status = enter_hibernate(resources->sensor);
805  }
806 
807  if (status)
808  {
809  if (!acc_detector_presence_process(resources->handle, resources->buffer, &resources->result))
810  {
811  printf("ERROR: acc_detector_presence_process() failed\n");
812  status = false;
813  }
814  }
815 
816  if (status)
817  {
818  /* Make sure we do not have a race for presence_frame_counter */
820 
822 
824 
826  {
827  uart_log("Recalibration\n");
828 
829  status = detector_activate(resources, false);
830 
831  if (status && calibrate_sensor(resources))
832  {
833  status = detector_activate(resources, true);
834  }
835  }
836  }
837 
838  if (status)
839  {
840  /* Make sure we do not have a race for results */
842 
843  /* Copy result if a presence was detected */
844  if (resources->result.presence_detected)
845  {
846  presence_detected = true;
851  }
852  else
853  {
854  presence_detected = false;
855  }
856 
858  }
859 
860  return status;
861 }
862 
863 static void detector_gpio_output(void)
864 {
865  /* Make sure we do not have a race for presence_detection_gpio */
867  bool detection_gpio = presence_detection_gpio;
869 
870  if (detection_gpio)
871  {
872  /* Setup generic gpio as output */
874 
876  {
877  /* Drive high signal if presence is detected */
879  }
880  else
881  {
882  /* Drive low signal on generic gpio */
884  }
885  }
886  else
887  {
888  /* Disable generic gpio */
890  }
891 }
892 
893 static void module_low_power(void)
894 {
896  {
898  }
899  else
900  {
901  /* Set ready pin LOW, we are about to power down */
903 
904  uart_log("Enter low power state\n");
906  uart_log("Exit low power state\n");
907  }
908 
910  {
911  /* Set ready pin HIGH, we are ready for a command */
913  }
914 }
915 
917 {
918  bool status = true;
919 
921  {
922  printf("ERROR: acc_sensor_hibernate_on failed\n");
923  status = false;
924  }
925 
927  return status;
928 }
929 
931 {
932  bool status = true;
933 
936  {
937  printf("ERROR: acc_sensor_hibernate_off failed\n");
938  status = false;
939  }
940 
941  return status;
942 }
943 
945 {
946  uart_log("Presence detected: %s ", result->presence_detected ? "True" : "False");
948  {
949  uint32_t distance_mm = (uint32_t)(1000 * result->presence_distance);
950  uart_log("(%" PRIu32 "mm)\n", distance_mm);
951  }
952  else
953  {
954  uart_log("\n");
955  }
956 }
957 
958 static void uart_log(const char *format, ...)
959 {
960  char log_buffer[UART_LOG_BUFFER_SIZE];
961 
962  va_list ap;
963 
964  va_start(ap, format);
965 
966  if (uart_logs_enabed)
967  {
968  int ret = vsnprintf(log_buffer, UART_LOG_BUFFER_SIZE, format, ap);
969 
970  if (ret >= UART_LOG_BUFFER_SIZE)
971  {
972  log_buffer[UART_LOG_BUFFER_SIZE - 4] = '.';
973  log_buffer[UART_LOG_BUFFER_SIZE - 3] = '.';
974  log_buffer[UART_LOG_BUFFER_SIZE - 2] = '.';
975  log_buffer[UART_LOG_BUFFER_SIZE - 1] = 0;
976  }
977 
978  printf("%s", log_buffer);
979  }
980 
981  va_end(ap);
982 }
acc_detector_presence_result_t::inter_presence_score
float inter_presence_score
Definition: acc_detector_presence.h:59
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
Definition: presence_reg_protocol.h:104
uart_log
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
Definition: i2c_presence_detector.c:958
PRESENCE_REG_PRESENCE_RESULT_FIELD_DETECTOR_ERROR_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_DETECTOR_ERROR_MASK
Definition: presence_reg_protocol.h:114
inter_presence_score
static float inter_presence_score
Definition: i2c_presence_detector.c:54
PRESENCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
#define PRESENCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
Definition: presence_reg_protocol.h:129
acc_rss_a121.h
i2c_presence_detector_get_counter
uint32_t i2c_presence_detector_get_counter(void)
Get presence detector measure counter.
Definition: i2c_presence_detector.c:296
presence_last_tick_ms
static uint32_t presence_last_tick_ms
Definition: i2c_presence_detector.c:51
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
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:208
PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
Definition: presence_reg_protocol.h:74
acc_integration_get_time
uint32_t acc_integration_get_time(void)
Get current time.
Definition: acc_integration_stm32.c:587
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:86
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
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:82
PRESENCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
#define PRESENCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
Definition: presence_reg_protocol.h:126
acc_cal_result_t
The result from a completed calibration.
Definition: acc_definitions_a121.h:30
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:16
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
Definition: presence_reg_protocol.h:96
ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
@ ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
Definition: acc_definitions_a121.h:73
get_command
static uint32_t get_command(void)
Get the i2c_detector_command values.
Definition: i2c_presence_detector.c:479
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
Definition: presence_reg_protocol.h:78
detector_gpio_output
static void detector_gpio_output(void)
Handle detector GPIO output.
Definition: i2c_presence_detector.c:863
i2c_presence_detector_get_status
uint32_t i2c_presence_detector_get_status(void)
Get presence detector status.
Definition: i2c_presence_detector.c:213
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:225
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:132
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:152
acc_detector_presence_result_t::presence_detected
bool presence_detected
Definition: acc_detector_presence.h:51
PRESENCE_REG_COMMAND_ENUM_STOP_DETECTOR
#define PRESENCE_REG_COMMAND_ENUM_STOP_DETECTOR
Definition: presence_reg_protocol.h:128
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:592
print_presence_result
static void print_presence_result(acc_detector_presence_result_t *result)
Print the presence detector result.
Definition: i2c_presence_detector.c:944
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
Definition: presence_reg_protocol.h:80
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:106
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
acc_detector_presence_result_t
Presence detector results container.
Definition: acc_detector_presence.h:46
detector_get_next
static bool detector_get_next(presence_detector_resources_t *resources)
Get next presence measurement.
Definition: i2c_presence_detector.c:767
sensor
acc_sensor_t * sensor
Definition: i2c_example_cargo.c:33
detector_activate
static bool detector_activate(presence_detector_resources_t *resources, bool enable)
Activate detector.
Definition: i2c_presence_detector.c:723
PRESENCE_REG_COMMAND_ENUM_START_DETECTOR
#define PRESENCE_REG_COMMAND_ENUM_START_DETECTOR
Definition: presence_reg_protocol.h:127
uart_logs_enabed
static bool uart_logs_enabed
Definition: i2c_presence_detector.c:55
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:90
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
Definition: presence_reg_protocol.h:82
acc_detector_presence_metadata_t
Definition: acc_detector_presence.h:88
PRESENCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
#define PRESENCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
Definition: presence_reg_protocol.h:130
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:613
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_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:308
i2c_presence_detector_get_distance
float i2c_presence_detector_get_distance(void)
Get presence detector distance.
Definition: i2c_presence_detector.c:260
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:930
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:84
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
acc_detector_presence_result_t::intra_presence_score
float intra_presence_score
Definition: acc_detector_presence.h:55
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:581
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:191
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
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:493
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:555
UART_LOG_BUFFER_SIZE
#define UART_LOG_BUFFER_SIZE
Definition: i2c_presence_detector.c:57
presence_frame_rate_mhz
static uint32_t presence_frame_rate_mhz
Definition: i2c_presence_detector.c:52
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:654
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:188
PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_MASK
Definition: presence_reg_protocol.h:110
presence_reg_protocol.h
enter_hibernate
static bool enter_hibernate(acc_sensor_t *sensor)
Enter sensor hibernation state.
Definition: i2c_presence_detector.c:916
acc_detector_presence_prepare
bool acc_detector_presence_prepare(const 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_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
PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_STICKY_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_STICKY_MASK
Definition: presence_reg_protocol.h:112
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
PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
Definition: presence_reg_protocol.h:72
acc_detector_presence_config_t
struct acc_detector_presence_config acc_detector_presence_config_t
Definition: acc_detector_presence.h:41
presence_reg_protocol_write_default
void presence_reg_protocol_write_default(void)
Definition: presence_reg_protocol.c:203
intra_presence_score
static float intra_presence_score
Definition: i2c_presence_detector.c:53
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:238
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
Definition: presence_reg_protocol.h:76
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:130
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_detector_presence_config_log
void acc_detector_presence_config_log(acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
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:244
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: i2c_presence_detector.c:344
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:272
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:284
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:63
acc_integration_critical_section_enter
void acc_integration_critical_section_enter(void)
Definition: acc_integration_cortex.c:9
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:186
PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
Definition: presence_reg_protocol.h:102
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:893
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:318
PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_POS
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_POS
Definition: presence_reg_protocol.h:115
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:568
PRESENCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
#define PRESENCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
Definition: presence_reg_protocol.h:131
acc_detector_presence_handle_t
struct acc_detector_presence_handle acc_detector_presence_handle_t
Definition: acc_detector_presence.h:34
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.
cargo_result_t::presence_detected
bool presence_detected
Definition: example_cargo.h:134
PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_MASK
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_MASK
Definition: presence_reg_protocol.h:116
i2c_presence_detector_get_presence_frame_rate_mhz
uint32_t i2c_presence_detector_get_presence_frame_rate_mhz(void)
Get the actual frame rate for the current presence detector configuration.
Definition: i2c_presence_detector.c:330
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:593
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
Definition: presence_reg_protocol.h:92
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:94
PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
Definition: presence_reg_protocol.h:100
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:174
PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
Definition: presence_reg_protocol.h:98
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:197
PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
Definition: presence_reg_protocol.h:88
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.