Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
source/main.cpp@23:bf9c1dd2b5cb, 2018-09-17 (annotated)
- Committer:
- dbartolovic
- Date:
- Mon Sep 17 12:46:41 2018 +0000
- Branch:
- testing-ignore
- Revision:
- 23:bf9c1dd2b5cb
- Parent:
- 16:482d8f81d6f3
- Child:
- 24:7539258b015c
Testing, ignore this branch
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:7ba4f82de9b6 | 20 | DigitalOut AccVcc(ACC_POWER_PIN); |
dbartolovic | 8:7ba4f82de9b6 | 21 | InterruptIn INT1(INT_PIN1); |
dbartolovic | 8:7ba4f82de9b6 | 22 | //InterruptIn INT2(INT_PIN2); |
dbartolovic | 8:7ba4f82de9b6 | 23 | I2C i2c(I2C_DATA,I2C_CLK); |
dbartolovic | 8:7ba4f82de9b6 | 24 | |
dbartolovic | 16:482d8f81d6f3 | 25 | Lis2dh12 mems(&i2c, memsI2CAddress); |
jurica238814 | 0:fc77522f4d28 | 26 | |
jurica238814 | 0:fc77522f4d28 | 27 | void disableI2C(){ |
jurica238814 | 0:fc77522f4d28 | 28 | NRF_TWI0->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 29 | NRF_TWI0->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 0:fc77522f4d28 | 30 | NRF_TWI1->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 31 | NRF_TWI1->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 0:fc77522f4d28 | 32 | NRF_TWIM0->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 33 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 34 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 35 | NRF_TWIM1->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 36 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 37 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 38 | DigitalOut foo(I2C_DATA); |
jurica238814 | 0:fc77522f4d28 | 39 | DigitalOut bar(I2C_CLK); |
jurica238814 | 0:fc77522f4d28 | 40 | foo = 1; |
jurica238814 | 0:fc77522f4d28 | 41 | bar = 1; |
jurica238814 | 0:fc77522f4d28 | 42 | } |
jurica238814 | 0:fc77522f4d28 | 43 | |
dbartolovic | 15:c0c01188a29b | 44 | extern int untilSleep; |
dbartolovic | 15:c0c01188a29b | 45 | void int1Handler(void) |
dbartolovic | 16:482d8f81d6f3 | 46 | { |
dbartolovic | 16:482d8f81d6f3 | 47 | __disable_irq(); |
dbartolovic | 16:482d8f81d6f3 | 48 | |
dbartolovic | 16:482d8f81d6f3 | 49 | mems.clearIntFlag(); |
dbartolovic | 16:482d8f81d6f3 | 50 | |
dbartolovic | 15:c0c01188a29b | 51 | untilSleep = ACTIVE_PERIOD / MEASURE_INTERVAL_MS; |
dbartolovic | 15:c0c01188a29b | 52 | |
dbartolovic | 16:482d8f81d6f3 | 53 | measureT.signal_set(START_MEAS); |
dbartolovic | 15:c0c01188a29b | 54 | |
dbartolovic | 16:482d8f81d6f3 | 55 | __enable_irq(); |
dbartolovic | 15:c0c01188a29b | 56 | } |
dbartolovic | 15:c0c01188a29b | 57 | |
dbartolovic | 8:7ba4f82de9b6 | 58 | int main(){ |
dbartolovic | 15:c0c01188a29b | 59 | |
dbartolovic | 8:7ba4f82de9b6 | 60 | tasks_init(); |
dbartolovic | 6:55607d577a42 | 61 | |
jurica238814 | 0:fc77522f4d28 | 62 | printf("Main program started.\r\n"); |
jurica238814 | 0:fc77522f4d28 | 63 | |
jurica238814 | 0:fc77522f4d28 | 64 | NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR |
jurica238814 | 0:fc77522f4d28 | 65 | NRF_NVMC->ERASEUICR = 0x00000001; // Erase all |
jurica238814 | 0:fc77522f4d28 | 66 | NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR |
jurica238814 | 0:fc77522f4d28 | 67 | NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function |
jurica238814 | 0:fc77522f4d28 | 68 | |
jurica238814 | 0:fc77522f4d28 | 69 | AccVcc = 1; |
dbartolovic | 16:482d8f81d6f3 | 70 | //wait_ms(POWER_UP_DELAY_MS); |
dbartolovic | 16:482d8f81d6f3 | 71 | Thread::wait(POWER_UP_DELAY_MS); |
jurica238814 | 0:fc77522f4d28 | 72 | |
dbartolovic | 15:c0c01188a29b | 73 | |
dbartolovic | 16:482d8f81d6f3 | 74 | //measureT.signal_set(START_MEAS); |
jurica238814 | 0:fc77522f4d28 | 75 | INT1.rise(int1Handler); |
jurica238814 | 0:fc77522f4d28 | 76 | NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps |
dbartolovic | 15:c0c01188a29b | 77 | |
jurica238814 | 0:fc77522f4d28 | 78 | |
jurica238814 | 0:fc77522f4d28 | 79 | BLE &ble = BLE::Instance(); |
jurica238814 | 0:fc77522f4d28 | 80 | ble.init(bleInitComplete); |
dbartolovic | 16:482d8f81d6f3 | 81 | |
dbartolovic | 14:65734075c8d3 | 82 | mems.setMode(LOW_POWER); |
dbartolovic | 14:65734075c8d3 | 83 | //mems.setMode(HIGH_RES); |
jurica238814 | 0:fc77522f4d28 | 84 | mems.enableAxes(X_axis); |
jurica238814 | 0:fc77522f4d28 | 85 | mems.enableAxes(Y_axis); |
jurica238814 | 0:fc77522f4d28 | 86 | mems.enableAxes(Z_axis); |
dbartolovic | 23:bf9c1dd2b5cb | 87 | mems.setODR(ACC_ODR_SLEEP_MODE); |
dbartolovic | 3:38eadab20283 | 88 | //mems.setScale(_16g); |
dbartolovic | 16:482d8f81d6f3 | 89 | mems.setScale(_8g); |
jurica238814 | 0:fc77522f4d28 | 90 | mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad |
jurica238814 | 0:fc77522f4d28 | 91 | mems.int1Latch(0x01); // Enable int1 latch |
jurica238814 | 0:fc77522f4d28 | 92 | mems.int1Threshold(INT1_THRESHOLD); |
jurica238814 | 0:fc77522f4d28 | 93 | mems.int1Duration(INT1_DUR); |
jurica238814 | 0:fc77522f4d28 | 94 | mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh |
dbartolovic | 16:482d8f81d6f3 | 95 | |
jurica238814 | 0:fc77522f4d28 | 96 | bleT.start(callback(bleF, &ble)); // Start bleT |
dbartolovic | 8:7ba4f82de9b6 | 97 | measureT.start(callback(measureF, &mems)); |
dbartolovic | 8:7ba4f82de9b6 | 98 | updateServiceT.start(updateServiceF); |
dbartolovic | 8:7ba4f82de9b6 | 99 | updateBuzzLedsT.start(updateBuzzLedsF); |
dbartolovic | 16:482d8f81d6f3 | 100 | servLoopT.start(servLoopC); |
jurica238814 | 0:fc77522f4d28 | 101 | |
jurica238814 | 0:fc77522f4d28 | 102 | |
jurica238814 | 0:fc77522f4d28 | 103 | while(1){ |
jurica238814 | 0:fc77522f4d28 | 104 | //disableI2C(); |
dbartolovic | 15:c0c01188a29b | 105 | //ble.waitForEvent(); |
dbartolovic | 15:c0c01188a29b | 106 | Thread::wait(0xFFFFFFFF); |
jurica238814 | 0:fc77522f4d28 | 107 | } |
jurica238814 | 0:fc77522f4d28 | 108 | } |