Continued work on MAX5715. MACRO functions are done, mostly tested in logic analyzer. SPI unable to work with hardware SS, so software SS is used instead
Added UART3 on PB10/PB11 for terminal (future use) git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@225 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -25,7 +25,11 @@
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include "MAX5715.h"
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -53,3 +57,83 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus MAX5715_construct(struct MAX5715* self, const struct IODevice* device)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
int loopCounter;
|
||||
if (self != NULL)
|
||||
{
|
||||
self->device = device;
|
||||
|
||||
for (loopCounter = 0; loopCounter < MAX5715_NUMBER_OF_DACS; loopCounter++)
|
||||
{
|
||||
self->dac[loopCounter].id = loopCounter;
|
||||
self->dac[loopCounter].value = 0x0000;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void MAX5715_destruct(struct MAX5715* self)
|
||||
{
|
||||
self->device = NULL;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus MAX5715_getSpiParameters(struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if ((configCPU_CLOCK_HZ / 2) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 4) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 8) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CPU clock is too high. The pre-scaler has a max of 256. A clock higher than 25,6 MHz
|
||||
// results in a SPI CLK higher than 100 kHz, which is the max of the display
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
// SPI pre-scaler was no problem - assign the remaining parameters
|
||||
parameters->SPI_CPHA = MAX5715_SPI_CPHA;
|
||||
parameters->SPI_CPOL = MAX5715_SPI_CPOL;
|
||||
parameters->SPI_CRCPolynomial = MAX5715_SPI_CRCPolynomial;
|
||||
parameters->SPI_DataSize = MAX5715_SPI_DataSize;
|
||||
parameters->SPI_Direction = MAX5715_SPI_Direction;
|
||||
parameters->SPI_FirstBit = MAX5715_SPI_FirstBit;
|
||||
parameters->SPI_Mode = MAX5715_SPI_Mode;
|
||||
parameters->SPI_NSS = MAX5715_SPI_NSS;
|
||||
parameters->SPI_NSS_internal = MAX5715_SPI_NSS_INTERNAL;
|
||||
parameters->rxQueueSize = MAX5715_SPI_RX_QUEUE;
|
||||
parameters->txQueueSize = MAX5715_SPI_TX_QUEUE;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus MAX5715_sendCommand(const struct MAX5715* self, uint8_t command, uint16_t data)
|
||||
{
|
||||
char buffer[3] = {(char)command, (char)(data >> 4), (char)((data << 4) & 0x00F0)};
|
||||
|
||||
return IODevice_write(self->device, buffer, 3);
|
||||
}
|
||||
|
||||
@@ -70,17 +70,26 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus NHD0420_construct(const struct IODevice* const device)
|
||||
ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* device)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (self->device == NULL)
|
||||
{
|
||||
self->device = device;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void NHD0420_destruct (const struct IODevice* self)
|
||||
void NHD0420_destruct (struct NHD0420* self)
|
||||
{
|
||||
|
||||
self->device = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +127,7 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
||||
parameters->SPI_FirstBit = NHD0420_SPI_FirstBit;
|
||||
parameters->SPI_Mode = NHD0420_SPI_Mode;
|
||||
parameters->SPI_NSS = NHD0420_SPI_NSS;
|
||||
parameters->SPI_NSS_internal = NHD0420_SPI_NSS_INTERNAL;
|
||||
parameters->rxQueueSize = NHD0420_SPI_RX_QUEUE;
|
||||
parameters->txQueueSize = NHD0420_SPI_TX_QUEUE;
|
||||
}
|
||||
@@ -127,7 +137,7 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setCursorToPosition(const struct IODevice* self, char row, char column)
|
||||
ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, char row, char column)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -157,7 +167,7 @@ ErrorStatus NHD0420_setCursorToPosition(const struct IODevice* self, char row, c
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setContrast(const struct IODevice* self, char contrast)
|
||||
ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -183,7 +193,7 @@ ErrorStatus NHD0420_setContrast(const struct IODevice* self, char contrast)
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setBacklightBrightness(const struct IODevice* self, char brightness)
|
||||
ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brightness)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -209,7 +219,7 @@ ErrorStatus NHD0420_setBacklightBrightness(const struct IODevice* self, char bri
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setRS232Baudrate(const struct IODevice* self, char baudrate)
|
||||
ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -233,7 +243,7 @@ ErrorStatus NHD0420_setRS232Baudrate(const struct IODevice* self, char baudrate)
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setI2CAddress(const struct IODevice* self, char address)
|
||||
ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -268,23 +278,23 @@ ErrorStatus NHD0420_setI2CAddress(const struct IODevice* self, char address)
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
ErrorStatus NHD0420_sendCommand(const struct IODevice* self, char command)
|
||||
ErrorStatus NHD0420_sendCommand(const struct NHD0420* self, char command)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
char buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
|
||||
|
||||
returnValue = IODevice_write(self, buffer, NHD0420_CMD_LENGTH);
|
||||
returnValue = IODevice_write(self->device, buffer, NHD0420_CMD_LENGTH);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_sendData(const struct IODevice* self, const char* buffer, size_t length)
|
||||
ErrorStatus NHD0420_sendData(const struct NHD0420* self, const char* buffer, size_t length)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
returnValue = IODevice_write(self, buffer, length);
|
||||
returnValue = IODevice_write(self->device, buffer, length);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user