![](/media/cache/profiles/b5c4ec91390a6fbccf8d918d443563ed.jpg.50x50_q85.jpg)
Edit
Dependencies: Lis2dh12 aconno_I2C aconno_nrf52_uart adc52832_common aconno_SEGGER_RTT
source/main.h@13:7ae1c5bcccb5, 2018-03-02 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Mar 02 10:29:59 2018 +0000
- Branch:
- NanoModule
- Revision:
- 13:7ae1c5bcccb5
- Parent:
- 12:d5d47f848af5
This version works ok for DICE project. ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 3:f2078081a779 | 1 | /* |
jurica238814 | 3:f2078081a779 | 2 | * Made by Jurica Resetar @ aconno |
jurica238814 | 3:f2078081a779 | 3 | * More info @ aconno.de |
jurica238814 | 3:f2078081a779 | 4 | * |
jurica238814 | 3:f2078081a779 | 5 | */ |
jurica238814 | 3:f2078081a779 | 6 | |
jurica238814 | 3:f2078081a779 | 7 | #ifndef MAIN_H |
jurica238814 | 3:f2078081a779 | 8 | #define MAIN_H |
jurica238814 | 3:f2078081a779 | 9 | |
jurica238814 | 3:f2078081a779 | 10 | #include "mbed.h" |
jurica238814 | 3:f2078081a779 | 11 | #include "nrf52_uart.h" |
jurica238814 | 3:f2078081a779 | 12 | #include "Lis2dh12.h" |
jurica238814 | 3:f2078081a779 | 13 | #include "Lis2dh12_regs.h" |
jurica238814 | 3:f2078081a779 | 14 | #include "aconno_ble.h" |
jurica238814 | 3:f2078081a779 | 15 | #include "ble/BLE.h" |
jurica238814 | 3:f2078081a779 | 16 | #include "GapAdvertisingData.h" |
jurica238814 | 3:f2078081a779 | 17 | |
jurica238814 | 3:f2078081a779 | 18 | #define DEBUG (0) |
jurica238814 | 13:7ae1c5bcccb5 | 19 | #define PRINT_ON_RTT (0) |
jurica238814 | 13:7ae1c5bcccb5 | 20 | #define DEBUG_LED (0) |
jurica238814 | 12:d5d47f848af5 | 21 | #define NANO_MODULE (1) |
jurica238814 | 13:7ae1c5bcccb5 | 22 | #define LSB_VALUE (192) |
jurica238814 | 10:83dab6cc625d | 23 | |
jurica238814 | 10:83dab6cc625d | 24 | #if NANO_MODULE |
jurica238814 | 10:83dab6cc625d | 25 | #define I2C_DATA (p2) |
jurica238814 | 10:83dab6cc625d | 26 | #define I2C_CLK (p3) |
jurica238814 | 10:83dab6cc625d | 27 | #define INT_PIN1 (p10) |
jurica238814 | 10:83dab6cc625d | 28 | #define INT_PIN2 (p9) |
jurica238814 | 10:83dab6cc625d | 29 | #define ACC_POWER_PIN (p13) |
jurica238814 | 10:83dab6cc625d | 30 | #define RED_LED_PIN (p12) |
jurica238814 | 10:83dab6cc625d | 31 | #else |
jurica238814 | 10:83dab6cc625d | 32 | #define I2C_DATA (p20) |
jurica238814 | 10:83dab6cc625d | 33 | #define I2C_CLK (p17) |
jurica238814 | 10:83dab6cc625d | 34 | #define INT_PIN1 (p16) |
jurica238814 | 10:83dab6cc625d | 35 | #define INT_PIN2 (p15) |
jurica238814 | 10:83dab6cc625d | 36 | #define ACC_POWER_PIN (p11) |
jurica238814 | 10:83dab6cc625d | 37 | #define RED_LED_PIN (p22) |
jurica238814 | 10:83dab6cc625d | 38 | #endif |
jurica238814 | 10:83dab6cc625d | 39 | |
jurica238814 | 13:7ae1c5bcccb5 | 40 | #define BLE_ACTIVE_TIME_S (0.4) |
jurica238814 | 3:f2078081a779 | 41 | #define POWER_UP_DELAY_MS (200) |
jurica238814 | 3:f2078081a779 | 42 | |
jurica238814 | 10:83dab6cc625d | 43 | #if PRINT_ON_RTT |
jurica238814 | 10:83dab6cc625d | 44 | #include "SEGGER_RTT.h" |
jurica238814 | 10:83dab6cc625d | 45 | #define printf(...) SEGGER_RTT_printf(0, __VA_ARGS__) |
jurica238814 | 10:83dab6cc625d | 46 | #else |
jurica238814 | 10:83dab6cc625d | 47 | #define printf(...) |
jurica238814 | 10:83dab6cc625d | 48 | #endif |
jurica238814 | 10:83dab6cc625d | 49 | |
jurica238814 | 13:7ae1c5bcccb5 | 50 | #define INT1_THRESHOLD (20u) |
jurica238814 | 10:83dab6cc625d | 51 | #define INT1_DUR (0x00) |
jurica238814 | 9:a9c5db477f35 | 52 | |
jurica238814 | 3:f2078081a779 | 53 | #define ACC_INT_SIG (0x00001020) // Acc interrupt signal |
jurica238814 | 3:f2078081a779 | 54 | #define DISABLE_BLE_SIG (0x00001030) |
jurica238814 | 3:f2078081a779 | 55 | |
jurica238814 | 3:f2078081a779 | 56 | #if DEBUG |
jurica238814 | 3:f2078081a779 | 57 | NRF52_UART uart(p12, p14, Baud9600); |
jurica238814 | 3:f2078081a779 | 58 | char buffer[255]; |
jurica238814 | 3:f2078081a779 | 59 | #define SEND(...) {uint8_t len = sprintf(buffer, __VA_ARGS__); uartM.lock(); uart.send(buffer, len); uartM.unlock();} |
jurica238814 | 3:f2078081a779 | 60 | #else |
jurica238814 | 3:f2078081a779 | 61 | #define SEND(...) |
jurica238814 | 3:f2078081a779 | 62 | #endif |
jurica238814 | 3:f2078081a779 | 63 | |
jurica238814 | 3:f2078081a779 | 64 | char memsI2CAddress = I2C_ADDRESS; |
jurica238814 | 3:f2078081a779 | 65 | Mutex uartM; |
jurica238814 | 3:f2078081a779 | 66 | Thread uartT; |
jurica238814 | 3:f2078081a779 | 67 | Thread bleT; |
jurica238814 | 10:83dab6cc625d | 68 | Thread measureT; |
jurica238814 | 3:f2078081a779 | 69 | |
jurica238814 | 10:83dab6cc625d | 70 | DigitalOut AccVcc(ACC_POWER_PIN); |
jurica238814 | 10:83dab6cc625d | 71 | DigitalOut redLed(RED_LED_PIN); |
jurica238814 | 3:f2078081a779 | 72 | InterruptIn INT1(INT_PIN1); |
jurica238814 | 3:f2078081a779 | 73 | //InterruptIn INT2(INT_PIN2); |
jurica238814 | 3:f2078081a779 | 74 | I2C i2c(I2C_DATA,I2C_CLK); |
jurica238814 | 3:f2078081a779 | 75 | Lis2dh12 mems(&i2c, memsI2CAddress); |
jurica238814 | 3:f2078081a779 | 76 | Ticker bleTicker; |
jurica238814 | 3:f2078081a779 | 77 | |
jurica238814 | 3:f2078081a779 | 78 | #endif |