From 129f398bacc59c4e221d3f9ad12be856d69de055 Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 8 May 2023 12:45:02 +0200 Subject: [PATCH] buttons WIP --- .gdbinit | 2 +- openocd.cfg | 7 ------- src/main.c | 20 +++++++++++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) delete mode 100644 openocd.cfg diff --git a/.gdbinit b/.gdbinit index 7ca5b21..d332826 100644 --- a/.gdbinit +++ b/.gdbinit @@ -1,5 +1,5 @@ -target remote localhost:3333 +#target extended-remote localhost:3333 set print pretty on set print elements 512 diff --git a/openocd.cfg b/openocd.cfg deleted file mode 100644 index 46a78cc..0000000 --- a/openocd.cfg +++ /dev/null @@ -1,7 +0,0 @@ -gdb_port 3333 - -source [find interface/stlink.cfg] -source [find target/stm32f0x.cfg] - -init -arm semihosting enable diff --git a/src/main.c b/src/main.c index 4fbc630..52d7e13 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,16 @@ #include +int bt_inputs() { + bool bt0 = !!(GPIOB->IDR & (1<<2)); + bool bt1 = !!(GPIOB->IDR & (1<<1)); + bool bt2 = !!(GPIOB->IDR & (1<<0)); + bool bt3 = !!(GPIOB->IDR & (1<<12)); + bool bt4 = !!(GPIOB->IDR & (1<<4)); + bool bt5 = !!(GPIOA->IDR & (1<<15)); + return (bt5<<5) | (bt4<<4) | (bt3<<3) | (bt2<<2) | (bt1<<1) | (bt0<<0); +} + int main(void) { /* Enable HSE w/ 8 MHz crystal */ /* FIXME */ @@ -55,6 +65,8 @@ int main(void) { #define IN(pin) (0) #define ANALOG(pin) (3<<(2*(pin))) #define CLEAR(pin) (3<<(2*(pin))) +#define PULLUP(pin) (1<<(2*pin)) +#define PULLDOWN(pin) (2<<(2*pin)) /* GPIOA: * 0 - !ADC_DRDY @@ -96,6 +108,7 @@ int main(void) { (3<PUPDR |= PULLUP(15); /* BT5 */ GPIOA->BSRR = (1<<1) | (1<<2); /* ADC ~SYNC, ~CS */ /* GPIOB: @@ -137,6 +150,11 @@ int main(void) { (3<PUPDR |= PULLUP(0) | /* BT2 */ + PULLUP(1) | /* BT1 */ + PULLUP(2) | /* BT0 */ + PULLUP(3) | /* BT4 */ + PULLUP(12); /* BT3 */ /* GPIOC: * PC13 - DFU button @@ -182,7 +200,7 @@ int main(void) { st_led.led[i].g += 2; st_led.led[i].b += 3; } - for (size_t i=0; i<100000; i++) { + for (size_t i=0; i<3000000; i++) { asm volatile ("nop"); } }