# GD32VF103XX pin definitions
#
# Sources:
# - GD32VF103XX Datasheet (Revision 1.2)
# - GD32VF103 User Manual (Revision 1.2)
#
# Pin codes:
#
# - 100 pins: V
# - 64 pins:  R
# - 48 pins:  C
# - 36 pins:  T
#
# Memory codes:
#
# - 128Kb Flash, 32Kb SRAM: B
# - 64Kb  Flash, 20Kb SRAM: 8
# - 32Kb  Flash, 10Kb SRAM: 6
# - 16Kb  Flash, 6Kb  SRAM: 4
#
# Copyright (c) 2021 Teslabs Engineering S.L.
# SPDX-License-Identifier: Apache 2.0

model: afio

series: gd32vf103

variants:
  - pincode: V
    memories: [B, 8]
  - pincode: R
    memories: [B, 8]
  - pincode: R
    memories: [6, 4]
  - pincode: C
    memories: [B, 8]
  - pincode: C
    memories: [6, 4]
  - pincode: T
    memories: [B, 8]
  - pincode: T
    memories: [6, 4]

signal-configs:
  ADC01_IN0:
    modes: [analog]
  ADC01_IN1:
    modes: [analog]
  ADC01_IN2:
    modes: [analog]
  ADC01_IN3:
    modes: [analog]
  ADC01_IN4:
    modes: [analog]
  ADC01_IN5:
    modes: [analog]
  ADC01_IN6:
    modes: [analog]
  ADC01_IN7:
    modes: [analog]
  ADC01_IN8:
    modes: [analog]
  ADC01_IN9:
    modes: [analog]
  ADC01_IN10:
    modes: [analog]
  ADC01_IN11:
    modes: [analog]
  ADC01_IN12:
    modes: [analog]
  ADC01_IN13:
    modes: [analog]
  ADC01_IN14:
    modes: [analog]
  ADC01_IN15:
    modes: [analog]
  CAN0_RX:
    modes: [inp]
  CAN0_TX:
    modes: [out]
  CAN1_RX:
    modes: [inp]
  CAN1_TX:
    modes: [out]
  CK_OUT0:
    modes: [out]
  DAC_OUT0:
    modes: [analog]
  DAC_OUT1:
    modes: [analog]
  EXMC_A16:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A17:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A18:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A19:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A20:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A21:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A22:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A23:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A24:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_A25:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D0:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D1:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D2:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D3:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D4:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D5:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D6:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D7:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D8:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D9:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D10:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D11:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D12:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D13:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D14:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_D15:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_NADV:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_NBL0:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_NBL1:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_NE0:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_NOE:
    modes: [out]
    exclude-pincodes: [R, C, T]
  EXMC_NWAIT:
    modes: [inp]
  EXMC_NWE:
    modes: [out]
    exclude-pincodes: [R, C, T]
  I2C0_SCL:
    modes: [out]
  I2C0_SDA:
    modes: [out]
  I2C0_SMBA:
    modes: [out]
  I2C1_SCL:
    modes: [out]
    exclude-memories: [6, 4]
  I2C1_SDA:
    modes: [out]
    exclude-memories: [6, 4]
  I2C1_SMBA:
    modes: [out]
    exclude-memories: [6, 4]
  I2S1_CK:
    modes: [inp, out]
  I2S1_MCK:
    modes: [out]
  I2S1_SD:
    modes: [inp, out]
  I2S1_WS:
    modes: [inp, out]
  I2S2_CK:
    modes: [inp, out]
    exclude-memories: [6, 4]
  I2S2_MCK:
    modes: [out]
    exclude-memories: [6, 4]
  I2S2_SD:
    modes: [inp, out]
    exclude-memories: [6, 4]
  I2S2_WS:
    modes: [inp, out]
    exclude-memories: [6, 4]
  SPI0_MISO:
    modes: [inp, out]
  SPI0_MOSI:
    modes: [inp, out]
  SPI0_NSS:
    modes: [inp, out]
  SPI0_SCK:
    modes: [inp, out]
  SPI1_MISO:
    modes: [inp, out]
  SPI1_MOSI:
    modes: [inp, out]
  SPI1_NSS:
    modes: [inp, out]
  SPI1_SCK:
    modes: [inp, out]
  SPI2_MISO:
    modes: [inp, out]
    exclude-memories: [6, 4]
  SPI2_MOSI:
    modes: [inp, out]
    exclude-memories: [6, 4]
  SPI2_NSS:
    modes: [inp, out]
    exclude-memories: [6, 4]
  SPI2_SCK:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TAMPER:
    modes: [inp]
  TIMER0_BRKIN:
    modes: [inp]
  TIMER0_CH0:
    modes: [inp, out]
  TIMER0_CH0_ON:
    modes: [out] 
  TIMER0_CH1:
    modes: [inp, out]
  TIMER0_CH1_ON:
    modes: [out] 
  TIMER0_CH2:
    modes: [inp, out]
  TIMER0_CH2_ON:
    modes: [out] 
  TIMER0_CH3:
    modes: [inp, out]
  TIMER0_ETI:
    modes: [inp]
  TIMER1_CH0:
    modes: [inp, out]
  TIMER1_CH0_ON:
    modes: [out] 
  TIMER1_CH1:
    modes: [inp, out]
  TIMER1_CH1_ON:
    modes: [out] 
  TIMER1_CH2:
    modes: [inp, out]
  TIMER1_CH2_ON:
    modes: [out] 
  TIMER1_CH3:
    modes: [inp, out]
  TIMER2_CH0:
    modes: [inp, out]
  TIMER2_CH1:
    modes: [inp, out]
  TIMER2_CH2:
    modes: [inp, out]
  TIMER2_CH3:
    modes: [inp, out]
  TIMER2_ETI:
    modes: [inp]
  TIMER3_CH0:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER3_CH1:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER3_CH2:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER3_CH3:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER3_ETI:
    modes: [inp]
    exclude-memories: [6, 4]
  TIMER4_CH0:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER4_CH1:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER4_CH2:
    modes: [inp, out]
    exclude-memories: [6, 4]
  TIMER4_CH3:
    modes: [inp, out]
    exclude-memories: [6, 4]
  USART0_CK:
    modes: [out]
  USART0_CTS:
    modes: [inp]
  USART0_RTS:
    modes: [out]
  USART0_RX:
    modes: [inp]
  USART0_TX:
    modes: [out]
  USART1_CK:
    modes: [out]
  USART1_CTS:
    modes: [inp]
  USART1_RTS:
    modes: [out]
  USART1_RX:
    modes: [inp]
  USART1_TX:
    modes: [out]
  USART2_CK:
    modes: [out]
    exclude-memories: [6, 4]
  USART2_CTS:
    modes: [inp]
    exclude-memories: [6, 4]
  USART2_RTS:
    modes: [out]
    exclude-memories: [6, 4]
  USART2_RX:
    modes: [inp]
    exclude-memories: [6, 4]
  USART2_TX:
    modes: [out]
    exclude-memories: [6, 4]
  UART3_RX:
    modes: [inp]
    exclude-memories: [6, 4]
  UART3_TX:
    modes: [out]
    exclude-memories: [6, 4]
  UART4_RX:
    modes: [inp]
    exclude-memories: [6, 4]
  UART4_TX:
    modes: [out]
    exclude-memories: [6, 4]
  USBFS_DM:
    modes: [inp, out]
  USBFS_DP:
    modes: [inp, out]
  USBFS_ID:
    modes: [inp, out]
  USBFS_SOF:
    modes: [out]
  USBFS_VBUS:
    modes: [inp]
  WKUP:
    modes: [inp]

