Skip to content

GPIO

Methods for handling digital input/output pins.

Enums

mira_gpio_dir_t

Name Description
MIRA_GPIO_DIR_IN
MIRA_GPIO_DIR_OUT

Functions

mira_gpio_set_dir

mira_status_t mira_gpio_set_dir(mira_gpio_pin_t pin, mira_gpio_dir_t dir);

Set direction of a GPIO pin.

Parameters

Name Description
pin GPIO pin reference.
dir Direction of pin.

mira_gpio_set_pull

mira_status_t mira_gpio_set_pull(mira_gpio_pin_t pin, mira_gpio_pull_t pull);

Configure an input pin's pull resistor.

Parameters

Name Description
pin GPIO pin reference.
pull See type mira_gpio_pull_t.

Return value

Name Description
MIRA_SUCCESS Pull up/down config set successfully.
MIRA_ERROR_INVALID_VALUE Value of pull is invalid.

mira_gpio_set_value

mira_status_t mira_gpio_set_value(mira_gpio_pin_t pin, mira_bool_t value);

Set value of a GPIO output pin.

Parameters

Name Description
pin GPIO pin reference.
value Value of the pin. MIRA_TRUE for high, MIRA_FALSE for low.

mira_gpio_get_value

mira_status_t mira_gpio_get_value(mira_gpio_pin_t pin, mira_bool_t *value);

Get value of a GPIO input pin.

Parameters

Name Description
pin GPIO pin reference.
value Pointer to where to store the pin value. MIRA_TRUE for high, MIRA_FALSE for low.

mira_gpio_enable_edge_event

mira_status_t mira_gpio_enable_edge_event(mira_gpio_pin_t pin, mira_edge_t edge);

Enable mira_gpio_edge_event event generation on pin level transitions.

To change the edge for an already enabled pin, first call mira_gpio_disable_edge_event for that specific pin.

Parameters

Name Description
pin GPIO pin reference.
edge Which edge(s) to generate an event for.

Return value

Name Description
MIRA_SUCCESS Edge event successfully enabled.
MIRA_ERROR_UNKNOWN An unknown error occurred.
MIRA_ERROR_INVALID_VALUE Value out of range.
MIRA_GPIO_ERROR_INVALID_PORT Pin not a GPIO pin.
MIRA_ERROR_ALREADY_INITIALIZED Edge event already initialized.
MIRA_GPIO_ERROR_EDGE_NO_RESOURCE_AVAILABLE No resource available.
MIRA_WARNING_PARTIAL_FUNCTIONALITY Full functionality not guaranteed.
MIRA_ERROR_NOT_IMPLEMENTED Function not implemented.

mira_gpio_disable_edge_event

mira_status_t mira_gpio_disable_edge_event(mira_gpio_pin_t pin);

Disable the generation of mira_gpio_edge_event events for a specific pin.

Parameters

Name Description
pin GPIO pin reference.

Return value

Name Description
MIRA_SUCCESS Edge event successfully disabled.
MIRA_ERROR_UNKNOWN An unknown error occurred.
MIRA_ERROR_INVALID_VALUE Value out of range.
MIRA_GPIO_ERROR_INVALID_PORT Pin not a GPIO pin.
MIRA_ERROR_ALREADY_INITIALIZED Edge event already initialized.
MIRA_GPIO_ERROR_EDGE_NO_RESOURCE_AVAILABLE No resource available.
MIRA_WARNING_PARTIAL_FUNCTIONALITY Full functionality not guaranteed.
MIRA_ERROR_NOT_IMPLEMENTED Function not implemented.

mira_gpio_has_triggered_edge_event

mira_bool_t mira_gpio_has_triggered_edge_event(mira_gpio_pin_t pin);

Check if GPIO pin has triggered an edge event.

Get the edge status of a pin, and reset it to MIRA_FALSE.

Use this in combination with PROCESS_WAIT_UNTIL(c):

mira_gpio_set_dir(BUTTON_PIN, MIRA_GPIO_DIR_IN);
mira_gpio_enable_edge_event(BUTTON_PIN, MIRA_EDGE_RISING);

while (1) {
    PROCESS_WAIT_UNTIL(mira_gpio_has_triggered_edge_event(BUTTON_PIN));

    do_processing();
}

Return value

Name Description
MIRA_TRUE The pin has triggered a mira_gpio_edge_event since the last call to this function.
MIRA_FALSE The pin has not triggered a mira_gpio_edge_event since the last call to this function.