Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
dbartolovic
Date:
Thu Sep 20 13:24:15 2018 +0000
Branch:
master
Revision:
27:724dc5ed4883
Parent:
26:6101bb09f70d
Turned led off

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:fc77522f4d28 1 /*
jurica238814 0:fc77522f4d28 2 * aconno.de
jurica238814 0:fc77522f4d28 3 * Made by Jurica Resetar
jurica238814 0:fc77522f4d28 4 * All right reserved
jurica238814 0:fc77522f4d28 5 *
jurica238814 0:fc77522f4d28 6 */
jurica238814 0:fc77522f4d28 7
jurica238814 0:fc77522f4d28 8 #include "main.h"
dbartolovic 8:7ba4f82de9b6 9 #include "bsp.h"
dbartolovic 8:7ba4f82de9b6 10 #include "tasks.h"
jurica238814 0:fc77522f4d28 11
dbartolovic 8:7ba4f82de9b6 12
dbartolovic 8:7ba4f82de9b6 13 char memsI2CAddress = I2C_ADDRESS;
dbartolovic 8:7ba4f82de9b6 14 Thread bleT;
dbartolovic 8:7ba4f82de9b6 15 Thread measureT;
dbartolovic 8:7ba4f82de9b6 16 Thread updateServiceT;
dbartolovic 8:7ba4f82de9b6 17 Thread updateBuzzLedsT;
dbartolovic 16:482d8f81d6f3 18 Thread servLoopT;
dbartolovic 8:7ba4f82de9b6 19
dbartolovic 24:7539258b015c 20
dbartolovic 24:7539258b015c 21 extern DigitalOut redLed;
dbartolovic 8:7ba4f82de9b6 22 DigitalOut AccVcc(ACC_POWER_PIN);
dbartolovic 8:7ba4f82de9b6 23 InterruptIn INT1(INT_PIN1);
dbartolovic 8:7ba4f82de9b6 24 //InterruptIn INT2(INT_PIN2);
dbartolovic 8:7ba4f82de9b6 25 I2C i2c(I2C_DATA,I2C_CLK);
dbartolovic 8:7ba4f82de9b6 26
dbartolovic 16:482d8f81d6f3 27 Lis2dh12 mems(&i2c, memsI2CAddress);
jurica238814 0:fc77522f4d28 28
jurica238814 0:fc77522f4d28 29
dbartolovic 15:c0c01188a29b 30 void int1Handler(void)
dbartolovic 16:482d8f81d6f3 31 {
dbartolovic 16:482d8f81d6f3 32 __disable_irq();
dbartolovic 16:482d8f81d6f3 33
dbartolovic 16:482d8f81d6f3 34 mems.clearIntFlag();
dbartolovic 27:724dc5ed4883 35 //redLed = !redLed;
dbartolovic 15:c0c01188a29b 36
dbartolovic 16:482d8f81d6f3 37 measureT.signal_set(START_MEAS);
dbartolovic 15:c0c01188a29b 38
dbartolovic 16:482d8f81d6f3 39 __enable_irq();
dbartolovic 15:c0c01188a29b 40 }
dbartolovic 15:c0c01188a29b 41
dbartolovic 8:7ba4f82de9b6 42 int main(){
dbartolovic 15:c0c01188a29b 43
dbartolovic 8:7ba4f82de9b6 44 tasks_init();
dbartolovic 6:55607d577a42 45
jurica238814 0:fc77522f4d28 46 printf("Main program started.\r\n");
jurica238814 0:fc77522f4d28 47
jurica238814 0:fc77522f4d28 48 NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR
jurica238814 0:fc77522f4d28 49 NRF_NVMC->ERASEUICR = 0x00000001; // Erase all
jurica238814 0:fc77522f4d28 50 NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR
jurica238814 0:fc77522f4d28 51 NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function
jurica238814 0:fc77522f4d28 52
dbartolovic 24:7539258b015c 53
jurica238814 0:fc77522f4d28 54 AccVcc = 1;
dbartolovic 24:7539258b015c 55 wait_ms(POWER_UP_DELAY_MS);
jurica238814 0:fc77522f4d28 56
dbartolovic 16:482d8f81d6f3 57 //measureT.signal_set(START_MEAS);
jurica238814 0:fc77522f4d28 58 INT1.rise(int1Handler);
jurica238814 0:fc77522f4d28 59 NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps
dbartolovic 15:c0c01188a29b 60
jurica238814 0:fc77522f4d28 61 BLE &ble = BLE::Instance();
jurica238814 0:fc77522f4d28 62 ble.init(bleInitComplete);
dbartolovic 16:482d8f81d6f3 63
dbartolovic 14:65734075c8d3 64 mems.setMode(LOW_POWER);
dbartolovic 14:65734075c8d3 65 //mems.setMode(HIGH_RES);
jurica238814 0:fc77522f4d28 66 mems.enableAxes(X_axis);
jurica238814 0:fc77522f4d28 67 mems.enableAxes(Y_axis);
jurica238814 0:fc77522f4d28 68 mems.enableAxes(Z_axis);
dbartolovic 24:7539258b015c 69 mems.setODR(ACC_ODR_MODE);
dbartolovic 3:38eadab20283 70 //mems.setScale(_16g);
dbartolovic 16:482d8f81d6f3 71 mems.setScale(_8g);
jurica238814 0:fc77522f4d28 72 mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad
jurica238814 0:fc77522f4d28 73 mems.int1Latch(0x01); // Enable int1 latch
jurica238814 0:fc77522f4d28 74 mems.int1Threshold(INT1_THRESHOLD);
jurica238814 0:fc77522f4d28 75 mems.int1Duration(INT1_DUR);
jurica238814 0:fc77522f4d28 76 mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh
dbartolovic 16:482d8f81d6f3 77
jurica238814 0:fc77522f4d28 78 bleT.start(callback(bleF, &ble)); // Start bleT
dbartolovic 8:7ba4f82de9b6 79 measureT.start(callback(measureF, &mems));
dbartolovic 8:7ba4f82de9b6 80 updateServiceT.start(updateServiceF);
dbartolovic 8:7ba4f82de9b6 81 updateBuzzLedsT.start(updateBuzzLedsF);
dbartolovic 16:482d8f81d6f3 82 servLoopT.start(servLoopC);
jurica238814 0:fc77522f4d28 83
jurica238814 0:fc77522f4d28 84 while(1){
jurica238814 0:fc77522f4d28 85 //disableI2C();
dbartolovic 15:c0c01188a29b 86 //ble.waitForEvent();
dbartolovic 15:c0c01188a29b 87 Thread::wait(0xFFFFFFFF);
jurica238814 0:fc77522f4d28 88 }
jurica238814 0:fc77522f4d28 89 }