chibios_config.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef USB_VBUS_PIN
  18. # define SPLIT_USB_DETECT // Force this on when dedicated pin is not used
  19. #endif
  20. #if defined(MCU_RP)
  21. # define CPU_CLOCK RP_CORE_CLK
  22. // ChibiOS uses the RP2040 timer peripheral as its real time counter, this timer
  23. // is monotonic and running at 1MHz.
  24. # define REALTIME_COUNTER_CLOCK 1000000
  25. # define USE_GPIOV1
  26. # define PAL_OUTPUT_TYPE_OPENDRAIN _Static_assert(0, "RP2040 has no Open Drain GPIO configuration, setting this is not possible");
  27. # define usb_lld_endpoint_fields
  28. # define I2C1_SCL_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4)
  29. # define I2C1_SDA_PAL_MODE I2C1_SCL_PAL_MODE
  30. # define USE_I2CV1_CONTRIB
  31. # if !defined(I2C1_CLOCK_SPEED)
  32. # define I2C1_CLOCK_SPEED 400000
  33. # endif
  34. # define SPI_SCK_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4)
  35. # define SPI_MOSI_PAL_MODE SPI_SCK_PAL_MODE
  36. # define SPI_MISO_PAL_MODE SPI_SCK_PAL_MODE
  37. #endif
  38. // STM32 compatibility
  39. #if defined(MCU_STM32)
  40. # define CPU_CLOCK STM32_SYSCLK
  41. # if defined(STM32F1XX)
  42. # define USE_GPIOV1
  43. # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_STM32_ALTERNATE_OPENDRAIN
  44. # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_STM32_ALTERNATE_PUSHPULL
  45. # else
  46. # define PAL_OUTPUT_TYPE_OPENDRAIN PAL_STM32_OTYPE_OPENDRAIN
  47. # define PAL_OUTPUT_TYPE_PUSHPULL PAL_STM32_OTYPE_PUSHPULL
  48. # define PAL_OUTPUT_SPEED_HIGHEST PAL_STM32_OSPEED_HIGHEST
  49. # define PAL_PUPDR_FLOATING PAL_STM32_PUPDR_FLOATING
  50. # endif
  51. # if defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32L1XX)
  52. # define USE_I2CV1
  53. # endif
  54. #endif
  55. // GD32 compatibility
  56. #if defined(MCU_GD32V)
  57. # define CPU_CLOCK GD32_SYSCLK
  58. # if defined(GD32VF103)
  59. # define USE_GPIOV1
  60. # define USE_I2CV1
  61. # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_GD32_ALTERNATE_OPENDRAIN
  62. # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_GD32_ALTERNATE_PUSHPULL
  63. # endif
  64. #endif
  65. // WB32 compatibility
  66. #if defined(MCU_WB32)
  67. # define CPU_CLOCK WB32_MAINCLK
  68. # if defined(WB32F3G71xx) || defined(WB32FQ95xx)
  69. # define PAL_OUTPUT_TYPE_OPENDRAIN PAL_WB32_OTYPE_OPENDRAIN
  70. # define PAL_OUTPUT_TYPE_PUSHPULL PAL_WB32_OTYPE_PUSHPULL
  71. # define PAL_OUTPUT_SPEED_HIGHEST PAL_WB32_OSPEED_HIGH
  72. # define PAL_PUPDR_FLOATING PAL_WB32_PUPDR_FLOATING
  73. # define SPI_SCK_FLAGS PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_WB32_CURRENT_LEVEL3
  74. # endif
  75. #endif
  76. #if defined(GD32VF103)
  77. /* This chip has the same API as STM32F103, but uses different names for literally the same thing.
  78. * As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake
  79. * we just redefine the GD32 names. */
  80. # include "gd32v_compatibility.h"
  81. #endif
  82. // teensy compatibility
  83. #if defined(MCU_KINETIS)
  84. # define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY
  85. # if defined(K20x) || defined(K60x) || defined(KL2x)
  86. # define USE_I2CV1
  87. # define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed
  88. # define USE_GPIOV1
  89. # endif
  90. #endif
  91. #if defined(MCU_MIMXRT1062)
  92. # include "clock_config.h"
  93. # define CPU_CLOCK BOARD_BOOTCLOCKRUN_CORE_CLOCK
  94. #endif
  95. #if defined(HT32)
  96. # define CPU_CLOCK HT32_CK_SYS_FREQUENCY
  97. # define PAL_MODE_ALTERNATE PAL_HT32_MODE_AF
  98. # define PAL_OUTPUT_TYPE_OPENDRAIN (PAL_HT32_MODE_OD | PAL_HT32_MODE_DIR)
  99. # define PAL_OUTPUT_TYPE_PUSHPULL PAL_HT32_MODE_DIR
  100. # define PAL_OUTPUT_SPEED_HIGHEST 0
  101. #endif
  102. #if !defined(REALTIME_COUNTER_CLOCK)
  103. # define REALTIME_COUNTER_CLOCK CPU_CLOCK
  104. #endif
  105. // SPI Fallbacks
  106. #ifndef SPI_SCK_FLAGS
  107. # define SPI_SCK_FLAGS PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST
  108. #endif
  109. #ifndef SPI_MOSI_FLAGS
  110. # define SPI_MOSI_FLAGS PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST
  111. #endif
  112. #ifndef SPI_MISO_FLAGS
  113. # define SPI_MISO_FLAGS PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST
  114. #endif