Files
ACD528xx_Test_Project/aconnoHelpers/aconnoHelpers.cpp
T

173 lines
4.1 KiB
C++

/**
* @file aconnoHelpers.cpp
* @author Jurica Resetar (Jurica@aconno.de)
* @brief
* @version 0.1
* @date 2019-01-22
*
* @copyright Copyright (c) 2019
*
*/
#include "aconnoHelpers.h"
#include "sdk_config.h"
#include "app_error.h"
#include "app_timer.h"
#include "nrf_drv_clock.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "MCP23017.h"
extern bool getInterruptSourceFlag;
/**@brief Function for the Timer initialization.
*
* @details Initializes the timer module. This creates and starts application timers.
*/
void timersInit(void)
{
// Initialize timer module.
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
}
/**@brief Function for starting application timers.
* @details Timers are run after the scheduler has started.
*/
void applicationTimerStart(void)
{
}
/**@brief Clear bond information /*/
void deleteBonds(void)
{
NRF_LOG_INFO("Erase bonds!");
}
/**@brief Function for initializing the nrf log module. */
void logInit(void)
{
ret_code_t err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
}
/**@brief Function for initializing the clock.
*/
void clockInit(void)
{
ret_code_t err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
}
BaseType_t xTaskCreateOrResume(TaskFunction_t pvTaskCode,
const char *pcName,
unsigned short usStackDepth,
void *pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask)
{
if (*pxCreatedTask == NULL)
{
return xTaskCreate(pvTaskCode, pcName, usStackDepth,
pvParameters, uxPriority, pxCreatedTask);
}
else
{
eTaskState taskState = eTaskGetState( *(pxCreatedTask) );
switch (taskState)
{
//todo: possibly handle other states
case eRunning:
NRF_LOG_INFO("Task Running");
break;
case eDeleted:
NRF_LOG_INFO("Task Deleted");
break;
case eReady:
NRF_LOG_INFO("Task Ready");
break;
case eBlocked:
NRF_LOG_INFO("Task Blocked");
break;
case eInvalid:
NRF_LOG_INFO("Task Invalid");
break;
case eSuspended:
NRF_LOG_INFO("Task Suspended");
vTaskResume(*pxCreatedTask);
return pdPASS;
}
//todo: return error ?
}
}
void logState(TaskHandle_t xCreatedTask)
{
eTaskState taskState =eTaskGetState( xCreatedTask );
switch (taskState)
{
case eRunning:
NRF_LOG_INFO("Task Running");
break;
case eDeleted:
NRF_LOG_INFO("Task Deleted");
break;
case eReady:
NRF_LOG_INFO("Task Ready");
break;
case eBlocked:
NRF_LOG_INFO("Task Blocked");
break;
case eInvalid:
NRF_LOG_INFO("Task Invalid");
break;
case eSuspended:
NRF_LOG_INFO("Task Suspended");
break;
}
}
void initIoExpander(MCP23017 *expdr)
{
expdr->reset();
expdr->config(0x01F8, 0xFFFF, 0x0000);
for(uint8_t x=3; x<10; x++) // Init values on Expander pins
{
expdr->writeGPIOBit(1, x);
}
expdr->writeGPIOBit(0, 10);
expdr->writeGPIOBit(0, 11);
}
uint8_t checkState(MCP23017 *expdr, AconnoGPIO *sw1)
{
uint8_t result = 0x00; // 0: pressed, 1: released
#define _(x) result |= (expdr->readGPIOBit(IOEXP_INT_SOURCE:: JOY_##x) << x##_BIT)
_(UP);
_(DOWN);
_(LEFT);
_(RIGHT);
_(CENTER);
#undef _
result |= (expdr->readGPIOBit(IOEXP_INT_SOURCE:: SW2) << SW2_BIT);
result |= ((uint8_t)sw1->read() << SW1_BIT);
result ^= 0xff;
return result;
}
void intFlagTimerCallback(TimerHandle_t xTimer)
{
getInterruptSourceFlag=true;
NRF_LOG_DEBUG("CALLBACK");
}