Skip to content

Commit

Permalink
firmware: add support for configuring all gpio pin modes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed Oct 18, 2023
1 parent 7871b38 commit e347346
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions firmware/include/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ int gpio_configure_pinmux(gpio_pin_t pin);
int gpio_configure_pinmux_and_resistors(gpio_pin_t pin, gpio_resistor_configuration_t resistor_mode);


/**
* Configures the system's pinmux to route the given GPIO pin to a physical pin
* and apply the given pin configuration.
*/
int gpio_configure_pinmux_and_pin(gpio_pin_t pin, gpio_pin_configuration_t pin_configuration);


/**
* Configures the system's pinmux to route all possible GPIO
* pins for a given port.
Expand Down
33 changes: 33 additions & 0 deletions firmware/platform/lpc43xx/drivers/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,39 @@ int gpio_configure_pinmux_and_resistors(gpio_pin_t pin, gpio_resistor_configurat
}


/**
* Configures the system's pinmux to route the given GPIO pin to a physical pin
* and apply the given pin configuration.
*
* Note that any provided function in the pin configuration will be overridden by
* the GPIO function.
*/
int gpio_configure_pinmux_and_pin(gpio_pin_t pin, gpio_pin_configuration_t pin_configuration)
{
uint8_t scu_group, scu_pin;

if (validate_port_and_pin(pin)) {
return EINVAL;
}

// Get the SCU group/pin so we can pinmux.
scu_group = gpio_get_group_number(pin);
scu_pin = gpio_get_pin_number(pin);

// If this port/pin doesn't correspond to a valid physical pin,
// fail out.
if ((scu_group == 0xff) || (scu_pin == 0xff)) {
return EINVAL;
}

// Select the pinmux function to apply.
pin_configuration.function = (pin.port == 5) ? 4 : 0;

// Finally, configure the SCU.
platform_scu_configure_pin(scu_group, scu_pin, pin_configuration);
return 0;
}


/**
* Configures the system's pinmux to route the given GPIO
Expand Down
2 changes: 2 additions & 0 deletions firmware/platform/lpc43xx/include/drivers/platform_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// For LPCxx devices, use the SCU resistor configuration as the GPIO resistor configuration.
typedef scu_resistor_configuration_t gpio_resistor_configuration_t;

// For LPCxx devices, use the SCU pin register block as the GPIO pin configuration.
typedef platform_scu_pin_register_t gpio_pin_configuration_t;

// Describe the chip's GPIO capabilities.
#define GPIO_MAX_PORTS 6
Expand Down

0 comments on commit e347346

Please sign in to comment.