From b8646bc40bd616167da150f6da4eda372f7de23d Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 17 Feb 2024 00:18:26 +1100 Subject: Update naming convention for GPIO control macros (#23085) --- platforms/arm_atsam/gpio.h | 24 ++++++++++++------------ platforms/avr/gpio.h | 22 +++++++++++----------- platforms/chibios/gpio.h | 34 +++++++++++++++++----------------- platforms/gpio.h | 19 ++++++++++++++++++- 4 files changed, 58 insertions(+), 41 deletions(-) (limited to 'platforms') diff --git a/platforms/arm_atsam/gpio.h b/platforms/arm_atsam/gpio.h index a42aaff54d..fd8caeab0b 100644 --- a/platforms/arm_atsam/gpio.h +++ b/platforms/arm_atsam/gpio.h @@ -15,7 +15,7 @@ */ #pragma once -#include "stdint.h" +#include #include "samd51j18a.h" #include "pin_defs.h" @@ -26,13 +26,13 @@ typedef uint8_t pin_t; #define SAMD_PIN(pin) ((pin)&0x1f) #define SAMD_PIN_MASK(pin) (1 << ((pin)&0x1f)) -#define setPinInput(pin) \ +#define gpio_set_pin_input(pin) \ do { \ PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.INEN = 1; \ PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ } while (0) -#define setPinInputHigh(pin) \ +#define gpio_set_pin_input_high(pin) \ do { \ PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ @@ -40,7 +40,7 @@ typedef uint8_t pin_t; PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \ } while (0) -#define setPinInputLow(pin) \ +#define gpio_set_pin_input_low(pin) \ do { \ PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ @@ -48,27 +48,27 @@ typedef uint8_t pin_t; PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \ } while (0) -#define setPinOutputPushPull(pin) \ +#define gpio_set_pin_output_push_pull(pin) \ do { \ PORT->Group[SAMD_PORT(pin)].DIRSET.reg = SAMD_PIN_MASK(pin); \ PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ } while (0) -#define setPinOutputOpenDrain(pin) _Static_assert(0, "arm_atsam platform does not implement an open-drain output") +#define gpio_set_pin_output_open_drain(pin) _Static_assert(0, "Open-drain outputs are not available on ATSAM") -#define setPinOutput(pin) setPinOutputPushPull(pin) +#define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) -#define writePinHigh(pin) \ +#define gpio_write_pin_high(pin) \ do { \ PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ } while (0) -#define writePinLow(pin) \ +#define gpio_write_pin_low(pin) \ do { \ PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ } while (0) -#define writePin(pin, level) \ +#define gpio_write_pin(pin, level) \ do { \ if (level) \ PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ @@ -76,6 +76,6 @@ typedef uint8_t pin_t; PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ } while (0) -#define readPin(pin) ((PORT->Group[SAMD_PORT(pin)].IN.reg & SAMD_PIN_MASK(pin)) != 0) +#define gpio_read_pin(pin) ((PORT->Group[SAMD_PORT(pin)].IN.reg & SAMD_PIN_MASK(pin)) != 0) -#define togglePin(pin) (PORT->Group[SAMD_PORT(pin)].OUTTGL.reg = SAMD_PIN_MASK(pin)) +#define gpio_toggle_pin(pin) (PORT->Group[SAMD_PORT(pin)].OUTTGL.reg = SAMD_PIN_MASK(pin)) diff --git a/platforms/avr/gpio.h b/platforms/avr/gpio.h index 95f15c28dc..6f089bc663 100644 --- a/platforms/avr/gpio.h +++ b/platforms/avr/gpio.h @@ -22,17 +22,17 @@ typedef uint8_t pin_t; /* Operation of GPIO by pin. */ -#define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) -#define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) -#define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") -#define setPinOutputPushPull(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) -#define setPinOutputOpenDrain(pin) _Static_assert(0, "AVR platform does not implement an open-drain output") -#define setPinOutput(pin) setPinOutputPushPull(pin) +#define gpio_set_pin_input(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) +#define gpio_set_pin_input_high(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) +#define gpio_set_pin_input_low(pin) _Static_assert(0, "GPIO pulldowns in input mode are not available on AVR") +#define gpio_set_pin_output_push_pull(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) +#define gpio_set_pin_output_open_drain(pin) _Static_assert(0, "Open-drain outputs are not available on AVR") +#define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) -#define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) -#define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) -#define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) +#define gpio_write_pin_high(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) +#define gpio_write_pin_low(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) +#define gpio_write_pin(pin, level) ((level) ? gpio_write_pin_high(pin) : gpio_write_pin_low(pin)) -#define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) +#define gpio_read_pin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) -#define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) +#define gpio_toggle_pin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) diff --git a/platforms/chibios/gpio.h b/platforms/chibios/gpio.h index 80551abac5..a8d6554f29 100644 --- a/platforms/chibios/gpio.h +++ b/platforms/chibios/gpio.h @@ -22,24 +22,24 @@ typedef ioline_t pin_t; /* Operation of GPIO by pin. */ -#define setPinInput(pin) palSetLineMode((pin), PAL_MODE_INPUT) -#define setPinInputHigh(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLUP) -#define setPinInputLow(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLDOWN) -#define setPinOutputPushPull(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_PUSHPULL) -#define setPinOutputOpenDrain(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_OPENDRAIN) -#define setPinOutput(pin) setPinOutputPushPull(pin) +#define gpio_set_pin_input(pin) palSetLineMode((pin), PAL_MODE_INPUT) +#define gpio_set_pin_input_high(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLUP) +#define gpio_set_pin_input_low(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLDOWN) +#define gpio_set_pin_output_push_pull(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_PUSHPULL) +#define gpio_set_pin_output_open_drain(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_OPENDRAIN) +#define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) -#define writePinHigh(pin) palSetLine(pin) -#define writePinLow(pin) palClearLine(pin) -#define writePin(pin, level) \ - do { \ - if (level) { \ - writePinHigh(pin); \ - } else { \ - writePinLow(pin); \ - } \ +#define gpio_write_pin_high(pin) palSetLine(pin) +#define gpio_write_pin_low(pin) palClearLine(pin) +#define gpio_write_pin(pin, level) \ + do { \ + if (level) { \ + gpio_write_pin_high(pin); \ + } else { \ + gpio_write_pin_low(pin); \ + } \ } while (0) -#define readPin(pin) palReadLine(pin) +#define gpio_read_pin(pin) palReadLine(pin) -#define togglePin(pin) palToggleLine(pin) +#define gpio_toggle_pin(pin) palToggleLine(pin) diff --git a/platforms/gpio.h b/platforms/gpio.h index b47f6f8e43..6a87e75b01 100644 --- a/platforms/gpio.h +++ b/platforms/gpio.h @@ -19,4 +19,21 @@ #if __has_include_next("gpio.h") # include_next "gpio.h" /* Include the platforms gpio.h */ -#endif \ No newline at end of file +#endif + +// ======== DEPRECATED DEFINES - DO NOT USE ======== + +#define setPinInput(pin) gpio_set_pin_input(pin) +#define setPinInputHigh(pin) gpio_set_pin_input_high(pin) +#define setPinInputLow(pin) gpio_set_pin_input_low(pin) +#define setPinOutputPushPull(pin) gpio_set_pin_output_push_pull(pin) +#define setPinOutputOpenDrain(pin) gpio_set_pin_output_open_drain(pin) +#define setPinOutput(pin) gpio_set_pin_output_push_pull(pin) + +#define writePinHigh(pin) gpio_write_pin_high(pin) +#define writePinLow(pin) gpio_write_pin_low(pin) +#define writePin(pin, level) gpio_write_pin(pin, level) + +#define readPin(pin) gpio_read_pin(pin) + +#define togglePin(pin) gpio_toggle_pin(pin) -- cgit v1.2.3