/** * @file main.cpp * @author Jurica Resetar (Jurica@aconno.de) * @brief Template project based on FreeRTOS and Nordic's SDK * @version 0.1 * @date 2019-02-11 * * @copyright Copyright (c) 2019 * */ #include #include #include "nordic_common.h" #include "nrf.h" #include "nrf_sdh_freertos.h" #include "FreeRTOS.h" #include "task.h" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" #include "settings.h" #include "basic_config.h" #include "arb_data.h" #include "aconnoConfig.h" #include "aconnoHelpers.h" #include "aconnoTasks.h" #include "aconnoBLE.h" #include "aconnoTasks.h" /** * @brief loger task handler * */ TaskHandle_t initTask; /** * @brief State Machine menu task handler * */ TaskHandle_t menuStateMachineTask; #if NRF_LOG_ENABLED extern TaskHandle_t mLoggerThread; #endif TaskHandle_t LDRTask; TaskHandle_t potTask; TaskHandle_t tempTask; TaskHandle_t gyroTask; TaskHandle_t bleTask; TaskHandle_t irTask; TaskHandle_t ledsTask; AconnoI2C i2c(PIN_EXP_SDA, PIN_EXP_SCL); AconnoSPI spi(PIN_EPD_MISO, PIN_EPD_MOSI, PIN_EPD_SCK); AconnoSAADC adc; AconnoGPIO ledRed(PIN_LED_RED, GPIO_DIR::GPIO_OUTPUT); AconnoGPIO ledBlue(PIN_LED_BLUE, GPIO_DIR::GPIO_OUTPUT); AconnoGPIO ledGreen(PIN_LED_GREEN, GPIO_DIR::GPIO_OUTPUT); AconnoGPIO irLed(PIN_IRLED, GPIO_DIR::GPIO_OUTPUT); AconnoGPIO sw1 (PIN_BUTTON, GPIO_DIR::GPIO_INPUT); AconnoGPIO ld1 (PIN_LED, GPIO_DIR::GPIO_OUTPUT); GDEP015OC1 epd(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY); MCP23017 expdr(i2c, TWI_EXPANDER_ADDR, EXPDR_A_INT, GPIO_DIR::GPIO_INTERRUPT, GPIO_PULL::OFF, GPIO_EDGE::FALLING, mainMenuInterruptCallback); LSM9DS1 mems(i2c); LDR light(adc, ADC_LIGHT); Potentiometer pot(adc, ADC_POT); MCP9700 ambientTemperature(adc, ADC_TEMP); /** @brief Function for application main entry. */ int main(void) { // Initialize modules. logInit(); clockInit(); NRF_LOG_INFO("\r\n\r\nMain started."); if(pdPASS != xTaskCreate(logTaskFunction, "INIT", 256, NULL, 1, &initTask)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } xTaskCreate(menuStateMachineTaskFunction, "MenuStateMachine", 256, NULL, 1, &menuStateMachineTask); xTaskCreate(ldrFunction, "LDR", 256, NULL, 1, &LDRTask); xTaskCreate(potentiometerFunction, "POT", 256, NULL, 1, &potTask); xTaskCreate(temperatureFunction, "TEMP", 256, NULL, 1, &tempTask); xTaskCreate(gyroFunction, "GYRO", 256, NULL, 1, &gyroTask); xTaskCreate(bleBeaconFunction, "BEACON", 256, NULL, 1, &bleTask); xTaskCreate(infraredFunction, "INFRARED", 256, NULL, 1, &irTask); xTaskCreate(ledsFunction, "LEDS", 256, NULL, 1, &ledsTask); // Activate deep sleep mode. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Initialize modules. timersInit(); applicationTimerStart(); // aconno BLE module init AconnoBLE &myBLE = *getAconnoBLEInstance(); myBLE.initBLEStack(); //myBLE.GATTInit(); #if 1 myBLE.setTXPower(4); myBLE.startAdvertising(APP_ADV_INTERVAL, APP_ADV_DURATION); #endif // Create a FreeRTOS task for the BLE stack. // The task will run advertising_start() before entering its loop. nrf_sdh_freertos_init(NULL, NULL); NRF_LOG_INFO("HRS FreeRTOS example started."); settingsInit(NULL); basicConfigInit(); arbDataInit(); // Start FreeRTOS scheduler. vTaskStartScheduler(); for(;;) { APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN); } } #if NRF_LOG_ENABLED /**@brief Thread for handling the logger. * * @details This thread is responsible for processing log entries if * logs are deferred. Thread flushes all log entries and suspends. It is * resumed by idle task hook. * * @param[in] arg Pointer used for passing some arbitrary information * (context) from the osThreadCreate() call to the thread. */ void loggerThread(void *arg) { UNUSED_PARAMETER(arg); while(1) { NRF_LOG_FLUSH(); vTaskSuspend(NULL); // Suspend myself } } #endif //NRF_LOG_ENABLED /**@brief A function which is hooked to idle task. * @note Idle hook must be enabled in FreeRTOS configuration * (configUSE_IDLE_HOOK). */ #ifdef __cplusplus extern "C" { void vApplicationIdleHook(void) { #if NRF_LOG_ENABLED vTaskResume(mLoggerThread); #endif } } #endif