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:
@@ -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