#ifndef CORE_CONFIG_PINS_H
#define CORE_CONFIG_PINS_H
  #include "stm32l1xx_hal.h"
  #include "stm32l1xx_hal_gpio.h"
  #include "stm32l1xx_hal_pwr_ex.h"
  #include "stm32l1xx_hal_adc.h" // ADC_CHANNEL_X

  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // DO NOT CHANGE THIS BLOCK!
  #define CONFIG_PERIF_I2C1                          1
  #define CONFIG_PERIF_I2C2                          2
  #define CONFIG_PERIF_SPI1                          1
  #define CONFIG_PERIF_SPI2                          2  
  // DO NOT CHANGE THIS BLOCK!
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  //============================================================================
  // External Memory (SPI):
  //  NSS (nCS) = PA15 (software)  
  #define CONFIG_PIN__EXTMEMSPI__CS                  GPIO_PIN_4
  #define CONFIG_PORT__EXTMEMSPI__CS                 GPIOA
  //============================================================================
  // External Memory (SPI):
  // SPI: SPI1 (AF5_SPI1)
  //  SCK (CK) = PB3 (hardware)
  //  MISO (SO) = PB4 (hardware)
  //  MOSI (SI) = PB5 (hardware)
  #define CONFIG_PIN__EXTMEMSPI__CK                  GPIO_PIN_5
  #define CONFIG_PIN__EXTMEMSPI__SO                  GPIO_PIN_6
  #define CONFIG_PIN__EXTMEMSPI__SI                  GPIO_PIN_7
  #define CONFIG_PORT__EXTMEMSPI__SO_SI_CK           GPIOA  
  #define CONFIG_PERIF_EXTMEMSPI                     CONFIG_PERIF_SPI1
  //============================================================================
  // External Memory Reset Pin
  // RST: PB8
  #define CONFIG_PIN__EXTMEM__RST                    GPIO_PIN_2
  #define CONFIG_PORT__EXTMEM__RST                   GPIOB
  //============================================================================
  // Switchboard Control Driver (SPI):
  // SPI: SPI2 (AF5_SPI2)
  //  NSS (CHS) = PB12 (hardware)
  //  SCK (CK)  = PB13 (hardware)
  //  MISO (SO) = PB14 (hardware)
  //  MOSI (SI) = PB15 (hardware)
  #define CONFIG_PIN__SBCONTROL__CHS                 GPIO_PIN_12
  #define CONFIG_PORT__SBCONTROL__CHS                GPIOB

  #define CONFIG_PIN__SBCONTROL__CK                  GPIO_PIN_13
  #define CONFIG_PIN__SBCONTROL__SO                  GPIO_PIN_14
  #define CONFIG_PIN__SBCONTROL__SI                  GPIO_PIN_15
  #define CONFIG_PORT__SBCONTROL__SO_SI_CK           GPIOB
  #define CONFIG_PERIF_SBCONTROLSPI                  CONFIG_PERIF_SPI2
  //============================================================================
  // Thermo-sensor (I2C):
  // I2C: I2C1 (AF4_I2C2)
  //  SDA (DA) = PB7 (hardware)
  //  SCL (CL) = PB6 (hardware)  
  #define CONFIG_PIN__TSENSI2C__DA                   GPIO_PIN_9
  #define CONFIG_PIN__TSENSI2C__CL                   GPIO_PIN_8  
  #define CONFIG_PORT__TSENSI2C__DA_CL               GPIOB  
  #define CONFIG_PERIF_TSENSI2C                      CONFIG_PERIF_I2C1
  //============================================================================
  // Thermo-sensor Power Pin
  // TSENS-PWR: -
  #define CONFIG_PIN__NTC_TSENS_PWR                  GPIO_PIN_0
  #define CONFIG_PORT__NTC_TSENS_PWR                 GPIOA
  #define CONFIG_ADC_CHANNEL_NTC_TSENS               ADC_CHANNEL_0
  //============================================================================
  // Power management Pin
  #define CONFIG_PIN__INPTRG                         GPIO_PIN_8
  #define CONFIG_PIN__INPTRG_1                       GPIO_PIN_9
  #define CONFIG_PIN__EXT_REG_MR                     GPIO_PIN_8
  #define CONFIG_PIN__INPTRG_EN                      GPIO_PIN_10

  #define CONFIG_PORT__INPTRG                        GPIOA
  #define CONFIG_PORT__INPTRG_1                      GPIOA
  #define CONFIG_PORT__EXT_REG_MR                    GPIOA   
  #define CONFIG_PORT__INPTRG_EN                     GPIOA
  #define CONFIG_ADC_CHANNEL_POWER                   ADC_CHANNEL_1
  //============================================================================
  // Battery-Voltage Monitor
  // VBAT_ADC: PA7 (Channel 7 = ADC_CHANNEL_7)
  // VBAT_EN:  PA6
  #define CONFIG_PIN__VBAT_ADC                       GPIO_PIN_7
  #define CONFIG_PIN__VBAT_EN                        GPIO_PIN_6
  #define CONFIG_PORT__VBAT_ADC                      GPIOA
  #define CONFIG_PORT__VBAT_EN                       GPIOA  
  #define CONFIG_ADC__VBAT_ADC                       ADC_CHANNEL_7  

  //============================================================================
  // LEDs (Red-led && Green-led)
  // REDLED: 
  // GREENLED: 
  #define CONFIG_PIN__LED_RED                        GPIO_PIN_2
  #define CONFIG_PIN__LED_GREEN                      GPIO_PIN_1
  #define CONFIG_PORT__LED_RED                       GPIOA
  #define CONFIG_PORT__LED_GREEN                     GPIOA
  //============================================================================
  // SwitchKeys Pins (parallel port)
  // 4 lines for ACM2543.1 and 6 lines for ACM2543.2
  #define CONFIG_PIN__SWKEYPP_L1                     GPIO_PIN_10   // CTRL-ADFRV1_ON
  #define CONFIG_PIN__SWKEYPP_L2                     GPIO_PIN_11   // CTRL-ADFRV2_ON
  #define CONFIG_PIN__SWKEYPP_L3                     GPIO_PIN_13   // CTRL-HMCV1_ON
  #define CONFIG_PIN__SWKEYPP_L4                     GPIO_PIN_14   // CTRL-HMCV2_ON
  #define CONFIG_PIN__SWKEYPP_L5                     GPIO_PIN_15   // CTRL-HMCV3_ON
  #define CONFIG_PIN__SWKEYPP_L6                     GPIO_PIN_5   
  #define CONFIG_PORT__SWKEYPP_L1                    GPIOB        
  #define CONFIG_PORT__SWKEYPP_L2                    GPIOB
  #define CONFIG_PORT__SWKEYPP_L3                    GPIOB
  #define CONFIG_PORT__SWKEYPP_L4                    GPIOB
  #define CONFIG_PORT__SWKEYPP_L5                    GPIOB
  #define CONFIG_PORT__SWKEYPP_L6                    GPIOB
  #define CONFIG_PORT__SINGLEPORTINIT                0    // only if CONFIG_PORT__SWKEYPP_Lx are the same! 
  //============================================================================
  // USB VBUS Line Detection
  // Be careful: wakeup pins must be choosed respectively to the VBUS pin
  // VBUS: PC13=WKUP2
  #define CONFIG_PIN__USB__VBUSDETECT                GPIO_PIN_13
  #define CONFIG_PORT__USB__VBUSDETECT               GPIOC
  // USB VBUS Line Detection - wakeup function
  // VBUS: WKUP2=PC13
  #define CONFIG_PIN__USB__VBUSWKUP                  PWR_WAKEUP_PIN2
  //============================================================================
//// Core Clock Output Pin
//// MCO: PA8
//#define CONFIG_PIN__MCO                            GPIO_PIN_8
//#define CONFIG_PORT__MCO                           GPIOA
//#define CONFIG_AF__MCO                             GPIO_AF0_MCO
  //============================================================================
  // Debug pins (can overlapp with already used if the corresponding perifieral is disabled)
  // DBGPIN1: PB6
  // DBGPIN2: PB7
  // DBGPIN3: -
  #define CONFIG_PIN__DBGPIN1                        GPIO_PIN_6
  #define CONFIG_PORT__DBGPIN1                       GPIOB     
  #define CONFIG_PIN__DBGPIN2                        GPIO_PIN_7
  #define CONFIG_PORT__DBGPIN2                       GPIOB
  #define CONFIG_PIN__DBGPIN3                        GPIO_PIN_1
  #define CONFIG_PORT__DBGPIN3                       GPIOB

#endif