-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPIO_out_example.c.txt
84 lines (67 loc) · 2.22 KB
/
GPIO_out_example.c.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*!\file GPIO_out_example.c
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief GPIO_out example
** \note Simple GPIO_out.c / GPIO_ex.c example to handle different GPIO outputs
**/
#include "sarmfsw.h"
#include "GPIO_out.h"
#define OUT_B0_GPIO_Port GPIOB
#define OUT_B0_Pin GPIO_PIN_0
#define OUT_B1_GPIO_Port GPIOB
#define OUT_B1_Pin GPIO_PIN_1
#define OUT_B2_GPIO_Port GPIOB
#define OUT_B2_Pin GPIO_PIN_2
#define OUT_Bx_TIMER &htim6
static GPIO_out out_B0; //!< GPIO_out out_B0 instance structure declaration
static GPIO_out out_B1; //!< GPIO_out out_B1 instance structure declaration
static GPIO_out out_B2; //!< GPIO_out out_B2 instance structure declaration
static GPIO_out * const GPIOs_out[] = { &out_B0, &out_B1, &out_B2 }; //!< GPIO_out pointers array (for handler loop)
static const uint8_t GPIOs_out_nb = SZ_ARRAY(GPIOs_out); //!< Number of GPIOs_out
/*!\brief GPIOs_out handler
**/
static void GPIOs_out_handler(void)
{
for (unsigned int i = 0 ; i < GPIOs_out_nb ; i++)
{
GPIO_out_handler(GPIOs_out[i]);
}
}
#ifndef LOGIC_OUT_IT
void GPIO_out_example_handler(void)
#else
void GPIO_out_example_init(void)
#endif
{
static bool init_io = false;
if (!init_io)
{
// Init outputs
GPIO_out_init(&out_B0, GPIO(OUT_B0), GPIO_PIN_SET);
GPIO_out_init(&out_B1, GPIO(OUT_B1), GPIO_PIN_SET);
GPIO_out_init(&out_B2, GPIO(OUT_B2), GPIO_PIN_SET);
// Start logic outputs with different modes
GPIO_out_SetStatic(&out_B0, Toggle, 5000); // Set B0 after 5s
GPIO_out_StartBlink(&out_B1, Set, 0, 500, 250, 0); // Blink B1 500ms On / 250ms Off indefinitely
GPIO_out_StartPulse(&out_B2, Set, 3000, 2000); // Pulse on B2 after 3s, Set for 2s
init_io = true;
}
#ifndef LOGIC_OUT_IT
GPIOs_out_handler();
#endif
}
#ifdef LOGIC_OUT_IT
/*!\brief Period elapsed callback in non blocking mode
** \note This function is called when TIM interrupt took place, inside HAL_TIM_IRQHandler().
** If multiple TIM peripheral use period callback interrupt, custom function is needed including code below.
** Another way is to use callback registration with proper function name.
** \param[in] htim - TIM handle
**/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == OUT_Bx_TIMER)
{
GPIOs_out_handler();
}
}
#endif