diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2015-03-29 22:05:36 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2015-03-29 22:05:36 +0200 |
commit | 16cc0f1414c33772dd6daa6c19d2be9dcaca2e64 (patch) | |
tree | 17b5f263f00a415b873d40188459b83940878a28 /gpio/gpio.h | |
parent | 49012588461f1a43e9e476f676d946d91c3df9e7 (diff) |
Added STM32F0 support.
Diffstat (limited to 'gpio/gpio.h')
-rw-r--r-- | gpio/gpio.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/gpio/gpio.h b/gpio/gpio.h index a5fdc4e..b4f9136 100644 --- a/gpio/gpio.h +++ b/gpio/gpio.h @@ -12,7 +12,7 @@ struct GPIO_reg_t { volatile uint32_t BSRR; volatile uint32_t BRR; volatile uint32_t LCKR; - #elif defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #else volatile uint32_t MODER; volatile uint32_t OTYPER; volatile uint32_t OSPEEDR; @@ -44,7 +44,7 @@ class GPIO_t { Output = 0x3, AF = 0xb, Analog = 0x0, - #elif defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #else Input, Output, AF, @@ -77,7 +77,7 @@ class GPIO_t { } else { g.reg.CRH = (g.reg.CRH & ~(0xf << (n * 4 - 32))) | m << (n * 4 - 32); } - #elif defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #else g.reg.MODER = (g.reg.MODER & ~(3 << (n * 2))) | m << (n * 2); #endif } @@ -85,7 +85,7 @@ class GPIO_t { void set_type(Type t) { #if defined(STM32F1) // TODO: Unified configure() method? - #elif defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #else if(t) { g.reg.OTYPER |= 1 << n; } else { @@ -97,13 +97,15 @@ class GPIO_t { void set_pull(Pull p) { #if defined(STM32F1) // TODO: Unified configure() method? - #elif defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #else g.reg.PUPDR = (g.reg.PUPDR & ~(3 << (n * 2))) | p << (n * 2); #endif } void set_af(int af) { - #if defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #if defined(STM32F1) + // TODO: Unified configure() method? + #else if(n < 8) { g.reg.AFRL = (g.reg.AFRL & ~(0xf << (n * 4))) | af << (n * 4); } else { @@ -113,7 +115,9 @@ class GPIO_t { } void set_speed(Speed s) { - #if defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #if defined(STM32F1) + // TODO: Unified configure() method? + #else g.reg.OSPEEDR = (g.reg.OSPEEDR & ~(3 << (n * 2))) | s << (n * 2); #endif } @@ -160,7 +164,7 @@ class GPIO_t { public: constexpr PinArray(const GPIO_t& gpio, int first, int last) : g(gpio), f(first), l(last) {} - #if defined(STM32F3) || defined(STM32F4) || defined(STM32L0) + #if ! defined(STM32F1) void set_mode(Pin::Mode m) { g.reg.MODER = (g.reg.MODER & ~mask2()) | ((0x55555555 * m) & mask2()); } @@ -198,7 +202,14 @@ class GPIO_t { typedef GPIO_t::Pin Pin; typedef GPIO_t::PinArray PinArray; -#if defined(STM32F1) +#if defined(STM32F0) +static GPIO_t GPIOA(0x48000000); +static GPIO_t GPIOB(0x48000400); +static GPIO_t GPIOC(0x48000800); +static GPIO_t GPIOD(0x48000c00); +static GPIO_t GPIOE(0x48001000); +static GPIO_t GPIOF(0x48001400); +#elif defined(STM32F1) static GPIO_t GPIOA(0x40010800); static GPIO_t GPIOB(0x40010c00); static GPIO_t GPIOC(0x40011000); |