Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
source/main.cpp@14:65734075c8d3, 2018-08-29 (annotated)
- Committer:
- dbartolovic
- Date:
- Wed Aug 29 10:52:27 2018 +0000
- Branch:
- axis_normal
- Revision:
- 14:65734075c8d3
- Parent:
- 8:7ba4f82de9b6
- Child:
- 15:c0c01188a29b
Switched to low power
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 | Mutex uartM; |
dbartolovic | 8:7ba4f82de9b6 | 15 | Thread uartT; |
dbartolovic | 8:7ba4f82de9b6 | 16 | Thread bleT; |
dbartolovic | 8:7ba4f82de9b6 | 17 | Thread measureT; |
dbartolovic | 8:7ba4f82de9b6 | 18 | Thread updateServiceT; |
dbartolovic | 8:7ba4f82de9b6 | 19 | Thread updateBuzzLedsT; |
dbartolovic | 8:7ba4f82de9b6 | 20 | |
dbartolovic | 8:7ba4f82de9b6 | 21 | DigitalOut AccVcc(ACC_POWER_PIN); |
dbartolovic | 8:7ba4f82de9b6 | 22 | InterruptIn INT1(INT_PIN1); |
dbartolovic | 8:7ba4f82de9b6 | 23 | //InterruptIn INT2(INT_PIN2); |
dbartolovic | 8:7ba4f82de9b6 | 24 | I2C i2c(I2C_DATA,I2C_CLK); |
dbartolovic | 8:7ba4f82de9b6 | 25 | Ticker bleTicker; |
dbartolovic | 8:7ba4f82de9b6 | 26 | |
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 | |
dbartolovic | 8:7ba4f82de9b6 | 45 | int main(){ |
dbartolovic | 8:7ba4f82de9b6 | 46 | Lis2dh12 mems(&i2c, memsI2CAddress); |
dbartolovic | 6:55607d577a42 | 47 | |
dbartolovic | 8:7ba4f82de9b6 | 48 | tasks_init(); |
dbartolovic | 6:55607d577a42 | 49 | |
jurica238814 | 0:fc77522f4d28 | 50 | printf("Main program started.\r\n"); |
jurica238814 | 0:fc77522f4d28 | 51 | |
jurica238814 | 0:fc77522f4d28 | 52 | NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR |
jurica238814 | 0:fc77522f4d28 | 53 | NRF_NVMC->ERASEUICR = 0x00000001; // Erase all |
jurica238814 | 0:fc77522f4d28 | 54 | NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR |
jurica238814 | 0:fc77522f4d28 | 55 | NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function |
jurica238814 | 0:fc77522f4d28 | 56 | |
jurica238814 | 0:fc77522f4d28 | 57 | AccVcc = 1; |
jurica238814 | 0:fc77522f4d28 | 58 | wait_ms(POWER_UP_DELAY_MS); |
jurica238814 | 0:fc77522f4d28 | 59 | |
jurica238814 | 0:fc77522f4d28 | 60 | /* |
jurica238814 | 0:fc77522f4d28 | 61 | INT1.rise(int1Handler); |
jurica238814 | 0:fc77522f4d28 | 62 | NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps |
jurica238814 | 0:fc77522f4d28 | 63 | */ |
jurica238814 | 0:fc77522f4d28 | 64 | |
jurica238814 | 0:fc77522f4d28 | 65 | BLE &ble = BLE::Instance(); |
jurica238814 | 0:fc77522f4d28 | 66 | ble.init(bleInitComplete); |
jurica238814 | 0:fc77522f4d28 | 67 | |
dbartolovic | 14:65734075c8d3 | 68 | mems.setMode(LOW_POWER); |
dbartolovic | 14:65734075c8d3 | 69 | //mems.setMode(HIGH_RES); |
jurica238814 | 0:fc77522f4d28 | 70 | mems.enableAxes(X_axis); |
jurica238814 | 0:fc77522f4d28 | 71 | mems.enableAxes(Y_axis); |
jurica238814 | 0:fc77522f4d28 | 72 | mems.enableAxes(Z_axis); |
jurica238814 | 0:fc77522f4d28 | 73 | mems.setODR(ODR_50Hz); |
dbartolovic | 3:38eadab20283 | 74 | //mems.setScale(_16g); |
dbartolovic | 3:38eadab20283 | 75 | mems.setScale(_2g); |
jurica238814 | 0:fc77522f4d28 | 76 | mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad |
jurica238814 | 0:fc77522f4d28 | 77 | mems.int1Latch(0x01); // Enable int1 latch |
jurica238814 | 0:fc77522f4d28 | 78 | mems.int1Threshold(INT1_THRESHOLD); |
jurica238814 | 0:fc77522f4d28 | 79 | mems.int1Duration(INT1_DUR); |
jurica238814 | 0:fc77522f4d28 | 80 | mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh |
jurica238814 | 0:fc77522f4d28 | 81 | |
jurica238814 | 0:fc77522f4d28 | 82 | bleT.start(callback(bleF, &ble)); // Start bleT |
dbartolovic | 8:7ba4f82de9b6 | 83 | measureT.start(callback(measureF, &mems)); |
dbartolovic | 8:7ba4f82de9b6 | 84 | updateServiceT.start(updateServiceF); |
dbartolovic | 8:7ba4f82de9b6 | 85 | updateBuzzLedsT.start(updateBuzzLedsF); |
jurica238814 | 0:fc77522f4d28 | 86 | |
jurica238814 | 0:fc77522f4d28 | 87 | |
jurica238814 | 0:fc77522f4d28 | 88 | while(1){ |
jurica238814 | 0:fc77522f4d28 | 89 | //disableI2C(); |
dbartolovic | 8:7ba4f82de9b6 | 90 | ble.waitForEvent(); |
jurica238814 | 0:fc77522f4d28 | 91 | } |
jurica238814 | 0:fc77522f4d28 | 92 | } |