Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
source/main.cpp@4:49b1aeca55e4, 2018-03-09 (annotated)
- Committer:
- dbartolovic
- Date:
- Fri Mar 09 17:05:05 2018 +0000
- Revision:
- 4:49b1aeca55e4
- Parent:
- 3:38eadab20283
- Parent:
- 2:41a1cdac47a7
- Child:
- 5:9903738f2587
Changed full scale to 2g
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" |
jurica238814 | 0:fc77522f4d28 | 9 | |
jurica238814 | 0:fc77522f4d28 | 10 | static advertising_packet advertisementPacket; |
jurica238814 | 0:fc77522f4d28 | 11 | static GapAdvertisingData adv_data = GapAdvertisingData(); |
jurica238814 | 0:fc77522f4d28 | 12 | |
jurica238814 | 0:fc77522f4d28 | 13 | void disableI2C(){ |
jurica238814 | 0:fc77522f4d28 | 14 | NRF_TWI0->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 15 | NRF_TWI0->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 0:fc77522f4d28 | 16 | NRF_TWI1->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 17 | NRF_TWI1->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 0:fc77522f4d28 | 18 | NRF_TWIM0->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 19 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 20 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 21 | NRF_TWIM1->ENABLE = 0; |
jurica238814 | 0:fc77522f4d28 | 22 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 23 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 0:fc77522f4d28 | 24 | DigitalOut foo(I2C_DATA); |
jurica238814 | 0:fc77522f4d28 | 25 | DigitalOut bar(I2C_CLK); |
jurica238814 | 0:fc77522f4d28 | 26 | foo = 1; |
jurica238814 | 0:fc77522f4d28 | 27 | bar = 1; |
jurica238814 | 0:fc77522f4d28 | 28 | } |
jurica238814 | 0:fc77522f4d28 | 29 | |
jurica238814 | 0:fc77522f4d28 | 30 | void bleF(BLE *ble) |
jurica238814 | 0:fc77522f4d28 | 31 | { |
jurica238814 | 0:fc77522f4d28 | 32 | while(true) |
jurica238814 | 0:fc77522f4d28 | 33 | { |
jurica238814 | 0:fc77522f4d28 | 34 | |
jurica238814 | 0:fc77522f4d28 | 35 | advertisementPacket.header = APPLICATION_ID; |
jurica238814 | 0:fc77522f4d28 | 36 | advertisementPacket.type = 0x00; |
jurica238814 | 0:fc77522f4d28 | 37 | advertisementPacket.gyroscope[0] = (int16_t)0; |
jurica238814 | 0:fc77522f4d28 | 38 | advertisementPacket.gyroscope[1] = (int16_t)0; |
jurica238814 | 0:fc77522f4d28 | 39 | advertisementPacket.gyroscope[2] = (int16_t)0; |
jurica238814 | 0:fc77522f4d28 | 40 | advertisementPacket.magnetometer[0] = (int16_t)0; |
jurica238814 | 0:fc77522f4d28 | 41 | advertisementPacket.magnetometer[1] = (int16_t)0; |
jurica238814 | 0:fc77522f4d28 | 42 | advertisementPacket.magnetometer[2] = (int16_t)0; |
jurica238814 | 0:fc77522f4d28 | 43 | |
dbartolovic | 1:198b9945994e | 44 | |
dbartolovic | 3:38eadab20283 | 45 | advertisementPacket.accelerometer[0] = (int16_t)mems.readXAxis()*LSB_VALUE; |
dbartolovic | 3:38eadab20283 | 46 | advertisementPacket.accelerometer[1] = (int16_t)mems.readYAxis()*LSB_VALUE; |
dbartolovic | 3:38eadab20283 | 47 | advertisementPacket.accelerometer[2] = (int16_t)mems.readZAxis()*LSB_VALUE; |
dbartolovic | 3:38eadab20283 | 48 | |
dbartolovic | 3:38eadab20283 | 49 | //advertisementPacket.acc_lsb_value = 0xC000; |
dbartolovic | 3:38eadab20283 | 50 | advertisementPacket.acc_lsb_value = 0x1000; |
dbartolovic | 1:198b9945994e | 51 | |
dbartolovic | 1:198b9945994e | 52 | |
dbartolovic | 3:38eadab20283 | 53 | printf("%6d\t", advertisementPacket.accelerometer[0]); |
dbartolovic | 3:38eadab20283 | 54 | printf("%6d\t", advertisementPacket.accelerometer[1]); |
dbartolovic | 3:38eadab20283 | 55 | printf("%6d\r\n", advertisementPacket.accelerometer[2]); |
dbartolovic | 1:198b9945994e | 56 | |
jurica238814 | 0:fc77522f4d28 | 57 | //updatePayload(ble, &advertisementPacket); |
jurica238814 | 0:fc77522f4d28 | 58 | |
jurica238814 | 0:fc77522f4d28 | 59 | /* setup advertising */ |
jurica238814 | 0:fc77522f4d28 | 60 | |
jurica238814 | 0:fc77522f4d28 | 61 | |
jurica238814 | 0:fc77522f4d28 | 62 | /* |
jurica238814 | 0:fc77522f4d28 | 63 | GapAdvertisingData advetisementData = GapAdvertisingData(); |
jurica238814 | 0:fc77522f4d28 | 64 | advetisementData = ble->getAdvertisingData(); |
jurica238814 | 0:fc77522f4d28 | 65 | advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet)); |
jurica238814 | 0:fc77522f4d28 | 66 | ble->setAdvertisingData(advetisementData); |
jurica238814 | 0:fc77522f4d28 | 67 | */ |
jurica238814 | 0:fc77522f4d28 | 68 | adv_data = ble->getAdvertisingData(); |
jurica238814 | 0:fc77522f4d28 | 69 | adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket)); |
jurica238814 | 0:fc77522f4d28 | 70 | ble->setAdvertisingData(adv_data); |
jurica238814 | 0:fc77522f4d28 | 71 | |
jurica238814 | 0:fc77522f4d28 | 72 | |
jurica238814 | 0:fc77522f4d28 | 73 | //printf("Ble advertisement is ON.\r\n"); |
jurica238814 | 0:fc77522f4d28 | 74 | |
jurica238814 | 0:fc77522f4d28 | 75 | #if DEBUG_LED |
jurica238814 | 0:fc77522f4d28 | 76 | redLed = 0; |
jurica238814 | 0:fc77522f4d28 | 77 | #endif |
jurica238814 | 0:fc77522f4d28 | 78 | ble->gap().startAdvertising(); |
jurica238814 | 0:fc77522f4d28 | 79 | wait_ms(1000); |
jurica238814 | 0:fc77522f4d28 | 80 | |
jurica238814 | 0:fc77522f4d28 | 81 | //wait_ms(MEASURE_INTERVAL_MS); |
jurica238814 | 0:fc77522f4d28 | 82 | //wait_ms(1000); |
jurica238814 | 0:fc77522f4d28 | 83 | |
jurica238814 | 0:fc77522f4d28 | 84 | //printf("Ble advertisement is OFF.\r\n\r\n"); |
jurica238814 | 0:fc77522f4d28 | 85 | #if DEBUG_LED |
jurica238814 | 0:fc77522f4d28 | 86 | redLed = 1; |
jurica238814 | 0:fc77522f4d28 | 87 | #endif |
dbartolovic | 1:198b9945994e | 88 | //ble->gap().stopAdvertising(); |
jurica238814 | 0:fc77522f4d28 | 89 | /* |
jurica238814 | 0:fc77522f4d28 | 90 | GapAdvertisingData advetisementData = GapAdvertisingData(); |
jurica238814 | 0:fc77522f4d28 | 91 | advetisementData = ble->getAdvertisingData(); |
jurica238814 | 0:fc77522f4d28 | 92 | advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet)); |
jurica238814 | 0:fc77522f4d28 | 93 | ble->setAdvertisingData(advetisementData); |
jurica238814 | 0:fc77522f4d28 | 94 | */ |
jurica238814 | 0:fc77522f4d28 | 95 | wait_ms(1000); |
jurica238814 | 0:fc77522f4d28 | 96 | } |
jurica238814 | 0:fc77522f4d28 | 97 | } |
jurica238814 | 0:fc77522f4d28 | 98 | |
jurica238814 | 0:fc77522f4d28 | 99 | |
jurica238814 | 0:fc77522f4d28 | 100 | int main(){ |
jurica238814 | 0:fc77522f4d28 | 101 | |
jurica238814 | 0:fc77522f4d28 | 102 | printf("Main program started.\r\n"); |
jurica238814 | 0:fc77522f4d28 | 103 | |
jurica238814 | 0:fc77522f4d28 | 104 | NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR |
jurica238814 | 0:fc77522f4d28 | 105 | NRF_NVMC->ERASEUICR = 0x00000001; // Erase all |
jurica238814 | 0:fc77522f4d28 | 106 | NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR |
jurica238814 | 0:fc77522f4d28 | 107 | NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function |
jurica238814 | 0:fc77522f4d28 | 108 | |
jurica238814 | 0:fc77522f4d28 | 109 | redLed = 1; |
jurica238814 | 0:fc77522f4d28 | 110 | AccVcc = 1; |
jurica238814 | 0:fc77522f4d28 | 111 | wait_ms(POWER_UP_DELAY_MS); |
jurica238814 | 0:fc77522f4d28 | 112 | |
jurica238814 | 0:fc77522f4d28 | 113 | /* |
jurica238814 | 0:fc77522f4d28 | 114 | INT1.rise(int1Handler); |
jurica238814 | 0:fc77522f4d28 | 115 | NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps |
jurica238814 | 0:fc77522f4d28 | 116 | */ |
jurica238814 | 0:fc77522f4d28 | 117 | |
jurica238814 | 0:fc77522f4d28 | 118 | BLE &ble = BLE::Instance(); |
jurica238814 | 0:fc77522f4d28 | 119 | ble.init(bleInitComplete); |
jurica238814 | 0:fc77522f4d28 | 120 | |
jurica238814 | 0:fc77522f4d28 | 121 | mems.setMode(LOW_POWER); |
dbartolovic | 3:38eadab20283 | 122 | //mems.setMode(HIGH_RES); |
jurica238814 | 0:fc77522f4d28 | 123 | mems.enableAxes(X_axis); |
jurica238814 | 0:fc77522f4d28 | 124 | mems.enableAxes(Y_axis); |
jurica238814 | 0:fc77522f4d28 | 125 | mems.enableAxes(Z_axis); |
jurica238814 | 0:fc77522f4d28 | 126 | mems.setODR(ODR_50Hz); |
dbartolovic | 3:38eadab20283 | 127 | //mems.setScale(_16g); |
dbartolovic | 3:38eadab20283 | 128 | mems.setScale(_2g); |
jurica238814 | 0:fc77522f4d28 | 129 | mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad |
jurica238814 | 0:fc77522f4d28 | 130 | mems.int1Latch(0x01); // Enable int1 latch |
jurica238814 | 0:fc77522f4d28 | 131 | mems.int1Threshold(INT1_THRESHOLD); |
jurica238814 | 0:fc77522f4d28 | 132 | mems.int1Duration(INT1_DUR); |
jurica238814 | 0:fc77522f4d28 | 133 | mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh |
jurica238814 | 0:fc77522f4d28 | 134 | |
jurica238814 | 0:fc77522f4d28 | 135 | bleT.start(callback(bleF, &ble)); // Start bleT |
jurica238814 | 0:fc77522f4d28 | 136 | |
jurica238814 | 0:fc77522f4d28 | 137 | |
jurica238814 | 0:fc77522f4d28 | 138 | while(1){ |
jurica238814 | 0:fc77522f4d28 | 139 | //disableI2C(); |
jurica238814 | 0:fc77522f4d28 | 140 | Thread::wait(0xFFFFFFFF); |
jurica238814 | 0:fc77522f4d28 | 141 | } |
jurica238814 | 0:fc77522f4d28 | 142 | } |