text: /*
   / _____)             _              | |
  ( (____  _____ ____ _| |_ _____  ____| |__
   \____ \| ___ |    (_   _) ___ |/ ___)  _ \
   _____) ) ____| | | || |_| ____( (___| | | |
  (______/|_____)_|_|_| \__)_____)\____)_| |_|
      (C)2013 Semtech
  
  Description: Target board general functions implementation
  
  License: Revised BSD License, see LICENSE.TXT file include in the project
  
  Maintainer: Miguel Luis and Gregory Cristian
  */
  #ifndef __BOARD_H__
  #define __BOARD_H__
  
  #include <stdbool.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  #include <stdint.h>
  #include "stm32l0xx.h"
  #include "stm32l0xx_hal.h"
  #include "utilities.h"
  #include "timer.h"
  #include "delay.h"
  #include "gpio.h"
  #include "adc.h"
  #include "printf.h"
  #include "spi.h"
  #include "i2c.h"
  #include "uart.h"
  #include "radio.h"
  #include "sx1276/sx1276.h"
  #include "gps.h"
  #include "gps-board.h"
  #include "rtc-board.h"
  #include "sx1276-board.h"
  #include "uart-board.h"
  
  
  #if defined( USE_USB_CDC )
  #include "uart-usb-board.h"
  #endif
  
  /*!
   * Define indicating if an external IO expander is to be used
   */
  //#define BOARD_IOE_EXT
  
  /*!
   * Generic definition
   */
  #ifndef SUCCESS
  #define SUCCESS                                     1
  #endif
  
  #ifndef FAIL
  #define FAIL                                        0
  #endif
  
  /*!
   * Board IO Extender pins definitions
   */
  #define IRQ_MPL3115                                 IOE_0
  #define IRQ_MAG3110                                 IOE_1
  #define GPS_POWER_ON                                IOE_2
  #define RADIO_PUSH_BUTTON                           IOE_3
  #define BOARD_POWER_DOWN                            IOE_4
  #define SPARE_IO_EXT_5                              IOE_5
  #define SPARE_IO_EXT_6                              IOE_6
  #define SPARE_IO_EXT_7                              IOE_7
  #define N_IRQ_SX9500                                IOE_8
  #define IRQ_1_MMA8451                               IOE_9
  #define IRQ_2_MMA8451                               IOE_10
  #define TX_EN_SX9500                                IOE_11
  #define LED_1                                       PB_3
  #define LED_2                                       PB_4
  
  /*!
   * Board MCU pins definitions
   */
  
  #define RADIO_RESET                                 PB_11
  
  #define RADIO_MOSI                                  PA_7
  #define RADIO_MISO                                  PA_6
  #define RADIO_SCLK                                  PA_5
  #define RADIO_NSS                                   PA_4
  
  #define RADIO_DIO_0                                 PB_10
  #define RADIO_DIO_1                                 PB_2
  #define RADIO_DIO_2                                 PB_0
  #define RADIO_DIO_3                                 PB_1
  #define RADIO_DIO_4                                 PB_5
  #define RADIO_DIO_5                                 PA_15
  
  #define RADIO_ANT_SWITCH_HF                         PA_1
  #define RADIO_ANT_SWITCH_LF                         PA_1
  
  #define OSC_LSE_IN                                  PC_14
  #define OSC_LSE_OUT                                 PC_15
  
  #define OSC_HSE_IN                                  PH_0
  #define OSC_HSE_OUT                                 PH_1
  
  #define USB_DM                                      PA_11
  #define USB_DP                                      PA_12
  
  #define I2C_SCL                                     PB_8
  #define I2C_SDA                                     PB_9
  
  #define BOOT_1                                      PB_2
      
  #define GPS_PPS                                     PA_8
  #define UART_TX                                     PA_9
  #define UART_RX                                     PA_10
  #define PRINTF_TX                                   PA_2
  #define PRINTF_RX                                   PA_3
  
  #define DC_DC_EN                                    PB_8
  #define BAT_LEVEL                                   PB_0
  
  #define CON_EXT_1                                   PB_13
  #define CON_EXT_3                                   PB_15
  #define CON_EXT_7                                   PB_12
  #define CON_EXT_8                                   PB_14
  #define CON_EXT_9                                   PB_3
  
  #define SWDIO                                       PA_13
  #define SWCLK                                       PA_14
  
  #define TEST_POINT1                                 PB_12
  #define TEST_POINT2                                 PB_13
  #define TEST_POINT3                                 PB_14
  #define TEST_POINT4                                 PB_15
  
  //#define PIN_NC                                      PB_5
  
  /*!
   * LED GPIO pins objects
   */
  extern Gpio_t IrqMpl3115;
  extern Gpio_t IrqMag3110;
  // modified
  // extern Gpio_t GpsPowerEn;
  extern Gpio_t RadioPushButton;
  extern Gpio_t BoardPowerUp;
  extern Gpio_t NcIoe5;
  extern Gpio_t NcIoe6;
  extern Gpio_t NcIoe7;
  extern Gpio_t NIrqSX9500;
  extern Gpio_t Irq1Mma8451;
  extern Gpio_t Irq2Mma8451;
  extern Gpio_t TxEnSX9500;
  extern Gpio_t Led1;
  extern Gpio_t Led2;
  extern Gpio_t Led3;
  extern Gpio_t Led4;
  
  /*!
   * Debug GPIO pins objects
   */
  #if defined( USE_DEBUG_PINS )
  extern Gpio_t DbgPin1;
  extern Gpio_t DbgPin2;
  extern Gpio_t DbgPin3;
  extern Gpio_t DbgPin4;
  extern Gpio_t DbgPin5;
  #endif
  
  
  /*!
   * MCU objects
   */
  extern Adc_t Adc;
  extern I2c_t I2c;
  
  extern Gpio_t GpsPps;
  extern Gpio_t GpsRx;
  extern Gpio_t GpsTx;
  extern Gpio_t UsbDetect;
  extern Gpio_t Wkup1;
  extern Gpio_t DcDcEnable;
  extern Gpio_t BatVal;
  
  /*!
   * Possible power sources
   */
  enum BoardPowerSource
  {
      USB_POWER = 0,
      BATTERY_POWER
  };
  
  /*!
   * \brief Disable interrupts
   *
   * \remark IRQ nesting is managed
   */
  void BoardDisableIrq( void );
  
  /*!
   * \brief Enable interrupts
   *
   * \remark IRQ nesting is managed
   */
  void BoardEnableIrq( void );
  
  /*!
   * \brief Initializes the target board peripherals.
   */
  void BoardInitMcu( void );
  
  /*!
   * \brief Initializes the boards peripherals.
   */
  void BoardInitPeriph( void );
  
  /*!
   * \brief De-initializes the target board peripherals to decrease power
   *        consumption.
   */
  void BoardDeInitMcu( void );
  
  /*!
   * \brief Get the current battery level
   *
   * \retval value  battery level ( 0: very low, 254: fully charged )
   */
  uint8_t BoardGetBatteryLevel( void );
  
  /*!
   * Returns a pseudo random seed generated using the MCU Unique ID
   *
   * \retval seed Generated pseudo random seed
   */
  uint32_t BoardGetRandomSeed( void );
  
  /*!
   * \brief Gets the board 64 bits unique ID
   *
   * \param [IN] id Pointer to an array that will contain the Unique ID
   */
  void BoardGetUniqueId( uint8_t *id );
  
  /*!
   * \brief Get the board power source
   *
   * \retval value  power source ( 0: USB_POWER,  1: BATTERY_POWER )
   */
  uint8_t GetBoardPowerSource( void );
  
  #endif // __BOARD_H__
  