Skip to content

Commit

Permalink
♻️ (PWM): Replace suspend/resume by enable/disable DeepSleep
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli authored and ladislas committed Feb 4, 2024
1 parent 2101d0a commit 4d84bb2
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 78 deletions.
4 changes: 0 additions & 4 deletions drivers/CorePwm/include/CorePwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ class CorePwm : public interface::PwmOut

void period(float value) final;

void suspend() final;
void resume() final;

void enableDeepSleep() final;
void disableDeepSleep() final;

private:
mbed::PwmOut _pwm;
bool _is_suspended = false;
};

} // namespace leka
24 changes: 2 additions & 22 deletions drivers/CorePwm/source/CorePwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,12 @@ void CorePwm::period(float value)
_pwm.period(value);
}

void CorePwm::suspend()
{
if (_is_suspended) {
return;
}

_pwm.suspend();
_is_suspended = true;
}

void CorePwm::resume()
{
if (!_is_suspended) {
return;
}

_pwm.resume();
_is_suspended = false;
}

void CorePwm::enableDeepSleep()
{
suspend();
_pwm.suspend();
}

void CorePwm::disableDeepSleep()
{
resume();
_pwm.resume();
}
47 changes: 0 additions & 47 deletions drivers/CorePwm/tests/CorePwm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ TEST(CorePwmTest, initialisation)
auto corepwm = CorePwm {NC};

ASSERT_NE(&corepwm, nullptr);
ASSERT_FALSE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, write)
Expand Down Expand Up @@ -53,52 +52,6 @@ TEST(CorePwmTest, period)
ASSERT_EQ(spy_PwmOut_getPeriod(), value);
}

TEST(CorePwmTest, suspend)
{
auto corepwm = CorePwm {NC};

corepwm.suspend();

ASSERT_TRUE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, suspendThenSuspend)
{
auto corepwm = CorePwm {NC};

corepwm.suspend();
corepwm.suspend();

ASSERT_TRUE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, suspendThenResume)
{
auto corepwm = CorePwm {NC};

corepwm.suspend();

ASSERT_TRUE(spy_PwmOut_isSuspended());

corepwm.resume();

ASSERT_FALSE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, suspendThenResumeThenResume)
{
auto corepwm = CorePwm {NC};

corepwm.suspend();

ASSERT_TRUE(spy_PwmOut_isSuspended());

corepwm.resume();
corepwm.resume();

ASSERT_FALSE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, enableDeepSleep)
{
auto corepwm = CorePwm {NC};
Expand Down
3 changes: 0 additions & 3 deletions include/interface/drivers/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class PwmOut : public interface::DeepSleepEnabled

virtual auto read() -> float = 0;
virtual void write(float value) = 0;

virtual void suspend() = 0;
virtual void resume() = 0;
};

} // namespace leka::interface
2 changes: 0 additions & 2 deletions tests/unit/mocks/mocks/leka/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class PwmOut : public interface::PwmOut
MOCK_METHOD(float, read, (), (override));
MOCK_METHOD(void, write, (float), (override));
MOCK_METHOD(void, period, (float), (override));
MOCK_METHOD(void, suspend, (), (override));
MOCK_METHOD(void, resume, (), (override));
MOCK_METHOD(void, enableDeepSleep, (), (override));
MOCK_METHOD(void, disableDeepSleep, (), (override));
};
Expand Down

0 comments on commit 4d84bb2

Please sign in to comment.