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:
@@ -11,7 +11,7 @@ ROOTDIR = ../
|
|||||||
|
|
||||||
LIBRARY_NAME = libHAL.a
|
LIBRARY_NAME = libHAL.a
|
||||||
|
|
||||||
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb -DOLI_STM32_H107 \
|
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb $(PLATFORM) $(RELEASE_DEFINES) \
|
||||||
-Iinc \
|
-Iinc \
|
||||||
-I$(ROOTDIR)/Platform/inc \
|
-I$(ROOTDIR)/Platform/inc \
|
||||||
-I$(ROOTDIR)/hsb-mrts/inc \
|
-I$(ROOTDIR)/hsb-mrts/inc \
|
||||||
@@ -23,8 +23,7 @@ CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb -DOLI_STM32_H107 \
|
|||||||
ARFLAGS = rs
|
ARFLAGS = rs
|
||||||
|
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
IODevice.o \
|
DisplayDevice.o \
|
||||||
keypadMatrix.o \
|
|
||||||
MAX5715.o \
|
MAX5715.o \
|
||||||
nhd0420.o
|
nhd0420.o
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// @file DisplayDevice.h
|
||||||
|
/// @brief File description
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Micro-Key bv
|
||||||
|
// Industrieweg 28, 9804 TG Noordhorn
|
||||||
|
// Postbus 92, 9800 AB Zuidhorn
|
||||||
|
// The Netherlands
|
||||||
|
// Tel: +31 594 503020
|
||||||
|
// Fax: +31 594 505825
|
||||||
|
// Email: support@microkey.nl
|
||||||
|
// Web: www.microkey.nl
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// $Revision$
|
||||||
|
/// $Author$
|
||||||
|
/// $Date$
|
||||||
|
// (c) 2015 Micro-Key bv
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// @defgroup {group_name} {group_description}
|
||||||
|
/// Description
|
||||||
|
|
||||||
|
/// @file DisplayDevice.h
|
||||||
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
#ifndef INC_DISPLAYDEVICE_H_
|
||||||
|
#define INC_DISPLAYDEVICE_H_
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Include files
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Constant and macro definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
OFF = 0,
|
||||||
|
ON = !OFF
|
||||||
|
} DisplayDevice_functionalState;
|
||||||
|
|
||||||
|
struct DisplayDevice;
|
||||||
|
|
||||||
|
typedef ErrorStatus (*DisplayResetFunction)(const struct DisplayDevice* self);
|
||||||
|
typedef ErrorStatus (*DisplaySetStateFunction)(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
||||||
|
typedef ErrorStatus (*DisplayWriteFunction)(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
|
||||||
|
typedef ErrorStatus (*DisplayClearFunction)(const struct DisplayDevice* self);
|
||||||
|
typedef ErrorStatus (*DisplaySetBrightnessFunction)(const struct DisplayDevice* self, size_t brightness);
|
||||||
|
typedef ErrorStatus (*DisplaySetContrastFunction)(const struct DisplayDevice* self, size_t contrast);
|
||||||
|
typedef ErrorStatus (*DisplayInvertFunction)(const struct DisplayDevice* self);
|
||||||
|
|
||||||
|
struct DisplayDeviceParameters
|
||||||
|
{
|
||||||
|
size_t numberOfRows;
|
||||||
|
size_t numberOfColumns;
|
||||||
|
size_t contrastMin;
|
||||||
|
size_t contrastMax;
|
||||||
|
size_t brightnessMin;
|
||||||
|
size_t brightnessMax;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DisplayDevice
|
||||||
|
{
|
||||||
|
DisplayResetFunction _reset;
|
||||||
|
DisplaySetStateFunction _setState;
|
||||||
|
DisplayWriteFunction _write;
|
||||||
|
DisplayClearFunction _clear;
|
||||||
|
DisplaySetBrightnessFunction _setBrightness;
|
||||||
|
DisplaySetContrastFunction _setContrast;
|
||||||
|
DisplayInvertFunction _invert;
|
||||||
|
struct DisplayDeviceParameters parameters;
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function declarations
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern ErrorStatus DisplayDevice_construct (struct DisplayDevice* self, struct DisplayDeviceParameters* parameters,
|
||||||
|
DisplayResetFunction reset,
|
||||||
|
DisplaySetStateFunction setState,
|
||||||
|
DisplayWriteFunction write,
|
||||||
|
DisplayClearFunction clear,
|
||||||
|
DisplaySetBrightnessFunction setBrightness,
|
||||||
|
DisplaySetContrastFunction setContrast,
|
||||||
|
DisplayInvertFunction invert);
|
||||||
|
|
||||||
|
extern ErrorStatus DisplayDevice_reset(const struct DisplayDevice* self);
|
||||||
|
extern ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
||||||
|
extern ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
|
||||||
|
extern ErrorStatus DisplayDevice_clear(const struct DisplayDevice* self);
|
||||||
|
extern ErrorStatus DisplayDevice_setBrightness(const struct DisplayDevice* self, size_t brightness);
|
||||||
|
extern ErrorStatus DisplayDevice_setContrast(const struct DisplayDevice* self, size_t contrast);
|
||||||
|
extern ErrorStatus DisplayDevice_invert(const struct DisplayDevice* self);
|
||||||
|
|
||||||
|
#endif /* INC_DISPLAYDEVICE_H_ */
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
// Include files
|
// Include files
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "DisplayDevice.h"
|
||||||
#include "IODevice.h"
|
#include "IODevice.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
@@ -118,6 +119,7 @@
|
|||||||
|
|
||||||
struct NHD0420
|
struct NHD0420
|
||||||
{
|
{
|
||||||
|
struct DisplayDevice displayDevice;
|
||||||
const struct IODevice* device;
|
const struct IODevice* device;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -182,7 +184,7 @@ extern ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, char row, char column);
|
extern ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, size_t row, size_t column);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,163 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// @file DisplayDevice.c
|
||||||
|
/// @brief Description
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Micro-Key bv
|
||||||
|
// Industrieweg 28, 9804 TG Noordhorn
|
||||||
|
// Postbus 92, 9800 AB Zuidhorn
|
||||||
|
// The Netherlands
|
||||||
|
// Tel: +31 594 503020
|
||||||
|
// Fax: +31 594 505825
|
||||||
|
// Email: support@microkey.nl
|
||||||
|
// Web: www.microkey.nl
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// $Revision$
|
||||||
|
/// $Author$
|
||||||
|
/// $Date$
|
||||||
|
// (c) 2017 Micro-Key bv
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// @file DisplayDevice.c
|
||||||
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Include files
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "DisplayDevice.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Constant and macro definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File-scope variables
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function declarations
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_construct (struct DisplayDevice* self, struct DisplayDeviceParameters* parameters,
|
||||||
|
DisplayResetFunction reset,
|
||||||
|
DisplaySetStateFunction setState,
|
||||||
|
DisplayWriteFunction write,
|
||||||
|
DisplayClearFunction clear,
|
||||||
|
DisplaySetBrightnessFunction setBrightness,
|
||||||
|
DisplaySetContrastFunction setContrast,
|
||||||
|
DisplayInvertFunction invert)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
self->_reset = reset;
|
||||||
|
self->_setState = setState;
|
||||||
|
self->_write = write;
|
||||||
|
self->_clear = clear;
|
||||||
|
self->_setBrightness = setBrightness;
|
||||||
|
self->_setContrast = setContrast;
|
||||||
|
self->_invert = invert;
|
||||||
|
|
||||||
|
self->parameters = *parameters;
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_reset(const struct DisplayDevice* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_reset != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_reset(self);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_setState != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_setState(self, state);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_write != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_write(self, buffer, length, row, column);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_clear(const struct DisplayDevice* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_clear != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_clear(self);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_setBrightness(const struct DisplayDevice* self, size_t brightness)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_setBrightness != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_setBrightness(self, brightness);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_setContrast(const struct DisplayDevice* self, size_t contrast)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_setContrast != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_setContrast(self, contrast);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus DisplayDevice_invert(const struct DisplayDevice* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (self->_invert != NULL)
|
||||||
|
{
|
||||||
|
returnValue = self->_invert(self);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
@@ -64,6 +64,11 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
|||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
||||||
|
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
|
||||||
|
static ErrorStatus clear(const struct DisplayDevice* self);
|
||||||
|
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness);
|
||||||
|
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function definitions
|
// Function definitions
|
||||||
@@ -77,6 +82,15 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic
|
|||||||
if (self->device == NULL)
|
if (self->device == NULL)
|
||||||
{
|
{
|
||||||
self->device = device;
|
self->device = device;
|
||||||
|
|
||||||
|
struct DisplayDeviceParameters ddParameters;
|
||||||
|
ddParameters.numberOfRows = NHD0420_NUMBER_OF_ROWS;
|
||||||
|
ddParameters.numberOfColumns = NHD0420_NUMBER_OF_COLUMNS;
|
||||||
|
ddParameters.brightnessMin = NHD0420_BRIGHTNESS_MIN;
|
||||||
|
ddParameters.brightnessMax = NHD0420_BRIGHTNESS_MAX;
|
||||||
|
ddParameters.contrastMin = NHD0420_CONTRAST_MIN;
|
||||||
|
ddParameters.contrastMax = NHD0420_CONTRAST_MAX;
|
||||||
|
DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, write, clear, setBrightness, setContrast, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -137,7 +151,7 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, char row, char column)
|
ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, size_t row, size_t column)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
@@ -298,3 +312,57 @@ ErrorStatus NHD0420_sendData(const struct NHD0420* self, const char* buffer, siz
|
|||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (state == ON)
|
||||||
|
{
|
||||||
|
returnValue = NHD0420_turnOnDisplay((const struct NHD0420*)self);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = NHD0420_turnOffDisplay((const struct NHD0420*)self);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
// Set cursor on display
|
||||||
|
returnValue = NHD0420_setCursorToPosition((const struct NHD0420*)self, row, column);
|
||||||
|
|
||||||
|
if (returnValue == SUCCESS)
|
||||||
|
{
|
||||||
|
returnValue = NHD0420_sendData((const struct NHD0420*)self, buffer, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus clear(const struct DisplayDevice* self)
|
||||||
|
{
|
||||||
|
return NHD0420_clearScreen((const struct NHD0420*)self);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness)
|
||||||
|
{
|
||||||
|
return NHD0420_setBacklightBrightness((const struct NHD0420*)self, brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast)
|
||||||
|
{
|
||||||
|
return NHD0420_setContrast((const struct NHD0420*)self, contrast);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,22 @@
|
|||||||
|
# Define release version for firmware here
|
||||||
|
RELEASE_PRODUCT = \""S0\""
|
||||||
|
RELEASE_MAJOR = 0
|
||||||
|
RELEASE_MINOR = 1
|
||||||
|
RELEASE_BRANCH = 0
|
||||||
|
RELEASE_PATCH = 0
|
||||||
|
|
||||||
|
PLATFORM_OLIMEX_STM32_H107 = OLI_STM32_H107
|
||||||
|
|
||||||
|
export RELEASE_DEFINES = \
|
||||||
|
-DRELEASE_PRODUCT=$(RELEASE_PRODUCT) \
|
||||||
|
-DRELEASE_MAJOR=$(RELEASE_MAJOR) \
|
||||||
|
-DRELEASE_MINOR=$(RELEASE_MINOR) \
|
||||||
|
-DRELEASE_BRANCH=$(RELEASE_BRANCH) \
|
||||||
|
-DRELEASE_PATCH=$(RELEASE_PATCH) \
|
||||||
|
|
||||||
|
export PLATFORM = -D$(PLATFORM_OLIMEX_STM32_H107)
|
||||||
|
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(MAKE) pho_hsb_olimex_stm32_h107
|
$(MAKE) pho_hsb_olimex_stm32_h107
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ ROOTDIR = ../
|
|||||||
|
|
||||||
LIBRARY_NAME = libPlatform.a
|
LIBRARY_NAME = libPlatform.a
|
||||||
|
|
||||||
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb -DOLI_STM32_H107 \
|
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb $(PLATFORM) $(RELEASE_DEFINES) \
|
||||||
-Iinc \
|
-Iinc \
|
||||||
-I$(ROOTDIR)/HAL/inc \
|
-I$(ROOTDIR)/HAL/inc \
|
||||||
-I$(ROOTDIR)/hsb-mrts/inc \
|
-I$(ROOTDIR)/hsb-mrts/inc \
|
||||||
@@ -25,13 +25,16 @@ ARFLAGS = rs
|
|||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
stm32f10x_it.o \
|
stm32f10x_it.o \
|
||||||
adc.o \
|
adc.o \
|
||||||
|
IODevice.o \
|
||||||
|
keypadMatrix.o \
|
||||||
led.o \
|
led.o \
|
||||||
|
oli_stm32_h107.o \
|
||||||
PCBA.o \
|
PCBA.o \
|
||||||
rtc.o \
|
rtc.o \
|
||||||
spi.o \
|
spi.o \
|
||||||
spiDevice.o \
|
spiDevice.o \
|
||||||
uart.o \
|
uart.o \
|
||||||
oli_stm32_h107.o \
|
Version.o \
|
||||||
|
|
||||||
|
|
||||||
vpath %.o $(OBJDIR)
|
vpath %.o $(OBJDIR)
|
||||||
|
|||||||
@@ -69,18 +69,16 @@ struct Pcba
|
|||||||
* PCBA_construct
|
* PCBA_construct
|
||||||
* Initializes the PCBA information of the hardware.
|
* Initializes the PCBA information of the hardware.
|
||||||
* PCBA information is defined via placed resistors
|
* PCBA information is defined via placed resistors
|
||||||
* This function can only be called once. Within the first call an internal flag
|
* This function creates a singleton. Calling this function for the first time
|
||||||
* is set to prevent any further calling. That is because the PCBA information
|
* constructs the PCBA information. Calling it afterwards returns the already
|
||||||
* cannot change during run-time
|
* constructed data
|
||||||
*
|
*
|
||||||
* @param self The PCBA information
|
* @return struct Pcba* The PCBA information singelton
|
||||||
*
|
*
|
||||||
* @return ErrorStatus SUCCESS if construction was successful
|
|
||||||
* ERROR otherwise
|
|
||||||
*
|
*
|
||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus PCBA_construct(struct Pcba* self);
|
extern struct Pcba* PCBA_getInstance(void);
|
||||||
|
|
||||||
#endif /* PCBA_H_ */
|
#endif /* PCBA_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// @file Version.h
|
||||||
|
/// @brief File description
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Micro-Key bv
|
||||||
|
// Industrieweg 28, 9804 TG Noordhorn
|
||||||
|
// Postbus 92, 9800 AB Zuidhorn
|
||||||
|
// The Netherlands
|
||||||
|
// Tel: +31 594 503020
|
||||||
|
// Fax: +31 594 505825
|
||||||
|
// Email: support@microkey.nl
|
||||||
|
// Web: www.microkey.nl
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// $Revision$
|
||||||
|
/// $Author$
|
||||||
|
/// $Date$
|
||||||
|
// (c) 2015 Micro-Key bv
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// @defgroup {group_name} {group_description}
|
||||||
|
/// Description
|
||||||
|
|
||||||
|
/// @file Version.h
|
||||||
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
#ifndef INC_VERSION_H_
|
||||||
|
#define INC_VERSION_H_
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Include files
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Constant and macro definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
struct Version
|
||||||
|
{
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
int branch;
|
||||||
|
int patch;
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function declarations
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Version_getInstance
|
||||||
|
* Initialises the Version information.
|
||||||
|
* Version information is supplied via macros in makefile
|
||||||
|
* This function creates a singleton. Calling this function for the first time
|
||||||
|
* constructs the Version information. Calling it afterwards returns the already
|
||||||
|
* constructed data
|
||||||
|
*
|
||||||
|
* @return struct Version* The Version information singleton
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern struct Version* Version_getInstance(void);
|
||||||
|
|
||||||
|
#endif /* INC_VERSION_H_ */
|
||||||
@@ -31,6 +31,8 @@
|
|||||||
// Include files
|
// Include files
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "IODevice.h"
|
#include "IODevice.h"
|
||||||
|
|
||||||
@@ -42,21 +44,55 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#define ADC_NUMBER_OF_CHANNELS (18) // 16 IOs + Temp + Vcc
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions.
|
// Type definitions.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct Adc; // Prototype
|
||||||
|
|
||||||
|
struct AdcChannelParameters
|
||||||
|
{
|
||||||
|
uint8_t channel;
|
||||||
|
uint8_t Rank;
|
||||||
|
uint8_t ADC_SampleTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AdcChannel
|
||||||
|
{
|
||||||
|
struct IODevice device;
|
||||||
|
struct Adc* parent;
|
||||||
|
uint8_t channel;
|
||||||
|
uint8_t Rank;
|
||||||
|
uint8_t ADC_SampleTime;
|
||||||
|
T_PL_GPIO input;
|
||||||
|
};
|
||||||
|
|
||||||
struct AdcParameters
|
struct AdcParameters
|
||||||
{
|
{
|
||||||
|
uint32_t ADC_Mode;
|
||||||
|
FunctionalState ADC_ScanConvMode;
|
||||||
|
FunctionalState ADC_ContinuousConvMode;
|
||||||
|
uint32_t ADC_ExternalTrigConv;
|
||||||
|
uint32_t ADC_DataAlign;
|
||||||
|
uint8_t ADC_NbrOfChannel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Adc
|
struct Adc
|
||||||
{
|
{
|
||||||
struct IODevice device;
|
ADC_TypeDef* ADCx;
|
||||||
ADC_InitTypeDef adc_InitStruct;
|
ADC_InitTypeDef ADC_InitStruct;
|
||||||
T_PL_GPIO input;
|
bool useDMA;
|
||||||
|
bool useRanks;
|
||||||
|
struct AdcChannel channel[ADC_NUMBER_OF_CHANNELS];
|
||||||
|
// Only necessary when the RANK parameter determines conversion order or RANK is used anyway
|
||||||
|
// For single conversions the READ function simply returns the converted value
|
||||||
|
// Note that the content of this array IS NOT SORTED BY CHANNEL NUMBER but sorted BY RANK NUMBER
|
||||||
|
// When initialising an ADC channel to a regular group, the RANK parameter determines the
|
||||||
|
// order of convertions. E.G. channel 5 can be put first while channel 1 can be put last.
|
||||||
|
// The array index stands for the RANK
|
||||||
|
uint16_t channelValue[ADC_NUMBER_OF_CHANNELS];
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -79,4 +115,118 @@ struct Adc
|
|||||||
*/
|
*/
|
||||||
extern ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters);
|
extern ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADC_destruct
|
||||||
|
* Destructor for an ADC instance
|
||||||
|
*
|
||||||
|
* @param self The ADC instance to destruct
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern void ADC_destruct(struct Adc* self);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADC_performInternalCalibration
|
||||||
|
* Apply internal ADC calibration to ADC instance
|
||||||
|
* ADC calibration is RESET and afterwards set.
|
||||||
|
*
|
||||||
|
* @param self The ADC instance to calibrate
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus ADC_performInternalCalibration(const struct Adc* self);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADC_setStatus
|
||||||
|
* Changes the status of the ADC instance
|
||||||
|
*
|
||||||
|
* @param self The ADC instance
|
||||||
|
* @param command new command for the ADC instance
|
||||||
|
* - ENABLE
|
||||||
|
* - DISABLE
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus ADC_setStatus (struct Adc* self, FunctionalState command);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADC_setDMAStatus
|
||||||
|
* Changes the status of the ADC instance's DMA
|
||||||
|
*
|
||||||
|
* @param self The ADC instance
|
||||||
|
* @param command new command for the ADC instance
|
||||||
|
* - ENABLE
|
||||||
|
* - DISABLE
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus ADC_setDMAStatus (struct Adc* self, FunctionalState command);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADCChannel_construct
|
||||||
|
* Constructor for ADC channel instance
|
||||||
|
*
|
||||||
|
* @param self The ADC channel instance to initialize
|
||||||
|
* @param parameters Additional ADC parameters
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct AdcChannelParameters* parameters);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADCChannel_destruct
|
||||||
|
* Destructor for an ADC channel instance
|
||||||
|
*
|
||||||
|
* @param self The ADC channel instance to destruct
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern void ADCChannel_destruct(struct AdcChannel* self);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* ADCChannel_read
|
||||||
|
* Read the current conversion value of the ADC channel in argument self
|
||||||
|
*
|
||||||
|
* @param self ADC channel object
|
||||||
|
* @param value The read value
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus ADCChannel_read(struct AdcChannel* self, uint16_t* value);
|
||||||
|
|
||||||
#endif /* INC_ADC_H_ */
|
#endif /* INC_ADC_H_ */
|
||||||
|
|||||||
@@ -61,11 +61,13 @@ typedef struct
|
|||||||
} T_PL_GPIO;
|
} T_PL_GPIO;
|
||||||
|
|
||||||
// Export of PCBA information
|
// Export of PCBA information
|
||||||
extern struct Pcba* const pcba;
|
extern struct Pcba* pcba;
|
||||||
|
|
||||||
// Export of LEDs
|
// Export of LEDs
|
||||||
extern struct Led* const ledGreen;
|
extern struct Led* const ledGreen;
|
||||||
extern struct Led* const ledOrange;
|
extern struct Led* const ledOrange;
|
||||||
|
// Export of ADCs
|
||||||
|
extern struct Adc* const adc1;
|
||||||
// Export of the rtc
|
// Export of the rtc
|
||||||
extern struct Rtc* const rtc;
|
extern struct Rtc* const rtc;
|
||||||
// Export of UARTs
|
// Export of UARTs
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ ErrorStatus IODevice_write(const struct IODevice* self, const char* buffer, size
|
|||||||
|
|
||||||
if (self->_write != NULL)
|
if (self->_write != NULL)
|
||||||
{
|
{
|
||||||
self->_write(self, buffer, length);
|
returnValue = self->_write(self, buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
@@ -24,12 +24,9 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Include files
|
// Include files
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "PCBA.h"
|
#include "PCBA.h"
|
||||||
|
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -46,7 +43,9 @@
|
|||||||
// File-scope variables
|
// File-scope variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static bool initialized = false;
|
static struct Pcba* instance = NULL;
|
||||||
|
static struct Pcba thisPCBA;
|
||||||
|
|
||||||
static const char nameArray[4][20] =
|
static const char nameArray[4][20] =
|
||||||
{
|
{
|
||||||
"Cathode/MCP repair ",
|
"Cathode/MCP repair ",
|
||||||
@@ -59,18 +58,32 @@ static const char nameArray[4][20] =
|
|||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ErrorStatus PCBA_construct(struct Pcba* self);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function definitions
|
// Function definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
ErrorStatus PCBA_construct(struct Pcba* self)
|
struct Pcba* PCBA_getInstance(void)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
if (!initialized)
|
if (instance == NULL)
|
||||||
{
|
{
|
||||||
|
instance = &thisPCBA;
|
||||||
|
returnValue = PCBA_construct(instance);
|
||||||
|
|
||||||
|
if (returnValue != SUCCESS)
|
||||||
|
{
|
||||||
|
instance = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ErrorStatus PCBA_construct(struct Pcba* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
uint8_t A0 = GPIO_ReadInputDataBit(self->A0.GPIO_Typedef, self->A0.GPIO_InitStruct.GPIO_Pin);
|
uint8_t A0 = GPIO_ReadInputDataBit(self->A0.GPIO_Typedef, self->A0.GPIO_InitStruct.GPIO_Pin);
|
||||||
uint8_t A1 = GPIO_ReadInputDataBit(self->A1.GPIO_Typedef, self->A1.GPIO_InitStruct.GPIO_Pin);
|
uint8_t A1 = GPIO_ReadInputDataBit(self->A1.GPIO_Typedef, self->A1.GPIO_InitStruct.GPIO_Pin);
|
||||||
@@ -78,11 +91,5 @@ ErrorStatus PCBA_construct(struct Pcba* self)
|
|||||||
self->pcba = (A0 & 0x01) | ((A1 << 1) & 0x02);
|
self->pcba = (A0 & 0x01) | ((A1 << 1) & 0x02);
|
||||||
snprintf(self->name, (sizeof(self->name) / sizeof(self->name[0])), "%s", nameArray[self->pcba]);
|
snprintf(self->name, (sizeof(self->name) / sizeof(self->name[0])), "%s", nameArray[self->pcba]);
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
returnValue = ERROR;
|
|
||||||
}
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// @file Version.c
|
||||||
|
/// @brief Description
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Micro-Key bv
|
||||||
|
// Industrieweg 28, 9804 TG Noordhorn
|
||||||
|
// Postbus 92, 9800 AB Zuidhorn
|
||||||
|
// The Netherlands
|
||||||
|
// Tel: +31 594 503020
|
||||||
|
// Fax: +31 594 505825
|
||||||
|
// Email: support@microkey.nl
|
||||||
|
// Web: www.microkey.nl
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// $Revision$
|
||||||
|
/// $Author$
|
||||||
|
/// $Date$
|
||||||
|
// (c) 2017 Micro-Key bv
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// @file Version.c
|
||||||
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Include files
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "Version.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Constant and macro definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File-scope variables
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static struct Version* instance = NULL;
|
||||||
|
static struct Version thisVersion;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function declarations
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ErrorStatus Version_construct(struct Version* self);
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct Version* Version_getInstance(void)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (instance == NULL)
|
||||||
|
{
|
||||||
|
instance = &thisVersion;
|
||||||
|
returnValue = Version_construct(instance);
|
||||||
|
|
||||||
|
if (returnValue != SUCCESS)
|
||||||
|
{
|
||||||
|
instance = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ErrorStatus Version_construct(struct Version* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
self->major = RELEASE_MAJOR;
|
||||||
|
self->minor = RELEASE_MINOR;
|
||||||
|
self->branch = RELEASE_BRANCH;
|
||||||
|
self->patch = RELEASE_PATCH;
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
@@ -60,14 +60,156 @@ ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters)
|
|||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
IODevice_construct(&self->device, read, NULL);
|
self->useDMA = false;
|
||||||
|
|
||||||
|
self->ADC_InitStruct.ADC_Mode = parameters->ADC_Mode;
|
||||||
|
self->ADC_InitStruct.ADC_ScanConvMode = parameters->ADC_ScanConvMode;
|
||||||
|
self->ADC_InitStruct.ADC_ContinuousConvMode = parameters->ADC_ContinuousConvMode;
|
||||||
|
self->ADC_InitStruct.ADC_ExternalTrigConv = parameters->ADC_ExternalTrigConv;
|
||||||
|
self->ADC_InitStruct.ADC_DataAlign = parameters->ADC_DataAlign;
|
||||||
|
self->ADC_InitStruct.ADC_NbrOfChannel = parameters->ADC_NbrOfChannel;
|
||||||
|
|
||||||
|
ADC_DeInit(self->ADCx);
|
||||||
|
|
||||||
|
ADC_Init(self->ADCx, &self->ADC_InitStruct);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ADC_destruct (struct Adc* self)
|
||||||
|
{
|
||||||
|
int channelCounter;
|
||||||
|
for (channelCounter = 0; channelCounter < ADC_NUMBER_OF_CHANNELS; channelCounter++)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ADC_DeInit(self->ADCx);
|
||||||
|
self->useDMA = false;
|
||||||
|
self->useRanks = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus ADC_performInternalCalibration(const struct Adc* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
/* Enable ADC1 reset calibration register */
|
||||||
|
ADC_ResetCalibration(self->ADCx);
|
||||||
|
/* Check the end of ADC1 reset calibration register */
|
||||||
|
while(ADC_GetResetCalibrationStatus(self->ADCx));
|
||||||
|
|
||||||
|
/* Start ADC1 calibration */
|
||||||
|
ADC_StartCalibration(self->ADCx);
|
||||||
|
/* Check the end of ADC1 calibration */
|
||||||
|
while(ADC_GetCalibrationStatus(self->ADCx));
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus ADC_setStatus (struct Adc* self, FunctionalState command)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
ADC_Cmd(self->ADCx, command);
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus ADC_setDMAStatus (struct Adc* self, FunctionalState command)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
ADC_DMACmd(self->ADCx, command);
|
||||||
|
|
||||||
|
if (command == ENABLE)
|
||||||
|
{
|
||||||
|
self->useDMA = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->useDMA = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct AdcChannelParameters* parameters)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
IODevice_construct(&self->device, read, NULL);
|
||||||
|
|
||||||
|
if ((parameters->Rank) > 0 && (parameters->Rank <= 16))
|
||||||
|
{
|
||||||
|
self->Rank = parameters->Rank;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
|
if (parameters->channel < 18)
|
||||||
|
{
|
||||||
|
self->channel = parameters->channel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (returnValue == SUCCESS)
|
||||||
|
{
|
||||||
|
self->ADC_SampleTime = parameters->ADC_SampleTime;
|
||||||
|
|
||||||
|
//TODO MAKE SURE EACH RANK IS USED ONLY ONCE
|
||||||
|
ADC_RegularChannelConfig(self->parent->ADCx, self->channel, self->Rank, self->ADC_SampleTime);
|
||||||
|
self->parent->useRanks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ADCChannel_destruct(struct AdcChannel* self)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus ADCChannel_read(struct AdcChannel* self, uint16_t* value)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
// For reading it is important whether Ranks are enabled or not
|
||||||
|
if (self->parent->useRanks)
|
||||||
|
{
|
||||||
|
// Rank starts with 1 - must be reduced by one in order tu be used as index
|
||||||
|
*value = self->parent->channelValue[self->Rank - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
(void)length;
|
||||||
|
|
||||||
|
uint16_t adcValue = 0;
|
||||||
|
returnValue = ADCChannel_read((struct AdcChannel*)self, &adcValue);
|
||||||
|
|
||||||
|
buffer[0] = adcValue >> 8;
|
||||||
|
buffer[1] = adcValue;
|
||||||
|
|
||||||
|
*actualLength = 2;
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,15 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "stm32f10x_adc.h"
|
||||||
#include "stm32f10x_bkp.h"
|
#include "stm32f10x_bkp.h"
|
||||||
|
#include "stm32f10x_dma.h"
|
||||||
#include "stm32f10x_gpio.h"
|
#include "stm32f10x_gpio.h"
|
||||||
#include "stm32f10x_pwr.h"
|
#include "stm32f10x_pwr.h"
|
||||||
#include "stm32f10x_it.h"
|
#include "stm32f10x_it.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "adc.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "PCBA.h"
|
#include "PCBA.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
@@ -48,6 +51,10 @@
|
|||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// ADC
|
||||||
|
#define ADC1_DR_Address ((uint32_t)0x4001244C)
|
||||||
|
#define ADC1_NUMBER_OF_USED_CHANNELS (3)
|
||||||
|
|
||||||
// UART1 Settings (Logger/Console)
|
// UART1 Settings (Logger/Console)
|
||||||
#define UART_LOG_BAUDRATE (57600)
|
#define UART_LOG_BAUDRATE (57600)
|
||||||
#define UART_LOG_TX_QUEUE (256)
|
#define UART_LOG_TX_QUEUE (256)
|
||||||
@@ -78,12 +85,15 @@
|
|||||||
// the IO/Peripheral object
|
// the IO/Peripheral object
|
||||||
|
|
||||||
// PCBA information
|
// PCBA information
|
||||||
static struct Pcba _pcba;
|
|
||||||
|
|
||||||
// LEDs
|
// LEDs
|
||||||
static struct Led _ledGreen;
|
static struct Led _ledGreen;
|
||||||
static struct Led _ledOrange;
|
static struct Led _ledOrange;
|
||||||
|
|
||||||
|
// ADC
|
||||||
|
static struct Adc _adc1;
|
||||||
|
static struct AdcParameters _adc1Parameters;
|
||||||
|
|
||||||
// RTC
|
// RTC
|
||||||
static struct Rtc _rtc;
|
static struct Rtc _rtc;
|
||||||
|
|
||||||
@@ -109,11 +119,14 @@ static struct KeypadParameters _keypadParameters;
|
|||||||
|
|
||||||
// The following pointers are for export (see platform.h) and external use.
|
// The following pointers are for export (see platform.h) and external use.
|
||||||
// Note that the pointer content is marked "const"
|
// Note that the pointer content is marked "const"
|
||||||
struct Pcba* const pcba = &_pcba;
|
struct Pcba* pcba;
|
||||||
|
|
||||||
struct Led* const ledGreen = &_ledGreen;
|
struct Led* const ledGreen = &_ledGreen;
|
||||||
struct Led* const ledOrange = &_ledOrange;
|
struct Led* const ledOrange = &_ledOrange;
|
||||||
|
|
||||||
|
struct Adc* const adc1 = &_adc1;
|
||||||
|
struct AdcParameters* adc1Parameters = &_adc1Parameters;
|
||||||
|
|
||||||
struct Rtc* const rtc = &_rtc;
|
struct Rtc* const rtc = &_rtc;
|
||||||
|
|
||||||
struct Uart* const uart1 = &_uart1;
|
struct Uart* const uart1 = &_uart1;
|
||||||
@@ -169,7 +182,7 @@ ErrorStatus initPlatform(void)
|
|||||||
/* --------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------*/
|
||||||
/* PCBA */
|
/* PCBA */
|
||||||
/* --------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------*/
|
||||||
// PCBA_construct(pcba);
|
pcba = PCBA_getInstance();
|
||||||
|
|
||||||
/* --------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------*/
|
||||||
/* LEDs */
|
/* LEDs */
|
||||||
@@ -177,6 +190,63 @@ ErrorStatus initPlatform(void)
|
|||||||
LED_construct(ledGreen);
|
LED_construct(ledGreen);
|
||||||
LED_construct(ledOrange);
|
LED_construct(ledOrange);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------*/
|
||||||
|
/* DMA1 - Channel 1 - For use with ADC1 */
|
||||||
|
/* --------------------------------------------------------------------*/
|
||||||
|
DMA_InitTypeDef DMA_InitStructure;
|
||||||
|
DMA_DeInit(DMA1_Channel1);
|
||||||
|
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
|
||||||
|
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)adc1->channelValue;
|
||||||
|
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
||||||
|
DMA_InitStructure.DMA_BufferSize = ADC1_NUMBER_OF_USED_CHANNELS;
|
||||||
|
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||||
|
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||||
|
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
||||||
|
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
||||||
|
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
||||||
|
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
||||||
|
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||||
|
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
|
||||||
|
/* Enable DMA1 channel1 */
|
||||||
|
DMA_Cmd(DMA1_Channel1, ENABLE);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------*/
|
||||||
|
/* ADC1 - for module feedback */
|
||||||
|
/* --------------------------------------------------------------------*/
|
||||||
|
IRQ_setInterruptProperties(ADC1_2_IRQn, 12, 12, DISABLE);
|
||||||
|
adc1Parameters->ADC_Mode = ADC_Mode_Independent;
|
||||||
|
adc1Parameters->ADC_ScanConvMode = ENABLE;
|
||||||
|
adc1Parameters->ADC_ContinuousConvMode = ENABLE;
|
||||||
|
adc1Parameters->ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
||||||
|
adc1Parameters->ADC_DataAlign = ADC_DataAlign_Right;
|
||||||
|
adc1Parameters->ADC_NbrOfChannel = ADC1_NUMBER_OF_USED_CHANNELS;
|
||||||
|
|
||||||
|
adc1->ADCx = ADC1;
|
||||||
|
ADC_construct(adc1, adc1Parameters);
|
||||||
|
|
||||||
|
struct AdcChannelParameters acParameters;
|
||||||
|
acParameters.channel = ADC_Channel_0;
|
||||||
|
acParameters.Rank = 3;
|
||||||
|
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||||
|
adc1->channel[acParameters.channel].parent = adc1;
|
||||||
|
ADCChannel_construct(&adc1->channel[acParameters.channel], &acParameters);
|
||||||
|
acParameters.channel = ADC_Channel_1;
|
||||||
|
acParameters.Rank = 2;
|
||||||
|
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||||
|
adc1->channel[acParameters.channel].parent = adc1;
|
||||||
|
ADCChannel_construct(&adc1->channel[acParameters.channel], &acParameters);
|
||||||
|
acParameters.channel = ADC_Channel_2;
|
||||||
|
acParameters.Rank = 1;
|
||||||
|
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||||
|
adc1->channel[acParameters.channel].parent = adc1;
|
||||||
|
ADCChannel_construct(&adc1->channel[acParameters.channel], &acParameters);
|
||||||
|
|
||||||
|
|
||||||
|
ADC_setDMAStatus(adc1, ENABLE);
|
||||||
|
ADC_setStatus(adc1, ENABLE);
|
||||||
|
ADC_performInternalCalibration(adc1);
|
||||||
|
ADC_SoftwareStartConvCmd(adc1->ADCx, ENABLE);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------*/
|
||||||
/* RTC */
|
/* RTC */
|
||||||
/* --------------------------------------------------------------------*/
|
/* --------------------------------------------------------------------*/
|
||||||
@@ -271,8 +341,6 @@ ErrorStatus initPlatform(void)
|
|||||||
|
|
||||||
Keypad_getDefaultParameters(keypadParam);
|
Keypad_getDefaultParameters(keypadParam);
|
||||||
Keypad_construct(keypad, keypadParam, KEYPAD_DEBOUNCE_TIME_MS);
|
Keypad_construct(keypad, keypadParam, KEYPAD_DEBOUNCE_TIME_MS);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
@@ -308,6 +376,16 @@ static ErrorStatus initClocks (void)
|
|||||||
// Enable RTC Clock
|
// Enable RTC Clock
|
||||||
RCC_RTCCLKCmd(ENABLE);
|
RCC_RTCCLKCmd(ENABLE);
|
||||||
|
|
||||||
|
RCC_PCLK2Config(RCC_HCLK_Div1);
|
||||||
|
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
||||||
|
|
||||||
|
|
||||||
|
RCC_AHBPeriphResetCmd(RCC_AHBPeriph_DMA1, DISABLE);
|
||||||
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
||||||
|
|
||||||
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
|
||||||
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||||
|
|
||||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||||
|
|
||||||
@@ -337,19 +415,23 @@ static ErrorStatus initIO (void)
|
|||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
T_PL_GPIO gpio;
|
||||||
|
|
||||||
/*PCBA IO initialisation -------------------------------------------------*/
|
/*PCBA IO initialisation -------------------------------------------------*/
|
||||||
// A0
|
// A0
|
||||||
pcba->A0.GPIO_Typedef = GPIOC;
|
gpio.GPIO_Typedef = GPIOC;
|
||||||
pcba->A0.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
|
gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
|
||||||
pcba->A0.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
|
gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
|
||||||
pcba->A0.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(pcba->A0.GPIO_Typedef, &pcba->A0.GPIO_InitStruct);
|
GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct);
|
||||||
|
PCBA_getInstance()->A0 = gpio;
|
||||||
// A1
|
// A1
|
||||||
pcba->A1.GPIO_Typedef = GPIOC;
|
gpio.GPIO_Typedef = GPIOC;
|
||||||
pcba->A1.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
|
gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
|
||||||
pcba->A1.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
|
gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
|
||||||
pcba->A1.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
GPIO_Init(pcba->A1.GPIO_Typedef, &pcba->A1.GPIO_InitStruct);
|
GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct);
|
||||||
|
PCBA_getInstance()->A1 = gpio;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -368,6 +450,27 @@ static ErrorStatus initIO (void)
|
|||||||
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
GPIO_Init(ledOrange->ledGpio.GPIO_Typedef, &ledOrange->ledGpio.GPIO_InitStruct);
|
GPIO_Init(ledOrange->ledGpio.GPIO_Typedef, &ledOrange->ledGpio.GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* ADC1 initialisation ---------------------------------------------------*/
|
||||||
|
// Channel 0 - PA0
|
||||||
|
gpio.GPIO_Typedef = GPIOA;
|
||||||
|
gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
|
gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
|
||||||
|
GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct);
|
||||||
|
adc1->channel[ADC_Channel_0].input = gpio;
|
||||||
|
// Channel 1 - PA1
|
||||||
|
gpio.GPIO_Typedef = GPIOA;
|
||||||
|
gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
|
gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
|
||||||
|
GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct);
|
||||||
|
adc1->channel[ADC_Channel_1].input = gpio;
|
||||||
|
// Channel 2 - PA2
|
||||||
|
gpio.GPIO_Typedef = GPIOA;
|
||||||
|
gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
|
gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
|
||||||
|
GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct);
|
||||||
|
adc1->channel[ADC_Channel_2].input = gpio;
|
||||||
|
|
||||||
|
|
||||||
/* USART1 initialisation -------------------------------------------------*/
|
/* USART1 initialisation -------------------------------------------------*/
|
||||||
// Init TX line
|
// Init TX line
|
||||||
_uart1.USART_TX.GPIO_Typedef = GPIOB;
|
_uart1.USART_TX.GPIO_Typedef = GPIOB;
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
ifndef EXECUTABLE
|
ifndef EXECUTABLE
|
||||||
|
|
||||||
# Define release version for firmware here
|
|
||||||
S0_RELEASE_PRODUCT = \""S0\""
|
|
||||||
S0_RELEASE_MAJOR = 0
|
|
||||||
S0_RELEASE_MINOR = 1
|
|
||||||
S0_RELEASE_BRANCH = 0
|
|
||||||
S0_RELEASE_REVISION = 0
|
|
||||||
|
|
||||||
|
|
||||||
# Main objects (not to be added in the library)
|
# Main objects (not to be added in the library)
|
||||||
OBJECTS_MAIN = \
|
OBJECTS_MAIN = \
|
||||||
@@ -19,7 +12,7 @@ system_stm32f10x.o \
|
|||||||
sysmem.o \
|
sysmem.o \
|
||||||
startup_stm32f10x_cl.o \
|
startup_stm32f10x_cl.o \
|
||||||
\
|
\
|
||||||
Display_nhd0420.o \
|
Display.o \
|
||||||
FreeRTOSFixes.o \
|
FreeRTOSFixes.o \
|
||||||
Logger.o \
|
Logger.o \
|
||||||
\
|
\
|
||||||
@@ -44,13 +37,6 @@ LINKER_SCRIPTS_DIR = linker
|
|||||||
LINKER_SCRIPT = LinkerScript.ld
|
LINKER_SCRIPT = LinkerScript.ld
|
||||||
STARTER_SCRIPT_DIR = startup
|
STARTER_SCRIPT_DIR = startup
|
||||||
|
|
||||||
RELEASE_DEFINES = \
|
|
||||||
-DRELEASE_PRODUCT=$(RELEASE_PRODUCT) \
|
|
||||||
-DRELEASE_MAJOR=$(RELEASE_MAJOR) \
|
|
||||||
-DRELEASE_MINOR=$(RELEASE_MINOR) \
|
|
||||||
-DRELEASE_BRANCH=$(RELEASE_BRANCH) \
|
|
||||||
-DRELEASE_REVISION=$(RELEASE_REVISION) \
|
|
||||||
|
|
||||||
INCLUDES = \
|
INCLUDES = \
|
||||||
-Iinc \
|
-Iinc \
|
||||||
-I$(STM32_STDPERIPH_INC) \
|
-I$(STM32_STDPERIPH_INC) \
|
||||||
@@ -64,16 +50,11 @@ INCLUDES = \
|
|||||||
|
|
||||||
all: OLI_STM32_H107
|
all: OLI_STM32_H107
|
||||||
|
|
||||||
OLI_STM32_H107: export RELEASE_PRODUCT := $(S0_RELEASE_PRODUCT)
|
|
||||||
OLI_STM32_H107: export RELEASE_MAJOR := $(S0_RELEASE_MAJOR)
|
|
||||||
OLI_STM32_H107: export RELEASE_MINOR := $(S0_RELEASE_MINOR)
|
|
||||||
OLI_STM32_H107: export RELEASE_BRANCH := $(S0_RELEASE_BRANCH)
|
|
||||||
OLI_STM32_H107: export RELEASE_REVISION := $(S0_RELEASE_REVISION)
|
|
||||||
OLI_STM32_H107: export OBJ_DIR := obj_release/
|
OLI_STM32_H107: export OBJ_DIR := obj_release/
|
||||||
OLI_STM32_H107: export OBJECTS := $(OBJECTS_GEN)
|
OLI_STM32_H107: export OBJECTS := $(OBJECTS_GEN)
|
||||||
OLI_STM32_H107: export OBJECTS_MAIN := $(OBJECTS_MAIN)
|
OLI_STM32_H107: export OBJECTS_MAIN := $(OBJECTS_MAIN)
|
||||||
OLI_STM32_H107: export CROSS_COMPILE := arm-none-eabi-
|
OLI_STM32_H107: export CROSS_COMPILE := arm-none-eabi-
|
||||||
OLI_STM32_H107: export CCFLAGS := -c -O2 -Wall -g -lc -lm -fno-common -mcpu=cortex-m3 -DOLI_STM32_H107 -DENABLE_SERIAL_LOGGING -mthumb $(RELEASE_DEFINES) $(INCLUDES)
|
OLI_STM32_H107: export CCFLAGS := -c -O2 -Wall -g -lc -lm -fno-common -mcpu=cortex-m3 -DOLI_STM32_H107 -DENABLE_SERIAL_LOGGING -mthumb $(PLATFORM) $(RELEASE_DEFINES) $(INCLUDES)
|
||||||
OLI_STM32_H107: export ASFLAGS := -g -mapcs-32
|
OLI_STM32_H107: export ASFLAGS := -g -mapcs-32
|
||||||
OLI_STM32_H107: export LDFLAGS := -g -nostartfiles -mcpu=cortex-m3 -mthumb -T$(LINKER_SCRIPTS_DIR)/$(LINKER_SCRIPT) -Wl,-Map=hsb_mrts_OLI_STM32_H107.map
|
OLI_STM32_H107: export LDFLAGS := -g -nostartfiles -mcpu=cortex-m3 -mthumb -T$(LINKER_SCRIPTS_DIR)/$(LINKER_SCRIPT) -Wl,-Map=hsb_mrts_OLI_STM32_H107.map
|
||||||
OLI_STM32_H107: export LDARCHIVES := -L. -L$(STM32_STDPERIPH_ROOT) -L$(PLATFORM_DIR) -L$(HAL_DIR) -lhsb_mrts_OLI_STM32_H107 -lPlatform -lHAL -lSTM_StdPeriph
|
OLI_STM32_H107: export LDARCHIVES := -L. -L$(STM32_STDPERIPH_ROOT) -L$(PLATFORM_DIR) -L$(HAL_DIR) -lhsb_mrts_OLI_STM32_H107 -lPlatform -lHAL -lSTM_StdPeriph
|
||||||
|
|||||||
@@ -34,26 +34,40 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include "semphr.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
#include "DisplayDevice.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define DISPLAY_MAX_ROWS (6)
|
||||||
|
#define DISPLAY_MAX_COLUMNS (25)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions.
|
// Type definitions.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct DisplayCharacter
|
||||||
|
{
|
||||||
|
char character;
|
||||||
|
bool isUpdated;
|
||||||
|
};
|
||||||
|
|
||||||
struct Display
|
struct Display
|
||||||
{
|
{
|
||||||
void* displayDriver; // USE WITH CAUTION - VOID POINTER
|
struct DisplayDevice* displayDevice;
|
||||||
TaskHandle_t taskHandle;
|
TaskHandle_t taskHandle;
|
||||||
int TaskPriority;
|
int TaskPriority;
|
||||||
|
uint16_t stackSize;
|
||||||
bool runTask;
|
bool runTask;
|
||||||
|
SemaphoreHandle_t displayShadowAccessSemaphore;
|
||||||
|
struct DisplayCharacter displayShadow[DISPLAY_MAX_ROWS][DISPLAY_MAX_COLUMNS];
|
||||||
|
int maxCharactersPerTransmit;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -65,11 +79,14 @@ struct Display
|
|||||||
* Constructor for a display application
|
* Constructor for a display application
|
||||||
*
|
*
|
||||||
* @param self The display object to initialize
|
* @param self The display object to initialize
|
||||||
* @param displayDriver The specific display driver that the
|
* @param displayDevice The specific display device that the
|
||||||
* application will use
|
* application will use
|
||||||
* This is a constant and will not be matter
|
* @param TaskPriority Priority for the display Task
|
||||||
* to changes after initialisation. Only
|
* 0 is highest (most important)
|
||||||
* via destruct and a new construct
|
* @param stackSize Number of words (not bytes) for the
|
||||||
|
* display task
|
||||||
|
* @param maxNumberOfCharacters Max number of characters to send within
|
||||||
|
* one transfer action
|
||||||
*
|
*
|
||||||
* @return ErrorStatus SUCCESS if initialisation was OK
|
* @return ErrorStatus SUCCESS if initialisation was OK
|
||||||
* ERROR otherwise
|
* ERROR otherwise
|
||||||
@@ -77,7 +94,7 @@ struct Display
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus Display_construct(struct Display* self, void* displayDriver);
|
extern ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displayDevice, int TaskPriority, uint16_t stackSize, int maxCharactersPerTransmit);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -109,6 +126,54 @@ extern void Display_destruct(struct Display* self);
|
|||||||
extern ErrorStatus Display_clearScreen(struct Display* self);
|
extern ErrorStatus Display_clearScreen(struct Display* self);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Display_setState
|
||||||
|
* Sets the display state
|
||||||
|
*
|
||||||
|
* @param self The display information to use
|
||||||
|
* @param state The state to set
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if clearing display was OK
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus Display_setState(struct Display* self, DisplayDevice_functionalState state);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Display_setBrightness
|
||||||
|
* Sets the display brightness
|
||||||
|
*
|
||||||
|
* @param self The display information to use
|
||||||
|
* @param brightness The brightness to set
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if clearing display was OK
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus Display_setBrightness(struct Display* self, size_t brightness);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Display_setContrast
|
||||||
|
* Sets the display contrast
|
||||||
|
*
|
||||||
|
* @param self The display information to use
|
||||||
|
* @param state The contrast to set
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if clearing display was OK
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus Display_setContrast(struct Display* self, size_t contrast);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
* Display_write
|
* Display_write
|
||||||
* Description of function
|
* Description of function
|
||||||
@@ -130,6 +195,6 @@ extern ErrorStatus Display_clearScreen(struct Display* self);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int length, unsigned int row, unsigned int column);
|
extern ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int length, size_t row, size_t column);
|
||||||
|
|
||||||
#endif /* DISPLAY_H_ */
|
#endif /* DISPLAY_H_ */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
/// @file Display_nhd0420.c
|
/// @file Display.c
|
||||||
/// @brief Description
|
/// @brief Description
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Micro-Key bv
|
// Micro-Key bv
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
// (c) 2017 Micro-Key bv
|
// (c) 2017 Micro-Key bv
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// @file Display_nhd0420.c
|
/// @file Display.c
|
||||||
/// @ingroup {group_name}
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
|
||||||
@@ -34,27 +34,16 @@
|
|||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define DISPLAY_TASK_STACK_SIZE (2048)
|
|
||||||
#define DISPLAY_TRANSMIT_MAX_CHUNK (10)
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions
|
// Type definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
struct displayCharacter
|
|
||||||
{
|
|
||||||
char character;
|
|
||||||
bool isUpdated;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// File-scope variables
|
// File-scope variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static SemaphoreHandle_t displayShadowAccessSemaphore;
|
|
||||||
|
|
||||||
static struct displayCharacter displayShadow[NHD0420_NUMBER_OF_ROWS][NHD0420_NUMBER_OF_COLUMNS];
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
@@ -62,46 +51,47 @@ static struct displayCharacter displayShadow[NHD0420_NUMBER_OF_ROWS][NHD0420_NUM
|
|||||||
|
|
||||||
static void DisplayTask(void* parameters);
|
static void DisplayTask(void* parameters);
|
||||||
|
|
||||||
inline static void Display_characterUpdate (struct displayCharacter* displayCharacter, char character);
|
inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character);
|
||||||
inline static bool Display_isCharacterUpdated (struct displayCharacter* displayCharacter);
|
inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter);
|
||||||
inline static char Display_getUpdatedCharacter (struct displayCharacter* displayCharacter);
|
inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter);
|
||||||
|
|
||||||
static void printfShadow(void);
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function definitions
|
// 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 rowCounter = 0;
|
||||||
int colCounter = 0;
|
int colCounter = 0;
|
||||||
ErrorStatus returnValue = SUCCESS;
|
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
|
// 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)
|
if(returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
// Create a semaphore to sync access to the display shadow
|
// Create a semaphore to sync access to the display shadow
|
||||||
vSemaphoreCreateBinary(displayShadowAccessSemaphore);
|
vSemaphoreCreateBinary(self->displayShadowAccessSemaphore);
|
||||||
xSemaphoreGive(displayShadowAccessSemaphore);
|
xSemaphoreGive(self->displayShadowAccessSemaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->runTask = true;
|
self->runTask = true;
|
||||||
|
|
||||||
if(returnValue == SUCCESS)
|
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;
|
returnValue = ERROR;
|
||||||
LOGGER_ERROR("Starting display task failed");
|
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;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,18 +109,42 @@ ErrorStatus Display_construct(struct Display* self, void* displayDriver)
|
|||||||
void Display_destruct(struct Display* self)
|
void Display_destruct(struct Display* self)
|
||||||
{
|
{
|
||||||
self->runTask = false;
|
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;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
// Prior to any action on the display memory, perform necessary checkings
|
// Prior to any action on the display memory, perform necessary checkings
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
// Check that the row coordinate does not exceed the display boundary
|
// 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;
|
returnValue = ERROR;
|
||||||
}
|
}
|
||||||
@@ -151,7 +152,7 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int
|
|||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
// Check that the column coordinate does not exceed the display boundary
|
// 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;
|
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
|
// Check that the length request does not exceed the display boundary
|
||||||
// This is checked in combination with the column coordinate
|
// 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
|
// 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;
|
returnValue = ERROR;
|
||||||
}
|
}
|
||||||
@@ -171,34 +172,34 @@ ErrorStatus Display_write(struct Display* self, const char* buffer, unsigned int
|
|||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
// Get the access semaphore to the display memory - wait for access
|
// Get the access semaphore to the display memory - wait for access
|
||||||
xSemaphoreTake(displayShadowAccessSemaphore, portMAX_DELAY);
|
xSemaphoreTake(self->displayShadowAccessSemaphore, portMAX_DELAY);
|
||||||
|
|
||||||
int loopCounter;
|
int loopCounter;
|
||||||
for (loopCounter = 0; loopCounter < length; 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;
|
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->character = character;
|
||||||
displayCharacter->isUpdated = true;
|
displayCharacter->isUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline static bool Display_isCharacterUpdated (struct displayCharacter* displayCharacter)
|
inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter)
|
||||||
{
|
{
|
||||||
return displayCharacter->isUpdated;
|
return displayCharacter->isUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline static char Display_getUpdatedCharacter (struct displayCharacter* displayCharacter)
|
inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter)
|
||||||
{
|
{
|
||||||
displayCharacter->isUpdated = false;
|
displayCharacter->isUpdated = false;
|
||||||
return displayCharacter->character;
|
return displayCharacter->character;
|
||||||
@@ -207,41 +208,43 @@ inline static char Display_getUpdatedCharacter (struct displayCharacter* display
|
|||||||
|
|
||||||
static void DisplayTask(void* parameters)
|
static void DisplayTask(void* parameters)
|
||||||
{
|
{
|
||||||
const struct Display* self = (const struct Display*)parameters;
|
struct Display* self = (struct Display*)parameters;
|
||||||
const struct NHD0420* displayDriver = (const struct NHD0420*)self->displayDriver;
|
|
||||||
|
|
||||||
bool leaveLoops = false;
|
bool leaveLoops = false;
|
||||||
char buffer[NHD0420_NUMBER_OF_COLUMNS];
|
char buffer[NHD0420_NUMBER_OF_COLUMNS];
|
||||||
int bufferIndex = 0;
|
int bufferIndex = 0;
|
||||||
int rowCounter = 0;
|
int rowCounter = 0;
|
||||||
int colCounter = 0;
|
int colCounter = 0;
|
||||||
|
|
||||||
|
size_t rowStart;
|
||||||
|
size_t columnStart;
|
||||||
while (self->runTask)
|
while (self->runTask)
|
||||||
{
|
{
|
||||||
// Get the access semaphore to the shadow - wait until the write function is finished with updating the shadow
|
// 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;
|
leaveLoops = false;
|
||||||
bufferIndex = 0;
|
bufferIndex = 0;
|
||||||
// printfShadow();
|
|
||||||
|
|
||||||
// Fragment display writing - writing will be done per line
|
// 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
|
// Found a character that has been updated
|
||||||
// Put the display cursor at the appropriate coordinates
|
// Put the display cursor at the appropriate coordinates
|
||||||
NHD0420_setCursorToPosition(displayDriver, rowCounter + 1, colCounter + 1);
|
rowStart = rowCounter + 1;
|
||||||
for (bufferIndex = 0; (colCounter < NHD0420_NUMBER_OF_COLUMNS); colCounter++, bufferIndex++)
|
columnStart = colCounter + 1;
|
||||||
|
for (bufferIndex = 0; (colCounter < self->displayDevice->parameters.numberOfColumns); colCounter++, bufferIndex++)
|
||||||
{
|
{
|
||||||
// Respect the max number of bytes to transmit
|
// Respect the max number of bytes to transmit
|
||||||
if (bufferIndex < DISPLAY_TRANSMIT_MAX_CHUNK)
|
if (bufferIndex < self->maxCharactersPerTransmit)
|
||||||
{
|
{
|
||||||
// Still within the boundaries
|
// 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
|
// Current character has been updated and must be sent to display
|
||||||
// But data from display shadow to transmit buffer
|
// But data from display shadow to transmit buffer
|
||||||
buffer[bufferIndex] = Display_getUpdatedCharacter(&displayShadow[rowCounter][colCounter]);
|
buffer[bufferIndex] = Display_getUpdatedCharacter(&self->displayShadow[rowCounter][colCounter]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -272,20 +275,20 @@ static void DisplayTask(void* parameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Give back display memory access semaphore to allow new updates
|
// Give back display memory access semaphore to allow new updates
|
||||||
xSemaphoreGive(displayShadowAccessSemaphore);
|
xSemaphoreGive(self->displayShadowAccessSemaphore);
|
||||||
if (bufferIndex > 0)
|
if (bufferIndex > 0)
|
||||||
{
|
{
|
||||||
// If there was an update found, send it to the display
|
// 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
|
// 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
|
// End of row reached - reset column and increment row
|
||||||
colCounter = 0;
|
colCounter = 0;
|
||||||
|
|
||||||
if (rowCounter < (NHD0420_NUMBER_OF_ROWS - 1))
|
if (rowCounter < (self->displayDevice->parameters.numberOfRows - 1))
|
||||||
{
|
{
|
||||||
// Increment row
|
// Increment row
|
||||||
rowCounter++;
|
rowCounter++;
|
||||||
@@ -296,6 +299,7 @@ static void DisplayTask(void* parameters)
|
|||||||
rowCounter = 0;
|
rowCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vTaskDelay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task has been marked to end - after leaving the endless loop, end/delete this task
|
// 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 <FreeRTOSFixes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// FreeRTOS includes
|
// FreeRTOS includes
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
@@ -38,17 +39,20 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "stm32f10x_rcc.h"
|
#include "stm32f10x_rcc.h"
|
||||||
|
|
||||||
|
#include "DisplayDevice.h"
|
||||||
#include "MAX5715.h"
|
#include "MAX5715.h"
|
||||||
#include "nhd0420.h"
|
#include "nhd0420.h"
|
||||||
#include "keypadMatrix.h"
|
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "adc.h"
|
||||||
#include "IODevice.h"
|
#include "IODevice.h"
|
||||||
|
#include "keypadMatrix.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "PCBA.h"
|
#include "PCBA.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "spiDevice.h"
|
#include "spiDevice.h"
|
||||||
|
#include "Version.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
@@ -132,8 +136,10 @@ static void printSystemInfoTask(void* parameters)
|
|||||||
{
|
{
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
uint16_t adcValue = 0;
|
||||||
|
LOGGER_INFO("---------------------------------------");
|
||||||
systeminfoCommandHandler();
|
systeminfoCommandHandler();
|
||||||
vTaskDelay(60000);
|
vTaskDelay(2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +158,8 @@ static ErrorStatus systeminfoCommandHandler(void)
|
|||||||
OS_logTaskInfo(ledTaskHandle);
|
OS_logTaskInfo(ledTaskHandle);
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
OS_logTaskInfo(sysTaskHandle);
|
OS_logTaskInfo(sysTaskHandle);
|
||||||
|
vTaskDelay(100);
|
||||||
|
OS_logTaskInfo(display.taskHandle);
|
||||||
|
|
||||||
return errorStatus;
|
return errorStatus;
|
||||||
}
|
}
|
||||||
@@ -160,26 +168,31 @@ static void initTask(void* parameters)
|
|||||||
{
|
{
|
||||||
initPlatform();
|
initPlatform();
|
||||||
|
|
||||||
|
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 40, &ledTaskArguments, 0, &ledTaskHandle);
|
||||||
|
|
||||||
Logger_construct(&uart1->device);
|
Logger_construct(&uart1->device);
|
||||||
|
|
||||||
NHD0420_construct(&nhd0420, &spiDisplay->device);
|
NHD0420_construct(&nhd0420, &spiDisplay->device);
|
||||||
|
|
||||||
Display_construct(&display, &nhd0420);
|
Display_construct(&display, &nhd0420.displayDevice, 0, 1024, 10);
|
||||||
PCBA_construct(pcba);
|
|
||||||
|
Display_clearScreen(&display);
|
||||||
|
|
||||||
Display_write(&display, pcba->name, sizeof(pcba->name) / sizeof(pcba->name[0]), 1, 1);
|
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_construct(&max5715, &spiDAC->device);
|
||||||
|
|
||||||
MAX5715_writeCODEn(&max5715, (MAX5715_SEL_DACA | MAX5715_SEL_DACC), 0x579B);
|
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);
|
xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 1, &sysTaskHandle);
|
||||||
|
|
||||||
// Delete this init task
|
// Delete this init task
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
#include "stm32f10x_usart.h"
|
#include "stm32f10x_usart.h"
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "keypadMatrix.h"
|
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user