Commit for SWO for HW validation menu updates
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@245 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -47,23 +47,26 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define KEYPAD_NUMBER_OF_ROWS (4)
|
||||
#define KEYPAD_NUMBER_OF_COLUMNS (4)
|
||||
#define KEYPAD_MAX_NUMBER_OF_ROWS (6)
|
||||
#define KEYPAD_MAX_NUMBER_OF_COLUMNS (6)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct KeypadQueueItem
|
||||
{
|
||||
char byte;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RELEASED = 0,
|
||||
PRESSED = (!RELEASED)
|
||||
}Keypad_KeyState;
|
||||
} Keypad_KeyState;
|
||||
|
||||
struct KeypadQueueItem
|
||||
{
|
||||
size_t rowCoordinate;
|
||||
size_t columnCoordinate;
|
||||
Keypad_KeyState keyEvent;
|
||||
};
|
||||
|
||||
struct keypadElement
|
||||
{
|
||||
@@ -74,9 +77,9 @@ struct keypadElement
|
||||
struct Keypad
|
||||
{
|
||||
struct IODevice device;
|
||||
struct keypadElement row[KEYPAD_NUMBER_OF_ROWS];
|
||||
struct keypadElement column[KEYPAD_NUMBER_OF_COLUMNS];
|
||||
Keypad_KeyState lastState[KEYPAD_NUMBER_OF_ROWS][KEYPAD_NUMBER_OF_COLUMNS];
|
||||
struct keypadElement row[KEYPAD_MAX_NUMBER_OF_ROWS];
|
||||
struct keypadElement column[KEYPAD_MAX_NUMBER_OF_COLUMNS];
|
||||
Keypad_KeyState lastState[KEYPAD_MAX_NUMBER_OF_ROWS][KEYPAD_MAX_NUMBER_OF_COLUMNS];
|
||||
xTaskHandle taskHandle;
|
||||
int taskPriority;
|
||||
uint16_t stackSize;
|
||||
@@ -85,7 +88,8 @@ struct Keypad
|
||||
size_t rxQueueSize;
|
||||
bool initialized;
|
||||
int waitToDebounce_ms;
|
||||
|
||||
size_t numberOfRows;
|
||||
size_t numberOfColumns;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -97,6 +101,8 @@ struct Keypad
|
||||
* contructor for the Keypad driver
|
||||
*
|
||||
* @param self Keypad object to initialize
|
||||
* @param numberOfRows Number of rows of the keypad matrix
|
||||
* @param numberOfColumns Number of columns of the keypad matrix
|
||||
* @param debounceTime debounce time for the keypad to use
|
||||
* @param taskPriority Priority of the keypad task
|
||||
* @param stackSize Stacksize for the task
|
||||
@@ -107,7 +113,7 @@ struct Keypad
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Keypad_construct(struct Keypad* self, int debounceTime, int taskPriority, uint16_t stackSize, size_t rxQueueSize);
|
||||
extern ErrorStatus Keypad_construct(struct Keypad* self, size_t numberOfRows, size_t numberOfColumns, int debounceTime, int taskPriority, uint16_t stackSize, size_t rxQueueSize);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "FreeRTOSFixes.h"
|
||||
|
||||
#include "Logger.h"
|
||||
@@ -56,6 +57,7 @@
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// IO device without WRITE
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||
static void KeypadTask(void* parameters);
|
||||
|
||||
@@ -64,7 +66,7 @@ static void KeypadTask(void* parameters);
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus Keypad_construct(struct Keypad* self, int debounceTime, int taskPriority, uint16_t stackSize, size_t rxQueueSize)
|
||||
ErrorStatus Keypad_construct(struct Keypad* self, size_t numberOfRows, size_t numberOfColumns, int debounceTime, int taskPriority, uint16_t stackSize, size_t rxQueueSize)
|
||||
{
|
||||
int rowCounter = 0;
|
||||
int colCounter = 0;
|
||||
@@ -81,14 +83,16 @@ ErrorStatus Keypad_construct(struct Keypad* self, int debounceTime, int taskPrio
|
||||
}
|
||||
|
||||
self->waitToDebounce_ms = debounceTime;
|
||||
self->rxQueueSize = rxQueueSize;
|
||||
self->stackSize = stackSize;
|
||||
self->taskPriority = taskPriority;
|
||||
self->rxQueueSize = rxQueueSize;
|
||||
self->stackSize = stackSize;
|
||||
self->taskPriority = taskPriority;
|
||||
self->numberOfRows = numberOfRows;
|
||||
self->numberOfColumns = numberOfColumns;
|
||||
|
||||
// Initialize memory to keep track of state changes per key
|
||||
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||
for (rowCounter = 0; rowCounter < self->numberOfRows; rowCounter++)
|
||||
{
|
||||
for (colCounter = 0; colCounter < KEYPAD_NUMBER_OF_COLUMNS; colCounter++)
|
||||
for (colCounter = 0; colCounter < self->numberOfColumns; colCounter++)
|
||||
{
|
||||
self->lastState[rowCounter][colCounter] = RELEASED;
|
||||
}
|
||||
@@ -151,7 +155,13 @@ static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length
|
||||
|
||||
if (keypad->initialized)
|
||||
{
|
||||
*actualLength = 1;
|
||||
struct KeypadQueueItem rxQueueItem;
|
||||
|
||||
if (xQueueReceive(keypad->rxQueue, &rxQueueItem, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
*actualLength = sizeof(struct KeypadQueueItem) / sizeof (char);
|
||||
memcpy(buffer, &rxQueueItem, sizeof(struct KeypadQueueItem) / sizeof (char));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -176,25 +186,31 @@ static void KeypadTask(void* parameters)
|
||||
vTaskDelay(self->waitToDebounce_ms);
|
||||
|
||||
// Set all row outputs
|
||||
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||
for (rowCounter = 0; rowCounter < self->numberOfRows; rowCounter++)
|
||||
{
|
||||
GPIO_SetBits(self->row[rowCounter].gpio.GPIO_Typedef, self->row[rowCounter].gpio.GPIO_InitStruct.GPIO_Pin);
|
||||
}
|
||||
|
||||
// Scan through each row individually by resetting it (output level low) and check all column levels
|
||||
|
||||
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||
for (rowCounter = 0; rowCounter < self->numberOfRows; 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++)
|
||||
for (colCounter = 0; colCounter < self->numberOfColumns; 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)
|
||||
{
|
||||
self->lastState[rowCounter][colCounter] = RELEASED;
|
||||
// Key has been released
|
||||
struct KeypadQueueItem rxQueueItem;
|
||||
rxQueueItem.rowCoordinate = rowCounter;
|
||||
rxQueueItem.columnCoordinate = colCounter;
|
||||
rxQueueItem.keyEvent = RELEASED;
|
||||
// Put event in queue
|
||||
xQueueSend(self->rxQueue, &rxQueueItem, 0);
|
||||
self->lastState[rowCounter][colCounter] = RELEASED;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,8 +221,14 @@ static void KeypadTask(void* parameters)
|
||||
{
|
||||
if (self->lastState[rowCounter][colCounter] == RELEASED)
|
||||
{
|
||||
self->lastState[rowCounter][colCounter] = PRESSED;
|
||||
// Key has been pressed
|
||||
struct KeypadQueueItem rxQueueItem;
|
||||
rxQueueItem.rowCoordinate = rowCounter;
|
||||
rxQueueItem.columnCoordinate = colCounter;
|
||||
rxQueueItem.keyEvent = PRESSED;
|
||||
// Put event in queue
|
||||
xQueueSend(self->rxQueue, &rxQueueItem, 0);
|
||||
self->lastState[rowCounter][colCounter] = PRESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -218,7 +240,7 @@ static void KeypadTask(void* parameters)
|
||||
}
|
||||
|
||||
// Reset all row outputs and return to IRQ status
|
||||
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; rowCounter++)
|
||||
for (rowCounter = 0; rowCounter < self->numberOfRows; rowCounter++)
|
||||
{
|
||||
GPIO_ResetBits(self->row[rowCounter].gpio.GPIO_Typedef, self->row[rowCounter].gpio.GPIO_InitStruct.GPIO_Pin);
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ ErrorStatus initPlatform(void)
|
||||
IRQ_setInterruptProperties(EXTI4_IRQn, 12, 12, ENABLE);
|
||||
IRQ_setInterruptProperties(EXTI9_5_IRQn, 12, 12, ENABLE);
|
||||
|
||||
Keypad_construct(keypad, KEYPAD_DEBOUNCE_TIME_MS, KEYPAD_TASK_PRIORITY, KEYPAD_STACK_SIZE, KEYPAD_DEF_QUEUESIZE);
|
||||
Keypad_construct(keypad, 4, 4, KEYPAD_DEBOUNCE_TIME_MS, KEYPAD_TASK_PRIORITY, KEYPAD_STACK_SIZE, KEYPAD_DEF_QUEUESIZE);
|
||||
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* GPIOs */
|
||||
|
||||
Reference in New Issue
Block a user