logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

chibios_config.h (7088B)


  1. /* Copyright 2019
  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. #pragma once
  17. #include "compiler_support.h"
  18. #ifndef USB_VBUS_PIN
  19. # define SPLIT_USB_DETECT // Force this on when dedicated pin is not used
  20. #endif
  21. #if defined(MCU_RP)
  22. # define CPU_CLOCK RP_CORE_CLK
  23. // ChibiOS uses the RP2040 timer peripheral as its real time counter, this timer
  24. // is monotonic and running at 1MHz.
  25. # define REALTIME_COUNTER_CLOCK 1000000
  26. # define USE_GPIOV1
  27. # define PAL_OUTPUT_TYPE_OPENDRAIN STATIC_ASSERT(0, "RP2040 has no Open Drain GPIO configuration, setting this is not possible");
  28. /* Aliases for GPIO PWM channels - every pin has at least one PWM channel
  29. * assigned */
  30. # define RP2040_PWM_CHANNEL_A 1U
  31. # define RP2040_PWM_CHANNEL_B 2U
  32. # ifndef BACKLIGHT_PAL_MODE
  33. # define BACKLIGHT_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE)
  34. # endif
  35. # define BACKLIGHT_PWM_COUNTER_FREQUENCY 1000000
  36. # ifndef BACKLIGHT_PWM_PERIOD
  37. # define BACKLIGHT_PWM_PERIOD BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048
  38. # endif
  39. # ifndef AUDIO_PWM_PAL_MODE
  40. # define AUDIO_PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE)
  41. # endif
  42. # define AUDIO_PWM_COUNTER_FREQUENCY 500000
  43. # define usb_lld_endpoint_fields
  44. # ifndef I2C1_SCL_PAL_MODE
  45. # define I2C1_SCL_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4)
  46. # endif
  47. # ifndef I2C1_SDA_PAL_MODE
  48. # define I2C1_SDA_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4)
  49. # endif
  50. # define USE_I2CV1_CONTRIB
  51. # if !defined(I2C1_CLOCK_SPEED)
  52. # define I2C1_CLOCK_SPEED 400000
  53. # endif
  54. # ifndef SPI_SCK_PAL_MODE
  55. # define SPI_SCK_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4)
  56. # endif
  57. # ifndef SPI_MOSI_PAL_MODE
  58. # define SPI_MOSI_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4)
  59. # endif
  60. # ifndef SPI_MISO_PAL_MODE
  61. # define SPI_MISO_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4)
  62. # endif
  63. # ifndef UART_TX_PAL_MODE
  64. # define UART_TX_PAL_MODE PAL_MODE_ALTERNATE_UART
  65. # endif
  66. # ifndef UART_RX_PAL_MODE
  67. # define UART_RX_PAL_MODE PAL_MODE_ALTERNATE_UART
  68. # endif
  69. # ifndef UART_CTS_PAL_MODE
  70. # define UART_CTS_PAL_MODE PAL_MODE_ALTERNATE_UART
  71. # endif
  72. # ifndef UART_RTS_PAL_MODE
  73. # define UART_RTS_PAL_MODE PAL_MODE_ALTERNATE_UART
  74. # endif
  75. #endif
  76. // STM32 compatibility
  77. #if defined(MCU_STM32)
  78. # if defined(STM32_CORE_CK)
  79. # define CPU_CLOCK STM32_CORE_CK
  80. # else
  81. # define CPU_CLOCK STM32_SYSCLK
  82. # endif
  83. # if defined(STM32F1XX)
  84. # define USE_GPIOV1
  85. # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_STM32_ALTERNATE_OPENDRAIN
  86. # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_STM32_ALTERNATE_PUSHPULL
  87. # define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
  88. # else
  89. # define PAL_OUTPUT_TYPE_OPENDRAIN PAL_STM32_OTYPE_OPENDRAIN
  90. # define PAL_OUTPUT_TYPE_PUSHPULL PAL_STM32_OTYPE_PUSHPULL
  91. # define PAL_OUTPUT_SPEED_HIGHEST PAL_STM32_OSPEED_HIGHEST
  92. # define PAL_PUPDR_FLOATING PAL_STM32_PUPDR_FLOATING
  93. # endif
  94. # if defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32L1XX)
  95. # define USE_I2CV1
  96. # endif
  97. # if defined(STM32G0XX) || defined(STM32G4XX) || defined(STM32L5XX) || defined(STM32H7XX)
  98. # define USE_USARTV3
  99. # endif
  100. #endif
  101. // GD32 compatibility
  102. #if defined(MCU_GD32V)
  103. # define CPU_CLOCK GD32_SYSCLK
  104. # if defined(GD32VF103)
  105. # define USE_GPIOV1
  106. # define USE_I2CV1
  107. # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_GD32_ALTERNATE_OPENDRAIN
  108. # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_GD32_ALTERNATE_PUSHPULL
  109. # define AUDIO_PWM_PAL_MODE PAL_MODE_GD32_ALTERNATE_PUSHPULL
  110. # endif
  111. #endif
  112. // WB32 compatibility
  113. #if defined(MCU_WB32)
  114. # define CPU_CLOCK WB32_MAINCLK
  115. # if defined(WB32F3G71xx) || defined(WB32FQ95xx)
  116. # define PAL_OUTPUT_TYPE_OPENDRAIN PAL_WB32_OTYPE_OPENDRAIN
  117. # define PAL_OUTPUT_TYPE_PUSHPULL PAL_WB32_OTYPE_PUSHPULL
  118. # define PAL_OUTPUT_SPEED_HIGHEST PAL_WB32_OSPEED_HIGH
  119. # define PAL_PUPDR_FLOATING PAL_WB32_PUPDR_FLOATING
  120. # define SPI_SCK_FLAGS PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_WB32_CURRENT_LEVEL3
  121. # endif
  122. #endif
  123. // AT32 compatibility
  124. #if defined(MCU_AT32)
  125. # define CPU_CLOCK AT32_SYSCLK
  126. # if defined(AT32F415)
  127. # define USE_GPIOV1
  128. # define USE_I2CV1
  129. # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_AT32_MUX_OPENDRAIN
  130. # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_AT32_MUX_PUSHPULL
  131. # define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
  132. # endif
  133. #endif
  134. #if defined(GD32VF103)
  135. /* This chip has the same API as STM32F103, but uses different names for literally the same thing.
  136. * As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake
  137. * we just redefine the GD32 names. */
  138. # include "gd32v_compatibility.h"
  139. #endif
  140. // teensy compatibility
  141. #if defined(MCU_KINETIS)
  142. # define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY
  143. # if defined(K20x) || defined(K60x) || defined(KL2x)
  144. # define USE_I2CV1
  145. # define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed
  146. # define USE_GPIOV1
  147. # endif
  148. #endif
  149. #if defined(MCU_MIMXRT1062)
  150. # include "clock_config.h"
  151. # define CPU_CLOCK BOARD_BOOTCLOCKRUN_CORE_CLOCK
  152. #endif
  153. #if defined(HT32)
  154. # define CPU_CLOCK HT32_CK_SYS_FREQUENCY
  155. # define PAL_MODE_ALTERNATE PAL_HT32_MODE_AF
  156. # define PAL_OUTPUT_TYPE_OPENDRAIN (PAL_HT32_MODE_OD | PAL_HT32_MODE_DIR)
  157. # define PAL_OUTPUT_TYPE_PUSHPULL PAL_HT32_MODE_DIR
  158. # define PAL_OUTPUT_SPEED_HIGHEST 0
  159. #endif
  160. #if !defined(REALTIME_COUNTER_CLOCK)
  161. # define REALTIME_COUNTER_CLOCK CPU_CLOCK
  162. #endif
  163. // SPI Fallbacks
  164. #ifndef SPI_SCK_FLAGS
  165. # define SPI_SCK_FLAGS PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST
  166. #endif
  167. #ifndef SPI_MOSI_FLAGS
  168. # define SPI_MOSI_FLAGS PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST
  169. #endif
  170. #ifndef SPI_MISO_FLAGS
  171. # define SPI_MISO_FLAGS PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST
  172. #endif