- 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
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -32,12 +32,25 @@
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define NHD0420_SPI_MAX_CLK_HZ (100000)
|
||||
// SPI settings
|
||||
#define NHD0420_SPI_Direction (SPI_Direction_1Line_Tx)
|
||||
#define NHD0420_SPI_Mode (SPI_Mode_Master)
|
||||
#define NHD0420_SPI_DataSize (SPI_DataSize_8b)
|
||||
#define NHD0420_SPI_CPOL (SPI_CPOL_High)
|
||||
#define NHD0420_SPI_CPHA (SPI_CPHA_2Edge)
|
||||
#define NHD0420_SPI_NSS (SPI_NSS_Soft)
|
||||
#define NHD0420_SPI_FirstBit (SPI_FirstBit_MSB)
|
||||
#define NHD0420_SPI_CRCPolynomial (7)
|
||||
#define NHD0420_SPI_RX_QUEUE (32)
|
||||
#define NHD0420_SPI_TX_QUEUE (32)
|
||||
|
||||
#define NHD0420_NUMBER_OF_ROWS (4)
|
||||
#define NHD0420_NUMBER_OF_COLUMNS (20)
|
||||
|
||||
@@ -109,7 +122,7 @@
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* NHD0420_Init
|
||||
* NHD0420_construct
|
||||
* Initialises the NewHeaven Display 0420
|
||||
*
|
||||
* @param interface The interface to use
|
||||
@@ -123,6 +136,34 @@
|
||||
extern ErrorStatus NHD0420_construct(void* interface);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* NHD0420_destruct
|
||||
* Destructor for the NHD0420 instance
|
||||
*
|
||||
* @param interface The interface to use
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void NHD0420_destruct(void);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* NHD0420_getSpiParameters
|
||||
* Function that assigns the NHD0420 SPI parameters to a spiParameters struct
|
||||
*
|
||||
* @param parameters
|
||||
*
|
||||
* @return ErrorStatus
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* NHD0420_setCursorToPosition
|
||||
* Sets the cursor of the display to the specified row and column
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
CROSS_COMPILE = arm-none-eabi-
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
LD = $(CROSS_COMPILE)gcc
|
||||
AR = $(CROSS_COMPILE)ar
|
||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||
OBJDUMP = $(CROSS_COMPILE)objdump
|
||||
|
||||
OBJDIR = obj
|
||||
SRCDIR = src/
|
||||
ROOTDIR = ../../
|
||||
|
||||
LIBRARY_NAME = ../libKeypad.a
|
||||
|
||||
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb \
|
||||
-Iinc \
|
||||
-I../Platform/inc \
|
||||
-I../Misc/inc \
|
||||
-I$(ROOTDIR)/hsb-mrts/inc \
|
||||
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc \
|
||||
-I$(ROOTDIR)/FreeRTOS/Source/include \
|
||||
-I$(ROOTDIR)/FreeRTOS/Source/portable/GCC/ARM_CM3 \
|
||||
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x \
|
||||
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
|
||||
ARFLAGS = rs
|
||||
|
||||
OBJECTS = \
|
||||
keypadMatrix.o \
|
||||
|
||||
|
||||
|
||||
vpath %.o $(OBJDIR)
|
||||
vpath %.c $(SRCDIR)
|
||||
|
||||
all: $(LIBRARY_NAME)
|
||||
|
||||
$(LIBRARY_NAME): $(OBJDIR) $(OBJECTS)
|
||||
$(AR) $(ARFLAGS) $@ $(addprefix $(OBJDIR)/, $(OBJECTS))
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CCFLAGS) $< -o $(OBJDIR)/$@
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir -p $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR) $(LIBRARY_NAME)
|
||||
|
||||
.PHONY: all clean
|
||||
@@ -0,0 +1,83 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file keypadMatrix.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) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @defgroup {group_name} {group_description}
|
||||
/// Description
|
||||
|
||||
/// @file keypadMatrix.h
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
#ifndef KEYPAD_INC_KEYPADMATRIX_H_
|
||||
#define KEYPAD_INC_KEYPADMATRIX_H_
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "stm32f10x_exti.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define KEYPAD_NUMBER_OF_ROWS (4)
|
||||
#define KEYPAD_NUMBER_OF_COLUMNS (4)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct keypadElement
|
||||
{
|
||||
T_PL_GPIO gpio;
|
||||
EXTI_InitTypeDef EXTI_InitStruct;
|
||||
};
|
||||
|
||||
struct Keypad
|
||||
{
|
||||
struct keypadElement row[KEYPAD_NUMBER_OF_ROWS];
|
||||
struct keypadElement column[KEYPAD_NUMBER_OF_COLUMNS];
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Keypad_construct
|
||||
* contructor for the Keypad driver
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Keypad_construct(void);
|
||||
|
||||
|
||||
|
||||
extern ErrorStatus Keypad_logModuleInfo(void);
|
||||
|
||||
|
||||
#endif /* KEYPAD_INC_KEYPADMATRIX_H_ */
|
||||
@@ -0,0 +1,133 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file keypadMatrix.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 keypadMatrix.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "FreeRTOSFixes.h"
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include "keypadMatrix.h"
|
||||
#include "platform.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define KEYPAD_STACK_SIZE (512)
|
||||
#define KEYPAD_TASK_PRIORITY (3)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static bool initialized = false;
|
||||
static xTaskHandle keypadTaskHandle = NULL;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static void KeypadTask(void* parameters);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus Keypad_construct(void)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
BaseType_t taskCreateReturn;
|
||||
|
||||
if(!initialized)
|
||||
{
|
||||
if(returnValue == SUCCESS)
|
||||
{
|
||||
taskCreateReturn = xTaskCreate(KeypadTask, (const char*)"keypadTask", KEYPAD_STACK_SIZE, NULL, KEYPAD_TASK_PRIORITY, &keypadTaskHandle);
|
||||
if(taskCreateReturn != pdPASS)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if(returnValue == SUCCESS)
|
||||
{
|
||||
initialized = true;
|
||||
LOGGER_INFO("Keypad task started");
|
||||
// GPIO_SetBits(kRow1->rowGpio.GPIO_Typedef, kRow1->rowGpio.GPIO_InitStruct.GPIO_Pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_ERROR("Keypad task FAILED with code %x", (unsigned int)taskCreateReturn);
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Keypad_logModuleInfo(void)
|
||||
{
|
||||
ErrorStatus errorStatus = SUCCESS;
|
||||
|
||||
OS_logTaskInfo(keypadTaskHandle);
|
||||
|
||||
return errorStatus;
|
||||
}
|
||||
|
||||
|
||||
void Keypad_Destruct (void)
|
||||
{
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
static void KeypadTask(void* parameters)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(1000);
|
||||
|
||||
LOGGER_DEBUG("ROW1: %d, ROW2: %d, ROW3: %d, ROW4: %d - Col1: %d, Col2: %d, Col3: %d, Col4: %d",
|
||||
GPIO_ReadOutputDataBit(keypad->row[0].gpio.GPIO_Typedef, keypad->row[0].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadOutputDataBit(keypad->row[1].gpio.GPIO_Typedef, keypad->row[1].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadOutputDataBit(keypad->row[2].gpio.GPIO_Typedef, keypad->row[2].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadOutputDataBit(keypad->row[3].gpio.GPIO_Typedef, keypad->row[3].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadInputDataBit(keypad->column[0].gpio.GPIO_Typedef, keypad->column[0].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadInputDataBit(keypad->column[1].gpio.GPIO_Typedef, keypad->column[1].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadInputDataBit(keypad->column[2].gpio.GPIO_Typedef, keypad->column[2].gpio.GPIO_InitStruct.GPIO_Pin),
|
||||
GPIO_ReadInputDataBit(keypad->column[3].gpio.GPIO_Typedef, keypad->column[3].gpio.GPIO_InitStruct.GPIO_Pin)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
all:
|
||||
# $(MAKE) -C Keypad
|
||||
$(MAKE) -C Keypad
|
||||
$(MAKE) -C Display
|
||||
$(MAKE) -C Misc
|
||||
$(MAKE) -C Platform
|
||||
|
||||
|
||||
clean:
|
||||
# $(MAKE) -C Keypad clean
|
||||
$(MAKE) -C Keypad clean
|
||||
$(MAKE) -C Display clean
|
||||
$(MAKE) -C Misc clean
|
||||
$(MAKE) -C Platform clean
|
||||
|
||||
@@ -23,10 +23,7 @@ CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb \
|
||||
ARFLAGS = rs
|
||||
|
||||
OBJECTS = \
|
||||
stm32f10x_it.o \
|
||||
led.o \
|
||||
spi.o \
|
||||
uart.o \
|
||||
IODevice.o
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file IODevice.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) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @defgroup {group_name} {group_description}
|
||||
/// Description
|
||||
|
||||
/// @file IODevice.h
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
#ifndef MISC_INC_IODEVICE_H_
|
||||
#define MISC_INC_IODEVICE_H_
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
struct IODevice;
|
||||
|
||||
typedef ErrorStatus (*ReadFunction)(struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||
typedef ErrorStatus (*WriteFunction)(struct IODevice* self, const char* buffer, size_t length);
|
||||
|
||||
struct IODevice
|
||||
{
|
||||
ReadFunction _read;
|
||||
WriteFunction _write;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern ErrorStatus IODevice_construct (struct IODevice* self, ReadFunction read, WriteFunction write);
|
||||
|
||||
extern ErrorStatus IODevice_write(struct IODevice* self, const char* buffer, size_t length);
|
||||
|
||||
extern ErrorStatus IODevice_read(struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||
|
||||
|
||||
#endif /* MISC_INC_IODEVICE_H_ */
|
||||
@@ -0,0 +1,78 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file IODevice.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 IODevice.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "IODevice.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus IODevice_construct (struct IODevice* self, ReadFunction read, WriteFunction write)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
self->_write = write;
|
||||
self->_read = read;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
ErrorStatus IODevice_write(struct IODevice* self, const char* buffer, size_t length)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (self->_write != NULL)
|
||||
{
|
||||
self->_write(self, buffer, length);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
@@ -14,6 +14,8 @@ LIBRARY_NAME = ../libPlatform.a
|
||||
CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb -DOLI_STM32_H107 \
|
||||
-Iinc \
|
||||
-I../Misc/inc \
|
||||
-I../Keypad/inc \
|
||||
-I../Display/inc \
|
||||
-I$(ROOTDIR)/hsb-mrts/inc \
|
||||
-I$(ROOTDIR)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc \
|
||||
-I$(ROOTDIR)/FreeRTOS/Source/include \
|
||||
@@ -23,12 +25,17 @@ CCFLAGS = -c -O2 -Wall -g -fno-common -mcpu=cortex-m3 -mthumb -DOLI_STM32_H107 \
|
||||
ARFLAGS = rs
|
||||
|
||||
OBJECTS = \
|
||||
stm32f10x_it.o \
|
||||
led.o \
|
||||
spi.o \
|
||||
uart.o \
|
||||
oli_stm32_h107.o \
|
||||
|
||||
|
||||
vpath %.o $(OBJDIR)
|
||||
vpath %.c \
|
||||
$(SRCDIR)
|
||||
$(SRCDIR) \
|
||||
$(ROOTDIR)/hsb-mrts/src
|
||||
|
||||
all: $(LIBRARY_NAME)
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "FreeRTOSConfig.h"
|
||||
|
||||
#include "stm32f10x.h"
|
||||
@@ -71,6 +73,9 @@ extern struct SpiDevice* const spiDAC;
|
||||
extern struct SpiDevice* const spiDisplay;
|
||||
extern struct SpiDevice* const spiEEPROM;
|
||||
|
||||
extern struct Keypad* const keypad;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -43,7 +43,17 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define SPI_DEF_Direction (SPI_Direction_2Lines_FullDuplex)
|
||||
#define SPI_DEF_Mode (SPI_Mode_Master)
|
||||
#define SPI_DEF_DataSize (SPI_DataSize_8b)
|
||||
#define SPI_DEF_CPOL (SPI_CPOL_Low)
|
||||
#define SPI_DEF_CPHA (SPI_CPHA_1Edge)
|
||||
#define SPI_DEF_NSS (SPI_NSS_Hard)
|
||||
#define SPI_DEF_BaudRatePrescaler (SPI_BaudRatePrescaler_2)
|
||||
#define SPI_DEF_FirstBit (SPI_FirstBit_MSB)
|
||||
#define SPI_DEF_CRCPolynomial (7)
|
||||
#define SPI_DEF_RX_QUEUE (16)
|
||||
#define SPI_DEF_TX_QUEUE (16)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
@@ -72,9 +82,25 @@ struct Spi
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
struct SpiParameters
|
||||
{
|
||||
uint16_t SPI_Direction;
|
||||
uint16_t SPI_Mode;
|
||||
uint16_t SPI_DataSize;
|
||||
uint16_t SPI_CPOL;
|
||||
uint16_t SPI_CPHA;
|
||||
uint16_t SPI_NSS;
|
||||
uint16_t SPI_BaudRatePrescaler;
|
||||
uint16_t SPI_FirstBit;
|
||||
uint16_t SPI_CRCPolynomial;
|
||||
UBaseType_t txQueueSize;
|
||||
UBaseType_t rxQueueSize;
|
||||
};
|
||||
|
||||
struct SpiDevice
|
||||
{
|
||||
struct Spi* spi;
|
||||
struct SpiParameters* spiParameters;
|
||||
T_PL_GPIO SPI_CE;
|
||||
};
|
||||
|
||||
@@ -86,13 +112,8 @@ struct SpiDevice
|
||||
* Spi_construct
|
||||
* Description of function
|
||||
*
|
||||
* @param self The UART object to initialize
|
||||
* @param baudrate Baudrate to use
|
||||
* @param wordlength Wordlength for the UART
|
||||
* @param stopbits Number of stopbits to use
|
||||
* @param parity Parity of the UART
|
||||
* @param mode Mode (TX, RX, Both)
|
||||
* @param hwFlowControl Control of hardware flow control
|
||||
* @param self The SPi object to initialize
|
||||
* @param parameters The SPI parameters to use
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if writing message was successful
|
||||
* ERROR otherwise
|
||||
@@ -100,7 +121,7 @@ struct SpiDevice
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus SPI_construct(struct Spi* self, uint16_t SPI_Direction, uint16_t SPI_Mode, uint16_t SPI_DataSize, uint16_t SPI_CPOL, uint16_t SPI_CPHA, uint16_t SPI_NSS, uint16_t SPI_BaudRatePrescaler, uint16_t SPI_FirstBit, uint16_t SPI_CRCPolynomial, UBaseType_t txQueueSize, UBaseType_t rxQueueSize);
|
||||
extern ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -118,6 +139,21 @@ extern ErrorStatus SPI_construct(struct Spi* self, uint16_t SPI_Direction, uint1
|
||||
extern ErrorStatus SPI_destruct(struct Spi* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Spi_getDefaultParameters
|
||||
* Function that assigns default parameters to the spi struct
|
||||
*
|
||||
* @param parameters
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if destruct was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Spi_Write
|
||||
* Write the data in buffer to the SPI in argument self
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -36,12 +36,20 @@
|
||||
#include "semphr.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "IODevice.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define UART_DEF_BAUDRATE (9600)
|
||||
#define UART_DEF_WORDLENGTH (USART_WordLength_8b)
|
||||
#define UART_DEF_STOPBITS (USART_StopBits_1)
|
||||
#define UART_DEF_PARITY (USART_Parity_No)
|
||||
#define UART_DEF_MODE (USART_Mode_Tx | USART_Mode_Rx)
|
||||
#define UART_DEF_HW_FLOW_CONTROL (USART_HardwareFlowControl_None)
|
||||
#define UART_DEF_RX_QUEUE (32)
|
||||
#define UART_DEF_TX_QUEUE (32)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
@@ -54,11 +62,19 @@ struct usartQueueItem
|
||||
|
||||
struct UartParameters
|
||||
{
|
||||
int baudrate;
|
||||
uint32_t baudrate;
|
||||
uint16_t wordlength;
|
||||
uint16_t stopbits;
|
||||
uint16_t parity;
|
||||
uint16_t mode;
|
||||
uint16_t hwFlowControl;
|
||||
UBaseType_t txQueueSize;
|
||||
UBaseType_t rxQueueSize;
|
||||
};
|
||||
|
||||
struct Uart
|
||||
{
|
||||
struct IODevice device;
|
||||
USART_TypeDef* USART_TypeDef;
|
||||
USART_InitTypeDef USART_InitStruct;
|
||||
USART_ClockInitTypeDef* USART_ClockInitStruct;
|
||||
@@ -76,7 +92,7 @@ struct Uart
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Uart_Init
|
||||
* Uart_construct
|
||||
* Description of function
|
||||
*
|
||||
* @param _self The UART object to initialize
|
||||
@@ -93,16 +109,29 @@ struct Uart
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wordlength, uint16_t stopbits, uint16_t parity, uint16_t mode, uint16_t hwFlowControl, UBaseType_t txQueueSize, UBaseType_t rxQueueSize);
|
||||
extern ErrorStatus Uart_construct(struct Uart* self, struct UartParameters* parameters);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Uart_getDefaultParameters
|
||||
* Function that assigns default parameters to the uart struct
|
||||
*
|
||||
* @param parameters
|
||||
*
|
||||
* @return ErrorStatus
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters);
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Uart_Write
|
||||
* Description of function
|
||||
*
|
||||
* @param _self The UART class object
|
||||
* @param self The UART class object
|
||||
* @param buffer Message string to send
|
||||
* @parm length Message length
|
||||
* @param length Message length
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if writing message was successful
|
||||
* ERROR otherwise
|
||||
@@ -110,7 +139,7 @@ extern ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wor
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length);
|
||||
extern ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length);
|
||||
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "led.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
#include "keypadMatrix.h"
|
||||
#include "nhd0420.h"
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -43,12 +45,6 @@
|
||||
// UART1 Settings (Logger/Console)
|
||||
#define UART_LOG_TYPEDEF (USART1)
|
||||
#define UART_LOG_BAUDRATE (57600)
|
||||
#define UART_LOG_WORDLENGTH (USART_WordLength_8b)
|
||||
#define UART_LOG_STOPBITS (USART_StopBits_1)
|
||||
#define UART_LOG_PARITY (USART_Parity_No)
|
||||
#define UART_LOG_MODE (USART_Mode_Tx | USART_Mode_Rx)
|
||||
#define UART_LOG_HW_FLOW_CONTROL (USART_HardwareFlowControl_None)
|
||||
#define UART_LOG_RX_QUEUE (256)
|
||||
#define UART_LOG_TX_QUEUE (256)
|
||||
|
||||
// SPI1 settings
|
||||
@@ -65,20 +61,11 @@
|
||||
#define SPI_DAC_RX_QUEUE (32)
|
||||
#define SPI_DAC_TX_QUEUE (32)
|
||||
|
||||
// SPI3 settings
|
||||
#define SPI_LCD_TYPEDEF (SPI3)
|
||||
#define SPI_LCD_Direction (SPI_Direction_2Lines_FullDuplex)
|
||||
#define SPI_LCD_Mode (SPI_Mode_Master)
|
||||
#define SPI_LCD_DataSize (SPI_DataSize_8b)
|
||||
#define SPI_LCD_CPOL (SPI_CPOL_High)
|
||||
#define SPI_LCD_CPHA (SPI_CPHA_2Edge)
|
||||
#define SPI_LCD_NSS (SPI_NSS_Soft)
|
||||
// Display has max SPI CLK of 100 kHz
|
||||
#define SPI_LCD_BaudRatePrescaler (SPI_BaudRatePrescaler_128)
|
||||
#define SPI_LCD_FirstBit (SPI_FirstBit_MSB)
|
||||
#define SPI_LCD_CRCPolynomial (7)
|
||||
#define SPI_LCD_RX_QUEUE (32)
|
||||
#define SPI_LCD_TX_QUEUE (32)
|
||||
// SPI3 settings (LCD / EEPROM)
|
||||
#define SPI_LCD_EEPROM_TYPEDEF (SPI3)
|
||||
#define SPI_LCD_EEPROM_Direction (SPI_Direction_2Lines_FullDuplex)
|
||||
#define SPI_LCD_EEPROM_RX_QUEUE (32)
|
||||
#define SPI_LCD_EEPROM_TX_QUEUE (32)
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -97,14 +84,20 @@ static struct Led _ledOrange;
|
||||
|
||||
// USART
|
||||
static struct Uart _uart1;
|
||||
static struct UartParameters _uart1Parameters;
|
||||
|
||||
// SPI
|
||||
static struct Spi _spi1;
|
||||
static struct SpiParameters _spi1Parameters;
|
||||
static struct SpiDevice _spiDAC;
|
||||
static struct Spi _spi3;
|
||||
static struct SpiParameters _spi3Parameters;
|
||||
static struct SpiDevice _spiDisplay;
|
||||
static struct SpiDevice _spiEEPROM;
|
||||
|
||||
// Keypad
|
||||
static struct Keypad _keypad;
|
||||
|
||||
// The following pointers are for export (see platform.h) and external use.
|
||||
// Note that the pointer content is marked "const"
|
||||
struct Led* const ledGreen = &_ledGreen;
|
||||
@@ -116,6 +109,8 @@ struct SpiDevice* const spiDAC = &_spiDAC;
|
||||
struct SpiDevice* const spiDisplay = &_spiDisplay;
|
||||
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
|
||||
|
||||
struct Keypad* const keypad = &_keypad;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -139,17 +134,60 @@ ErrorStatus initPlatform(void)
|
||||
// Initialize the Console UART
|
||||
IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE);
|
||||
uart1->USART_TypeDef = UART_LOG_TYPEDEF;
|
||||
returnValue = Uart_Init(uart1, UART_LOG_BAUDRATE, UART_LOG_WORDLENGTH, UART_LOG_STOPBITS, UART_LOG_PARITY, UART_LOG_MODE, UART_LOG_HW_FLOW_CONTROL, UART_LOG_TX_QUEUE, UART_LOG_RX_QUEUE);
|
||||
Uart_getDefaultParameters(&_uart1Parameters);
|
||||
// Adjust to higher baudrate for intensive logging
|
||||
_uart1Parameters.baudrate = UART_LOG_BAUDRATE;
|
||||
// Adjust the TX queue size for intensive logging
|
||||
_uart1Parameters.txQueueSize = UART_LOG_TX_QUEUE;
|
||||
returnValue = Uart_construct(uart1, &_uart1Parameters);
|
||||
|
||||
IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
|
||||
spi1->initialized = false;
|
||||
spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
|
||||
SPI_construct(spi1, SPI_DAC_Direction, SPI_DAC_Mode, SPI_DAC_DataSize, SPI_DAC_CPOL, SPI_DAC_CPHA, SPI_DAC_NSS, SPI_DAC_BaudRatePrescaler, SPI_DAC_FirstBit, SPI_DAC_CRCPolynomial, SPI_DAC_TX_QUEUE, SPI_DAC_RX_QUEUE);
|
||||
SPI_getDefaultParameters(&_spi1Parameters);
|
||||
SPI_construct(spi1, &_spi1Parameters);
|
||||
|
||||
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
|
||||
spi3->initialized = false;
|
||||
spi3->SPI_TypeDef = SPI_LCD_TYPEDEF;
|
||||
SPI_construct(spi3, SPI_LCD_Direction, SPI_LCD_Mode, SPI_LCD_DataSize, SPI_LCD_CPOL, SPI_LCD_CPHA, SPI_LCD_NSS, SPI_LCD_BaudRatePrescaler, SPI_LCD_FirstBit, SPI_LCD_CRCPolynomial, SPI_LCD_TX_QUEUE, SPI_LCD_RX_QUEUE);
|
||||
spi3->SPI_TypeDef = SPI_LCD_EEPROM_TYPEDEF;
|
||||
// Get the SPI parameters from the NHD0420 driver. They are more critical than the parameters from the EEPROM
|
||||
NHD0420_getSpiParameters(&_spi3Parameters);
|
||||
// In order to use multiple slaves on this bus (and to increase performance), some parameters are altered
|
||||
// Use full-duples instead of TX only, because the EEPROM is both write- and readable
|
||||
_spi3Parameters.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
// Adjust the RX and TX queues for multiple use
|
||||
_spi3Parameters.rxQueueSize = SPI_LCD_EEPROM_RX_QUEUE;
|
||||
_spi3Parameters.txQueueSize = SPI_LCD_EEPROM_TX_QUEUE;
|
||||
SPI_construct(spi3, &_spi3Parameters);
|
||||
|
||||
// Enable the interrupts for the Keypad columns
|
||||
keypad->column[0].EXTI_InitStruct.EXTI_Line = EXTI_Line4;
|
||||
keypad->column[0].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
keypad->column[0].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
keypad->column[0].EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&keypad->column[0].EXTI_InitStruct);
|
||||
// Enable the interrupts for the Keypad columns
|
||||
keypad->column[1].EXTI_InitStruct.EXTI_Line = EXTI_Line5;
|
||||
keypad->column[1].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
keypad->column[1].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
keypad->column[1].EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&keypad->column[1].EXTI_InitStruct);
|
||||
// Enable the interrupts for the Keypad columns
|
||||
keypad->column[2].EXTI_InitStruct.EXTI_Line = EXTI_Line6;
|
||||
keypad->column[2].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
keypad->column[2].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
keypad->column[2].EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&keypad->column[2].EXTI_InitStruct);
|
||||
// Enable the interrupts for the Keypad columns
|
||||
keypad->column[3].EXTI_InitStruct.EXTI_Line = EXTI_Line7;
|
||||
keypad->column[3].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
keypad->column[3].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
keypad->column[3].EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&keypad->column[3].EXTI_InitStruct);
|
||||
|
||||
IRQ_setInterruptProperties(EXTI4_IRQn, 11, 0, ENABLE);
|
||||
IRQ_setInterruptProperties(EXTI9_5_IRQn, 11, 0, ENABLE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -173,6 +211,8 @@ static ErrorStatus initIO (void)
|
||||
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
||||
|
||||
|
||||
//! Enable USART clock
|
||||
|
||||
/* Peripheral bus power --------------------------------------------------*/
|
||||
@@ -180,6 +220,8 @@ static ErrorStatus initIO (void)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
|
||||
@@ -285,5 +327,65 @@ static ErrorStatus initIO (void)
|
||||
GPIO_Init(_spiEEPROM.SPI_CE.GPIO_Typedef, &_spiEEPROM.SPI_CE.GPIO_InitStruct);
|
||||
|
||||
|
||||
// Keypad I/O
|
||||
// Row1
|
||||
keypad->row[0].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->row[0].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
keypad->row[0].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
|
||||
keypad->row[0].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->row[0].gpio.GPIO_Typedef, &keypad->row[0].gpio.GPIO_InitStruct);
|
||||
|
||||
// Row2
|
||||
keypad->row[1].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->row[1].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
keypad->row[1].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
|
||||
keypad->row[1].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->row[1].gpio.GPIO_Typedef, &keypad->row[1].gpio.GPIO_InitStruct);
|
||||
// Row3
|
||||
keypad->row[2].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->row[2].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
keypad->row[2].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
|
||||
keypad->row[2].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->row[2].gpio.GPIO_Typedef, &keypad->row[2].gpio.GPIO_InitStruct);
|
||||
// Row4
|
||||
keypad->row[3].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->row[3].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
keypad->row[3].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
|
||||
keypad->row[3].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->row[3].gpio.GPIO_Typedef, &keypad->row[3].gpio.GPIO_InitStruct);
|
||||
|
||||
// Column1
|
||||
keypad->column[0].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->column[0].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
|
||||
keypad->column[0].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
|
||||
keypad->column[0].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->column[0].gpio.GPIO_Typedef, &keypad->column[0].gpio.GPIO_InitStruct);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4);
|
||||
|
||||
// Column2
|
||||
keypad->column[1].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->column[1].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
|
||||
keypad->column[1].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
|
||||
keypad->column[1].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->column[1].gpio.GPIO_Typedef, &keypad->column[1].gpio.GPIO_InitStruct);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource5);
|
||||
|
||||
// Column3
|
||||
keypad->column[2].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->column[2].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
|
||||
keypad->column[2].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
|
||||
keypad->column[2].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->column[2].gpio.GPIO_Typedef, &keypad->column[2].gpio.GPIO_InitStruct);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource6);
|
||||
|
||||
// Column4
|
||||
keypad->column[3].gpio.GPIO_Typedef = GPIOD;
|
||||
keypad->column[3].gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
|
||||
keypad->column[3].gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
|
||||
keypad->column[3].gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(keypad->column[3].gpio.GPIO_Typedef, &keypad->column[3].gpio.GPIO_InitStruct);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource7);
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus SPI_construct(struct Spi* self, uint16_t SPI_Direction, uint16_t SPI_Mode, uint16_t SPI_DataSize, uint16_t SPI_CPOL, uint16_t SPI_CPHA, uint16_t SPI_NSS, uint16_t SPI_BaudRatePrescaler, uint16_t SPI_FirstBit, uint16_t SPI_CRCPolynomial, UBaseType_t txQueueSize, UBaseType_t rxQueueSize)
|
||||
ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -69,24 +69,24 @@ ErrorStatus SPI_construct(struct Spi* self, uint16_t SPI_Direction, uint16_t SPI
|
||||
|
||||
SPI_I2S_DeInit(self->SPI_TypeDef);
|
||||
|
||||
self->SPI_InitStruct.SPI_Direction = SPI_Direction;
|
||||
self->SPI_InitStruct.SPI_Mode = SPI_Mode;
|
||||
self->SPI_InitStruct.SPI_DataSize = SPI_DataSize;
|
||||
self->SPI_InitStruct.SPI_CPOL = SPI_CPOL;
|
||||
self->SPI_InitStruct.SPI_CPHA = SPI_CPHA;
|
||||
self->SPI_InitStruct.SPI_NSS = SPI_NSS;
|
||||
self->SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler;
|
||||
self->SPI_InitStruct.SPI_FirstBit = SPI_FirstBit;
|
||||
self->SPI_InitStruct.SPI_CRCPolynomial = SPI_CRCPolynomial;
|
||||
self->SPI_InitStruct.SPI_Direction = parameters->SPI_Direction;
|
||||
self->SPI_InitStruct.SPI_Mode = parameters->SPI_Mode;
|
||||
self->SPI_InitStruct.SPI_DataSize = parameters->SPI_DataSize;
|
||||
self->SPI_InitStruct.SPI_CPOL = parameters->SPI_CPOL;
|
||||
self->SPI_InitStruct.SPI_CPHA = parameters->SPI_CPHA;
|
||||
self->SPI_InitStruct.SPI_NSS = parameters->SPI_NSS;
|
||||
self->SPI_InitStruct.SPI_BaudRatePrescaler = parameters->SPI_BaudRatePrescaler;
|
||||
self->SPI_InitStruct.SPI_FirstBit = parameters->SPI_FirstBit;
|
||||
self->SPI_InitStruct.SPI_CRCPolynomial = parameters->SPI_CRCPolynomial;
|
||||
SPI_Init(self->SPI_TypeDef, &self->SPI_InitStruct);
|
||||
|
||||
//! Enable USART interface
|
||||
SPI_Cmd(self->SPI_TypeDef, ENABLE);
|
||||
|
||||
//! Create a new FREERTOS queue to handle data from app to USART output
|
||||
self->txQueue = xQueueCreate(txQueueSize, sizeof(struct spiQueueItem));
|
||||
self->txQueue = xQueueCreate(parameters->txQueueSize, sizeof(struct spiQueueItem));
|
||||
//! Create a new FREERTOS queue to handle data from USART input to app
|
||||
self->rxQueue = xQueueCreate(rxQueueSize, sizeof(struct spiQueueItem));
|
||||
self->rxQueue = xQueueCreate(parameters->rxQueueSize, sizeof(struct spiQueueItem));
|
||||
//! Queue identifier must not be 0 (0 means that the queue is not available)
|
||||
if (self->txQueue == 0)
|
||||
{
|
||||
@@ -126,9 +126,32 @@ ErrorStatus SPI_destruct (struct Spi* self)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
self->initialized = false;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
parameters->SPI_BaudRatePrescaler = SPI_DEF_BaudRatePrescaler;
|
||||
parameters->SPI_CPHA = SPI_DEF_CPHA;
|
||||
parameters->SPI_CPOL = SPI_DEF_CPOL;
|
||||
parameters->SPI_CRCPolynomial = SPI_DEF_CRCPolynomial;
|
||||
parameters->SPI_DataSize = SPI_DEF_DataSize;
|
||||
parameters->SPI_Direction = SPI_DEF_Direction;
|
||||
parameters->SPI_FirstBit = SPI_DEF_FirstBit;
|
||||
parameters->SPI_Mode = SPI_DEF_Mode;
|
||||
parameters->SPI_NSS = SPI_DEF_NSS;
|
||||
parameters->rxQueueSize = SPI_DEF_RX_QUEUE;
|
||||
parameters->txQueueSize = SPI_DEF_TX_QUEUE;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length)
|
||||
{
|
||||
struct spiQueueItem txItem;
|
||||
@@ -11,9 +11,9 @@
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -54,53 +54,56 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
static ErrorStatus write(struct IODevice* self, const char* buffer, size_t length);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wordlength, uint16_t stopbits, uint16_t parity, uint16_t mode, uint16_t hwFlowControl, UBaseType_t txQueueSize, UBaseType_t rxQueueSize)
|
||||
ErrorStatus Uart_construct(struct Uart* self, struct UartParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
IODevice_construct(&self->device, NULL, write);
|
||||
|
||||
//! Create semaphore to synchronize with USART interrupt handler
|
||||
vSemaphoreCreateBinary(_self->txSemaphore);
|
||||
vSemaphoreCreateBinary(self->txSemaphore);
|
||||
|
||||
USART_DeInit(_self->USART_TypeDef);
|
||||
USART_DeInit(self->USART_TypeDef);
|
||||
|
||||
_self->USART_ClockInitStruct->USART_Clock = USART_Clock_Enable;
|
||||
_self->USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
|
||||
_self->USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
|
||||
_self->USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
|
||||
self->USART_ClockInitStruct->USART_Clock = USART_Clock_Enable;
|
||||
self->USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
|
||||
self->USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
|
||||
self->USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
|
||||
|
||||
//! Enable USART clock
|
||||
USART_ClockInit(_self->USART_TypeDef, _self->USART_ClockInitStruct);
|
||||
USART_ClockInit(self->USART_TypeDef, self->USART_ClockInitStruct);
|
||||
|
||||
// Initialise the UART
|
||||
_self->USART_InitStruct.USART_BaudRate = baudrate;
|
||||
_self->USART_InitStruct.USART_WordLength = wordlength;
|
||||
_self->USART_InitStruct.USART_StopBits = stopbits;
|
||||
_self->USART_InitStruct.USART_Parity = parity;
|
||||
_self->USART_InitStruct.USART_Mode = mode;
|
||||
_self->USART_InitStruct.USART_HardwareFlowControl = hwFlowControl;
|
||||
self->USART_InitStruct.USART_BaudRate = parameters->baudrate;
|
||||
self->USART_InitStruct.USART_WordLength = parameters->wordlength;
|
||||
self->USART_InitStruct.USART_StopBits = parameters->stopbits;
|
||||
self->USART_InitStruct.USART_Parity = parameters->parity;
|
||||
self->USART_InitStruct.USART_Mode = parameters->mode;
|
||||
self->USART_InitStruct.USART_HardwareFlowControl = parameters->hwFlowControl;
|
||||
|
||||
USART_Init(_self->USART_TypeDef, &_self->USART_InitStruct);
|
||||
USART_Init(self->USART_TypeDef, &self->USART_InitStruct);
|
||||
|
||||
//! Enable USART interface
|
||||
USART_Cmd(_self->USART_TypeDef, ENABLE);
|
||||
USART_Cmd(self->USART_TypeDef, ENABLE);
|
||||
|
||||
//! Create a new FREERTOS queue to handle data from app to USART output
|
||||
_self->txQueue = xQueueCreate(txQueueSize, sizeof(struct usartQueueItem));
|
||||
self->txQueue = xQueueCreate(parameters->txQueueSize, sizeof(struct usartQueueItem));
|
||||
//! Create a new FREERTOS queue to handle data from USART input to app
|
||||
_self->rxQueue = xQueueCreate(rxQueueSize, sizeof(struct usartQueueItem));
|
||||
self->rxQueue = xQueueCreate(parameters->rxQueueSize, sizeof(struct usartQueueItem));
|
||||
//! Queue identifier must not be 0 (0 means that the queue is not available)
|
||||
if (_self->txQueue == 0)
|
||||
if (self->txQueue == 0)
|
||||
{
|
||||
//! Queue identifier is 0 -> error
|
||||
returnValue = ERROR; //! Set error flag
|
||||
}
|
||||
if (_self->rxQueue == 0)
|
||||
if (self->rxQueue == 0)
|
||||
{
|
||||
//! Queue identifier is 0 -> error
|
||||
returnValue = ERROR; //! Set error flag
|
||||
@@ -108,7 +111,7 @@ ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wordlength
|
||||
//! Queue identifier is not 0 -> queue is available
|
||||
|
||||
//! take txSemaphore
|
||||
if (xSemaphoreTake(_self->txSemaphore, 0) == pdFALSE)
|
||||
if (xSemaphoreTake(self->txSemaphore, 0) == pdFALSE)
|
||||
{
|
||||
//! An error has occurred
|
||||
returnValue = ERROR;
|
||||
@@ -117,14 +120,37 @@ ErrorStatus Uart_Init(struct Uart* _self, uint32_t baudrate, uint16_t wordlength
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
//! Enable the UART RX not empty interrupt
|
||||
USART_ITConfig(_self->USART_TypeDef, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(self->USART_TypeDef, USART_IT_RXNE, ENABLE);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length)
|
||||
ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
parameters->baudrate = UART_DEF_BAUDRATE;
|
||||
parameters->wordlength = UART_DEF_WORDLENGTH;
|
||||
parameters->stopbits = UART_DEF_STOPBITS;
|
||||
parameters->mode = UART_DEF_MODE;
|
||||
parameters->parity = UART_DEF_PARITY;
|
||||
parameters->hwFlowControl = UART_DEF_HW_FLOW_CONTROL;
|
||||
parameters->txQueueSize = UART_DEF_TX_QUEUE;
|
||||
parameters->rxQueueSize = UART_DEF_RX_QUEUE;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static ErrorStatus write(struct IODevice* self, const char* buffer, size_t length)
|
||||
{
|
||||
return Uart_Write((struct Uart*)self, buffer, length);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length)
|
||||
{
|
||||
struct usartQueueItem usartTxItem;
|
||||
ErrorStatus returnValue = SUCCESS; //! Define return variable
|
||||
@@ -135,7 +161,7 @@ ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length)
|
||||
{
|
||||
usartTxItem.byte = buffer[txCounter]; //! Copy current data in struct
|
||||
//! Add the current set of data to bluetooth transmission queue
|
||||
if (pdTRUE != xQueueSend(_self->txQueue, &usartTxItem, 0))
|
||||
if (pdTRUE != xQueueSend(self->txQueue, &usartTxItem, 0))
|
||||
{
|
||||
//! Adding item was NOT successful - break out of loop
|
||||
returnValue = ERROR; //! Set return value to FALSE
|
||||
@@ -147,12 +173,12 @@ ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length)
|
||||
{
|
||||
//! Semaphore has been taken
|
||||
//! Enable the USARTx TXE (transmission empty) interrupt
|
||||
USART_ITConfig(_self->USART_TypeDef, USART_IT_TXE, ENABLE);
|
||||
USART_ITConfig(self->USART_TypeDef, USART_IT_TXE, ENABLE);
|
||||
|
||||
//! Try to take Semaphore - If the USART transmission is still busy, the
|
||||
//! Semaphore cannot be taken - FREERTOS will suspend this task until the
|
||||
//! Semaphore is released again
|
||||
xSemaphoreTake(_self->txSemaphore, portMAX_DELAY);
|
||||
xSemaphoreTake(self->txSemaphore, portMAX_DELAY);
|
||||
|
||||
/** Enabling the TX interrupt will immediately cause an interrupt because
|
||||
* the transmission register is still empty. The ISR will get the data
|
||||
@@ -161,7 +187,7 @@ ErrorStatus Uart_Write(struct Uart* _self, const uint8_t* buffer, int length)
|
||||
* An empty queue will cause the transmission complete flag (TC) to be set,
|
||||
* which is polled
|
||||
*/
|
||||
while (USART_GetFlagStatus(_self->USART_TypeDef, USART_FLAG_TC) == RESET)
|
||||
while (USART_GetFlagStatus(self->USART_TypeDef, USART_FLAG_TC) == RESET)
|
||||
{
|
||||
//! The software must wait until TC=1. The TC flag remains cleared during
|
||||
//! all data transfers and it is set by hardware at the last frame's
|
||||
Reference in New Issue
Block a user