Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Files at this revision

API Documentation at this revision

Comitter:
jurica238814
Date:
Wed Mar 07 13:40:28 2018 +0000
Child:
1:198b9945994e
Commit message:
Init commit.

Changed in this revision

Lis2dh12.lib Show annotated file Show diff for this revision Revisions of this file
SEGGER_RTT.lib Show annotated file Show diff for this revision Revisions of this file
aconno_I2C.lib Show annotated file Show diff for this revision Revisions of this file
aconno_ble/aconno_ble.cpp Show annotated file Show diff for this revision Revisions of this file
aconno_ble/aconno_ble.h Show annotated file Show diff for this revision Revisions of this file
adc52832_common.lib Show annotated file Show diff for this revision Revisions of this file
config/mbed_app.json Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
source/main.cpp Show annotated file Show diff for this revision Revisions of this file
source/main.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lis2dh12.lib	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/jurica238814/code/Lis2dh12/#043396f22548
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SEGGER_RTT.lib	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/jurica238814/code/aconno_SEGGER_RTT/#e61e7fc7cfe1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_I2C.lib	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/jurica238814/code/aconno_I2C/#3c0eab894a4b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_ble/aconno_ble.cpp	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,55 @@
+/*
+ *   Made by Jurica Resetar @ aconno
+ *   More info @ aconno.de
+ *
+ */
+
+#include "aconno_ble.h"
+
+/**
+* Callback triggered when the ble initialization process has finished
+*/
+
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+    advertising_packet advertisementPacket;
+    BLE&        ble   = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        return;
+    }
+
+    /* Ensure that it is the default instance of BLE */
+    if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+        return;
+    }
+    
+    advertisementPacket.header = APPLICATION_ID;
+    advertisementPacket.type = 0x00;
+    advertisementPacket.gyroscope[0] = (int16_t)0;
+    advertisementPacket.gyroscope[1] = (int16_t)0;
+    advertisementPacket.gyroscope[2] = (int16_t)0;
+    advertisementPacket.accelerometer[0] = (int16_t)0;
+    advertisementPacket.accelerometer[1] = (int16_t)0;
+    advertisementPacket.accelerometer[2] = (int16_t)0;
+    advertisementPacket.magnetometer[0] = (int16_t)0;
+    advertisementPacket.magnetometer[1] = (int16_t)0;
+    advertisementPacket.magnetometer[2] = (int16_t)0;
+    
+    /* setup advertising */
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(uint8_t)*11);
+    ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS);
+    ble.gap().startAdvertising();
+}
+
+void updatePayload(BLE *ble, advertising_packet *advertisementPacket)
+{
+    ble->gap().stopAdvertising();
+    GapAdvertisingData advetisementData = GapAdvertisingData();
+    advetisementData = ble->getAdvertisingData();
+    advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)advertisementPacket, sizeof(advertising_packet));
+    ble->setAdvertisingData(advetisementData);
+    //ble->gap().startAdvertising();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_ble/aconno_ble.h	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,44 @@
+/*
+*  Made by Jurica Resetar @ aconno
+*  More info @ aconno.de
+*  jurica_resetar@yahoo.com
+*/
+
+#ifndef ACONNO_BLE_H
+#define ACONNO_BLE_H
+
+#include "mbed.h"
+#include "ble/BLE.h"
+#include "GapAdvertisingData.h"
+
+#define MSD_SIZE_b          (10)
+#define ADV_INTERVAL_MS     (100)
+#define APPLICATION_ID      (0xFFFF0059) //(0xCF170059)
+
+/* Global variables and constants */
+
+struct __attribute__((packed, aligned(1))) advertising_packet{
+    uint32_t header;
+    uint8_t  type;
+    union{
+        struct{
+            int16_t gyroscope[3];
+            int16_t accelerometer[3];
+            int16_t magnetometer[3];
+        };
+        struct{
+            float temperature;
+            float humidity;
+            float pressure;
+            float light;
+            uint8_t battery;
+        };
+    };
+};
+
+/* Function declarations */
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params);
+void updatePayload(BLE *ble, advertising_packet *advertisementPacket);
+
+
+#endif      //ACONNO_BLE_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/adc52832_common.lib	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/aconno-dev-team/code/adc52832_common/#5bc25386a9fd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/mbed_app.json	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,7 @@
+{
+    "target_overrides": {
+        "NRF52_DK": {
+            "target.uart_hwfc": 0
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#5f6572179d66ce4c09d6517b659ac51133cc980d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/main.cpp	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,133 @@
+/* 
+ * aconno.de
+ * Made by Jurica Resetar
+ * All right reserved 
+ *
+ */
+
+#include "main.h"
+
+static advertising_packet advertisementPacket;
+static GapAdvertisingData adv_data = GapAdvertisingData();
+
+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 bleF(BLE *ble)
+{
+    while(true)
+    {
+
+        advertisementPacket.header = APPLICATION_ID;
+        advertisementPacket.type = 0x00;
+        advertisementPacket.gyroscope[0] = (int16_t)0;
+        advertisementPacket.gyroscope[1] = (int16_t)0;
+        advertisementPacket.gyroscope[2] = (int16_t)0;
+        advertisementPacket.magnetometer[0] = (int16_t)0;
+        advertisementPacket.magnetometer[1] = (int16_t)0;
+        advertisementPacket.magnetometer[2] = (int16_t)0;
+        
+        /*
+        advertisementPacket.accelerometer[0] = (int16_t)mems.readXAxis()*LSB_VALUE;
+        advertisementPacket.accelerometer[1] = (int16_t)mems.readYAxis()*LSB_VALUE;
+        advertisementPacket.accelerometer[2] = (int16_t)mems.readZAxis()*LSB_VALUE;    
+        */
+        //advertisementPacket.accelerometer[2] = 0x2323;
+        //updatePayload(ble, &advertisementPacket);
+        
+        /* setup advertising */
+        
+        
+        /*
+        GapAdvertisingData advetisementData = GapAdvertisingData();
+        advetisementData = ble->getAdvertisingData();
+        advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
+        ble->setAdvertisingData(advetisementData);
+        */
+        adv_data = ble->getAdvertisingData();
+        adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
+        ble->setAdvertisingData(adv_data);
+        
+        
+        //printf("Ble advertisement is ON.\r\n");
+        
+        #if DEBUG_LED
+            redLed = 0;
+        #endif
+        ble->gap().startAdvertising();
+        wait_ms(1000);
+        
+        //wait_ms(MEASURE_INTERVAL_MS);
+        //wait_ms(1000);
+        
+        //printf("Ble advertisement is OFF.\r\n\r\n");
+        #if DEBUG_LED
+            redLed = 1;
+        #endif
+        ble->gap().stopAdvertising();
+        /*
+        GapAdvertisingData advetisementData = GapAdvertisingData();
+        advetisementData = ble->getAdvertisingData();
+        advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
+        ble->setAdvertisingData(advetisementData);
+        */
+        wait_ms(1000);
+    }
+}
+
+
+int main(){
+    
+    printf("Main program started.\r\n");
+    
+    NRF_NVMC->CONFIG = 0x00000002;      // Erase enable UICR
+    NRF_NVMC->ERASEUICR = 0x00000001;   // Erase all
+    NRF_NVMC->CONFIG = 0x00000001;      // Write enable UICR
+    NRF_UICR->NFCPINS = 0xFFFFFFFE;     // Change NFC to GPIO function
+    
+    redLed = 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.enableAxes(X_axis);
+    mems.enableAxes(Y_axis);
+    mems.enableAxes(Z_axis);    
+    mems.setODR(ODR_50Hz);
+    mems.setScale(_16g);
+    mems.int1Setup(0x40);       // IntActivity 1 driven to INT1 pad
+    mems.int1Latch(0x01);       // Enable int1 latch
+    mems.int1Threshold(INT1_THRESHOLD); 
+    mems.int1Duration(INT1_DUR);            
+    mems.int1Config(0x2A);      // Enable XHigh, YHigh and ZHigh
+    
+    bleT.start(callback(bleF, &ble));   // Start bleT
+    
+    
+    while(1){
+        //disableI2C();
+        Thread::wait(0xFFFFFFFF);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/main.h	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,78 @@
+/*
+ *   Made by Jurica Resetar @ aconno
+ *   More info @ aconno.de
+ *
+ */
+
+#ifndef MAIN_H
+#define MAIN_H
+ 
+#include "mbed.h"
+#include "Lis2dh12.h"
+#include "Lis2dh12_regs.h"
+#include "aconno_ble.h"
+#include "ble/BLE.h"
+#include "GapAdvertisingData.h"
+
+#define DEBUG               (0)
+#define PRINT_ON_RTT        (0)
+#define DEBUG_LED           (1)
+#define NANO_MODULE         (0)
+#define LSB_VALUE           (192)
+
+#if NANO_MODULE
+    #define I2C_DATA            (p2)
+    #define I2C_CLK             (p3)
+    #define INT_PIN1            (p10)
+    #define INT_PIN2            (p9)
+    #define ACC_POWER_PIN       (p13)
+    #define RED_LED_PIN         (p12)
+#else
+    #define I2C_DATA            (p20)
+    #define I2C_CLK             (p17)
+    #define INT_PIN1            (p16)
+    #define INT_PIN2            (p15)
+    #define ACC_POWER_PIN       (p11)
+    #define RED_LED_PIN         (p22)
+#endif
+
+#define BLE_ACTIVE_TIME_S   (0.4)
+#define POWER_UP_DELAY_MS   (200)
+#define MEASURE_INTERVAL_MS (250)
+
+#if PRINT_ON_RTT
+    #include "SEGGER_RTT.h"
+    #define printf(...)                      SEGGER_RTT_printf(0, __VA_ARGS__)
+#else
+    #define printf(...)
+#endif
+
+#define INT1_THRESHOLD      (20u)
+#define INT1_DUR            (0x00)
+    
+#define ACC_INT_SIG         (0x00001020)    // Acc interrupt signal
+#define DISABLE_BLE_SIG     (0x00001030)
+
+#if DEBUG
+    NRF52_UART uart(p12, p14, Baud9600);
+    char buffer[255];
+    #define SEND(...) {uint8_t len = sprintf(buffer, __VA_ARGS__); uartM.lock(); uart.send(buffer, len); uartM.unlock();}
+#else
+    #define SEND(...)
+#endif
+
+char memsI2CAddress = I2C_ADDRESS;
+Mutex uartM;
+Thread uartT;
+Thread bleT;
+Thread measureT;
+
+DigitalOut AccVcc(ACC_POWER_PIN);
+DigitalOut redLed(RED_LED_PIN);
+InterruptIn INT1(INT_PIN1);
+//InterruptIn INT2(INT_PIN2);
+I2C i2c(I2C_DATA,I2C_CLK);
+Lis2dh12 mems(&i2c, memsI2CAddress);
+Ticker bleTicker;
+
+#endif