Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
dev_led.c
Go to the documentation of this file.
1/*
2 * @ingroup version-information
3 * @file dev_led.c
4 * @details <b>Description</b><br>This file has all the logic for led blinkys.
5 * @author M70027
6 * @author M70027
7 * @version 1.0
8 * @date 2024
9 * @warning Improper use can crash your application.
10 * @copyright
11 */
12
13/*
14 (c) 2024 Microchip Technology Inc. and its subsidiaries. You may use this
15 software and any derivatives exclusively with Microchip products.
16
17 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
18 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
19 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
20 PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
21 WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
22
23 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
24 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
25 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
26 BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
27 FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
28 ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
29 THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
30
31 MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
32 TERMS.
33 */
34
35
41#include "xc.h"
42#include "dev_led.h"
43#include "system/pins.h"
44
45
51#define LED_STATE_OFF 0
52#define LED_STATE_ON 1
53#define LED_STATE_BLINK 2
54#define LED_STATE_BLINK_SLOW 3
55#define LED_STATE_BLINK_FAST 4
56#define LED_STATE_BLINK_COUNT 5
57
// end of dev-led-enums-private
59
60
65
66
68
79{
80 //Peripherals are initialized by MCC
84}
85
86
94void Dev_LED_On(uint8_t led_id)
95{
96 if (led_id >= NUM_OF_LEDS)
97 return;
98 if (ledStates[led_id] == LED_STATE_ON)
99 return;
100 ledStates[led_id] = LED_STATE_ON;
101 switch(led_id)
102 {
103 case LED_PIM_RED: LED_DP_PIM_on(); break;
104 case LED_BOARD_RED: LED_Board_Red_On(); break;
105 case LED_BOARD_GREEN: LED_Board_Green_On(); break;
106 default: Nop(); break;
107 }
108}
109
110
118void Dev_LED_Off(uint8_t led_id)
119{
120 if (led_id >= NUM_OF_LEDS)
121 return;
122 if (ledStates[led_id] == LED_STATE_OFF)
123 return;
124 ledStates[led_id] = LED_STATE_OFF;
125 switch(led_id)
126 {
127 case LED_PIM_RED: LED_DP_PIM_off(); break;
128 case LED_BOARD_RED: LED_Board_Red_Off(); break;
130 default: Nop(); break;
131 }
132}
133
134
142void Dev_LED_Toggle(uint8_t led_id)
143{
144 switch(led_id)
145 {
149 default: Nop(); break;
150 }
151}
152
153
161void Dev_LED_Blink(uint8_t led_id)
162{
163 if (led_id >= NUM_OF_LEDS)
164 return;
165 ledStates[led_id] = LED_STATE_BLINK;
166}
167
168
176void Dev_LED_Blink_Iter(uint8_t led_id, uint8_t count)
177{
178 if (led_id >= NUM_OF_LEDS)
179 return;
181 ledIterationsCounter[led_id] = count;
182}
183
184
192void Dev_LED_Blink_Slow(uint8_t led_id)
193{
194 if (led_id >= NUM_OF_LEDS)
195 return;
197}
198
199
207void Dev_LED_Blink_Fast(uint8_t led_id)
208{
209 if (led_id >= NUM_OF_LEDS)
210 return;
212}
213
214
225{
226 uint8_t led_index=0;
227 uint8_t timermax=0;
228
229 for (led_index = 0; led_index < NUM_OF_LEDS; led_index++)
230 {
231 if (ledStates[led_index] > LED_STATE_ON)
232 {
233 if (ledStates[led_index] == LED_STATE_BLINK_SLOW)
234 timermax = BLINK_SLOW_INTERVAL;
235 else if (ledStates[led_index] == LED_STATE_BLINK_FAST)
236 timermax = BLINK_FAST_INTERVAL;
237 else // normal speed
238 timermax = BLINK_INTERVAL;
239 if (++ledTimer[led_index] >= timermax)
240 {
241 ledTimer[led_index] = 0;
242 switch(led_index)
243 {
247 default: Nop(); break;
248 }
249 }
250 }
251 }
252}
uint8_t ledTimer[NUM_OF_LEDS]
array that stores led blink times
Definition dev_led.c:64
uint8_t ledIterationsCounter[NUM_OF_LEDS]
Definition dev_led.c:67
uint8_t ledStates[NUM_OF_LEDS]
array that stores the led states
Definition dev_led.c:63
led device driver
#define NUM_OF_LEDS
Definition dev_led.h:31
#define LED_BOARD_GREEN
Definition dev_led.h:62
#define LED_PIM_RED
enumerating away
Definition dev_led.h:60
#define LED_DP_PIM_Toggle_State
Definition dev_led.h:51
#define LED_Board_Red_On
abstracting away led mcc function calls.
Definition dev_led.h:41
#define BLINK_SLOW_INTERVAL
Definition dev_led.h:66
#define LED_DP_PIM_off
Definition dev_led.h:50
#define BLINK_FAST_INTERVAL
Definition dev_led.h:67
#define LED_Board_Green_On
Definition dev_led.h:45
#define LED_DP_PIM_on
Definition dev_led.h:49
#define LED_Board_Green_Off
Definition dev_led.h:46
#define LED_Board_Green_Toggle_State
Definition dev_led.h:47
#define LED_Board_Red_Toggle_State
Definition dev_led.h:43
#define BLINK_INTERVAL
Definition dev_led.h:68
#define LED_BOARD_RED
Definition dev_led.h:61
#define LED_Board_Red_Off
Definition dev_led.h:42
#define LED_STATE_ON
Definition dev_led.c:52
#define LED_STATE_BLINK_FAST
Definition dev_led.c:55
void Dev_LED_Initialize(void)
This function contains the LED initialization.
Definition dev_led.c:78
void Dev_LED_Blink_Slow(uint8_t led_id)
Set the LED in SLOW blinking mode.
Definition dev_led.c:192
void Dev_LED_Off(uint8_t led_id)
Switch off the LED.
Definition dev_led.c:118
void Dev_LED_On(uint8_t led_id)
Switch on the LED.
Definition dev_led.c:94
#define LED_STATE_OFF
These are the macros indicating the status of the LED.
Definition dev_led.c:51
void Dev_LED_Blink_Fast(uint8_t led_id)
Set the LED in FAST blinking mode.
Definition dev_led.c:207
#define LED_STATE_BLINK_COUNT
Definition dev_led.c:56
void Dev_LED_Blink_Iter(uint8_t led_id, uint8_t count)
Set the LED in blinking mode in number of LED iterations.
Definition dev_led.c:176
#define LED_STATE_BLINK_SLOW
Definition dev_led.c:54
void Dev_LED_Toggle(uint8_t led_id)
Toggles the LED state.
Definition dev_led.c:142
void Dev_LED_Task_100ms()
This function needs to be called every 100ms and contains the code to update the status of the LEDs.
Definition dev_led.c:224
#define LED_STATE_BLINK
Definition dev_led.c:53
void Dev_LED_Blink(uint8_t led_id)
Set the LED in blinking mode.
Definition dev_led.c:161