qmk_firmware

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

board.c (4414B)


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