The "PIO" variant supports multiplexing up to two peripherals per pin in addition to GPIO (software control). Each pin has configurable pull-up, glitch filter, interrupt and multi-drive capabilities.
The "GPIO" variant supports multiplexing up to four peripherals per pin in addition to GPIO. Each pin has configurable pull-up/pull-down/buskeeper, glitch filter, interrupt, open-drain and schmitt-trigger capabilities, as well as configurable drive strength and slew rate control.
Both controllers are configured using the same API, but the functions may accept different values for some parameters depending on the actual portmux implementation, and some parameters may be ignored by one of the implementation (e.g. the "PIO" implementation will ignore the drive strength flags since the hardware doesn't support configurable drive strength.)
The available ports are defined on the form
#define PORTMUX_PORT_A (something)
where "A" matches the identifier given in the chip's data sheet, and "something" is whatever the portmux implementation needs to identify the port (usually a memory address).
The pin mask is a bitmask of type pin_mask_t, where each '1' bit indicates a pin to apply the current operation to. The width of the bitmask is implementation specific, but it's usually 32 bits on 32-bit architectures.
enum portmux_function {
PORTMUX_FUNC_A,
PORTMUX_FUNC_B,
};
To configure a set of pins to be connected to a given peripheral function, the following function is used.
void portmux_select_peripheral(void *port, pin_mask_t pin_mask, enum portmux_function func, unsigned long flags);
To configure a set of pins to be controlled by software (GPIO), the following function is used. In this case, no "function" argument is required since "GPIO" is a function in its own right.
void portmux_select_gpio(void *port, pin_mask_t pin_mask, unsigned long flags);
Both of these functions take a "flags" parameter which may be used to alter the default configuration of the pin. This is a bitmask of various flags defined in an implementation-specific way, but the names of the flags are the same on all implementations.
PORTMUX_DIR_OUTPUT: Output pin. Setting this flag enables the output driver.PORTMUX_DIR_INPUT: Input pin. Setting this flag disables the output driver.
PORTMUX_INIT_HIGH: Drive the pin high (Vdd) initially.PORTMUX_INIT_LOW: Drive the pin low (Vss) initially.Note that some portmux implementations may not support all of these flags. If PORTMUX_BUSKEEPER is specified but not supported by the hardware, the driver may enable a pull-up instead. If PORTMUX_PULL_DOWN is specified but not supported by the hardware, it will be ignored.
PORTMUX_PULL_UP: Weak pull-up to VddPORTMUX_PULL_DOWN: Weak pull-down to VssPORTMUX_BUSKEEPER: Enable pull-up or pull-down depending on the state of the pin when it is released. This will prevent the pin from toggling.
PORTMUX_DRIVE_MIN: Minimum drive strength. This will give low power consumption, but may cause corruption of high-speed signals.PORTMUX_DRIVE_LOW: Low drive strength. Somewhat higher power consumption, but tolerates higher speed.PORTMUX_DRIVE_HIGH: High drive strength. Higher power consumption, can handle higher speeds.PORTMUX_DRIVE_MAX: Maximum drive strength. Highest power consumption, but can handle very high-speed signals.Note that setting the drive strength too high may cause excessive overshoot and EMI problems, which may in turn cause signal corruption.
This mode is also known as "multi-drive" mode.
PORTMUX_OPEN_DRAIN
All of these functions take a drive_strength parameter, which must be one of the PORTMUX_DRIVE_x flags specified above. Any other portmux flags will be silently filtered out.
void gpio_set_value(unsigned int pin, bool value); bool gpio_get_value(unsigned int pin);
1.5.8