13.8.1.1.3 Workflow

  1. Create a PORT module pin configuration struct, which can be filled out to adjust the configuration of a single port pin.
    struct port_config config_port_pin;
    
  2. Initialize the pin configuration struct with the module's default values.
    port_get_config_defaults(&config_port_pin);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  3. Adjust the configuration struct to request an input pin.
    config_port_pin.direction  = PORT_PIN_DIR_INPUT;
    config_port_pin.input_pull = PORT_PIN_PULL_UP;
    
  4. Configure push button pin with the initialized pin configuration struct, to enable the input sampler on the pin.
    port_pin_set_config(BUTTON_0_PIN, &config_port_pin);
    
  5. Adjust the configuration struct to request an output pin.
    config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
    
    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.
  6. Configure LED pin with the initialized pin configuration struct, to enable the output driver on the pin.
    port_pin_set_config(LED_0_PIN, &config_port_pin);