Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/videokit/ltdc-init-optimize' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Mar 15, 2022
2 parents 1482395 + 609e47b commit 13a1286
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 47 deletions.
5 changes: 2 additions & 3 deletions drivers/CoreVideo/include/CoreLTDC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ namespace leka {
class CoreLTDC : public interface::LTDCBase
{
public:
CoreLTDC(interface::STM32Hal &hal, interface::DSIBase &dsi);
explicit CoreLTDC(interface::STM32Hal &hal);

void initialize() final;

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

private:
interface::STM32Hal &_hal;
interface::DSIBase &_dsi;

LTDC_HandleTypeDef _hltdc {};
LTDC_LayerCfgTypeDef _layerConfig {};
Expand Down
17 changes: 15 additions & 2 deletions drivers/CoreVideo/source/CoreDSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,27 @@ CoreDSI::CoreDSI(interface::STM32Hal &hal) : _hal(hal)

void CoreDSI::initialize()
{
/** @brief Enable DSI Host and wrapper clocks */
_hal.HAL_RCC_DSI_CLK_ENABLE();

/** @brief Soft Reset the DSI Host and wrapper */
_hal.HAL_RCC_DSI_FORCE_RESET();
_hal.HAL_RCC_DSI_RELEASE_RESET();

/** @brief NVIC configuration for DSI interrupt that is now enabled */
_hal.HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
_hal.HAL_NVIC_EnableIRQ(DSI_IRQn);

reset();

_hal.HAL_DSI_DeInit(&_hdsi);

DSI_PLLInitTypeDef dsiPllInit;

dsiPllInit.PLLNDIV = 100;
dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;

_hal.HAL_DSI_DeInit(&_hdsi);

// Initialize DSI
// DO NOT MOVE to the constructor as LCD initialization
// must be performed in a very specific order
Expand Down
23 changes: 16 additions & 7 deletions drivers/CoreVideo/source/CoreLTDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace leka;

CoreLTDC::CoreLTDC(interface::STM32Hal &hal, interface::DSIBase &dsi) : _hal(hal), _dsi(dsi)
CoreLTDC::CoreLTDC(interface::STM32Hal &hal) : _hal(hal)
{
_hltdc.Instance = LTDC;

Expand All @@ -22,12 +22,21 @@ CoreLTDC::CoreLTDC(interface::STM32Hal &hal, interface::DSIBase &dsi) : _hal(hal
_hltdc.Init.AccumulatedActiveW = (lcd::dimension::width + lcd::property::HSA + lcd::property::HBP - 1);
_hltdc.Init.TotalWidth = (lcd::dimension::width + lcd::property::HSA + lcd::property::HBP + lcd::property::HFP - 1);

_hltdc.Init.VerticalSync = (lcd::property::VSA - 1);
_hltdc.Init.AccumulatedVBP = (lcd::property::VSA + lcd::property::VBP - 1);
_hltdc.Init.AccumulatedActiveH = (lcd::dimension::height + lcd::property::VSA + lcd::property::VBP - 1);
_hltdc.Init.TotalHeigh =
(lcd::dimension::height + lcd::property::VSA + lcd::property::VBP + lcd::property::VFP - 1);

// Background values
_hltdc.Init.Backcolor.Blue = 0;
_hltdc.Init.Backcolor.Green = 0;
_hltdc.Init.Backcolor.Red = 0;

// Misc
// Polarity
_hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AH;
_hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AH;
_hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AH;
_hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;

// Layer config
Expand Down Expand Up @@ -56,11 +65,11 @@ CoreLTDC::CoreLTDC(interface::STM32Hal &hal, interface::DSIBase &dsi) : _hal(hal

void CoreLTDC::initialize()
{
configurePeriphClock();
/** @brief NVIC configuration for LTDC interrupt that is now enabled */
_hal.HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
_hal.HAL_NVIC_EnableIRQ(LTDC_IRQn);

// Get LTDC config from DSI
DSI_VidCfgTypeDef dsi_video_config = _dsi.getConfig();
_hal.HAL_LTDC_StructInitFromVideoConfig(&_hltdc, &dsi_video_config);
configurePeriphClock();

// Initialize LTDC
// This part **must not** be moved to the constructor as LCD
Expand Down Expand Up @@ -92,7 +101,7 @@ void CoreLTDC::configurePeriphClock()
_hal.HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}

auto CoreLTDC::getHandle() const -> LTDC_HandleTypeDef
auto CoreLTDC::getHandle() -> LTDC_HandleTypeDef &
{
return _hltdc;
}
Expand Down
17 changes: 0 additions & 17 deletions drivers/CoreVideo/source/CoreVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,13 @@ CoreVideo::CoreVideo(interface::STM32Hal &hal, interface::SDRAM &coresdram, inte

void CoreVideo::initialize()
{
_coredsi.reset();

/** @brief Enable the LTDC clock */
_hal.HAL_RCC_LTDC_CLK_ENABLE();

/** @brief Toggle Sw reset of LTDC IP */
_hal.HAL_RCC_LTDC_FORCE_RESET();
_hal.HAL_RCC_LTDC_RELEASE_RESET();

/** @brief Enable DSI Host and wrapper clocks */
_hal.HAL_RCC_DSI_CLK_ENABLE();

/** @brief Soft Reset the DSI Host and wrapper */
_hal.HAL_RCC_DSI_FORCE_RESET();
_hal.HAL_RCC_DSI_RELEASE_RESET();

/** @brief NVIC configuration for LTDC interrupt that is now enabled */
_hal.HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
_hal.HAL_NVIC_EnableIRQ(LTDC_IRQn);

/** @brief NVIC configuration for DSI interrupt that is now enabled */
_hal.HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
_hal.HAL_NVIC_EnableIRQ(DSI_IRQn);

_coredsi.initialize();

_coreltdc.initialize();
Expand Down
12 changes: 12 additions & 0 deletions drivers/CoreVideo/tests/CoreDSI_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ TEST_F(CoreDSITest, initializationSequence)
{
{
InSequence seq;

EXPECT_CALL(halmock, HAL_RCC_DSI_CLK_ENABLE).Times(1);
EXPECT_CALL(halmock, HAL_RCC_DSI_FORCE_RESET).Times(1);
EXPECT_CALL(halmock, HAL_RCC_DSI_RELEASE_RESET).Times(1);

EXPECT_CALL(halmock, HAL_NVIC_SetPriority(DSI_IRQn, _, _)).Times(1);
EXPECT_CALL(halmock, HAL_NVIC_EnableIRQ(DSI_IRQn)).Times(1);

EXPECT_CALL(halmock, HAL_RCC_GPIOJ_CLK_ENABLE).Times(1);
EXPECT_CALL(halmock, HAL_GPIO_Init).Times(1);
EXPECT_CALL(halmock, HAL_GPIO_WritePin).Times(2);

EXPECT_CALL(halmock, HAL_DSI_DeInit).Times(1);
EXPECT_CALL(halmock, HAL_DSI_Init).Times(1);
EXPECT_CALL(halmock, HAL_DSI_ConfigVideoMode).Times(1);
Expand Down
38 changes: 30 additions & 8 deletions drivers/CoreVideo/tests/CoreLTDC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ using ::testing::Property;
class CoreLTDCTest : public ::testing::Test
{
protected:
CoreLTDCTest() : coreltdc(halmock, dsimock) {}
CoreLTDCTest() : coreltdc(halmock) {}

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

mock::CoreSTM32Hal halmock;
mock::CoreDSI dsimock;
CoreLTDC coreltdc;
};

Expand Down Expand Up @@ -53,15 +52,25 @@ TEST_F(CoreLTDCTest, handleConfigurationSetupTimingConfig)
{
auto handle = coreltdc.getHandle();

auto horizontal_sync = (lcd::property::HSA - 1);
auto accumulated_HBP = (lcd::property::HSA + lcd::property::HBP - 1);
auto accumulated_activeW = (lcd::dimension::width + lcd::property::HSA + lcd::property::HBP - 1);
auto horizontal_sync = (lcd::property::HSA - 1);
auto accumulated_HBP = (lcd::property::HSA + lcd::property::HBP - 1);
auto accumulated_active_width = (lcd::dimension::width + lcd::property::HSA + lcd::property::HBP - 1);
auto total_width = (lcd::dimension::width + lcd::property::HSA + lcd::property::HBP + lcd::property::HFP - 1);

auto vertical_sync = (lcd::property::VSA - 1);
auto accumulated_VBP = (lcd::property::VSA + lcd::property::VBP - 1);
auto accumulated_active_height = (lcd::dimension::height + lcd::property::VSA + lcd::property::VBP - 1);
auto total_height = (lcd::dimension::height + lcd::property::VSA + lcd::property::VBP + lcd::property::VFP - 1);

ASSERT_EQ(handle.Init.HorizontalSync, horizontal_sync);
ASSERT_EQ(handle.Init.AccumulatedHBP, accumulated_HBP);
ASSERT_EQ(handle.Init.AccumulatedActiveW, accumulated_activeW);
ASSERT_EQ(handle.Init.AccumulatedActiveW, accumulated_active_width);
ASSERT_EQ(handle.Init.TotalWidth, total_width);

ASSERT_EQ(handle.Init.VerticalSync, vertical_sync);
ASSERT_EQ(handle.Init.AccumulatedVBP, accumulated_VBP);
ASSERT_EQ(handle.Init.AccumulatedActiveH, accumulated_active_height);
ASSERT_EQ(handle.Init.TotalHeigh, total_height);
}

TEST_F(CoreLTDCTest, handleConfigurationSetupBackgroundConfig)
Expand All @@ -71,6 +80,15 @@ TEST_F(CoreLTDCTest, handleConfigurationSetupBackgroundConfig)
ASSERT_EQ(handle.Init.Backcolor.Blue, 0);
ASSERT_EQ(handle.Init.Backcolor.Green, 0);
ASSERT_EQ(handle.Init.Backcolor.Red, 0);
}

TEST_F(CoreLTDCTest, handleConfigurationSetupPolarityConfig)
{
auto handle = coreltdc.getHandle();

ASSERT_EQ(handle.Init.HSPolarity, LTDC_HSPOLARITY_AH);
ASSERT_EQ(handle.Init.VSPolarity, LTDC_VSPOLARITY_AH);
ASSERT_EQ(handle.Init.DEPolarity, LTDC_DEPOLARITY_AH);
ASSERT_EQ(handle.Init.PCPolarity, LTDC_PCPOLARITY_IPC);
}

Expand Down Expand Up @@ -131,10 +149,14 @@ TEST_F(CoreLTDCTest, initializationSequence)

{
InSequence seq;

EXPECT_CALL(halmock, HAL_NVIC_SetPriority(LTDC_IRQn, _, _)).Times(1);
EXPECT_CALL(halmock, HAL_NVIC_EnableIRQ(LTDC_IRQn)).Times(1);

EXPECT_CALL(halmock, HAL_RCCEx_PeriphCLKConfig(WithStructEqualTo(expected))).Times(1);
EXPECT_CALL(dsimock, getConfig).Times(1);
EXPECT_CALL(halmock, HAL_LTDC_StructInitFromVideoConfig).Times(1);

EXPECT_CALL(halmock, HAL_LTDC_Init).Times(1);

EXPECT_CALL(halmock, HAL_LTDC_ConfigLayer(_, _, default_layer_id)).Times(1);
}

Expand Down
8 changes: 0 additions & 8 deletions drivers/CoreVideo/tests/CoreVideo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,9 @@ TEST_F(CoreVideoTest, initialization)
{
InSequence seq;

EXPECT_CALL(dsimock, reset).Times(1);
EXPECT_CALL(halmock, HAL_RCC_LTDC_CLK_ENABLE).Times(1);
EXPECT_CALL(halmock, HAL_RCC_LTDC_FORCE_RESET).Times(1);
EXPECT_CALL(halmock, HAL_RCC_LTDC_RELEASE_RESET).Times(1);
EXPECT_CALL(halmock, HAL_RCC_DSI_CLK_ENABLE).Times(1);
EXPECT_CALL(halmock, HAL_RCC_DSI_FORCE_RESET).Times(1);
EXPECT_CALL(halmock, HAL_RCC_DSI_RELEASE_RESET).Times(1);
EXPECT_CALL(halmock, HAL_NVIC_SetPriority(LTDC_IRQn, _, _)).Times(1);
EXPECT_CALL(halmock, HAL_NVIC_EnableIRQ(LTDC_IRQn)).Times(1);
EXPECT_CALL(halmock, HAL_NVIC_SetPriority(DSI_IRQn, _, _)).Times(1);
EXPECT_CALL(halmock, HAL_NVIC_EnableIRQ(DSI_IRQn)).Times(1);
EXPECT_CALL(dsimock, initialize).Times(1);
EXPECT_CALL(ltdcmock, initialize).Times(1);
EXPECT_CALL(dsimock, start).Times(1);
Expand Down
2 changes: 1 addition & 1 deletion spikes/lk_cg_animations/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CoreSTM32Hal hal;
CoreSDRAM coresdram(hal);
CoreDMA2D coredma2d(hal);
CoreDSI coredsi(hal);
CoreLTDC coreltdc(hal, coredsi);
CoreLTDC coreltdc(hal);
CoreGraphics coregraphics(coredma2d);
CoreFont corefont(pixel);
CoreLCDDriverOTM8009A coreotm(coredsi, PinName::SCREEN_BACKLIGHT_PWM);
Expand Down
7 changes: 6 additions & 1 deletion spikes/lk_lcd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CoreSTM32Hal hal;
CoreSDRAM coresdram(hal);
CoreDMA2D coredma2d(hal);
CoreDSI coredsi(hal);
CoreLTDC coreltdc(hal, coredsi);
CoreLTDC coreltdc(hal);
CoreGraphics coregraphics(coredma2d);
CoreFont corefont(pixel);
CoreLCDDriverOTM8009A coreotm(coredsi, PinName::SCREEN_BACKLIGHT_PWM);
Expand All @@ -55,6 +55,11 @@ void DMA2D_IRQHandler(void)
{
HAL_DMA2D_IRQHandler(&coredma2d.getHandle());
}

void LTDC_IRQHandler(void)
{
HAL_LTDC_IRQHandler(&coreltdc.getHandle());
}
}

void registerCallbacks()
Expand Down

0 comments on commit 13a1286

Please sign in to comment.