Long Range / Mbed 2 deprecated SX1272_LoRaWAN_App_LR

Dependencies:   X_NUCLEO_IKS01A2 driver_mbed_TH02 mbed LoRaWAN-lib-v1_0_1 SX1272Lib

Fork of Training-Aug2018-SX1272-X-NUCLEO-IKS01A2 by Uttam Bhat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers board.cpp Source File

board.cpp

00001 /*
00002  / _____)             _              | |
00003 ( (____  _____ ____ _| |_ _____  ____| |__
00004  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00005  _____) ) ____| | | || |_| ____( (___| | | |
00006 (______/|_____)_|_|_| \__)_____)\____)_| |_|
00007     (C)2015 Semtech
00008 
00009 Description: Target board general functions implementation
00010 
00011 License: Revised BSD License, see LICENSE.TXT file include in the project
00012 
00013 Maintainer: Miguel Luis and Gregory Cristian
00014 */
00015 #include "mbed.h"
00016 #include "board.h"
00017 
00018 DigitalIn I2cInterrupt( D5 );
00019 I2C I2c(I2C_SDA, I2C_SCL);
00020 
00021 DigitalOut Pc7( D9 );
00022 DigitalIn Pc1( A4 );
00023 
00024 //DigitalIn UsrButton( PC_13 );
00025 DigitalIn UsrButton( D10 );
00026 
00027 DigitalOut Led( D6 );
00028 
00029 /* Instantiate the expansion board */
00030 XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, NC, NC);
00031  
00032 /* Retrieve the composing elements of the expansion board */
00033 LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
00034 HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
00035 LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
00036 LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
00037 LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
00038 
00039 SX1272MB2xAS Radio( NULL );
00040 
00041 void BoardInit( void )
00042 {
00043 
00044     /* Enable all sensors */
00045     hum_temp->enable();
00046     press_temp->enable();
00047     magnetometer->enable();
00048     accelerometer->enable();
00049     acc_gyro->enable_x();
00050     acc_gyro->enable_g();
00051 
00052     TimerTimeCounterInit( );
00053 }
00054 
00055 uint8_t BoardGetBatteryLevel( void ) 
00056 {
00057     return 0xFE;
00058 }
00059 
00060 uint32_t BoardGetRandomSeed( void )
00061 {
00062     return ( ( *( uint32_t* )ID1 ) ^ ( *( uint32_t* )ID2 ) ^ ( *( uint32_t* )ID3 ) );
00063 }
00064 
00065 void BoardGetDevEUI( uint8_t *id )
00066 {
00067     uint32_t DevEuiHWord = 0;
00068 
00069     if( ( id[7] == 0 ) && ( id[6] == 0 ) && ( id[5] == 0 ) && ( id[4] == 0 ) )
00070     {        
00071         DevEuiHWord = BoardGetRandomSeed( );
00072         id[7] = (DevEuiHWord >> 3) & 0xFF;
00073         id[6] = (DevEuiHWord >> 2) & 0xFF;
00074         id[5] = (DevEuiHWord >> 1) & 0xFF;
00075         id[4] = (DevEuiHWord >> 0) & 0xFF;
00076     }    
00077 }
00078 
00079 void BoardGetUniqueId( uint8_t *id )
00080 {
00081     id[7] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 24;
00082     id[6] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 16;
00083     id[5] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 8;
00084     id[4] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) );
00085     id[3] = ( ( *( uint32_t* )ID2 ) ) >> 24;
00086     id[2] = ( ( *( uint32_t* )ID2 ) ) >> 16;
00087     id[1] = ( ( *( uint32_t* )ID2 ) ) >> 8;
00088     id[0] = ( ( *( uint32_t* )ID2 ) );
00089 }
00090