diff --git a/hal/interfaces/Gpio.cpp b/hal/interfaces/Gpio.cpp index 027d9fd49..308d2f81f 100644 --- a/hal/interfaces/Gpio.cpp +++ b/hal/interfaces/Gpio.cpp @@ -1,4 +1,5 @@ #include "hal/interfaces/Gpio.hpp" +#include "infra/util/Function.hpp" namespace hal { @@ -20,9 +21,9 @@ namespace hal return pin.Get(); } - void InputPin::EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) + void InputPin::EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type) { - pin.EnableInterrupt(action, trigger); + pin.EnableInterrupt(action, trigger, type); } void InputPin::DisableInterrupt() @@ -133,7 +134,7 @@ namespace hal void DummyPin::ResetConfig() {} - void DummyPin::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger) + void DummyPin::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger, InterruptType type) {} void DummyPin::DisableInterrupt() diff --git a/hal/interfaces/Gpio.hpp b/hal/interfaces/Gpio.hpp index 408afea17..bf0aec326 100644 --- a/hal/interfaces/Gpio.hpp +++ b/hal/interfaces/Gpio.hpp @@ -2,6 +2,7 @@ #define HAL_GPIO_HPP #include "infra/util/Function.hpp" +#include namespace hal { @@ -12,6 +13,12 @@ namespace hal bothEdges }; + enum class InterruptType : uint8_t + { + dispatched, + immediate + }; + enum class PinConfigType : uint8_t { input, @@ -40,7 +47,7 @@ namespace hal virtual void Config(PinConfigType config, bool startOutputState) = 0; virtual void ResetConfig() = 0; - virtual void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) = 0; + virtual void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched) = 0; virtual void DisableInterrupt() = 0; }; @@ -54,7 +61,7 @@ namespace hal bool Get() const; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger); + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched); void DisableInterrupt(); private: @@ -110,7 +117,7 @@ namespace hal void Config(PinConfigType config) override; void Config(PinConfigType config, bool startOutputState) override; void ResetConfig() override; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) override; + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched) override; void DisableInterrupt() override; }; diff --git a/hal/interfaces/test_doubles/GpioMock.hpp b/hal/interfaces/test_doubles/GpioMock.hpp index 63b134e89..b663b4bfa 100644 --- a/hal/interfaces/test_doubles/GpioMock.hpp +++ b/hal/interfaces/test_doubles/GpioMock.hpp @@ -2,6 +2,7 @@ #define HAL_GPIO_MOCK_HPP #include "hal/interfaces/Gpio.hpp" +#include "infra/util/Function.hpp" #include "gmock/gmock.h" namespace hal @@ -10,16 +11,16 @@ namespace hal : public GpioPin { public: - MOCK_CONST_METHOD0(Get, bool()); - MOCK_METHOD1(Set, void(bool value)); - MOCK_CONST_METHOD0(GetOutputLatch, bool()); - MOCK_METHOD0(SetAsInput, void()); - MOCK_CONST_METHOD0(IsInput, bool()); - MOCK_METHOD1(Config, void(PinConfigType config)); - MOCK_METHOD2(Config, void(PinConfigType config, bool startOutputState)); - MOCK_METHOD0(ResetConfig, void()); - MOCK_METHOD2(EnableInterrupt, void(const infra::Function& action, InterruptTrigger trigger)); - MOCK_METHOD0(DisableInterrupt, void()); + MOCK_METHOD(bool, Get, (), (const override)); + MOCK_METHOD(void, Set, (bool value), (override)); + MOCK_METHOD(bool, GetOutputLatch, (), (const override)); + MOCK_METHOD(void, SetAsInput, (), (override)); + MOCK_METHOD(bool, IsInput, (), (const override)); + MOCK_METHOD(void, Config, (PinConfigType config), (override)); + MOCK_METHOD(void, Config, (PinConfigType config, bool startOutputState), (override)); + MOCK_METHOD(void, ResetConfig, (), (override)); + MOCK_METHOD(void, EnableInterrupt, (const infra::Function& action, InterruptTrigger trigger, InterruptType type), (override)); + MOCK_METHOD(void, DisableInterrupt, (), (override)); }; } diff --git a/hal/interfaces/test_doubles/GpioStub.cpp b/hal/interfaces/test_doubles/GpioStub.cpp index 2bee4f03a..6a11c7679 100644 --- a/hal/interfaces/test_doubles/GpioStub.cpp +++ b/hal/interfaces/test_doubles/GpioStub.cpp @@ -1,5 +1,11 @@ #include "hal/interfaces/test_doubles/GpioStub.hpp" +#include "hal/interfaces/Gpio.hpp" +#include "infra/timer/Timer.hpp" #include "infra/util/CompareMembers.hpp" +#include "infra/util/Function.hpp" +#include "infra/util/Optional.hpp" +#include +#include namespace hal { @@ -50,7 +56,7 @@ namespace hal void GpioPinStub::ResetConfig() {} - void GpioPinStub::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger) + void GpioPinStub::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger, InterruptType type) { triggerOnChange = std::make_pair(actionOnInterrupt, trigger); } diff --git a/hal/interfaces/test_doubles/GpioStub.hpp b/hal/interfaces/test_doubles/GpioStub.hpp index ec4ff0ee8..33066760d 100644 --- a/hal/interfaces/test_doubles/GpioStub.hpp +++ b/hal/interfaces/test_doubles/GpioStub.hpp @@ -2,12 +2,10 @@ #define HAL_GPIO_STUB_HPP #include "hal/interfaces/Gpio.hpp" -#include "infra/timer/TimerService.hpp" +#include "infra/timer/Timer.hpp" +#include "infra/util/Function.hpp" #include "infra/util/Optional.hpp" -#include "infra/util/VariantDetail.hpp" -#include -#include -#include +#include #include namespace hal @@ -26,7 +24,7 @@ namespace hal void Config(PinConfigType config) override; void Config(PinConfigType config, bool startOutputState) override; void ResetConfig() override; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) override; + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type) override; void DisableInterrupt() override; void SetStubState(bool value); diff --git a/services/util/GpioPinInverted.cpp b/services/util/GpioPinInverted.cpp index 5b3f63702..3f5d74307 100644 --- a/services/util/GpioPinInverted.cpp +++ b/services/util/GpioPinInverted.cpp @@ -1,4 +1,9 @@ #include "services/util/GpioPinInverted.hpp" +#include "hal/interfaces/Gpio.hpp" +#include "infra/util/Function.hpp" +#include +#include +#include namespace services { @@ -46,12 +51,12 @@ namespace services pin.ResetConfig(); } - void GpioPinInverted::EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger) + void GpioPinInverted::EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger, hal::InterruptType type) { static const std::array inverse = { hal::InterruptTrigger::fallingEdge, hal::InterruptTrigger::risingEdge, hal::InterruptTrigger::bothEdges }; assert(static_cast(trigger) < inverse.size()); - pin.EnableInterrupt(action, inverse[static_cast(trigger)]); + pin.EnableInterrupt(action, inverse[static_cast(trigger)], type); } void GpioPinInverted::DisableInterrupt() diff --git a/services/util/GpioPinInverted.hpp b/services/util/GpioPinInverted.hpp index b1e83bfa0..2ba06d08c 100644 --- a/services/util/GpioPinInverted.hpp +++ b/services/util/GpioPinInverted.hpp @@ -2,7 +2,7 @@ #define SERVICES_GPIO_PIN_INVERTED_HPP #include "hal/interfaces/Gpio.hpp" -#include "infra/timer/Timer.hpp" +#include "infra/util/Function.hpp" namespace services { @@ -20,7 +20,7 @@ namespace services void Config(hal::PinConfigType config) override; void Config(hal::PinConfigType config, bool startOutputState) override; void ResetConfig() override; - void EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger) override; + void EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger, hal::InterruptType type) override; void DisableInterrupt() override; private: