global: remove BV specific LEDs functions
This commit is contained in:
parent
fa3293a1f9
commit
accb5fd95b
|
@ -86,10 +86,9 @@ void main(void)
|
|||
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // start main clock
|
||||
board_setup(); // setup board to control LED
|
||||
#if defined(BUSVOODOO)
|
||||
led_red(); // switch red LED to indicate bootloader started
|
||||
#else
|
||||
led_on(); // indicate bootloader started
|
||||
#if defined(BUSVOODOO)
|
||||
led_toggle(); // switch from blue to red LED
|
||||
#endif
|
||||
usb_dfu_setup(); // setup USB DFU for firmware upload
|
||||
usb_dfu_start(); // run DFU mode
|
||||
|
|
59
global.c
59
global.c
|
@ -28,7 +28,6 @@
|
|||
#include <libopencm3/cm3/systick.h> // SysTick library
|
||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||
#include <libopencm3/stm32/gpio.h> // general purpose input output library
|
||||
#include <libopencm3/stm32/timer.h> // timer library
|
||||
#include <libopencm3/stm32/exti.h> // external interrupt defines
|
||||
|
||||
#include "global.h" // common methods
|
||||
|
@ -68,8 +67,7 @@ char* b2s(uint64_t binary, uint8_t rjust)
|
|||
void led_on(void)
|
||||
{
|
||||
#if defined(BUSVOODOO)
|
||||
timer_disable_counter(TIM1); // disable timer for PWM
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to 'output push-pull'
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin push-pull
|
||||
#endif
|
||||
#if defined(LED_ON) && LED_ON
|
||||
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
|
||||
|
@ -82,8 +80,7 @@ void led_on(void)
|
|||
void led_off(void)
|
||||
{
|
||||
#if defined(BUSVOODOO)
|
||||
timer_disable_counter(TIM1); // disable timer for PWM
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(LED_PIN)); // set LED pin to 'output push-pull'
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(LED_PIN)); // set LED pin to floating to disable LEDs
|
||||
#else
|
||||
#if defined(LED_ON) && LED_ON
|
||||
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
|
||||
|
@ -97,50 +94,11 @@ void led_off(void)
|
|||
void led_toggle(void)
|
||||
{
|
||||
#if defined(BUSVOODOO)
|
||||
timer_disable_counter(TIM1); // disable timer for PWM
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to 'output push-pull'
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to push-pull
|
||||
#endif
|
||||
gpio_toggle(GPIO(LED_PORT), GPIO(LED_PIN));
|
||||
}
|
||||
|
||||
#if defined(BUSVOODOO)
|
||||
void led_blink(double period, double duty)
|
||||
{
|
||||
if (period<0.0 || period>6.0 || duty<0.0 || duty>1.0) { // input argument out of bounds
|
||||
return; // do nothing
|
||||
}
|
||||
timer_disable_counter(TIM1); // disable timer for PWM before resetting it
|
||||
if (0.0==period) { // no blinking
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin as normal output
|
||||
if (duty>0.5) { // LED should be on
|
||||
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN)); // switch LED on
|
||||
} else { // LED should be off
|
||||
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN)); // switch LED off
|
||||
}
|
||||
} else {
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO(LED_PIN)); // set LED pin to alternate function for PWM
|
||||
timer_set_counter(TIM1, 0); // reset counter
|
||||
timer_set_period(TIM1, 0xffff*(period/6.0)); // set period
|
||||
timer_set_oc_value(TIM1, TIM_OC1, 0xffff*(period/6.0)*duty); // PWM duty cycle
|
||||
timer_enable_counter(TIM1); // enable timer to start blinking
|
||||
}
|
||||
}
|
||||
|
||||
void led_blue(void)
|
||||
{
|
||||
timer_disable_counter(TIM1); // disable timer for PWM
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to 'output push-pull'
|
||||
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
|
||||
}
|
||||
|
||||
void led_red(void)
|
||||
{
|
||||
timer_disable_counter(TIM1); // disable timer for PWM
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to 'output push-pull'
|
||||
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
|
||||
}
|
||||
#endif
|
||||
|
||||
void sleep_us(uint32_t duration)
|
||||
{
|
||||
systick_counter_disable(); // disable SysTick to reconfigure it
|
||||
|
@ -213,16 +171,9 @@ void board_setup(void)
|
|||
// setup LED
|
||||
rcc_periph_clock_enable(RCC_GPIO(LED_PORT)); // enable clock for LED
|
||||
#if defined(BUSVOODOO)
|
||||
// LED is connected to TIM1_CH1, allowing to used the PWM output so to display patterns
|
||||
rcc_periph_clock_enable(RCC_TIM1); // enable clock for timer domain
|
||||
timer_reset(TIM1); // reset timer configuration
|
||||
timer_set_mode(TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_CENTER_1, TIM_CR1_DIR_UP); // configure timer to up counting mode (center aligned for more precise duty cycle control)
|
||||
timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1); // use PWM output compare mode
|
||||
timer_enable_oc_output(TIM1, TIM_OC1); // enable output compare output
|
||||
timer_enable_break_main_output(TIM1); // required to enable timer, even when no dead time is used
|
||||
timer_set_prescaler(TIM1, 3296-1); // set prescaler to allow 3/3 seconds PWM output (72MHz/2^16/3296=0.33Hz)
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(LED_PIN)); // set LED pin to floating to disable LEDs
|
||||
#else
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to 'output push-pull'
|
||||
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to output push-pull do drive LED
|
||||
#endif
|
||||
led_off(); // switch off LED per default
|
||||
|
||||
|
|
15
global.h
15
global.h
|
@ -357,7 +357,7 @@
|
|||
#if defined(SYSTEM_BOARD) || defined(CORE_BOARD)
|
||||
/* on system and core board LED is on pin 11/PA1 */
|
||||
#define LED_PORT A /**< GPIO port (port A) */
|
||||
#define LED_PIN 1 /**< GPIO pin (pin PA1) */
|
||||
#define LED_PIN 1 /**< GPIO pin (pin PA1) */
|
||||
#define LED_ON 0 /**< LED is on when pin is low */
|
||||
#elif defined(BLUE_PILL)
|
||||
/* on minimum system LED is on pin 2/PC13 */
|
||||
|
@ -373,7 +373,7 @@
|
|||
/* on BusVoodoo LED is on pin PA8 */
|
||||
#define LED_PORT A /**< GPIO port (port A) */
|
||||
#define LED_PIN 8 /**< GPIO pin (pin PA8) */
|
||||
#define LED_ON 1 /**< LED is on when pin is high */
|
||||
#define LED_ON 1 /**< blue LED is on when pin is high, red LED is on when pin is low, LED is off when LED is floating */
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
|
@ -448,17 +448,6 @@ void led_on(void);
|
|||
void led_off(void);
|
||||
/** toggle board LED */
|
||||
void led_toggle(void);
|
||||
#if defined(BUSVOODOO)
|
||||
/** set LED blinking pattern
|
||||
* @param[in] period blue+red pattern duration in seconds (up to 3+3)
|
||||
* @param[in] duty blue LED on duty cycle, before switching to red (0-1)
|
||||
*/
|
||||
void led_blink(double period, double duty);
|
||||
/** switch on blue LED */
|
||||
void led_blue(void);
|
||||
/** switch on red LED */
|
||||
void led_red(void);
|
||||
#endif
|
||||
/** go to sleep for some microseconds
|
||||
* @param[in] duration sleep duration in us
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue