/* * Configure the specified GPIO pin. * The clocks on the necessary ports will be enabled automatically. * * Returns 0 on success, -EINVAL otherwise. */ int kinetis_gpio_config(const struct kinetis_gpio_dsc *dsc, u32 regval) { int rv; /* * Verify the function arguments */ rv = kinetis_validate_gpio(dsc); if (rv != 0) goto out; /* * Enable the clock on the port we are going to use */ rv = kinetis_periph_enable(port_clock_gate[dsc->port], 1); if (rv != 0) goto out; /* * Configure the pin */ KINETIS_PORT(dsc->port)->pcr[dsc->pin] = regval; rv = 0; out: return rv; }
/* * Updates GPIO pin configuration by unmasking PCR register value * * Returns 0 on success, -EINVAL otherwise. */ int kinetis_gpio_config_unmask(const struct kinetis_gpio_dsc *dsc, u32 mask) { int rv; rv = kinetis_validate_gpio(dsc); if (rv != 0) return rv; KINETIS_PORT(dsc->port)->pcr[dsc->pin] &= ~mask; return 0; }