Skip to content

Commit

Permalink
🔀 Merge branch 'yann/refactor/corevideo/use-pwm-of-leka' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Jan 31, 2024
2 parents fef24f7 + 736a255 commit 85dc80e
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 31 deletions.
3 changes: 2 additions & 1 deletion app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ namespace motors {
namespace display::internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -242,7 +243,7 @@ namespace display::internal {
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
2 changes: 2 additions & 0 deletions drivers/CorePwm/include/CorePwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CorePwm : public interface::PwmOut
auto read() -> float final;
void write(float value) final;

void period(float value) final;

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

Expand Down
5 changes: 5 additions & 0 deletions drivers/CorePwm/source/CorePwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ void CorePwm::write(float value)
_pwm.write(value);
}

void CorePwm::period(float value)
{
_pwm.period(value);
}

void CorePwm::suspend()
{
if (_is_suspended) {
Expand Down
10 changes: 10 additions & 0 deletions drivers/CorePwm/tests/CorePwm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ TEST(CorePwmTest, read)
ASSERT_EQ(val, 0.5f);
}

TEST(CorePwmTest, period)
{
auto corepwm = CorePwm {NC};
auto value = 1.F / 100.F;

corepwm.period(value);

ASSERT_EQ(spy_PwmOut_getPeriod(), value);
}

TEST(CorePwmTest, suspend)
{
auto corepwm = CorePwm {NC};
Expand Down
8 changes: 4 additions & 4 deletions drivers/CoreVideo/include/CoreLCDDriverOTM8009A.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

#include <array>

#include "drivers/PwmOut.h"

#include "interface/DSI.hpp"
#include "interface/LCDDriver.hpp"
#include "interface/drivers/PwmOut.h"

namespace leka {

Expand All @@ -19,7 +18,8 @@ namespace leka {
class CoreLCDDriverOTM8009A : public interface::LCDDriver
{
public:
CoreLCDDriverOTM8009A(interface::DSIBase &dsi, PinName backlight) : _dsi {dsi}, _backlight {backlight} {};
CoreLCDDriverOTM8009A(interface::DSIBase &dsi, interface::PwmOut &backlight)
: _dsi {dsi}, _backlight {backlight} {};

void initialize() final;
void setLandscapeOrientation() final;
Expand All @@ -31,7 +31,7 @@ class CoreLCDDriverOTM8009A : public interface::LCDDriver

private:
interface::DSIBase &_dsi;
mbed::PwmOut _backlight;
interface::PwmOut &_backlight;

float _previous_brightness_value = {1.F};
};
Expand Down
1 change: 1 addition & 0 deletions drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include <array>
#include <cstddef>

#include "rtos/ThisThread.h"

Expand Down
27 changes: 13 additions & 14 deletions drivers/CoreVideo/tests/CoreLCDDriverOTM8009A_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
#include "gtest/gtest.h"
#include "mocks/leka/CoreDSI.h"
#include "mocks/leka/CoreSTM32Hal.h"
#include "stubs/mbed/PwmOut.h"
#include "mocks/leka/PwmOut.h"

using namespace leka;

using ::testing::_;
using ::testing::Args;
using ::testing::ElementsAre;
using ::testing::InSequence;

class CoreOTM8009ATest : public ::testing::Test
{
protected:
CoreOTM8009ATest() : otm(dsimock, PinName::SCREEN_BACKLIGHT_PWM) {}
CoreOTM8009ATest() : otm(dsimock, backlightmock) {}

// void SetUp() override {}
// void TearDown() override {}

mock::PwmOut backlightmock;

mock::CoreDSI dsimock;
CoreLCDDriverOTM8009A otm;
};
Expand All @@ -36,11 +37,10 @@ TEST_F(CoreOTM8009ATest, instantiation)

TEST_F(CoreOTM8009ATest, initialize)
{
EXPECT_CALL(backlightmock, period(0.01F));
EXPECT_CALL(dsimock, write(_)).Times(101);

otm.initialize();

EXPECT_EQ(spy_PwmOut_getPeriod(), 0.01f);
}

TEST_F(CoreOTM8009ATest, setLandscapeOrientation)
Expand Down Expand Up @@ -72,6 +72,7 @@ TEST_F(CoreOTM8009ATest, turnOn)
{
auto expected_instruction_array = ElementsAre(lcd::otm8009a::display::turn_on::command, 0x00);

EXPECT_CALL(backlightmock, write(1));
EXPECT_CALL(dsimock, write(expected_instruction_array)).Times(1);

otm.turnOn();
Expand All @@ -81,34 +82,32 @@ TEST_F(CoreOTM8009ATest, turnOff)
{
auto expected_instruction_array = ElementsAre(lcd::otm8009a::display::turn_off::command, 0x00);

EXPECT_CALL(backlightmock, write(0));
EXPECT_CALL(dsimock, write(expected_instruction_array)).Times(1);

otm.turnOff();
}

TEST_F(CoreOTM8009ATest, setBrightness)
{
otm.setBrightness(0.5);
auto value = 0.5F;
EXPECT_CALL(backlightmock, write(value));

EXPECT_EQ(spy_PwmOut_getValue(), 0.5);
otm.setBrightness(value);
}

TEST_F(CoreOTM8009ATest, setBrightnessTurnOffThenTurnOn)
{
auto initial_brightness_value = 0.4F;

EXPECT_CALL(backlightmock, write(initial_brightness_value));
otm.setBrightness(initial_brightness_value);

EXPECT_EQ(spy_PwmOut_getValue(), initial_brightness_value);

EXPECT_CALL(backlightmock, write(0));
EXPECT_CALL(dsimock, write(_)).Times(1);
otm.turnOff();

EXPECT_EQ(spy_PwmOut_getValue(), 0);
EXPECT_NE(spy_PwmOut_getValue(), initial_brightness_value);

EXPECT_CALL(backlightmock, write(initial_brightness_value));
EXPECT_CALL(dsimock, write(_)).Times(1);
otm.turnOn();

EXPECT_EQ(spy_PwmOut_getValue(), initial_brightness_value);
}
6 changes: 1 addition & 5 deletions drivers/CoreVideo/tests/CoreLCD_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@

#include "gtest/gtest.h"
#include "mocks/leka/CoreLCDDriver.h"
#include "stubs/mbed/PwmOut.h"

using namespace leka;
using ::testing::_;

using ::testing::An;
using ::testing::Args;
using ::testing::AtLeast;
using ::testing::ElementsAre;
using ::testing::InSequence;

class CoreLCDTest : public ::testing::Test
Expand Down
2 changes: 2 additions & 0 deletions include/interface/drivers/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class PwmOut
public:
virtual ~PwmOut() = default;

virtual void period(float value) = 0;

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

Expand Down
3 changes: 2 additions & 1 deletion spikes/lk_activity_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace motors {
namespace display::internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -173,7 +174,7 @@ namespace display::internal {
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
3 changes: 2 additions & 1 deletion spikes/lk_behavior_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ namespace display {
namespace internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -157,7 +158,7 @@ namespace display {
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
1 change: 1 addition & 0 deletions spikes/lk_cg_animations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_link_libraries(spike_lk_cg_animations
CoreVideo
CoreLL
CoreSTM32Hal
CorePwm
FileManagerKit
UIAnimationKit
)
Expand Down
5 changes: 4 additions & 1 deletion spikes/lk_cg_animations/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "CoreLCDDriverOTM8009A.hpp"
#include "CoreLL.h"
#include "CoreLTDC.hpp"
#include "CorePwm.h"
#include "CoreSDRAM.hpp"
#include "CoreSTM32Hal.h"
#include "CoreVideo.hpp"
Expand All @@ -38,6 +39,8 @@ HelloWorld hello;
SDBlockDevice sd_blockdevice(SD_SPI_MOSI, SD_SPI_MISO, SD_SPI_SCK);
FATFileSystem fatfs("fs");

CorePwm backlight(SCREEN_BACKLIGHT_PWM);

CoreLL corell;
CGPixel pixel(corell);
CoreSTM32Hal hal;
Expand All @@ -47,7 +50,7 @@ CoreDSI coredsi(hal);
CoreLTDC coreltdc(hal);
CoreGraphics coregraphics(coredma2d);
CoreFont corefont(pixel);
CoreLCDDriverOTM8009A coreotm(coredsi, PinName::SCREEN_BACKLIGHT_PWM);
CoreLCDDriverOTM8009A coreotm(coredsi, backlight);
CoreLCD corelcd(coreotm);
CoreJPEGModeDMA _corejpegmode {hal};
CoreJPEG corejpeg {hal, _corejpegmode};
Expand Down
3 changes: 2 additions & 1 deletion spikes/lk_command_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ namespace display {
namespace internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -132,7 +133,7 @@ namespace internal {
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
3 changes: 2 additions & 1 deletion spikes/lk_fs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace sd {
namespace display::internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -70,7 +71,7 @@ namespace display::internal {
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
1 change: 1 addition & 0 deletions spikes/lk_lcd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_link_libraries(spike_lk_lcd
CoreVideo
CoreLL
CoreSTM32Hal
CorePwm
EventLoopKit
FileManagerKit
VideoKit
Expand Down
4 changes: 3 additions & 1 deletion spikes/lk_lcd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "CoreLCDDriverOTM8009A.hpp"
#include "CoreLL.h"
#include "CoreLTDC.hpp"
#include "CorePwm.h"
#include "CoreSDRAM.hpp"
#include "CoreSTM32Hal.h"
#include "CoreVideo.hpp"
Expand All @@ -40,6 +41,7 @@ FATFileSystem fatfs("fs");
namespace display::internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -50,7 +52,7 @@ auto coredsi = CoreDSI {hal};
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
3 changes: 2 additions & 1 deletion spikes/lk_reinforcer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ auto motionkit = MotionKit {motor::left, motor::right, imukit, motion::internal:
namespace display::internal {

auto event_loop = EventLoopKit {};
auto backlight = CorePwm {SCREEN_BACKLIGHT_PWM};

auto corell = CoreLL {};
auto pixel = CGPixel {corell};
Expand All @@ -169,7 +170,7 @@ namespace display::internal {
auto coreltdc = CoreLTDC {hal};
auto coregraphics = CoreGraphics {coredma2d};
auto corefont = CoreFont {pixel};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, PinName::SCREEN_BACKLIGHT_PWM};
auto coreotm = CoreLCDDriverOTM8009A {coredsi, backlight};
auto corelcd = CoreLCD {coreotm};
auto _corejpegmode = CoreJPEGModeDMA {hal};
auto corejpeg = CoreJPEG {hal, _corejpegmode};
Expand Down
1 change: 1 addition & 0 deletions tests/unit/mocks/mocks/leka/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PwmOut : public interface::PwmOut
public:
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));
};
Expand Down

0 comments on commit 85dc80e

Please sign in to comment.