Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

source/main.cpp

Committer:
dbartolovic
Date:
2018-03-20
Revision:
8:7ba4f82de9b6
Parent:
7:ac8277568115
Child:
14:65734075c8d3
Child:
19:2681edc2f2b9

File content as of revision 8:7ba4f82de9b6:

/* 
 * aconno.de
 * Made by Jurica Resetar
 * All right reserved 
 *
 */

#include "main.h"
#include "bsp.h"
#include "tasks.h"


char memsI2CAddress = I2C_ADDRESS;
Mutex uartM;
Thread uartT;
Thread bleT;
Thread measureT;
Thread updateServiceT;
Thread updateBuzzLedsT;

DigitalOut AccVcc(ACC_POWER_PIN);
InterruptIn INT1(INT_PIN1);
//InterruptIn INT2(INT_PIN2);
I2C i2c(I2C_DATA,I2C_CLK);
Ticker bleTicker;


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;
}

int main(){
    Lis2dh12 mems(&i2c, memsI2CAddress);
    
    tasks_init();
    
    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
    
    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.setMode(HIGH_RES);
    mems.enableAxes(X_axis);
    mems.enableAxes(Y_axis);
    mems.enableAxes(Z_axis);    
    mems.setODR(ODR_50Hz);
    //mems.setScale(_16g);
    mems.setScale(_2g);
    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
    measureT.start(callback(measureF, &mems));
    updateServiceT.start(updateServiceF);
    updateBuzzLedsT.start(updateBuzzLedsF);
    
    
    while(1){
        //disableI2C();
        ble.waitForEvent();
    }
}