ADC debugged and functional now
Added Version interface Added DisplayDevice to create an independent bridge between display app and specific display driver git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@228 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file Display_nhd0420.c
|
||||
/// @file Display.c
|
||||
/// @brief Description
|
||||
// -----------------------------------------------------------------------------
|
||||
// Micro-Key bv
|
||||
@@ -17,7 +17,7 @@
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @file Display_nhd0420.c
|
||||
/// @file Display.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
@@ -34,27 +34,16 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define DISPLAY_TASK_STACK_SIZE (2048)
|
||||
#define DISPLAY_TRANSMIT_MAX_CHUNK (10)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct displayCharacter
|
||||
{
|
||||
char character;
|
||||
bool isUpdated;
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static SemaphoreHandle_t displayShadowAccessSemaphore;
|
||||
|
||||
static struct displayCharacter displayShadow[NHD0420_NUMBER_OF_ROWS][NHD0420_NUMBER_OF_COLUMNS];
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -62,46 +51,47 @@ static struct displayCharacter displayShadow[NHD0420_NUMBER_OF_ROWS][NHD0420_NUM
|
||||
|
||||
static void DisplayTask(void* parameters);
|
||||
|
||||
inline static void Display_characterUpdate (struct displayCharacter* displayCharacter, char character);
|
||||
inline static bool Display_isCharacterUpdated (struct displayCharacter* displayCharacter);
|
||||
inline static char Display_getUpdatedCharacter (struct displayCharacter* displayCharacter);
|
||||
|
||||
static void printfShadow(void);
|
||||
inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character);
|
||||
inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter);
|
||||
inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ErrorStatus Display_construct(struct Display* self, void* displayDriver)
|
||||
ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displayDevice, int TaskPriority, uint16_t stackSize, int maxCharactersPerTransmit)
|
||||
{
|
||||
int rowCounter = 0;
|
||||
int colCounter = 0;
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
// This is of type NHD0420 - Cast is valid only within this C file
|
||||
self->displayDriver = displayDriver;
|
||||
|
||||
self->displayDevice = displayDevice;
|
||||
self->TaskPriority = TaskPriority;
|
||||
self->stackSize = stackSize;
|
||||
self->maxCharactersPerTransmit = maxCharactersPerTransmit;
|
||||
|
||||
// Clear the display shadow
|
||||
for (rowCounter = 0; rowCounter < NHD0420_NUMBER_OF_ROWS; rowCounter++)
|
||||
for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++)
|
||||
{
|
||||
for (colCounter = 0; colCounter < NHD0420_NUMBER_OF_COLUMNS; colCounter++)
|
||||
for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++)
|
||||
{
|
||||
Display_characterUpdate(&displayShadow[rowCounter][colCounter], 0x20);
|
||||
Display_characterUpdate(&self->displayShadow[rowCounter][colCounter], 0x20);
|
||||
}
|
||||
}
|
||||
|
||||
if(returnValue == SUCCESS)
|
||||
{
|
||||
// Create a semaphore to sync access to the display shadow
|
||||
vSemaphoreCreateBinary(displayShadowAccessSemaphore);
|
||||
xSemaphoreGive(displayShadowAccessSemaphore);
|
||||
vSemaphoreCreateBinary(self->displayShadowAccessSemaphore);
|
||||
xSemaphoreGive(self->displayShadowAccessSemaphore);
|
||||
}
|
||||
|
||||
self->runTask = true;
|
||||
|
||||
if(returnValue == SUCCESS)
|
||||
{
|
||||
if (xTaskCreate(DisplayTask, (const char*)"DisplayTask", DISPLAY_TASK_STACK_SIZE, self, self->TaskPriority, self->taskHandle) != pdTRUE)
|
||||
if (xTaskCreate(DisplayTask, (const char*)"DisplayTask", self->stackSize, self, self->TaskPriority, self->taskHandle) != pdTRUE)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
LOGGER_ERROR("Starting display task failed");
|
||||
@@ -112,19 +102,6 @@ ErrorStatus Display_construct(struct Display* self, void* displayDriver)
|
||||
}
|
||||
}
|
||||
|
||||
if(returnValue == SUCCESS)
|
||||
{
|
||||
// If initialisation of module was successful, RESET and adjust the display
|
||||
NHD0420_clearScreen(self->displayDriver);
|
||||
vTaskDelay(5);
|
||||
NHD0420_setContrast(self->displayDriver, 30);
|
||||
vTaskDelay(5);
|
||||
NHD0420_setBacklightBrightness(self->displayDriver, 3);
|
||||
vTaskDelay(5);
|
||||
NHD0420_turnOnDisplay(self->displayDriver);
|
||||
vTaskDelay(5);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@@ -132,18 +109,42 @@ ErrorStatus Display_construct(struct Display* self, void* displayDriver)
|
||||
void Display_destruct(struct Display* self)
|
||||
{
|
||||
self->runTask = false;
|
||||
vSemaphoreDelete(displayShadowAccessSemaphore);
|
||||
vSemaphoreDelete(self->displayShadowAccessSemaphore);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int length, unsigned int row, unsigned int column)
|
||||
ErrorStatus Display_clearScreen(struct Display* self)
|
||||
{
|
||||
return DisplayDevice_clear(self->displayDevice);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Display_setState(struct Display* self, DisplayDevice_functionalState state)
|
||||
{
|
||||
return DisplayDevice_setState(self->displayDevice, state);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Display_setBrightness(struct Display* self, size_t brightness)
|
||||
{
|
||||
return DisplayDevice_setBrightness(self->displayDevice, brightness);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Display_setContrast(struct Display* self, size_t contrast)
|
||||
{
|
||||
return DisplayDevice_setContrast(self->displayDevice, contrast);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int length, size_t row, size_t column)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
// Prior to any action on the display memory, perform necessary checkings
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
// Check that the row coordinate does not exceed the display boundary
|
||||
if (row - 1 >= NHD0420_NUMBER_OF_ROWS)
|
||||
if (row - 1 >= self->displayDevice->parameters.numberOfRows)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
@@ -151,7 +152,7 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
// Check that the column coordinate does not exceed the display boundary
|
||||
if (column - 1 >= NHD0420_NUMBER_OF_COLUMNS)
|
||||
if (column - 1 >= self->displayDevice->parameters.numberOfColumns)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
@@ -160,9 +161,9 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int
|
||||
{
|
||||
// Check that the length request does not exceed the display boundary
|
||||
// This is checked in combination with the column coordinate
|
||||
// NHD0420_NUMBER_OF_COLUMNS - column >= length
|
||||
// numberOfColumns - column >= length
|
||||
// must be valid in order to put the requested message on display
|
||||
if (NHD0420_NUMBER_OF_COLUMNS - (column - 1) < length)
|
||||
if (self->displayDevice->parameters.numberOfColumns - (column - 1) < length)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
@@ -171,34 +172,34 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
// Get the access semaphore to the display memory - wait for access
|
||||
xSemaphoreTake(displayShadowAccessSemaphore, portMAX_DELAY);
|
||||
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
|
||||
|
||||
int loopCounter;
|
||||
for (loopCounter = 0; loopCounter < length; loopCounter++)
|
||||
{
|
||||
Display_characterUpdate(&displayShadow[row - 1][(column - 1) + loopCounter], buffer[loopCounter]);
|
||||
Display_characterUpdate(&self->displayShadow[row - 1][(column - 1) + loopCounter], buffer[loopCounter]);
|
||||
}
|
||||
|
||||
xSemaphoreGive(displayShadowAccessSemaphore);
|
||||
xSemaphoreGive(self->displayShadowAccessSemaphore);
|
||||
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
inline static void Display_characterUpdate (struct displayCharacter* displayCharacter, char character)
|
||||
inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character)
|
||||
{
|
||||
displayCharacter->character = character;
|
||||
displayCharacter->isUpdated = true;
|
||||
}
|
||||
|
||||
|
||||
inline static bool Display_isCharacterUpdated (struct displayCharacter* displayCharacter)
|
||||
inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter)
|
||||
{
|
||||
return displayCharacter->isUpdated;
|
||||
}
|
||||
|
||||
|
||||
inline static char Display_getUpdatedCharacter (struct displayCharacter* displayCharacter)
|
||||
inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter)
|
||||
{
|
||||
displayCharacter->isUpdated = false;
|
||||
return displayCharacter->character;
|
||||
@@ -207,41 +208,43 @@ inline static char Display_getUpdatedCharacter (struct displayCharacter* display
|
||||
|
||||
static void DisplayTask(void* parameters)
|
||||
{
|
||||
const struct Display* self = (const struct Display*)parameters;
|
||||
const struct NHD0420* displayDriver = (const struct NHD0420*)self->displayDriver;
|
||||
struct Display* self = (struct Display*)parameters;
|
||||
|
||||
bool leaveLoops = false;
|
||||
char buffer[NHD0420_NUMBER_OF_COLUMNS];
|
||||
int bufferIndex = 0;
|
||||
int rowCounter = 0;
|
||||
int colCounter = 0;
|
||||
|
||||
size_t rowStart;
|
||||
size_t columnStart;
|
||||
while (self->runTask)
|
||||
{
|
||||
// Get the access semaphore to the shadow - wait until the write function is finished with updating the shadow
|
||||
xSemaphoreTake(displayShadowAccessSemaphore, portMAX_DELAY);
|
||||
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
|
||||
leaveLoops = false;
|
||||
bufferIndex = 0;
|
||||
// printfShadow();
|
||||
|
||||
// Fragment display writing - writing will be done per line
|
||||
for (; colCounter < NHD0420_NUMBER_OF_COLUMNS; colCounter++)
|
||||
for (; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++)
|
||||
{
|
||||
if (Display_isCharacterUpdated(&displayShadow[rowCounter][colCounter]))
|
||||
if (Display_isCharacterUpdated(&self->displayShadow[rowCounter][colCounter]))
|
||||
{
|
||||
// Found a character that has been updated
|
||||
// Put the display cursor at the appropriate coordinates
|
||||
NHD0420_setCursorToPosition(displayDriver, rowCounter + 1, colCounter + 1);
|
||||
for (bufferIndex = 0; (colCounter < NHD0420_NUMBER_OF_COLUMNS); colCounter++, bufferIndex++)
|
||||
rowStart = rowCounter + 1;
|
||||
columnStart = colCounter + 1;
|
||||
for (bufferIndex = 0; (colCounter < self->displayDevice->parameters.numberOfColumns); colCounter++, bufferIndex++)
|
||||
{
|
||||
// Respect the max number of bytes to transmit
|
||||
if (bufferIndex < DISPLAY_TRANSMIT_MAX_CHUNK)
|
||||
if (bufferIndex < self->maxCharactersPerTransmit)
|
||||
{
|
||||
// Still within the boundaries
|
||||
if (Display_isCharacterUpdated(&displayShadow[rowCounter][colCounter]))
|
||||
if (Display_isCharacterUpdated(&self->displayShadow[rowCounter][colCounter]))
|
||||
{
|
||||
// Current character has been updated and must be sent to display
|
||||
// But data from display shadow to transmit buffer
|
||||
buffer[bufferIndex] = Display_getUpdatedCharacter(&displayShadow[rowCounter][colCounter]);
|
||||
buffer[bufferIndex] = Display_getUpdatedCharacter(&self->displayShadow[rowCounter][colCounter]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -272,20 +275,20 @@ static void DisplayTask(void* parameters)
|
||||
}
|
||||
|
||||
// Give back display memory access semaphore to allow new updates
|
||||
xSemaphoreGive(displayShadowAccessSemaphore);
|
||||
xSemaphoreGive(self->displayShadowAccessSemaphore);
|
||||
if (bufferIndex > 0)
|
||||
{
|
||||
// If there was an update found, send it to the display
|
||||
IODevice_write(displayDriver->device, buffer, bufferIndex);
|
||||
DisplayDevice_write(self->displayDevice, buffer, bufferIndex, rowStart, columnStart);
|
||||
}
|
||||
|
||||
// Handle the counters for row and column
|
||||
if (colCounter > (NHD0420_NUMBER_OF_COLUMNS - 1))
|
||||
if (colCounter > (self->displayDevice->parameters.numberOfColumns - 1))
|
||||
{
|
||||
// End of row reached - reset column and increment row
|
||||
colCounter = 0;
|
||||
|
||||
if (rowCounter < (NHD0420_NUMBER_OF_ROWS - 1))
|
||||
if (rowCounter < (self->displayDevice->parameters.numberOfRows - 1))
|
||||
{
|
||||
// Increment row
|
||||
rowCounter++;
|
||||
@@ -296,6 +299,7 @@ static void DisplayTask(void* parameters)
|
||||
rowCounter = 0;
|
||||
}
|
||||
}
|
||||
vTaskDelay(10);
|
||||
}
|
||||
|
||||
// Task has been marked to end - after leaving the endless loop, end/delete this task
|
||||
@@ -303,74 +307,3 @@ static void DisplayTask(void* parameters)
|
||||
|
||||
}
|
||||
|
||||
|
||||
// DEBUG FUNCTION - MIGHT NOT BE NECESSARY LATER ON
|
||||
static void printfShadow(void)
|
||||
{
|
||||
char tempBuffer[21];
|
||||
char flagBuffer[21];
|
||||
int tempLoop;
|
||||
for (tempLoop = 0; tempLoop < 20; tempLoop++)
|
||||
{
|
||||
tempBuffer[tempLoop] = displayShadow[0][tempLoop].character;
|
||||
if (displayShadow[0][tempLoop].isUpdated)
|
||||
{
|
||||
flagBuffer[tempLoop] = '1';
|
||||
}
|
||||
else
|
||||
{
|
||||
flagBuffer[tempLoop] = '0';
|
||||
}
|
||||
}
|
||||
tempBuffer[20] = '\0';
|
||||
flagBuffer[20] = '\0';
|
||||
|
||||
LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer);
|
||||
for (tempLoop = 0; tempLoop < 20; tempLoop++)
|
||||
{
|
||||
tempBuffer[tempLoop] = displayShadow[1][tempLoop].character;
|
||||
if (displayShadow[1][tempLoop].isUpdated)
|
||||
{
|
||||
flagBuffer[tempLoop] = '1';
|
||||
}
|
||||
else
|
||||
{
|
||||
flagBuffer[tempLoop] = '0';
|
||||
}
|
||||
}
|
||||
tempBuffer[20] = '\0';
|
||||
flagBuffer[20] = '\0';
|
||||
|
||||
LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer);
|
||||
for (tempLoop = 0; tempLoop < 20; tempLoop++)
|
||||
{
|
||||
tempBuffer[tempLoop] = displayShadow[2][tempLoop].character;
|
||||
if (displayShadow[2][tempLoop].isUpdated)
|
||||
{
|
||||
flagBuffer[tempLoop] = '1';
|
||||
}
|
||||
else
|
||||
{
|
||||
flagBuffer[tempLoop] = '0';
|
||||
}
|
||||
}
|
||||
tempBuffer[20] = '\0';
|
||||
flagBuffer[20] = '\0';
|
||||
|
||||
LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer);
|
||||
for (tempLoop = 0; tempLoop < 20; tempLoop++)
|
||||
{
|
||||
tempBuffer[tempLoop] = displayShadow[3][tempLoop].character;
|
||||
if (displayShadow[3][tempLoop].isUpdated)
|
||||
{
|
||||
flagBuffer[tempLoop] = '1';
|
||||
}
|
||||
else
|
||||
{
|
||||
flagBuffer[tempLoop] = '0';
|
||||
}
|
||||
}
|
||||
tempBuffer[20] = '\0';
|
||||
flagBuffer[20] = '\0';
|
||||
LOGGER_DEBUG("%s -- %s", tempBuffer, flagBuffer);
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <FreeRTOSFixes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// FreeRTOS includes
|
||||
#include "FreeRTOS.h"
|
||||
@@ -38,17 +39,20 @@
|
||||
#include "misc.h"
|
||||
#include "stm32f10x_rcc.h"
|
||||
|
||||
#include "DisplayDevice.h"
|
||||
#include "MAX5715.h"
|
||||
#include "nhd0420.h"
|
||||
#include "keypadMatrix.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "adc.h"
|
||||
#include "IODevice.h"
|
||||
#include "keypadMatrix.h"
|
||||
#include "led.h"
|
||||
#include "PCBA.h"
|
||||
#include "uart.h"
|
||||
#include "spi.h"
|
||||
#include "spiDevice.h"
|
||||
#include "Version.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -132,8 +136,10 @@ static void printSystemInfoTask(void* parameters)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
uint16_t adcValue = 0;
|
||||
LOGGER_INFO("---------------------------------------");
|
||||
systeminfoCommandHandler();
|
||||
vTaskDelay(60000);
|
||||
vTaskDelay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +158,8 @@ static ErrorStatus systeminfoCommandHandler(void)
|
||||
OS_logTaskInfo(ledTaskHandle);
|
||||
vTaskDelay(100);
|
||||
OS_logTaskInfo(sysTaskHandle);
|
||||
vTaskDelay(100);
|
||||
OS_logTaskInfo(display.taskHandle);
|
||||
|
||||
return errorStatus;
|
||||
}
|
||||
@@ -160,26 +168,31 @@ static void initTask(void* parameters)
|
||||
{
|
||||
initPlatform();
|
||||
|
||||
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 40, &ledTaskArguments, 0, &ledTaskHandle);
|
||||
|
||||
Logger_construct(&uart1->device);
|
||||
|
||||
NHD0420_construct(&nhd0420, &spiDisplay->device);
|
||||
|
||||
Display_construct(&display, &nhd0420);
|
||||
PCBA_construct(pcba);
|
||||
Display_construct(&display, &nhd0420.displayDevice, 0, 1024, 10);
|
||||
|
||||
Display_clearScreen(&display);
|
||||
|
||||
Display_write(&display, pcba->name, sizeof(pcba->name) / sizeof(pcba->name[0]), 1, 1);
|
||||
Display_write(&display, "A", 1, 1, 20);
|
||||
Display_write(&display, "SW V. 1.0.0.0", 13, 3, 4);
|
||||
|
||||
char buffer[20];
|
||||
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "SW V. %d.%d.%d.%d", Version_getInstance()->major,
|
||||
Version_getInstance()->minor,
|
||||
Version_getInstance()->branch,
|
||||
Version_getInstance()->patch);
|
||||
Display_write(&display, buffer, strlen(buffer), 3, 4);
|
||||
|
||||
MAX5715_construct(&max5715, &spiDAC->device);
|
||||
|
||||
MAX5715_writeCODEn(&max5715, (MAX5715_SEL_DACA | MAX5715_SEL_DACC), 0x579B);
|
||||
|
||||
|
||||
|
||||
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 40, &ledTaskArguments, 0, &ledTaskHandle);
|
||||
xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 1, &sysTaskHandle);
|
||||
|
||||
// Delete this init task
|
||||
vTaskDelete(NULL);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "stm32f10x_usart.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "keypadMatrix.h"
|
||||
#include "led.h"
|
||||
#include "platform.h"
|
||||
#include "rtc.h"
|
||||
|
||||
Reference in New Issue
Block a user