Skip to content

Commit

Permalink
Merge pull request #35 from antoinevg/antoinevg/more-flexible-scu-gpi…
Browse files Browse the repository at this point in the history
…o-configuration

Add support for configuring all gpio pin modes
  • Loading branch information
antoinevg authored Oct 19, 2023
2 parents 7871b38 + e03e2c9 commit 26e1059
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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
35 changes: 34 additions & 1 deletion firmware/platform/lpc43xx/drivers/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,47 @@ 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
* pin to a physical pin.
*/
int gpio_configure_pinmux(gpio_pin_t pin)
{
gpio_configure_pinmux_and_resistors(pin, SCU_NO_PULL);
return gpio_configure_pinmux_and_resistors(pin, SCU_NO_PULL);
}


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 26e1059

Please sign in to comment.