IRPyro API  (sKEMLIB1)
Collection of routines and data structures covering the functionality of the IRPyro sensor
Micro_controller_template.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file Micro_controller_template.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.6
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief Micro controller specific code to access the IRPyro sensor.
9 * @verbatim
10 ===============================================================================
11 ##### How to use this template #####
12 ===============================================================================
13 [..]
14 (#) The Micro_controller_template.c and Micro_controller_template.h contain
15  the minimal declarations and function implementation that are specific
16  to the hardware configuration in which an IRPyro sensor is connected.
17 (#) This template is organized in two layers:
18  (++) Private functions which are micro controller and board specific,
19  for initialization and configuration.
20  (+++) GPIO initialization
21  GPIO_structure_init(): Enables the specific port-pin combination
22  specific to ARM micro controller
23  (see ../Libraries/STM32F30x_StdPeriph_Driver/src/stm32f30x_gpio.c)
24  (+++) I2C initialization
25  Micro_controller_I2C_init(): High level load of the data structure
26  specific to I2C implementation on ARM micro controllers.
27  i2c_Init(): Detailed initialization of I2C specific to ARM micro controllers.
28  (+++) Timer configuration
29  (+++) External Interrupt configuration
30  (+++) USART configuration
31  Locate the pins dedicated to the USART in your micro controller
32  Change the values accordingly on Micro_controller_UART_Init()
33  Configure RealTerm or similar with this values:
34  Baud rate: 921600
35  Parity : None
36  Data Bits: 8
37  Stop Bits: 1
38  Hardware Flow Control: None
39  Capture streaming data.
40  (++) Public interface functions to the IRPyro API. The purpose is to provide
41  a layer to hide the specifics of the micro controller regarding:
42  (+++) Micro_controller_template functions
43  (-) Micro_controller_template_init(): Groups together the private
44  configuration functions.
45  (-) Micro_controller_delay_ms(): To provide a delay function,
46  required only at power-up of the IRPyro sensor
47  (+++) GPIO Control Functions
48  (-) INT_pin_read(): If this pin is active low FIFO data is ready.
49  (-) CS_pin_set() : Control of IRPyro power line.
50  (-) power_set() : Power up toggle sequence.
51  (+++) I2C Control Functions prototypes
52  (-) i2c_Write() : Sends commands to the IRPyro via I2C
53  (-) i2c_Read() : Retrieves status / data from the IRPyro via I2C
54  (+++) USART Access Functions prototypes
55  (-) UART_byte_get() : Recovers a byte from the USART
56  (-) UART_stream_send(): Sends collected data from the IRPyro
57 (#) The present example is tailored for the STM32F303 NUCLEO-32 micro controllers
58 * @endverbatim
59 ******************************************************************************
60  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
61  @verbatim
62  Copyright (c) 2018, _KEMET, Ltd
63  All rights reserved.
64  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
65  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
66  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
67  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
68  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
69  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
70  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
71  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
72  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
73  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74  @endverbatim
75 ******************************************************************************
76 */
77 /* Includes ------------------------------------------------------------------*/
79 /** @defgroup IRPyro_microcontroller_interface IRPyro micro controller interface
80  * @brief Provides access to: GPIO, I2C, UART, LEDs, TIM for the NUCLEO-F303K8 board
81  * @verbatim
82  * @endverbatim
83  * @attention Modify accordingly depending on architecture
84  * @{
85 */
86 /* Private variables ---------------------------------------------------------*/
87 /** @defgroup IRPyro_I2C IRPyro I2C
88  * @brief Intermediate level functions to access I2C
89  * @verbatim
90  * Module provides initialization, read and write functions that allow
91  * architecture independence to the IRPyro API
92  * @endverbatim
93  * @note Modify accordingly depending on architecture
94  * @{
95  */
96 /** @defgroup I2C_G1_IRPyro IRPyro I2C Suggested Configuration Values
97  * @brief I2C clock and timeout values for ARM
98  * @verbatim
99  * Sets the clock and timeout constants for the I2C read and write
100  * functions
101  * @endverbatim
102  * @note Modify accordingly depending on architecture
103  * @{
104  */
105 #define I2C_CLK_TIMING_DEFAULT 0x00A00D26 // Refer to STM AN4235 --> 0x00800D22 0x00A00D26
106 #define I2C_TIMEOUT_DEFAULT 50 // Number of tries for a flag (5000)
107 #define I2C_SCL_PIN GPIO_Pin_7 // SCL pin
108 #define I2C_SDA_PIN GPIO_Pin_6 // SDA pin
109 #define I2C_SCL_SRC GPIO_PinSource7 // SCL pin
110 #define I2C_SDA_SRC GPIO_PinSource6 // SDA pin
111 #define I2C_PORT GPIOB // PORT B
112 /** end of IRPyro I2C Suggested Configuration Values
113  * @}
114  */
115 /** @defgroup I2C_G2_IRPyro IRPyro I2C Configuration Structure
116  * @brief Data structure to group the I2C configuration values
117  * @verbatim
118  * This structure is accessed by i2c_Write and i2c_Read
119  * @endverbatim
120  * @note Modify accordingly depending on architecture
121  * @{
122  */
123 /**
124  * @struct I2C_Config Micro_controller_template.c
125  * @brief IRPyro Analog Front End (AFE) register structure definition
126  */
127 typedef struct I2C_Config
128 {
129  uint32_t CLK_Timing; ///< clock timing
130  uint32_t Timeout; ///< timeout in counts
131  uint16_t SCL_Pin; ///< I2C clock pin
132  uint16_t SDA_Pin; ///< I2C data pin
133  uint8_t SCL_Src; ///< I2C clock source pin
134  uint8_t SDA_Src; ///< I2C data source pin
135  GPIO_TypeDef* GPIOx; ///< I2C Port
137 typedef enum {Error = 0, Success = !Error } Status;
138 /** end of IRPyro I2C Configuration Structure
139  * @}
140  */
141 /** end of IRPyro access to I2C functions
142  * @}
143  */
144 /* Private functions ---------------------------------------------------------*/
145 static void Micro_controller_GPIO_init(void);
146 static void Micro_controller_I2C_init(void);
147 static void Micro_controller_UART_init(void);
148 static void Micro_controller_Systick_init(uint16_t frequency);
150 /* GPIO Control Functions prototypes ******************************************/
151 static void GPIO_structure_init(uint32_t GPIO_Pin_x, GPIOMode_TypeDef GPIO_Mode,
152  GPIOOType_TypeDef Output_Type, GPIOSpeed_TypeDef Speed,
153  GPIOPuPd_TypeDef PuPd, GPIO_TypeDef* GPIOx);
154 /* I2C Initialization function ************************************************/
155 static void i2c_Init (I2C_Config_Type* Config);
156 /* External Interrupt private function prototypes -----------------------------------------------*/
157 static void EXTI9_5_Config(void);
158 static void EXTI4_Config(void);
159 /* LED configuration of Backplane boards function prototype -----------------------------------------------*/
160 static void Micro_controller_LED_configure(void);
161 static void Micro_controller_TIM_init(void);
162 /** @defgroup IRPyro_Micro_controller Micro controller interface
163  * @brief Micro controller architecture dependent functions
164  * @verbatim
165  * Functions to initialize ports, timers and delays
166  * implemented for the STM32 micro controllers
167  * @endverbatim
168  * @note Modify accordingly depending on architecture
169  * @{
170  */
171 /**
172  * @brief Groups all required initialization in one function
173  * @attention Modify accordingly depending on architecture
174  */
176 {
177  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
185 }
186 /**
187  * @brief Example of board initialization to set up all the ports and
188  * peripherals. (Read_Me.txt)
189  *
190  * @attention Modify this function to enable the appropriate pins location for
191  * INT and CS lines where the IRPyro is connected.
192  */
194 {
195  // IRPyro INT lines on the IRPyro Base Board (dIRBB01) and demo boards
196  // set pins 4, 5 , 6 & 7 of port A as normal INPUTS
197  GPIO_structure_init(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12,
198  GPIO_Mode_IN,
199  GPIO_OType_PP,
200  GPIO_Speed_2MHz,
201  GPIO_PuPd_UP,
202  GPIOA );
203  // IRPyro CS lines lines on the IRPyro Base Board (dIRBB01) and demo boards
204  // set pins 1, 2, 3, 4 & 5 of port B as normal OUTPUTS
205  GPIO_structure_init(GPIO_Pin_1 |GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5,
206  GPIO_Mode_OUT,
207  GPIO_OType_PP,
208  GPIO_Speed_2MHz,
209  GPIO_PuPd_NOPULL,
210  GPIOB );
211  // IRPyro I2C Lines on the IRPyro Base Board (dIRBB01) and demo boards
212  // set pins 6 & 7 of port B as in ALTERNATE FUNCTION
213  GPIO_structure_init(GPIO_Pin_6 | GPIO_Pin_7,
214  GPIO_Mode_AF,
215  GPIO_OType_OD,
216  GPIO_Speed_50MHz,
217  GPIO_PuPd_NOPULL,
218  GPIOB );
219 }
220 /**
221  * @brief Calls I2C initialization. See Read_Me.txt
222  * @attention Modify accordingly depending on the initialization of the I2C lines
223  * on the micro controller architecture.
224  */
226 {
236 }
237 /**
238  * @brief Initializes the USART 2 on the STM32F303K8
239  * PORT A and pins 2,15 are used.
240  * Refer to STM document RM0316 section 29 and the stm32f30x_usart.c
241  */
243 {
244  EXTI4_Config();
245  EXTI9_5_Config();
246 }
247 /**
248  * @brief Initializes the USART 2 on the STM32F303K8
249  * PORT A and pins 2,15 are used.
250  * Refer to STM document RM0316 section 29 and the stm32f30x_usart.c
251  */
253 {
254  // CONFIGURATIONS
255  GPIO_InitTypeDef GPIO_InitState; // Port and pin
256  USART_InitTypeDef USART_InitStruct ; // USART
257  USART_ClockInitTypeDef USART_InitClockStruct; // USART clock
258  NVIC_InitTypeDef NVIC_InitStructure ; // USART interrupt
259  USART2->ICR = 0xE;
260  RCC->CFGR3 |= 0x10;
261  RCC->CFGR = 0x0034000A;
262  SYSCFG->CFGR1 |= (uint32_t)0x100000;
263  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); // enables clocks for USART2
264  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // enables pins for USART2 on Port A
265 
266  GPIO_InitState.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_15 ; // Pin configuration for port A
267  GPIO_InitState.GPIO_Mode = GPIO_Mode_AF ;
268  GPIO_InitState.GPIO_Speed = GPIO_Speed_10MHz ;
269  GPIO_InitState.GPIO_OType = GPIO_OType_PP ;
270  GPIO_InitState.GPIO_PuPd = GPIO_PuPd_NOPULL ;
271  GPIO_Init(GPIOA,&GPIO_InitState) ;
272  GPIO_PinAFConfig(GPIOA,GPIO_PinSource15,GPIO_AF_7); // Pin source enabled
273  GPIO_PinAFConfig(GPIOA,GPIO_PinSource2 ,GPIO_AF_7);
274 
275  USART_DeInit(USART2); // USART2 initialization
276  USART_StructInit(&USART_InitStruct);
277  USART_ClockStructInit(&USART_InitClockStruct);
278  USART_InitStruct.USART_BaudRate = 921600; // see Micro_controller_CLOCK_init
279  USART_ClockInit(USART2,&USART_InitClockStruct);
280  USART_Init(USART2,&USART_InitStruct) ; // Usart 2 initialization
281  USART_ITConfig(USART2,USART_IT_RXNE,ENABLE) ;
282 
283 
284  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; // we want to configure the USARTX interrupts
285  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // USARTX priority group
286  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // sub priority inside the group
287  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ; // the USARTX interrupts are globally enabled
288  NVIC_Init(&NVIC_InitStructure); // the properties are passed to the NVIC_Init function which takes care of the low level stuff
289  NVIC_EnableIRQ(USART2_IRQn);
290  USART_Cmd(USART2,ENABLE) ;
291 }
292 /**
293  * @brief Example of board timer initialization to set a delay
294  *
295  * The IRPyro sensor requires a delay loop to allow settling
296  * Refer to section "12.8 Device Power Up and Reset" in the Reference Manual
297  * This can be achieved using an interrupt based counter as shown in this example.
298  *
299  * @attention This function is required to use Micro_controller_delay_ms()
300  */
301 void Micro_controller_Systick_init(uint16_t frequency)
302 {
303  RCC_ClocksTypeDef RCC_Clocks;
304  RCC_GetClocksFreq(&RCC_Clocks);
305  (void) SysTick_Config(RCC_Clocks.HCLK_Frequency / frequency);
306 }
307 static volatile uint32_t ticks;
308 static volatile uint32_t ticks_down;
309 /**
310  * @brief Updates the both tick counters on a Systick interrupt every millisecond
311  * @attention Modify accordingly depending on architecture
312  */
313 void SysTick_Handler(void)
314 {
315  if (ticks < UINT32_MAX )
316  {
317  ++ticks;
318  }
319  if (ticks_down)
320  {
321  --ticks_down;
322  }
323 }
324 /**
325  * @brief Sets the tick_down to monitor a time out
326  * @attention Modify accordingly depending on architecture
327  */
328 void Micro_controller_timeout_set(uint32_t timeout)
329 {
330  ticks_down = timeout;
331 }
332 /**
333  * @brief Recovers the tick_down value to check is not expired
334  * @attention Modify accordingly depending on architecture
335  */
337 {
338  return ticks_down;
339 }
340 /**
341  * @brief Sets the tick counter
342  * @param delay integer value in milliseconds
343  * @attention Modify accordingly depending on architecture
344  */
345 void Micro_controller_delay_set(uint32_t delay)
346 {
347  ticks = delay;
348 }
349 /**
350  * @brief Retrieves the tick counter
351  * @attention Modify accordingly depending on architecture
352  */
354 {
355  return ticks;
356 }
357 /**
358  * @brief return the system clock as milliseconds
359  * @attention Modify accordingly depending on architecture
360  */
361 static uint32_t SysTick_millis(void)
362 {
363  return ticks;
364 }
365 /**
366  * @brief Example of delay function in micro seconds.
367  * Refer to section "12.8 Device Power Up and Reset" in the Reference Manual
368  * @param time_us integer value in micro seconds
369  * @attention Modify accordingly depending on architecture
370  */
371 void Micro_controller_delay_us(uint32_t time_us)
372 {
373 #define CLOCK_CYCLES_PER_INSTRUCTION 1
374 #define CLOCK_FREQ 72 //IN MHZ (e.g. 16 for 16 MHZ)
375  for (int i=0; i<time_us; ++i)
376  {
377  for (int cycleCount = CLOCK_FREQ / CLOCK_CYCLES_PER_INSTRUCTION; cycleCount>0; --cycleCount)
378  {
379  }
380  }
381 }
382 /**
383  * @brief Example of delay function.
384  *
385  * This delay function is required to allow the IRPyro
386  * sensor to stabilize on power up. In this example
387  * SysTick_Handler() provides the delay.
388  * Refer to section "12.8 Device Power Up and Reset" in the Reference Manual
389  *
390  * @param time_ms delay time in milliseconds.
391  * @retval None.
392  * @attention Modify accordingly depending on architecture
393  */
394 void Micro_controller_delay_ms(uint32_t time_ms)
395 {
396  uint32_t start, end;
397  start = SysTick_millis();
398  end = start + time_ms;
399  if (start < end)
400  {
401  while ((SysTick_millis() >= start) && (SysTick_millis() < end))
402  {
403  // do nothing
404  }
405  }
406  else
407  {
408  while ((SysTick_millis() >= start) || (SysTick_millis() < end))
409  {
410  // do nothing
411  };
412  }
413 }
414 /** end of Micro_controller_template
415  * @}
416  */
417 /**@defgroup IRPyro_GPIO IRPyro GPIO
418  * @brief access to General I/O functions (GPIO)
419  * @verbatim
420  * Provides the data structure.
421  * For ARM type micro controllers enable clocks and configure pins.
422  * @endverbatim
423  * @attention Modify accordingly depending on architecture
424  * @{
425  */
426 /** @defgroup GPIO_F1_IRPyro IRPyro initialization of GPIO structure.
427  * @brief Initializes the GPIO structure
428  * @verbatim
429  * The GPIO implementation on the STM32F3 micro controllers
430  * provides architecture independence to the IRPyro API
431  * @endverbatim
432  * @attention Modify accordingly depending on architecture
433  * @{
434  */
435 /**
436  * @brief Populates and initializes GPIO structures.
437  * @param GPIO_Pin_x: Pin Number (can use bitwise operation for multiple pins)
438  * @param GPIO_Mode: Port Mode, Input, Output, Analogue, Alternate Function
439  * @param Output_Type: PP or OD
440  * @param Speed: GPIO Speed
441  * @param PuPd: Pull up configuration, Up, Down, None
442  * @param GPIOx: GPIO Port: A,B,C,D,E,F
443  * @retval None
444  * @verbatim This function uses the ST libraries to configure the registers of
445  * the GPIO pins. The purpose of this function is to offer a higher
446  * level configuration for the pins, ensuring that the structure is
447  * fully populated every time.
448  * @endverbatim
449  * @attention Modify this function so the pins where the IRPyro are connected can be
450  * accessible according to the requirements of the chosen MCU
451  */
452 void GPIO_structure_init(uint32_t GPIO_Pin_x,
453  GPIOMode_TypeDef GPIO_Mode,
454  GPIOOType_TypeDef Output_Type,
455  GPIOSpeed_TypeDef Speed,
456  GPIOPuPd_TypeDef PuPd,
457  GPIO_TypeDef* GPIOx)
458 {
459  // Declare Structure
460  GPIO_InitTypeDef my_GPIO_Struc;
461  // Enable respective GPIO clock
462  if (GPIOx==GPIOA)
463  {
464  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
465  }
466  if (GPIOx==GPIOB)
467  {
468  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
469  }
470  // Populate Structure
471  my_GPIO_Struc.GPIO_Pin = GPIO_Pin_x;
472  my_GPIO_Struc.GPIO_Mode = GPIO_Mode;
473  my_GPIO_Struc.GPIO_OType = Output_Type;
474  my_GPIO_Struc.GPIO_Speed = Speed;
475  my_GPIO_Struc.GPIO_PuPd = PuPd;
476  // Initialize Port
477  GPIO_Init(GPIOx, &my_GPIO_Struc);
478 }
479 /** end of IRPyro initialization of GPIO structure.
480  * @}
481  */
482 /** @defgroup GPIO_F2_IRPyro IRPyro GPIO control functions.
483  * @brief Read and write functions for the CS and INT
484  * @verbatim
485  * For the IRPyro sensor the CS pin acts like a chip enable powering up the
486  * sensor.
487  * The INT pin on the IRPyro, when enabled, indicates that data is ready on
488  * the FIFO, for collection
489  * @endverbatim
490  * @attention Modify this function so affected pins of the MCU can work as an INPUT
491  * @{
492  */
493 /**
494  * @brief Reads the status of the pin assigned to the INT line of IRPyro
495  *
496  * When the INT field in the AFE register is set to 1 the INT line on
497  * the IRPyro will go LOW when data is ready.
498  * @param port IRPyro port number
499  * @param pin IRPyro pin number to the INT pin
500  * @retval INT_pin_status INT pin is asserted LOW return (1)
501  * @attention Modify this function so the INT pin acts as an INPUT
502  */
503 uint8_t INT_pin_read(uint8_t port, uint8_t pin)
504 {
505  GPIO_TypeDef* GPIOx;
506  uint16_t GPIO_Pin = 1 << pin;
507  uint8_t INT_pin_status = 0x00;
508  switch (port)
509  {
510  case 1:
511  GPIOx = GPIOA;
512  break;
513  case 2:
514  GPIOx = GPIOB;
515  break;
516  default:
517  GPIOx = GPIOA;
518  break;
519  }
520  INT_pin_status = (0 == GPIO_ReadInputDataBit(GPIOx, GPIO_Pin)) ? 1 : 0;
521  return INT_pin_status;
522 }
523 /**
524  * @brief ON/OFF control from the MCU to the IRPyro sensor
525  *
526  * CS HIGH enables the IRPyro, CS LOW effectively turns OFF the sensor
527  * @param port IRPyro port number
528  * @param pin IRPyro pin number to the CS pin
529  * @param value 0/1 for OFF/ON
530  * @retval None
531  * @attention If this function is modified, the affected pins of the MCU should
532  * work as an OUTPUT
533  */
534 void CS_pin_set(uint8_t port, uint8_t pin, uint8_t value)
535 {
536  GPIO_TypeDef* GPIOx;
537  uint16_t GPIO_Pin = 1<<pin;
538  BitAction BitVal;
539  switch (port)
540  {
541  case 1:
542  GPIOx = GPIOA;
543  break;
544  case 2:
545  GPIOx = GPIOB;
546  break;
547  default:
548  GPIOx = GPIOA;
549  break;
550  }
551  BitVal = (value == 0) ? Bit_RESET : Bit_SET;
552  if ( BitVal )
553  {
554  GPIO_SetBits(GPIOx,GPIO_Pin) ;
555  }
556  else
557  {
558  GPIO_ResetBits(GPIOx,GPIO_Pin) ;
559  }
560 }
561 /**
562  * @brief Power sequence from the MCU to the IRPyro sensor
563  *
564  * @param port IRPyro port number
565  * @param pin IRPyro pin number to the CS pin
566  * @retval None
567  * @attention Refer to section "12.8 Device Power Up and Reset" in the Reference Manual
568  */
569 void power_set(uint8_t port, uint8_t pin)
570 {
571  CS_pin_set(port, pin, 0);
572  CS_pin_set(port, pin, 1);
574  CS_pin_set(port, pin, 0);
576  CS_pin_set(port, pin, 1);
578 }
579 /** end of IRPyro GPIO control functions.
580  * @}
581  */
582 /** end of IRPyro access to General I/O functions (GPIO)
583  * @}
584  */
585 /* I2C Private Variables ----------------------------------------------------------*/
586 static I2C_Config_Type Config = {0}; ///< Configuration Structure for the I2C Module
587 static uint8_t Config_Valid_Flag =0; ///< Configuration valid flag indicating module has been configured
588 /** @addtogroup IRPyro_I2C
589  * @{
590  */
591 /** @defgroup I2C_G3_IRPyro I2C Initialization Function
592  * @brief Initializes the I2C structure
593  * @verbatim
594  * The I2C implementation on the STM32F3 micro controllers
595  * provides architecture independence to the IRPyro API
596  * @endverbatim
597  * @note Modify accordingly depending on architecture
598  * @{
599  */
600 /**
601  * @brief Initializes the I2C Hardware (I2C1).
602  * @param[in] External_Config Data structure with the I2C definition according to STM
603  * @retval None
604  * @verbatim
605  * This function uses the ST hardware libraries to configure the
606  * registers responsible for the I2C hardware. This function sets
607  * the bus mode (master/slave), clock speed, master address, etc.
608  * This function also sets which pins should be used for the I2C bus.
609  * @endverbatim
610  * @attention Modify this function to allow the chosen MCU access to the I2C bus
611  * as a master
612  */
613 void i2c_Init(I2C_Config_Type* External_Config)
614 {
615  // Structure Declaration
616  I2C_InitTypeDef I2C_InitStructure = {0};
617  // Check for pointer
618  if (External_Config)
619  {
620  // Set Configuration Structure
621  Config.Timeout = External_Config->Timeout;
622  Config.CLK_Timing = External_Config->CLK_Timing;
623  // Enable Peripheral clock
624  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
625  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
626  // Set up alternate function pin config
627  GPIO_PinAFConfig(External_Config->GPIOx, External_Config->SCL_Src, GPIO_AF_4);
628  GPIO_PinAFConfig(External_Config->GPIOx, External_Config->SDA_Src, GPIO_AF_4);
629  // Deinitialise I2C
630  I2C_DeInit(I2C1);
631  I2C_SoftwareResetCmd(I2C1);
632  // Define I2C Init structure
633  I2C_InitStructure.I2C_Timing = Config.CLK_Timing; // Controls the CLK for I2C Bus
634  I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable; // I2C_AnalogFilter_Enable;
635  I2C_InitStructure.I2C_DigitalFilter = 0x00; // This parameter can be a number between 0x00 and 0x0F */
636  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; // Other options are MSBus.
637  I2C_InitStructure.I2C_OwnAddress1 = 0x00; // Is there a standard for the master address?
638  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; // I guess this refers to the bit after every command
639  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; //Not sure about this one.
640  // Initialize structure
641  I2C_Init(I2C1, &I2C_InitStructure);
642  // Enable I2C Hardware
643  SYSCFG_I2CFastModePlusConfig(SYSCFG_I2CFastModePlus_I2C1, ENABLE);
644  I2C_Cmd(I2C1, ENABLE);
645  // Set Config valid flag
646  Config_Valid_Flag = 1;
647  }
648 }
649 /** end of I2C Initialization Function
650  * @}
651  */
652 /** @defgroup I2C_G4_IRPyro I2C Control Functions
653  * @brief Master to slave read and write functions
654  * @verbatim
655  * The I2C implementation on the STM32F3 micro controllers
656  * provides architecture independence to the IRPyro API
657  * @endverbatim
658  * @note Modify accordingly depending on architecture
659  * @{
660  */
661 /**
662  * @brief Sends data via I2C port.
663  * @param[in] DeviceAddr Slave device address
664  * @param[in] Command First byte to be sent
665  * @param[in,out] *pBuffer: Remaining data bytes to be sent
666  * @param[in] len Number of bytes to be sent
667  * @retval Pass/Fail
668  * @verbatim
669  * This function sends an array of bytes over the I2C bus of a given
670  * length. The function is responsible for setting up the I2C transfer
671  * handling, i.e. calling the slave address and sending the data if an ACK is received.
672  * @endverbatim
673  * @attention Modify this function to implement an I2C write that is platform specific
674  * @todo Use of GOTO on the I2C read and write functions in order to detect what
675  * causes the function to return. Needs to be addressed. Multiple returns reduce
676  * complexity but is difficult to trace. This functions could be re-factored since
677  * there are several waiting loops, required for the flags in use
678  */
679 uint8_t i2c_Write(uint8_t DeviceAddr ,uint8_t Command, uint8_t* pBuffer, uint8_t len)
680 {
681  // Local Variables
682  uint32_t timeout = Config.Timeout;
683  uint32_t counter = 0;
684  uint8_t op_code = 0;
685  // Exit if configuration is not valid
686  if (!Config_Valid_Flag)
687  {
688  op_code = 0; // no configuration
689  goto finish;
690  }
691  // Wait until I2C is not busy
692  while (I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET)
693  {
694  if ((--timeout) == 0)
695  {
696  op_code = 2; // I2C_ISR_BUSY time out
697  goto finish;
698  }
699  }
700  // Flush buffer before transmitting
701  I2C_Cmd(I2C1, DISABLE);
702  I2C_Cmd(I2C1, ENABLE);
703  // Configure slave address, nbytes, reload, end mode and start or stop generation //
704  I2C_TransferHandling(I2C1, ((DeviceAddr& 0x7f) << 1),(len+1), I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
705  // Wait until TXIS flag is set //
706  timeout = Config.Timeout;
707  while (I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET)
708  {
709  if ((--timeout) == 0)
710  {
711  op_code = 3; // I2C_ISR_TXIS time out
712  goto finish;
713  }
714  }
715  // Send the set i2c Command
716  I2C_SendData(I2C1, Command);
717  // Now send the len amount of data bytes
718  while (counter < len)
719  {
720  // Wait until TXIS flag is set //
721  timeout = Config.Timeout;
722  while (I2C_GetFlagStatus(I2C1, I2C_ISR_TXE) == RESET)
723  {
724  if ((--timeout) == 0)
725  {
726  op_code = 4; // I2C_ISR_TXE time out
727  goto finish;
728  }
729  }
730  // Send Data
731  I2C_SendData(I2C1, pBuffer[counter]);
732  ++counter;
733  }
734  // Wait until TC flag is set
735  timeout = Config.Timeout;
736  while (I2C_GetFlagStatus(I2C1, I2C_ISR_TXE) == RESET)
737  {
738  if ((--timeout) == 0)
739  {
740  op_code = 5; // I2C_ISR_TXE time out
741  goto finish;
742  }
743  }
744  // Clear STOPF flag
745  I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
746  op_code = 1; // success!
747  // All operations completed OK return true
748 finish:
749  // if(op_code != 1) op_code = 0; // values <> 1,0 are for debugging only
750  return op_code;
751 }
752 /**
753  * @brief Reads data via I2C port.
754  * @param DeviceAddr: Slave device address
755  * @param Command: First byte to be sent
756  * @param *pBuffer: Pointer to receiving bytes array
757  * @param len: Number of bytes to be received
758  * @retval Pass/Fail
759  * @verbatim This function is used to receive an array of bytes over the I2C bus
760  * of a given length. The function is responsible for setting up the
761  * I2C transfer handling, i.e. calling the slave address and reading
762  * the data if an ACK is received.
763  * @endverbatim
764  * @attention Modify this function to implement an I2C read that is platform specific
765  * @todo Use of GOTO on the I2C read and write functions in order to detect what
766  * causes the function to return. Needs to be addressed. Multiple returns reduce
767  * complexity but is difficult to trace. This functions could be re-factored since
768  * there are several waiting loops, required for the flags in use.
769  */
770 uint8_t i2c_Read(uint8_t DeviceAddr,uint8_t Command, uint8_t* pBuffer, uint16_t len)
771 {
772  // local time out counter
773  uint32_t timeout = Config.Timeout;
774  uint8_t op_code =0;
775  // Exit if configuration is not valid
776  if (!Config_Valid_Flag)
777  {
778  op_code = 0; // no configuration
779  goto finish;
780  }
781  // Test on BUSY Flag //
782  while (I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET)
783  {
784  if ((--timeout) == 0)
785  {
786  op_code = 2; // I2C_ISR_BUSY time out
787  goto finish;
788  }
789  }
790  // Configure slave address, nbytes, reload, end mode and start or stop generation //
791  I2C_TransferHandling(I2C1, (DeviceAddr << 1), 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
792  // Wait until TXIS flag is set
793  timeout = Config.Timeout;
794  while (I2C_GetFlagStatus(I2C1, I2C_ISR_TXE) == RESET)
795  {
796  if ((--timeout) == 0)
797  {
798  op_code = 3; // I2C_ISR_TXE time out
799  goto finish;
800  }
801  }
802  // Send ASIC command //
803  I2C_SendData(I2C1, Command);
804  // Wait until TC flag is set //
805  timeout = Config.Timeout;
806  while (I2C_GetFlagStatus(I2C1, I2C_ISR_TC) == RESET)
807  {
808  if ((--timeout) == 0)
809  {
810  op_code = 4; // I2C_ISR_TC time out
811  goto finish;
812  }
813  }
814  // Configure slave address, nbytes, reload, end mode and start or stop generation //
815  I2C_TransferHandling(I2C1, (DeviceAddr << 1), len, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
816  // Wait until all data are received //
817  while (len)
818  {
819  // Wait until RXNE flag is set //
820  timeout = Config.Timeout;
821  while (I2C_GetFlagStatus(I2C1, I2C_ISR_RXNE) == RESET)
822  {
823  if ((--timeout) == 0)
824  {
825  op_code = 5; // I2C_ISR_RXNE time out
826  goto finish;
827  }
828  }
829  // Read data from RXDR //
830  *pBuffer = I2C_ReceiveData(I2C1);
831  // Point to the next location where the byte read will be saved //
832  ++pBuffer;
833  // Decrement the read bytes counter //
834  --len;
835  }
836  // Wait until STOP flag is set //
837  timeout = Config.Timeout;
838  while (I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == RESET)
839  {
840  if ((--timeout) == 0)
841  {
842  op_code = 6; // I2C_ISR_STOPF time out
843  goto finish;
844  }
845  }
846  /* Clear STOPF flag */
847  I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
848  op_code =1;
849  /* All operations completed OK return true*/
850 finish:
851  // if(op_code != 1) op_code = 0; // values <> 1,0 are for debugging only
852  return op_code;
853 }
854 /** end of I2C Control Functions
855  * @}
856  */
857 /** end of IRPyro_I2C
858  * @}
859  */
860 /** @defgroup Micro_controller_interrupt_external External interrupt configuration
861  * @brief Architecture dependent functions
862  * @verbatim
863  * Functions to initialize ports, pins and interrupts handlers required to monitor
864  * external interrupts. This implementation is specific for the STM32 micro controllers
865  * STM32F30x Peripherals Interrupt Handlers
866  * Add here the Interrupt Handler for the used peripheral(s) (PPP), for the
867  * available peripheral interrupt handler's name please refer to the startup
868  * file (startup_stm32f30x.s).
869  * @endverbatim
870  * @note Modify accordingly depending on architecture
871  * @{
872  */
873 /**
874  * @brief Configure Sensor 1 INT line in interrupt mode
875  * @attention Initialization of GPIO is a prerequisite for successful configuration
876  */
877 static void EXTI4_Config(void)
878 {
879  EXTI_InitTypeDef EXTI_InitStructure;
880  NVIC_InitTypeDef NVIC_InitStructure;
881  /* Enable SYSCFG clock */
882  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
883  /* Connect EXTI4 Line to PA4 pin */
884  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource4);
885  /* Enable and set EXTI15_10 Interrupt to the lowest priority */
886 
887  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
888  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; // EXTI4 priority group
889  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // sub priority inside the group
890  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
891  NVIC_Init(&NVIC_InitStructure);
892  NVIC_EnableIRQ(EXTI4_IRQn);
893 
894  /* Configure EXTI4 line */
895  EXTI_InitStructure.EXTI_Line = EXTI_Line4;
896  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
897  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
898  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
899  EXTI_Init(&EXTI_InitStructure);
900 }
901 /**
902  * @brief Configure Sensor 2,3, and 4 INT line in interrupt mode
903  * @attention Initialization of GPIO is a prerequisite for successful configuration
904  */
905 static void EXTI9_5_Config(void)
906 {
907  EXTI_InitTypeDef EXTI_InitStructure;
908  NVIC_InitTypeDef NVIC_InitStructure;
909  /* Enable SYSCFG clock */
910  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
911  /* Connect EXTI5 Line to PA5 pin */
912  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource5);
913  /* Connect EXTI6 Line to PA6 pin */
914  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource6);
915  /* Connect EXTI7 Line to PA7 pin */
916  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource7);
917  /* Enable and set Button EXTI Interrupt to the lowest priority */
918 
919  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
920  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; // EXTI9_5 priority group
921  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // sub priority inside the group
922  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
923  NVIC_Init(&NVIC_InitStructure);
924  NVIC_EnableIRQ(EXTI9_5_IRQn);
925 
926  /* Configure Button EXTI line */
927  EXTI_InitStructure.EXTI_Line = EXTI_Line5;
928  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
929  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
930  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
931  EXTI_Init(&EXTI_InitStructure);
932  EXTI_InitStructure.EXTI_Line = EXTI_Line6;
933  EXTI_Init(&EXTI_InitStructure);
934  EXTI_InitStructure.EXTI_Line = EXTI_Line7;
935  EXTI_Init(&EXTI_InitStructure);
936 }
937 /* collects the status of the wake up event */
938 volatile uint8_t EXTI_line_record[4] = {0};
939 // typedef void (*EXTernal_callback)(void);
941 /**
942  * @brief Starts function callbacks
943  * @param Callback Function to call after each interval.
944  */
946 {
947  EXTI_Callback_Fn = Callback;
948 }
949 /**
950  * @brief Ends function callbacks.
951  */
952 static void EXTernal_Callback_Disable(void)
953 {
954  EXTI_Callback_Fn = NULL;
955 }
956 /**
957  * @brief Configures function callbacks
958  * @param Callback Function to call after event detected
959  */
961 {
962  // Callback_Fn = Callback;
963  if (Callback)
964  {
965  EXTernal_Callback_Enable(Callback);
966  }
967  else
968  {
970  }
971 }
972 /**
973  * @brief This function handles external line 4 interrupt request.
974  */
976 {
977  if(EXTI_GetITStatus(EXTI_Line4) != RESET)
978  {
979  /* Signal Sensor 1 data is ready */
980  EXTI_line_record[0]= 1;
981  if (NULL != EXTI_Callback_Fn)
982  {
983  (*EXTI_Callback_Fn)();
984  EXTI_line_record[0]= 0;
985  }
986  /* Clear the EXTI line 4 pending bit */
987  EXTI_ClearITPendingBit(EXTI_Line4);
988  }
989 }
990 /**
991  * @brief This function handles external lines 5 to 9 interrupt request.
992  */
994 {
995  if((EXTI_GetITStatus(EXTI_Line7) != RESET))
996  {
997  /* Signal Sensor 4 data is ready */
998  EXTI_line_record[3]= 1;
999  if (NULL != EXTI_Callback_Fn)
1000  {
1001  (*EXTI_Callback_Fn)();
1002  EXTI_line_record[3]= 0;
1003  }
1004  /* Clear the EXTI line 7 pending bit */
1005  EXTI_ClearITPendingBit(EXTI_Line7);
1006  }
1007  if((EXTI_GetITStatus(EXTI_Line6) != RESET))
1008  {
1009  /* Signal Sensor 3 data is ready */
1010  EXTI_line_record[2]= 1;
1011  if (NULL != EXTI_Callback_Fn)
1012  {
1013  (*EXTI_Callback_Fn)();
1014  EXTI_line_record[2]= 0;
1015  }
1016  /* Clear the EXTI line 6 pending bit */
1017  EXTI_ClearITPendingBit(EXTI_Line6);
1018  }
1019  if((EXTI_GetITStatus(EXTI_Line5) != RESET))
1020  {
1021  /* Signal Sensor 2 data is ready */
1022  EXTI_line_record[1]= 1;
1023  if (NULL != EXTI_Callback_Fn)
1024  {
1025  (*EXTI_Callback_Fn)();
1026  EXTI_line_record[1]= 0;
1027  }
1028  /* Clear the EXTI line 5 pending bit */
1029  EXTI_ClearITPendingBit(EXTI_Line5);
1030  }
1031 }
1032 /**
1033  * @brief This function access the status of the interrupt lines for the wake up event
1034  * @param exti_line the exti_line to be questioned
1035  * @return 1 for exti_line awake 0 for no event detected
1036  */
1037 uint8_t EXTI_detected(uint8_t exti_line)
1038 {
1039  uint8_t op_result = 0;
1040  op_result = EXTI_line_record[exti_line];
1041  EXTI_line_record[exti_line] =0;
1042  return op_result;
1043 }
1044 /**
1045  * @} end of Micro_controller_interrupt_external group
1046  */
1047 /**@defgroup USART_IRPyro IRPyro Functions access the USART
1048  * @brief Allows to get a byte from the USART and send a stream of data to a client
1049  * @note Modify accordingly depending on architecture
1050  * @{
1051  */
1052 /* USART Private Variable-----------------------------------------------------*/
1053 volatile uint8_t uart_byte; // char from UART
1054 /* USART Private Functions ---------------------------------------------------*/
1055 void UART_PutChar(USART_TypeDef* USARTx, uint8_t ch);
1056 /**
1057  * @brief Puts a char in the USART
1058  */
1059 void UART_PutChar(USART_TypeDef* USARTx, uint8_t ch)
1060 {
1061  while(!(USARTx->ISR & USART_ISR_TXE));
1062  USARTx->TDR = ch;
1063 }
1064 /**
1065  * @brief Puts a string in the USART
1066  * @param USARTx usart
1067  * @param str
1068  */
1069 void UART_PutString(USART_TypeDef* USARTx, uint8_t * str)
1070 {
1071  while(*str != 0)
1072  {
1073  UART_PutChar(USARTx, *str);
1074  ++str;
1075  }
1076 }
1077 /**
1078  * @brief Puts a number in the USART
1079  * @param USARTx usart port sending the number
1080  * @param number to be send
1081  */
1082 void UART_PutNumber(USART_TypeDef* USARTx, uint32_t number)
1083 {
1084  char value[10] = {0}; //a temp array to hold results of conversion
1085  int i = 0; //loop index
1086  do
1087  {
1088  value[i] = (char)(number % 10) + '0'; //convert integer to character
1089  ++i;
1090  number /= 10;
1091  }
1092  while(number);
1093  while(i) //send data
1094  {
1095  UART_PutChar(USARTx, value[--i]);
1096  }
1097 }
1098 // typedef void (*USART_callback)(void);
1101 /**
1102  * @brief Starts function callbacks
1103  * @param Callback Function to call after each interval.
1104  */
1106 {
1107  USARTCallback_Tx_Fn = Callback;
1108 }
1109 /**
1110  * @brief Ends function callbacks.
1111  */
1112 static void USART_Callback_Tx_Disable(void)
1113 {
1114  USARTCallback_Tx_Fn = NULL;
1115 }
1116 /**
1117  * @brief Configures function callbacks
1118  * @param Callback Function to call after event detected
1119  */
1121 {
1122  if (Callback)
1123  {
1124  USART_Callback_Tx_Enable(Callback);
1125  }
1126  else
1127  {
1129  }
1130 }
1132 {
1133  USARTCallback_Rx_Fn = Callback;
1134 }
1135 /**
1136  * @brief Ends function callbacks.
1137  */
1138 static void USART_Callback_Rx_Disable(void)
1139 {
1140  USARTCallback_Rx_Fn = NULL;
1141 }
1142 /**
1143  * @brief Configures function callbacks
1144  * @param Callback Function to call after event detected
1145  */
1147 {
1148  if (Callback)
1149  {
1150  USART_Callback_Rx_Enable(Callback);
1151  }
1152  else
1153  {
1155  }
1156 }
1157 /**
1158  * @brief Handles incomming char from the USART and stores it in global uart_byte
1159  */
1161 {
1162 // Get data from UART
1163  if(USART_GetITStatus(USART2 , USART_IT_RXNE) != RESET)
1164  {
1165  if (NULL != USARTCallback_Rx_Fn)
1166  {
1167  (*USARTCallback_Rx_Fn)();
1168  }
1169  }
1170 // Send data to the UART
1171  if(USART_GetITStatus(USART2 , USART_IT_TXE) != RESET)
1172  {
1173  if (NULL != USARTCallback_Tx_Fn)
1174  {
1175  (*USARTCallback_Tx_Fn)();
1176  }
1177  }
1178 }
1179 /**
1180  * @brief Interface to acces uart_byte
1181  */
1182 uint8_t UART_byte_get()
1183 {
1184  return uart_byte;
1185 }
1186 /**
1187  * @brief Formats output and sends to USART as a string
1188  * @param format constant format string as with printf
1189  * @param ... variable argument, list pf values.
1190  */
1191 static void UART_display_write(char const * format, ...)
1192 {
1193  va_list args;
1194  char buf[80] = "";
1195  va_start(args, format);
1196  vsprintf(buf, format, args); /* buf contains the formatted string */
1197  UART_PutString(USART2, (uint8_t*)buf);
1198  va_end(args); /* Clean up. Do NOT omit */
1199 }
1200 /**
1201  * @brief Plain text data for the active channels of the sensor including, frame counter and saturation byte
1202  * @param channel_value array of channel values
1203  * @param channel_saturation encoded saturation bits
1204  */
1205 void UART_stream_char_send(uint32_t *channel_value, uint8_t channel_saturation)
1206 {
1207  UART_display_write("FRAME #, %5u, CH, %5u, %5u, %5u, %5u, SAT, %2u \r\n",
1208  channel_value[5],
1209  channel_value[1],
1210  channel_value[2],
1211  channel_value[3],
1212  channel_value[4],
1213  channel_saturation);
1214 }
1215 /**
1216  * @brief Builds a binary data packet for the channels of the sensor, frame counter and saturation byte
1217  * @param DataS raw data from the sensor
1218  */
1219 void UART_stream_binary_send(uint8_t *DataS)
1220 {
1221 #define PACKET_SIZE 19
1222 #define SATURATION_MASK 0x80
1223 #define SATURATION_FLAG(CH,POS) ((CH & SATURATION_MASK) >> (7 - POS))
1224  uint8_t data[PACKET_SIZE] = {0};
1225  uint8_t index_data = 3, index_DataS =0;
1226  data[0] = 0xAA ; // start of packet marker
1227  data[1] = 0x02 ; // data type
1228  data[2] = 0x0E ; // 14 bytes of data
1229  for(uint8_t channel=0; channel < 4; ++ channel)
1230  {
1231  data[index_data++] = DataS[index_DataS ++]& 0x7f;
1232  data[index_data++] = DataS[index_DataS ++];
1233  data[index_data++] = DataS[index_DataS ++];
1234  }
1235 //fc
1236  data[index_data++] = DataS[index_DataS++];
1237  data[index_data++] = DataS[index_DataS++];
1238 //saturation byte
1239  data[17] = SATURATION_FLAG(DataS[0],0);
1240  data[17] += SATURATION_FLAG(DataS[3],1);
1241  data[17] += SATURATION_FLAG(DataS[6],2);
1242  data[17] += SATURATION_FLAG(DataS[9],3);
1243  data[18] = 0x55 ; // footer
1244  for(uint8_t index_packet=0; index_packet < PACKET_SIZE; ++index_packet)
1245  {
1246  UART_PutChar(USART2, data[index_packet]); // send data
1247  }
1248 }
1249 /** end of IRPyro_USART
1250  * @}
1251  */
1252 /** @defgroup EMITTER Status LEDs and emitter management
1253  * @{
1254  */
1255 /**
1256 * @brief configures and enables status LED's on the backplane boards
1257 */
1259 {
1260  // READY and RUNNING LEDs on the IRPyro Base Board (dIRBB01) and demo boards
1261  // set pins 0 and 1 of port A as normal OUTPUTS
1262  // Set pin 3 for ASIC_PS power control pin on the IRPB_027 rev B backplanes
1263  GPIO_structure_init(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3,
1264  GPIO_Mode_OUT,
1265  GPIO_OType_PP,
1266  GPIO_Speed_2MHz,
1267  GPIO_PuPd_NOPULL,
1268  GPIOA );
1269 
1270  // Enable ASIC_PS pin for IRPB_027 boards (IRPyro TO)
1271  GPIO_SetBits(GPIOA, GPIO_Pin_3);
1272 }
1273 /**
1274 * @brief Controls RUN led state
1275 */
1276 static void LED_RUN(uint8_t LED_run)
1277 {
1278 #define LED_RUN_ON GPIO_ResetBits(GPIOA,GPIO_Pin_1);
1279 #define LED_RUN_OFF GPIO_SetBits(GPIOA,GPIO_Pin_1);
1280  if (LED_run)
1281  {
1282  LED_RUN_ON
1283  }
1284  else
1285  {
1286  LED_RUN_OFF
1287  }
1288 };
1289 /**
1290 * @brief Control for the READY led state
1291 */
1292 void LED_READY(uint8_t LED_ready)
1293 {
1294 #define LED_READY_ON GPIO_ResetBits(GPIOA,GPIO_Pin_0) ;
1295 #define LED_READY_OFF GPIO_SetBits(GPIOA,GPIO_Pin_0) ;
1296  if (LED_ready)
1297  {
1298  LED_READY_ON
1299  }
1300  else
1301  {
1303  }
1304 };
1305 /**
1306 * @brief Configuration when the INTERNAL emitter is selected
1307 */
1309 {
1310  // Emitter on the IRPyro Base Board (dIRBB01) and demo boards
1311  // set pin 0 of port B as normal OUTPUT
1312  GPIO_structure_init(GPIO_Pin_0,
1313  GPIO_Mode_OUT,
1314  GPIO_OType_PP,
1315  GPIO_Speed_2MHz,
1316  GPIO_PuPd_NOPULL,
1317  GPIOB );
1318 };
1319 /**
1320 * @brief Configuration when the EXTERNAL emitter is selected
1321 */
1323 {
1324  GPIO_ResetBits(GPIOB,1) ;
1325  // Emitter on the IRPyro Base Board (dIRBB01) and demo boards
1326  // set pin 0 of port B as normal INPUT
1327  GPIO_structure_init(GPIO_Pin_0,
1328  GPIO_Mode_IN,
1329  GPIO_OType_PP,
1330  GPIO_Speed_2MHz,
1331  GPIO_PuPd_UP,
1332  GPIOB );
1333 };
1334 static volatile uint16_t EmitterTimer;
1335 /**
1336 * @brief
1337 */
1338 static void Emitter_status_and_timer_set(uint8_t *EmitterStatus, uint8_t EmitterONTime)
1339 {
1340  if ( 2 == *EmitterStatus )
1341  {
1342  GPIO_SetBits(GPIOB,GPIO_Pin_0) ;
1343  EmitterTimer = EmitterONTime ;
1344  *EmitterStatus = 0x06 ; // internal emitter in use and ON
1345  }
1346  else
1347  {
1348  GPIO_ResetBits(GPIOB,GPIO_Pin_0) ;
1349  EmitterTimer = 0 ;
1350  *EmitterStatus = 0x0A ; // internal emitter in use and permanently OFF
1351  }
1352 };
1353 /**
1354 * @brief
1355 */
1356 static void Emitter_toggle(uint8_t *EmitterStatus, uint8_t EmitterONTime, uint8_t EmitterOFFTime)
1357 {
1358  if ( 4 == ( *EmitterStatus & 0x04 ) )
1359  {
1360  GPIO_ResetBits(GPIOB, GPIO_Pin_0) ;
1361  EmitterTimer = EmitterOFFTime ;
1362  }
1363  else
1364  {
1365  GPIO_SetBits(GPIOB, GPIO_Pin_0) ;
1366  EmitterTimer = EmitterONTime ;
1367  }
1368 }
1369 /**
1370 * @brief
1371 */
1372 static void Emitter_status_and_timer_update(uint8_t *EmitterStatus, uint8_t EmitterONTime, uint8_t EmitterOFFTime)
1373 {
1374  if ( ( 2 == ( *EmitterStatus & 0xA ) ) && ( 0 == EmitterTimer ) )
1375  {
1376  Emitter_toggle( EmitterStatus, EmitterONTime, EmitterOFFTime);
1377  *EmitterStatus ^= 0x04 ;
1378  }
1379 };
1380 /**
1381 * @brief
1382 */
1383 static uint8_t Emitter_status_evaluate(uint8_t EmitterStatus)
1384 {
1385  if (EmitterStatus == 0 || EmitterStatus == 1)
1386  {
1387  // Internal Emitter is OFF or External Emitter is ON
1388  return 1;
1389  }
1390  else
1391  {
1392  // Internal Emitter is in use
1393  return 0;
1394  }
1395 };
1396 /**
1397 * @brief Changes Emitter status and applies timing parameters
1398 */
1399 void Emitter_control(uint8_t *EmitterStatus, uint8_t EmitterONTime, uint8_t EmitterOFFTime)
1400 {
1401 // handle emitter
1402  if ( 0x80 == ( 0x80 & *EmitterStatus ) )
1403  {
1404  /* Emitter status has just changed
1405  If now 0, neither external nor internal function is enabled, so turn OFF output & set 'output ON' status to 0 but also set pin as input
1406  if now 1, external function is enabled, so ditto
1407  If now 2, internal function is enabled, so enable as output & turn ON
1408  If now 3, internal function is enabled but output permanently OFF
1409  */
1410  *EmitterStatus &= 0x7F ;
1411  if (Emitter_status_evaluate(*EmitterStatus))
1412  {
1414  *EmitterStatus &= 0xFB ; // clear 'internal emitter ON' flag
1415  EmitterTimer = 0 ;
1416  }
1417  else
1418  {
1420  Emitter_status_and_timer_set(EmitterStatus, EmitterONTime);
1421  }
1422  }
1423  Emitter_status_and_timer_update(EmitterStatus, EmitterONTime, EmitterOFFTime);
1424 }
1425 /**
1426 * @brief Configuration for hardware timer for emitter control
1427 */
1428 static void Micro_controller_TIM_init(void)
1429 {
1430  NVIC_InitTypeDef NVIC_InitStructure ;
1431 
1432  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; // we want to configure the TIM3 update interrupts
1433  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // TIM3 priority group
1434  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // sub priority inside the group
1435  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ; // the TIM3 interrupts are globally enabled
1436  NVIC_Init(&NVIC_InitStructure); // the properties are passed to the NVIC_Init function which takes care of the low level stuff
1437 
1438  TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct ;
1439 
1440  //Timer Clock for RUNNING LED
1441  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
1442  //Disable Interrupt
1443  TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);
1444  //Define Timer Structure
1445  TIM_TimeBaseInitStruct.TIM_Prescaler = 1; // Divides by 1
1446  TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; // Count upwards
1447  TIM_TimeBaseInitStruct.TIM_Period = 30000; // Divides by 30,000 making 1ms
1448  TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; // Sets ratio between timer clock and sampling clock used in digital filters (not relevant here)
1449  //Initialise Timer Structure
1450  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStruct);
1451  //Enable Interrupt
1452  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
1453  //Enable interrupt Handler
1454  NVIC_EnableIRQ(TIM3_IRQn);
1455  //Enable timer
1456  TIM_Cmd(TIM3, ENABLE);
1457 };
1458 volatile uint8_t led_run_value = 0;
1459 volatile uint16_t tim3_counter = 0;
1460 volatile uint8_t led_ready_value = 0;
1461 volatile uint32_t sample_period_timer = 0;
1462 //typedef void (*TIM_callback)(void);
1465 {
1466  sample_period_timer = count_value;
1467 }
1469 {
1470  return sample_period_timer;
1471 }
1472 /**
1473  * @brief Starts function callbacks
1474  * @param Callback Function to call after each interval.
1475  */
1477 {
1478  TIM_Callback_Fn = Callback;
1479 }
1480 /**
1481  * @brief Ends function callbacks.
1482  */
1483 static void TIM_Callback_Disable(void)
1484 {
1485  TIM_Callback_Fn = NULL;
1486 }
1487 /**
1488  * @brief Configures function callbacks
1489  * @param Callback Function to call after event detected
1490  */
1492 {
1493  if (Callback)
1494  {
1495  TIM_Callback_Enable(Callback);
1496  }
1497  else
1498  {
1500  }
1501 }
1502 /**
1503 * @brief Interrupt timer for running LED on backplane boards
1504 */
1505 void TIM3_IRQHandler (void)
1506 {
1507  //Clear Timer Flag
1508  TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
1509  if ( sample_period_timer > 0 )
1510  {
1512  }
1513  if ( EmitterTimer > 0 )
1514  {
1515  --EmitterTimer ;
1516  }
1517  if (tim3_counter > 500)
1518  {
1519  led_run_value = (!led_run_value) & 1;
1520  tim3_counter = 0;
1522  if (NULL != TIM_Callback_Fn)
1523  {
1524  (*TIM_Callback_Fn)();
1525  }
1526  }
1527  else
1528  {
1529  ++ tim3_counter;
1530  }
1531 // led_ready_value = (!led_ready_value) & 1;
1532 // LED_READY(led_ready_value);
1533 }
1534 /** end of Status LEDs and emitter management
1535  * @}
1536  */
1537 /** end of IRPyro_microcontroller_interface
1538  * @}
1539  */
1540 
1541 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
SysTick_Handler
void SysTick_Handler(void)
Updates the both tick counters on a Systick interrupt every millisecond.
Definition: Micro_controller_template.c:313
UART_PutChar
void UART_PutChar(USART_TypeDef *USARTx, uint8_t ch)
Puts a char in the USART.
Definition: Micro_controller_template.c:1059
Micro_controller_UART_init
static void Micro_controller_UART_init(void)
Initializes the USART 2 on the STM32F303K8 PORT A and pins 2,15 are used. Refer to STM document RM031...
Definition: Micro_controller_template.c:252
I2C_Config::Timeout
uint32_t Timeout
timeout in counts
Definition: Micro_controller_template.c:130
led_run_value
volatile uint8_t led_run_value
Definition: Micro_controller_template.c:1458
i2c_Init
static void i2c_Init(I2C_Config_Type *Config)
Initializes the I2C Hardware (I2C1).
Definition: Micro_controller_template.c:613
EXTernal_callback
void(* EXTernal_callback)(void)
Definition: Micro_controller_template.h:64
Micro_controller_TIM_init
static void Micro_controller_TIM_init(void)
Configuration for hardware timer for emitter control.
Definition: Micro_controller_template.c:1428
USART_Callback_Rx_Enable
static void USART_Callback_Rx_Enable(USART_callback Callback)
Definition: Micro_controller_template.c:1131
Micro_controller_timeout_set
void Micro_controller_timeout_set(uint32_t timeout)
Sets the tick_down to monitor a time out.
Definition: Micro_controller_template.c:328
TIM_Callback_Disable
static void TIM_Callback_Disable(void)
Ends function callbacks.
Definition: Micro_controller_template.c:1483
LED_READY
void LED_READY(uint8_t LED_ready)
Control for the READY led state.
Definition: Micro_controller_template.c:1292
Status
Status
Definition: Micro_controller_template.c:137
power_set
void power_set(uint8_t port, uint8_t pin)
Power sequence from the MCU to the IRPyro sensor.
Definition: Micro_controller_template.c:569
EXTI_Callback_Fn
static EXTernal_callback EXTI_Callback_Fn
Definition: Micro_controller_template.c:940
TIM3_IRQHandler
void TIM3_IRQHandler(void)
Interrupt timer for running LED on backplane boards.
Definition: Micro_controller_template.c:1505
Config
static I2C_Config_Type Config
Configuration Structure for the I2C Module.
Definition: Micro_controller_template.c:586
LED_READY_OFF
#define LED_READY_OFF
Micro_controller_timeout_get
uint32_t Micro_controller_timeout_get(void)
Recovers the tick_down value to check is not expired.
Definition: Micro_controller_template.c:336
I2C_Config
IRPyro Analog Front End (AFE) register structure definition.
Definition: Micro_controller_template.c:128
Micro_controller_GPIO_init
static void Micro_controller_GPIO_init(void)
Example of board initialization to set up all the ports and peripherals. (Read_Me....
Definition: Micro_controller_template.c:193
EXTernal_Callback_Setup
void EXTernal_Callback_Setup(EXTernal_callback Callback)
Configures function callbacks.
Definition: Micro_controller_template.c:960
I2C_Config::SCL_Pin
uint16_t SCL_Pin
I2C clock pin.
Definition: Micro_controller_template.c:131
USARTCallback_Rx_Fn
static USART_callback USARTCallback_Rx_Fn
Definition: Micro_controller_template.c:1100
CLOCK_CYCLES_PER_INSTRUCTION
#define CLOCK_CYCLES_PER_INSTRUCTION
Emitter_configure_as_input
static void Emitter_configure_as_input(void)
Configuration when the EXTERNAL emitter is selected.
Definition: Micro_controller_template.c:1322
i2c_Write
uint8_t i2c_Write(uint8_t DeviceAddr, uint8_t Command, uint8_t *pBuffer, uint8_t len)
Sends data via I2C port.
Definition: Micro_controller_template.c:679
I2C_SCL_PIN
#define I2C_SCL_PIN
Definition: Micro_controller_template.c:107
Micro_controller_template_init
void Micro_controller_template_init(void)
Groups all required initialization in one function.
Definition: Micro_controller_template.c:175
USART_Callback_Rx_Disable
static void USART_Callback_Rx_Disable(void)
Ends function callbacks.
Definition: Micro_controller_template.c:1138
SATURATION_FLAG
#define SATURATION_FLAG(CH, POS)
USART_Callback_Tx_Disable
static void USART_Callback_Tx_Disable(void)
Ends function callbacks.
Definition: Micro_controller_template.c:1112
I2C_Config::CLK_Timing
uint32_t CLK_Timing
clock timing
Definition: Micro_controller_template.c:129
LED_RUN_OFF
#define LED_RUN_OFF
Micro_controller_delay_set
void Micro_controller_delay_set(uint32_t delay)
Sets the tick counter.
Definition: Micro_controller_template.c:345
I2C_Config::SDA_Src
uint8_t SDA_Src
I2C data source pin.
Definition: Micro_controller_template.c:134
LED_READY_ON
#define LED_READY_ON
TIM_Callback_Enable
static void TIM_Callback_Enable(EXTernal_callback Callback)
Starts function callbacks.
Definition: Micro_controller_template.c:1476
I2C_Config::SDA_Pin
uint16_t SDA_Pin
I2C data pin.
Definition: Micro_controller_template.c:132
CLOCK_FREQ
#define CLOCK_FREQ
tim3_counter
volatile uint16_t tim3_counter
Definition: Micro_controller_template.c:1459
LED_RUN_ON
#define LED_RUN_ON
Emitter_control
void Emitter_control(uint8_t *EmitterStatus, uint8_t EmitterONTime, uint8_t EmitterOFFTime)
Changes Emitter status and applies timing parameters.
Definition: Micro_controller_template.c:1399
Micro_controller_LED_configure
static void Micro_controller_LED_configure(void)
configures and enables status LED's on the backplane boards
Definition: Micro_controller_template.c:1258
EXTI_detected
uint8_t EXTI_detected(uint8_t exti_line)
This function access the status of the interrupt lines for the wake up event.
Definition: Micro_controller_template.c:1037
Emitter_configure_as_output
static void Emitter_configure_as_output(void)
Configuration when the INTERNAL emitter is selected.
Definition: Micro_controller_template.c:1308
GPIO_structure_init
static void GPIO_structure_init(uint32_t GPIO_Pin_x, GPIOMode_TypeDef GPIO_Mode, GPIOOType_TypeDef Output_Type, GPIOSpeed_TypeDef Speed, GPIOPuPd_TypeDef PuPd, GPIO_TypeDef *GPIOx)
Populates and initializes GPIO structures.
Definition: Micro_controller_template.c:452
Micro_controller_I2C_init
static void Micro_controller_I2C_init(void)
Calls I2C initialization. See Read_Me.txt.
Definition: Micro_controller_template.c:225
USART_Callback_Rx_Setup
void USART_Callback_Rx_Setup(USART_callback Callback)
Configures function callbacks.
Definition: Micro_controller_template.c:1146
i2c_Read
uint8_t i2c_Read(uint8_t DeviceAddr, uint8_t Command, uint8_t *pBuffer, uint16_t len)
Reads data via I2C port.
Definition: Micro_controller_template.c:770
Success
@ Success
Definition: Micro_controller_template.c:137
USART_Callback_Tx_Enable
static void USART_Callback_Tx_Enable(USART_callback Callback)
Starts function callbacks.
Definition: Micro_controller_template.c:1105
I2C_PORT
#define I2C_PORT
Definition: Micro_controller_template.c:111
SysTick_millis
static uint32_t SysTick_millis(void)
return the system clock as milliseconds
Definition: Micro_controller_template.c:361
Micro_controller_Systick_init
static void Micro_controller_Systick_init(uint16_t frequency)
Example of board timer initialization to set a delay.
Definition: Micro_controller_template.c:301
Emitter_status_evaluate
static uint8_t Emitter_status_evaluate(uint8_t EmitterStatus)
Definition: Micro_controller_template.c:1383
EmitterTimer
static volatile uint16_t EmitterTimer
Definition: Micro_controller_template.c:1333
Micro_controller_template.h
Public functions of Micro controller specific code to access the IRPyro sensor.
Micro_controller_External_interrupt_init
static void Micro_controller_External_interrupt_init(void)
Initializes the USART 2 on the STM32F303K8 PORT A and pins 2,15 are used. Refer to STM document RM031...
Definition: Micro_controller_template.c:242
EXTI_line_record
volatile uint8_t EXTI_line_record[4]
Definition: Micro_controller_template.c:938
UART_display_write
static void UART_display_write(char const *format,...)
Formats output and sends to USART as a string.
Definition: Micro_controller_template.c:1191
UART_PutString
void UART_PutString(USART_TypeDef *USARTx, uint8_t *str)
Puts a string in the USART.
Definition: Micro_controller_template.c:1069
I2C_Config::SCL_Src
uint8_t SCL_Src
I2C clock source pin.
Definition: Micro_controller_template.c:133
EXTI4_IRQHandler
void EXTI4_IRQHandler(void)
This function handles external line 4 interrupt request.
Definition: Micro_controller_template.c:975
I2C_SDA_SRC
#define I2C_SDA_SRC
Definition: Micro_controller_template.c:110
INT_pin_read
uint8_t INT_pin_read(uint8_t port, uint8_t pin)
Reads the status of the pin assigned to the INT line of IRPyro.
Definition: Micro_controller_template.c:503
EXTI9_5_IRQHandler
void EXTI9_5_IRQHandler(void)
This function handles external lines 5 to 9 interrupt request.
Definition: Micro_controller_template.c:993
ticks
static volatile uint32_t ticks
Definition: Micro_controller_template.c:307
I2C_Config_Type
struct I2C_Config I2C_Config_Type
EXTernal_Callback_Enable
static void EXTernal_Callback_Enable(EXTernal_callback Callback)
Starts function callbacks.
Definition: Micro_controller_template.c:945
Micro_controller_delay_us
void Micro_controller_delay_us(uint32_t time_us)
Example of delay function in micro seconds. Refer to section "12.8 Device Power Up and Reset" in the ...
Definition: Micro_controller_template.c:371
Micro_controller_sample_period_timer_set
void Micro_controller_sample_period_timer_set(uint32_t count_value)
Definition: Micro_controller_template.c:1464
CS_pin_set
void CS_pin_set(uint8_t port, uint8_t pin, uint8_t value)
ON/OFF control from the MCU to the IRPyro sensor.
Definition: Micro_controller_template.c:534
USARTCallback_Tx_Fn
static USART_callback USARTCallback_Tx_Fn
Definition: Micro_controller_template.c:1099
EXTI9_5_Config
static void EXTI9_5_Config(void)
Configure Sensor 2,3, and 4 INT line in interrupt mode.
Definition: Micro_controller_template.c:905
I2C_Config::GPIOx
GPIO_TypeDef * GPIOx
I2C Port.
Definition: Micro_controller_template.c:135
Micro_controller_delay_get
uint32_t Micro_controller_delay_get(void)
Retrieves the tick counter.
Definition: Micro_controller_template.c:353
sample_period_timer
volatile uint32_t sample_period_timer
Definition: Micro_controller_template.c:1461
LED_RUN
static void LED_RUN(uint8_t LED_run)
Controls RUN led state.
Definition: Micro_controller_template.c:1276
UART_PutNumber
void UART_PutNumber(USART_TypeDef *USARTx, uint32_t number)
Puts a number in the USART.
Definition: Micro_controller_template.c:1082
USART_callback
void(* USART_callback)(void)
Definition: Micro_controller_template.h:73
Micro_controller_delay_ms
void Micro_controller_delay_ms(uint32_t time_ms)
Example of delay function.
Definition: Micro_controller_template.c:394
led_ready_value
volatile uint8_t led_ready_value
Definition: Micro_controller_template.c:1460
Emitter_status_and_timer_update
static void Emitter_status_and_timer_update(uint8_t *EmitterStatus, uint8_t EmitterONTime, uint8_t EmitterOFFTime)
Definition: Micro_controller_template.c:1372
TIM_Callback_Fn
static TIM_callback TIM_Callback_Fn
Definition: Micro_controller_template.c:1463
EXTernal_Callback_Disable
static void EXTernal_Callback_Disable(void)
Ends function callbacks.
Definition: Micro_controller_template.c:952
I2C_CLK_TIMING_DEFAULT
#define I2C_CLK_TIMING_DEFAULT
Definition: Micro_controller_template.c:105
TIM_Callback_Setup
void TIM_Callback_Setup(TIM_callback Callback)
Configures function callbacks.
Definition: Micro_controller_template.c:1491
UART_stream_binary_send
void UART_stream_binary_send(uint8_t *DataS)
Builds a binary data packet for the channels of the sensor, frame counter and saturation byte.
Definition: Micro_controller_template.c:1219
UART_byte_get
uint8_t UART_byte_get()
Interface to acces uart_byte.
Definition: Micro_controller_template.c:1182
Emitter_toggle
static void Emitter_toggle(uint8_t *EmitterStatus, uint8_t EmitterONTime, uint8_t EmitterOFFTime)
Definition: Micro_controller_template.c:1356
EXTI4_Config
static void EXTI4_Config(void)
Configure Sensor 1 INT line in interrupt mode.
Definition: Micro_controller_template.c:877
UART_stream_char_send
void UART_stream_char_send(uint32_t *channel_value, uint8_t channel_saturation)
Plain text data for the active channels of the sensor including, frame counter and saturation byte.
Definition: Micro_controller_template.c:1205
Error
@ Error
Definition: Micro_controller_template.c:137
USART2_IRQHandler
void USART2_IRQHandler()
Handles incomming char from the USART and stores it in global uart_byte.
Definition: Micro_controller_template.c:1160
I2C_SCL_SRC
#define I2C_SCL_SRC
Definition: Micro_controller_template.c:109
PACKET_SIZE
#define PACKET_SIZE
USART_Callback_Tx_Setup
void USART_Callback_Tx_Setup(USART_callback Callback)
Configures function callbacks.
Definition: Micro_controller_template.c:1120
TIM_callback
void(* TIM_callback)(void)
Definition: Micro_controller_template.h:87
Emitter_status_and_timer_set
static void Emitter_status_and_timer_set(uint8_t *EmitterStatus, uint8_t EmitterONTime)
Definition: Micro_controller_template.c:1338
I2C_SDA_PIN
#define I2C_SDA_PIN
Definition: Micro_controller_template.c:108
uart_byte
volatile uint8_t uart_byte
Definition: Micro_controller_template.c:1053
I2C_TIMEOUT_DEFAULT
#define I2C_TIMEOUT_DEFAULT
Definition: Micro_controller_template.c:106
Micro_controller_sample_period_timer_get
uint32_t Micro_controller_sample_period_timer_get(void)
Definition: Micro_controller_template.c:1468
ticks_down
static volatile uint32_t ticks_down
Definition: Micro_controller_template.c:308
Config_Valid_Flag
static uint8_t Config_Valid_Flag
Configuration valid flag indicating module has been configured.
Definition: Micro_controller_template.c:587