Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ (corevideo): Replace const struct with namespace for constexpr values #392

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/CoreVideo/include/CGPixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct CGPixel {
void draw(CGColor color)
{
uintptr_t destination_address =
lcd::frame_buffer_address + (4 * (coordinates.y * lcd::dimension.width + coordinates.x));
lcd::frame_buffer_address + (4 * (coordinates.y * lcd::dimension::width + coordinates.x));
uint32_t destinationColor = color.getARGB();

corell.rawMemoryWrite(destination_address, destinationColor);
Expand Down
36 changes: 20 additions & 16 deletions drivers/CoreVideo/include/internal/corevideo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@ namespace lcd {

// TODO : this should not depend on OTM driver,
// TODO : it should be instanciated and passed to objects that need it
const struct {
uint16_t width = lcd::otm8009a::landscape::width;
uint16_t height = lcd::otm8009a::landscape::height;
} dimension;
namespace dimension {

constexpr uint16_t width = lcd::otm8009a::landscape::width;
constexpr uint16_t height = lcd::otm8009a::landscape::height;

} // namespace dimension

// TODO : this should not depend on OTM driver,
// TODO : it should be instanciated and passed to objects that need it
const struct {
uint16_t VSA = lcd::otm8009a::landscape::vsync; // Vertical start active time in units of lines
uint16_t VBP = lcd::otm8009a::landscape::vbp; // Vertical Back Porch time in units of lines
uint16_t VFP = lcd::otm8009a::landscape::vfp; // Vertical Front Porch time in units of lines
uint16_t VACT = lcd::otm8009a::landscape::height; // Vertical Active time in units of lines = imageSize Y in
// pixels to display
uint16_t HSA = lcd::otm8009a::landscape::hsync; // Horizontal start active time in units of lcdClk
uint16_t HBP = lcd::otm8009a::landscape::hbp; // Horizontal Back Porch time in units of lcdClk
uint16_t HFP = lcd::otm8009a::landscape::hfp; // Horizontal Front Porch time in units of lcdClk
uint16_t HACT = lcd::otm8009a::landscape::width; // Horizontal Active time in units of lcdClk = imageSize X in
// pixels to display
} property;
namespace property {

constexpr uint16_t VSA = lcd::otm8009a::landscape::vsync; // Vertical start active time in units of lines
constexpr uint16_t VBP = lcd::otm8009a::landscape::vbp; // Vertical Back Porch time in units of lines
constexpr uint16_t VFP = lcd::otm8009a::landscape::vfp; // Vertical Front Porch time in units of lines
constexpr uint16_t VACT = lcd::otm8009a::landscape::height; // Vertical Active time in units of lines =
// imageSize Y in pixels to display
constexpr uint16_t HSA = lcd::otm8009a::landscape::hsync; // Horizontal start active time in units of lcdClk
constexpr uint16_t HBP = lcd::otm8009a::landscape::hbp; // Horizontal Back Porch time in units of lcdClk
constexpr uint16_t HFP = lcd::otm8009a::landscape::hfp; // Horizontal Front Porch time in units of lcdClk
constexpr uint16_t HACT = lcd::otm8009a::landscape::width; // Horizontal Active time in units of lcdClk =
// imageSize X in pixels to display

} // namespace property

} // namespace lcd

Expand Down
2 changes: 1 addition & 1 deletion drivers/CoreVideo/source/CoreDMA2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ auto CoreDMA2D::getHandle() -> DMA2D_HandleTypeDef
void CoreDMA2D::transferDrawing(uintptr_t first_pixel_address, uint32_t width, uint32_t height, uint32_t color)
{
_hdma2d.Init.Mode = DMA2D_R2M;
_hdma2d.Init.OutputOffset = lcd::dimension.width - width;
_hdma2d.Init.OutputOffset = lcd::dimension::width - width;

transferData(color, first_pixel_address, width, height);
}
Expand Down
20 changes: 10 additions & 10 deletions drivers/CoreVideo/source/CoreDSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ CoreDSI::CoreDSI(LKCoreSTM32HalBase &hal) : _hal(hal)
_config.Mode = DSI_VID_MODE_BURST; // Mode Video burst ie : one LgP per line
_config.NullPacketSize = 0xFFF;
_config.NumberOfChunks = 0;
_config.PacketSize = lcd::property.HACT; // Value depending on display orientation choice portrait/landscape
_config.HorizontalSyncActive = (lcd::property.HSA * dsi::laneByteClock_kHz) / dsi::lcdClock;
_config.HorizontalBackPorch = (lcd::property.HBP * dsi::laneByteClock_kHz) / dsi::lcdClock;
_config.HorizontalLine =
((lcd::property.HACT + lcd::property.HSA + lcd::property.HBP + lcd::property.HFP) * dsi::laneByteClock_kHz) /
dsi::lcdClock; // Value depending on display orientation choice portrait/landscape
_config.VerticalSyncActive = lcd::property.VSA;
_config.VerticalBackPorch = lcd::property.VBP;
_config.VerticalFrontPorch = lcd::property.VFP;
_config.VerticalActive = lcd::property.VACT; // Value depending on display orientation choice portrait/landscape
_config.PacketSize = lcd::property::HACT; // Value depending on display orientation choice portrait/landscape
_config.HorizontalSyncActive = (lcd::property::HSA * dsi::laneByteClock_kHz) / dsi::lcdClock;
_config.HorizontalBackPorch = (lcd::property::HBP * dsi::laneByteClock_kHz) / dsi::lcdClock;
_config.HorizontalLine = ((lcd::property::HACT + lcd::property::HSA + lcd::property::HBP + lcd::property::HFP) *
dsi::laneByteClock_kHz) /
dsi::lcdClock; // Value depending on display orientation choice portrait/landscape
_config.VerticalSyncActive = lcd::property::VSA;
_config.VerticalBackPorch = lcd::property::VBP;
_config.VerticalFrontPorch = lcd::property::VFP;
_config.VerticalActive = lcd::property::VACT; // Value depending on display orientation choice portrait/landscape

// Enable or disable sending LP command while streaming is active in video mode
_config.LPCommandEnable = DSI_LP_COMMAND_ENABLE; // Enable sending commands in mode LP (Low Power)
Expand Down
4 changes: 2 additions & 2 deletions drivers/CoreVideo/source/CoreFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ void CoreFont::display(const char *text, uint32_t size, uint32_t starting_line,
character.origin.x += graphics::font_pixel_width;
}

if ((character.origin.x + graphics::font_pixel_width) > lcd::dimension.width) {
if ((character.origin.x + graphics::font_pixel_width) > lcd::dimension::width) {
character.origin.y += graphics::font_pixel_height;
character.origin.x = 0;
}
if ((character.origin.y + graphics::font_pixel_height) > lcd::dimension.height) {
if ((character.origin.y + graphics::font_pixel_height) > lcd::dimension::height) {
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/CoreVideo/source/CoreGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ CoreGraphics::CoreGraphics(interface::DMA2DBase &dma2d) : _dma2d(dma2d) {}
void CoreGraphics::clearScreen(CGColor color)
{
FilledRectangle rect;
rect.width = lcd::dimension.width;
rect.height = lcd::dimension.height;
rect.width = lcd::dimension::width;
rect.height = lcd::dimension::height;

drawRectangle(rect, color);
}

void CoreGraphics::drawRectangle(FilledRectangle rectangle, CGColor color)
{
uintptr_t destination_address =
lcd::frame_buffer_address + 4 * (lcd::dimension.width * rectangle.origin.y + rectangle.origin.x);
lcd::frame_buffer_address + 4 * (lcd::dimension::width * rectangle.origin.y + rectangle.origin.x);

uint32_t destinationColor = color.getARGB();

Expand Down
20 changes: 10 additions & 10 deletions drivers/CoreVideo/source/CoreLTDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ CoreLTDC::CoreLTDC(LKCoreSTM32HalBase &hal, interface::DSIBase &dsi) : _hal(hal)
_hltdc.Instance = LTDC;

// LCD pixel width/height
_hltdc.LayerCfg->ImageWidth = lcd::dimension.width;
_hltdc.LayerCfg->ImageHeight = lcd::dimension.height;
_hltdc.LayerCfg->ImageWidth = lcd::dimension::width;
_hltdc.LayerCfg->ImageHeight = lcd::dimension::height;

// Timing and synchronization
_hltdc.Init.HorizontalSync = (lcd::property.HSA - 1);
_hltdc.Init.AccumulatedHBP = (lcd::property.HSA + lcd::property.HBP - 1);
_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.HorizontalSync = (lcd::property::HSA - 1);
_hltdc.Init.AccumulatedHBP = (lcd::property::HSA + lcd::property::HBP - 1);
_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);

// Background values
_hltdc.Init.Backcolor.Blue = 0;
Expand All @@ -32,9 +32,9 @@ CoreLTDC::CoreLTDC(LKCoreSTM32HalBase &hal, interface::DSIBase &dsi) : _hal(hal)

// Layer config
_layerConfig.WindowX0 = 0;
_layerConfig.WindowX1 = lcd::dimension.width;
_layerConfig.WindowX1 = lcd::dimension::width;
_layerConfig.WindowY0 = 0;
_layerConfig.WindowY1 = lcd::dimension.height;
_layerConfig.WindowY1 = lcd::dimension::height;

_layerConfig.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;

Expand All @@ -50,8 +50,8 @@ CoreLTDC::CoreLTDC(LKCoreSTM32HalBase &hal, interface::DSIBase &dsi) : _hal(hal)
_layerConfig.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
_layerConfig.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;

_layerConfig.ImageWidth = lcd::dimension.width;
_layerConfig.ImageHeight = lcd::dimension.height;
_layerConfig.ImageWidth = lcd::dimension::width;
_layerConfig.ImageHeight = lcd::dimension::height;
}

void CoreLTDC::initialize()
Expand Down
2 changes: 1 addition & 1 deletion drivers/CoreVideo/tests/CGPixel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(CGPixelTest, draw)
CGColor color = CGColor::magenta;

uintptr_t expected_address =
lcd::frame_buffer_address + (4 * (pixel.coordinates.y * lcd::dimension.width + pixel.coordinates.x));
lcd::frame_buffer_address + (4 * (pixel.coordinates.y * lcd::dimension::width + pixel.coordinates.x));
auto expected_data = color.getARGB();

EXPECT_CALL(llmock, rawMemoryWrite(expected_address, expected_data));
Expand Down
20 changes: 10 additions & 10 deletions drivers/CoreVideo/tests/CoreDSI_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ TEST_F(CoreDSITest, handleConfigurationVideoConfigGeneral)
ASSERT_EQ(config.Mode, DSI_VID_MODE_BURST);
ASSERT_EQ(config.NullPacketSize, 0xFFF);
ASSERT_EQ(config.NumberOfChunks, 0);
ASSERT_EQ(config.PacketSize, lcd::property.HACT);
ASSERT_EQ(config.PacketSize, lcd::property::HACT);
}

TEST_F(CoreDSITest, handleConfigurationVideoConfigHorizontal)
{
auto config = coredsi.getConfig();

auto horizontalSyncActive = (lcd::property.HSA * dsi::laneByteClock_kHz) / dsi::lcdClock;
auto horizontalBackPorch = (lcd::property.HBP * dsi::laneByteClock_kHz) / dsi::lcdClock;
auto horizontalLine =
((lcd::property.HACT + lcd::property.HSA + lcd::property.HBP + lcd::property.HFP) * dsi::laneByteClock_kHz) /
dsi::lcdClock;
auto horizontalSyncActive = (lcd::property::HSA * dsi::laneByteClock_kHz) / dsi::lcdClock;
auto horizontalBackPorch = (lcd::property::HBP * dsi::laneByteClock_kHz) / dsi::lcdClock;
auto horizontalLine = ((lcd::property::HACT + lcd::property::HSA + lcd::property::HBP + lcd::property::HFP) *
dsi::laneByteClock_kHz) /
dsi::lcdClock;

ASSERT_EQ(config.HorizontalSyncActive, horizontalSyncActive);
ASSERT_EQ(config.HorizontalBackPorch, horizontalBackPorch);
Expand All @@ -78,10 +78,10 @@ TEST_F(CoreDSITest, handleConfigurationVideoConfigVertical)
{
auto config = coredsi.getConfig();

ASSERT_EQ(config.VerticalSyncActive, lcd::property.VSA);
ASSERT_EQ(config.VerticalBackPorch, lcd::property.VBP);
ASSERT_EQ(config.VerticalFrontPorch, lcd::property.VFP);
ASSERT_EQ(config.VerticalActive, lcd::property.VACT);
ASSERT_EQ(config.VerticalSyncActive, lcd::property::VSA);
ASSERT_EQ(config.VerticalBackPorch, lcd::property::VBP);
ASSERT_EQ(config.VerticalFrontPorch, lcd::property::VFP);
ASSERT_EQ(config.VerticalActive, lcd::property::VACT);
}

TEST_F(CoreDSITest, handleConfigurationVideoConfigLowPower)
Expand Down
4 changes: 2 additions & 2 deletions drivers/CoreVideo/tests/CoreFont_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ TEST_F(CoreFontTest, displayWithScreenWidthReached)
sprintf(buff,
"This sentence is supposed to be on multiple lines because it is too long to be displayed on "
"only one line of the screen.");
uint8_t max_char_per_line = lcd::dimension.width / graphics::font_pixel_width;
uint8_t max_char_per_line = lcd::dimension::width / graphics::font_pixel_width;
ASSERT_GT(text_length, max_char_per_line); // Text to display MUST exceed 47 characters for this test

auto starting_line = 1;
Expand Down Expand Up @@ -297,7 +297,7 @@ TEST_F(CoreFontTest, displayWithScreenHeightReached)

auto starting_line = 20;

auto expected_last_pixel_y_position = lcd::dimension.height;
auto expected_last_pixel_y_position = lcd::dimension::height;

// TODO: This EXPECT_CALL suppress the GMOCK WARNING: Uninteresting mock function call. Remove it in the future
EXPECT_CALL(llmock, rawMemoryWrite).Times(AnyNumber());
Expand Down
6 changes: 3 additions & 3 deletions drivers/CoreVideo/tests/CoreGraphics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_F(CoreGraphicsTest, drawRectangle)
rectangle.height = rectangle_height;

uintptr_t expected_address =
lcd::frame_buffer_address + n_channel * (lcd::dimension.width * starting_pixel_line + starting_pixel_column);
lcd::frame_buffer_address + n_channel * (lcd::dimension::width * starting_pixel_line + starting_pixel_column);

EXPECT_CALL(dma2dmock,
transferDrawing(expected_address, rectangle_width, rectangle_height, expected_color.getARGB()))
Expand All @@ -60,7 +60,7 @@ TEST_F(CoreGraphicsTest, clearScreenDefaultColor)
uintptr_t expected_address = lcd::frame_buffer_address + 0;
auto expected_color = CGColor::white;

EXPECT_CALL(dma2dmock, transferDrawing(expected_address, lcd::dimension.width, lcd::dimension.height,
EXPECT_CALL(dma2dmock, transferDrawing(expected_address, lcd::dimension::width, lcd::dimension::height,
expected_color.getARGB()))
.Times(1);

Expand All @@ -72,7 +72,7 @@ TEST_F(CoreGraphicsTest, clearScreenOtherColor)
uintptr_t expected_address = lcd::frame_buffer_address + 0;
auto expected_color = CGColor::magenta;

EXPECT_CALL(dma2dmock, transferDrawing(expected_address, lcd::dimension.width, lcd::dimension.height,
EXPECT_CALL(dma2dmock, transferDrawing(expected_address, lcd::dimension::width, lcd::dimension::height,
expected_color.getARGB()))
.Times(1);

Expand Down
20 changes: 10 additions & 10 deletions drivers/CoreVideo/tests/CoreLTDC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ TEST_F(CoreLTDCTest, handleConfigurationLayerCfg)
{
auto handle = coreltdc.getHandle();

ASSERT_EQ(handle.LayerCfg->ImageWidth, lcd::dimension.width);
ASSERT_EQ(handle.LayerCfg->ImageHeight, lcd::dimension.height);
ASSERT_EQ(handle.LayerCfg->ImageWidth, lcd::dimension::width);
ASSERT_EQ(handle.LayerCfg->ImageHeight, lcd::dimension::height);
}

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 total_width = (lcd::dimension.width + lcd::property.HSA + lcd::property.HBP + lcd::property.HFP - 1);
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 total_width = (lcd::dimension::width + lcd::property::HSA + lcd::property::HBP + lcd::property::HFP - 1);

ASSERT_EQ(handle.Init.HorizontalSync, horizontal_sync);
ASSERT_EQ(handle.Init.AccumulatedHBP, accumulated_HBP);
Expand All @@ -79,9 +79,9 @@ TEST_F(CoreLTDCTest, setupLayerConfig)
auto layer_config = coreltdc.getLayerConfig();

ASSERT_EQ(layer_config.WindowX0, 0);
ASSERT_EQ(layer_config.WindowX1, lcd::dimension.width);
ASSERT_EQ(layer_config.WindowX1, lcd::dimension::width);
ASSERT_EQ(layer_config.WindowY0, 0);
ASSERT_EQ(layer_config.WindowY1, lcd::dimension.height);
ASSERT_EQ(layer_config.WindowY1, lcd::dimension::height);

ASSERT_EQ(layer_config.PixelFormat, LTDC_PIXEL_FORMAT_ARGB8888);

Expand All @@ -97,8 +97,8 @@ TEST_F(CoreLTDCTest, setupLayerConfig)
ASSERT_EQ(layer_config.BlendingFactor1, LTDC_BLENDING_FACTOR1_PAxCA);
ASSERT_EQ(layer_config.BlendingFactor2, LTDC_BLENDING_FACTOR2_PAxCA);

ASSERT_EQ(layer_config.ImageWidth, lcd::dimension.width);
ASSERT_EQ(layer_config.ImageHeight, lcd::dimension.height);
ASSERT_EQ(layer_config.ImageWidth, lcd::dimension::width);
ASSERT_EQ(layer_config.ImageHeight, lcd::dimension::height);
}

MATCHER_P(WithStructEqualTo, expected, "Compare RCC_PeriphCLKInitTypeDef")
Expand Down
4 changes: 2 additions & 2 deletions libs/LKAnimationKit/source/BouncingSquare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ auto BouncingSquare::squareWillBeOutOfBoundHorizontal() const -> bool
if (_square.origin.x + _shift.horizontal <= 0) {
return true;
}
if (_square.origin.x + _square.width + _shift.horizontal > static_cast<uint32_t>(lcd::dimension.width - 1)) {
if (_square.origin.x + _square.width + _shift.horizontal > static_cast<uint32_t>(lcd::dimension::width - 1)) {
return true;
}
return false;
Expand All @@ -55,7 +55,7 @@ auto BouncingSquare::squareWillBeOutOfBoundVertical() const -> bool
if (_square.origin.y + _shift.vertical <= 0) {
return true;
}
if (_square.origin.y + _square.height + _shift.vertical > static_cast<uint32_t>(lcd::dimension.height - 1)) {
if (_square.origin.y + _square.height + _shift.vertical > static_cast<uint32_t>(lcd::dimension::height - 1)) {
return true;
}
return false;
Expand Down