pins:
  PA0:
    pincodes: [V, R, C, T]
    afs: [WKUP, USART1_CTS, ADC01_IN0, TIMER1_CH0_ETI，TIMER4_CH0]
  PA1:
    pincodes: [V, R, C, T]
    afs: [USART1_RTS, ADC01_IN1, TIMER1_CH1, TIMER4_CH1]
  PA2:
    pincodes: [V, R, C, T]
    afs: [USART1_TX, ADC01_IN2, TIMER1_CH2, TIMER4_CH2]
  PA3:
    pincodes: [V, R, C, T]
    afs: [USART1_RX, ADC01_IN3, TIMER1_CH3, TIMER4_CH3]
  PA4:
    pincodes: [V, R, C, T]
    afs: [SPI0_NSS, USART1_CK, ADC01_IN4, DAC_OUT0]
  PA5:
    pincodes: [V, R, C, T]
    afs: [SPI0_SCK, ADC01_IN5, DAC_OUT1]
  PA6:
    pincodes: [V, R, C, T]
    afs: [SPI0_MISO, ADC01_IN6, TIMER2_CH0]
  PA7:
    pincodes: [V, R, C, T]
    afs: [SPI0_MOSI, ADC01_IN7, TIMER2_CH1]
  PA8:
    pincodes: [V, R, C, T]
    afs: [USART0_CK, TIMER0_CH0, CK_OUT0, USBFS_SOF]
  PA9:
    pincodes: [V, R, C, T]
    afs: [USART0_TX, TIMER0_CH1, USBFS_VBUS]
  PA10:
    pincodes: [V, R, C, T]
    afs: [USART0_RX, TIMER0_CH2, USBFS_ID]
  PA11:
    pincodes: [V, R, C, T]
    afs: [USART0_CTS, CAN0_RX, TIMER0_CH3, USBFS_DM, TIMER0_CH3]
  PA12:
    pincodes: [V, R, C, T]
    afs: [USART0_RTS, CAN0_TX, TIMER0_ETI, USBFS_DP]
  PA13:
    pincodes: [V, R, C, T]
    afs: []
  PA14:
    pincodes: [V, R, C, T]
    afs: []
  PA15:
    pincodes: [V, R, C, T]
    afs: [SPI2_NSS, I2S2_WS]
  PB0:
    pincodes: [V, R, C, T]
    afs: [ADC01_IN8, TIMER2_CH2]
  PB1:
    pincodes: [V, R, C, T]
    afs: [ADC01_IN9, TIMER2_CH3]
  PB2:
    pincodes: [V, R, C, T]
    afs: []
  PB3:
    pincodes: [V, R, C, T]
    afs: [SPI2_SCK, I2S2_CK]
  PB4:
    pincodes: [V, R, C, T]
    afs: [SPI2_MISO]
  PB5:
    pincodes: [V, R, C, T]
    afs: [I2C0_SMBA, SPI2_MOSI, I2S2_SD]
  PB6:
    pincodes: [V, R, C, T]
    afs: [I2C0_SCL, TIMER3_CH0]
  PB7:
    pincodes: [V, R, C, T]
    afs: [I2C0_SDA , TIMER3_CH1, EXMC_NADV]
  PB8:
    pincodes: [V, R, C]
    afs: [TIMER3_CH2]
  PB9:
    pincodes: [V, R, C]
    afs: [TIMER3_CH3]
  PB10:
    pincodes: [V, R, C]
    afs: [I2C1_SCL, USART2_TX]
  PB11:
    pincodes: [V, R, C]
    afs: [I2C1_SDA, USART2_RX]
  PB12:
    pincodes: [V, R, C]
    afs: [SPI1_NSS, I2C1_SMBA, USART2_CK, TIMER0_BRKIN, I2S1_WS, CAN1_RX]
  PB13:
    pincodes: [V, R, C]
    afs: [SPI1_SCK, USART2_CTS, TIMER0_CH0_ON, I2S1_CK, CAN1_TX]
  PB14:
    pincodes: [V, R, C]
    afs: [SPI1_MISO, USART2_RTS, TIMER0_CH1_ON]
  PB15:
    pincodes: [V, R, C]
    afs: [SPI1_MOSI, TIMER0_CH2_ON, I2S1_SD]
  PC0:
    pincodes: [V, R]
    afs: [ADC01_IN10]
  PC1:
    pincodes: [V, R]
    afs: [ADC01_IN11]
  PC2:
    pincodes: [V, R]
    afs: [ADC01_IN12]
  PC3:
    pincodes: [V, R]
    afs: [ADC01_IN13]
  PC4:
    pincodes: [V, R]
    afs: [ADC01_IN14]
  PC5:
    pincodes: [V, R]
    afs: [ADC01_IN15]
  PC6:
    pincodes: [V, R]
    afs: [I2S1_MCK]
  PC7:
    pincodes: [V, R]
    afs: [I2S2_MCK]
  PC8:
    pincodes: [V, R]
    afs: []
  PC9:
    pincodes: [V, R]
    afs: []
  PC10:
    pincodes: [V, R]
    afs: [UART3_TX]
  PC11:
    pincodes: [V, R]
    afs: [UART3_RX]
  PC12:
    pincodes: [V, R]
    afs: [UART4_TX]
  PC13:
    pincodes: [V, R, C]
    afs: [TAMPER]
  PC14:
    pincodes: [V, R, C]
    afs: []
  PC15:
    pincodes: [V, R, C]
    afs: []
  PD0:
    pincodes: [V, R, C, T]
    afs: [EXMC_D2]
  PD1:
    pincodes: [V, R, C, T]
    afs: [EXMC_D3]
  PD2:
    pincodes: [V, R]
    afs: [TIMER2_ETI, UART4_RX]
  PD3:
    pincodes: [V]
    afs: []
  PD4:
    pincodes: [V]
    afs: [EXMC_NOE]
  PD5:
    pincodes: [V]
    afs: [EXMC_NWE]
  PD6:
    pincodes: [V]
    afs: [EXMC_NWAIT]
  PD7:
    pincodes: [V]
    afs: [EXMC_NE0]
  PD8:
    pincodes: [V]
    afs: [EXMC_D13]
  PD9:
    pincodes: [V]
    afs: [EXMC_D14]
  PD10:
    pincodes: [V]
    afs: [EXMC_D15]
  PD11:
    pincodes: [V]
    afs: [EXMC_A16]
  PD12:
    pincodes: [V]
    afs: [EXMC_A17]
  PD13:
    pincodes: [V]
    afs: [EXMC_A18]
  PD14:
    pincodes: [V]
    afs: [EXMC_D0]
  PD15:
    pincodes: [V]
    afs: [EXMC_D1]
  PE0:
    pincodes: [V]
    afs: [TIMER3_ETI, EXMC_NBL0]
  PE1:
    pincodes: [V]
    afs: [EXMC_NBL1]
  PE2:
    pincodes: [V]
    afs: [EXMC_A23]
  PE3:
    pincodes: [V]
    afs: [EXMC_A19]
  PE4:
    pincodes: [V]
    afs: [EXMC_A20]
  PE5:
    pincodes: [V]
    afs: [EXMC_A21]
  PE6:
    pincodes: [V]
    afs: [EXMC_A22]
  PE7:
    pincodes: [V]
    afs: [EXMC_D4]
  PE8:
    pincodes: [V]
    afs: [EXMC_D5]
  PE9:
    pincodes: [V]
    afs: [EXMC_D6]
  PE10:
    pincodes: [V]
    afs: [EXMC_D7]
  PE11:
    pincodes: [V]
    afs: [EXMC_D8]
  PE12:
    pincodes: [V]
    afs: [EXMC_D9]
  PE13:
    pincodes: [V]
    afs: [EXMC_D10]
  PE14:
    pincodes: [V]
    afs: [EXMC_D11]
  PE15:
    pincodes: [V]
    afs: [EXMC_D12]

