Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/stm32f103/bluepill/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@
#endif

#ifndef HAVE_BUTTON
#define HAVE_BUTTON 0
#define HAVE_BUTTON 1
#endif
#ifndef BUTTON_ACTIVE_HIGH
#define BUTTON_ACTIVE_HIGH 1
#endif
#ifndef BUTTON_GPIO_PORT
#define BUTTON_GPIO_PORT GPIOB
#endif
#ifndef BUTTON_GPIO_PIN
#define BUTTON_GPIO_PIN GPIO2
#endif
// Blue-Pull has 100k resistors on PB2, so we can't use weak pulls to read it.
#ifndef BUTTON_USES_PULL
#define BUTTON_USES_PULL 0
#endif

#ifndef BUTTON_SAMPLE_DELAY_CYCLES
Expand All @@ -60,6 +73,10 @@
#define HAVE_USB_PULLUP_CONTROL 0
#endif

#ifndef USES_GPIOB
#define USES_GPIOB 1
#endif

#ifndef USES_GPIOC
#define USES_GPIOC 1
#endif
Expand Down
17 changes: 12 additions & 5 deletions src/stm32f103/target_stm32f103.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#define USES_GPIOC 0
#endif

#ifndef BUTTON_USES_PULL
#define BUTTON_USES_PULL 1
#endif

#ifdef FLASH_SIZE_OVERRIDE
_Static_assert((FLASH_BASE + FLASH_SIZE_OVERRIDE >= APP_BASE_ADDRESS),
"Incompatible flash size");
Expand Down Expand Up @@ -95,12 +99,15 @@ void target_gpio_setup(void) {
#if HAVE_BUTTON
{
const uint8_t mode = GPIO_MODE_INPUT;
const uint8_t conf = GPIO_CNF_INPUT_PULL_UPDOWN;
const uint8_t conf = (BUTTON_USES_PULL ? GPIO_CNF_INPUT_PULL_UPDOWN
: GPIO_CNF_INPUT_FLOAT);
gpio_set_mode(BUTTON_GPIO_PORT, mode, conf, BUTTON_GPIO_PIN);
if (BUTTON_ACTIVE_HIGH) {
gpio_clear(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN);
} else {
gpio_set(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN);
if (BUTTON_USES_PULL) {
if (BUTTON_ACTIVE_HIGH) {
gpio_clear(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN);
} else {
gpio_set(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN);
}
}
}
#endif
Expand Down