ADC debugged and functional now

Added Version interface

Added DisplayDevice to create an independent bridge between display app and specific display driver

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@228 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-04 09:06:16 +00:00
parent 802e9c64ca
commit c613e64e8a
24 changed files with 1147 additions and 231 deletions

View File

@@ -0,0 +1,226 @@
// -----------------------------------------------------------------------------
/// @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 "FreeRTOSFixes.h"
#include "Logger.h"
#include "keypadMatrix.h"
#include "platform.h"
#include "stm32f10x_it.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define KEYPAD_STACK_SIZE (512)
#define KEYPAD_TASK_PRIORITY (3)
#define KEYPAD_DEF_QUEUESIZE (32)
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
static void KeypadTask(void* parameters);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus Keypad_construct(struct Keypad* self, struct KeypadParameters* parameters, int debounceTime)
{
int rowCounter = 0;
int colCounter = 0;
ErrorStatus returnValue = SUCCESS;
if(keypad != NULL)
{
IODevice_construct(&self->device, read, NULL);
if(returnValue == SUCCESS)
{
//! Create semaphore to synchronize with Keypad/EXTI interrupt handler
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;
}
}
if(returnValue == SUCCESS)
{
LOGGER_INFO("Keypad task started");
}
else
{
LOGGER_ERROR("Keypad task FAILED");
}
}
return returnValue;
}
void Keypad_Destruct (const struct Keypad* self)
{
vTaskDelete(self->taskHandle);
vQueueDelete(self->rxQueue);
}
ErrorStatus Keypad_getDefaultParameters(struct KeypadParameters* parameters)
{
ErrorStatus errorStatus = SUCCESS;
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;
}
static void KeypadTask(void* parameters)
{
int rowCounter = 0;
int colCounter = 0;
struct Keypad* self = (struct Keypad*) parameters;
while (1)
{
// 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);
// Set all row outputs
for (rowCounter = 0; rowCounter < KEYPAD_NUMBER_OF_ROWS; 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++)
{
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)
{
self->lastState[rowCounter][colCounter] = RELEASED;
// Key has been released
LOGGER_DEBUG("KEY row%d, column%d released", rowCounter, colCounter);
}
else
{
// nothing changed
}
}
else
{
if (self->lastState[rowCounter][colCounter] == RELEASED)
{
self->lastState[rowCounter][colCounter] = PRESSED;
// Key has been pressed
LOGGER_DEBUG("KEY row%d, column%d pressed", rowCounter, colCounter);
}
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);
}
}