GPIO¶
Methods for handling digital input/output pins.
Defines¶
| Name | Value | Description | 
|---|---|---|
MIRA_GPIO_PIN(_PORT, _PIN) | 
(((_PORT) << 8) | (_PIN)) | Generate a reference to a pin, given port and pin number. | 
MIRA_GPIO_PIN_UNDEFINED | 
((mira_gpio_pin_t) (-1)) | 
Types¶
| Name | Type | Description | 
|---|---|---|
mira_gpio_pin_t | 
uint16_t | 
Reference to a given hardware pin. Contains port and pin number.  | 
Enums¶
mira_gpio_dir_t¶
| Name | Value | Description | 
|---|---|---|
MIRA_GPIO_DIR_IN | 
||
MIRA_GPIO_DIR_OUT | 
Variables¶
| Type | Name | Description | 
|---|---|---|
process_event_t | 
mira_gpio_edge_event | 
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
| Parameter | Description | 
|---|---|
pin | 
GPIO pin reference. | 
dir | 
Direction of pin. | 
Return
MIRA_SUCCESS if successful.
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
| Parameter | Description | 
|---|---|
pin | 
GPIO pin reference. | 
pull | 
See type mira_gpio_pull_t. | 
Return
See enum definition.
| Value | 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
| Parameter | Description | 
|---|---|
pin | 
GPIO pin reference. | 
value | 
Value of the pin. MIRA_TRUE for high, MIRA_FALSE for low. | 
Return
MIRA_SUCCESS if successful.
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
| Parameter | Description | 
|---|---|
pin | 
GPIO pin reference. | 
value | 
Pointer to where to store the pin value. MIRA_TRUE for high, MIRA_FALSE for low. | 
Return
MIRA_SUCCESS if successful.
mira_gpio_enable_edge_event¶
mira_status_t mira_gpio_enable_edge_event( mira_gpio_pin_t pin, mira_edge_t edge);
Enable 
To change the edge for an already enabled pin, first call mira_gpio_disable_edge_event for that specific pin. 
Parameters
| Parameter | Description | 
|---|---|
pin | 
GPIO pin reference. | 
edge | 
Which edge(s) to generate an event for. | 
Return
See enum definition.
| Value | 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
Parameters
| Parameter | Description | 
|---|---|
pin | 
GPIO pin reference. | 
Return
See enum definition.
| Value | 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 | 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. |