diff options
| author | Ryan <fauxpark@gmail.com> | 2024-02-17 00:18:26 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-17 00:18:26 +1100 |
| commit | b8646bc40bd616167da150f6da4eda372f7de23d (patch) | |
| tree | 8029e1180ff0666a07d8ef896461333a836611fa /platforms | |
| parent | 6890c1aeb82c0c2239841db57e1bd99c3a0651a5 (diff) | |
Update naming convention for GPIO control macros (#23085)
Diffstat (limited to 'platforms')
| -rw-r--r-- | platforms/arm_atsam/gpio.h | 24 | ||||
| -rw-r--r-- | platforms/avr/gpio.h | 22 | ||||
| -rw-r--r-- | platforms/chibios/gpio.h | 34 | ||||
| -rw-r--r-- | platforms/gpio.h | 19 |
4 files changed, 58 insertions, 41 deletions
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 @@ | |||
| 15 | */ | 15 | */ |
| 16 | #pragma once | 16 | #pragma once |
| 17 | 17 | ||
| 18 | #include "stdint.h" | 18 | #include <stdint.h> |
| 19 | #include "samd51j18a.h" | 19 | #include "samd51j18a.h" |
| 20 | 20 | ||
| 21 | #include "pin_defs.h" | 21 | #include "pin_defs.h" |
| @@ -26,13 +26,13 @@ typedef uint8_t pin_t; | |||
| 26 | #define SAMD_PIN(pin) ((pin)&0x1f) | 26 | #define SAMD_PIN(pin) ((pin)&0x1f) |
| 27 | #define SAMD_PIN_MASK(pin) (1 << ((pin)&0x1f)) | 27 | #define SAMD_PIN_MASK(pin) (1 << ((pin)&0x1f)) |
| 28 | 28 | ||
| 29 | #define setPinInput(pin) \ | 29 | #define gpio_set_pin_input(pin) \ |
| 30 | do { \ | 30 | do { \ |
| 31 | PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.INEN = 1; \ | 31 | PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.INEN = 1; \ |
| 32 | PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ | 32 | PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ |
| 33 | } while (0) | 33 | } while (0) |
| 34 | 34 | ||
| 35 | #define setPinInputHigh(pin) \ | 35 | #define gpio_set_pin_input_high(pin) \ |
| 36 | do { \ | 36 | do { \ |
| 37 | PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ | 37 | PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ |
| 38 | PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ | 38 | PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ |
| @@ -40,7 +40,7 @@ typedef uint8_t pin_t; | |||
| 40 | PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \ | 40 | PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \ |
| 41 | } while (0) | 41 | } while (0) |
| 42 | 42 | ||
| 43 | #define setPinInputLow(pin) \ | 43 | #define gpio_set_pin_input_low(pin) \ |
| 44 | do { \ | 44 | do { \ |
| 45 | PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ | 45 | PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \ |
| 46 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ | 46 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ |
| @@ -48,27 +48,27 @@ typedef uint8_t pin_t; | |||
| 48 | PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \ | 48 | PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \ |
| 49 | } while (0) | 49 | } while (0) |
| 50 | 50 | ||
| 51 | #define setPinOutputPushPull(pin) \ | 51 | #define gpio_set_pin_output_push_pull(pin) \ |
| 52 | do { \ | 52 | do { \ |
| 53 | PORT->Group[SAMD_PORT(pin)].DIRSET.reg = SAMD_PIN_MASK(pin); \ | 53 | PORT->Group[SAMD_PORT(pin)].DIRSET.reg = SAMD_PIN_MASK(pin); \ |
| 54 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ | 54 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ |
| 55 | } while (0) | 55 | } while (0) |
| 56 | 56 | ||
| 57 | #define setPinOutputOpenDrain(pin) _Static_assert(0, "arm_atsam platform does not implement an open-drain output") | 57 | #define gpio_set_pin_output_open_drain(pin) _Static_assert(0, "Open-drain outputs are not available on ATSAM") |
| 58 | 58 | ||
| 59 | #define setPinOutput(pin) setPinOutputPushPull(pin) | 59 | #define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) |
| 60 | 60 | ||
| 61 | #define writePinHigh(pin) \ | 61 | #define gpio_write_pin_high(pin) \ |
| 62 | do { \ | 62 | do { \ |
| 63 | PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ | 63 | PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ |
| 64 | } while (0) | 64 | } while (0) |
| 65 | 65 | ||
| 66 | #define writePinLow(pin) \ | 66 | #define gpio_write_pin_low(pin) \ |
| 67 | do { \ | 67 | do { \ |
| 68 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ | 68 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ |
| 69 | } while (0) | 69 | } while (0) |
| 70 | 70 | ||
| 71 | #define writePin(pin, level) \ | 71 | #define gpio_write_pin(pin, level) \ |
| 72 | do { \ | 72 | do { \ |
| 73 | if (level) \ | 73 | if (level) \ |
| 74 | PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ | 74 | PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \ |
| @@ -76,6 +76,6 @@ typedef uint8_t pin_t; | |||
| 76 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ | 76 | PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \ |
| 77 | } while (0) | 77 | } while (0) |
| 78 | 78 | ||
| 79 | #define readPin(pin) ((PORT->Group[SAMD_PORT(pin)].IN.reg & SAMD_PIN_MASK(pin)) != 0) | 79 | #define gpio_read_pin(pin) ((PORT->Group[SAMD_PORT(pin)].IN.reg & SAMD_PIN_MASK(pin)) != 0) |
| 80 | 80 | ||
| 81 | #define togglePin(pin) (PORT->Group[SAMD_PORT(pin)].OUTTGL.reg = SAMD_PIN_MASK(pin)) | 81 | #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; | |||
| 22 | 22 | ||
| 23 | /* Operation of GPIO by pin. */ | 23 | /* Operation of GPIO by pin. */ |
| 24 | 24 | ||
| 25 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | 25 | #define gpio_set_pin_input(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) |
| 26 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | 26 | #define gpio_set_pin_input_high(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) |
| 27 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | 27 | #define gpio_set_pin_input_low(pin) _Static_assert(0, "GPIO pulldowns in input mode are not available on AVR") |
| 28 | #define setPinOutputPushPull(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) | 28 | #define gpio_set_pin_output_push_pull(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) |
| 29 | #define setPinOutputOpenDrain(pin) _Static_assert(0, "AVR platform does not implement an open-drain output") | 29 | #define gpio_set_pin_output_open_drain(pin) _Static_assert(0, "Open-drain outputs are not available on AVR") |
| 30 | #define setPinOutput(pin) setPinOutputPushPull(pin) | 30 | #define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) |
| 31 | 31 | ||
| 32 | #define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | 32 | #define gpio_write_pin_high(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) |
| 33 | #define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | 33 | #define gpio_write_pin_low(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) |
| 34 | #define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | 34 | #define gpio_write_pin(pin, level) ((level) ? gpio_write_pin_high(pin) : gpio_write_pin_low(pin)) |
| 35 | 35 | ||
| 36 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) | 36 | #define gpio_read_pin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) |
| 37 | 37 | ||
| 38 | #define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) | 38 | #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; | |||
| 22 | 22 | ||
| 23 | /* Operation of GPIO by pin. */ | 23 | /* Operation of GPIO by pin. */ |
| 24 | 24 | ||
| 25 | #define setPinInput(pin) palSetLineMode((pin), PAL_MODE_INPUT) | 25 | #define gpio_set_pin_input(pin) palSetLineMode((pin), PAL_MODE_INPUT) |
| 26 | #define setPinInputHigh(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLUP) | 26 | #define gpio_set_pin_input_high(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLUP) |
| 27 | #define setPinInputLow(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLDOWN) | 27 | #define gpio_set_pin_input_low(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLDOWN) |
| 28 | #define setPinOutputPushPull(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_PUSHPULL) | 28 | #define gpio_set_pin_output_push_pull(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_PUSHPULL) |
| 29 | #define setPinOutputOpenDrain(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_OPENDRAIN) | 29 | #define gpio_set_pin_output_open_drain(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_OPENDRAIN) |
| 30 | #define setPinOutput(pin) setPinOutputPushPull(pin) | 30 | #define gpio_set_pin_output(pin) gpio_set_pin_output_push_pull(pin) |
| 31 | 31 | ||
| 32 | #define writePinHigh(pin) palSetLine(pin) | 32 | #define gpio_write_pin_high(pin) palSetLine(pin) |
| 33 | #define writePinLow(pin) palClearLine(pin) | 33 | #define gpio_write_pin_low(pin) palClearLine(pin) |
| 34 | #define writePin(pin, level) \ | 34 | #define gpio_write_pin(pin, level) \ |
| 35 | do { \ | 35 | do { \ |
| 36 | if (level) { \ | 36 | if (level) { \ |
| 37 | writePinHigh(pin); \ | 37 | gpio_write_pin_high(pin); \ |
| 38 | } else { \ | 38 | } else { \ |
| 39 | writePinLow(pin); \ | 39 | gpio_write_pin_low(pin); \ |
| 40 | } \ | 40 | } \ |
| 41 | } while (0) | 41 | } while (0) |
| 42 | 42 | ||
| 43 | #define readPin(pin) palReadLine(pin) | 43 | #define gpio_read_pin(pin) palReadLine(pin) |
| 44 | 44 | ||
| 45 | #define togglePin(pin) palToggleLine(pin) | 45 | #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 @@ | |||
| 19 | 19 | ||
| 20 | #if __has_include_next("gpio.h") | 20 | #if __has_include_next("gpio.h") |
| 21 | # include_next "gpio.h" /* Include the platforms gpio.h */ | 21 | # include_next "gpio.h" /* Include the platforms gpio.h */ |
| 22 | #endif \ No newline at end of file | 22 | #endif |
| 23 | |||
| 24 | // ======== DEPRECATED DEFINES - DO NOT USE ======== | ||
| 25 | |||
| 26 | #define setPinInput(pin) gpio_set_pin_input(pin) | ||
| 27 | #define setPinInputHigh(pin) gpio_set_pin_input_high(pin) | ||
| 28 | #define setPinInputLow(pin) gpio_set_pin_input_low(pin) | ||
| 29 | #define setPinOutputPushPull(pin) gpio_set_pin_output_push_pull(pin) | ||
| 30 | #define setPinOutputOpenDrain(pin) gpio_set_pin_output_open_drain(pin) | ||
| 31 | #define setPinOutput(pin) gpio_set_pin_output_push_pull(pin) | ||
| 32 | |||
| 33 | #define writePinHigh(pin) gpio_write_pin_high(pin) | ||
| 34 | #define writePinLow(pin) gpio_write_pin_low(pin) | ||
| 35 | #define writePin(pin, level) gpio_write_pin(pin, level) | ||
| 36 | |||
| 37 | #define readPin(pin) gpio_read_pin(pin) | ||
| 38 | |||
| 39 | #define togglePin(pin) gpio_toggle_pin(pin) | ||
