summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2022-01-19 23:52:41 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2022-01-26 23:40:29 +0100
commit5f7df5720d5a43f3c7e1aeea509bcf62e149870a (patch)
tree98045a6f9e8d1daeaafede2ffe0f8492d2ba9068
parentedfce5a5bfbe14d568ef706c8a8ecc8ca3a6a808 (diff)
stm32_gpio: provide port and pin numbers
Accessing Pin.n and Pin.get_portnum() will give you values suitable for use with EXTI and similar places. Signed-off-by: Karl Palsson <karlp@tweak.net.au>
-rw-r--r--gpio/stm32_gpio.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/gpio/stm32_gpio.h b/gpio/stm32_gpio.h
index 6a428d4..7d47b92 100644
--- a/gpio/stm32_gpio.h
+++ b/gpio/stm32_gpio.h
@@ -32,10 +32,10 @@ class STM32_GPIO_v1_t : public mmio_ptr<STM32_GPIO_reg_v1_t> {
class Pin {
private:
const STM32_GPIO_v1_t& g;
- int n;
public:
- constexpr Pin(const STM32_GPIO_v1_t& gpio, int pin) : g(gpio), n(pin) {}
+ const int n;
+ constexpr Pin(const STM32_GPIO_v1_t& gpio, const int pin) : g(gpio), n(pin) {}
enum Mode {
Input = 0x4,
@@ -76,6 +76,10 @@ class STM32_GPIO_v1_t : public mmio_ptr<STM32_GPIO_reg_v1_t> {
void toggle() {
set(!(g->ODR & (1 << n)));
}
+
+ unsigned get_portnum() {
+ return (((*(uint32_t*)&g) >>10) & 0xf) - 2;
+ }
};
class PinArray {
@@ -121,10 +125,10 @@ class STM32_GPIO_v2_t : public mmio_ptr<STM32_GPIO_reg_v2_t> {
class Pin {
private:
const STM32_GPIO_v2_t& g;
- int n;
public:
- constexpr Pin(const STM32_GPIO_v2_t& gpio, int pin) : g(gpio), n(pin) {}
+ const int n;
+ constexpr Pin(const STM32_GPIO_v2_t& gpio, const int pin) : g(gpio), n(pin) {}
enum Mode {
Input,
@@ -202,6 +206,10 @@ class STM32_GPIO_v2_t : public mmio_ptr<STM32_GPIO_reg_v2_t> {
void toggle() {
set(!(g->ODR & (1 << n)));
}
+
+ unsigned get_portnum() {
+ return (((*(uint32_t*)&g) >>10) & 0xf);
+ }
};
class PinArray {