Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
dbartolovic
Date:
Wed Mar 14 08:48:26 2018 +0000
Revision:
7:ac8277568115
Parent:
6:55607d577a42
Child:
8:7ba4f82de9b6
Added small LED and buzzer test.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:fc77522f4d28 1 /*
jurica238814 0:fc77522f4d28 2 * Made by Jurica Resetar @ aconno
jurica238814 0:fc77522f4d28 3 * More info @ aconno.de
jurica238814 0:fc77522f4d28 4 *
jurica238814 0:fc77522f4d28 5 */
jurica238814 0:fc77522f4d28 6
jurica238814 0:fc77522f4d28 7 #ifndef MAIN_H
jurica238814 0:fc77522f4d28 8 #define MAIN_H
jurica238814 0:fc77522f4d28 9
jurica238814 0:fc77522f4d28 10 #include "mbed.h"
jurica238814 0:fc77522f4d28 11 #include "Lis2dh12.h"
jurica238814 0:fc77522f4d28 12 #include "Lis2dh12_regs.h"
jurica238814 0:fc77522f4d28 13 #include "aconno_ble.h"
jurica238814 0:fc77522f4d28 14 #include "ble/BLE.h"
jurica238814 0:fc77522f4d28 15 #include "GapAdvertisingData.h"
dbartolovic 6:55607d577a42 16 #include "acd52832_bsp.h"
dbartolovic 6:55607d577a42 17 #include "acn_nrf52_pwm.h"
jurica238814 0:fc77522f4d28 18
jurica238814 0:fc77522f4d28 19 #define DEBUG (0)
dbartolovic 5:9903738f2587 20 #define PRINT_ON_RTT (1)
dbartolovic 6:55607d577a42 21 #define DEBUG_LED (0)
jurica238814 0:fc77522f4d28 22 #define NANO_MODULE (0)
dbartolovic 3:38eadab20283 23 //#define LSB_VALUE (192)
dbartolovic 5:9903738f2587 24 #define LSB_VALUE (1)
jurica238814 0:fc77522f4d28 25
jurica238814 0:fc77522f4d28 26 #if NANO_MODULE
jurica238814 0:fc77522f4d28 27 #define I2C_DATA (p2)
jurica238814 0:fc77522f4d28 28 #define I2C_CLK (p3)
jurica238814 0:fc77522f4d28 29 #define INT_PIN1 (p10)
jurica238814 0:fc77522f4d28 30 #define INT_PIN2 (p9)
jurica238814 0:fc77522f4d28 31 #define ACC_POWER_PIN (p13)
jurica238814 0:fc77522f4d28 32 #define RED_LED_PIN (p12)
jurica238814 0:fc77522f4d28 33 #else
jurica238814 0:fc77522f4d28 34 #define I2C_DATA (p20)
jurica238814 0:fc77522f4d28 35 #define I2C_CLK (p17)
jurica238814 0:fc77522f4d28 36 #define INT_PIN1 (p16)
jurica238814 0:fc77522f4d28 37 #define INT_PIN2 (p15)
jurica238814 0:fc77522f4d28 38 #define ACC_POWER_PIN (p11)
dbartolovic 7:ac8277568115 39 #define RED_LED_PIN (p31) //p22
dbartolovic 7:ac8277568115 40 #define GREEN_LED_PIN (p2)
dbartolovic 7:ac8277568115 41 #define BLUE_LED_PIN (p3)
dbartolovic 6:55607d577a42 42 #define BUZZER_PIN (p18)
jurica238814 0:fc77522f4d28 43 #endif
jurica238814 0:fc77522f4d28 44
jurica238814 0:fc77522f4d28 45 #define BLE_ACTIVE_TIME_S (0.4)
jurica238814 0:fc77522f4d28 46 #define POWER_UP_DELAY_MS (200)
dbartolovic 5:9903738f2587 47 #define MEASURE_INTERVAL_MS (100)
jurica238814 0:fc77522f4d28 48
dbartolovic 6:55607d577a42 49
dbartolovic 6:55607d577a42 50 #define BUZZER_FREQUENCY_HZ (4000)
dbartolovic 6:55607d577a42 51 #define BUZZ_TIME_S (2) /* Buzz time in s */
dbartolovic 6:55607d577a42 52
jurica238814 0:fc77522f4d28 53 #if PRINT_ON_RTT
jurica238814 0:fc77522f4d28 54 #include "SEGGER_RTT.h"
jurica238814 0:fc77522f4d28 55 #define printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)
jurica238814 0:fc77522f4d28 56 #else
jurica238814 0:fc77522f4d28 57 #define printf(...)
jurica238814 0:fc77522f4d28 58 #endif
jurica238814 0:fc77522f4d28 59
jurica238814 0:fc77522f4d28 60 #define INT1_THRESHOLD (20u)
jurica238814 0:fc77522f4d28 61 #define INT1_DUR (0x00)
jurica238814 0:fc77522f4d28 62
jurica238814 0:fc77522f4d28 63 #define ACC_INT_SIG (0x00001020) // Acc interrupt signal
jurica238814 0:fc77522f4d28 64 #define DISABLE_BLE_SIG (0x00001030)
jurica238814 0:fc77522f4d28 65
jurica238814 0:fc77522f4d28 66 #if DEBUG
jurica238814 0:fc77522f4d28 67 NRF52_UART uart(p12, p14, Baud9600);
jurica238814 0:fc77522f4d28 68 char buffer[255];
jurica238814 0:fc77522f4d28 69 #define SEND(...) {uint8_t len = sprintf(buffer, __VA_ARGS__); uartM.lock(); uart.send(buffer, len); uartM.unlock();}
jurica238814 0:fc77522f4d28 70 #else
jurica238814 0:fc77522f4d28 71 #define SEND(...)
jurica238814 0:fc77522f4d28 72 #endif
jurica238814 0:fc77522f4d28 73
jurica238814 0:fc77522f4d28 74 char memsI2CAddress = I2C_ADDRESS;
jurica238814 0:fc77522f4d28 75 Mutex uartM;
jurica238814 0:fc77522f4d28 76 Thread uartT;
jurica238814 0:fc77522f4d28 77 Thread bleT;
jurica238814 0:fc77522f4d28 78 Thread measureT;
jurica238814 0:fc77522f4d28 79
jurica238814 0:fc77522f4d28 80 DigitalOut AccVcc(ACC_POWER_PIN);
jurica238814 0:fc77522f4d28 81 DigitalOut redLed(RED_LED_PIN);
dbartolovic 6:55607d577a42 82 #if NANO_MODULE == 0
dbartolovic 7:ac8277568115 83 DigitalOut greenLed(GREEN_LED_PIN);
dbartolovic 7:ac8277568115 84 DigitalOut blueLed(BLUE_LED_PIN);
dbartolovic 6:55607d577a42 85 #endif
jurica238814 0:fc77522f4d28 86 InterruptIn INT1(INT_PIN1);
jurica238814 0:fc77522f4d28 87 //InterruptIn INT2(INT_PIN2);
jurica238814 0:fc77522f4d28 88 I2C i2c(I2C_DATA,I2C_CLK);
jurica238814 0:fc77522f4d28 89 Lis2dh12 mems(&i2c, memsI2CAddress);
jurica238814 0:fc77522f4d28 90 Ticker bleTicker;
dbartolovic 6:55607d577a42 91 Ticker test_ticker;
dbartolovic 6:55607d577a42 92
dbartolovic 6:55607d577a42 93 NRF52_PWM buzzer(NRF_PWM2);
jurica238814 0:fc77522f4d28 94
jurica238814 0:fc77522f4d28 95 #endif