From c22df1415784186110bbf253e3fe2e231a55c9c3 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 14 Oct 2012 00:16:05 +0200 Subject: Add wrapper class around GPIO register class. --- gpio/gpio.h | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'gpio/gpio.h') diff --git a/gpio/gpio.h b/gpio/gpio.h index 725d4df..9a693df 100644 --- a/gpio/gpio.h +++ b/gpio/gpio.h @@ -1,7 +1,9 @@ #ifndef GPIO_H #define GPIO_H -struct GPIO_t { +#include + +struct GPIO_reg_t { #if defined(STM32F1) volatile uint32_t CRL; volatile uint32_t CRH; @@ -24,21 +26,28 @@ struct GPIO_t { #endif }; +class GPIO_t { + public: + GPIO_reg_t& reg; + + constexpr GPIO_t(uint32_t reg_addr) : reg(*(GPIO_reg_t*)reg_addr) {} +}; + #if defined(STM32F1) -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; +static GPIO_t GPIOA(0x40010800); +static GPIO_t GPIOB(0x40010c00); +static GPIO_t GPIOC(0x40011000); +static GPIO_t GPIOD(0x40011400); #elif defined(STM32F4) -static GPIO_t& GPIOA = *(GPIO_t*)0x40020000; -static GPIO_t& GPIOB = *(GPIO_t*)0x40020400; -static GPIO_t& GPIOC = *(GPIO_t*)0x40020800; -static GPIO_t& GPIOD = *(GPIO_t*)0x40020c00; -static GPIO_t& GPIOE = *(GPIO_t*)0x40021000; -static GPIO_t& GPIOF = *(GPIO_t*)0x40021400; -static GPIO_t& GPIOG = *(GPIO_t*)0x40021800; -static GPIO_t& GPIOH = *(GPIO_t*)0x40021c00; -static GPIO_t& GPIOI = *(GPIO_t*)0x40022000; +static GPIO_t GPIOA(0x40020000); +static GPIO_t GPIOB(0x40020400); +static GPIO_t GPIOC(0x40020800); +static GPIO_t GPIOD(0x40020c00); +static GPIO_t GPIOE(0x40021000); +static GPIO_t GPIOF(0x40021400); +static GPIO_t GPIOG(0x40021800); +static GPIO_t GPIOH(0x40021c00); +static GPIO_t GPIOI(0x40022000); #endif #endif -- cgit v1.2.3