Updates on the IODevice structure.
Display and Logger fully functional. Keypad task completed - yet to be tested git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@219 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
// Include files
|
// Include files
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "IODevice.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -133,7 +134,7 @@
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_construct(void* interface);
|
extern ErrorStatus NHD0420_construct(const struct IODevice* const device);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -177,7 +178,7 @@ extern ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column);
|
extern ErrorStatus NHD0420_setCursorToPosition(char row, char column);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -194,7 +195,7 @@ extern ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_setContrast(uint8_t contrast);
|
extern ErrorStatus NHD0420_setContrast(char contrast);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -211,7 +212,7 @@ extern ErrorStatus NHD0420_setContrast(uint8_t contrast);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness);
|
extern ErrorStatus NHD0420_setBacklightBrightness(char brightness);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -236,7 +237,7 @@ extern ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate);
|
extern ErrorStatus NHD0420_setRS232Baudrate(char baudrate);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -262,7 +263,7 @@ extern ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_setI2CAddress(uint8_t address);
|
extern ErrorStatus NHD0420_setI2CAddress(char address);
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
* NHD0420_SendCommand
|
* NHD0420_SendCommand
|
||||||
@@ -276,8 +277,8 @@ extern ErrorStatus NHD0420_setI2CAddress(uint8_t address);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus NHD0420_sendCommand(uint8_t command);
|
extern ErrorStatus NHD0420_sendCommand(char command);
|
||||||
|
|
||||||
extern ErrorStatus NHD0420_sendData(const uint8_t* buffer, size_t length);
|
extern ErrorStatus NHD0420_sendData(const char* buffer, size_t length);
|
||||||
|
|
||||||
#endif /* DISPLAY_INC_NHD0420_H_ */
|
#endif /* DISPLAY_INC_NHD0420_H_ */
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
|||||||
NHD0420_CURSOR_OFFSET_ROW4
|
NHD0420_CURSOR_OFFSET_ROW4
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool initialized = false;
|
static const struct IODevice* displayDevice = NULL;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
@@ -71,22 +71,20 @@ static bool initialized = false;
|
|||||||
// Function definitions
|
// Function definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static struct SpiDevice* nhd0420Interface;
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_construct(void* interface)
|
ErrorStatus NHD0420_construct(const struct IODevice* const device)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
if (!initialized)
|
if (displayDevice == NULL)
|
||||||
{
|
{
|
||||||
nhd0420Interface = (struct SpiDevice*)interface;
|
displayDevice = device;
|
||||||
|
}
|
||||||
if (returnValue == SUCCESS)
|
else
|
||||||
{
|
{
|
||||||
initialized = true;
|
returnValue = ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +138,7 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column)
|
ErrorStatus NHD0420_setCursorToPosition(char row, char column)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
@@ -161,8 +159,8 @@ ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column)
|
|||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
uint8_t address = nhd0420_cursorRowOffset[row] + column;
|
char address = nhd0420_cursorRowOffset[(int)row] + column;
|
||||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_CURSOR_SET, address};
|
||||||
returnValue = NHD0420_sendData(buffer, 3);
|
returnValue = NHD0420_sendData(buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +168,7 @@ ErrorStatus NHD0420_setCursorToPosition(uint8_t row, uint8_t column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_setContrast(uint8_t contrast)
|
ErrorStatus NHD0420_setContrast(char contrast)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
@@ -188,7 +186,7 @@ ErrorStatus NHD0420_setContrast(uint8_t contrast)
|
|||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_CONTRAST, contrast};
|
||||||
returnValue = NHD0420_sendData(buffer, 3);
|
returnValue = NHD0420_sendData(buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +194,7 @@ ErrorStatus NHD0420_setContrast(uint8_t contrast)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness)
|
ErrorStatus NHD0420_setBacklightBrightness(char brightness)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
@@ -214,7 +212,7 @@ ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness)
|
|||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
uint8_t buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
|
char buffer[3] = {NHD0420_CMD_PREFIX, NHD0420_CMD_SET_BRIGHTNESS, brightness};
|
||||||
returnValue = NHD0420_sendData(buffer, 3);
|
returnValue = NHD0420_sendData(buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +220,7 @@ ErrorStatus NHD0420_setBacklightBrightness(uint8_t brightness)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate)
|
ErrorStatus NHD0420_setRS232Baudrate(char baudrate)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
@@ -239,14 +237,14 @@ ErrorStatus NHD0420_setRS232Baudrate(uint8_t baudrate)
|
|||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
uint8_t 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(buffer, 3);
|
returnValue = NHD0420_sendData(buffer, 3);
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_setI2CAddress(uint8_t address)
|
ErrorStatus NHD0420_setI2CAddress(char address)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
@@ -263,7 +261,7 @@ ErrorStatus NHD0420_setI2CAddress(uint8_t address)
|
|||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
uint8_t 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(buffer, 3);
|
returnValue = NHD0420_sendData(buffer, 3);
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
@@ -281,23 +279,23 @@ ErrorStatus NHD0420_setI2CAddress(uint8_t address)
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
ErrorStatus NHD0420_sendCommand(uint8_t command)
|
ErrorStatus NHD0420_sendCommand(char command)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
uint8_t buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
|
char buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
|
||||||
|
|
||||||
returnValue = SPI_write(nhd0420Interface, buffer, NHD0420_CMD_LENGTH);
|
returnValue = IODevice_write(displayDevice, buffer, NHD0420_CMD_LENGTH);
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus NHD0420_sendData(const uint8_t* buffer, size_t length)
|
ErrorStatus NHD0420_sendData(const char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
returnValue = SPI_write(nhd0420Interface, buffer, length);
|
returnValue = IODevice_write(displayDevice, buffer, length);
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ keypadMatrix.o \
|
|||||||
|
|
||||||
|
|
||||||
vpath %.o $(OBJDIR)
|
vpath %.o $(OBJDIR)
|
||||||
vpath %.c $(SRCDIR)
|
vpath %.c \
|
||||||
|
$(SRCDIR) \
|
||||||
|
$(ROOTDIR)/hsb-mrts/src
|
||||||
|
|
||||||
all: $(LIBRARY_NAME)
|
all: $(LIBRARY_NAME)
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,12 @@
|
|||||||
// Include files
|
// Include files
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "semphr.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "IODevice.h"
|
||||||
|
|
||||||
#include "stm32f10x_exti.h"
|
#include "stm32f10x_exti.h"
|
||||||
|
|
||||||
@@ -47,6 +52,17 @@
|
|||||||
// Type definitions.
|
// Type definitions.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct KeypadQueueItem
|
||||||
|
{
|
||||||
|
char byte;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
RELEASED = 0,
|
||||||
|
PRESSED = (!RELEASED)
|
||||||
|
}Keypad_KeyState;
|
||||||
|
|
||||||
struct keypadElement
|
struct keypadElement
|
||||||
{
|
{
|
||||||
T_PL_GPIO gpio;
|
T_PL_GPIO gpio;
|
||||||
@@ -55,8 +71,19 @@ struct keypadElement
|
|||||||
|
|
||||||
struct Keypad
|
struct Keypad
|
||||||
{
|
{
|
||||||
|
struct IODevice device;
|
||||||
struct keypadElement row[KEYPAD_NUMBER_OF_ROWS];
|
struct keypadElement row[KEYPAD_NUMBER_OF_ROWS];
|
||||||
struct keypadElement column[KEYPAD_NUMBER_OF_COLUMNS];
|
struct keypadElement column[KEYPAD_NUMBER_OF_COLUMNS];
|
||||||
|
Keypad_KeyState lastState[KEYPAD_NUMBER_OF_ROWS][KEYPAD_NUMBER_OF_COLUMNS];
|
||||||
|
xTaskHandle taskHandle;
|
||||||
|
SemaphoreHandle_t scanSemaphore;
|
||||||
|
xQueueHandle rxQueue;
|
||||||
|
int waitToDebounce_ms;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct KeypadParameters
|
||||||
|
{
|
||||||
|
int rxQueueSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -67,17 +94,48 @@ struct Keypad
|
|||||||
* Keypad_construct
|
* Keypad_construct
|
||||||
* contructor for the Keypad driver
|
* contructor for the Keypad driver
|
||||||
*
|
*
|
||||||
|
* @param self Keypad object to initialize
|
||||||
|
* @param parameters Parameters to use for initialisation
|
||||||
|
* @param debounceTime debounce time for the keypad to use
|
||||||
|
*
|
||||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
* ERROR otherwise
|
* ERROR otherwise
|
||||||
*
|
*
|
||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus Keypad_construct(void);
|
extern ErrorStatus Keypad_construct(struct Keypad* self, struct KeypadParameters* parameters, int debounceTime);
|
||||||
|
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Keypad_destruct
|
||||||
|
* destructor for the Keypad driver
|
||||||
|
*
|
||||||
|
* @param self Keypad object to destruct
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern void Keypad_destruct (const struct Keypad* self);
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Keypad_getDefaultParameters
|
||||||
|
* Returns default parameters for a keypad
|
||||||
|
*
|
||||||
|
* @param parameters Keypad parameters struct that will be
|
||||||
|
* filled with default values
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus Keypad_getDefaultParameters(struct KeypadParameters* parameters);
|
||||||
|
|
||||||
extern ErrorStatus Keypad_logModuleInfo(void);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* KEYPAD_INC_KEYPADMATRIX_H_ */
|
#endif /* KEYPAD_INC_KEYPADMATRIX_H_ */
|
||||||
|
|||||||
@@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "task.h"
|
|
||||||
#include "FreeRTOSFixes.h"
|
#include "FreeRTOSFixes.h"
|
||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
@@ -36,12 +34,15 @@
|
|||||||
#include "keypadMatrix.h"
|
#include "keypadMatrix.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include "stm32f10x_it.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define KEYPAD_STACK_SIZE (512)
|
#define KEYPAD_STACK_SIZE (512)
|
||||||
#define KEYPAD_TASK_PRIORITY (3)
|
#define KEYPAD_TASK_PRIORITY (3)
|
||||||
|
#define KEYPAD_DEF_QUEUESIZE (32)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions
|
// Type definitions
|
||||||
@@ -52,13 +53,13 @@
|
|||||||
// File-scope variables
|
// File-scope variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static bool initialized = false;
|
|
||||||
static xTaskHandle keypadTaskHandle = NULL;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||||
static void KeypadTask(void* parameters);
|
static void KeypadTask(void* parameters);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -66,31 +67,63 @@ static void KeypadTask(void* parameters);
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus Keypad_construct(void)
|
ErrorStatus Keypad_construct(struct Keypad* self, struct KeypadParameters* parameters, int debounceTime)
|
||||||
{
|
{
|
||||||
|
int rowCounter = 0;
|
||||||
|
int colCounter = 0;
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
BaseType_t taskCreateReturn;
|
|
||||||
|
|
||||||
if(!initialized)
|
if(keypad != NULL)
|
||||||
{
|
{
|
||||||
|
IODevice_construct(&self->device, read, NULL);
|
||||||
|
|
||||||
if(returnValue == SUCCESS)
|
if(returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
taskCreateReturn = xTaskCreate(KeypadTask, (const char*)"keypadTask", KEYPAD_STACK_SIZE, NULL, KEYPAD_TASK_PRIORITY, &keypadTaskHandle);
|
//! Create semaphore to synchronize with Keypad/EXTI interrupt handler
|
||||||
if(taskCreateReturn != pdPASS)
|
vSemaphoreCreateBinary(self->scanSemaphore);
|
||||||
|
}
|
||||||
|
|
||||||
|
self->waitToDebounce_ms = debounceTime;
|
||||||
|
|
||||||
|
// Initialize memory to keep track of state changes per key
|
||||||
|
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||||
{
|
{
|
||||||
|
for (colCounter = 0; colCounter < KEYPAD_NUMBER_OF_COLUMNS; colCounter++)
|
||||||
|
{
|
||||||
|
self->lastState[rowCounter][colCounter] = RELEASED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Create a new FREERTOS queue to handle data from Keypad input to app
|
||||||
|
self->rxQueue = xQueueCreate(parameters->rxQueueSize, sizeof(struct KeypadQueueItem));
|
||||||
|
if (self->rxQueue == 0)
|
||||||
|
{
|
||||||
|
//! Queue identifier is 0 -> error
|
||||||
|
returnValue = ERROR; //! Set error flag
|
||||||
|
}
|
||||||
|
|
||||||
|
if(returnValue == SUCCESS)
|
||||||
|
{
|
||||||
|
xTaskCreate(KeypadTask, (const char*)"keypadTask", KEYPAD_STACK_SIZE, keypad, KEYPAD_TASK_PRIORITY, self->taskHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(returnValue == SUCCESS)
|
||||||
|
{
|
||||||
|
//! take txSemaphore
|
||||||
|
if (xSemaphoreTake(self->scanSemaphore, 0) == pdFALSE)
|
||||||
|
{
|
||||||
|
//! An error has occurred
|
||||||
returnValue = ERROR;
|
returnValue = ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(returnValue == SUCCESS)
|
if(returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
initialized = true;
|
|
||||||
LOGGER_INFO("Keypad task started");
|
LOGGER_INFO("Keypad task started");
|
||||||
// GPIO_SetBits(kRow1->rowGpio.GPIO_Typedef, kRow1->rowGpio.GPIO_InitStruct.GPIO_Pin);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGGER_ERROR("Keypad task FAILED with code %x", (unsigned int)taskCreateReturn);
|
LOGGER_ERROR("Keypad task FAILED");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,36 +131,91 @@ ErrorStatus Keypad_construct(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus Keypad_logModuleInfo(void)
|
void Keypad_Destruct (const struct Keypad* self)
|
||||||
|
{
|
||||||
|
vTaskDelete(self->taskHandle);
|
||||||
|
vQueueDelete(self->rxQueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus Keypad_getDefaultParameters(struct KeypadParameters* parameters)
|
||||||
{
|
{
|
||||||
ErrorStatus errorStatus = SUCCESS;
|
ErrorStatus errorStatus = SUCCESS;
|
||||||
|
|
||||||
OS_logTaskInfo(keypadTaskHandle);
|
parameters->rxQueueSize = KEYPAD_DEF_QUEUESIZE;
|
||||||
|
|
||||||
|
return errorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||||
|
{
|
||||||
|
ErrorStatus errorStatus = SUCCESS;
|
||||||
|
|
||||||
|
*actualLength = 1;
|
||||||
|
|
||||||
return errorStatus;
|
return errorStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Keypad_Destruct (void)
|
|
||||||
{
|
|
||||||
initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void KeypadTask(void* parameters)
|
static void KeypadTask(void* parameters)
|
||||||
{
|
{
|
||||||
|
int rowCounter = 0;
|
||||||
|
int colCounter = 0;
|
||||||
|
struct Keypad* self = (struct Keypad*) parameters;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
vTaskDelay(1000);
|
// Wait for an interrupt to occur on one of the keypad columns
|
||||||
|
xSemaphoreTake(self->scanSemaphore, portMAX_DELAY);
|
||||||
|
// Debounce the keypad and wait for debounceTime prior to do anything
|
||||||
|
vTaskDelay(self->waitToDebounce_ms);
|
||||||
|
|
||||||
LOGGER_DEBUG("ROW1: %d, ROW2: %d, ROW3: %d, ROW4: %d - Col1: %d, Col2: %d, Col3: %d, Col4: %d",
|
// Set all row outputs
|
||||||
GPIO_ReadOutputDataBit(keypad->row[0].gpio.GPIO_Typedef, keypad->row[0].gpio.GPIO_InitStruct.GPIO_Pin),
|
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||||
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_SetBits(self->row[rowCounter].gpio.GPIO_Typedef, self->row[rowCounter].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),
|
// Scan through each row individually by resetting it (output level low) and check all column levels
|
||||||
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)
|
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||||
);
|
{
|
||||||
|
GPIO_ResetBits(self->row[rowCounter].gpio.GPIO_Typedef, self->row[rowCounter].gpio.GPIO_InitStruct.GPIO_Pin);
|
||||||
|
|
||||||
|
for (colCounter = 0; colCounter < KEYPAD_NUMBER_OF_COLUMNS; colCounter++)
|
||||||
|
{
|
||||||
|
if (GPIO_ReadInputDataBit(self->column[colCounter].gpio.GPIO_Typedef, self->column[colCounter].gpio.GPIO_InitStruct.GPIO_Pin) == (uint8_t)Bit_SET)
|
||||||
|
{
|
||||||
|
if (self->lastState[rowCounter][colCounter] == PRESSED)
|
||||||
|
{
|
||||||
|
// Key has been released
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// nothing changed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (self->lastState[rowCounter][colCounter] == RELEASED)
|
||||||
|
{
|
||||||
|
// Key has been pressed
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// nothing changed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GPIO_SetBits(self->row[rowCounter].gpio.GPIO_Typedef, self->row[rowCounter].gpio.GPIO_InitStruct.GPIO_Pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset all row outputs and return to IRQ status
|
||||||
|
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||||
|
{
|
||||||
|
GPIO_ResetBits(self->row[rowCounter].gpio.GPIO_Typedef, self->row[rowCounter].gpio.GPIO_InitStruct.GPIO_Pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
IRQ_setKeypadEXTI(self, ENABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,8 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
struct IODevice;
|
struct IODevice;
|
||||||
|
|
||||||
typedef ErrorStatus (*ReadFunction)(struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
typedef ErrorStatus (*ReadFunction)(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||||
typedef ErrorStatus (*WriteFunction)(struct IODevice* self, const char* buffer, size_t length);
|
typedef ErrorStatus (*WriteFunction)(const struct IODevice* self, const char* buffer, size_t length);
|
||||||
|
|
||||||
struct IODevice
|
struct IODevice
|
||||||
{
|
{
|
||||||
@@ -62,9 +62,9 @@ struct IODevice
|
|||||||
|
|
||||||
extern ErrorStatus IODevice_construct (struct IODevice* self, ReadFunction read, WriteFunction write);
|
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_write(const struct IODevice* self, const char* buffer, size_t length);
|
||||||
|
|
||||||
extern ErrorStatus IODevice_read(struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
extern ErrorStatus IODevice_read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISC_INC_IODEVICE_H_ */
|
#endif /* MISC_INC_IODEVICE_H_ */
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ ErrorStatus IODevice_construct (struct IODevice* self, ReadFunction read, WriteF
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorStatus IODevice_write(struct IODevice* self, const char* buffer, size_t length)
|
ErrorStatus IODevice_write(const struct IODevice* self, const char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ OBJECTS = \
|
|||||||
stm32f10x_it.o \
|
stm32f10x_it.o \
|
||||||
led.o \
|
led.o \
|
||||||
spi.o \
|
spi.o \
|
||||||
|
spiDevice.o \
|
||||||
uart.o \
|
uart.o \
|
||||||
oli_stm32_h107.o \
|
oli_stm32_h107.o \
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
/// @file led.h
|
/// @file led.h
|
||||||
/// @brief File description
|
/// @brief File description
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "IODevice.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
@@ -47,6 +49,7 @@
|
|||||||
|
|
||||||
struct Led
|
struct Led
|
||||||
{
|
{
|
||||||
|
struct IODevice device;
|
||||||
T_PL_GPIO ledGpio;
|
T_PL_GPIO ledGpio;
|
||||||
bool status;
|
bool status;
|
||||||
};
|
};
|
||||||
@@ -56,6 +59,8 @@ struct Led
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus LED_construct (struct Led* self);
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
* LED_turnOn
|
* LED_turnOn
|
||||||
* Turns on the LED identified with the ID
|
* Turns on the LED identified with the ID
|
||||||
@@ -68,7 +73,7 @@ struct Led
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus LED_turnOn(struct Led* const led);
|
extern ErrorStatus LED_turnOn(struct Led* led);
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
* LED_turnOff
|
* LED_turnOff
|
||||||
@@ -82,6 +87,6 @@ extern ErrorStatus LED_turnOn(struct Led* const led);
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus LED_turnOff(struct Led* const led);
|
extern ErrorStatus LED_turnOff(struct Led* led);
|
||||||
|
|
||||||
#endif /* LED_INC_LED_H_ */
|
#endif /* LED_INC_LED_H_ */
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "IODevice.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
@@ -69,7 +70,7 @@ struct Spi
|
|||||||
SPI_TypeDef* SPI_TypeDef;
|
SPI_TypeDef* SPI_TypeDef;
|
||||||
SPI_InitTypeDef SPI_InitStruct;
|
SPI_InitTypeDef SPI_InitStruct;
|
||||||
T_PL_GPIO SPI_CLK;
|
T_PL_GPIO SPI_CLK;
|
||||||
T_PL_GPIO* SPI_CE;
|
const T_PL_GPIO* SPI_CE;
|
||||||
T_PL_GPIO SPI_MOSI;
|
T_PL_GPIO SPI_MOSI;
|
||||||
T_PL_GPIO SPI_MISO;
|
T_PL_GPIO SPI_MISO;
|
||||||
SemaphoreHandle_t spiClaimed; //! Semaphore to protect SPI bus
|
SemaphoreHandle_t spiClaimed; //! Semaphore to protect SPI bus
|
||||||
@@ -97,13 +98,6 @@ struct SpiParameters
|
|||||||
UBaseType_t rxQueueSize;
|
UBaseType_t rxQueueSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SpiDevice
|
|
||||||
{
|
|
||||||
struct Spi* spi;
|
|
||||||
struct SpiParameters* spiParameters;
|
|
||||||
T_PL_GPIO SPI_CE;
|
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -121,7 +115,7 @@ struct SpiDevice
|
|||||||
* @todo
|
* @todo
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
extern ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters);
|
extern ErrorStatus SPI_construct(struct Spi* self, const struct SpiParameters* parameters);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
/** ----------------------------------------------------------------------------
|
||||||
@@ -154,19 +148,4 @@ extern ErrorStatus SPI_destruct(struct Spi* self);
|
|||||||
extern ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters);
|
extern ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters);
|
||||||
|
|
||||||
|
|
||||||
/** ----------------------------------------------------------------------------
|
|
||||||
* Spi_Write
|
|
||||||
* Write the data in buffer to the SPI in argument self
|
|
||||||
*
|
|
||||||
* @param self The UART class object
|
|
||||||
* @param buffer Message string to send
|
|
||||||
* @parm length Message length
|
|
||||||
*
|
|
||||||
* @return ErrorStatus SUCCESS if writing message was successful
|
|
||||||
* ERROR otherwise
|
|
||||||
*
|
|
||||||
* @todo
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
extern ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length);
|
|
||||||
#endif /* MISC_INC_SPI_H_ */
|
#endif /* MISC_INC_SPI_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// @file spiDevice.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) 2015 Micro-Key bv
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// @defgroup {group_name} {group_description}
|
||||||
|
/// Description
|
||||||
|
|
||||||
|
/// @file spiDevice.h
|
||||||
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
#ifndef PLATFORM_INC_SPIDEVICE_H_
|
||||||
|
#define PLATFORM_INC_SPIDEVICE_H_
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Include files
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "IODevice.h"
|
||||||
|
#include "spi.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Constant and macro definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct SpiDevice
|
||||||
|
{
|
||||||
|
struct IODevice device;
|
||||||
|
struct Spi* spi;
|
||||||
|
struct SpiParameters parameters;
|
||||||
|
T_PL_GPIO SPI_CE;
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function declarations
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
extern ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE);
|
||||||
|
|
||||||
|
/** ----------------------------------------------------------------------------
|
||||||
|
* Spi_Write
|
||||||
|
* Write the data in buffer to the SPI in argument self
|
||||||
|
*
|
||||||
|
* @param self The UART class object
|
||||||
|
* @param buffer Message string to send
|
||||||
|
* @parm length Message length
|
||||||
|
*
|
||||||
|
* @return ErrorStatus SUCCESS if writing message was successful
|
||||||
|
* ERROR otherwise
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
* -----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
extern ErrorStatus SpiDevice_write (const struct SpiDevice* self, const char* buffer, int length);
|
||||||
|
|
||||||
|
#endif /* PLATFORM_INC_SPIDEVICE_H_ */
|
||||||
@@ -45,17 +45,53 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
|
||||||
|
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function definitions
|
// Function definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
ErrorStatus LED_turnOn(struct Led* const led)
|
|
||||||
|
ErrorStatus LED_construct (struct Led* self)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
IODevice_construct(&self->device, read, write);
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
|
||||||
|
{
|
||||||
|
(void)length;
|
||||||
|
|
||||||
|
if (buffer != 0)
|
||||||
|
{
|
||||||
|
return LED_turnOn((struct Led*)self);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return LED_turnOff((struct Led*)self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||||
|
{
|
||||||
|
struct Led* led = (struct Led*)self;
|
||||||
|
(void)length;
|
||||||
|
*actualLength = 1;
|
||||||
|
*buffer = (char)led->status;
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus LED_turnOn(struct Led* led)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "stm32f10x_it.h"
|
#include "stm32f10x_it.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "spiDevice.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
@@ -66,6 +67,9 @@
|
|||||||
#define SPI_LCD_EEPROM_Direction (SPI_Direction_2Lines_FullDuplex)
|
#define SPI_LCD_EEPROM_Direction (SPI_Direction_2Lines_FullDuplex)
|
||||||
#define SPI_LCD_EEPROM_RX_QUEUE (32)
|
#define SPI_LCD_EEPROM_RX_QUEUE (32)
|
||||||
#define SPI_LCD_EEPROM_TX_QUEUE (32)
|
#define SPI_LCD_EEPROM_TX_QUEUE (32)
|
||||||
|
|
||||||
|
// Keypad Settings
|
||||||
|
#define KEYPAD_DEBOUNCE_TIME_MS (20)
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions
|
// Type definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -88,28 +92,35 @@ static struct UartParameters _uart1Parameters;
|
|||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
static struct Spi _spi1;
|
static struct Spi _spi1;
|
||||||
static struct SpiParameters _spi1Parameters;
|
|
||||||
static struct SpiDevice _spiDAC;
|
static struct SpiDevice _spiDAC;
|
||||||
static struct Spi _spi3;
|
static struct Spi _spi3;
|
||||||
static struct SpiParameters _spi3Parameters;
|
static struct SpiParameters _spi3DisplayParameters;
|
||||||
|
static struct SpiParameters _spi3EEPROMParameters;
|
||||||
static struct SpiDevice _spiDisplay;
|
static struct SpiDevice _spiDisplay;
|
||||||
static struct SpiDevice _spiEEPROM;
|
static struct SpiDevice _spiEEPROM;
|
||||||
|
|
||||||
// Keypad
|
// Keypad
|
||||||
static struct Keypad _keypad;
|
static struct Keypad _keypad;
|
||||||
|
static struct KeypadParameters _keypadParameters;
|
||||||
|
|
||||||
// The following pointers are for export (see platform.h) and external use.
|
// The following pointers are for export (see platform.h) and external use.
|
||||||
// Note that the pointer content is marked "const"
|
// Note that the pointer content is marked "const"
|
||||||
struct Led* const ledGreen = &_ledGreen;
|
struct Led* const ledGreen = &_ledGreen;
|
||||||
struct Led* const ledOrange = &_ledOrange;
|
struct Led* const ledOrange = &_ledOrange;
|
||||||
|
|
||||||
struct Uart* const uart1 = &_uart1;
|
struct Uart* const uart1 = &_uart1;
|
||||||
|
struct UartParameters* uartLoggerParam = &_uart1Parameters;
|
||||||
|
|
||||||
struct Spi* const spi1 = &_spi1;
|
struct Spi* const spi1 = &_spi1;
|
||||||
struct Spi* const spi3 = &_spi3;
|
struct Spi* const spi3 = &_spi3;
|
||||||
struct SpiDevice* const spiDAC = &_spiDAC;
|
struct SpiDevice* const spiDAC = &_spiDAC;
|
||||||
struct SpiDevice* const spiDisplay = &_spiDisplay;
|
struct SpiDevice* const spiDisplay = &_spiDisplay;
|
||||||
|
struct SpiParameters* const spiDisplayParam = &_spi3DisplayParameters;
|
||||||
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
|
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
|
||||||
|
struct SpiParameters* const spiEEPROMParam = &_spi3EEPROMParameters;
|
||||||
|
|
||||||
struct Keypad* const keypad = &_keypad;
|
struct Keypad* const keypad = &_keypad;
|
||||||
|
struct KeypadParameters* const keypadParam = &_keypadParameters;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
@@ -131,36 +142,42 @@ ErrorStatus initPlatform(void)
|
|||||||
{
|
{
|
||||||
returnValue = initIO();
|
returnValue = initIO();
|
||||||
|
|
||||||
|
LED_construct(ledGreen);
|
||||||
|
LED_construct(ledOrange);
|
||||||
|
|
||||||
// Initialize the Console UART
|
// Initialize the Console UART
|
||||||
IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE);
|
IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE);
|
||||||
uart1->USART_TypeDef = UART_LOG_TYPEDEF;
|
uart1->USART_TypeDef = UART_LOG_TYPEDEF;
|
||||||
Uart_getDefaultParameters(&_uart1Parameters);
|
Uart_getDefaultParameters(uartLoggerParam);
|
||||||
// Adjust to higher baudrate for intensive logging
|
// Adjust to higher baudrate for intensive logging
|
||||||
_uart1Parameters.baudrate = UART_LOG_BAUDRATE;
|
uartLoggerParam->baudrate = UART_LOG_BAUDRATE;
|
||||||
// Adjust the TX queue size for intensive logging
|
// Adjust the TX queue size for intensive logging
|
||||||
_uart1Parameters.txQueueSize = UART_LOG_TX_QUEUE;
|
uartLoggerParam->txQueueSize = UART_LOG_TX_QUEUE;
|
||||||
returnValue = Uart_construct(uart1, &_uart1Parameters);
|
returnValue = Uart_construct(uart1, uartLoggerParam);
|
||||||
|
|
||||||
IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
|
// IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
|
||||||
spi1->initialized = false;
|
// spi1->initialized = false;
|
||||||
spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
|
// spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
|
||||||
SPI_getDefaultParameters(&_spi1Parameters);
|
// SPI_getDefaultParameters(&_spi1Parameters);
|
||||||
SPI_construct(spi1, &_spi1Parameters);
|
// SPI_construct(spi1, &_spi1Parameters);
|
||||||
|
|
||||||
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
|
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
|
||||||
spi3->initialized = false;
|
spi3->initialized = false;
|
||||||
spi3->SPI_TypeDef = SPI_LCD_EEPROM_TYPEDEF;
|
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
|
// Get the SPI parameters from the NHD0420 driver. They are more critical than the parameters from the EEPROM
|
||||||
NHD0420_getSpiParameters(&_spi3Parameters);
|
NHD0420_getSpiParameters(spiDisplayParam);
|
||||||
// In order to use multiple slaves on this bus (and to increase performance), some parameters are altered
|
// 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
|
// Use full-duples instead of TX only, because the EEPROM is both write- and readable
|
||||||
_spi3Parameters.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
spiDisplayParam->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||||
// Adjust the RX and TX queues for multiple use
|
// Adjust the RX and TX queues for multiple use
|
||||||
_spi3Parameters.rxQueueSize = SPI_LCD_EEPROM_RX_QUEUE;
|
spiDisplayParam->rxQueueSize = SPI_LCD_EEPROM_RX_QUEUE;
|
||||||
_spi3Parameters.txQueueSize = SPI_LCD_EEPROM_TX_QUEUE;
|
spiDisplayParam->txQueueSize = SPI_LCD_EEPROM_TX_QUEUE;
|
||||||
SPI_construct(spi3, &_spi3Parameters);
|
///TODO SPI_CE should be initialized individually
|
||||||
|
GPIO_SetBits(spiDisplay->SPI_CE.GPIO_Typedef, spiDisplay->SPI_CE.GPIO_InitStruct.GPIO_Pin);
|
||||||
|
SpiDevice_construct(spiDisplay, spi3, spiDisplayParam, spiDisplay->SPI_CE);
|
||||||
|
SpiDevice_construct(spiEEPROM, spi3, spiEEPROMParam, spiEEPROM->SPI_CE);
|
||||||
|
|
||||||
// Enable the interrupts for the Keypad columns
|
// Set-up the interrupts for the Keypad columns
|
||||||
keypad->column[0].EXTI_InitStruct.EXTI_Line = EXTI_Line4;
|
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_Mode = EXTI_Mode_Interrupt;
|
||||||
keypad->column[0].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
keypad->column[0].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||||
@@ -188,6 +205,9 @@ ErrorStatus initPlatform(void)
|
|||||||
IRQ_setInterruptProperties(EXTI4_IRQn, 11, 0, ENABLE);
|
IRQ_setInterruptProperties(EXTI4_IRQn, 11, 0, ENABLE);
|
||||||
IRQ_setInterruptProperties(EXTI9_5_IRQn, 11, 0, ENABLE);
|
IRQ_setInterruptProperties(EXTI9_5_IRQn, 11, 0, ENABLE);
|
||||||
|
|
||||||
|
Keypad_getDefaultParameters(keypadParam);
|
||||||
|
Keypad_construct(keypad, keypadParam, KEYPAD_DEBOUNCE_TIME_MS);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,18 +247,18 @@ static ErrorStatus initIO (void)
|
|||||||
|
|
||||||
/*LED IO initialisation --------------------------------------------------*/
|
/*LED IO initialisation --------------------------------------------------*/
|
||||||
// Init LED Green
|
// Init LED Green
|
||||||
_ledGreen.ledGpio.GPIO_Typedef = GPIOC;
|
ledGreen->ledGpio.GPIO_Typedef = GPIOC;
|
||||||
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
ledGreen->ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
|
ledGreen->ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
|
||||||
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
ledGreen->ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
GPIO_Init(_ledGreen.ledGpio.GPIO_Typedef, &_ledGreen.ledGpio.GPIO_InitStruct);
|
GPIO_Init(ledGreen->ledGpio.GPIO_Typedef, &ledGreen->ledGpio.GPIO_InitStruct);
|
||||||
|
|
||||||
// Init LED Orange
|
// Init LED Orange
|
||||||
_ledOrange.ledGpio.GPIO_Typedef = GPIOC;
|
ledOrange->ledGpio.GPIO_Typedef = GPIOC;
|
||||||
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
|
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
|
||||||
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
GPIO_Init(_ledOrange.ledGpio.GPIO_Typedef, &_ledOrange.ledGpio.GPIO_InitStruct);
|
GPIO_Init(ledOrange->ledGpio.GPIO_Typedef, &ledOrange->ledGpio.GPIO_InitStruct);
|
||||||
|
|
||||||
/* USART1 initialisation -------------------------------------------------*/
|
/* USART1 initialisation -------------------------------------------------*/
|
||||||
// Init TX line
|
// Init TX line
|
||||||
|
|||||||
@@ -44,22 +44,23 @@
|
|||||||
// File-scope variables
|
// File-scope variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function definitions
|
// Function definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
|
ErrorStatus SPI_construct(struct Spi* self, const struct SpiParameters* parameters)
|
||||||
{
|
{
|
||||||
ErrorStatus returnValue = SUCCESS;
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
if (!self->initialized)
|
if (!self->initialized)
|
||||||
|
|
||||||
{
|
{
|
||||||
//! Create semaphore to synchronize with USART interrupt handler
|
//! Create semaphore to synchronize with USART interrupt handler
|
||||||
vSemaphoreCreateBinary(self->txSemaphore);
|
vSemaphoreCreateBinary(self->txSemaphore);
|
||||||
@@ -83,9 +84,9 @@ ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
|
|||||||
//! Enable USART interface
|
//! Enable USART interface
|
||||||
SPI_Cmd(self->SPI_TypeDef, ENABLE);
|
SPI_Cmd(self->SPI_TypeDef, ENABLE);
|
||||||
|
|
||||||
//! Create a new FREERTOS queue to handle data from app to USART output
|
//! Create a new FREERTOS queue to handle data from app to SPI output
|
||||||
self->txQueue = xQueueCreate(parameters->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
|
//! Create a new FREERTOS queue to handle data from SPI input to app
|
||||||
self->rxQueue = xQueueCreate(parameters->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)
|
//! Queue identifier must not be 0 (0 means that the queue is not available)
|
||||||
if (self->txQueue == 0)
|
if (self->txQueue == 0)
|
||||||
@@ -110,7 +111,7 @@ ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
|
|||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
{
|
{
|
||||||
//! Enable the UART RX not empty interrupt
|
//! Enable the UART RX not empty interrupt
|
||||||
SPI_I2S_ITConfig(self->SPI_TypeDef, SPI_I2S_IT_RXNE, ENABLE);
|
// SPI_I2S_ITConfig(self->SPI_TypeDef, SPI_I2S_IT_RXNE, ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnValue == SUCCESS)
|
if (returnValue == SUCCESS)
|
||||||
@@ -151,76 +152,3 @@ ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters)
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length)
|
|
||||||
{
|
|
||||||
struct spiQueueItem txItem;
|
|
||||||
ErrorStatus returnValue = SUCCESS; //! Define return variable
|
|
||||||
int txCounter; //! Define a loop counter var
|
|
||||||
|
|
||||||
xSemaphoreTake(self->spi->spiClaimed, portMAX_DELAY);
|
|
||||||
self->spi->SPI_CE = &self->SPI_CE;
|
|
||||||
|
|
||||||
// De-select the current device to avoid start-issues
|
|
||||||
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
|
|
||||||
{
|
|
||||||
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Copy the incoming data into BLUETOOTH data structure
|
|
||||||
for (txCounter = 0; txCounter < length; txCounter++)
|
|
||||||
{
|
|
||||||
txItem.byte = buffer[txCounter]; //! Copy current data in struct
|
|
||||||
//! Add the current set of data to bluetooth transmission queue
|
|
||||||
if (pdTRUE != xQueueSend(self->spi->txQueue, &txItem, 0))
|
|
||||||
{
|
|
||||||
//! Adding item was NOT successful - break out of loop
|
|
||||||
returnValue = ERROR; //! Set return value to FALSE
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (returnValue == SUCCESS)
|
|
||||||
{
|
|
||||||
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
|
|
||||||
{
|
|
||||||
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Semaphore has been taken
|
|
||||||
//! Enable the SPI TXE (transmission empty) interrupt
|
|
||||||
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_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->spi->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
|
|
||||||
* from the uart transmission queue and transmit byte-wise until the
|
|
||||||
* queue is empty.
|
|
||||||
* An empty queue will cause the transmission complete flag (TC) to be set,
|
|
||||||
* which is polled
|
|
||||||
*/
|
|
||||||
while (SPI_I2S_GetFlagStatus(self->spi->SPI_TypeDef, SPI_I2S_FLAG_BSY) == SET)
|
|
||||||
{
|
|
||||||
//! The software must wait until TXE=1. The TXE flag remains cleared during
|
|
||||||
//! all data transfers and it is set by hardware at the last frame's
|
|
||||||
//! end of transmission
|
|
||||||
}
|
|
||||||
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
|
|
||||||
{
|
|
||||||
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
|
|
||||||
}
|
|
||||||
xSemaphoreGive(self->spi->spiClaimed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//! Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (returnValue); //! Return result to caller
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/// @file spiDevice.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 spiDevice.c
|
||||||
|
/// @ingroup {group_name}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Include files
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
#include "spiDevice.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Constant and macro definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File-scope variables
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function declarations
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
|
||||||
|
//static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Function definitions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
IODevice_construct(&self->device, NULL, write);
|
||||||
|
|
||||||
|
SPI_construct(self->spi, parameters);
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
|
||||||
|
{
|
||||||
|
return SpiDevice_write((const struct SpiDevice*)self, buffer, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorStatus SpiDevice_write (const struct SpiDevice* self, const char* buffer, int length)
|
||||||
|
{
|
||||||
|
struct spiQueueItem txItem;
|
||||||
|
ErrorStatus returnValue = SUCCESS; //! Define return variable
|
||||||
|
int txCounter; //! Define a loop counter var
|
||||||
|
|
||||||
|
|
||||||
|
xSemaphoreTake(self->spi->spiClaimed, portMAX_DELAY);
|
||||||
|
self->spi->SPI_CE = &self->SPI_CE;
|
||||||
|
|
||||||
|
|
||||||
|
//! Copy the incoming data into SPI data structure
|
||||||
|
for (txCounter = 0; txCounter < length; txCounter++)
|
||||||
|
{
|
||||||
|
txItem.byte = buffer[txCounter]; //! Copy current data in struct
|
||||||
|
if (uxQueueSpacesAvailable(self->spi->txQueue) == 2)
|
||||||
|
{
|
||||||
|
// Prevent locking in case that more data than queue-space should be send
|
||||||
|
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
|
||||||
|
{
|
||||||
|
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
|
||||||
|
}
|
||||||
|
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_IT_TXE, ENABLE);
|
||||||
|
}
|
||||||
|
//! Add the current set of data to SPI transmission queue
|
||||||
|
if (pdTRUE != xQueueSend(self->spi->txQueue, &txItem, portMAX_DELAY ))
|
||||||
|
{
|
||||||
|
//! Adding item was NOT successful - break out of loop
|
||||||
|
returnValue = ERROR; //! Set return value to FALSE
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (returnValue == SUCCESS)
|
||||||
|
{
|
||||||
|
// De-select the current device to avoid start-issues
|
||||||
|
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
|
||||||
|
{
|
||||||
|
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
|
||||||
|
}
|
||||||
|
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_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->spi->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
|
||||||
|
* from the uart transmission queue and transmit byte-wise until the
|
||||||
|
* queue is empty.
|
||||||
|
* An empty queue will cause the transmission complete flag (TC) to be set,
|
||||||
|
* which is polled
|
||||||
|
*/
|
||||||
|
while (SPI_I2S_GetFlagStatus(self->spi->SPI_TypeDef, SPI_I2S_FLAG_BSY) == SET)
|
||||||
|
{
|
||||||
|
//! The software must wait until TXE=1. The TXE flag remains cleared during
|
||||||
|
//! all data transfers and it is set by hardware at the last frame's
|
||||||
|
//! end of transmission
|
||||||
|
}
|
||||||
|
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
|
||||||
|
{
|
||||||
|
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
|
||||||
|
}
|
||||||
|
xSemaphoreGive(self->spi->spiClaimed);
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
{
|
||||||
|
//! Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return returnValue; //! Return result to caller
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ErrorStatus SpiDevice_read(const struct SpiDevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||||
|
{
|
||||||
|
ErrorStatus returnValue = SUCCESS;
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus write(struct IODevice* self, const char* buffer, size_t length);
|
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function definitions
|
// Function definitions
|
||||||
@@ -144,7 +144,7 @@ ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static ErrorStatus write(struct IODevice* self, const char* buffer, size_t length)
|
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
return Uart_Write((struct Uart*)self, buffer, length);
|
return Uart_Write((struct Uart*)self, buffer, length);
|
||||||
}
|
}
|
||||||
@@ -156,12 +156,16 @@ ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length)
|
|||||||
ErrorStatus returnValue = SUCCESS; //! Define return variable
|
ErrorStatus returnValue = SUCCESS; //! Define return variable
|
||||||
int txCounter; //! Define a loop counter var
|
int txCounter; //! Define a loop counter var
|
||||||
|
|
||||||
//! Copy the incoming data into BLUETOOTH data structure
|
//! Copy the incoming data into UART data structure
|
||||||
for (txCounter = 0; txCounter < length; txCounter++)
|
for (txCounter = 0; txCounter < length; txCounter++)
|
||||||
{
|
{
|
||||||
usartTxItem.byte = buffer[txCounter]; //! Copy current data in struct
|
usartTxItem.byte = buffer[txCounter]; //! Copy current data in struct
|
||||||
//! Add the current set of data to bluetooth transmission queue
|
if (uxQueueSpacesAvailable(self->txQueue) == 2)
|
||||||
if (pdTRUE != xQueueSend(self->txQueue, &usartTxItem, 0))
|
{
|
||||||
|
USART_ITConfig(self->USART_TypeDef, USART_IT_TXE, ENABLE);
|
||||||
|
}
|
||||||
|
//! Add the current set of data to UART transmission queue
|
||||||
|
if (pdTRUE != xQueueSend(self->txQueue, &usartTxItem, portMAX_DELAY))
|
||||||
{
|
{
|
||||||
//! Adding item was NOT successful - break out of loop
|
//! Adding item was NOT successful - break out of loop
|
||||||
returnValue = ERROR; //! Set return value to FALSE
|
returnValue = ERROR; //! Set return value to FALSE
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
#include "keypadMatrix.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -56,6 +58,8 @@ void SysTick_Handler(void);
|
|||||||
|
|
||||||
extern void IRQ_setInterruptProperties(uint8_t irqChannel, uint8_t preemptionPriority, uint8_t subPriority, FunctionalState command);
|
extern void IRQ_setInterruptProperties(uint8_t irqChannel, uint8_t preemptionPriority, uint8_t subPriority, FunctionalState command);
|
||||||
|
|
||||||
|
extern void IRQ_setKeypadEXTI(struct Keypad* self, FunctionalState command);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -40,8 +40,11 @@
|
|||||||
#include "keypadMatrix.h"
|
#include "keypadMatrix.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "IODevice.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "spi.h"
|
||||||
|
#include "spiDevice.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
@@ -137,8 +140,6 @@ static ErrorStatus systeminfoCommandHandler(void)
|
|||||||
|
|
||||||
errorStatus &= Logger_logModuleInfo();
|
errorStatus &= Logger_logModuleInfo();
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
errorStatus &= Keypad_logModuleInfo();
|
|
||||||
vTaskDelay(100);
|
|
||||||
OS_logTaskInfo(ledTaskHandle);
|
OS_logTaskInfo(ledTaskHandle);
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
OS_logTaskInfo(sysTaskHandle);
|
OS_logTaskInfo(sysTaskHandle);
|
||||||
@@ -152,9 +153,7 @@ static void initTask(void* parameters)
|
|||||||
|
|
||||||
Logger_construct(&uart1->device);
|
Logger_construct(&uart1->device);
|
||||||
|
|
||||||
Keypad_construct();
|
NHD0420_construct(&spiDisplay->device);
|
||||||
|
|
||||||
NHD0420_construct(spiDisplay);
|
|
||||||
|
|
||||||
NHD0420_turnOffDisplay();
|
NHD0420_turnOffDisplay();
|
||||||
vTaskDelay(1000);
|
vTaskDelay(1000);
|
||||||
@@ -180,14 +179,16 @@ static void initTask(void* parameters)
|
|||||||
|
|
||||||
static void ledBlinkTask (void* parameters)
|
static void ledBlinkTask (void* parameters)
|
||||||
{
|
{
|
||||||
|
char high = 1;
|
||||||
|
char low = 0;
|
||||||
struct LedTaskArguments* arguments = (struct LedTaskArguments*) parameters;
|
struct LedTaskArguments* arguments = (struct LedTaskArguments*) parameters;
|
||||||
struct Led* led = arguments->led;
|
struct Led* led = arguments->led;
|
||||||
int frequency = arguments->frequency;
|
int frequency = arguments->frequency;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
LED_turnOn(led);
|
IODevice_write(&led->device, &high, 1);
|
||||||
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
|
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
|
||||||
LED_turnOff(led);
|
IODevice_write(&led->device, &low, 1);
|
||||||
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
|
vTaskDelay(configTICK_RATE_HZ / (frequency * 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,11 @@
|
|||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
|
|
||||||
#include "stm32f10x_it.h"
|
#include "stm32f10x_it.h"
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
#include "stm32f10x_exti.h"
|
#include "stm32f10x_exti.h"
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "keypadMatrix.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
@@ -72,7 +73,6 @@ void IRQ_setInterruptProperties(uint8_t irqChannel, uint8_t preemptionPriority,
|
|||||||
{
|
{
|
||||||
NVIC_InitTypeDef NVIC_InitStructure; //! Define empty NVIC structure
|
NVIC_InitTypeDef NVIC_InitStructure; //! Define empty NVIC structure
|
||||||
|
|
||||||
//! Configure the USARTx Interrupt
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = irqChannel;
|
NVIC_InitStructure.NVIC_IRQChannel = irqChannel;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preemptionPriority;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = preemptionPriority;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = subPriority;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = subPriority;
|
||||||
@@ -81,7 +81,18 @@ void IRQ_setInterruptProperties(uint8_t irqChannel, uint8_t preemptionPriority,
|
|||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void IRQ_setKeypadEXTI(struct Keypad* self, FunctionalState command)
|
||||||
|
{
|
||||||
|
int colCounter;
|
||||||
|
for (colCounter = 0; colCounter < KEYPAD_NUMBER_OF_COLUMNS; colCounter++)
|
||||||
|
{
|
||||||
|
self->column[colCounter].EXTI_InitStruct.EXTI_LineCmd = command;
|
||||||
|
EXTI_Init(&self->column[colCounter].EXTI_InitStruct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
* @brief This function handles SVCall exception.
|
* @brief This function handles SVCall exception.
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
@@ -268,13 +279,16 @@ void SPI3_IRQHandler (void)
|
|||||||
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EXTI4_IRQHandler(void)
|
void EXTI4_IRQHandler(void)
|
||||||
{
|
{
|
||||||
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
||||||
|
|
||||||
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
||||||
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
||||||
|
|
||||||
LOGGER_INFO_ISR("EXT4 ISR");
|
LOGGER_INFO_ISR("EXT4 ISR");
|
||||||
|
|
||||||
|
|
||||||
EXTI_ClearITPendingBit(EXTI_Line4);
|
EXTI_ClearITPendingBit(EXTI_Line4);
|
||||||
|
|
||||||
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
||||||
@@ -286,16 +300,22 @@ void EXTI9_5_IRQHandler (void)
|
|||||||
|
|
||||||
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
|
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
|
||||||
{
|
{
|
||||||
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
||||||
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
||||||
LOGGER_INFO_ISR("EXT5 ISR");
|
LOGGER_INFO_ISR("EXT5 ISR");
|
||||||
EXTI_ClearITPendingBit(EXTI_Line5);
|
EXTI_ClearITPendingBit(EXTI_Line5);
|
||||||
}
|
}
|
||||||
else if (EXTI_GetITStatus(EXTI_Line6) != RESET)
|
else if (EXTI_GetITStatus(EXTI_Line6) != RESET)
|
||||||
{
|
{
|
||||||
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
||||||
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
||||||
LOGGER_INFO_ISR("EXT6 ISR");
|
LOGGER_INFO_ISR("EXT6 ISR");
|
||||||
EXTI_ClearITPendingBit(EXTI_Line6);
|
EXTI_ClearITPendingBit(EXTI_Line6);
|
||||||
}
|
}
|
||||||
else if (EXTI_GetITStatus(EXTI_Line7) != RESET)
|
else if (EXTI_GetITStatus(EXTI_Line7) != RESET)
|
||||||
{
|
{
|
||||||
|
IRQ_setKeypadEXTI(keypad, DISABLE);
|
||||||
|
xSemaphoreGiveFromISR(keypad->scanSemaphore, &higherPriorityTaskWoken);
|
||||||
LOGGER_INFO_ISR("EXT7 ISR");
|
LOGGER_INFO_ISR("EXT7 ISR");
|
||||||
EXTI_ClearITPendingBit(EXTI_Line7);
|
EXTI_ClearITPendingBit(EXTI_Line7);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user