#ifndef CORE_CONFIG_PINS_H
#define CORE_CONFIG_PINS_H
  #include "stm32l1xx_hal_gpio.h"
  #include "stm32l1xx_hal_pwr_ex.h"
  #include "stm32l1xx_hal_adc.h" // ADC_CHANNEL_X
  //============================================================================
  // External Memory (SPI):
  //  NSS (nCS) = PB11 (software)  
  #define CONFIG_PIN__EXTMEMSPI__CS                  GPIO_PIN_11
  #define CONFIG_PORT__EXTMEMSPI__CS                 GPIOB
  //============================================================================
  // External Memory (SPI):
  // SPI: SPI2 (AF5_SPI2)
  //  SCK (CK) = PB13 (hardware)
  //  MISO (SO) = PB14 (hardware)
  //  MOSI (SI) = PB15 (hardware)
  #define CONFIG_PIN__EXTMEMSPI__CK                  GPIO_PIN_13
  #define CONFIG_PIN__EXTMEMSPI__SO                  GPIO_PIN_14
  #define CONFIG_PIN__EXTMEMSPI__SI                  GPIO_PIN_15
  #define CONFIG_PORT__EXTMEMSPI__SO_SI_CK           GPIOB
  #define CONFIG_AF__EXTMEMSPI__SO_SI_CK             GPIO_AF5_SPI2
  //============================================================================
  // External Memory Reset Pin
  // RST: PB10
  #define CONFIG_PIN__EXTMEM__RST                    GPIO_PIN_10
  #define CONFIG_PORT__EXTMEM__RST                   GPIOB
  //============================================================================
  // Thermo-sensor (I2C):
  // I2C: I2C1 (AF4_I2C1)
  //  SDA (DA) = PB7 (hardware)
  //  SCL (CL) = PB6 (hardware)  
  #define CONFIG_PIN__TSENSI2C__DA                   GPIO_PIN_7
  #define CONFIG_PIN__TSENSI2C__CL                   GPIO_PIN_6  
  #define CONFIG_PORT__TSENSI2C__DA_CL               GPIOB
  #define CONFIG_AF__TSENSI2C__SO_SI_CK              GPIO_AF4_I2C1
  //============================================================================
  // Thermo-sensor Power Pin
  // TSENS-PWR: PB5
  #define CONFIG_PIN__TSENS_PWR                      GPIO_PIN_5  
  #define CONFIG_PORT__TSENS_PWR                     GPIOB  
  //============================================================================
  // Battery-Voltage Monitor
  // VBAT_ADC: PA4 (Channel 4 = ADC_CHANNEL_4)
  // VBAT_EN:  PB5
  #define CONFIG_PIN__VBAT_ADC                       GPIO_PIN_4
  #define CONFIG_PIN__VBAT_EN                        GPIO_PIN_5
  #define CONFIG_PORT__VBAT_ADC                      GPIOA
  #define CONFIG_PORT__VBAT_EN                       GPIOB  
  #define CONFIG_ADC__VBAT_ADC                       ADC_CHANNEL_4  

  //============================================================================
  // LEDs (Red-led && Green-led)
  // REDLED: 
  // GREENLED: 
  #define CONFIG_PIN__LED_RED                        GPIO_PIN_15
  #define CONFIG_PIN__LED_GREEN                      GPIO_PIN_3
  #define CONFIG_PORT__LED_RED                       GPIOA
  #define CONFIG_PORT__LED_GREEN                     GPIOB
  //============================================================================
  // SwitchKeys Pins (parallel port)
  // Port#1 = PA0
  // Port#2 = PA1
  // Port#3 = PA2
  // Port#4 = PA3
  #define CONFIG_PIN__SWKEYPP_L1                     GPIO_PIN_0
  #define CONFIG_PIN__SWKEYPP_L2                     GPIO_PIN_1
  #define CONFIG_PIN__SWKEYPP_L3                     GPIO_PIN_2
  #define CONFIG_PIN__SWKEYPP_L4                     GPIO_PIN_3
  #define CONFIG_PORT__SWKEYPP_L1                    GPIOA
  #define CONFIG_PORT__SWKEYPP_L2                    GPIOA
  #define CONFIG_PORT__SWKEYPP_L3                    GPIOA
  #define CONFIG_PORT__SWKEYPP_L4                    GPIOA
  #define CONFIG_PORT__SINGLEPORTINIT                1    // 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: PA4
  // DBGPIN2: PB6
  // DBGPIN3: PB7
  #define CONFIG_PIN__DBGPIN1                        GPIO_PIN_4  ??
  #define CONFIG_PORT__DBGPIN1                       GPIOA       ??
  #define CONFIG_PIN__DBGPIN2                        GPIO_PIN_6
  #define CONFIG_PORT__DBGPIN2                       GPIOB
  #define CONFIG_PIN__DBGPIN3                        GPIO_PIN_7
  #define CONFIG_PORT__DBGPIN3                       GPIOB

#endif