logo

qmk_firmware

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

board.c (4414B)


  1. /*
  2. Copyright (C) 2020 Yaotian Feng, Codetector<codetector@codetector.cn>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "hal.h"
  14. /* ============ Private Defines ===================== */
  15. /* ============ Function Prototypes ================== */
  16. #define PBIT(PORT, LINE) ((PAL_PORT(LINE) == PORT) ? (1 << PAL_PAD(LINE)) : 0)
  17. #define PAFIO_L(PORT, LINE, AF) (((PAL_PORT(LINE) == PORT) && (PAL_PAD(LINE) < 8)) ? (AF << (PAL_PAD(LINE) << 2)) : 0)
  18. #define PAFIO_H(PORT, LINE, AF) (((PAL_PORT(LINE) == PORT) && (PAL_PAD(LINE) >= 8)) ? (AF << ((PAL_PAD(LINE) - 8) << 2)) : 0)
  19. #define PAFIO(PORT, N, LINE, AF) ((N) ? PAFIO_H(PORT, LINE, AF) : PAFIO_L(PORT, LINE, AF))
  20. #define OUT_BITS(PORT) (PBIT(PORT, B5) | PBIT(PORT, B4) | PBIT(PORT, B3) | PBIT(PORT, B2) | PBIT(PORT, D1) | 0)
  21. #define IN_BITS(PORT) (PBIT(PORT, C4) | PBIT(PORT, C5) | PBIT(PORT, D0) | PBIT(PORT, B15) | PBIT(PORT, C11) | PBIT(PORT, A15) | PBIT(PORT, C12) | PBIT(PORT, C13) | PBIT(PORT, A8) | PBIT(PORT, A10) | PBIT(PORT, A11) | PBIT(PORT, A14) | PBIT(PORT, D2) | PBIT(PORT, D3) | 0)
  22. // Alternate Functions
  23. #define AF_BITS(PORT, N) (PAFIO(PORT, N, LINE_UART_RX, AFIO_USART) | PAFIO(PORT, N, LINE_UART_TX, AFIO_USART) | PAFIO(PORT, N, LINE_BT_UART_TX, AFIO_USART) | PAFIO(PORT, N, LINE_BT_UART_RX, AFIO_USART) | PAFIO(PORT, N, B5, AFIO_GPIO) | PAFIO(PORT, N, B4, AFIO_GPIO) | PAFIO(PORT, N, B3, AFIO_GPIO) | PAFIO(PORT, N, B2, AFIO_GPIO) | PAFIO(PORT, N, D1, AFIO_GPIO) | PAFIO(PORT, N, C4, AFIO_GPIO) | PAFIO(PORT, N, C5, AFIO_GPIO) | PAFIO(PORT, N, D0, AFIO_GPIO) | PAFIO(PORT, N, B15, AFIO_GPIO) | PAFIO(PORT, N, C11, AFIO_GPIO) | PAFIO(PORT, N, A15, AFIO_GPIO) | PAFIO(PORT, N, C12, AFIO_GPIO) | PAFIO(PORT, N, C13, AFIO_GPIO) | PAFIO(PORT, N, A8, AFIO_GPIO) | PAFIO(PORT, N, A10, AFIO_GPIO) | PAFIO(PORT, N, A11, AFIO_GPIO) | PAFIO(PORT, N, A14, AFIO_GPIO) | PAFIO(PORT, N, D2, AFIO_GPIO) | PAFIO(PORT, N, D3, AFIO_GPIO) | 0)
  24. /**
  25. * @brief PAL setup.
  26. * @details Digital I/O ports static configuration as defined in @p board.h.
  27. * This variable is used by the HAL when initializing the PAL driver.
  28. */
  29. const PALConfig pal_default_config = {
  30. // GPIO A
  31. .setup[0] =
  32. {
  33. .DIR = OUT_BITS(IOPORTA),
  34. .INE = IN_BITS(IOPORTA),
  35. .PU = IN_BITS(IOPORTA),
  36. .PD = 0x0000,
  37. .OD = 0x0000,
  38. .DRV = 0x0000,
  39. .LOCK = 0x0000,
  40. .OUT = 0x0000,
  41. .CFG[0] = AF_BITS(IOPORTA, 0),
  42. .CFG[1] = AF_BITS(IOPORTA, 1),
  43. },
  44. // GPIO B
  45. .setup[1] =
  46. {
  47. .DIR = OUT_BITS(IOPORTB),
  48. .INE = IN_BITS(IOPORTB),
  49. .PU = IN_BITS(IOPORTB),
  50. .PD = 0x0000,
  51. .OD = 0x0000,
  52. .DRV = 0x0000,
  53. .LOCK = 0x0000,
  54. .OUT = 0x0000,
  55. .CFG[0] = AF_BITS(IOPORTB, 0),
  56. .CFG[1] = AF_BITS(IOPORTB, 1),
  57. },
  58. // GPIO C
  59. .setup[2] =
  60. {
  61. .DIR = OUT_BITS(IOPORTC),
  62. .INE = IN_BITS(IOPORTC),
  63. .PU = IN_BITS(IOPORTC),
  64. .PD = 0x0000,
  65. .OD = 0x0000,
  66. .DRV = 0x0000,
  67. .LOCK = 0x0000,
  68. .OUT = 0x0000,
  69. .CFG[0] = AF_BITS(IOPORTC, 0),
  70. .CFG[1] = AF_BITS(IOPORTC, 1),
  71. },
  72. // GPIO D
  73. .setup[3] =
  74. {
  75. .DIR = OUT_BITS(IOPORTD),
  76. .INE = IN_BITS(IOPORTD),
  77. .PU = IN_BITS(IOPORTD),
  78. .PD = 0x0000,
  79. .OD = 0x0000,
  80. .DRV = 0x0000,
  81. .LOCK = 0x0000,
  82. .OUT = 0x0000,
  83. .CFG[0] = AF_BITS(IOPORTD, 0),
  84. .CFG[1] = AF_BITS(IOPORTD, 1),
  85. },
  86. .ESSR[0] = 0x00000000,
  87. .ESSR[1] = 0x00000000,
  88. };
  89. void __early_init(void) { ht32_clock_init(); }
  90. void boardInit(void) {}