From 258b43caa39c36ebb7f3d9fcefa7a9c7c6f90709 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Nov 2022 23:29:25 +0000 Subject: [PATCH 01/22] Initial --- lib/io/hardware_gpio.cpp | 77 +++++++++++++++++++++++++++++++++++----- lib/io/hardware_gpio.hpp | 43 ++++++++++++++++++++-- scripts/hooks/pre-commit | 0 scripts/setup | 0 4 files changed, 109 insertions(+), 11 deletions(-) mode change 100755 => 100644 scripts/hooks/pre-commit mode change 100755 => 100644 scripts/setup diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index a9743ff1..10e2b79a 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -1,16 +1,36 @@ #include "hardware_gpio.hpp" +#include +#include +#include + + + + namespace hyped::io { std::optional HardwareGpioReader::read() { - // TODO: implement - throw -1; + + int out = *gpio_readAddr & pinMAP; + if (out > 0) { + return core::DigitalSignal::kHigh; + } else{ + return core::DigitalSignal::kLow; + } } GpioWriteResult HardwareGpioWriter::write(const core::DigitalSignal state) { - // TODO: implement + //Not sure if this correct + //May just erase everything + //May need to + if (state == core::DigitalSignal::kHigh) { + *gpio_setAddr |= pinMAP; + } else { + *gpio_clearAddr &= ~pinMAP; + } + throw -1; } @@ -19,18 +39,57 @@ HardwareGpio::HardwareGpio(hyped::core::ILogger &log) : log_(log) // TODO: implement } + + std::optional> HardwareGpio::getReader(const uint8_t pin) { - // TODO: implement - log_.log(hyped::core::LogLevel::kFatal, "GPIO reader not implemented"); - return std::nullopt; + //What happens if all shared pointers are removed and this is called? + if (InitializedReaders.count(pin) != 0) { + std::shared_ptr reader; + return reader; + } + const uint8_t bank = pin / 32; + const uint8_t pinID = pin % 32; + const uint8_t pinMAP = (1 << pinID); + + const off_t pinAddress = bankAddresses[bank]; + volatile void *gpio_addr; + volatile unsigned int *gpio_read; + + + int fd = open("/dev/mem", O_RDWR); + gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + gpio_read = static_cast(gpio_addr) + pinRead; + + auto reader = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); + InitializedReaders[pin] = true; + return reader; } std::optional> HardwareGpio::getWriter(const uint8_t pin) { - // TODO: implement - log_.log(hyped::core::LogLevel::kFatal, "GPIO writer not implemented"); - return std::nullopt; + if (InitializedWriters.count(pin) != 0) { + std::shared_ptr writer; + return writer; + } + + + const uint8_t bank = pin / 32; + const uint8_t pinID = pin % 32; + const uint8_t pinMAP = (1 << pinID); + + const off_t pinAddress = bankAddresses[bank]; + volatile void *gpio_addr; + volatile unsigned int *gpio_set; + volatile unsigned int *gpio_clear; + + int fd = open("/dev/mem", O_RDWR); + gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + gpio_set = static_cast(gpio_addr) + pinSet; + gpio_clear = static_cast(gpio_addr) + pinClear; + auto writer = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); + InitializedWriters[pin] = true; + return writer; } } // namespace hyped::io diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 8d1d2a86..48af02ef 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -3,6 +3,7 @@ #include "gpio.hpp" #include +#include namespace hyped::io { @@ -11,16 +12,31 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(); + HardwareGpioReader(uint8_t pin, volatile unsigned int *read): pinMAP(pin), gpio_readAddr(read){}; + + const uint8_t pinMAP; + volatile unsigned int *gpio_readAddr; + friend class HardwareGpio; }; + + + + + + class HardwareGpioWriter : public IGpioWriter { public: virtual GpioWriteResult write(const core::DigitalSignal state); private: - HardwareGpioWriter(const uint8_t pin); + HardwareGpioWriter(const uint8_t pin, volatile unsigned int *set, volatile unsigned int *clear): pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear){}; + + const uint8_t pinMAP; + volatile unsigned int *gpio_setAddr; + volatile unsigned int *gpio_clearAddr; + friend class HardwareGpio; }; @@ -28,6 +44,21 @@ class HardwareGpioWriter : public IGpioWriter { * Hardware GPIO interface, requires physical GPIO pins to be present. This should only * be instantiated at the top level and then provided to users through the IGpio interface. */ + +//GPIO Start Addr End Addr +//GPIO0 0x44E0_7000 0x44E0_7FFF +//GPIO1 0x4804_C000 0x4804_CFFF +//GPIO2 0x481A_C000 0x481A_CFFF +//GPIO3 0x481A_E000 0x481A_EFFF + +//GPIO_DATAIN (READ) 0x138h +//GPIO_DATAOUT 0x13c +//SET 0x194 +//CLEAR 0x190 +// const uint8_t bank = pin_ / 32; // offset: GPIO_0,1,2,3 +// const uint8_t pin_id = pin_ % 32; + + class HardwareGpio { public: HardwareGpio(hyped::core::ILogger &log); @@ -37,6 +68,14 @@ class HardwareGpio { private: hyped::core::ILogger &log_; + const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; + std::unordered_map InitializedWriters; + std::unordered_map InitializedReaders; + + static constexpr unsigned int pinSize = 0x1000; + static constexpr unsigned int pinRead = 0x138; + static constexpr unsigned int pinClear = 0x190; + static constexpr unsigned int pinSet = 0x194; }; } // namespace hyped::io diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit old mode 100755 new mode 100644 diff --git a/scripts/setup b/scripts/setup old mode 100755 new mode 100644 From b83ffff0f92f58be02928c6b0ff13dbf428729a9 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Nov 2022 23:36:47 +0000 Subject: [PATCH 02/22] Fixed shared dereference by adding to map --- lib/io/hardware_gpio.cpp | 9 +++++---- lib/io/hardware_gpio.hpp | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 10e2b79a..0e8ea047 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -44,6 +44,7 @@ HardwareGpio::HardwareGpio(hyped::core::ILogger &log) : log_(log) std::optional> HardwareGpio::getReader(const uint8_t pin) { //What happens if all shared pointers are removed and this is called? + //Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. if (InitializedReaders.count(pin) != 0) { std::shared_ptr reader; return reader; @@ -61,8 +62,8 @@ std::optional> HardwareGpio::getReader(const uint8_ gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); gpio_read = static_cast(gpio_addr) + pinRead; - auto reader = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); - InitializedReaders[pin] = true; + InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); + std::shared_ptr reader; return reader; } @@ -87,8 +88,8 @@ std::optional> HardwareGpio::getWriter(const uint8_ gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); gpio_set = static_cast(gpio_addr) + pinSet; gpio_clear = static_cast(gpio_addr) + pinClear; - auto writer = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); - InitializedWriters[pin] = true; + InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); + std::shared_ptr writer; return writer; } diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 48af02ef..8c703721 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -69,8 +69,8 @@ class HardwareGpio { private: hyped::core::ILogger &log_; const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; - std::unordered_map InitializedWriters; - std::unordered_map InitializedReaders; + std::unordered_map> InitializedWriters; + std::unordered_map> InitializedReaders; static constexpr unsigned int pinSize = 0x1000; static constexpr unsigned int pinRead = 0x138; From da7c525de670f045e5c56c24937300594e210b76 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Nov 2022 18:47:22 +0000 Subject: [PATCH 03/22] Fixed Writer+Reader intialization and throw with small changes --- lib/io/hardware_gpio.cpp | 7 +++++-- lib/io/hardware_gpio.hpp | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 0e8ea047..e0e92a4e 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -30,8 +30,6 @@ GpioWriteResult HardwareGpioWriter::write(const core::DigitalSignal state) } else { *gpio_clearAddr &= ~pinMAP; } - - throw -1; } HardwareGpio::HardwareGpio(hyped::core::ILogger &log) : log_(log) @@ -47,6 +45,7 @@ std::optional> HardwareGpio::getReader(const uint8_ //Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. if (InitializedReaders.count(pin) != 0) { std::shared_ptr reader; + reader = InitializedWriters[pin]; return reader; } const uint8_t bank = pin / 32; @@ -64,6 +63,7 @@ std::optional> HardwareGpio::getReader(const uint8_ InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); std::shared_ptr reader; + reader = InitializedReader[pin]; return reader; } @@ -71,6 +71,7 @@ std::optional> HardwareGpio::getWriter(const uint8_ { if (InitializedWriters.count(pin) != 0) { std::shared_ptr writer; + writer = InitializedWriters[pin]; return writer; } @@ -90,7 +91,9 @@ std::optional> HardwareGpio::getWriter(const uint8_ gpio_clear = static_cast(gpio_addr) + pinClear; InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); std::shared_ptr writer; + writer = InitializedWriters[pin]; return writer; } } // namespace hyped::io +//hello world \ No newline at end of file diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 8c703721..7419c0f7 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -55,9 +55,8 @@ class HardwareGpioWriter : public IGpioWriter { //GPIO_DATAOUT 0x13c //SET 0x194 //CLEAR 0x190 -// const uint8_t bank = pin_ / 32; // offset: GPIO_0,1,2,3 -// const uint8_t pin_id = pin_ % 32; +//Page 211 - 213 P8 Header Pins class HardwareGpio { public: From 4f5bab585412a41c2366fad20e4ba1a857775fb3 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Nov 2022 19:07:01 +0000 Subject: [PATCH 04/22] Fixed shared pointer --- lib/io/hardware_gpio.cpp | 42 ++++++++++++++++++++++++---------------- lib/io/hardware_gpio.hpp | 18 +++-------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index e0e92a4e..a19af407 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -4,9 +4,6 @@ #include - - - namespace hyped::io { std::optional HardwareGpioReader::read() @@ -30,6 +27,7 @@ GpioWriteResult HardwareGpioWriter::write(const core::DigitalSignal state) } else { *gpio_clearAddr &= ~pinMAP; } + return GpioWriteResult::kSuccess; } HardwareGpio::HardwareGpio(hyped::core::ILogger &log) : log_(log) @@ -43,9 +41,9 @@ std::optional> HardwareGpio::getReader(const uint8_ { //What happens if all shared pointers are removed and this is called? //Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. + if (InitializedReaders.count(pin) != 0) { - std::shared_ptr reader; - reader = InitializedWriters[pin]; + std::shared_ptr reader = InitializedReaders[pin]; return reader; } const uint8_t bank = pin / 32; @@ -56,26 +54,30 @@ std::optional> HardwareGpio::getReader(const uint8_ volatile void *gpio_addr; volatile unsigned int *gpio_read; - int fd = open("/dev/mem", O_RDWR); - gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); - gpio_read = static_cast(gpio_addr) + pinRead; + if (fd < 0) { + return std::nullopt; + } + gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + if (gpio_addr == MAP_FAILED) { + return std::nullopt; + } + + gpio_read = static_cast(gpio_addr) + pinRead; InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); - std::shared_ptr reader; - reader = InitializedReader[pin]; + std::shared_ptr reader = InitializedReaders[pin]; return reader; } + std::optional> HardwareGpio::getWriter(const uint8_t pin) { if (InitializedWriters.count(pin) != 0) { - std::shared_ptr writer; - writer = InitializedWriters[pin]; + std::shared_ptr writer = InitializedWriters[pin]; return writer; } - const uint8_t bank = pin / 32; const uint8_t pinID = pin % 32; const uint8_t pinMAP = (1 << pinID); @@ -86,14 +88,20 @@ std::optional> HardwareGpio::getWriter(const uint8_ volatile unsigned int *gpio_clear; int fd = open("/dev/mem", O_RDWR); + if (fd < 0) { + return std::nullopt; + } + gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + if (gpio_addr == MAP_FAILED) { + return std::nullopt; + } + gpio_set = static_cast(gpio_addr) + pinSet; gpio_clear = static_cast(gpio_addr) + pinClear; InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); - std::shared_ptr writer; - writer = InitializedWriters[pin]; + std::shared_ptr writer = InitializedWriters[pin]; return writer; } -} // namespace hyped::io -//hello world \ No newline at end of file +} // namespace hyped::io \ No newline at end of file diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 7419c0f7..e7ba97b0 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -40,23 +40,8 @@ class HardwareGpioWriter : public IGpioWriter { friend class HardwareGpio; }; -/** - * Hardware GPIO interface, requires physical GPIO pins to be present. This should only - * be instantiated at the top level and then provided to users through the IGpio interface. - */ -//GPIO Start Addr End Addr -//GPIO0 0x44E0_7000 0x44E0_7FFF -//GPIO1 0x4804_C000 0x4804_CFFF -//GPIO2 0x481A_C000 0x481A_CFFF -//GPIO3 0x481A_E000 0x481A_EFFF -//GPIO_DATAIN (READ) 0x138h -//GPIO_DATAOUT 0x13c -//SET 0x194 -//CLEAR 0x190 - -//Page 211 - 213 P8 Header Pins class HardwareGpio { public: @@ -67,6 +52,9 @@ class HardwareGpio { private: hyped::core::ILogger &log_; + //Bank Addresses are header base addresses. + //Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible + const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; From e997646a13ae4b7763e058bb13a95957aa20c4fc Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Nov 2022 19:15:46 +0000 Subject: [PATCH 05/22] Added loggin --- lib/io/hardware_gpio.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index a19af407..7992718e 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -56,11 +56,13 @@ std::optional> HardwareGpio::getReader(const uint8_ int fd = open("/dev/mem", O_RDWR); if (fd < 0) { + log_.log(hyped::core::LogLevel::kFatal, "opening /dev/mem failed"); return std::nullopt; } gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); if (gpio_addr == MAP_FAILED) { + log_.log(hyped::core::LogLevel::kFatal, "mmap failed"); return std::nullopt; } From 591b44632b0039d9209d87a7157226a1d254d301 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Nov 2022 18:56:59 +0000 Subject: [PATCH 06/22] Added Comments and fixed types --- lib/io/hardware_gpio.cpp | 59 +++++++++++++++++++++++++++------------- lib/io/hardware_gpio.hpp | 20 +++++++------- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 7992718e..70bd6066 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -9,7 +9,8 @@ namespace hyped::io { std::optional HardwareGpioReader::read() { - int out = *gpio_readAddr & pinMAP; + const uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; + // if (out > 0) { return core::DigitalSignal::kHigh; } else{ @@ -19,13 +20,11 @@ std::optional HardwareGpioReader::read() GpioWriteResult HardwareGpioWriter::write(const core::DigitalSignal state) { - //Not sure if this correct - //May just erase everything - //May need to + //Set and Clear are seperate registers. if (state == core::DigitalSignal::kHigh) { - *gpio_setAddr |= pinMAP; + *gpio_setAddr = pinMAP; } else { - *gpio_clearAddr &= ~pinMAP; + *gpio_clearAddr = pinMAP; } return GpioWriteResult::kSuccess; } @@ -46,14 +45,27 @@ std::optional> HardwareGpio::getReader(const uint8_ std::shared_ptr reader = InitializedReaders[pin]; return reader; } - const uint8_t bank = pin / 32; - const uint8_t pinID = pin % 32; - const uint8_t pinMAP = (1 << pinID); + //There are 4 Bank Numbers, 0 1 2 3 + //So interger division by 32 gives us bank number + const uint32_t bank = pin / 32; + // Modulo by 32 gets us the ID of the pin relative to the bank + const uint32_t pinID = pin % 32; + //gpio addresses contain 32 pins, so we use pinmap to specify specific pin. + const uint32_t pinMAP = (1 << pinID); + if (bank > 3) { + log_.log(hyped::core::LogLevel::kFatal, "invalid pin number"); + return std::nullopt; + } + + //Now that we have the bank number, we can get the actual memory address. const off_t pinAddress = bankAddresses[bank]; volatile void *gpio_addr; - volatile unsigned int *gpio_read; + volatile uint32_t *gpio_read; + /** + /dev/mem and mmap is related to making the registry available as a virtual memory address. + **/ int fd = open("/dev/mem", O_RDWR); if (fd < 0) { log_.log(hyped::core::LogLevel::kFatal, "opening /dev/mem failed"); @@ -65,8 +77,10 @@ std::optional> HardwareGpio::getReader(const uint8_ log_.log(hyped::core::LogLevel::kFatal, "mmap failed"); return std::nullopt; } - - gpio_read = static_cast(gpio_addr) + pinRead; + // Type conversion for address adding from void + const uint64_t base = reinterpret_cast(gpio_addr); + //pinRead is the hardware specified address for reading. + gpio_read = reinterpret_cast(base + pinRead); InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); std::shared_ptr reader = InitializedReaders[pin]; return reader; @@ -80,14 +94,14 @@ std::optional> HardwareGpio::getWriter(const uint8_ return writer; } - const uint8_t bank = pin / 32; - const uint8_t pinID = pin % 32; - const uint8_t pinMAP = (1 << pinID); + const uint32_t bank = pin / 32; + const uint32_t pinID = pin % 32; + const uint32_t pinMAP = (1 << pinID); const off_t pinAddress = bankAddresses[bank]; volatile void *gpio_addr; - volatile unsigned int *gpio_set; - volatile unsigned int *gpio_clear; + volatile uint32_t *gpio_set; + volatile uint32_t *gpio_clear; int fd = open("/dev/mem", O_RDWR); if (fd < 0) { @@ -99,8 +113,15 @@ std::optional> HardwareGpio::getWriter(const uint8_ return std::nullopt; } - gpio_set = static_cast(gpio_addr) + pinSet; - gpio_clear = static_cast(gpio_addr) + pinClear; + + const uint64_t base = reinterpret_cast(gpio_addr); + + //pinset is the hardware specified address for reading. + gpio_set = reinterpret_cast(base + pinSet); + + //pinclear is the hardware specified address for reading. + gpio_clear = reinterpret_cast(base + pinClear); + InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); std::shared_ptr writer = InitializedWriters[pin]; return writer; diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index e7ba97b0..a410acd9 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -12,10 +12,10 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(uint8_t pin, volatile unsigned int *read): pinMAP(pin), gpio_readAddr(read){}; + HardwareGpioReader(uint8_t pin, volatile uint32_t *read): pinMAP(pin), gpio_readAddr(read){}; const uint8_t pinMAP; - volatile unsigned int *gpio_readAddr; + volatile uint32_t *gpio_readAddr; friend class HardwareGpio; }; @@ -31,11 +31,11 @@ class HardwareGpioWriter : public IGpioWriter { virtual GpioWriteResult write(const core::DigitalSignal state); private: - HardwareGpioWriter(const uint8_t pin, volatile unsigned int *set, volatile unsigned int *clear): pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear){}; + HardwareGpioWriter(const uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear): pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear){}; const uint8_t pinMAP; - volatile unsigned int *gpio_setAddr; - volatile unsigned int *gpio_clearAddr; + volatile uint32_t *gpio_setAddr; + volatile uint32_t *gpio_clearAddr; friend class HardwareGpio; }; @@ -58,11 +58,11 @@ class HardwareGpio { const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; - - static constexpr unsigned int pinSize = 0x1000; - static constexpr unsigned int pinRead = 0x138; - static constexpr unsigned int pinClear = 0x190; - static constexpr unsigned int pinSet = 0x194; + //Also hardware specified addresses and sizes for read, clear, set, size, etc. + static constexpr uint32_t pinSize = 0x1000; + static constexpr uint32_t pinRead = 0x138; + static constexpr uint32_t pinClear = 0x190; + static constexpr uint32_t pinSet = 0x194; }; } // namespace hyped::io From cbd231ee52aceb6e814c687c9e4849e17dd8d13d Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Nov 2022 19:12:02 +0000 Subject: [PATCH 07/22] Fixed compiler error --- lib/io/hardware_gpio.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 49ae47cb..fb05a97e 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -8,43 +8,33 @@ namespace hyped::io { std::optional HardwareGpioReader::read() { -<<<<<<< HEAD - + //pinMap just 0000.... with 1 flipped in pin number. + //So AND with readAddr to extract the specific pin const uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; - // + if (out > 0) { return core::DigitalSignal::kHigh; } else{ return core::DigitalSignal::kLow; } -======= - // TODOLater: implement - throw -1; ->>>>>>> master } core::Result HardwareGpioWriter::write(const core::DigitalSignal state) { -<<<<<<< HEAD //Set and Clear are seperate registers. if (state == core::DigitalSignal::kHigh) { *gpio_setAddr = pinMAP; } else { *gpio_clearAddr = pinMAP; } - return GpioWriteResult::kSuccess; -======= - // TODOLater: implement - throw -1; ->>>>>>> master + return core::Result::kSuccess; } HardwareGpio::HardwareGpio(core::ILogger &log) : log_(log) { - // TODOLater: implement + // TODO: implement } -<<<<<<< HEAD std::optional> HardwareGpio::getReader(const uint8_t pin) @@ -136,20 +126,6 @@ std::optional> HardwareGpio::getWriter(const uint8_ InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); std::shared_ptr writer = InitializedWriters[pin]; return writer; -======= -std::optional> HardwareGpio::getReader(const std::uint8_t pin) -{ - // TODOLater: implement - log_.log(core::LogLevel::kFatal, "GPIO reader not implemented"); - return std::nullopt; -} - -std::optional> HardwareGpio::getWriter(const std::uint8_t pin) -{ - // TODOLater: implement - log_.log(core::LogLevel::kFatal, "GPIO writer not implemented"); - return std::nullopt; ->>>>>>> master } } // namespace hyped::io \ No newline at end of file From fe3cc1f96b0fb1e5ab2423bcd1390ed5c68d11ee Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Nov 2022 19:17:36 +0000 Subject: [PATCH 08/22] Removed hyped --- lib/io/hardware_gpio.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index fb05a97e..22f793d4 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -55,7 +55,7 @@ std::optional> HardwareGpio::getReader(const uint8_ //gpio addresses contain 32 pins, so we use pinmap to specify specific pin. const uint32_t pinMAP = (1 << pinID); if (bank > 3) { - log_.log(hyped::core::LogLevel::kFatal, "invalid pin number"); + log_.log(core::LogLevel::kFatal, "invalid pin number"); return std::nullopt; } @@ -69,13 +69,13 @@ std::optional> HardwareGpio::getReader(const uint8_ **/ int fd = open("/dev/mem", O_RDWR); if (fd < 0) { - log_.log(hyped::core::LogLevel::kFatal, "opening /dev/mem failed"); + log_.log(core::LogLevel::kFatal, "opening /dev/mem failed"); return std::nullopt; } gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); if (gpio_addr == MAP_FAILED) { - log_.log(hyped::core::LogLevel::kFatal, "mmap failed"); + log_.log(core::LogLevel::kFatal, "mmap failed"); return std::nullopt; } // Type conversion for address adding from void From a4fb12df21b3d77ba333bd723cd50afe82149d55 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 08:48:52 +0800 Subject: [PATCH 09/22] Clang-changes --- lib/io/hardware_gpio.cpp | 69 +++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 22f793d4..b249fdbf 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -1,27 +1,28 @@ #include "hardware_gpio.hpp" -#include -#include + #include +#include +#include namespace hyped::io { std::optional HardwareGpioReader::read() { - //pinMap just 0000.... with 1 flipped in pin number. - //So AND with readAddr to extract the specific pin + // pinMap just 0000.... with 1 flipped in pin number. + // So AND with readAddr to extract the specific pin const uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; - + if (out > 0) { return core::DigitalSignal::kHigh; - } else{ + } else { return core::DigitalSignal::kLow; } } core::Result HardwareGpioWriter::write(const core::DigitalSignal state) { - //Set and Clear are seperate registers. + // Set and Clear are seperate registers. if (state == core::DigitalSignal::kHigh) { *gpio_setAddr = pinMAP; } else { @@ -35,36 +36,34 @@ HardwareGpio::HardwareGpio(core::ILogger &log) : log_(log) // TODO: implement } - - std::optional> HardwareGpio::getReader(const uint8_t pin) { - //What happens if all shared pointers are removed and this is called? - //Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. - + // What happens if all shared pointers are removed and this is called? + // Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. + if (InitializedReaders.count(pin) != 0) { std::shared_ptr reader = InitializedReaders[pin]; return reader; } - //There are 4 Bank Numbers, 0 1 2 3 - //So interger division by 32 gives us bank number + // There are 4 Bank Numbers, 0 1 2 3 + // So interger division by 32 gives us bank number const uint32_t bank = pin / 32; // Modulo by 32 gets us the ID of the pin relative to the bank const uint32_t pinID = pin % 32; - //gpio addresses contain 32 pins, so we use pinmap to specify specific pin. + // gpio addresses contain 32 pins, so we use pinmap to specify specific pin. const uint32_t pinMAP = (1 << pinID); if (bank > 3) { log_.log(core::LogLevel::kFatal, "invalid pin number"); return std::nullopt; } - //Now that we have the bank number, we can get the actual memory address. + // Now that we have the bank number, we can get the actual memory address. const off_t pinAddress = bankAddresses[bank]; volatile void *gpio_addr; volatile uint32_t *gpio_read; - /** + /** /dev/mem and mmap is related to making the registry available as a virtual memory address. **/ int fd = open("/dev/mem", O_RDWR); @@ -72,22 +71,22 @@ std::optional> HardwareGpio::getReader(const uint8_ log_.log(core::LogLevel::kFatal, "opening /dev/mem failed"); return std::nullopt; } - - gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + + gpio_addr = mmap(0, pinSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); if (gpio_addr == MAP_FAILED) { log_.log(core::LogLevel::kFatal, "mmap failed"); return std::nullopt; } // Type conversion for address adding from void const uint64_t base = reinterpret_cast(gpio_addr); - //pinRead is the hardware specified address for reading. + // pinRead is the hardware specified address for reading. gpio_read = reinterpret_cast(base + pinRead); - InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); + InitializedReaders[pin] + = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); std::shared_ptr reader = InitializedReaders[pin]; return reader; } - std::optional> HardwareGpio::getWriter(const uint8_t pin) { if (InitializedWriters.count(pin) != 0) { @@ -95,8 +94,8 @@ std::optional> HardwareGpio::getWriter(const uint8_ return writer; } - const uint32_t bank = pin / 32; - const uint32_t pinID = pin % 32; + const uint32_t bank = pin / 32; + const uint32_t pinID = pin % 32; const uint32_t pinMAP = (1 << pinID); const off_t pinAddress = bankAddresses[bank]; @@ -105,25 +104,21 @@ std::optional> HardwareGpio::getWriter(const uint8_ volatile uint32_t *gpio_clear; int fd = open("/dev/mem", O_RDWR); - if (fd < 0) { - return std::nullopt; - } + if (fd < 0) { return std::nullopt; } - gpio_addr = mmap(0, pinSize , PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); - if (gpio_addr == MAP_FAILED) { - return std::nullopt; - } + gpio_addr = mmap(0, pinSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + if (gpio_addr == MAP_FAILED) { return std::nullopt; } - const uint64_t base = reinterpret_cast(gpio_addr); - - //pinset is the hardware specified address for reading. + + // pinset is the hardware specified address for reading. gpio_set = reinterpret_cast(base + pinSet); - - //pinclear is the hardware specified address for reading. + + // pinclear is the hardware specified address for reading. gpio_clear = reinterpret_cast(base + pinClear); - InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); + InitializedWriters[pin] + = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); std::shared_ptr writer = InitializedWriters[pin]; return writer; } From f4732006f9fdca70ab5a0ceeccd3043459f73634 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 08:59:33 +0800 Subject: [PATCH 10/22] clang changes --- lib/io/hardware_gpio.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 877310c5..879b7ee4 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -12,7 +12,7 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(uint8_t pin, volatile uint32_t *read): pinMAP(pin), gpio_readAddr(read){}; + HardwareGpioReader(uint8_t pin, volatile uint32_t *read):pinMAP(pin), gpio_readAddr(read); const uint8_t pinMAP; volatile uint32_t *gpio_readAddr; @@ -31,11 +31,11 @@ class HardwareGpioWriter : public IGpioWriter { virtual core::Result write(const core::DigitalSignal state); private: - HardwareGpioWriter(const uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear): pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear){}; + HardwareGpioWriter(const uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear):pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear); const uint8_t pinMAP; - volatile uint32_t *gpio_setAddr; - volatile uint32_t *gpio_clearAddr; + volatile uint32_t *gpio_setAddr; + volatile uint32_t *gpio_clearAddr; friend class HardwareGpio; }; @@ -59,10 +59,10 @@ class HardwareGpio { std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; //Also hardware specified addresses and sizes for read, clear, set, size, etc. - static constexpr uint32_t pinSize = 0x1000; - static constexpr uint32_t pinRead = 0x138; - static constexpr uint32_t pinClear = 0x190; - static constexpr uint32_t pinSet = 0x194; + static constexpr uint32_t pinSize= 0x1000; + static constexpr uint32_t pinRead= 0x138; + static constexpr uint32_t pinClear= 0x190; + static constexpr uint32_t pinSet= 0x194; }; } // namespace hyped::io From e61a46262f18614d4a8d63044b0e4ec7b0c1df1a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 09:04:23 +0800 Subject: [PATCH 11/22] test --- lib/io/hardware_gpio.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 879b7ee4..56a63717 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -59,10 +59,10 @@ class HardwareGpio { std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; //Also hardware specified addresses and sizes for read, clear, set, size, etc. - static constexpr uint32_t pinSize= 0x1000; - static constexpr uint32_t pinRead= 0x138; - static constexpr uint32_t pinClear= 0x190; - static constexpr uint32_t pinSet= 0x194; + static constexpr uint32_t pinSize = 0x1000; + static constexpr uint32_t pinRead = 0x138; + static constexpr uint32_t pinClear = 0x190; + static constexpr uint32_t pinSet = 0x194; }; } // namespace hyped::io From a63d7e4ee3d4d2dbfc84548e81edae0850a134ff Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 09:06:52 +0800 Subject: [PATCH 12/22] Fixed clang --- lib/io/hardware_gpio.hpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 56a63717..8d84e665 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -2,9 +2,10 @@ #include "gpio.hpp" -#include #include +#include + namespace hyped::io { class HardwareGpioReader : public IGpioReader { @@ -12,7 +13,7 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(uint8_t pin, volatile uint32_t *read):pinMAP(pin), gpio_readAddr(read); + HardwareGpioReader(uint8_t pin, volatile uint32_t *read) : pinMAP(pin), gpio_readAddr(read); const uint8_t pinMAP; volatile uint32_t *gpio_readAddr; @@ -20,19 +21,16 @@ class HardwareGpioReader : public IGpioReader { friend class HardwareGpio; }; - - - - - - class HardwareGpioWriter : public IGpioWriter { public: virtual core::Result write(const core::DigitalSignal state); private: - HardwareGpioWriter(const uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear):pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear); - + HardwareGpioWriter(const uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear) + : pinMAP(pin), + gpio_setAddr(set), + gpio_clearAddr(clear); + const uint8_t pinMAP; volatile uint32_t *gpio_setAddr; volatile uint32_t *gpio_clearAddr; @@ -40,9 +38,6 @@ class HardwareGpioWriter : public IGpioWriter { friend class HardwareGpio; }; - - - class HardwareGpio { public: HardwareGpio(core::ILogger &log); @@ -52,17 +47,17 @@ class HardwareGpio { private: core::ILogger &log_; - //Bank Addresses are header base addresses. - //Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible + // Bank Addresses are header base addresses. + // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; - //Also hardware specified addresses and sizes for read, clear, set, size, etc. - static constexpr uint32_t pinSize = 0x1000; - static constexpr uint32_t pinRead = 0x138; + // Also hardware specified addresses and sizes for read, clear, set, size, etc. + static constexpr uint32_t pinSize = 0x1000; + static constexpr uint32_t pinRead = 0x138; static constexpr uint32_t pinClear = 0x190; - static constexpr uint32_t pinSet = 0x194; + static constexpr uint32_t pinSet = 0x194; }; } // namespace hyped::io From e1c0bb3aeb3108eac9a9049c0f263b69238884b4 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 09:24:12 +0800 Subject: [PATCH 13/22] Fixed std --- lib/io/hardware_gpio.cpp | 6 +++--- lib/io/hardware_gpio.hpp | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index b249fdbf..fbf82ffd 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -11,7 +11,7 @@ std::optional HardwareGpioReader::read() { // pinMap just 0000.... with 1 flipped in pin number. // So AND with readAddr to extract the specific pin - const uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; + const std::uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; if (out > 0) { return core::DigitalSignal::kHigh; @@ -36,7 +36,7 @@ HardwareGpio::HardwareGpio(core::ILogger &log) : log_(log) // TODO: implement } -std::optional> HardwareGpio::getReader(const uint8_t pin) +std::optional> HardwareGpio::getReader(const std::uint8_t pin) { // What happens if all shared pointers are removed and this is called? // Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. @@ -87,7 +87,7 @@ std::optional> HardwareGpio::getReader(const uint8_ return reader; } -std::optional> HardwareGpio::getWriter(const uint8_t pin) +std::optional> HardwareGpio::getWriter(const std::uint8_t pin) { if (InitializedWriters.count(pin) != 0) { std::shared_ptr writer = InitializedWriters[pin]; diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 8d84e665..4acc23e3 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -13,9 +13,9 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(uint8_t pin, volatile uint32_t *read) : pinMAP(pin), gpio_readAddr(read); + HardwareGpioReader(std::uint8_t pin, volatile uint32_t *read) : pinMAP(pin), gpio_readAddr(read){}; - const uint8_t pinMAP; + const std::uint8_t pinMAP; volatile uint32_t *gpio_readAddr; friend class HardwareGpio; @@ -26,12 +26,12 @@ class HardwareGpioWriter : public IGpioWriter { virtual core::Result write(const core::DigitalSignal state); private: - HardwareGpioWriter(const uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear) + HardwareGpioWriter(const std::uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear) : pinMAP(pin), gpio_setAddr(set), - gpio_clearAddr(clear); + gpio_clearAddr(clear){}; - const uint8_t pinMAP; + const std::uint8_t pinMAP; volatile uint32_t *gpio_setAddr; volatile uint32_t *gpio_clearAddr; @@ -51,8 +51,8 @@ class HardwareGpio { // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; - std::unordered_map> InitializedWriters; - std::unordered_map> InitializedReaders; + std::unordered_map> InitializedWriters; + std::unordered_map> InitializedReaders; // Also hardware specified addresses and sizes for read, clear, set, size, etc. static constexpr uint32_t pinSize = 0x1000; static constexpr uint32_t pinRead = 0x138; From 9578ad554a17fc1b68a8f4d1f6d1c98d1a8c0cc3 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 09:24:58 +0800 Subject: [PATCH 14/22] clang --- lib/io/hardware_gpio.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 4acc23e3..4075ce7f 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -13,7 +13,9 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(std::uint8_t pin, volatile uint32_t *read) : pinMAP(pin), gpio_readAddr(read){}; + HardwareGpioReader(std::uint8_t pin, volatile uint32_t *read) + : pinMAP(pin), + gpio_readAddr(read){}; const std::uint8_t pinMAP; volatile uint32_t *gpio_readAddr; From f742e05592def19ffe5e91d08fd053e1cba73d97 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Dec 2022 09:29:28 +0800 Subject: [PATCH 15/22] Added std to uint_32 and 64 --- lib/io/hardware_gpio.cpp | 28 ++++++++++++++-------------- lib/io/hardware_gpio.hpp | 20 +++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index fbf82ffd..57957d09 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -48,11 +48,11 @@ std::optional> HardwareGpio::getReader(const std::u // There are 4 Bank Numbers, 0 1 2 3 // So interger division by 32 gives us bank number - const uint32_t bank = pin / 32; + const std::uint32_t bank = pin / 32; // Modulo by 32 gets us the ID of the pin relative to the bank - const uint32_t pinID = pin % 32; + const std::uint32_t pinID = pin % 32; // gpio addresses contain 32 pins, so we use pinmap to specify specific pin. - const uint32_t pinMAP = (1 << pinID); + const std::uint32_t pinMAP = (1 << pinID); if (bank > 3) { log_.log(core::LogLevel::kFatal, "invalid pin number"); return std::nullopt; @@ -61,7 +61,7 @@ std::optional> HardwareGpio::getReader(const std::u // Now that we have the bank number, we can get the actual memory address. const off_t pinAddress = bankAddresses[bank]; volatile void *gpio_addr; - volatile uint32_t *gpio_read; + volatile std::uint32_t *gpio_read; /** /dev/mem and mmap is related to making the registry available as a virtual memory address. @@ -78,9 +78,9 @@ std::optional> HardwareGpio::getReader(const std::u return std::nullopt; } // Type conversion for address adding from void - const uint64_t base = reinterpret_cast(gpio_addr); + const std::uint64_t base = reinterpret_cast(gpio_addr); // pinRead is the hardware specified address for reading. - gpio_read = reinterpret_cast(base + pinRead); + gpio_read = reinterpret_cast(base + pinRead); InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); std::shared_ptr reader = InitializedReaders[pin]; @@ -94,14 +94,14 @@ std::optional> HardwareGpio::getWriter(const std::u return writer; } - const uint32_t bank = pin / 32; - const uint32_t pinID = pin % 32; - const uint32_t pinMAP = (1 << pinID); + const std::uint32_t bank = pin / 32; + const std::uint32_t pinID = pin % 32; + const std::uint32_t pinMAP = (1 << pinID); const off_t pinAddress = bankAddresses[bank]; volatile void *gpio_addr; - volatile uint32_t *gpio_set; - volatile uint32_t *gpio_clear; + volatile std::uint32_t *gpio_set; + volatile std::uint32_t *gpio_clear; int fd = open("/dev/mem", O_RDWR); if (fd < 0) { return std::nullopt; } @@ -109,13 +109,13 @@ std::optional> HardwareGpio::getWriter(const std::u gpio_addr = mmap(0, pinSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); if (gpio_addr == MAP_FAILED) { return std::nullopt; } - const uint64_t base = reinterpret_cast(gpio_addr); + const std::uint64_t base = reinterpret_cast(gpio_addr); // pinset is the hardware specified address for reading. - gpio_set = reinterpret_cast(base + pinSet); + gpio_set = reinterpret_cast(base + pinSet); // pinclear is the hardware specified address for reading. - gpio_clear = reinterpret_cast(base + pinClear); + gpio_clear = reinterpret_cast(base + pinClear); InitializedWriters[pin] = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 4075ce7f..bf432cc6 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -13,12 +13,12 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(std::uint8_t pin, volatile uint32_t *read) + HardwareGpioReader(std::uint8_t pin, volatile std::uint32_t *read) : pinMAP(pin), gpio_readAddr(read){}; const std::uint8_t pinMAP; - volatile uint32_t *gpio_readAddr; + volatile std::uint32_t *gpio_readAddr; friend class HardwareGpio; }; @@ -28,14 +28,16 @@ class HardwareGpioWriter : public IGpioWriter { virtual core::Result write(const core::DigitalSignal state); private: - HardwareGpioWriter(const std::uint8_t pin, volatile uint32_t *set, volatile uint32_t *clear) + HardwareGpioWriter(const std::uint8_t pin, + volatile std::uint32_t *set, + volatile std::uint32_t *clear) : pinMAP(pin), gpio_setAddr(set), gpio_clearAddr(clear){}; const std::uint8_t pinMAP; - volatile uint32_t *gpio_setAddr; - volatile uint32_t *gpio_clearAddr; + volatile std::uint32_t *gpio_setAddr; + volatile std::uint32_t *gpio_clearAddr; friend class HardwareGpio; }; @@ -56,10 +58,10 @@ class HardwareGpio { std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; // Also hardware specified addresses and sizes for read, clear, set, size, etc. - static constexpr uint32_t pinSize = 0x1000; - static constexpr uint32_t pinRead = 0x138; - static constexpr uint32_t pinClear = 0x190; - static constexpr uint32_t pinSet = 0x194; + static constexpr std::uint32_t pinSize = 0x1000; + static constexpr std::uint32_t pinRead = 0x138; + static constexpr std::uint32_t pinClear = 0x190; + static constexpr std::uint32_t pinSet = 0x194; }; } // namespace hyped::io From 659e22f2b11c57dd1f8423ca0839e905372cf825 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 16 Jan 2023 19:08:04 +0000 Subject: [PATCH 16/22] Added comments --- lib/io/hardware_gpio.cpp | 21 ++++++++++----------- lib/io/hardware_gpio.hpp | 28 ++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 57957d09..40bdb7eb 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -12,7 +12,7 @@ std::optional HardwareGpioReader::read() // pinMap just 0000.... with 1 flipped in pin number. // So AND with readAddr to extract the specific pin const std::uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; - + if (out > 0) { return core::DigitalSignal::kHigh; } else { @@ -32,46 +32,42 @@ core::Result HardwareGpioWriter::write(const core::DigitalSignal state) } HardwareGpio::HardwareGpio(core::ILogger &log) : log_(log) -{ - // TODO: implement -} +{} std::optional> HardwareGpio::getReader(const std::uint8_t pin) { // What happens if all shared pointers are removed and this is called? // Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. - if (InitializedReaders.count(pin) != 0) { std::shared_ptr reader = InitializedReaders[pin]; return reader; } // There are 4 Bank Numbers, 0 1 2 3 - // So interger division by 32 gives us bank number + // Integer divison to get bank number const std::uint32_t bank = pin / 32; // Modulo by 32 gets us the ID of the pin relative to the bank const std::uint32_t pinID = pin % 32; - // gpio addresses contain 32 pins, so we use pinmap to specify specific pin. + // Gpio addresses contain 32 pins, so we use pinmap to specify specific pin. const std::uint32_t pinMAP = (1 << pinID); if (bank > 3) { log_.log(core::LogLevel::kFatal, "invalid pin number"); return std::nullopt; } - // Now that we have the bank number, we can get the actual memory address. + // Get memory address from bank address const off_t pinAddress = bankAddresses[bank]; volatile void *gpio_addr; volatile std::uint32_t *gpio_read; - /** - /dev/mem and mmap is related to making the registry available as a virtual memory address. - **/ + // /dev/mem and mmap is related to making the registry available as a virtual memory address. int fd = open("/dev/mem", O_RDWR); if (fd < 0) { log_.log(core::LogLevel::kFatal, "opening /dev/mem failed"); return std::nullopt; } + // Get the memory mapping of the GPIO pin. gpio_addr = mmap(0, pinSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); if (gpio_addr == MAP_FAILED) { log_.log(core::LogLevel::kFatal, "mmap failed"); @@ -81,6 +77,8 @@ std::optional> HardwareGpio::getReader(const std::u const std::uint64_t base = reinterpret_cast(gpio_addr); // pinRead is the hardware specified address for reading. gpio_read = reinterpret_cast(base + pinRead); + + // Keep track of intialized pins InitializedReaders[pin] = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); std::shared_ptr reader = InitializedReaders[pin]; @@ -89,6 +87,7 @@ std::optional> HardwareGpio::getReader(const std::u std::optional> HardwareGpio::getWriter(const std::uint8_t pin) { + // Check if pin is already initialized if (InitializedWriters.count(pin) != 0) { std::shared_ptr writer = InitializedWriters[pin]; return writer; diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index bf432cc6..54eb476f 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -8,8 +8,17 @@ namespace hyped::io { +// GPIO hardware specified addresses and sizes for read, clear, set, size, etc. +static constexpr std::uint32_t pinSize = 0x1000; +static constexpr std::uint32_t pinRead = 0x138; +static constexpr std::uint32_t pinClear = 0x190; +static constexpr std::uint32_t pinSet = 0x194; + class HardwareGpioReader : public IGpioReader { public: + /** + * @brief Read a high or low from the GPIO pin. + */ virtual std::optional read(); private: @@ -25,6 +34,10 @@ class HardwareGpioReader : public IGpioReader { class HardwareGpioWriter : public IGpioWriter { public: + /** + * @brief Writes a high or low to the GPIO pin. + * @param state The digital signal to write to the pin. + */ virtual core::Result write(const core::DigitalSignal state); private: @@ -42,6 +55,11 @@ class HardwareGpioWriter : public IGpioWriter { friend class HardwareGpio; }; +/** + * Hardware GPIO interface, requires physical GPIO pins to be present. This should only + * be instantiated at the top level and then provided to users through the IGpio interface. + * Ensure inputted pins are defined as pin = 32*X + Y (GPIOX_Y) + */ class HardwareGpio { public: HardwareGpio(core::ILogger &log); @@ -50,6 +68,12 @@ class HardwareGpio { virtual std::optional> getWriter(const std::uint8_t pin); private: + /** + * @brief Initialises the GPIO pin for reading or writing. + * @param pin The pin to initialise. + * @param edge The edge to trigger on. Defaults to "both". + * @param direction The direction of the pin. + */ core::ILogger &log_; // Bank Addresses are header base addresses. // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible @@ -58,10 +82,6 @@ class HardwareGpio { std::unordered_map> InitializedWriters; std::unordered_map> InitializedReaders; // Also hardware specified addresses and sizes for read, clear, set, size, etc. - static constexpr std::uint32_t pinSize = 0x1000; - static constexpr std::uint32_t pinRead = 0x138; - static constexpr std::uint32_t pinClear = 0x190; - static constexpr std::uint32_t pinSet = 0x194; }; } // namespace hyped::io From 07869e0897aa51f579c74ca13808785f56246acc Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Jan 2023 18:20:54 +0000 Subject: [PATCH 17/22] ClangFormatted --- lib/io/hardware_gpio.hpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 54eb476f..44677612 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -68,12 +68,7 @@ class HardwareGpio { virtual std::optional> getWriter(const std::uint8_t pin); private: - /** - * @brief Initialises the GPIO pin for reading or writing. - * @param pin The pin to initialise. - * @param edge The edge to trigger on. Defaults to "both". - * @param direction The direction of the pin. - */ + core::ILogger &log_; // Bank Addresses are header base addresses. // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible From ad58a8420112cf85ca828652a6499b65ada25e78 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Jan 2023 18:23:27 +0000 Subject: [PATCH 18/22] CF --- lib/io/hardware_gpio.cpp | 8 ++++---- lib/io/hardware_gpio.hpp | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 40bdb7eb..21d57275 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -12,7 +12,7 @@ std::optional HardwareGpioReader::read() // pinMap just 0000.... with 1 flipped in pin number. // So AND with readAddr to extract the specific pin const std::uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; - + if (out > 0) { return core::DigitalSignal::kHigh; } else { @@ -31,10 +31,10 @@ core::Result HardwareGpioWriter::write(const core::DigitalSignal state) return core::Result::kSuccess; } -HardwareGpio::HardwareGpio(core::ILogger &log) : log_(log) -{} +HardwareGpio::HardwareGpio(core::ILogger &log) + : log_(log) -std::optional> HardwareGpio::getReader(const std::uint8_t pin) + std::optional> HardwareGpio::getReader(const std::uint8_t pin) { // What happens if all shared pointers are removed and this is called? // Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 44677612..da8a687f 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -16,7 +16,7 @@ static constexpr std::uint32_t pinSet = 0x194; class HardwareGpioReader : public IGpioReader { public: - /** + /** * @brief Read a high or low from the GPIO pin. */ virtual std::optional read(); @@ -34,7 +34,7 @@ class HardwareGpioReader : public IGpioReader { class HardwareGpioWriter : public IGpioWriter { public: - /** + /** * @brief Writes a high or low to the GPIO pin. * @param state The digital signal to write to the pin. */ @@ -68,7 +68,6 @@ class HardwareGpio { virtual std::optional> getWriter(const std::uint8_t pin); private: - core::ILogger &log_; // Bank Addresses are header base addresses. // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible From ed16431e3aae699313c1f55f477850e94c323192 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Jan 2023 18:28:01 +0000 Subject: [PATCH 19/22] cf2 --- lib/io/hardware_gpio.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 21d57275..7f30272f 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -31,10 +31,11 @@ core::Result HardwareGpioWriter::write(const core::DigitalSignal state) return core::Result::kSuccess; } -HardwareGpio::HardwareGpio(core::ILogger &log) - : log_(log) +HardwareGpio::HardwareGpio(core::ILogger &log) : log_(log) +{ +} - std::optional> HardwareGpio::getReader(const std::uint8_t pin) +std::optional> HardwareGpio::getReader(const std::uint8_t pin) { // What happens if all shared pointers are removed and this is called? // Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. From 032ea6226676247af65425f257e61d0b6f8c1186 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Jan 2023 18:33:46 +0000 Subject: [PATCH 20/22] MacChanges? --- lib/io/i2c.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/io/i2c.cpp b/lib/io/i2c.cpp index a9a6517e..4a87183c 100644 --- a/lib/io/i2c.cpp +++ b/lib/io/i2c.cpp @@ -16,7 +16,7 @@ namespace hyped::io { I2c::I2c(const std::uint8_t bus_address, core::ILogger &log) : sensor_address_(0), log_(log) { char path[13]; // up to "/dev/i2c-2" - sprintf(path, "/dev/i2c-%d", bus_address); + snprintf(path, sizeof(path), "/dev/i2c-%d", bus_address); file_descriptor_ = open(path, O_RDWR, 0); if (file_descriptor_ < 0) { /* log "Could not open i2c device" */ }; From 646a4e1cf27f5d37fb5e4f80140d7642449d96a1 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 6 Feb 2023 19:14:43 +0000 Subject: [PATCH 21/22] Style fixes for most done. Will discuss about some changes. --- lib/io/hardware_gpio.cpp | 51 ++++++++++++++++++++-------------------- lib/io/hardware_gpio.hpp | 24 +++++++++---------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 7f30272f..87b66ec2 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -11,22 +11,22 @@ std::optional HardwareGpioReader::read() { // pinMap just 0000.... with 1 flipped in pin number. // So AND with readAddr to extract the specific pin - const std::uint8_t out = *gpio_readAddr & pinMAP ? 1 : 0; - - if (out > 0) { + const std::uint8_t out = 0; + if (*gpio_readAddr & pin_map){ return core::DigitalSignal::kHigh; } else { return core::DigitalSignal::kLow; } + } core::Result HardwareGpioWriter::write(const core::DigitalSignal state) { // Set and Clear are seperate registers. if (state == core::DigitalSignal::kHigh) { - *gpio_setAddr = pinMAP; + *gpio_setAddr = pin_map; } else { - *gpio_clearAddr = pinMAP; + *gpio_clearAddr = pin_map; } return core::Result::kSuccess; } @@ -39,8 +39,8 @@ std::optional> HardwareGpio::getReader(const std::u { // What happens if all shared pointers are removed and this is called? // Map solves this, GPIO will always hold one pointer so it dosen't get destroyed. - if (InitializedReaders.count(pin) != 0) { - std::shared_ptr reader = InitializedReaders[pin]; + if (initialized_readers_.count(pin) != 0) { + std::shared_ptr reader = initialized_readers_[pin]; return reader; } @@ -48,16 +48,16 @@ std::optional> HardwareGpio::getReader(const std::u // Integer divison to get bank number const std::uint32_t bank = pin / 32; // Modulo by 32 gets us the ID of the pin relative to the bank - const std::uint32_t pinID = pin % 32; + const std::uint32_t pin_id = pin % 32; // Gpio addresses contain 32 pins, so we use pinmap to specify specific pin. - const std::uint32_t pinMAP = (1 << pinID); + const std::uint32_t pin_map = (1 << pin_id); if (bank > 3) { log_.log(core::LogLevel::kFatal, "invalid pin number"); return std::nullopt; } // Get memory address from bank address - const off_t pinAddress = bankAddresses[bank]; + const off_t pin_address = bank_addresses[bank]; volatile void *gpio_addr; volatile std::uint32_t *gpio_read; @@ -69,7 +69,7 @@ std::optional> HardwareGpio::getReader(const std::u } // Get the memory mapping of the GPIO pin. - gpio_addr = mmap(0, pinSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + gpio_addr = mmap(0, pin_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pin_address); if (gpio_addr == MAP_FAILED) { log_.log(core::LogLevel::kFatal, "mmap failed"); return std::nullopt; @@ -77,28 +77,27 @@ std::optional> HardwareGpio::getReader(const std::u // Type conversion for address adding from void const std::uint64_t base = reinterpret_cast(gpio_addr); // pinRead is the hardware specified address for reading. - gpio_read = reinterpret_cast(base + pinRead); + gpio_read = reinterpret_cast(base + pin_read); // Keep track of intialized pins - InitializedReaders[pin] - = std::shared_ptr(new HardwareGpioReader(pinMAP, gpio_read)); - std::shared_ptr reader = InitializedReaders[pin]; + initialized_readers_[pin] = std::shared_ptr(new HardwareGpioReader(pin_map, gpio_read)); + std::shared_ptr reader = initialized_readers_[pin]; return reader; } std::optional> HardwareGpio::getWriter(const std::uint8_t pin) { // Check if pin is already initialized - if (InitializedWriters.count(pin) != 0) { - std::shared_ptr writer = InitializedWriters[pin]; + if (initialized_writers_.count(pin) != 0) { + std::shared_ptr writer = initialized_writers_[pin]; return writer; } const std::uint32_t bank = pin / 32; - const std::uint32_t pinID = pin % 32; - const std::uint32_t pinMAP = (1 << pinID); + const std::uint32_t pin_id = pin % 32; + const std::uint32_t pin_map = (1 << pin_id); - const off_t pinAddress = bankAddresses[bank]; + const off_t pin_address = bank_addresses[bank]; volatile void *gpio_addr; volatile std::uint32_t *gpio_set; volatile std::uint32_t *gpio_clear; @@ -106,20 +105,20 @@ std::optional> HardwareGpio::getWriter(const std::u int fd = open("/dev/mem", O_RDWR); if (fd < 0) { return std::nullopt; } - gpio_addr = mmap(0, pinSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pinAddress); + gpio_addr = mmap(0, pin_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pin_address); if (gpio_addr == MAP_FAILED) { return std::nullopt; } const std::uint64_t base = reinterpret_cast(gpio_addr); // pinset is the hardware specified address for reading. - gpio_set = reinterpret_cast(base + pinSet); + gpio_set = reinterpret_cast(base + pin_set); // pinclear is the hardware specified address for reading. - gpio_clear = reinterpret_cast(base + pinClear); + gpio_clear = reinterpret_cast(base + pin_clear); - InitializedWriters[pin] - = std::shared_ptr(new HardwareGpioWriter(pinMAP, gpio_set, gpio_clear)); - std::shared_ptr writer = InitializedWriters[pin]; + initialized_writers_[pin] + = std::shared_ptr(new HardwareGpioWriter(pin_map, gpio_set, gpio_clear)); + std::shared_ptr writer = initialized_writers_[pin]; return writer; } diff --git a/lib/io/hardware_gpio.hpp b/lib/io/hardware_gpio.hpp index 5d0499d9..e246c0fd 100644 --- a/lib/io/hardware_gpio.hpp +++ b/lib/io/hardware_gpio.hpp @@ -9,10 +9,10 @@ namespace hyped::io { // GPIO hardware specified addresses and sizes for read, clear, set, size, etc. -static constexpr std::uint32_t pinSize = 0x1000; -static constexpr std::uint32_t pinRead = 0x138; -static constexpr std::uint32_t pinClear = 0x190; -static constexpr std::uint32_t pinSet = 0x194; +static constexpr std::uint32_t pin_size = 0x1000; +static constexpr std::uint32_t pin_read = 0x138; +static constexpr std::uint32_t pin_clear = 0x190; +static constexpr std::uint32_t pin_set = 0x194; class HardwareGpioReader : public IGpioReader { public: @@ -22,11 +22,11 @@ class HardwareGpioReader : public IGpioReader { virtual std::optional read(); private: - HardwareGpioReader(std::uint8_t pin, volatile std::uint32_t *read) - : pinMAP(pin), + HardwareGpioReader(const std::uint8_t pin, volatile std::uint32_t *read) + : pin_map(pin), gpio_readAddr(read){}; - const std::uint8_t pinMAP; + const std::uint8_t pin_map; volatile std::uint32_t *gpio_readAddr; friend class HardwareGpio; @@ -44,11 +44,11 @@ class HardwareGpioWriter : public IGpioWriter { HardwareGpioWriter(const std::uint8_t pin, volatile std::uint32_t *set, volatile std::uint32_t *clear) - : pinMAP(pin), + : pin_map(pin), gpio_setAddr(set), gpio_clearAddr(clear){}; - const std::uint8_t pinMAP; + const std::uint8_t pin_map; volatile std::uint32_t *gpio_setAddr; volatile std::uint32_t *gpio_clearAddr; @@ -72,9 +72,9 @@ class HardwareGpio { // Bank Addresses are header base addresses. // Page 211-213 Figure 6-7/8 P8 Header Pins Beaglebone Bible - const off_t bankAddresses[4] = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; - std::unordered_map> InitializedWriters; - std::unordered_map> InitializedReaders; + const std::array bank_addresses = {0x44e07000, 0x4804c000, 0x481ac000, 0x481ae000}; + std::unordered_map> initialized_writers_; + std::unordered_map> initialized_readers_; // Also hardware specified addresses and sizes for read, clear, set, size, etc. }; From b53e8c01eca983b9c3bfbd013983e8e9212ae926 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 Feb 2023 18:12:42 +0000 Subject: [PATCH 22/22] clang --- lib/io/hardware_gpio.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/io/hardware_gpio.cpp b/lib/io/hardware_gpio.cpp index 87b66ec2..415b7d84 100644 --- a/lib/io/hardware_gpio.cpp +++ b/lib/io/hardware_gpio.cpp @@ -12,12 +12,11 @@ std::optional HardwareGpioReader::read() // pinMap just 0000.... with 1 flipped in pin number. // So AND with readAddr to extract the specific pin const std::uint8_t out = 0; - if (*gpio_readAddr & pin_map){ + if (*gpio_readAddr & pin_map) { return core::DigitalSignal::kHigh; } else { return core::DigitalSignal::kLow; } - } core::Result HardwareGpioWriter::write(const core::DigitalSignal state) @@ -80,7 +79,8 @@ std::optional> HardwareGpio::getReader(const std::u gpio_read = reinterpret_cast(base + pin_read); // Keep track of intialized pins - initialized_readers_[pin] = std::shared_ptr(new HardwareGpioReader(pin_map, gpio_read)); + initialized_readers_[pin] + = std::shared_ptr(new HardwareGpioReader(pin_map, gpio_read)); std::shared_ptr reader = initialized_readers_[pin]; return reader; } @@ -93,7 +93,7 @@ std::optional> HardwareGpio::getWriter(const std::u return writer; } - const std::uint32_t bank = pin / 32; + const std::uint32_t bank = pin / 32; const std::uint32_t pin_id = pin % 32; const std::uint32_t pin_map = (1 << pin_id);