Update naming convention for GPIO control macros (#23085)
This commit is contained in:
parent
6890c1aeb8
commit
b8646bc40b
12 changed files with 100 additions and 83 deletions
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "stdint.h"
|
||||
#include <stdint.h>
|
||||
#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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -19,4 +19,21 @@
|
|||
|
||||
#if __has_include_next("gpio.h")
|
||||
# include_next "gpio.h" /* Include the platforms gpio.h */
|
||||
#endif
|
||||
#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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue