Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/videokit/prepare-implementation-of-video…
Browse files Browse the repository at this point in the history
…kit' into develop
  • Loading branch information
ladislas committed Apr 27, 2022
2 parents 348f2d4 + a48345f commit 8f36034
Show file tree
Hide file tree
Showing 24 changed files with 347 additions and 44 deletions.
2 changes: 1 addition & 1 deletion drivers/CoreVideo/include/CoreLCD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "drivers/PwmOut.h"

#include "interface/LCD.hpp"
#include "interface/LCDDriver.hpp"
#include "interface/drivers/LCD.hpp"

namespace leka {

Expand Down
2 changes: 1 addition & 1 deletion drivers/CoreVideo/include/CoreLTDC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CoreLTDC : public interface::LTDCBase

void initialize() final;

[[nodiscard]] auto getHandle() -> LTDC_HandleTypeDef &;
[[nodiscard]] auto getHandle() -> LTDC_HandleTypeDef & final;
[[nodiscard]] auto getLayerConfig() const -> LTDC_LayerCfgTypeDef;

private:
Expand Down
48 changes: 39 additions & 9 deletions drivers/CoreVideo/include/CoreVideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,41 @@
#include "interface/Font.hpp"
#include "interface/Graphics.hpp"
#include "interface/JPEG.hpp"
#include "interface/LCD.hpp"
#include "interface/LTDC.hpp"
#include "interface/SDRAM.hpp"
#include "interface/drivers/LCD.hpp"
#include "interface/drivers/STM32Hal.h"
#include "interface/drivers/Video.h"
#include "interface/platform/File.h"

namespace leka {

class CoreVideo
class CoreVideo : public interface::Video
{
public:
CoreVideo(interface::STM32Hal &hal, interface::SDRAM &coresdram, interface::DMA2DBase &coredma2d,
interface::DSIBase &coredsi, interface::LTDCBase &coreltdc, interface::LCD &corelcd,
interface::Graphics &coregraphics, interface::Font &corefont, interface::JPEGBase &corejpeg);

void initialize();
void initialize() final;

void turnOff();
void turnOn();
void turnOff() final;
void turnOn() final;

void setBrightness(float value);
void setBrightness(float value) final;

void clearScreen(CGColor color = CGColor::white);
void clearScreen() final;
void clearScreen(CGColor color);
void displayRectangle(interface::Graphics::FilledRectangle rectangle, CGColor color);
void displayImage(interface::File &file);
void playVideo(interface::File &file);
void displayImage(interface::File &file) final;
void playVideo(interface::File &file) final;
void displayText(const char *text, uint32_t size, uint32_t starting_line, CGColor foreground = CGColor::black,
CGColor background = CGColor::white);

auto getDMA2DHandle() -> DMA2D_HandleTypeDef &;
auto getLTDCHandle() -> LTDC_HandleTypeDef &;
auto getJPEGHandle() -> JPEG_HandleTypeDef &;

private:
interface::STM32Hal &_hal;
interface::SDRAM &_coresdram;
Expand All @@ -50,4 +56,28 @@ class CoreVideo
interface::JPEGBase &_corejpeg;
};

#define HAL_VIDEO_DECLARE_IRQ_HANDLERS(instance) \
extern "C" { \
void DMA2D_IRQHandler(void) \
{ \
HAL_DMA2D_IRQHandler(&instance.getDMA2DHandle()); \
} \
void LTDC_IRQHandler(void) \
{ \
HAL_LTDC_IRQHandler(&instance.getLTDCHandle()); \
} \
void JPEG_IRQHandler(void) \
{ \
HAL_JPEG_IRQHandler(&instance.getJPEGHandle()); \
} \
void DMA2_Stream0_IRQHandler(void) \
{ \
HAL_DMA_IRQHandler(instance.getJPEGHandle().hdmain); \
} \
void DMA2_Stream1_IRQHandler(void) \
{ \
HAL_DMA_IRQHandler(instance.getJPEGHandle().hdmaout); \
} \
}

} // namespace leka
6 changes: 5 additions & 1 deletion drivers/CoreVideo/include/interface/LTDC.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Leka - LekaOS
// Copyright 2021 APF France handicap
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "interface/drivers/STM32Hal.h"

namespace leka::interface {

class LTDCBase
{
public:
virtual ~LTDCBase() = default;
virtual void initialize() = 0;

virtual auto getHandle() -> LTDC_HandleTypeDef & = 0;
};

} // namespace leka::interface
20 changes: 20 additions & 0 deletions drivers/CoreVideo/source/CoreVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ void CoreVideo::setBrightness(float value)
_corelcd.setBrightness(value);
}

void CoreVideo::clearScreen()
{
clearScreen(CGColor::white);
}

void CoreVideo::clearScreen(CGColor color)
{
_coregraphics.clearScreen(color);
Expand Down Expand Up @@ -102,3 +107,18 @@ void CoreVideo::displayText(const char *text, uint32_t size, uint32_t starting_l
{
_corefont.display(text, size, starting_line, foreground, background);
}

auto CoreVideo::getDMA2DHandle() -> DMA2D_HandleTypeDef &
{
return _coredma2d.getHandle();
}

auto CoreVideo::getLTDCHandle() -> LTDC_HandleTypeDef &
{
return _coreltdc.getHandle();
}

auto CoreVideo::getJPEGHandle() -> JPEG_HandleTypeDef &
{
return _corejpeg.getHandle();
}
29 changes: 27 additions & 2 deletions drivers/CoreVideo/tests/CoreVideo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace leka;
using ::testing::_;
using ::testing::InSequence;
using ::testing::Return;
using ::testing::ReturnRef;

class CoreVideoTest : public ::testing::Test
{
Expand Down Expand Up @@ -117,9 +118,9 @@ TEST_F(CoreVideoTest, setBrightness)
corevideo.setBrightness(brightness_value);
}

TEST_F(CoreVideoTest, clearScreen)
TEST_F(CoreVideoTest, clearScreenDefaultColor)
{
EXPECT_CALL(graphicsmock, clearScreen).Times(1);
EXPECT_CALL(graphicsmock, clearScreen(compareColor(CGColor::white))).Times(1);

corevideo.clearScreen();
}
Expand Down Expand Up @@ -221,3 +222,27 @@ TEST_F(CoreVideoTest, playVideo)

corevideo.playVideo(filemock);
}

TEST_F(CoreVideoTest, getDMA2DHandle)
{
auto expected_handle = DMA2D_HandleTypeDef {};
EXPECT_CALL(dma2dmock, getHandle).WillOnce(ReturnRef(expected_handle));

corevideo.getDMA2DHandle();
}

TEST_F(CoreVideoTest, getLTDCHandle)
{
auto expected_handle = LTDC_HandleTypeDef {};
EXPECT_CALL(ltdcmock, getHandle).WillOnce(ReturnRef(expected_handle));

corevideo.getLTDCHandle();
}

TEST_F(CoreVideoTest, getJPEGHandle)
{
auto expected_handle = JPEG_HandleTypeDef {};
EXPECT_CALL(jpegmock, getHandle).WillOnce(ReturnRef(expected_handle));

corevideo.getJPEGHandle();
}
File renamed without changes.
28 changes: 28 additions & 0 deletions include/interface/drivers/Video.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "interface/platform/File.h"

namespace leka::interface {

class Video
{
public:
virtual ~Video() = default;

virtual void initialize() = 0;

virtual void turnOff() = 0;
virtual void turnOn() = 0;

virtual void setBrightness(float value) = 0;

virtual void clearScreen() = 0;
virtual void displayImage(interface::File &file) = 0;
virtual void playVideo(interface::File &file) = 0;
};

} // namespace leka::interface
27 changes: 27 additions & 0 deletions include/interface/libs/VideoKit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <filesystem>

namespace leka::interface {

class VideoKit
{
public:
virtual ~VideoKit() = default;

virtual void initializeScreen() = 0;

virtual void turnOn() = 0;
virtual void turnOff() = 0;

virtual void displayImage(const std::filesystem::path &path) = 0;

virtual void playVideo(const std::filesystem::path &path, bool must_loop = false) = 0;
virtual void stopVideo() = 0;
};

} // namespace leka::interface
6 changes: 3 additions & 3 deletions libs/BehaviorKit/include/BehaviorKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

#include "CoreMotor.h"
#include "LedKit.h"
#include "VideoKit.h"
#include "interface/libs/VideoKit.h"

namespace leka {

class BehaviorKit
{
public:
explicit BehaviorKit(VideoKit &videokit, LedKit &ledkit, CoreMotor &motor_left, CoreMotor &motor_right)
explicit BehaviorKit(interface::VideoKit &videokit, LedKit &ledkit, CoreMotor &motor_left, CoreMotor &motor_right)
: _videokit(videokit), _ledkit(ledkit), _motor_left(motor_left), _motor_right(motor_right)
{
// nothing do to
Expand Down Expand Up @@ -43,7 +43,7 @@ class BehaviorKit
void stop();

private:
VideoKit &_videokit;
interface::VideoKit &_videokit;
LedKit &_ledkit;
CoreMotor &_motor_left;
CoreMotor &_motor_right;
Expand Down
11 changes: 8 additions & 3 deletions libs/BehaviorKit/tests/BehaviorKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "CorePwm.h"
#include "CoreSPI.h"
#include "LedKit.h"
#include "VideoKit.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mocks/leka/LEDAnimation.h"
#include "mocks/leka/PwmOut.h"
#include "mocks/leka/VideoKit.h"
#include "mocks/mbed/DigitalOut.h"
#include "mocks/mbed/EventFlags.h"

Expand All @@ -25,12 +25,12 @@ using ::testing::InSequence;
class BehaviorKitTest : public ::testing::Test
{
protected:
BehaviorKitTest() : behaviorkit(videokit, ledkit, motor_left, motor_right) {};
BehaviorKitTest() : behaviorkit(mock_videokit, ledkit, motor_left, motor_right) {};

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

VideoKit videokit {};
mock::VideoKit mock_videokit {};

CoreSPI spi {NC, NC, NC, NC};
CoreLED<LedKit::kNumberOfLedsBelt> belt {spi};
Expand Down Expand Up @@ -65,6 +65,7 @@ TEST_F(BehaviorKitTest, spinBlink)
{
static constexpr auto expected_speed = 0.5;

EXPECT_CALL(mock_videokit, playVideo);
{
InSequence seq;

Expand All @@ -90,6 +91,7 @@ TEST_F(BehaviorKitTest, blinkGreen)
{
static constexpr auto expected_speed = 0.5;

EXPECT_CALL(mock_videokit, playVideo);
{
InSequence seq;

Expand Down Expand Up @@ -141,6 +143,8 @@ TEST_F(BehaviorKitTest, spinRight)

TEST_F(BehaviorKitTest, lowBattery)
{
EXPECT_CALL(mock_videokit, displayImage);

behaviorkit.lowBattery();
}

Expand All @@ -150,6 +154,7 @@ TEST_F(BehaviorKitTest, stop)

ledkit.start(&mock_animation);

EXPECT_CALL(mock_videokit, stopVideo);
EXPECT_CALL(mock_animation, stop).Times(1);
EXPECT_CALL(dir_1_left, write(0));
EXPECT_CALL(dir_2_left, write(0));
Expand Down
12 changes: 6 additions & 6 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include "RCLogger.h"
#include "SerialNumberKit.h"
#include "StateMachine.h"
#include "VideoKit.h"
#include "interface/RobotController.h"
#include "interface/drivers/Battery.h"
#include "interface/drivers/FirmwareUpdate.h"
#include "interface/drivers/Timeout.h"
#include "interface/libs/VideoKit.h"

namespace leka {

Expand All @@ -42,8 +42,8 @@ class RobotController : public interface::RobotController

explicit RobotController(interface::Timeout &sleep_timeout, interface::Battery &battery,
SerialNumberKit &serialnumberkit, interface::FirmwareUpdate &firmware_update,
CoreMotor &motor_left, CoreMotor &motor_right, LedKit &ledkit, VideoKit &videokit,
BehaviorKit &behaviorkit, CommandKit &cmdkit)
CoreMotor &motor_left, CoreMotor &motor_right, LedKit &ledkit,
interface::VideoKit &videokit, BehaviorKit &behaviorkit, CommandKit &cmdkit)
: _sleep_timeout(sleep_timeout),
_battery(battery),
_serialnumberkit(serialnumberkit),
Expand Down Expand Up @@ -85,7 +85,7 @@ class RobotController : public interface::RobotController
_behaviorkit.sleeping();
_videokit.turnOn();

_event_queue.call_in(20s, &_videokit, &VideoKit::turnOff);
_event_queue.call_in(20s, &_videokit, &interface::VideoKit::turnOff);
_event_queue.call_in(20s, &_ledkit, &LedKit::stop);
}

Expand Down Expand Up @@ -124,7 +124,7 @@ class RobotController : public interface::RobotController
_battery_kit.onDataUpdated([this](uint8_t level) { onStartChargingBehavior(level); });
_videokit.turnOn();

_event_queue.call_in(1min, &_videokit, &VideoKit::turnOff);
_event_queue.call_in(1min, &_videokit, &interface::VideoKit::turnOff);
_event_queue.call_in(1min, &_ledkit, &LedKit::stop);
}

Expand Down Expand Up @@ -253,7 +253,7 @@ class RobotController : public interface::RobotController
CoreMotor &_motor_left;
CoreMotor &_motor_right;
LedKit &_ledkit;
VideoKit &_videokit;
interface::VideoKit &_videokit;

BehaviorKit &_behaviorkit;
CommandKit &_cmdkit;
Expand Down
Loading

0 comments on commit 8f36034

Please sign in to comment.