- added IODevice support
- fixed some issues with the logger and stack sizes git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@216 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#include "nhd0420.h"
|
||||
@@ -58,6 +60,8 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
||||
NHD0420_CURSOR_OFFSET_ROW4
|
||||
};
|
||||
|
||||
static bool initialized = false;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -72,7 +76,65 @@ static struct SpiDevice* nhd0420Interface;
|
||||
ErrorStatus NHD0420_construct(void* interface)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
nhd0420Interface = (struct SpiDevice*)interface;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
nhd0420Interface = (struct SpiDevice*)interface;
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void NHD0420_destruct (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if ((configCPU_CLOCK_HZ / 64) < NHD0420_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 128) < NHD0420_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 256) < NHD0420_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
|
||||
}
|
||||
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 = NHD0420_SPI_CPHA;
|
||||
parameters->SPI_CPOL = NHD0420_SPI_CPOL;
|
||||
parameters->SPI_CRCPolynomial = NHD0420_SPI_CRCPolynomial;
|
||||
parameters->SPI_DataSize = NHD0420_SPI_DataSize;
|
||||
parameters->SPI_Direction = NHD0420_SPI_Direction;
|
||||
parameters->SPI_FirstBit = NHD0420_SPI_FirstBit;
|
||||
parameters->SPI_Mode = NHD0420_SPI_Mode;
|
||||
parameters->SPI_NSS = NHD0420_SPI_NSS;
|
||||
parameters->rxQueueSize = NHD0420_SPI_RX_QUEUE;
|
||||
parameters->txQueueSize = NHD0420_SPI_TX_QUEUE;
|
||||
}
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
@@ -100,7 +162,7 @@ ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column)
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
uint8_t address = nhd0420_cursorRowOffset[row] + column;
|
||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
|
||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
|
||||
returnValue = NHD0420_sendData(buffer, 3);
|
||||
}
|
||||
|
||||
@@ -126,7 +188,7 @@ ErrorStatus NHD0420_setContrast(uint8_t contrast)
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
|
||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
|
||||
returnValue = NHD0420_sendData(buffer, 3);
|
||||
}
|
||||
|
||||
@@ -152,7 +214,7 @@ ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness)
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
|
||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
|
||||
returnValue = NHD0420_sendData(buffer, 3);
|
||||
}
|
||||
|
||||
@@ -177,7 +239,7 @@ ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate)
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_RS232_BR, baudrate};
|
||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_RS232_BR, baudrate};
|
||||
returnValue = NHD0420_sendData(buffer, 3);
|
||||
}
|
||||
return returnValue;
|
||||
@@ -201,7 +263,7 @@ ErrorStatus NHD0420_setI2CAddress(uint8_t address)
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_I2C_ADDRSS, address};
|
||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_I2C_ADDRSS, address};
|
||||
returnValue = NHD0420_sendData(buffer, 3);
|
||||
}
|
||||
return returnValue;
|
||||
|
||||
Reference in New Issue
Block a user