Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nickshl/DevCore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornickshl <nicolai.shlapunov@gmail.com>2018-10-14 19:47:53 +0300
committernickshl <nicolai.shlapunov@gmail.com>2018-10-14 19:47:53 +0300
commitb10143629b456256a0b255fccaee21b96d995b31 (patch)
tree883c6a1800fc23dc44013676c2c9e0aec359a4ea /Display
parentdea80e6a1743a02e119fe0a9bb4a00c3e6301d1e (diff)
Some code cleanup
Diffstat (limited to 'Display')
-rw-r--r--Display/DisplayDrv.cpp92
-rw-r--r--Display/Image.cpp2
-rw-r--r--Display/Image.h21
-rw-r--r--Display/Primitives.cpp4
-rw-r--r--Display/Primitives.h4
5 files changed, 65 insertions, 58 deletions
diff --git a/Display/DisplayDrv.cpp b/Display/DisplayDrv.cpp
index 16c1eac..ac75415 100644
--- a/Display/DisplayDrv.cpp
+++ b/Display/DisplayDrv.cpp
@@ -42,12 +42,14 @@ Result DisplayDrv::Setup()
// If deisplay and touchscreen share same SPI
if(tft_hspi == touch_hspi)
{
- // Set prescaler for SPI
- MODIFY_REG(tft_hspi->Instance->CR1, (uint32_t)SPI_CR1_BR_Msk, SPI_BAUDRATEPRESCALER_64);
- // Init touchscreen driver
- touch.Init();
- // Restore prescaler for SPI
- MODIFY_REG(tft_hspi->Instance->CR1, (uint32_t)SPI_CR1_BR_Msk, SPI_BAUDRATEPRESCALER_2);
+ // Read original SPI prescaler
+ uint32_t prescaler = READ_REG(tft_hspi->Instance->CR1) & SPI_CR1_BR_Msk;
+ // Set prescaler for SPI
+ MODIFY_REG(tft_hspi->Instance->CR1, (uint32_t)SPI_CR1_BR_Msk, SPI_BAUDRATEPRESCALER_64);
+ // Init touchscreen driver
+ touch.Init();
+ // Restore prescaler for SPI
+ MODIFY_REG(tft_hspi->Instance->CR1, (uint32_t)SPI_CR1_BR_Msk, prescaler);
}
else
{
@@ -82,48 +84,50 @@ Result DisplayDrv::Loop()
if(screen_update.Take(100U) == Result::RESULT_OK)
{
// Set window for all screen and pointer to first pixel
- LockDisplay();
- // Set address window for all screen
- tft.SetAddrWindow(0, 0, width-1, height-1);
- // For each line/row
- for(int32_t i=0; i < height; i++)
+ if(LockDisplay() == Result::RESULT_OK)
{
- // Clear half of buffer
- memset(scr_buf[i%2], 0x00, sizeof(scr_buf[0]));
- // Take semaphore before draw line
- line_mutex.Lock();
- // Set pointer to first element
- VisObject* p_obj = object_list;
- // Do for all objects
- while(p_obj != nullptr)
+ // Set address window for all screen
+ tft.SetAddrWindow(0, 0, width-1, height-1);
+ // For each line/row
+ for(int32_t i=0; i < height; i++)
{
- // Draw object to buf
- if(update_mode) p_obj->DrawInBufH(scr_buf[i%2], width, i);
- else p_obj->DrawInBufW(scr_buf[i%2], width, i);
- // Set pointer to next object in list
- p_obj = p_obj->p_next;
+ // Clear half of buffer
+ memset(scr_buf[i%2], 0x00, sizeof(scr_buf[0]));
+ // Take semaphore before draw line
+ line_mutex.Lock();
+ // Set pointer to first element
+ VisObject* p_obj = object_list;
+ // Do for all objects
+ while(p_obj != nullptr)
+ {
+ // Draw object to buf
+ if(update_mode) p_obj->DrawInBufH(scr_buf[i%2], width, i);
+ else p_obj->DrawInBufW(scr_buf[i%2], width, i);
+ // Set pointer to next object in list
+ p_obj = p_obj->p_next;
+ }
+ // Give semaphore after changes
+ line_mutex.Release();
+ // Wait until previous transfer complete
+ while(tft.IsTransferComplete() == false) taskYIELD();
+ // Write stream to LCD
+ tft.SpiWriteStream((uint8_t*)scr_buf[i%2], width*tft.GetBytesPerPixel());
+ // DO NOT TRY "OPTIMIZE" CODE !!!
+ // Two "while" cycles used for generate next line when previous line
+ // transfer via SPI to display.
}
- // Give semaphore after changes
- line_mutex.Release();
- // Wait until previous transfer complete
+ // Wait until last transfer complete
while(tft.IsTransferComplete() == false) taskYIELD();
- // Write stream to LCD
- tft.SpiWriteStream((uint8_t*)scr_buf[i%2], width*tft.GetBytesPerPixel());
- // DO NOT TRY "OPTIMIZE" CODE !!!
- // Two "while" cycles used for generate next line when previous line
- // transfer via SPI to display.
- }
- // Wait until last transfer complete
- while(tft.IsTransferComplete() == false) taskYIELD();
- // Pull up CS
- tft.StopTransfer();
- // Give semaphore after draw frame
- UnlockDisplay();
- // Calculate FPS if debug info is ON
- if(DISPLAY_DEBUG_INFO)
- {
- // FPS in format XX.X
- fps_x10 = (1000 * 10) / (HAL_GetTick() - time_ms);
+ // Pull up CS
+ tft.StopTransfer();
+ // Give semaphore after draw frame
+ UnlockDisplay();
+ // Calculate FPS if debug info is ON
+ if(DISPLAY_DEBUG_INFO)
+ {
+ // FPS in format XX.X
+ fps_x10 = (1000 * 10) / (HAL_GetTick() - time_ms);
+ }
}
}
diff --git a/Display/Image.cpp b/Display/Image.cpp
index cc17e54..36c3fb5 100644
--- a/Display/Image.cpp
+++ b/Display/Image.cpp
@@ -29,7 +29,7 @@
// *****************************************************************************
// *** Constructor *********************************************************
// *****************************************************************************
-Image::Image(int32_t x, int32_t y, const ImageDesc& img_dsc) : img_description(img_dsc)
+Image::Image(int32_t x, int32_t y, const ImageDesc& img_dsc)
{
x_start = x;
y_start = y;
diff --git a/Display/Image.h b/Display/Image.h
index 57061bd..67d4ab5 100644
--- a/Display/Image.h
+++ b/Display/Image.h
@@ -84,13 +84,18 @@ class Image : public VisObject
// *************************************************************************
// *** Constructor *****************************************************
// *************************************************************************
+ Image() {};
+
+ // *************************************************************************
+ // *** Constructor *****************************************************
+ // *************************************************************************
Image(int32_t x, int32_t y, const ImageDesc& img_dsc);
// *************************************************************************
// *** Put line in buffer **********************************************
// *************************************************************************
virtual void DrawInBufH(uint16_t* buf, int32_t n, int32_t row, int32_t y = 0);
-
+
// *************************************************************************
// *** Put line in buffer **********************************************
// *************************************************************************
@@ -100,25 +105,23 @@ class Image : public VisObject
// *** Set Horizontal Flip function ************************************
// *************************************************************************
void SetHorizontalFlip(bool flip) {hor_mirror = flip;}
-
+
// *************************************************************************
// *** Set Image function **********************************************
// *************************************************************************
void SetImage(const ImageDesc& img_dsc, bool semaphore_taken = false);
protected:
- // Reference to image description structure
- const ImageDesc& img_description;
// Bits per pixel
- uint8_t bits_per_pixel;
+ uint8_t bits_per_pixel = 0U;
// Pointer to the image
- const void* img;
+ const void* img = nullptr;
// Pointer to the palette
- const uint16_t* palette;
+ const uint16_t* palette = nullptr;
// Transparent color (-1 no transparent colors)
- int32_t transparent_color;
+ int32_t transparent_color = -1;
// Horizontal mirror
- bool hor_mirror;
+ bool hor_mirror = false;
};
// *****************************************************************************
diff --git a/Display/Primitives.cpp b/Display/Primitives.cpp
index 2b7ad57..85ad546 100644
--- a/Display/Primitives.cpp
+++ b/Display/Primitives.cpp
@@ -31,7 +31,7 @@
// *****************************************************************************
// *** Constructor *********************************************************
// *****************************************************************************
-Box::Box(int32_t x, int32_t y, int32_t w, int32_t h, int32_t c, bool is_fill)
+Box::Box(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t c, bool is_fill)
{
SetParams(x, y, w, h, c, is_fill);
}
@@ -39,7 +39,7 @@ Box::Box(int32_t x, int32_t y, int32_t w, int32_t h, int32_t c, bool is_fill)
// *****************************************************************************
// *** SetParams ***********************************************************
// *****************************************************************************
-void Box::SetParams(int32_t x, int32_t y, int32_t w, int32_t h, int32_t c, bool is_fill)
+void Box::SetParams(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t c, bool is_fill)
{
color = c;
x_start = x;
diff --git a/Display/Primitives.h b/Display/Primitives.h
index 2a4e0ee..408c454 100644
--- a/Display/Primitives.h
+++ b/Display/Primitives.h
@@ -58,12 +58,12 @@ class Box : public VisObject
// *************************************************************************
// *** Constructor *****************************************************
// *************************************************************************
- Box(int32_t x, int32_t y, int32_t w, int32_t h, int32_t c, bool is_fill = false);
+ Box(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t c, bool is_fill = false);
// *************************************************************************
// *** SetParams *******************************************************
// *************************************************************************
- void SetParams(int32_t x, int32_t y, int32_t w, int32_t h, int32_t c, bool is_fill = false);
+ void SetParams(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t c, bool is_fill = false);
// *************************************************************************
// *** Put line in buffer **********************************************