11/***************************************************************************/ /**
22 * @file util.c
33 * @brief Utility functions.
4- * @version 2 .0
4+ * @version 3 .0
55 * @author Brecht Van Eeckhoudt
66 ******************************************************************************/
77
@@ -19,10 +19,25 @@ volatile uint32_t msTicks; /* Volatile because it's a global variable that's mod
1919 *****************************************************************************/
2020void initLEDS (void )
2121{
22- GPIO_PinModeSet (gpioPortF , 4 , gpioModePushPull , 1 ); /* LED0 */
23- GPIO_PinModeSet (gpioPortF , 5 , gpioModePushPull , 1 ); /* LED1 */
24- GPIO_PinOutClear (gpioPortF , 4 ); /* Disable LED0 */
25- GPIO_PinOutClear (gpioPortF , 5 ); /* Disable LED1 */
22+ GPIO_PinModeSet (LED0_PORT , LED0_PIN , gpioModePushPull , 1 );
23+ GPIO_PinModeSet (LED1_PORT , LED1_PIN , gpioModePushPull , 1 );
24+ GPIO_PinOutClear (LED0_PORT , LED0_PIN ); /* Disable LED0 */
25+ GPIO_PinOutClear (LED1_PORT , LED1_PIN ); /* Disable LED1 */
26+ }
27+
28+
29+ /**************************************************************************/ /**
30+ * @brief
31+ * Enable or disable LED0.
32+ *
33+ * @param[in] enabled
34+ * @li True - Enable LED0
35+ * @li False - Disable LED0.
36+ *****************************************************************************/
37+ void led0 (bool enabled )
38+ {
39+ if (enabled ) GPIO_PinOutSet (LED0_PORT , LED0_PIN );
40+ else GPIO_PinOutClear (LED0_PORT , LED0_PIN );
2641}
2742
2843
@@ -44,14 +59,14 @@ void Error (uint8_t number)
4459 dbcritInt (">>> Error (" , number , ")! Please reset MCU. <<<" , false);
4560#endif /* DEBUGGING */
4661
47- GPIO_PinOutClear (gpioPortF , 4 ); /* Disable LED0 */
48- GPIO_PinOutSet (gpioPortF , 5 ); /* Enable LED1 */
62+ GPIO_PinOutClear (LED0_PORT , LED0_PIN ); /* Disable LED0 */
63+ GPIO_PinOutSet (LED1_PORT , LED1_PIN ); /* Enable LED1 */
4964
5065 while (1 )
5166 {
5267 Delay (100 );
53- GPIO_PinOutToggle (gpioPortF , 4 ); /* Toggle LED0 */
54- GPIO_PinOutToggle (gpioPortF , 5 ); /* Toggle LED1 */
68+ GPIO_PinOutToggle (LED0_PORT , LED0_PIN ); /* Toggle LED0 */
69+ GPIO_PinOutToggle (LED1_PORT , LED1_PIN ); /* Toggle LED1 */
5570 }
5671}
5772
@@ -83,27 +98,19 @@ void Delay (uint32_t dlyTicks)
8398
8499/**************************************************************************/ /**
85100 * @brief
86- * Disable SysTick interrupt and counter by clearing their bits.
101+ * Disable
87102 *
88103 * @note
89104 * SysTick interrupt and counter (used by Delay) need to
90105 * be disabled before going to EM2.
91- *****************************************************************************/
92- void disableSystick (void )
93- {
94- SysTick -> CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk ;
95- }
96-
97-
98- /**************************************************************************/ /**
99- * @brief
100- * Enable SysTick interrupt and counter by setting their bits.
101106 *
102- * @note
103- * SysTick interrupt and counter (used by Delay) need to
104- * be enabled after waking up from EM2 .
107+ * @param[in] enabled
108+ * @li True - Enable SysTick interrupt and counter by setting their bits.
109+ * @li False - Disable SysTick interrupt and counter by clearing their bits .
105110 *****************************************************************************/
106- void enableSystick ( void )
111+ void systickInterrupts ( bool enabled )
107112{
108- SysTick -> CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk ;
113+ if (enabled ) SysTick -> CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk ;
114+ else SysTick -> CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk ;
109115}
116+
0 commit comments