Simple test application for the STMicroelectronics X-NUCLEO-LED61A1 LED Control Expansion Board.
Dependencies: X_NUCLEO_LED61A1 mbed
Fork of HelloWorld_LED61A1 by
LED Control with the X-NUCLEO-LED61A1 Expansion Board
This application provides a simple example of usage of the X-NUCLEO-LED61A1 LED Control Expansion Board.
It shows how to control a LED stripe load connected to the board by means of a sinusoidal wave form injected into the PWM dimming control pin.
Diff: main.cpp
- Revision:
- 14:c1a43abb901f
- Parent:
- 13:97083451e538
- Child:
- 15:dd6dc0e07402
diff -r 97083451e538 -r c1a43abb901f main.cpp --- a/main.cpp Fri Mar 11 15:59:03 2016 +0000 +++ b/main.cpp Mon Mar 14 10:09:40 2016 +0000 @@ -50,17 +50,14 @@ /* PI. */ #ifndef M_PI - #define M_PI (3.14159265358979323846f) + #define M_PI (3.14159265358979323846f) #endif /* Loop period in micro-seconds. */ -#define LOOP_PERIOD_us (5E5) /* 0.5 seconds. */ +#define LOOP_PERIOD_us (5E5) /* 0.5 seconds. */ /* Sin period in micro-seconds. */ -#define PWM_SIN_PERIOD_us (1E7) /* 10 seconds. */ - -/* Duration of initialization interval in milli-seconds. */ -#define INITIALIZATION_INTERVAL_ms (2E3) /* 2 seconds. */ +#define PWM_SIN_PERIOD_us (1E7) /* 10 seconds. */ /* Variables -----------------------------------------------------------------*/ @@ -72,42 +69,13 @@ LED6001 *led; /* Interrupt flags. */ -static volatile bool ticker_irq_triggered; -static volatile bool xfault_irq_triggered; - -/* PWM dimming values. */ -static float pwm_dimming; +static volatile bool ticker_irq_triggered = false; +static volatile bool xfault_irq_triggered = false; /* Functions -----------------------------------------------------------------*/ /** - * @brief Initilizing the demo. - * @param None. - * @retval None. - */ -void LEDInit(void) -{ - /* Printing to the console. */ - printf("Initializing LED driver..."); - - /* Initializing Interrupt flags. */ - xfault_irq_triggered = false; - ticker_irq_triggered = false; - - /* Initializing PWM dimming to maximum values. */ - pwm_dimming = 1.0f; - - /* Start-up sequence. */ - led->PowerOFF(); - wait_ms(INITIALIZATION_INTERVAL_ms); - led->PowerON(); - - /* Printing to the console. */ - printf("Done.\r\n\n"); -} - -/** * @brief Handling the LED capabilities. * @param None. * @retval None. @@ -117,7 +85,7 @@ static int tick = 0; /* Handling the LED dimming when powered ON. */ - pwm_dimming = 0.5f * sin(2 * M_PI * (tick++ * LOOP_PERIOD_us) / PWM_SIN_PERIOD_us) + 0.5f; + float pwm_dimming = 0.5f * sin(2 * M_PI * (tick++ * LOOP_PERIOD_us) / PWM_SIN_PERIOD_us) + 0.5f; tick %= (int) (PWM_SIN_PERIOD_us / LOOP_PERIOD_us); /* Printing to the console. */ @@ -161,10 +129,13 @@ void XFaultHandler(void) { /* Printing to the console. */ - printf("XFAULT Interrupt detected! Re-initializing LED driver...\r\n"); + printf("XFAULT Interrupt detected! Re-initializing LED driver..."); - /* Re-initializing the demo. */ - LEDInit(); + /* Re-starting-up LED Control Component. */ + led->StartUp(); + + /* Printing to the console. */ + printf("Done.\r\n\n"); led->EnableXFaultIRQ(); } @@ -189,8 +160,8 @@ led->EnableXFaultIRQ(); ticker.attach_us(TickerIRQ, LOOP_PERIOD_us); - /* Initializing the demo. */ - LEDInit(); + /* Starting-up LED Control Component. */ + led->StartUp(); /*----- LED Control. -----*/