In this use case, the PORT module is configured for:
- One pin in input mode, with pull-up enabled
- One pin in output mode
This use case sets up the PORT to read the current state of a GPIO pin set as an input, and mirrors the opposite logical state on a pin configured as an output.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
void configure_port_pins(void)
{
}
Add to user application initialization (typically the start of main()
):
Workflow
- Create a PORT module pin configuration struct, which can be filled out to adjust the configuration of a single port pin.
- Initialize the pin configuration struct with the module's default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Adjust the configuration struct to request an input pin.
- Configure push button pin with the initialized pin configuration struct, to enable the input sampler on the pin.
- Adjust the configuration struct to request an output pin.
- Note
- The existing configuration struct may be re-used, as long as any values that have been altered from the default settings are taken into account by the user application.
- Configure LED pin with the initialized pin configuration struct, to enable the output driver on the pin.
Use Case
Code
Copy-paste the following code to your user application:
Workflow
- Read in the current input sampler state of push button pin, which has been configured as an input in the use-case setup code.
- Write the inverted pin level state to LED pin, which has been configured as an output in the use-case setup code.