Commit e002454b authored by Projects's avatar Projects

lcd: Fixed the tearing effect (at least in FreeRTOS).

parent 6e04225a
......@@ -36,6 +36,10 @@
#include <em_rtc.h>
#include <em_timer.h>
#ifdef FREERTOS
xSemaphoreHandle lcd_sem;
#endif /* FREERTOS */
// Frame buffer - pixels are stored as consecutive rows
uint8_t lcd_buffer[LCD_BUF_SIZE];
uint8_t * const off_buffer = lcd_buffer + LCD_CONTROL_BYTES;
......@@ -147,6 +151,13 @@ void lcd_init(void)
{
uint16_t cmd;
#ifdef FREERTOS
lcd_sem = xSemaphoreCreateMutex();
if(lcd_sem == NULL) {
// TODO oops..
}
#endif /* FREERTOS */
spi_init();
// TODO I am pretty sure, it will be already initialized somewhere..
CMU_ClockEnable(cmuClock_GPIO, true);
......@@ -206,6 +217,11 @@ void lcd_clear(void)
uint32_t *p = (uint32_t*)lcd_buffer;
uint16_t x, y;
#ifdef FREERTOS
if(xSemaphoreTake(lcd_sem, LCD_SEM_TICKS) != pdTRUE)
return;
#endif /* FREERTOS */
for(y = 0; y < LCD_HEIGHT; ++y) {
// skip control bytes
p = (uint32_t*)((uint8_t*)p + 2);
......@@ -215,6 +231,10 @@ void lcd_clear(void)
*p++ = 0x00;
}
}
#ifdef FREERTOS
xSemaphoreGive(lcd_sem);
#endif /* FREERTOS */
}
void lcd_update(void)
......
......@@ -30,6 +30,14 @@
#include "em_gpio.h"
#ifdef FREERTOS
#include <FreeRTOS.h>
#include <semphr.h>
///> How long should we wait for the semaphore
#define LCD_SEM_TICKS 100
extern xSemaphoreHandle lcd_sem;
#endif /* FREERTOS */
// Dimensions
#define LCD_HEIGHT 128
#define LCD_WIDTH 128
......
......@@ -56,6 +56,10 @@ static void lcd_dma_tx_complete(unsigned int channel, bool primary, void *user)
(void) user;
dma_transfer_active = false;
#ifdef FREERTOS
xSemaphoreGive(lcd_sem);
#endif /* FREERTOS */
}
void lcd_dma_init(void)
......@@ -110,10 +114,17 @@ void lcd_dma_init(void)
void lcd_dma_send_frame(void)
{
#ifdef FREERTOS
if(xSemaphoreTake(lcd_sem, LCD_SEM_TICKS) != pdTRUE)
return;
#else
while(dma_transfer_active);
#endif /* else FREERTOS */
dma_transfer_active = true;
DMA_ActivateScatterGather(DMA_CHANNEL, true, dma_cfg_block, DMA_TRANSFERS);
// semaphore is given back in the DMA transfer finished interrupt
}
bool lcd_dma_is_active(void)
......
......@@ -96,7 +96,7 @@ DEPFLAGS = -MMD -MP -MF $(@:.o=.d)
override CFLAGS += -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb \
-mfix-cortex-m3-ldrd -ffunction-sections \
-fdata-sections -fomit-frame-pointer -DGCC_ARMCM3 \
$(DEPFLAGS)
-DFREERTOS $(DEPFLAGS)
override ASMFLAGS += -x assembler-with-cpp -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb
......@@ -107,7 +107,7 @@ override LDFLAGS += -Xlinker -Map=$(LST_DIR)/$(PROJECTNAME).map -mcpu=cortex-m3
-mthumb -T../common/Device/EnergyMicro/EFM32GG/Source/GCC/efm32gg.ld \
-Wl,--gc-sections
LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
INCLUDEPATHS += \
-Isrc \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment