qmk_firmware

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

gpio.h (1764B)


      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 3 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 
     18 #include <hal.h>
     19 #include "pin_defs.h"
     20 
     21 typedef ioline_t pin_t;
     22 
     23 /* Operation of GPIO by pin. */
     24 
     25 #define gpio_set_pin_input(pin) palSetLineMode((pin), PAL_MODE_INPUT)
     26 #define gpio_set_pin_input_high(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLUP)
     27 #define gpio_set_pin_input_low(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLDOWN)
     28 #define gpio_set_pin_output_push_pull(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_PUSHPULL)
     29 #define gpio_set_pin_output_open_drain(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_OPENDRAIN)
     30 #define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin)
     31 
     32 #define gpio_write_pin_high(pin) palSetLine(pin)
     33 #define gpio_write_pin_low(pin) palClearLine(pin)
     34 #define gpio_write_pin(pin, level)    \
     35     do {                              \
     36         if (level) {                  \
     37             gpio_write_pin_high(pin); \
     38         } else {                      \
     39             gpio_write_pin_low(pin);  \
     40         }                             \
     41     } while (0)
     42 
     43 #define gpio_read_pin(pin) palReadLine(pin)
     44 
     45 #define gpio_toggle_pin(pin) palToggleLine(pin)