Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
jurica238814
Date:
Thu Sep 13 12:20:35 2018 +0200
Branch:
mbedOsUpdate
Revision:
19:2681edc2f2b9
Parent:
8:7ba4f82de9b6
Child:
22:7dae8496b97c
Work in progress

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 19:2681edc2f2b9 1 /*
jurica238814 0:fc77522f4d28 2 * aconno.de
jurica238814 0:fc77522f4d28 3 * Made by Jurica Resetar
jurica238814 19:2681edc2f2b9 4 * All right reserved
jurica238814 0:fc77522f4d28 5 *
jurica238814 0:fc77522f4d28 6 */
jurica238814 0:fc77522f4d28 7
dbartolovic 8:7ba4f82de9b6 8 #include "bsp.h"
jurica238814 19:2681edc2f2b9 9 #include "bspLed.h"
dbartolovic 8:7ba4f82de9b6 10 #include "tasks.h"
jurica238814 19:2681edc2f2b9 11 #include <events/mbed_events.h>
jurica238814 19:2681edc2f2b9 12 #include "aconnoConfig.h"
jurica238814 19:2681edc2f2b9 13 #include "aconno_ble.h"
jurica238814 0:fc77522f4d28 14
jurica238814 19:2681edc2f2b9 15 #if !defined(MBED_CPU_STATS_ENABLED) || !defined(DEVICE_LPTICKER) || !defined(DEVICE_SLEEP)
jurica238814 19:2681edc2f2b9 16 #error [NOT_SUPPORTED] Test not supported for statistics
jurica238814 19:2681edc2f2b9 17 #endif
dbartolovic 8:7ba4f82de9b6 18
jurica238814 19:2681edc2f2b9 19 EventQueue queue(32 * EVENTS_EVENT_SIZE);
jurica238814 19:2681edc2f2b9 20
dbartolovic 8:7ba4f82de9b6 21 Thread uartT;
dbartolovic 8:7ba4f82de9b6 22 Thread bleT;
dbartolovic 8:7ba4f82de9b6 23 Thread measureT;
dbartolovic 8:7ba4f82de9b6 24 Thread updateServiceT;
dbartolovic 8:7ba4f82de9b6 25 Thread updateBuzzLedsT;
jurica238814 19:2681edc2f2b9 26 Thread updateStatisticsT;
jurica238814 0:fc77522f4d28 27
jurica238814 0:fc77522f4d28 28 void disableI2C(){
jurica238814 0:fc77522f4d28 29 NRF_TWI0->ENABLE = 0;
jurica238814 0:fc77522f4d28 30 NRF_TWI0->PSELSCL = 0xFFFFFFFF;
jurica238814 0:fc77522f4d28 31 NRF_TWI1->ENABLE = 0;
jurica238814 0:fc77522f4d28 32 NRF_TWI1->PSELSCL = 0xFFFFFFFF;
jurica238814 0:fc77522f4d28 33 NRF_TWIM0->ENABLE = 0;
jurica238814 0:fc77522f4d28 34 NRF_TWIM0->PSEL.SCL = 0x80000000;
jurica238814 0:fc77522f4d28 35 NRF_TWIM0->PSEL.SDA = 0x80000000;
jurica238814 0:fc77522f4d28 36 NRF_TWIM1->ENABLE = 0;
jurica238814 0:fc77522f4d28 37 NRF_TWIM0->PSEL.SCL = 0x80000000;
jurica238814 0:fc77522f4d28 38 NRF_TWIM0->PSEL.SDA = 0x80000000;
jurica238814 0:fc77522f4d28 39 DigitalOut foo(I2C_DATA);
jurica238814 0:fc77522f4d28 40 DigitalOut bar(I2C_CLK);
jurica238814 0:fc77522f4d28 41 foo = 1;
jurica238814 0:fc77522f4d28 42 bar = 1;
jurica238814 0:fc77522f4d28 43 }
jurica238814 0:fc77522f4d28 44
jurica238814 19:2681edc2f2b9 45 void printStatsF()
jurica238814 19:2681edc2f2b9 46 {
jurica238814 19:2681edc2f2b9 47 mbed_stats_cpu_t stats;
jurica238814 19:2681edc2f2b9 48
jurica238814 19:2681edc2f2b9 49 mbed_stats_cpu_get(&stats);
jurica238814 19:2681edc2f2b9 50 printf("%-20lld", stats.uptime/1000);
jurica238814 19:2681edc2f2b9 51 printf("%-20lld", stats.idle_time/1000);
jurica238814 19:2681edc2f2b9 52 printf("%-20lld", stats.sleep_time/1000);
jurica238814 19:2681edc2f2b9 53 printf("%-20lld\n", stats.deep_sleep_time/1000);
jurica238814 19:2681edc2f2b9 54 }
jurica238814 19:2681edc2f2b9 55
jurica238814 19:2681edc2f2b9 56 void bleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
jurica238814 19:2681edc2f2b9 57 BLE &ble = BLE::Instance();
jurica238814 19:2681edc2f2b9 58 queue.call(Callback<void()>(&ble, &BLE::processEvents));
jurica238814 19:2681edc2f2b9 59 }
jurica238814 19:2681edc2f2b9 60
jurica238814 19:2681edc2f2b9 61 Thread testThread;
jurica238814 19:2681edc2f2b9 62
jurica238814 19:2681edc2f2b9 63 void testFunction()
jurica238814 19:2681edc2f2b9 64 {
jurica238814 19:2681edc2f2b9 65 while(1)
jurica238814 19:2681edc2f2b9 66 {
jurica238814 19:2681edc2f2b9 67 printf("Test thread\n");
jurica238814 19:2681edc2f2b9 68 Thread::wait(1000);
jurica238814 19:2681edc2f2b9 69 }
jurica238814 19:2681edc2f2b9 70 }
jurica238814 19:2681edc2f2b9 71
jurica238814 19:2681edc2f2b9 72 void int1Handler(void)
jurica238814 19:2681edc2f2b9 73 {
jurica238814 19:2681edc2f2b9 74 __disable_irq();
jurica238814 19:2681edc2f2b9 75 /*
jurica238814 19:2681edc2f2b9 76 untilSleep = ACTIVE_PERIOD / MEASURE_INTERVAL_MS;
jurica238814 19:2681edc2f2b9 77 measureT.signal_set(START_MEAS);
jurica238814 19:2681edc2f2b9 78 */
jurica238814 19:2681edc2f2b9 79 mems.clearIntFlag();
jurica238814 19:2681edc2f2b9 80 redLed = !redLed;
jurica238814 19:2681edc2f2b9 81 __enable_irq();
jurica238814 19:2681edc2f2b9 82 }
jurica238814 19:2681edc2f2b9 83
jurica238814 19:2681edc2f2b9 84 int main()
jurica238814 19:2681edc2f2b9 85 {
jurica238814 19:2681edc2f2b9 86
jurica238814 19:2681edc2f2b9 87 printf("Main program started.\r\n");
jurica238814 19:2681edc2f2b9 88
jurica238814 19:2681edc2f2b9 89 bspLedInit();
jurica238814 19:2681edc2f2b9 90
dbartolovic 8:7ba4f82de9b6 91 Lis2dh12 mems(&i2c, memsI2CAddress);
jurica238814 19:2681edc2f2b9 92
jurica238814 19:2681edc2f2b9 93 lisPowerCtrl((lisPower_t)LIS_ON);
jurica238814 0:fc77522f4d28 94 wait_ms(POWER_UP_DELAY_MS);
jurica238814 0:fc77522f4d28 95
jurica238814 19:2681edc2f2b9 96
jurica238814 19:2681edc2f2b9 97 lisInt1Pin.rise(int1Handler);
jurica238814 0:fc77522f4d28 98 NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps
jurica238814 19:2681edc2f2b9 99
jurica238814 19:2681edc2f2b9 100 /*
jurica238814 0:fc77522f4d28 101 BLE &ble = BLE::Instance();
jurica238814 19:2681edc2f2b9 102 ble.onEventsToProcess(bleEventsProcessing);
jurica238814 0:fc77522f4d28 103 ble.init(bleInitComplete);
jurica238814 19:2681edc2f2b9 104 */
jurica238814 19:2681edc2f2b9 105
dbartolovic 5:9903738f2587 106 //mems.setMode(LOW_POWER);
dbartolovic 5:9903738f2587 107 mems.setMode(HIGH_RES);
jurica238814 0:fc77522f4d28 108 mems.enableAxes(X_axis);
jurica238814 0:fc77522f4d28 109 mems.enableAxes(Y_axis);
jurica238814 19:2681edc2f2b9 110 mems.enableAxes(Z_axis);
jurica238814 0:fc77522f4d28 111 mems.setODR(ODR_50Hz);
dbartolovic 3:38eadab20283 112 //mems.setScale(_16g);
dbartolovic 3:38eadab20283 113 mems.setScale(_2g);
jurica238814 0:fc77522f4d28 114 mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad
jurica238814 0:fc77522f4d28 115 mems.int1Latch(0x01); // Enable int1 latch
jurica238814 19:2681edc2f2b9 116 mems.int1Threshold(INT1_THRESHOLD);
jurica238814 19:2681edc2f2b9 117 mems.int1Duration(INT1_DUR);
jurica238814 0:fc77522f4d28 118 mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh
jurica238814 19:2681edc2f2b9 119 //lisPowerCtrl(LIS_OFF);
jurica238814 19:2681edc2f2b9 120
jurica238814 19:2681edc2f2b9 121 //disableI2C(); // THIS REALLY NEEDS TO BE HERE!
jurica238814 19:2681edc2f2b9 122
jurica238814 19:2681edc2f2b9 123 #if PRINT_ON_RTT
jurica238814 19:2681edc2f2b9 124 queue.call_every(2000, printStatsF);
jurica238814 19:2681edc2f2b9 125 #endif
jurica238814 19:2681edc2f2b9 126 //testThread.start(testFunction);
jurica238814 19:2681edc2f2b9 127 //measureT.start(callback(measureF, &mems));
jurica238814 19:2681edc2f2b9 128 //updateServiceT.start(updateServiceF);
jurica238814 19:2681edc2f2b9 129 //updateBuzzLedsT.start(updateBuzzLedsF);
jurica238814 19:2681edc2f2b9 130
jurica238814 19:2681edc2f2b9 131 queue.dispatch_forever();
jurica238814 19:2681edc2f2b9 132
jurica238814 0:fc77522f4d28 133 }