Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3_cpp_extensions.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrDimLis <mrlisdim@gmail.com>2020-09-23 19:47:15 +0300
committerGitHub <noreply@github.com>2020-09-23 19:47:15 +0300
commit5edcd2ddbb6523bed7fd86f210f2738ad16a695b (patch)
tree58ee572e04be29bc1f8d6c1d5d4fc4c8d291b504
parent1229c03c875bf944b7a4949afab94e0b94dd350e (diff)
parent5729cc6de24a23f8c126613d5cd59561c4a85faf (diff)
Merge pull request #14 from thirdpin/feature/pinout_port
[gpio] Make the port typed
-rw-r--r--cm3cpp/gpio.hpp54
-rw-r--r--cm3cpp/private/pinout.h2
2 files changed, 53 insertions, 3 deletions
diff --git a/cm3cpp/gpio.hpp b/cm3cpp/gpio.hpp
index 340c6f2..b293fbd 100644
--- a/cm3cpp/gpio.hpp
+++ b/cm3cpp/gpio.hpp
@@ -52,7 +52,57 @@ class Gpio
public:
struct Pinout
{
- uint32_t port;
+ enum Port
+ {
+// Check preprocessor value is not empty
+// Works for integer values
+// https://stackoverflow.com/questions/4102351/test-for-empty-macro-definition
+#if (GPIOA + 0)
+ PORT_A = GPIOA
+#endif
+#if (GPIOB + 0)
+ ,
+ PORT_B = GPIOC
+#endif
+#if (GPIOC + 0)
+ ,
+ PORT_C = GPIOC
+#endif
+#if (GPIOD + 0)
+ ,
+ PORT_D = GPIOD
+#endif
+#if (GPIOE + 0)
+ ,
+ PORT_E = GPIOE
+#endif
+#if (GPIOF + 0)
+ ,
+ PORT_F = GPIOF
+#endif
+#if (GPIOG + 0)
+ ,
+ PORT_G = GPIOG
+#endif
+#if (GPIOH + 0)
+ ,
+ PORT_H = GPIOH
+#endif
+#if (GPIOI + 0)
+ ,
+ PORT_I = GPIOI
+#endif
+#if (GPIOJ + 0)
+ ,
+ PORT_J = GPIOJ
+#endif
+#if (GPIOK + 0)
+ ,
+ PORT_K = GPIOK
+#endif
+ };
+
+ Port port;
uint16_t pin;
uint8_t pin_number;
};
@@ -126,7 +176,7 @@ class Gpio
private:
Pinout _pinout;
-};
+}; // namespace gpio
} // namespace gpio
diff --git a/cm3cpp/private/pinout.h b/cm3cpp/private/pinout.h
index ae42718..dfb0841 100644
--- a/cm3cpp/private/pinout.h
+++ b/cm3cpp/private/pinout.h
@@ -3,7 +3,7 @@
#define PINOUT_CTOR(port, pin) \
{ \
- GPIO##port, GPIO##pin, pin \
+ static_cast<Pinout::Port>(GPIO##port), GPIO##pin, pin \
}
#define PNULL \