Fixed some initialisation issues
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@237 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ struct DisplayDevice
|
|||||||
DisplaySetContrastFunction _setContrast;
|
DisplaySetContrastFunction _setContrast;
|
||||||
DisplayInvertFunction _invert;
|
DisplayInvertFunction _invert;
|
||||||
struct DisplayDeviceParameters parameters;
|
struct DisplayDeviceParameters parameters;
|
||||||
|
bool initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ struct NHD0420
|
|||||||
{
|
{
|
||||||
struct DisplayDevice displayDevice;
|
struct DisplayDevice displayDevice;
|
||||||
const struct IODevice* device;
|
const struct IODevice* device;
|
||||||
|
bool initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ ErrorStatus DisplayDevice_construct (struct DisplayDevice* self, struct DisplayD
|
|||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
self->_reset = reset;
|
self->_reset = reset;
|
||||||
self->_setState = setState;
|
self->_setState = setState;
|
||||||
self->_write = write;
|
self->_write = write;
|
||||||
@@ -75,6 +77,11 @@ ErrorStatus DisplayDevice_construct (struct DisplayDevice* self, struct DisplayD
|
|||||||
self->_invert = invert;
|
self->_invert = invert;
|
||||||
|
|
||||||
self->parameters = *parameters;
|
self->parameters = *parameters;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
@@ -82,11 +89,17 @@ ErrorStatus DisplayDevice_construct (struct DisplayDevice* self, struct DisplayD
|
|||||||
ErrorStatus DisplayDevice_reset(const struct DisplayDevice* self)
|
ErrorStatus DisplayDevice_reset(const struct DisplayDevice* self)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_reset != NULL)
|
if (self->_reset != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_reset(self);
|
returnValue = self->_reset(self);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,11 +107,17 @@ ErrorStatus DisplayDevice_reset(const struct DisplayDevice* self)
|
|||||||
ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_setState != NULL)
|
if (self->_setState != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_setState(self, state);
|
returnValue = self->_setState(self, state);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,11 +125,17 @@ ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevi
|
|||||||
ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_write != NULL)
|
if (self->_write != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_write(self, buffer, length, row, column);
|
returnValue = self->_write(self, buffer, length, row, column);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,11 +143,17 @@ ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* bu
|
|||||||
ErrorStatus DisplayDevice_clear(const struct DisplayDevice* self)
|
ErrorStatus DisplayDevice_clear(const struct DisplayDevice* self)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_clear != NULL)
|
if (self->_clear != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_clear(self);
|
returnValue = self->_clear(self);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,11 +161,17 @@ ErrorStatus DisplayDevice_clear(const struct DisplayDevice* self)
|
|||||||
ErrorStatus DisplayDevice_setBrightness(const struct DisplayDevice* self, size_t brightness)
|
ErrorStatus DisplayDevice_setBrightness(const struct DisplayDevice* self, size_t brightness)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_setBrightness != NULL)
|
if (self->_setBrightness != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_setBrightness(self, brightness);
|
returnValue = self->_setBrightness(self, brightness);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,11 +179,17 @@ ErrorStatus DisplayDevice_setBrightness(const struct DisplayDevice* self, size_t
|
|||||||
ErrorStatus DisplayDevice_setContrast(const struct DisplayDevice* self, size_t contrast)
|
ErrorStatus DisplayDevice_setContrast(const struct DisplayDevice* self, size_t contrast)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_setContrast != NULL)
|
if (self->_setContrast != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_setContrast(self, contrast);
|
returnValue = self->_setContrast(self, contrast);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,10 +197,16 @@ ErrorStatus DisplayDevice_setContrast(const struct DisplayDevice* self, size_t c
|
|||||||
ErrorStatus DisplayDevice_invert(const struct DisplayDevice* self)
|
ErrorStatus DisplayDevice_invert(const struct DisplayDevice* self)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (self->_invert != NULL)
|
if (self->_invert != NULL)
|
||||||
{
|
{
|
||||||
returnValue = self->_invert(self);
|
returnValue = self->_invert(self);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ ErrorStatus MAX5715Channel_construct(struct MAX5715_DAC* self, struct MAX5715* p
|
|||||||
if (id < MAX5715_NUMBER_OF_DACS)
|
if (id < MAX5715_NUMBER_OF_DACS)
|
||||||
{
|
{
|
||||||
// Check that the parent has no channel already initialized on that ID
|
// Check that the parent has no channel already initialized on that ID
|
||||||
if (!parent->dac[id].initialized)
|
if ((!parent->dac[id].initialized) && (parent->initialized))
|
||||||
{
|
{
|
||||||
if (!self->initialized)
|
if (!self->initialized)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic
|
|||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
if (self->device == NULL)
|
if (!self->initialized)
|
||||||
|
{
|
||||||
|
if (device != NULL)
|
||||||
{
|
{
|
||||||
self->device = device;
|
self->device = device;
|
||||||
|
|
||||||
@@ -96,6 +98,11 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic
|
|||||||
{
|
{
|
||||||
returnValue = ERROR;
|
returnValue = ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
@@ -104,6 +111,7 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic
|
|||||||
void NHD0420_destruct (struct NHD0420* self)
|
void NHD0420_destruct (struct NHD0420* self)
|
||||||
{
|
{
|
||||||
self->device = NULL;
|
self->device = NULL;
|
||||||
|
self->initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -154,7 +162,8 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
|||||||
ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, size_t row, size_t column)
|
ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, size_t row, size_t column)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
// Setting cursor requires sending a command sequence with an additional
|
// Setting cursor requires sending a command sequence with an additional
|
||||||
// address parameter representing the line/column
|
// address parameter representing the line/column
|
||||||
|
|
||||||
@@ -176,7 +185,11 @@ ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, size_t row,
|
|||||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
|
||||||
returnValue = NHD0420_sendData(self, buffer, 3);
|
returnValue = NHD0420_sendData(self, buffer, 3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +197,8 @@ ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, size_t row,
|
|||||||
ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast)
|
ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
// Setting contrast requires sending a command sequence with an additional
|
// Setting contrast requires sending a command sequence with an additional
|
||||||
// parameter representing the contrast
|
// parameter representing the contrast
|
||||||
// Contrast values must be between NHD0420_CONTRAST_MIN and
|
// Contrast values must be between NHD0420_CONTRAST_MIN and
|
||||||
@@ -202,7 +216,11 @@ ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast)
|
|||||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
|
||||||
returnValue = NHD0420_sendData(self, buffer, 3);
|
returnValue = NHD0420_sendData(self, buffer, 3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +228,8 @@ ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast)
|
|||||||
ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brightness)
|
ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brightness)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
// Setting backlight brightness requires sending a command sequence with an
|
// Setting backlight brightness requires sending a command sequence with an
|
||||||
// additional parameter representing the brightness
|
// additional parameter representing the brightness
|
||||||
// Brightness values must be between NHD0420_BRIGHTNESS_MIN and
|
// Brightness values must be between NHD0420_BRIGHTNESS_MIN and
|
||||||
@@ -228,7 +247,11 @@ ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brig
|
|||||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
|
||||||
returnValue = NHD0420_sendData(self, buffer, 3);
|
returnValue = NHD0420_sendData(self, buffer, 3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +259,8 @@ ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brig
|
|||||||
ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate)
|
ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
// Setting baudrate requires sending a command sequence with an
|
// Setting baudrate requires sending a command sequence with an
|
||||||
// additional parameter representing the baudrate
|
// additional parameter representing the baudrate
|
||||||
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
|
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
|
||||||
@@ -253,6 +277,11 @@ ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate)
|
|||||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_RS232_BR, baudrate};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_RS232_BR, baudrate};
|
||||||
returnValue = NHD0420_sendData(self, buffer, 3);
|
returnValue = NHD0420_sendData(self, buffer, 3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +289,8 @@ ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate)
|
|||||||
ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address)
|
ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
// Setting I2C requires sending a command sequence with an
|
// Setting I2C requires sending a command sequence with an
|
||||||
// additional parameter representing the address
|
// additional parameter representing the address
|
||||||
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
|
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
|
||||||
@@ -277,6 +307,11 @@ ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address)
|
|||||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_I2C_ADDRSS, address};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_I2C_ADDRSS, address};
|
||||||
returnValue = NHD0420_sendData(self, buffer, 3);
|
returnValue = NHD0420_sendData(self, buffer, 3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,11 +330,16 @@ ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address)
|
|||||||
ErrorStatus NHD0420_sendCommand(const struct NHD0420* self, char command)
|
ErrorStatus NHD0420_sendCommand(const struct NHD0420* self, char command)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
char buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
|
char buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
|
||||||
|
|
||||||
returnValue = IODevice_write(self->device, buffer, NHD0420_CMD_LENGTH);
|
returnValue = IODevice_write(self->device, buffer, NHD0420_CMD_LENGTH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,18 +347,23 @@ ErrorStatus NHD0420_sendCommand(const struct NHD0420* self, char command)
|
|||||||
ErrorStatus NHD0420_sendData(const struct NHD0420* self, const char* buffer, size_t length)
|
ErrorStatus NHD0420_sendData(const struct NHD0420* self, const char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
returnValue = IODevice_write(self->device, buffer, length);
|
returnValue = IODevice_write(self->device, buffer, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
if (state == ON)
|
if (state == ON)
|
||||||
{
|
{
|
||||||
returnValue = NHD0420_turnOnDisplay((const struct NHD0420*)self);
|
returnValue = NHD0420_turnOnDisplay((const struct NHD0420*)self);
|
||||||
@@ -327,8 +372,11 @@ static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_func
|
|||||||
{
|
{
|
||||||
returnValue = NHD0420_turnOffDisplay((const struct NHD0420*)self);
|
returnValue = NHD0420_turnOffDisplay((const struct NHD0420*)self);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,6 +384,8 @@ static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_func
|
|||||||
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
// Set cursor on display
|
// Set cursor on display
|
||||||
returnValue = NHD0420_setCursorToPosition((const struct NHD0420*)self, row, column);
|
returnValue = NHD0420_setCursorToPosition((const struct NHD0420*)self, row, column);
|
||||||
|
|
||||||
@@ -343,26 +393,52 @@ static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, s
|
|||||||
{
|
{
|
||||||
returnValue = NHD0420_sendData((const struct NHD0420*)self, buffer, length);
|
returnValue = NHD0420_sendData((const struct NHD0420*)self, buffer, length);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus clear(const struct DisplayDevice* self)
|
static ErrorStatus clear(const struct DisplayDevice* self)
|
||||||
|
{
|
||||||
|
if (!self->initialized)
|
||||||
{
|
{
|
||||||
return NHD0420_clearScreen((const struct NHD0420*)self);
|
return NHD0420_clearScreen((const struct NHD0420*)self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness)
|
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness)
|
||||||
|
{
|
||||||
|
if (!self->initialized)
|
||||||
{
|
{
|
||||||
return NHD0420_setBacklightBrightness((const struct NHD0420*)self, brightness);
|
return NHD0420_setBacklightBrightness((const struct NHD0420*)self, brightness);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast)
|
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast)
|
||||||
|
{
|
||||||
|
if (!self->initialized)
|
||||||
{
|
{
|
||||||
return NHD0420_setContrast((const struct NHD0420*)self, contrast);
|
return NHD0420_setContrast((const struct NHD0420*)self, contrast);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length
|
|||||||
ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters)
|
ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
|
|
||||||
self->useDMA = false;
|
self->useDMA = false;
|
||||||
|
|
||||||
@@ -73,7 +75,14 @@ ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters)
|
|||||||
|
|
||||||
ADC_Init(self->ADCx, &self->ADC_InitStruct);
|
ADC_Init(self->ADCx, &self->ADC_InitStruct);
|
||||||
|
|
||||||
|
int loopCounter;
|
||||||
|
for (loopCounter = 0; loopCounter < ADC_NUMBER_OF_CHANNELS; loopCounter++)
|
||||||
|
{
|
||||||
|
self->channel[loopCounter].initialized = false;
|
||||||
|
self->channelValue[loopCounter] = 0;
|
||||||
|
}
|
||||||
|
self->initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
@@ -90,6 +99,7 @@ void ADC_destruct (struct Adc* self)
|
|||||||
ADC_DeInit(self->ADCx);
|
ADC_DeInit(self->ADCx);
|
||||||
self->useDMA = false;
|
self->useDMA = false;
|
||||||
self->useRanks = false;
|
self->useRanks = false;
|
||||||
|
self->initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -144,6 +154,11 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
|
|||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
// Check that the parent has no channel already initialized on that ID
|
||||||
|
if ((!parent->channel[parameters->channel].initialized) && (parent->initialized))
|
||||||
|
{
|
||||||
|
if (!self->initialized)
|
||||||
|
{
|
||||||
IODevice_construct(&self->device, read, NULL);
|
IODevice_construct(&self->device, read, NULL);
|
||||||
|
|
||||||
if ((parameters->Rank) > 0 && (parameters->Rank <= 16))
|
if ((parameters->Rank) > 0 && (parameters->Rank <= 16))
|
||||||
@@ -163,14 +178,23 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
|
|||||||
returnValue = ERROR;
|
returnValue = ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
|
parent->channel[self->channel] = *self;
|
||||||
|
self->parent = parent;
|
||||||
self->ADC_SampleTime = parameters->ADC_SampleTime;
|
self->ADC_SampleTime = parameters->ADC_SampleTime;
|
||||||
|
|
||||||
//TODO MAKE SURE EACH RANK IS USED ONLY ONCE
|
//TODO MAKE SURE EACH RANK IS USED ONLY ONCE
|
||||||
ADC_RegularChannelConfig(self->parent->ADCx, self->channel, self->Rank, self->ADC_SampleTime);
|
ADC_RegularChannelConfig(self->parent->ADCx, self->channel, self->Rank, self->ADC_SampleTime);
|
||||||
self->parent->useRanks = true;
|
self->parent->useRanks = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
@@ -178,7 +202,7 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
|
|||||||
|
|
||||||
void ADCChannel_destruct(struct AdcChannel* self)
|
void ADCChannel_destruct(struct AdcChannel* self)
|
||||||
{
|
{
|
||||||
|
self->initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -233,22 +233,23 @@ ErrorStatus initPlatform(void)
|
|||||||
adc1->ADCx = ADC1;
|
adc1->ADCx = ADC1;
|
||||||
ADC_construct(adc1, adc1Parameters);
|
ADC_construct(adc1, adc1Parameters);
|
||||||
|
|
||||||
|
struct AdcChannel adcChannel = {.initialized = false};
|
||||||
|
|
||||||
struct AdcChannelParameters acParameters;
|
struct AdcChannelParameters acParameters;
|
||||||
acParameters.channel = ADC_Channel_0;
|
acParameters.channel = ADC_Channel_0;
|
||||||
acParameters.Rank = 3;
|
acParameters.Rank = 3;
|
||||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||||
adc1->channel[acParameters.channel].parent = adc1;
|
ADCChannel_construct(&adcChannel, adc1, &acParameters);
|
||||||
ADCChannel_construct(&adc1->channel[acParameters.channel], &acParameters);
|
|
||||||
acParameters.channel = ADC_Channel_1;
|
acParameters.channel = ADC_Channel_1;
|
||||||
acParameters.Rank = 2;
|
acParameters.Rank = 2;
|
||||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||||
adc1->channel[acParameters.channel].parent = adc1;
|
ADCChannel_construct(&adcChannel, adc1, &acParameters);
|
||||||
ADCChannel_construct(&adc1->channel[acParameters.channel], &acParameters);
|
|
||||||
acParameters.channel = ADC_Channel_2;
|
acParameters.channel = ADC_Channel_2;
|
||||||
acParameters.Rank = 1;
|
acParameters.Rank = 1;
|
||||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||||
adc1->channel[acParameters.channel].parent = adc1;
|
ADCChannel_construct(&adcChannel, adc1, &acParameters);
|
||||||
ADCChannel_construct(&adc1->channel[acParameters.channel], &acParameters);
|
|
||||||
|
|
||||||
|
|
||||||
ADC_setDMAStatus(adc1, ENABLE);
|
ADC_setDMAStatus(adc1, ENABLE);
|
||||||
|
|||||||
@@ -160,7 +160,6 @@
|
|||||||
<buildTargets>
|
<buildTargets>
|
||||||
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
<buildCommand>make</buildCommand>
|
<buildCommand>make</buildCommand>
|
||||||
<buildArguments/>
|
|
||||||
<buildTarget>all</buildTarget>
|
<buildTarget>all</buildTarget>
|
||||||
<stopOnError>true</stopOnError>
|
<stopOnError>true</stopOnError>
|
||||||
<useDefaultCommand>true</useDefaultCommand>
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
|||||||
Reference in New Issue
Block a user