diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-09-05 17:43:52 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-09-05 17:44:18 +0200 |
commit | 2d1ff52bffaa8bcc9c59d9369074859c66a9dc75 (patch) | |
tree | b66d6dc7e32a1488db7d377677900c7216bdbfeb /gpio/pin.h | |
parent | 242eafc266dc8b138f832d0dddb27afe5e901bb1 (diff) |
Added F1 support to GPIO code.
Diffstat (limited to 'gpio/pin.h')
-rw-r--r-- | gpio/pin.h | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -12,10 +12,17 @@ class Pin { Pin(GPIO_t& gpio, int pin) : g(gpio), n(pin) {} enum Mode { + #if defined(STM32F1) + Input = 0x4, + Output = 0x3, + AF = 0xb, + Analog = 0x0, + #elif defined(STM32F4) Input, Output, AF, Analog, + #endif }; enum Type { @@ -30,27 +37,45 @@ class Pin { }; void set_mode(Mode m) { + #if defined(STM32F1) + if(n < 8) { + g.CRL = (g.CRL & ~(0xf << (n * 4))) | m << (n * 4); + } else { + g.CRH = (g.CRH & ~(0xf << (n * 4 - 32))) | m << (n * 4 - 32); + } + #elif defined(STM32F4) g.MODER = (g.MODER & ~(3 << (n * 2))) | m << (n * 2); + #endif } void set_type(Type t) { + #if defined(STM32F1) + // TODO: Unified configure() method? + #elif defined(STM32F4) if(t) { g.OTYPER |= 1 << n; } else { g.OTYPER &= ~(1 << n); } + #endif } void set_pull(Pull p) { + #if defined(STM32F1) + // TODO: Unified configure() method? + #elif defined(STM32F4) g.PUPDR = (g.PUPDR & ~(3 << (n * 2))) | p << (n * 2); + #endif } void set_af(int af) { + #if defined(STM32F4) if(n < 8) { g.AFRL = (g.AFRL & ~(0xf << (n * 4))) | af << (n * 4); } else { g.AFRH = (g.AFRH & ~(0xf << (n * 4 - 32))) | af << (n * 4 - 32); } + #endif } void on() { |