File tree Expand file tree Collapse file tree 4 files changed +29
-27
lines changed Expand file tree Collapse file tree 4 files changed +29
-27
lines changed Original file line number Diff line number Diff line change 1919
2020#include "board_driver_led.h"
2121
22+ volatile uint8_t ledKeepValue = 0 ;
23+ volatile uint8_t ledTargetValue = 20 ;
24+ volatile int8_t ledDirection = 1 ;
2225
26+ inline void LED_pulse ()
27+ {
28+ if (ledKeepValue == 0 ) {
29+ ledTargetValue += ledDirection ;
30+ LED_toggle ();
31+ }
32+ ledKeepValue ++ ;
33+
34+ if (ledTargetValue > 240 || ledTargetValue < 10 ) {
35+ ledDirection = - ledDirection ;
36+ ledTargetValue += ledDirection ;
37+ }
38+
39+ if (ledKeepValue == ledTargetValue ) {
40+ LED_toggle ();
41+ }
42+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ inline void LED_init(void) { PORT->Group[BOARD_LED_PORT].DIRSET.reg = (1<<BOARD_
2727inline void LED_on (void ) { PORT -> Group [BOARD_LED_PORT ].OUTSET .reg = (1 <<BOARD_LED_PIN ); }
2828inline void LED_off (void ) { PORT -> Group [BOARD_LED_PORT ].OUTCLR .reg = (1 <<BOARD_LED_PIN ); }
2929inline void LED_toggle (void ) { PORT -> Group [BOARD_LED_PORT ].OUTTGL .reg = (1 <<BOARD_LED_PIN ); }
30+ void LED_pulse ();
3031
3132inline void LEDRX_init (void ) { PORT -> Group [BOARD_LEDRX_PORT ].DIRSET .reg = (1 <<BOARD_LEDRX_PIN ); }
3233inline void LEDRX_on (void ) { PORT -> Group [BOARD_LEDRX_PORT ].OUTCLR .reg = (1 <<BOARD_LEDRX_PIN ); }
@@ -38,6 +39,4 @@ inline void LEDTX_on(void) { PORT->Group[BOARD_LEDTX_PORT].OUTCLR.reg = (1<<BOAR
3839inline void LEDTX_off (void ) { PORT -> Group [BOARD_LEDTX_PORT ].OUTSET .reg = (1 <<BOARD_LEDTX_PIN ); }
3940inline void LEDTX_toggle (void ) { PORT -> Group [BOARD_LEDTX_PORT ].OUTTGL .reg = (1 <<BOARD_LEDTX_PIN ); }
4041
41- inline void LED_configure (uint32_t sampleRate ) { SysTick_Config (sampleRate ); }
42-
4342#endif // _BOARD_DRIVER_LED_
Original file line number Diff line number Diff line change 1818*/
1919
2020#include <sam.h>
21- #include "board_driver_led.h"
2221
2322struct ConstVectors
2423{
@@ -140,26 +139,3 @@ void PendSV_Handler(void)
140139 __BKPT (2 );
141140 while (1 );
142141}
143-
144- volatile uint8_t keepValue = 0 ;
145- volatile uint8_t targetValue = 20 ;
146- volatile int8_t direction = 1 ;
147-
148- void SysTick_Handler (void )
149- {
150- if (keepValue == 0 ) {
151- targetValue += direction ;
152- LED_toggle ();
153- }
154- keepValue ++ ;
155-
156- if (targetValue > 240 || targetValue < 10 ) {
157- direction = - direction ;
158- targetValue += direction ;
159- }
160-
161- if (keepValue == targetValue ) {
162- LED_toggle ();
163- }
164- //TC5->COUNT16.INTFLAG.bit.MC0 = 1; // Clear interrupt
165- }
Original file line number Diff line number Diff line change @@ -181,12 +181,14 @@ int main(void)
181181
182182 /* Initialize LEDs */
183183 LED_init ();
184- LED_configure (1000 );
185184 LEDRX_init ();
186185 LEDRX_off ();
187186 LEDTX_init ();
188187 LEDTX_off ();
189188
189+ /* Start the sys tick (1 ms) */
190+ SysTick_Config (1000 );
191+
190192 /* Wait for a complete enum on usb or a '#' char on serial line */
191193 while (1 )
192194 {
@@ -222,3 +224,8 @@ int main(void)
222224#endif
223225 }
224226}
227+
228+ void SysTick_Handler (void )
229+ {
230+ LED_pulse ();
231+ }
You can’t perform that action at this time.
0 commit comments