Improvements:

- HAL re-organized
- FreeRTOS running stable
- UART finished
- SPI1 & SPI3 finished and functional
- Display driver added (functional)


git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@172 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-09-20 06:51:53 +00:00
parent f5dd9e0f09
commit c9562e8bfd
313 changed files with 8279 additions and 50216 deletions

View File

@@ -0,0 +1,241 @@
// -----------------------------------------------------------------------------
/// @file nhd0420.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 nhd0420.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdio.h>
#include "stm32f10x.h"
#include "nhd0420.h"
#include "spi.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define NHD0420_CURSOR_OFFSET_ROW1 (0x00)
#define NHD0420_CURSOR_OFFSET_ROW2 (0x40)
#define NHD0420_CURSOR_OFFSET_ROW3 (0x14)
#define NHD0420_CURSOR_OFFSET_ROW4 (0x54)
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
{
NHD0420_CURSOR_OFFSET_ROW1,
NHD0420_CURSOR_OFFSET_ROW2,
NHD0420_CURSOR_OFFSET_ROW3,
NHD0420_CURSOR_OFFSET_ROW4
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
static struct SpiDevice* nhd0420Interface;
ErrorStatus NHD0420_construct(void* interface)
{
ErrorStatus returnValue = SUCCESS;
nhd0420Interface = (struct SpiDevice*)interface;
return returnValue;
}
ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column)
{
ErrorStatus returnValue = SUCCESS;
// Setting cursor requires sending a command sequence with an additional
// address parameter representing the line/column
// Each line has a dedicated offset, the column is simply added to that offset
// Make sure to keep within boundaries to avoid glitches
row = row -1;
column = column - 1;
// Check the coordinates to avoid glitches
if ((row >= NHD0420_NUMBER_OF_ROWS) && (column >= NHD0420_NUMBER_OF_COLUMNS))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
uint8_t address = nhd0420_cursorRowOffset[row] + column;
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setContrast(uint8_t contrast)
{
ErrorStatus returnValue = SUCCESS;
// Setting contrast requires sending a command sequence with an additional
// parameter representing the contrast
// Contrast values must be between NHD0420_CONTRAST_MIN and
// NHD0420_CONTRAST_MAX. If boundaries are exceeded, this function will be
// left with an ERROR
if ((contrast < NHD0420_CONTRAST_MIN) || (contrast > NHD0420_CONTRAST_MAX))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness)
{
ErrorStatus returnValue = SUCCESS;
// Setting backlight brightness requires sending a command sequence with an
// additional parameter representing the brightness
// Brightness values must be between NHD0420_BRIGHTNESS_MIN and
// NHD0420_BRIGHTNESS_MAX. If boundaries are exceeded, this function will be
// left with an ERROR
if ((brightness < NHD0420_BRIGHTNESS_MIN) || (brightness > NHD0420_BRIGHTNESS_MAX))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate)
{
ErrorStatus returnValue = SUCCESS;
// Setting baudrate requires sending a command sequence with an
// additional parameter representing the baudrate
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
// NHD0420_BAUDRATE_MAX. If boundaries are exceeded, this function will be
// left with an ERROR
if ((baudrate < NHD0420_BAUDRATE_MIN) || (baudrate > NHD0420_BAUDRATE_MAX))
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_RS232_BR, baudrate};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
ErrorStatus NHD0420_setI2CAddress(uint8_t address)
{
ErrorStatus returnValue = SUCCESS;
// Setting I2C requires sending a command sequence with an
// additional parameter representing the address
// Baudrate values must be between NHD0420_BAUDRATE_MIN and
// NHD0420_BAUDRATE_MAX. If boundaries are exeeded, this function will be
// left with an ERROR
if ((address | 0xFE) != 0xFE)
{
returnValue = ERROR;
}
if (returnValue == SUCCESS)
{
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CHANGE_I2C_ADDRSS, address};
returnValue = NHD0420_sendData(buffer, 3);
}
return returnValue;
}
/** ----------------------------------------------------------------------------
* NHD0420_SendCommand
* Send a command to the display
*
* @param command
*
* @return ErrorStatus SUCCESS if initialisation was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
ErrorStatus NHD0420_sendCommand(uint8_t command)
{
ErrorStatus returnValue = SUCCESS;
uint8_t buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
returnValue = SPI_write(nhd0420Interface, buffer, NHD0420_CMD_LENGTH);
return returnValue;
}
ErrorStatus NHD0420_sendData(const uint8_t* buffer, size_t length)
{
ErrorStatus returnValue = SUCCESS;
returnValue = SPI_write(nhd0420Interface, buffer, length);
return returnValue;
}