X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=example%2Fblink%2Fmain.c;h=0a38069be301c930f6751a393cf60196f0587237;hb=83a5eb2ed34ed78edacd92a69f366b89728ac5d0;hp=73fd41bd9c1ad61f124d655eb002ef9d0b6ada7e;hpb=5e1e150d5cced4770aae0f8e053c99d7d6a0d39c;p=fw%2Fstlink diff --git a/example/blink/main.c b/example/blink/main.c index 73fd41b..0a38069 100644 --- a/example/blink/main.c +++ b/example/blink/main.c @@ -7,36 +7,30 @@ typedef unsigned int uint32_t; #if CONFIG_STM32VL_DISCOVERY -# define GPIOC 0x40011000 /* port C */ -# define GPIOC_CRH (GPIOC + 0x04) /* port configuration register high */ -# define GPIOC_ODR (GPIOC + 0x0c) /* port output data register */ +#define GPIOC 0x40011000 /* port C */ +#define GPIOC_CRH (GPIOC + 0x04) /* port configuration register high */ +#define LED_PORT_ODR (GPIOC + 0x0c) /* port output data register */ -# define LED_BLUE (1 << 8) /* port C, pin 8 */ -# define LED_GREEN (1 << 9) /* port C, pin 9 */ +#define LED_BLUE (1 << 8) /* port C, pin 8 */ +#define LED_GREEN (1 << 9) /* port C, pin 9 */ +#define LED_ORANGE 0 +#define LED_RED 0 static inline void setup_leds(void) { *(volatile uint32_t*)GPIOC_CRH = 0x44444411; } -static inline void switch_leds_on(void) -{ - *(volatile uint32_t*)GPIOC_ODR = LED_BLUE | LED_GREEN; -} - -static inline void switch_leds_off(void) -{ - *(volatile uint32_t*)GPIOC_ODR = 0; -} - #elif CONFIG_STM32L_DISCOVERY -# define GPIOB 0x40020400 /* port B */ -# define GPIOB_MODER (GPIOB + 0x00) /* port mode register */ -# define GPIOB_ODR (GPIOB + 0x14) /* port output data register */ +#define GPIOB 0x40020400 /* port B */ +#define GPIOB_MODER (GPIOB + 0x00) /* port mode register */ +#define LED_PORT_ODR (GPIOB + 0x14) /* port output data register */ -# define LED_BLUE (1 << 6) /* port B, pin 6 */ -# define LED_GREEN (1 << 7) /* port B, pin 7 */ +#define LED_BLUE (1 << 6) /* port B, pin 6 */ +#define LED_GREEN (1 << 7) /* port B, pin 7 */ +#define LED_ORANGE 0 +#define LED_RED 0 static inline void setup_leds(void) { @@ -44,26 +38,16 @@ static inline void setup_leds(void) *(volatile uint32_t*)GPIOB_MODER |= (1 << (7 * 2)) | (1 << (6 * 2)); } -static inline void switch_leds_on(void) -{ - *(volatile uint32_t*)GPIOB_ODR = LED_BLUE | LED_GREEN; -} - -static inline void switch_leds_off(void) -{ - *(volatile uint32_t*)GPIOB_ODR = 0; -} - #elif CONFIG_STM32F4_DISCOVERY #define GPIOD 0x40020C00 /* port D */ -# define GPIOD_MODER (GPIOD + 0x00) /* port mode register */ -# define GPIOD_ODR (GPIOD + 0x14) /* port output data register */ +#define GPIOD_MODER (GPIOD + 0x00) /* port mode register */ +#define LED_PORT_ODR (GPIOD + 0x14) /* port output data register */ -# define LED_GREEN (1 << 12) /* port B, pin 12 */ -# define LED_ORANGE (1 << 13) /* port B, pin 13 */ -# define LED_RED (1 << 14) /* port B, pin 14 */ -# define LED_BLUE (1 << 15) /* port B, pin 15 */ +#define LED_GREEN (1 << 12) /* port D, pin 12 */ +#define LED_ORANGE (1 << 13) /* port D, pin 13 */ +#define LED_RED (1 << 14) /* port D, pin 14 */ +#define LED_BLUE (1 << 15) /* port D, pin 15 */ void _tmain(void) { main(); @@ -74,22 +58,20 @@ static inline void setup_leds(void) (1 << (13 * 2)) | (1 << (14 * 2)) | (1 << (15 * 2)); } +#else +#error "Architecture must be defined!" +#endif /* otherwise, error */ static inline void switch_leds_on(void) { - *(volatile uint32_t*)GPIOD_ODR = LED_GREEN | LED_RED ; + *(volatile uint32_t*)LED_PORT_ODR = LED_BLUE | LED_GREEN | LED_ORANGE | LED_RED; } static inline void switch_leds_off(void) { - *(volatile uint32_t*)GPIOD_ODR = 0; + *(volatile uint32_t*)LED_PORT_ODR = 0; } -#else -#error "Architecture must be defined!" -#endif /* otherwise, error */ - - #define delay() \ do { \ register unsigned int i; \