qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

gd32v_compatibility.h (4372B)


      1 /* Copyright 2021 QMK
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #pragma once
     18 
     19 /* GD32VF103 has the same API as STM32F103, but uses different names for literally the same thing.
     20  * As of 23.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake
     21  * we just redefine the GD32 names. */
     22 
     23 /* Close your eyes kids. */
     24 #define MCU_STM32
     25 
     26 /* AFIO redefines */
     27 #define MAPR PCF0
     28 #define AFIO_MAPR_USART1_REMAP AFIO_PCF0_USART0_REMAP
     29 #define AFIO_MAPR_USART2_REMAP AFIO_PCF0_USART1_REMAP
     30 #define AFIO_MAPR_USART3_REMAP_PARTIALREMAP AFIO_PCF0_USART2_REMAP_PARTIALREMAP
     31 #define AFIO_MAPR_USART3_REMAP_FULLREMAP AFIO_PCF0_USART2_REMAP_FULLREMAP
     32 
     33 /* DMA redefines. */
     34 #define STM32_DMA_STREAM(stream) GD32_DMA_STREAM(stream)
     35 #define STM32_DMA_STREAM_ID(peripheral, channel) GD32_DMA_STREAM_ID(peripheral - 1, channel - 1)
     36 #define STM32_DMA_CR_DIR_M2P GD32_DMA_CTL_DIR_M2P
     37 #define STM32_DMA_CR_PSIZE_WORD GD32_DMA_CTL_PWIDTH_WORD
     38 #define STM32_DMA_CR_PSIZE_HWORD GD32_DMA_CTL_PWIDTH_HWORD
     39 #define STM32_DMA_CR_MSIZE_WORD GD32_DMA_CTL_MWIDTH_WORD
     40 #define STM32_DMA_CR_MSIZE_BYTE GD32_DMA_CTL_MWIDTH_BYTE
     41 #define STM32_DMA_CR_MINC GD32_DMA_CTL_MNAGA
     42 #define STM32_DMA_CR_CIRC GD32_DMA_CTL_CMEN
     43 #define STM32_DMA_CR_PL GD32_DMA_CTL_PRIO
     44 #define STM32_DMA_CR_CHSEL GD32_DMA_CTL_CHSEL
     45 #define cr1 ctl0
     46 #define cr2 ctl1
     47 #define cr3 ctl2
     48 #define dier dmainten
     49 
     50 /* ADC redefines */
     51 #if HAL_USE_ADC
     52 #    define STM32_ADC_USE_ADC1 GD32_ADC_USE_ADC0
     53 
     54 #    define smpr1 sampt0
     55 #    define smpr2 sampt1
     56 #    define sqr1 rsq0
     57 #    define sqr2 rsq1
     58 #    define sqr3 rsq2
     59 
     60 #    define ADC_SMPR2_SMP_AN0 ADC_SAMPT1_SMP_SPT0
     61 #    define ADC_SMPR2_SMP_AN1 ADC_SAMPT1_SMP_SPT1
     62 #    define ADC_SMPR2_SMP_AN2 ADC_SAMPT1_SMP_SPT2
     63 #    define ADC_SMPR2_SMP_AN3 ADC_SAMPT1_SMP_SPT3
     64 #    define ADC_SMPR2_SMP_AN4 ADC_SAMPT1_SMP_SPT4
     65 #    define ADC_SMPR2_SMP_AN5 ADC_SAMPT1_SMP_SPT5
     66 #    define ADC_SMPR2_SMP_AN6 ADC_SAMPT1_SMP_SPT6
     67 #    define ADC_SMPR2_SMP_AN7 ADC_SAMPT1_SMP_SPT7
     68 #    define ADC_SMPR2_SMP_AN8 ADC_SAMPT1_SMP_SPT8
     69 #    define ADC_SMPR2_SMP_AN9 ADC_SAMPT1_SMP_SPT9
     70 
     71 #    define ADC_SMPR1_SMP_AN10 ADC_SAMPT0_SMP_SPT10
     72 #    define ADC_SMPR1_SMP_AN11 ADC_SAMPT0_SMP_SPT11
     73 #    define ADC_SMPR1_SMP_AN12 ADC_SAMPT0_SMP_SPT12
     74 #    define ADC_SMPR1_SMP_AN13 ADC_SAMPT0_SMP_SPT13
     75 #    define ADC_SMPR1_SMP_AN14 ADC_SAMPT0_SMP_SPT14
     76 #    define ADC_SMPR1_SMP_AN15 ADC_SAMPT0_SMP_SPT15
     77 
     78 #    define ADC_SQR3_SQ1_N ADC_RSQ2_RSQ1_N
     79 #endif
     80 
     81 /* FLASH redefines */
     82 #if defined(EEPROM_ENABLE)
     83 #    define SR STAT
     84 #    define FLASH_SR_BSY FLASH_STAT_BUSY
     85 #    define FLASH_SR_PGERR FLASH_STAT_PGERR
     86 #    define FLASH_SR_EOP FLASH_STAT_ENDF
     87 #    define FLASH_SR_WRPRTERR FLASH_STAT_WPERR
     88 #    define FLASH_SR_WRPERR FLASH_SR_WRPRTERR
     89 #    define FLASH_OBR_OPTERR FLASH_OBSTAT_OBERR
     90 #    define AR ADDR
     91 #    define CR CTL
     92 #    define FLASH_CR_PER FLASH_CTL_PER
     93 #    define FLASH_CR_STRT FLASH_CTL_START
     94 #    define FLASH_CR_LOCK FLASH_CTL_LK
     95 #    define FLASH_CR_PG FLASH_CTL_PG
     96 #    define KEYR KEY
     97 #endif
     98 
     99 /* Serial USART redefines. */
    100 #if HAL_USE_SERIAL
    101 #    if !defined(SERIAL_USART_CR1)
    102 #        define SERIAL_USART_CR1 (USART_CTL0_PCEN | USART_CTL0_PM | USART_CTL0_WL) // parity enable, odd parity, 9 bit length
    103 #    endif
    104 #    if !defined(SERIAL_USART_CR2)
    105 #        define SERIAL_USART_CR2 (USART_CTL1_STB_1) // 2 stop bits
    106 #    endif
    107 #    if !defined(SERIAL_USART_CR3)
    108 #        define SERIAL_USART_CR3 0x0
    109 #    endif
    110 #    define USART_CR3_HDSEL USART_CTL2_HDEN
    111 #    define CCR CHCV
    112 #endif
    113 
    114 /* SPI redefines. */
    115 #if HAL_USE_SPI
    116 #    define SPI_CR1_LSBFIRST SPI_CTL0_LF
    117 #    define SPI_CR1_CPHA SPI_CTL0_CKPH
    118 #    define SPI_CR1_CPOL SPI_CTL0_CKPL
    119 #    define SPI_CR1_BR_0 SPI_CTL0_PSC_0
    120 #    define SPI_CR1_BR_1 SPI_CTL0_PSC_1
    121 #    define SPI_CR1_BR_2 SPI_CTL0_PSC_2
    122 #endif