Edit
Dependencies: Lis2dh12 aconno_I2C aconno_nrf52_uart adc52832_common aconno_SEGGER_RTT
Diff: source/main.cpp
- Revision:
- 3:f2078081a779
- Child:
- 6:4a4e5dbc8e1e
- Child:
- 8:4b1ac4733b3d
diff -r e7952623d06c -r f2078081a779 source/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/main.cpp Tue Jan 16 17:24:31 2018 +0000 @@ -0,0 +1,102 @@ +/* + * aconno.de + * Made by Jurica Resetar + * All right reserved + * + */ + +#include "main.h" + +void printOnUart(){ + while(1){ + SEND("Uart works...\r\n"); + wait_ms(500); + } +} + +void disableI2C(){ + NRF_TWI0->ENABLE = 0; + NRF_TWI0->PSELSCL = 0xFFFFFFFF; + NRF_TWI1->ENABLE = 0; + NRF_TWI1->PSELSCL = 0xFFFFFFFF; + NRF_TWIM0->ENABLE = 0; + NRF_TWIM0->PSEL.SCL = 0x80000000; + NRF_TWIM0->PSEL.SDA = 0x80000000; + NRF_TWIM1->ENABLE = 0; + NRF_TWIM0->PSEL.SCL = 0x80000000; + NRF_TWIM0->PSEL.SDA = 0x80000000; + DigitalOut foo(I2C_DATA); + DigitalOut bar(I2C_CLK); + foo = 1; + bar = 1; +} + +void disableBle(){ + bleTicker.detach(); + bleT.signal_set(DISABLE_BLE_SIG); +} + +void int1Handler(){ + __disable_irq(); + I2C i2c(I2C_DATA,I2C_CLK); + mems.clearIntFlag(); + bleT.signal_set(ACC_INT_SIG); + bleTicker.attach(disableBle, BLE_ACTIVE_TIME_S); + disableI2C(); + __enable_irq(); +} + + +void bleF(BLE *ble){ + // Thread function for managing BLE radio + // First wait for acc interrupt signal + while(true){ + Thread::signal_wait(ACC_INT_SIG); + Thread::signal_clr(ACC_INT_SIG); + ble->gap().startAdvertising(); + #if DEBUG_LED + redLed = 0; + #endif + Thread::signal_wait(DISABLE_BLE_SIG); + Thread::signal_clr(DISABLE_BLE_SIG); + ble->gap().stopAdvertising(); + #if DEBUG_LED + redLed = 1; + #endif + } +} + +int main(){ + redLed = 1; + rgbLEDR = 1; + rgbLEDG = 1; + rgbLEDB = 1; + AccVcc = 1; + wait_ms(POWER_UP_DELAY_MS); + + INT1.rise(int1Handler); + NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps + + BLE &ble = BLE::Instance(); + ble.init(bleInitComplete); + + mems.setMode(LOW_POWER); + + mems.disableAxes(X_axis); + mems.disableAxes(Y_axis); + mems.enableAxes(Z_axis); + mems.setODR(ODR_10Hz); + mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad + + mems.int1Latch(0x01); // Enable int1 latch + mems.int1Threshold(0x10); + mems.int1Duration(0x00); + mems.int1Config(0x20); // Enable XHigh and YHigh + + bleT.start(callback(bleF, &ble)); // Start bleT + + while(1){ + disableI2C(); + Thread::wait(0xFFFFFFFF); + } +}