From 3682d10a279f2d2228d72ad54e501d3eedf52884 Mon Sep 17 00:00:00 2001 From: Steins7 Date: Tue, 4 Feb 2020 19:50:01 +0100 Subject: [PATCH] Got external interrupts to work * fixed io driver * fixed encoder 3D print --- cad/encoder.scad | 6 ++--- src/config.h | 65 ++---------------------------------------------- src/drivers/io.c | 10 ++------ src/main.c | 4 +-- 4 files changed, 9 insertions(+), 76 deletions(-) diff --git a/cad/encoder.scad b/cad/encoder.scad index 76ae1a3..c65a830 100644 --- a/cad/encoder.scad +++ b/cad/encoder.scad @@ -1,4 +1,4 @@ -//$fn = 100; +$fn = 100; r = 12; h = 12; @@ -25,9 +25,9 @@ difference() { cube([3,2*center_r,h], center=true); } difference() { - translate([0,0,0.7]) + translate([0,0,3]) cylinder(h=h, r=0.8*r, center=true); - translate([0,0,0.7]) + translate([0,0,3]) cylinder(h=h, r=1.4*center_r, center=true); } diff --git a/src/config.h b/src/config.h index aa69fe6..5bd4f41 100644 --- a/src/config.h +++ b/src/config.h @@ -1,6 +1,5 @@ -/**************************************************************************** - * IRQ Priority - ****************************************************************************/ +//------------------------------------------------------------------------------ +/* priorities */ #define EXTI0_IRQ_PRIORITY 8 #define EXTI1_IRQ_PRIORITY 8 #define EXTI2_IRQ_PRIORITY 8 @@ -28,63 +27,3 @@ #define ADC1_2_IRQ_PRIORITY 5 -/**************************************************************************** - * USART Pin and use configuration - ****************************************************************************/ - -//#define USE_USART1 -//#define USART1_GPIO_PORT -//#define USART1_GPIO_PINS - -// USART2: Tx --> PA2, Rx --> PA3 -//#define USE_USART2 -//#define USART2_GPIO_PORT _GPIOA -//#define USART2_GPIO_PINS PIN_2|PIN_3 - -//#define USE_USART6 -//#define USART6_GPIO_PORT -//#define USART6_GPIO_PINS - -/**************************************************************************** - * I2C Pin and use configuration - ****************************************************************************/ - -// I2C1 : SCL --> PB8, SDA --> PB9 -//#define USE_I2C1 -//#define I2C1_GPIO_PORT _GPIOB -//#define I2C1_GPIO_PINS PIN_8|PIN_9 - -//#define USE_I2C2 -//#define I2C2_GPIO_PORT -//#define I2C2_GPIO_PINS - -//#define USE_I2C3 -//#define I2C3_GPIO_PORT -//#define I2C3_GPIO_PINS - -/**************************************************************************** - * SPI pin and use configuration - ****************************************************************************/ - -// SPI1 pins : LCD_SCK --> D13 --> PA5 : SPI1_SCK -// LCD_MOSI --> D11 --> PA7 : SPI1_MOSI -//#define USE_SPI1 -//#define SPI1_GPIO_PORT _GPIOA -//#define SPI1_GPIO_PINS PIN_5|PIN_7 - -//#define USE_SPI2 -//#define SPI2_GPIO_PORT -//#define SPI2_GPIO_PINS - -//#define USE_SPI3 -//#define SPI3_GPIO_PORT -//#define SPI3_GPIO_PINS - -//#define USE_SPI4 -//#define SPI4_GPIO_PORT -//#define SPI4_GPIO_PINS - -//#define USE_SPI5 -//#define SPI5_GPIO_PORT -//#define SPI5_GPIO_PINS - diff --git a/src/drivers/io.c b/src/drivers/io.c index 502002a..88ba5db 100644 --- a/src/drivers/io.c +++ b/src/drivers/io.c @@ -17,31 +17,26 @@ static OnIO io_cb[16]={ void EXTI0_IRQHandler() { if (io_cb[0]) (io_cb[0])(); - EXTI->PR = 1<<0; } void EXTI1_IRQHandler() { if (io_cb[1]) (io_cb[1])(); - EXTI->PR = 1<<1; } void EXTI2_IRQHandler() { if (io_cb[2]) (io_cb[2])(); - EXTI->PR = 1<<2; } void EXTI3_IRQHandler() { if (io_cb[3]) (io_cb[3])(); - EXTI->PR = 1<<3; } void EXTI4_IRQHandler() { if (io_cb[4]) (io_cb[4])(); - EXTI->PR = 1<<4; } @@ -143,9 +138,9 @@ int io_configure(GPIO_TypeDef *gpio, uint16_t pin, uint16_t pin_cfg, OnIO cb) { else if (gpio == GPIOE) port_mask = SYSCFG_EXTI_PE_MASK; // setup external IRQ lines - uint16_t afio_mask; + uint64_t afio_mask; for(int i=0; i<4; ++i) { - afio_mask = ((pin_mask & (0xFFFF << i)) >> i) * port_mask; + afio_mask = ((pin_mask & (0xFFFFll << (i*16))) >> (i*16)) * port_mask; if(afio_mask) AFIO->EXTICR[i] |= afio_mask; } @@ -204,7 +199,6 @@ int io_configure(GPIO_TypeDef *gpio, uint16_t pin, uint16_t pin_cfg, OnIO cb) { break; default: return -1; //impossible to get there - } } } diff --git a/src/main.c b/src/main.c index ce07d3b..5e5a928 100644 --- a/src/main.c +++ b/src/main.c @@ -84,8 +84,8 @@ int main(void) { //voltage = ((data*4) << 8)/4095; //temp = ((voltage - 0x73) << 8)/0x9; - uint32_t pin = io_read(GPIOB, PIN_8); - if(!pin) count = !count; + //uint32_t pin = io_read(GPIOB, PIN_8); + //if(!pin) count = !count; if(count) update_temp(T1, (int16_t)TIM4->CNT/2); // update T2