Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for configuring all gpio pin modes #35

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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