# GD32E103XX pin definitions
#
# Sources:
# - GD32E103XX Datasheet (Revision 1.5)
# - GD32E103 User Manual (Revision 1.5)
#
# 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
#
# Copyright (c) 2021 YuLong Yao <feilongphone@gmail.com>
# SPDX-License-Identifier: Apache 2.0

model: afio

series: gd32e103

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

signal-configs:
  ADC01_IN0:
    modes: [analog]
  ADC01_IN1:
    modes: [analog]
  ADC01_IN10:
    modes: [analog]
    exclude-pincodes: [T, C]
  ADC01_IN11:
    modes: [analog]
    exclude-pincodes: [T, C]
  ADC01_IN12:
    modes: [analog]
    exclude-pincodes: [T, C]
  ADC01_IN13:
    modes: [analog]
    exclude-pincodes: [T, C]
  ADC01_IN14:
    modes: [analog]
    exclude-pincodes: [T, C]
  ADC01_IN15:
    modes: [analog]
    exclude-pincodes: [T, C]
  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]
  CK_OUT0:
    modes: [out]
  CTC_SYNC:
    modes: [out]
  DAC_OUT0:
    modes: [analog]
  DAC_OUT1:
    modes: [analog]
  EXMC_A16:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A17:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A18:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A19:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A20:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A21:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A22:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_A23:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_CLK:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D0:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D1:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D10:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D11:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D12:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D13:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D14:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D15:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D2:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D3:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D4:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D5:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D6:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D7:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D8:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_D9:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_NBL0:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_NBL1:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_NE0:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_NL(NADV):
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_NOE:
    modes: [out]
    exclude-pincodes: [T, R, C]
  EXMC_NWAIT:
    modes: [inp]
    exclude-pincodes: [T, R, C]
  EXMC_NWE:
    modes: [out]
    exclude-pincodes: [T, R, C]
  I2C0_SCL:
    modes: [out]
  I2C0_SDA:
    modes: [out]
  I2C0_SMBA:
    modes: [out]
  I2C0_TXFRAME:
    modes: [out]
  I2C1_SCL:
    modes: [out]
    exclude-pincodes: [T]
  I2C1_SDA:
    modes: [out]
    exclude-pincodes: [T]
  I2C1_SMBA:
    modes: [out]
    exclude-pincodes: [T]
  I2C1_TXFRAME:
    modes: [out]
    exclude-pincodes: [T]
  I2S1_CK:
    modes: [out]
    exclude-pincodes: [T]
  I2S1_MCK:
    modes: [out]
    exclude-pincodes: [T, C]
  I2S1_SD:
    modes: [inp, out]
    exclude-pincodes: [T]
  I2S1_WS:
    modes: [inp, out]
    exclude-pincodes: [T]
  I2S2_CK:
    modes: [out]
    exclude-pincodes: [T]
  I2S2_MCK:
    modes: [out]
    exclude-pincodes: [T, C]
  I2S2_SD:
    modes: [inp, out]
    exclude-pincodes: [T]
  I2S2_WS:
    modes: [inp, out]
    exclude-pincodes: [T]
  RTC_TAMPER:
    modes: [inp]
    exclude-pincodes: [T]
  SPI0_IO2:
    modes: [out]
  SPI0_IO3:
    modes: [out]
  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]
    exclude-pincodes: [T]
  SPI1_MOSI:
    modes: [inp, out]
    exclude-pincodes: [T]
  SPI1_NSS:
    modes: [inp, out]
    exclude-pincodes: [T]
  SPI1_SCK:
    modes: [inp, out]
    exclude-pincodes: [T]
  SPI2_MISO:
    modes: [inp, out]
    exclude-pincodes: [T]
  SPI2_MOSI:
    modes: [inp, out]
    exclude-pincodes: [T]
  SPI2_NSS:
    modes: [inp, out]
    exclude-pincodes: [T]
  SPI2_SCK:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER0_BKIN:
    modes: [inp]
    exclude-pincodes: [T]
  TIMER0_CH0:
    modes: [inp, out]
  TIMER0_CH0_ON:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER0_CH1:
    modes: [inp, out]
  TIMER0_CH1_ON:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER0_CH2:
    modes: [inp, out]
  TIMER0_CH2_ON:
    modes: [out]
    exclude-pincodes: [T]
  TIMER0_CH3:
    modes: [inp, out]
  TIMER0_ETI:
    modes: [inp]
  TIMER10_CH0:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER11_CH0:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER11_CH11:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER12_CH0:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER13_CH0:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER1_CH0_ETI:
    modes: [inp]
  TIMER1_CH1:
    modes: [inp, out]
  TIMER1_CH2:
    modes: [inp, 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]
    exclude-pincodes: [T, C]
  TIMER3_CH0:
    modes: [inp, out]
  TIMER3_CH1:
    modes: [inp, out]
  TIMER3_CH2:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER3_CH3:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER3_ETI:
    modes: [inp]
    exclude-pincodes: [T, R, C]
  TIMER4_CH0:
    modes: [inp, out]
  TIMER4_CH1:
    modes: [inp, out]
  TIMER4_CH2:
    modes: [inp, out]
  TIMER4_CH3:
    modes: [inp, out]
  TIMER7_BKIN:
    modes: [inp]
    exclude-pincodes: [T, C]
  TIMER7_CH0:
    modes: [inp, out]
    exclude-pincodes: [T, C]
  TIMER7_CH0_ON:
    modes: [inp, out]
    exclude-pincodes: [T, C]
  TIMER7_CH1:
    modes: [inp, out]
    exclude-pincodes: [T, C]
  TIMER7_CH1_ON:
    modes: [inp, out]
    exclude-pincodes: [T, C]
  TIMER7_CH2:
    modes: [inp, out]
    exclude-pincodes: [T, C]
  TIMER7_CH2_ON:
    modes: [out]
    exclude-pincodes: [T, C]
  TIMER7_CH3:
    modes: [inp, out]
    exclude-pincodes: [T, C]
  TIMER7_ETI:
    modes: [inp]
    exclude-pincodes: [T, C]
  TIMER8_CH0:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER8_CH1:
    modes: [inp, out]
    exclude-pincodes: [T]
  TIMER9_CH0:
    modes: [inp, out]
    exclude-pincodes: [T]
  TRACECK:
    modes: [out]
    exclude-pincodes: [T, R, C]
  TRACED0:
    modes: [out]
    exclude-pincodes: [T, R, C]
  TRACED1:
    modes: [out]
    exclude-pincodes: [T, R, C]
  TRACED2:
    modes: [out]
    exclude-pincodes: [T, R, C]
  TRACED3:
    modes: [out]
    exclude-pincodes: [T, R, C]
  UART3_RX:
    modes: [inp]
    exclude-pincodes: [T, C]
  UART3_TX:
    modes: [out]
    exclude-pincodes: [T, C]
  UART4_RX:
    modes: [inp]
    exclude-pincodes: [T, C]
  UART4_TX:
    modes: [out]
    exclude-pincodes: [T, C]
  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-pincodes: [T]
  USART2_CTS:
    modes: [inp]
    exclude-pincodes: [T]
  USART2_RTS:
    modes: [out]
    exclude-pincodes: [T]
  USART2_RX:
    modes: [inp]
    exclude-pincodes: [T]
  USART2_TX:
    modes: [out]
    exclude-pincodes: [T]
  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: [C, V, R, T]
    afs: [TIMER7_ETI, ADC01_IN0, TIMER1_CH0_ETI, TIMER4_CH0, USART1_CTS, WKUP] 
  PA1:
    pincodes: [C, V, R, T]
    afs: [TIMER1_CH1, TIMER4_CH1, ADC01_IN1, USART1_RTS] 
  PA2:
    pincodes: [C, V, R, T]
    afs: [TIMER1_CH2, ADC01_IN2, TIMER4_CH2, SPI0_IO2, TIMER8_CH0, USART1_TX] 
  PA3:
    pincodes: [C, V, R, T]
    afs: [ADC01_IN3, USART1_RX, TIMER8_CH1, TIMER4_CH3, TIMER1_CH3, SPI0_IO3] 
  PA4:
    pincodes: [C, V, R, T]
    afs: [ADC01_IN4, DAC_OUT0, SPI0_NSS, USART1_CK] 
  PA5:
    pincodes: [C, V, R, T]
    afs: [SPI0_SCK, ADC01_IN5, DAC_OUT1] 
  PA6:
    pincodes: [C, V, R, T]
    afs: [TIMER2_CH0, TIMER12_CH0, ADC01_IN6, SPI0_MISO, TIMER7_BKIN] 
  PA7:
    pincodes: [C, V, R, T]
    afs: [TIMER13_CH0, ADC01_IN7, SPI0_MOSI, TIMER2_CH1, TIMER7_CH0_ON] 
  PA8:
    pincodes: [C, V, R, T]
    afs: [CK_OUT0, USBFS_SOF, USART0_CK, VCORE, CTC_SYNC, TIMER0_CH0] 
  PA9:
    pincodes: [C, V, R, T]
    afs: [USBFS_VBUS, USART0_TX, TIMER0_CH1] 
  PA10:
    pincodes: [C, V, R, T]
    afs: [TIMER0_CH2, USART0_RX, USBFS_ID, V1REF] 
  PA11:
    pincodes: [C, V, R, T]
    afs: [USART0_CTS, TIMER0_CH3, USBFS_DM] 
  PA12:
    pincodes: [C, V, R, T]
    afs: [USBFS_DP, USART0_RTS, TIMER0_ETI] 
  PA13:
    pincodes: [C, V, R, T]
    afs: [] 
  PA14:
    pincodes: [C, V, R, T]
    afs: [] 
  PA15:
    pincodes: [C, V, R, T]
    afs: [SPI2_NSS, I2S2_WS] 
  PB0:
    pincodes: [C, V, R, T]
    afs: [ADC01_IN8, TIMER2_CH2, TIMER7_CH1_ON] 
  PB1:
    pincodes: [C, V, R, T]
    afs: [ADC01_IN9, TIMER2_CH3, TIMER7_CH2_ON] 
  PB2:
    pincodes: [C, V, R, T]
    afs: [] 
  PB3:
    pincodes: [C, V, R, T]
    afs: [SPI2_SCK, I2S2_CK] 
  PB4:
    pincodes: [C, V, R, T]
    afs: [SPI2_MISO, I2C0_TXFRAME] 
  PB5:
    pincodes: [C, V, R, T]
    afs: [I2S2_SD, SPI2_MOSI, I2C0_SMBA] 
  PB6:
    pincodes: [C, V, R, T]
    afs: [I2C0_SCL, TIMER3_CH0] 
  PB7:
    pincodes: [C, V, R, T]
    afs: [TIMER3_CH1, EXMC_NL(NADV), I2C0_SDA] 
  PB8:
    pincodes: [C, V, R]
    afs: [TIMER9_CH0, TIMER3_CH2] 
  PB9:
    pincodes: [C, V, R]
    afs: [TIMER10_CH0, TIMER3_CH3] 
  PB10:
    pincodes: [C, V, R]
    afs: [I2C1_SCL, USART2_TX] 
  PB11:
    pincodes: [C, V, R]
    afs: [USART2_RX, I2C1_SDA] 
  PB12:
    pincodes: [C, V, R]
    afs: [SPI1_NSS, TIMER0_BKIN, I2S1_WS, I2C1_SMBA, USART2_CK] 
  PB13:
    pincodes: [C, V, R]
    afs: [USART2_CTS, SPI1_SCK, I2C1_TXFRAME, TIMER0_CH0_ON, I2S1_CK] 
  PB14:
    pincodes: [C, V, R]
    afs: [USART2_RTS, TIMER11_CH0, SPI1_MISO, TIMER0_CH1_ON] 
  PB15:
    pincodes: [C, V, R]
    afs: [TIMER11_CH11, 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: [TIMER7_CH0, I2S1_MCK] 
  PC7:
    pincodes: [V, R]
    afs: [TIMER7_CH1, I2S2_MCK] 
  PC8:
    pincodes: [V, R]
    afs: [TIMER7_CH2] 
  PC9:
    pincodes: [V, R]
    afs: [TIMER7_CH3] 
  PC10:
    pincodes: [V, R]
    afs: [UART3_TX] 
  PC11:
    pincodes: [V, R]
    afs: [UART3_RX] 
  PC12:
    pincodes: [V, R]
    afs: [UART4_TX] 
  PC13:
    pincodes: [C, V, R]
    afs: [RTC_TAMPER] 
  PC14:
    pincodes: [C, V, R]
    afs: [OSC32IN] 
  PC15:
    pincodes: [C, V, R]
    afs: [OSC32OUT] 
  PD0:
    pincodes: [C, V, R, T]
    afs: [EXMC_D2] 
  PD1:
    pincodes: [C, V, R, T]
    afs: [EXMC_D3] 
  PD2:
    pincodes: [V, R]
    afs: [UART4_RX, TIMER2_ETI] 
  PD3:
    pincodes: [V]
    afs: [EXMC_CLK] 
  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: [EXMC_NBL0, TIMER3_ETI] 
  PE1:
    pincodes: [V]
    afs: [EXMC_NBL1] 
  PE2:
    pincodes: [V]
    afs: [EXMC_A23, TRACECK] 
  PE3:
    pincodes: [V]
    afs: [EXMC_A19, TRACED0] 
  PE4:
    pincodes: [V]
    afs: [EXMC_A20, TRACED1] 
  PE5:
    pincodes: [V]
    afs: [TRACED2, EXMC_A21] 
  PE6:
    pincodes: [V]
    afs: [TRACED3, 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:
  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]
  SPI0_IO2:
    pins: [PA2, PB6]
  SPI0_IO3:
    pins: [PA3, PB7]
  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]