remaps:
  CAN0_RX:
    pins: [PA11, null, PB8, PD0]
  CAN0_TX:
    pins: [PA12, null, PB9, PD1]
  CAN1_RX:
    pins: [PB12, PB5]
  CAN1_TX:
    pins: [PB13, PB6]
  I2C0_SCL:
    pins: [PB6, PB8]
  I2C0_SDA:
    pins: [PB7, PB9]
  I2S2_SD:
    pins: [PB5, PC12]
  I2S2_WS:
    pins: [PA15, PA4]
  I2S2_CK:
    pins: [PB3, PC10]
  SPI0_MISO:
    pins: [PA6, PB4]
  SPI0_MOSI:
    pins: [PA7, PB5]
  SPI0_NSS:
    pins: [PA4, PA15]
  SPI0_SCK:
    pins: [PA5, PB3]
  SPI2_MISO:
    pins: [PB4, PC11]
  SPI2_MOSI:
    pins: [PB5, PC12]
  SPI2_NSS:
    pins: [PA15, PA4]
  SPI2_SCK:
    pins: [PB3, PC10]
  TIMER0_BKIN:
    pins: [PB12, PA6, null, PE15]
  TIMER0_CH0:
    pins: [PA8, PA8, null, PE9]
  TIMER0_CH1:
    pins: [PA9, PA9, null, PE11]
  TIMER0_CH2:
    pins: [PA10, PA10, null, PE13]
  TIMER0_CH3:
    pins: [PA11, PA11, null, PE14]
  TIMER0_CH0_ON:
    pins: [PB13, PA7, null, PE8]
  TIMER0_CH1_ON:
    pins: [PB14, PB0, null, PE10]
  TIMER0_CH2_ON:
    pins: [PB15, PB1, null, PE12]
  TIMER0_ETI:
    pins: [PA12, PA12, null, PE7]
  TIMER1_CH0:
    pins: [PA0, PA15, PA0, PA15]
  TIMER1_CH1:
    pins: [PA1, PB3, PA1, PB3]
  TIMER1_CH2:
    pins: [PA2, PA2, PB10, PB10]
  TIMER1_CH3:
    pins: [PA3, PA3, PB11, PB11]
  TIMER1_ETI:
    pins: [PA0, PA15, PA0, PA15]
  TIMER2_CH0:
    pins: [PA6, null, PB4, PC6]
  TIMER2_CH1:
    pins: [PA7, null, PB5, PC7]
  TIMER2_CH2:
    pins: [PB0, null, PB0, PC8]
  TIMER2_CH3:
    pins: [PB1, null, PB1, PC9]
  TIMER3_CH0:
    pins: [PB6, PD12]
  TIMER3_CH1:
    pins: [PB7, PD13]
  TIMER3_CH2:
    pins: [PB8, PD14]
  TIMER3_CH3:
    pins: [PB9, PD15]
  USART0_RX:
    pins: [PA10, PB7]
  USART0_TX:
    pins: [PA9, PB6]
  USART1_CK:
    pins: [PA4, PD7]
  USART1_CTS:
    pins: [PA0, PD3]
  USART1_RTS:
    pins: [PA1, PD4]
  USART1_RX:
    pins: [PA3, PD6]
  USART1_TX:
    pins: [PA2, PD5]
  USART2_CK:
    pins: [PB12, PC12, null, PD10]
  USART2_CTS:
    pins: [PB13, PB13, null, PD11]
  USART2_RTS:
    pins: [PB14, PB14, null, PD12]
  USART2_RX:
    pins: [PB11, PC11, null, PD9]
  USART2_TX:
    pins: [PB10, PC10, null, PD8]
