summaryrefslogtreecommitdiff
path: root/gpio
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-09-05 17:43:52 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-09-05 17:44:18 +0200
commit2d1ff52bffaa8bcc9c59d9369074859c66a9dc75 (patch)
treeb66d6dc7e32a1488db7d377677900c7216bdbfeb /gpio
parent242eafc266dc8b138f832d0dddb27afe5e901bb1 (diff)
Added F1 support to GPIO code.
Diffstat (limited to 'gpio')
-rw-r--r--gpio/gpio.h1
-rw-r--r--gpio/pin.h25
2 files changed, 26 insertions, 0 deletions
diff --git a/gpio/gpio.h b/gpio/gpio.h
index 324950e..ef7186f 100644
--- a/gpio/gpio.h
+++ b/gpio/gpio.h
@@ -28,6 +28,7 @@ struct GPIO_t {
static GPIO_t& GPIOA = *(GPIO_t*)0x40010800;
static GPIO_t& GPIOB = *(GPIO_t*)0x40010c00;
static GPIO_t& GPIOC = *(GPIO_t*)0x40011000;
+static GPIO_t& GPIOD = *(GPIO_t*)0x40011400;
#elif defined(STM32F4)
static GPIO_t& GPIOA = *(GPIO_t*)0x40020000;
static GPIO_t& GPIOB = *(GPIO_t*)0x40020400;
diff --git a/gpio/pin.h b/gpio/pin.h
index 1ad3ca2..f66c956 100644
--- a/gpio/pin.h
+++ b/gpio/pin.h
@@ -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() {