stm: pull-up usr switch on pyboard (fixes regression).

This commit is contained in:
Damien George 2014-01-05 23:49:34 +00:00
parent 568a6c9d79
commit 6b0b4a0cad
2 changed files with 28 additions and 25 deletions

View File

@ -8,10 +8,10 @@
#include "led.h" #include "led.h"
/* LED numbers, used internally */ /* LED numbers, used internally */
#define PYB_LED_1 (1) #define PYB_LED_1 (0)
#define PYB_LED_2 (2) #define PYB_LED_2 (1)
#define PYB_LED_3 (3) #define PYB_LED_3 (2)
#define PYB_LED_4 (4) #define PYB_LED_4 (3)
#if defined(PYBOARD) #if defined(PYBOARD)
#define PYB_LED1_PORT (GPIOA) #define PYB_LED1_PORT (GPIOA)
@ -86,22 +86,22 @@ void led_state(pyb_led_t led, int state) {
switch (led) { switch (led) {
case PYB_LED_1: case PYB_LED_1:
pin = PYB_LED1_PIN; pin = PYB_LED1_PIN;
port = PYB_LED1_PORT; port = PYB_LED1_PORT;
break; break;
case PYB_LED_2: case PYB_LED_2:
pin = PYB_LED2_PIN; pin = PYB_LED2_PIN;
port = PYB_LED2_PORT; port = PYB_LED2_PORT;
break; break;
case PYB_LED_3: case PYB_LED_3:
pin = PYB_LED3_PIN; pin = PYB_LED3_PIN;
port = PYB_LED3_PORT; port = PYB_LED3_PORT;
break; break;
case PYB_LED_4: case PYB_LED_4:
pin = PYB_LED4_PIN; pin = PYB_LED4_PIN;
port = PYB_LED4_PORT; port = PYB_LED4_PORT;
break; break;
default: default:
return; return;
} }
@ -120,27 +120,27 @@ void led_toggle(pyb_led_t led) {
switch (led) { switch (led) {
case PYB_LED_1: case PYB_LED_1:
pin = PYB_LED1_PIN; pin = PYB_LED1_PIN;
port = PYB_LED1_PORT; port = PYB_LED1_PORT;
break; break;
case PYB_LED_2: case PYB_LED_2:
pin = PYB_LED2_PIN; pin = PYB_LED2_PIN;
port = PYB_LED2_PORT; port = PYB_LED2_PORT;
break; break;
case PYB_LED_3: case PYB_LED_3:
pin = PYB_LED3_PIN; pin = PYB_LED3_PIN;
port = PYB_LED3_PORT; port = PYB_LED3_PORT;
break; break;
case PYB_LED_4: case PYB_LED_4:
pin = PYB_LED4_PIN; pin = PYB_LED4_PIN;
port = PYB_LED4_PORT; port = PYB_LED4_PORT;
break; break;
default: default:
return; return;
} }
if (!(port->ODR & pin)) { if (!(port->ODR & pin)) {
// turn LED off // turn LED off
PYB_LED_OFF(port, pin); PYB_LED_OFF(port, pin);
} else { } else {
// turn LED on (output low) // turn LED on (output low)

View File

@ -12,6 +12,7 @@
#if defined (PYBOARD) #if defined (PYBOARD)
#define USRSW_PORT (GPIOA) #define USRSW_PORT (GPIOA)
#define USRSW_PIN (GPIO_Pin_13) #define USRSW_PIN (GPIO_Pin_13)
#define USRSW_PUPD (GPIO_PuPd_UP)
#define USRSW_EXTI_PIN (EXTI_PinSource13) #define USRSW_EXTI_PIN (EXTI_PinSource13)
#define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA) #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA)
#define USRSW_EXTI_LINE (EXTI_Line13) #define USRSW_EXTI_LINE (EXTI_Line13)
@ -20,18 +21,20 @@
#elif defined (STM32F4DISC) #elif defined (STM32F4DISC)
#define USRSW_PORT (GPIOA) #define USRSW_PORT (GPIOA)
#define USRSW_PIN (GPIO_Pin_0) #define USRSW_PIN (GPIO_Pin_0)
#define USRSW_PUPD (GPIO_PuPd_NOPULL)
#define USRSW_EXTI_PIN (EXTI_PinSource0) #define USRSW_EXTI_PIN (EXTI_PinSource0)
#define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA) #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA)
#define USRSW_EXTI_LINE (EXTI_Line0) #define USRSW_EXTI_LINE (EXTI_Line0)
#define USRSW_EXTI_IRQN (EXTI0_IRQn) #define USRSW_EXTI_IRQN (EXTI0_IRQn)
#define USRSW_EXTI_EDGE (EXTI_Trigger_Falling) #define USRSW_EXTI_EDGE (EXTI_Trigger_Falling)
#endif #endif
void switch_init(void) { void switch_init(void) {
// make it an input with pull-up // make it an input with pull-up
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = USRSW_PIN; GPIO_InitStructure.GPIO_Pin = USRSW_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* allow external pull up/down */ GPIO_InitStructure.GPIO_PuPd = USRSW_PUPD;
GPIO_Init(USRSW_PORT, &GPIO_InitStructure); GPIO_Init(USRSW_PORT, &GPIO_InitStructure);
// the rest does the EXTI interrupt // the rest does the EXTI interrupt