Edit
Dependencies: Lis2dh12 aconno_I2C aconno_nrf52_uart adc52832_common aconno_SEGGER_RTT
source/main.cpp@5:ceb5f3789cb0, 2018-02-27 (annotated)
- Committer:
- jurica238814
- Date:
- Tue Feb 27 12:46:20 2018 +0000
- Branch:
- NanoModule
- Revision:
- 5:ceb5f3789cb0
- Parent:
- 3:f2078081a779
- Child:
- 6:4a4e5dbc8e1e
- Child:
- 8:4b1ac4733b3d
Init commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 3:f2078081a779 | 1 | /* |
jurica238814 | 3:f2078081a779 | 2 | * aconno.de |
jurica238814 | 3:f2078081a779 | 3 | * Made by Jurica Resetar |
jurica238814 | 3:f2078081a779 | 4 | * All right reserved |
jurica238814 | 3:f2078081a779 | 5 | * |
jurica238814 | 3:f2078081a779 | 6 | */ |
jurica238814 | 3:f2078081a779 | 7 | |
jurica238814 | 3:f2078081a779 | 8 | #include "main.h" |
jurica238814 | 3:f2078081a779 | 9 | |
jurica238814 | 3:f2078081a779 | 10 | void printOnUart(){ |
jurica238814 | 3:f2078081a779 | 11 | while(1){ |
jurica238814 | 3:f2078081a779 | 12 | SEND("Uart works...\r\n"); |
jurica238814 | 3:f2078081a779 | 13 | wait_ms(500); |
jurica238814 | 3:f2078081a779 | 14 | } |
jurica238814 | 3:f2078081a779 | 15 | } |
jurica238814 | 3:f2078081a779 | 16 | |
jurica238814 | 3:f2078081a779 | 17 | void disableI2C(){ |
jurica238814 | 3:f2078081a779 | 18 | NRF_TWI0->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 19 | NRF_TWI0->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 3:f2078081a779 | 20 | NRF_TWI1->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 21 | NRF_TWI1->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 3:f2078081a779 | 22 | NRF_TWIM0->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 23 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 3:f2078081a779 | 24 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 3:f2078081a779 | 25 | NRF_TWIM1->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 26 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 3:f2078081a779 | 27 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 3:f2078081a779 | 28 | DigitalOut foo(I2C_DATA); |
jurica238814 | 3:f2078081a779 | 29 | DigitalOut bar(I2C_CLK); |
jurica238814 | 3:f2078081a779 | 30 | foo = 1; |
jurica238814 | 3:f2078081a779 | 31 | bar = 1; |
jurica238814 | 3:f2078081a779 | 32 | } |
jurica238814 | 3:f2078081a779 | 33 | |
jurica238814 | 3:f2078081a779 | 34 | void disableBle(){ |
jurica238814 | 3:f2078081a779 | 35 | bleTicker.detach(); |
jurica238814 | 3:f2078081a779 | 36 | bleT.signal_set(DISABLE_BLE_SIG); |
jurica238814 | 3:f2078081a779 | 37 | } |
jurica238814 | 3:f2078081a779 | 38 | |
jurica238814 | 3:f2078081a779 | 39 | void int1Handler(){ |
jurica238814 | 3:f2078081a779 | 40 | __disable_irq(); |
jurica238814 | 3:f2078081a779 | 41 | I2C i2c(I2C_DATA,I2C_CLK); |
jurica238814 | 3:f2078081a779 | 42 | mems.clearIntFlag(); |
jurica238814 | 3:f2078081a779 | 43 | bleT.signal_set(ACC_INT_SIG); |
jurica238814 | 3:f2078081a779 | 44 | bleTicker.attach(disableBle, BLE_ACTIVE_TIME_S); |
jurica238814 | 3:f2078081a779 | 45 | disableI2C(); |
jurica238814 | 3:f2078081a779 | 46 | __enable_irq(); |
jurica238814 | 3:f2078081a779 | 47 | } |
jurica238814 | 3:f2078081a779 | 48 | |
jurica238814 | 3:f2078081a779 | 49 | |
jurica238814 | 3:f2078081a779 | 50 | void bleF(BLE *ble){ |
jurica238814 | 3:f2078081a779 | 51 | // Thread function for managing BLE radio |
jurica238814 | 3:f2078081a779 | 52 | // First wait for acc interrupt signal |
jurica238814 | 3:f2078081a779 | 53 | while(true){ |
jurica238814 | 3:f2078081a779 | 54 | Thread::signal_wait(ACC_INT_SIG); |
jurica238814 | 3:f2078081a779 | 55 | Thread::signal_clr(ACC_INT_SIG); |
jurica238814 | 3:f2078081a779 | 56 | ble->gap().startAdvertising(); |
jurica238814 | 3:f2078081a779 | 57 | #if DEBUG_LED |
jurica238814 | 3:f2078081a779 | 58 | redLed = 0; |
jurica238814 | 3:f2078081a779 | 59 | #endif |
jurica238814 | 3:f2078081a779 | 60 | Thread::signal_wait(DISABLE_BLE_SIG); |
jurica238814 | 3:f2078081a779 | 61 | Thread::signal_clr(DISABLE_BLE_SIG); |
jurica238814 | 3:f2078081a779 | 62 | ble->gap().stopAdvertising(); |
jurica238814 | 3:f2078081a779 | 63 | #if DEBUG_LED |
jurica238814 | 3:f2078081a779 | 64 | redLed = 1; |
jurica238814 | 3:f2078081a779 | 65 | #endif |
jurica238814 | 3:f2078081a779 | 66 | } |
jurica238814 | 3:f2078081a779 | 67 | } |
jurica238814 | 3:f2078081a779 | 68 | |
jurica238814 | 3:f2078081a779 | 69 | int main(){ |
jurica238814 | 3:f2078081a779 | 70 | redLed = 1; |
jurica238814 | 3:f2078081a779 | 71 | rgbLEDR = 1; |
jurica238814 | 3:f2078081a779 | 72 | rgbLEDG = 1; |
jurica238814 | 3:f2078081a779 | 73 | rgbLEDB = 1; |
jurica238814 | 3:f2078081a779 | 74 | AccVcc = 1; |
jurica238814 | 3:f2078081a779 | 75 | wait_ms(POWER_UP_DELAY_MS); |
jurica238814 | 3:f2078081a779 | 76 | |
jurica238814 | 3:f2078081a779 | 77 | INT1.rise(int1Handler); |
jurica238814 | 3:f2078081a779 | 78 | NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps |
jurica238814 | 3:f2078081a779 | 79 | |
jurica238814 | 3:f2078081a779 | 80 | BLE &ble = BLE::Instance(); |
jurica238814 | 3:f2078081a779 | 81 | ble.init(bleInitComplete); |
jurica238814 | 3:f2078081a779 | 82 | |
jurica238814 | 3:f2078081a779 | 83 | mems.setMode(LOW_POWER); |
jurica238814 | 3:f2078081a779 | 84 | |
jurica238814 | 3:f2078081a779 | 85 | mems.disableAxes(X_axis); |
jurica238814 | 3:f2078081a779 | 86 | mems.disableAxes(Y_axis); |
jurica238814 | 3:f2078081a779 | 87 | mems.enableAxes(Z_axis); |
jurica238814 | 3:f2078081a779 | 88 | mems.setODR(ODR_10Hz); |
jurica238814 | 3:f2078081a779 | 89 | mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad |
jurica238814 | 3:f2078081a779 | 90 | |
jurica238814 | 3:f2078081a779 | 91 | mems.int1Latch(0x01); // Enable int1 latch |
jurica238814 | 3:f2078081a779 | 92 | mems.int1Threshold(0x10); |
jurica238814 | 3:f2078081a779 | 93 | mems.int1Duration(0x00); |
jurica238814 | 3:f2078081a779 | 94 | mems.int1Config(0x20); // Enable XHigh and YHigh |
jurica238814 | 3:f2078081a779 | 95 | |
jurica238814 | 3:f2078081a779 | 96 | bleT.start(callback(bleF, &ble)); // Start bleT |
jurica238814 | 3:f2078081a779 | 97 | |
jurica238814 | 3:f2078081a779 | 98 | while(1){ |
jurica238814 | 3:f2078081a779 | 99 | disableI2C(); |
jurica238814 | 3:f2078081a779 | 100 | Thread::wait(0xFFFFFFFF); |
jurica238814 | 3:f2078081a779 | 101 | } |
jurica238814 | 3:f2078081a779 | 102 | } |