Skip to content

Commit

Permalink
♻️ (corevideo): Replace const struct with namespace for constexpr values
Browse files Browse the repository at this point in the history
closes #156
  • Loading branch information
ladislas committed Dec 13, 2021
1 parent 172d2ab commit 60cad2e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 45 deletions.
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
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

0 comments on commit 60cad2e

Please sign in to comment.