Files
ACD528xx_Test_Project/aconnoHelpers/aconnoHelpers.cpp
T

149 lines
3.5 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"
/**@brief Function for the Timer initialization.
*
* @details Initializes the timer module. This creates and starts application timers.
*/
void timers_init(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 application_timers_start(void)
{
}
/**@brief Clear bond information /*/
void delete_bonds(void)
{
NRF_LOG_INFO("Erase bonds!");
}
/**@brief Function for initializing the nrf log module. */
void log_init(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 clock_init(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);
}