IRPyro TO API demo
Specific demo for the IRPyro TO with IRPyro API
main_for_TO.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file main_for_TO.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.0
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief Example for the IRPyro TO. Single and multiple sensor configuration
9 * to enable to operator to collect samples.
10 * Example to show how to change configuration parameter of a single sensor
11 *
12 * @verbatim
13  ===============================================================================
14  ##### How to use this example #####
15  ===============================================================================
16  [..]
17  Requirements
18  (#) IRPyro API: (IRPyroAPI.c)
19  (#) IRPyro TO, IRPyro Base Board (IRPB_027)(See _KEMET website)
20  (#) RealTerm : Serial terminal or similar to messages or capture data into a file
21  (#) Keil compiler: Version 5 onwards (https://www.keil.com/download/product/)
22  to build this example.
23  (#) C99 option enabled on the compiler to support initialization macros.
24  (#) The STM32 Standard Peripheral Library, see:
25  (http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries.html)
26  [..]
27  (#) See Micro_controller_template.c for details on how to configure SDA,SCL
28  INT and CS lines values.
29  (#) Create a variable of IRPyro_sensor_device_type
30  (#) Assign the values of the port and pin for the CS
31  (#) Fill the AFE, CCP, and WUP registers with the desired values
32  (#) Compile, load and run.
33  (#) Display collected data on RealTerm or equivalent
34  @endverbatim
35  ******************************************************************************
36  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
37  @verbatim
38  Copyright (c) 2018, _KEMET, Ltd
39  All rights reserved.
40 
41  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
42  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
45  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
46  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51  @endverbatim
52 
53  ******************************************************************************
54  */
55 /* Include section ------------------------------------------------------------------*/
56 #include "main_for_TO.h"
57 
58 static void read_a_TO_sample(IRPyro_sensor_device_type* this_device);
59 static void read_sample_single_TO_device(void);
60 static void read_sample_multiple_TO_devices(void);
61 static void IOCTL_TO_example(void);
62 static void wake_up_TO_event_detection(void);
63 static void demo_board_sensor_control(int value);
64 static void usart_callback_setup(void);
65 static void IRPyro_sensor_population(IRPyro_devices this_list, uint8_t *list_size);
66 static void sensor_power_stabilize();
67 
68 /** @defgroup IRPyroAPI_Examples Code examples for IRPyro TO
69  * @brief How to stream IRPyro data and change parameters at high level
70  * @{
71  */
72 /**
73  * @brief Call point to the example functions
74  * @attention Uncomment the function to run
75  */
76 int main(void)
77 {
78  read_sample_single_TO_device(); // use with single sensor board
79 // IOCTL_TO_example(); // use with single sensor board
80 // wake_up_TO_event_detection(); // use with single sensor board
81 // read_sample_multiple_TO_devices(); // use with multiple sensors
82 }
83 /**
84  * @brief Example to initialize one IRPyro TO and stream data
85  * Creates an IRPyro TO sensor with one channel active and the minimal
86  * Required configuration: location of the CS port and pin and a I2C
87  * address. See Read_Me.txt
88  * @attention Set your serial terminal console with the following parameters:
89  * @verbatim
90  * Baud Rate: 921600
91  * Parity: None
92  * Data Bits: 8
93  * Stop Bits: 1
94  * Hardware Flow Control: None
95  * Software Flow Control: None
96  * @endverbatim
97  * Select display format to the UART by un-commenting the appropriate function:
98  * - UART_stream_char_send() for plain text display comma delimited.
99  * - UART_stream_binary_send() for binary format package.
100  * @note Modify accordingly depending on architecture
101  * @note The field .number_of_active_channels on the IRPyro TO devices can only be set to 1.
102  * - when equal to 1 data from channel 2 is collected
103  * @attention
104  * FIFO data collected is stored in the first available position of the
105  * channel_value array.
106  * channel 2 -> channel_value[0]
107  * frame counter -> channel_value[5]
108  */
110 {
111 #define NUMBER_OF_SAMPLES_TO_COUNT 6000000
112  /*-------------------------- memory allocation----------------------------*/
113  IRPyro_sensor_device_type IRPyro_Sensor =
114  {
115  .CS_Port = 2,
116  .CS_Pin = 1,
117  .INT_Port = 1,
118  .INT_Pin = 4,
119  .address = 0x75,
120  .number_of_active_channels = 1,
121  .read_mode = 1,
122  };
123  /*-------------------------- Register configuration ----------------------*/
124  AFE_reg_type IRPyro_Sensor_AFE =
125  {
126  .S7_S0 = 0, // Sets the sampling rate to 1,000 samples per second.
127  .LP = LOW_POWER_DISABLE, // Low power sets the sampling rate to 166 samples per second.
128  .HP = HP_DISABLE, // High pass filter enabled
129  .C_LP = LOW_PASS_180, // Low pass filter set at 180Hz
130  .CLK_OUT = CLK_DISABLE, // Clock output enabled to synchronize other IRPyro sensors
131  .SYNC = MASTER, // IRPyro set as Master
132  .TEMP = TEMP_DISABLE, //
133  .INT = INT_DISABLE // IRPyro indicates data ready enable
134  };
135 
136  CCP_reg_type IRPyro_Sensor_Ch_Cfg =
137  {
138  .Feedback_cap = FEEDBACK_3200_1280, // Feedback capacitance
139  .High_pass_filter_setting = HIGH_PASS_1HZ, // High pass filter set at 1Hz
140  .Feedback_transconductance = TCONDUCT_0_15T, // Time constant selection
141  .status_bit = CH_ENABLE // Channel ready to collect data
142  };
143 
144  WUP_reg_type IRPyro_Sensor_WUP_Cfg =
145  {
146  .UHT = MAX_WUP_THRESHOLD, // Upper High Threshold = 255 events
147  .ULT = SAFE_WUP_THRESHOLD, // Upper Low Threshold = 180 events
148  .LHT = MIN_WUP_THRESHOLD, // Low High Threshold = 0 events
149  .LLT = MIN_WUP_THRESHOLD, // Low Low Threshold = 0 events
150  .WT_Threshold = DEFAULT_NO_EVENTS, // Wake up event Threshold = 10 events
151  .DP0_DP2 = NOT_IN_USE_VALUE, // Active pixel channel
152  .CH0_CH2 = SEL_CH_2, // Reference channel
153  .ST = SLEEP_MODE_ONE_CH // Sleep mode type
154  };
155 
156  IRPyro_Sensor.AFE_register = IRPyro_Sensor_AFE;
157  IRPyro_Sensor.CCP_register[2] = IRPyro_Sensor_Ch_Cfg;
158  IRPyro_Sensor.WUP_register = IRPyro_Sensor_WUP_Cfg;
159 
160  /*-------------------------- board setup ---------------------------------*/
161  Micro_controller_template_init();
164  // disable all CS lines
166  /*----------------- enable the sensor for streaming-----------------------*/
167  IRPyro_open(&IRPyro_Sensor);
168 
169  for(int samples_counter = 0; samples_counter<NUMBER_OF_SAMPLES_TO_COUNT; ++samples_counter)
170  {
171  /*------------------------- application variables ------------------------*/
172 
173  /*-----------read the collected data and store in memory -----------------*/
174  IRPyro_read(&IRPyro_Sensor);
175  /*--------------- send collected data to a host --------------------------*/
176  UART_stream_char_send(IRPyro_Sensor.channel_value, IRPyro_Sensor.channel_saturation_byte);
177  // UART_stream_binary_send(IRPyro_Sensor.raw_data);
178  }
179  /*---------------- do what is needed with the value ----------------------*/
180 
181  /*--------------------- close the device ---------------------------------*/
182  IRPyro_close(&IRPyro_Sensor);
183 }
184 /**
185  * @brief Collects the number of data samples indicated by NUMBER_OF_FRAMES_TO_COUNT
186  * @param this_device IRPyro configuration data
187  * @attention Set your serial terminal console with the following parameters:
188  * @verbatim
189  * Baud Rate: 921600
190  * Parity: None
191  * Data Bits: 8
192  * Stop Bits: 1
193  * Hardware Flow Control: None
194  * Software Flow Control: None
195  * @endverbatim
196  * Select display format to the UART by un-commenting the appropriate function:
197  * - UART_stream_char_send() for plain text display comma delimited.
198  * - UART_stream_binary_send() for binary format package.
199  */
200 static void read_a_TO_sample(IRPyro_sensor_device_type* this_device)
201 {
202 #define NUMBER_OF_FRAMES_TO_COUNT 3 // change to the desired number
203 #define IRPyro_FRAME_COUNT_LOCATION 5 // position on the user data buffer
204  uint16_t sample_counter = 0;
205  int read_delay = 1;
206 
207  /* A delay is created based on the power mode and the sample rate configured
208  to avoid reading the device too fast.
209  */
210  if(this_device->AFE_register.C_LP)
211  {
212  read_delay = (this_device->AFE_register.S7_S0 +1)*6; // on low power aprox factor
213  }
214  else
215  {
216  read_delay = this_device->AFE_register.S7_S0 +1;
217  }
218  IRPyro_read(this_device);
219  while (sample_counter < NUMBER_OF_FRAMES_TO_COUNT)
220  {
221  Micro_controller_delay_ms(read_delay);
222  if (IRPyro_read(this_device))
223  {
224  ++sample_counter;
225  UART_stream_char_send(this_device->channel_value, this_device->channel_saturation_byte);
226  //UART_stream_binary_send(this_device->raw_data);
227  }
228  }
229 }
230 /**
231  * @brief Example to initialize multiple IRPyros and stream data
232  *
233  * Creates a list of IRPyro sensors with all four channels active and the minimal
234  * required configuration: location of the CS and INT port/pin and a I2C
235  * address. See Read_Me.txt
236  * @attention Set your serial terminal console with the following parameters:
237  * @verbatim
238  * Baud Rate: 921600
239  * Parity: None
240  * Data Bits: 8
241  * Stop Bits: 1
242  * Hardware Flow Control: None
243  * Software Flow Control: None
244  * @endverbatim
245  * Select display format to the UART by un-commenting the appropriate function:
246  * - UART_stream_char_send() for plain text display comma delimited.
247  * - UART_stream_binary_send() for binary format package.
248  * @note Modify accordingly depending on architecture
249  */
251 {
252  /*------------------------- IRPyro sensor definition ---------------------*/
253  /*
254  * NOTE: .number_of_active_channels can be set to 1 or 4.
255  * - when equal to 1 data from channel 2 is collected
256  * - when equal to 4 data from channels 1-4 is collected.
257  * IMPORTANT:
258  * FIFO data collected is stored in each individual sensor data structure
259  * using the same criteria as with a single sensor. See stream_data_IRPyro()
260  */
261 #define IRPyro_MAXINT 2147483647
262  /*------------------- Memory allocation, initialization ------------------*/
263 
264  IRPyro_devices IRPyro_device = {0};
265 
266  /*----------------------- --- CONFIGURATION ----- -----------------------*/
267 
268  AFE_reg_type IRPyro_AFE_Master =
269  {
270  .S7_S0 = 0, // Sets the sampling rate to 1,000 samples per second.
271  .LP = LOW_POWER_DISABLE, // Low power sets the sampling rate to 166 samples per second.
272  .HP = HP_DISABLE, // High pass filter enabled
273  .C_LP = LOW_PASS_180, // Low pass filter set at 180Hz
274  .CLK_OUT = CLK_DISABLE, // Clock output enabled to synchronize other IRPyro sensors
275  .SYNC = MASTER, // IRPyro set as Master
276  .TEMP = TEMP_DISABLE, //
277  .INT = INT_DISABLE // IRPyro indicates data ready enable
278  };
279 
280  CCP_reg_type IRPyro_Ch_Cfg =
281  {
282  .Feedback_cap = FEEDBACK_200_80, // Feedback capacitance
283  .High_pass_filter_setting = HIGH_PASS_1HZ, // High pass filter set at 1Hz
284  .Feedback_transconductance = TCONDUCT_1_2T, // Time constant selection
285  .status_bit = CH_ENABLE // Channel ready to collect data
286  };
287 
288  WUP_reg_type IRPyro_WUP_Cfg =
289  {
290  .UHT = MAX_WUP_THRESHOLD, // Upper High Threshold = 255 events
291  .ULT = SAFE_WUP_THRESHOLD, // Upper Low Threshold = 180 events
292  .LHT = MIN_WUP_THRESHOLD, // Low High Threshold = 0 events
293  .LLT = MIN_WUP_THRESHOLD, // Low Low Threshold = 0 events
294  .WT_Threshold = DEFAULT_NO_EVENTS, // Wake up time Threshold = 10 events
295  .DP0_DP2 = NOT_IN_USE_VALUE, // Active pixel channel
296  .CH0_CH2 = SEL_CH_2, // Reference channel
297  .ST = SLEEP_MODE_ONE_CH // Sleep mode type
298  };
299  uint8_t num_of_IRPyro_on_demo_board = 3; // number of devices on a IRPB_027 Rev B demo board
300  /*----------------- ADDRESSES ------------*/
301  /* Assuming four sensors on an IRPyro Break out board or demo board*/
302  IRPyro_device[0].INT_Port = 1;
303  IRPyro_device[0].CS_Port = 2;
304  IRPyro_device[0].CS_Pin = 1;
305  IRPyro_device[0].INT_Pin = 4;
306  IRPyro_device[0].address = 0x70;
307 
308  IRPyro_device[1].CS_Port = 2;
309  IRPyro_device[1].INT_Port = 1;
310  IRPyro_device[1].CS_Pin = 5;
311  IRPyro_device[1].INT_Pin = 5;
312  IRPyro_device[1].address = 0x69;
313 
314  IRPyro_device[2].CS_Port = 2;
315  IRPyro_device[2].INT_Port = 1;
316  IRPyro_device[2].CS_Pin = 4;
317  IRPyro_device[2].INT_Pin = 6;
318  IRPyro_device[2].address = 0x68;
319 
320  /*----------------- CONFIGURATION ------------*/
321  IRPyro_device[0].number_of_active_channels = 1;
322  IRPyro_device[0].read_mode = 1;
323  IRPyro_device[0].AFE_register = IRPyro_AFE_Master; // MASTER
324  IRPyro_device[0].CCP_register[2] = IRPyro_Ch_Cfg;
325  IRPyro_device[0].WUP_register = IRPyro_WUP_Cfg;
326 
327  IRPyro_device[1].number_of_active_channels = 1;
328  IRPyro_device[1].read_mode = 1;
329  IRPyro_device[1].AFE_register = IRPyro_AFE_Master;
330  IRPyro_device[1].CCP_register[2] = IRPyro_Ch_Cfg;
331  IRPyro_device[1].WUP_register = IRPyro_WUP_Cfg;
332 
333  IRPyro_device[2].number_of_active_channels = 1;
334  IRPyro_device[2].read_mode = 1;
335  IRPyro_device[2].AFE_register = IRPyro_AFE_Master;
336  IRPyro_device[2].CCP_register[2] = IRPyro_Ch_Cfg;
337  IRPyro_device[2].WUP_register = IRPyro_WUP_Cfg;
338 
339  /*-------------------------- board setup ---------------------------------*/
340  Micro_controller_template_init();
343  IRPyro_sensor_population(IRPyro_device, &num_of_IRPyro_on_demo_board);
344  // disable all CS lines
346  /*-------- test the open_list, read_list and close_list functions --------*/
347  /*-------------------------- open_list ---------------------------------*/
348  IRPyro_open_devices(IRPyro_device, num_of_IRPyro_on_demo_board);
349  /*-------------------------- read_list ---------------------------------*/
350  for (int sweep=0; sweep< IRPyro_MAXINT; ++sweep)
351  {
352  IRPyro_read_devices(IRPyro_device, num_of_IRPyro_on_demo_board);
353  for(int i=0; i<3 ; ++i)
354  {
355  UART_PutString(USART2, (uint8_t*)"SENSOR:");
356  UART_PutNumber(USART2, (uint32_t)i);
357  UART_PutString(USART2, (uint8_t*)" , ");
358  UART_stream_char_send(IRPyro_device[i].channel_value, IRPyro_device[i].channel_saturation_byte);
359  //UART_stream_binary_send(IRPyro_device[i].raw_data);
360  }
361  }
362  /*-------------------------- close_list ---------------------------------*/
363  IRPyro_close_devices(IRPyro_device, 4);
364  /*-------------------------- collate results -----------------------------*/
365 }
366 /**
367  * @brief Shows how to change sensor parameters on the run.
368  * @attention Set your serial terminal console with the following parameters:
369  * @verbatim
370  * Baud Rate: 921600
371  * Parity: None
372  * Data Bits: 8
373  * Stop Bits: 1
374  * Hardware Flow Control: None
375  * Software Flow Control: None
376  * @endverbatim
377  * Select display format to the UART by un-commenting the appropriate function:
378  * - UART_stream_char_send() for plain text display comma delimited.
379  * - UART_stream_binary_send() for binary format package.
380  * @note This function demonstrates
381  sampling_rate_set, high_pass_set, low_pass_set, gain_set, power_off,
382  sampling_rate_get, high_pass_get, low_pass_get, gain_get, power_normal,
383  power_low,
384  power_sleep,
385  power_wakeup
386  */
387 static void IOCTL_TO_example(void)
388 {
389  /*-------------------------- memory allocation----------------------------*/
390  IRPyro_sensor_device_type IRPyro_Sensor =
391  {
392  .CS_Port = 2,
393  .CS_Pin = 1,
394  .INT_Port = 1,
395  .INT_Pin = 4,
396  .address = 0x75,
397  .number_of_active_channels = 1,
398  .read_mode = 1,
399  };
400  /*----------------------- --- CONFIGURATION ------------------------------*/
401  AFE_reg_type IRPyro_AFE_Single =
402  {
403  .S7_S0 = 0, // Sets the sampling rate to 1,000 samples per second.
404  .LP = LOW_POWER_DISABLE, // Low power sets the sampling rate to 166 samples per second.
405  .HP = HP_DISABLE, // High pass filter enabled
406  .C_LP = LOW_PASS_180, // Low pass filter set at 180Hz
407  .CLK_OUT = CLK_DISABLE, // Clock output enabled to synchronize other IRPyro sensors
408  .SYNC = MASTER, // IRPyro set as Master
409  .TEMP = TEMP_DISABLE, //
410  .INT = INT_DISABLE // IRPyro indicates data ready enable
411  };
412  CCP_reg_type IRPyro_Ch_Cfg =
413  {
414  .Feedback_cap = FEEDBACK_3200_1280, // Feedback capacitance
415  .High_pass_filter_setting = HIGH_PASS_1HZ, // High pass filter set at 1Hz
416  .Feedback_transconductance = TCONDUCT_0_15T, // Time constant selection
417  .status_bit = CH_ENABLE // Channel ready to collect data
418  };
419 
420  /*-------- Single Sensor Configuration -----------------------------------*/
421  IRPyro_Sensor.AFE_register = IRPyro_AFE_Single;
422  IRPyro_Sensor.CCP_register[2] = IRPyro_Ch_Cfg;
423  IRPyro_cmd_type IOCTL_cmd = {0};
424  IRPyro_arg_type IOCTL_arg = {0};
425  /*-------------------------- board setup ---------------------------------*/
426  Micro_controller_template_init();
429  // disable all CS lines
431  /*----------------- enable the sensor for streaming-----------------------*/
432  IRPyro_open(&IRPyro_Sensor);
433  /*------------------------ Sampling rate ---------------------------------*/
434  IOCTL_cmd.cmd = sampling_rate_get; // Normal power, 0x00 = 1ms
435  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
436  read_a_TO_sample(&IRPyro_Sensor);
437 
438  IOCTL_cmd.cmd = sampling_rate_set; // Normal power, 0xaa = 10 ms
439  IOCTL_arg.arg = 0x0A;
440  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
441  read_a_TO_sample(&IRPyro_Sensor);
442 
443  IOCTL_cmd.cmd = sampling_rate_set; // Normal power, 0x00 = 1 ms
444  IOCTL_arg.arg = 0x00;
445  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
446  read_a_TO_sample(&IRPyro_Sensor);
447  /*------------------------ High pass filter ------------------------------*/
448  IOCTL_cmd.cmd = high_pass_set; // Normal power, 0x02 = 2 Hz
449  IOCTL_arg.arg = HIGH_PASS_2HZ;
450  IOCTL_arg.channel = 1;
451  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
452  read_a_TO_sample(&IRPyro_Sensor);
453 
454  IOCTL_cmd.cmd = high_pass_get;
455  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
456  read_a_TO_sample(&IRPyro_Sensor);
457 
458  IOCTL_cmd.cmd = high_pass_set;
459  IOCTL_arg.arg = HIGH_PASS_8HZ;
460  IOCTL_arg.channel = 2;
461  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
462  read_a_TO_sample(&IRPyro_Sensor);
463 
464  IOCTL_cmd.cmd = high_pass_get;
465  read_a_TO_sample(&IRPyro_Sensor);
466  /*------------------------ Low pass filter ------------------------------*/
467  IOCTL_cmd.cmd = low_pass_set;
468  IOCTL_arg.arg = LOW_PASS_45;
469  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
470  read_a_TO_sample(&IRPyro_Sensor);
471 
472  IOCTL_cmd.cmd = low_pass_get;
473  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
474  read_a_TO_sample(&IRPyro_Sensor);
475  /*------------------------ Gain changes ----------------------------------*/
476  IOCTL_cmd.cmd = gain_set;
477  IOCTL_arg.arg = GAIN_08;
478  IOCTL_arg.channel = 3;
479  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
480  read_a_TO_sample(&IRPyro_Sensor);
481 
482  IOCTL_cmd.cmd = gain_get;
483  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
484  read_a_TO_sample(&IRPyro_Sensor);
485 
486  IOCTL_cmd.cmd = gain_set;
487  IOCTL_arg.arg = GAIN_16;
488  IOCTL_arg.channel = 4;
489  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
490  read_a_TO_sample(&IRPyro_Sensor);
491  /*------------------------ Power control ---------------------------------*/
492  IOCTL_cmd.cmd = power_normal;
493  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
494  read_a_TO_sample(&IRPyro_Sensor);
495 
496  IOCTL_cmd.cmd = power_low;
497  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
498  read_a_TO_sample(&IRPyro_Sensor);
499 
500  IOCTL_cmd.cmd = power_sleep;
501  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
502 
503  IOCTL_cmd.cmd = power_wakeup;
504  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
505 
506  IOCTL_cmd.cmd = power_off;
507  IRPyro_ioctl(&IRPyro_Sensor, &IOCTL_cmd, IOCTL_arg);
508 
509  IRPyro_close(&IRPyro_Sensor);
510 };
511 /**
512  * @brief callback function
513  * @attention This function is called from an interrupt service request function
514  * and should be minimal.
515  */
516 static void wakeup_event_callback(void)
517 {
518 // add non blocking code
519 }
520 /**
521  * @brief Wake up event detection
522  * This function configures the IRPyro sensor to sleep mode
523  * @attention Set your serial terminal console with the following parameters:
524  * @verbatim
525  * Baud Rate: 921600
526  * Parity: None
527  * Data Bits: 8
528  * Stop Bits: 1
529  * Hardware Flow Control: None
530  * Software Flow Control: None
531  * @endverbatim
532  * Select display format to the UART by un-commenting the appropriate function:
533  * - UART_stream_char_send() for plain text display comma delimited.
534  * - UART_stream_binary_send() for binary format package.
535  * @attention This function is called from an interrupt service request function
536  * and should be minimal.
537  */
538 static void wake_up_TO_event_detection(void)
539 {
540 #define TIME_TO_WAIT 600000
541  /*------------------ Memory allocation, initialization-------------------*/
542  IRPyro_sensor_device_type IRPyro_single_sensor = {0}; // Instance of sensor
543  uint32_t time_to_wait = TIME_TO_WAIT;
544  uint8_t wake_up_detected = 0;
545  IRPyro_cmd_type IOCTL_cmd = {0};
546  IRPyro_arg_type IOCTL_arg = {0};
547 
548  /*-------------------Physical Location ----------------------------------*/
549  IRPyro_single_sensor.CS_Port = 2;
550  IRPyro_single_sensor.CS_Pin = 1;
551  IRPyro_single_sensor.INT_Port = 1;
552  IRPyro_single_sensor.INT_Pin = 4;
553  /*-------------------Test configuration ---------------------------------*/
554  IRPyro_single_sensor.read_mode = 1; // Polled configuration
555  IRPyro_single_sensor.address = 0x08; // I2C address to configure
556  IRPyro_single_sensor.number_of_active_channels = 1; // configures channel 2 for streaming
557  /*------------------- Wake up event definition -------------------------*/
558  IRPyro_single_sensor.WUP_register.UHT = MAX_WUP_THRESHOLD; // Upper High Threshold = 255 events
559  IRPyro_single_sensor.WUP_register.ULT = SAFE_WUP_THRESHOLD; // Upper Low Threshold = 180 events
560  IRPyro_single_sensor.WUP_register.LHT = MIN_WUP_THRESHOLD; // Low High Threshold = 0 events
561  IRPyro_single_sensor.WUP_register.LLT = MIN_WUP_THRESHOLD; // Low Low Threshold = 0 events
562  IRPyro_single_sensor.WUP_register.WT_Threshold = DEFAULT_NO_EVENTS; // Wake up event Threshold = 10 events
563  IRPyro_single_sensor.WUP_register.DP0_DP2 = NOT_IN_USE_VALUE; // Active pixel channel
564  IRPyro_single_sensor.WUP_register.CH0_CH2 = SEL_CH_2; // Reference channel
565  IRPyro_single_sensor.WUP_register.ST = SLEEP_MODE_ONE_CH; // Single channel selected
566  /*-------------------------- board setup ---------------------------------*/
567  Micro_controller_template_init();
570  // disable all CS lines
572  /*------------------------ Begin Test ------------------------------------*/
573  UART_PutString(USART2, (uint8_t*)"15 Configure sensor WAKE UP EVENT, SEND TO SLEEP, DETECT WAKE UP \n");
574  IRPyro_open(&IRPyro_single_sensor);
575  UART_PutString(USART2, (uint8_t*)"WAKE UP EVENT DETECTION BY HARDWARE INTERRUPT \n");
576 
577  /*------------------------ Send sensor to sleep --------------------------*/
578  UART_PutString(USART2, (uint8_t*)"SET IRPyro ON POWER NORMAL \n");
579  IOCTL_cmd.cmd = power_normal;
580  IRPyro_ioctl(&IRPyro_single_sensor, &IOCTL_cmd, IOCTL_arg);
581  read_a_TO_sample(&IRPyro_single_sensor);
582 
583  UART_PutString(USART2, (uint8_t*)"SET IRPyro ON POWER SLEEP \n");
584  IOCTL_cmd.cmd = power_sleep;
585  IRPyro_ioctl(&IRPyro_single_sensor, &IOCTL_cmd, IOCTL_arg);
586 
587  /*------------------------ Send MCU to sleep -----------------------------*/
588  UART_PutString(USART2, (uint8_t*)"SEND MCU TO SLEEP \n");
589  UART_PutString(USART2, (uint8_t*)"WAIT FOR IRPyro TO WAKE MCU \n");
590  /*--------------- assign external function to wake-up event --------------*/
591  EXTernal_Callback_Setup(wakeup_event_callback);
592  // PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
593  /*--------------- send micro controller to sleep --------------------------*/
594  PWR_EnterSleepMode(PWR_SLEEPEntry_WFI);
595 
596  /*wait for the sensor to wake up or time to run out*/
597  do
598  {
599  wake_up_detected = EXTI_detected(0);
600  --time_to_wait;
601  }
602  while ((time_to_wait != 0) && (wake_up_detected == 0));
603 
604  if (time_to_wait == 0 && wake_up_detected == 0)
605  {
606  IOCTL_cmd.cmd = power_wakeup;
607  UART_PutString(USART2, (uint8_t*)"FORCED POWER WAKE UP \n");
608  IRPyro_ioctl(&IRPyro_single_sensor, &IOCTL_cmd, IOCTL_arg);
609  UART_PutString(USART2, (uint8_t*)"READ TEST AFTER FORCED POWER WAKE UP \n");
610  read_a_TO_sample(&IRPyro_single_sensor);
611  }
612  else
613  {
614  UART_PutString(USART2, (uint8_t*)"WAKE UP EVENT DETECTED!! \n");
615  UART_PutString(USART2, (uint8_t*)"READ TEST AFTER WAKE UP EVENT \n");
616  read_a_TO_sample(&IRPyro_single_sensor);
617  }
618 
619  IRPyro_close(&IRPyro_single_sensor);
620  /*-------------------------- collate results -----------------------------*/
621  UART_PutString(USART2, (uint8_t*)"============\n");
622  UART_PutString(USART2, (uint8_t*)"--------------WAKE UP EVENT DETECTION BY HARDWARE INTERRUPT-------------------------\n");
623 }
624 /**
625  * @brief USART TX function
626  */
627 static void tx_function(void)
628 {
629 
630 }
631 /**
632  * @brief USART RX function
633  */
634 static void rx_function(void)
635 {
636  uint8_t uart_byte = (uint8_t)USART_ReceiveData(USART2);
637 }
638 /**
639  * @brief configures USART irq functions
640  */
641 static void usart_callback_setup(void)
642 {
643  USART_Callback_Rx_Setup(rx_function);
644  USART_Callback_Tx_Setup(tx_function);
645 }
646 /**
647  * @brief Detect IRPyro sensors present in the demo board
648  * @param this_list IRPyro sensor array
649  * @param list_size number of sensors in the array
650 */
651 static void IRPyro_sensor_population(IRPyro_devices this_list, uint8_t *list_size)
652 {
653  uint8_t num_of_IRPyro = *list_size;
654  uint8_t devices_present =0;
655  for(uint8_t current=0 ; current < num_of_IRPyro; ++ current)
656  {
657  if (IRPyro_open(&this_list[current]) == 1)
658  {
659  ++ devices_present;
660  }
661  }
662  *list_size = devices_present;
663 }
664 /**
665  * @brief Changes the state of all the CS lines as used on the IRPyro backplane board
666  * @param state 0 disabled / 1 enabled
667  */
669 {
670  CS_pin_set(2,1,state);
671  CS_pin_set(2,3,state);
672  CS_pin_set(2,4,state);
673  CS_pin_set(2,5,state);
674 }
675 /**
676  * @brief power cycles the sensors on the board to assure stability
677 */
679 {
680  // toggle all CS lines
682  Micro_controller_delay_ms(30);
684  Micro_controller_delay_ms(30);
686 }
687 /** end of IRPyroAPI_Examples
688  * @}
689  */
690 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
wake_up_TO_event_detection
static void wake_up_TO_event_detection(void)
Wake up event detection This function configures the IRPyro sensor to sleep mode.
Definition: main_for_TO.c:538
usart_callback_setup
static void usart_callback_setup(void)
configures USART irq functions
Definition: main_for_TO.c:641
main_for_TO.h
Function prototypes and initialization macros for example code.
read_sample_single_TO_device
static void read_sample_single_TO_device(void)
Example to initialize one IRPyro TO and stream data Creates an IRPyro TO sensor with one channel acti...
Definition: main_for_TO.c:109
rx_function
static void rx_function(void)
USART RX function.
Definition: main_for_TO.c:634
read_sample_multiple_TO_devices
static void read_sample_multiple_TO_devices(void)
Example to initialize multiple IRPyros and stream data.
Definition: main_for_TO.c:250
IOCTL_TO_example
static void IOCTL_TO_example(void)
Shows how to change sensor parameters on the run.
Definition: main_for_TO.c:387
tx_function
static void tx_function(void)
USART TX function.
Definition: main_for_TO.c:627
demo_board_sensor_control
static void demo_board_sensor_control(int value)
Changes the state of all the CS lines as used on the IRPyro backplane board.
Definition: main_for_TO.c:668
NUMBER_OF_FRAMES_TO_COUNT
#define NUMBER_OF_FRAMES_TO_COUNT
sensor_power_stabilize
static void sensor_power_stabilize()
power cycles the sensors on the board to assure stability
Definition: main_for_TO.c:678
TIME_TO_WAIT
#define TIME_TO_WAIT
read_a_TO_sample
static void read_a_TO_sample(IRPyro_sensor_device_type *this_device)
Collects the number of data samples indicated by NUMBER_OF_FRAMES_TO_COUNT.
Definition: main_for_TO.c:200
wakeup_event_callback
static void wakeup_event_callback(void)
callback function
Definition: main_for_TO.c:516
NUMBER_OF_SAMPLES_TO_COUNT
#define NUMBER_OF_SAMPLES_TO_COUNT
main
int main(void)
Call point to the example functions.
Definition: main_for_TO.c:76
IRPyro_MAXINT
#define IRPyro_MAXINT
IRPyro_sensor_population
static void IRPyro_sensor_population(IRPyro_devices this_list, uint8_t *list_size)
Detect IRPyro sensors present in the demo board.
Definition: main_for_TO.c:651