car_fmw: reuse STM evaluation board library code in car_led library
This commit is contained in:
+10
-37
@@ -5,54 +5,27 @@
|
|||||||
#include "stm32f4_discovery.h"
|
#include "stm32f4_discovery.h"
|
||||||
#include "stm32f4xx_conf.h"
|
#include "stm32f4xx_conf.h"
|
||||||
|
|
||||||
#define CAR_LED_GPIO_PORT_CLOCK RCC_AHB1Periph_GPIOD
|
|
||||||
#define CAR_LED_GPIO_PORT GPIOD
|
|
||||||
#define CAR_LED_PIN_GREEN GPIO_Pin_12
|
|
||||||
#define CAR_LED_PIN_ORANGE GPIO_Pin_13
|
|
||||||
#define CAR_LED_PIN_RED GPIO_Pin_14
|
|
||||||
#define CAR_LED_PIN_BLUE GPIO_Pin_15
|
|
||||||
|
|
||||||
inline void leds_init(void)
|
inline void leds_init(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
STM_EVAL_LEDInit(LED4);
|
||||||
RCC_AHB1PeriphClockCmd(CAR_LED_GPIO_PORT_CLOCK, ENABLE);
|
STM_EVAL_LEDInit(LED3);
|
||||||
GPIO_InitStructure.GPIO_Pin = CAR_LED_PIN_GREEN
|
STM_EVAL_LEDInit(LED5);
|
||||||
| CAR_LED_PIN_ORANGE
|
STM_EVAL_LEDInit(LED6);
|
||||||
| CAR_LED_PIN_RED
|
|
||||||
| CAR_LED_PIN_BLUE;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
||||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
|
||||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
|
||||||
GPIO_Init(CAR_LED_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
LED_GREEN,
|
LED_GREEN = LED4,
|
||||||
LED_ORANGE,
|
LED_ORANGE = LED3,
|
||||||
LED_RED,
|
LED_RED = LED5,
|
||||||
LED_BLUE
|
LED_BLUE = LED6
|
||||||
} led_t;
|
} led_t;
|
||||||
|
|
||||||
inline void led_set(led_t led, bool on)
|
inline void led_set(led_t led, bool on)
|
||||||
{
|
{
|
||||||
int led_pin = CAR_LED_PIN_GREEN;
|
|
||||||
switch(led) {
|
|
||||||
case LED_ORANGE:
|
|
||||||
led_pin = CAR_LED_PIN_ORANGE;
|
|
||||||
break;
|
|
||||||
case LED_RED:
|
|
||||||
led_pin = CAR_LED_PIN_RED;
|
|
||||||
break;
|
|
||||||
case LED_BLUE:
|
|
||||||
led_pin = CAR_LED_PIN_BLUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (on)
|
if (on)
|
||||||
GPIO_SetBits(CAR_LED_GPIO_PORT, led_pin);
|
STM_EVAL_LEDOn(led);
|
||||||
else
|
else
|
||||||
GPIO_ResetBits(CAR_LED_GPIO_PORT, led_pin);
|
STM_EVAL_LEDOff(led);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user