#include "ruuvi_driver_error.h"
#include "ruuvi_interface_gpio.h"
#include <stdbool.h>
#include <stdlib.h>
Go to the source code of this file.
- Author
- Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
- Date
- 2020-01-27
- Copyright
- Ruuvi Innovations Ltd, license BSD-3-Clause.
LED control.
Typical usage:
err_code =
rt_led_write (RUUVI_BOARD_LED_GREEN, RUUVI_BOARD_LEDS_ACTIVE_STATE);
_do_stuff_();
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_SUCCESS
Internal Error.
void ri_yield_indication_set(const ri_yield_state_ind_fp_t indication)
rd_status_t rt_gpio_init(void)
initialise GPIO. Pins are in high-Z state by default.
rd_status_t rt_led_init(const ri_gpio_id_t *const leds, const ri_gpio_state_t *const active_states, const size_t num_leds)
LED initialization function.
rd_status_t rt_led_activity_led_set(const ri_gpio_id_t led)
Set LED which is used to indicate activity.
rd_status_t rt_led_write(const ri_gpio_id_t led, const bool state)
LED write function. Set given LED ON or OFF.
void rt_led_activity_indicate(const bool state)
Function to indicate activity in program. Led is turned on while program is active and off while in s...
rd_status_t rt_led_uninit(void)
LED uninitialization function.
Definition in file ruuvi_task_led.h.
◆ RT_LED_OFF
#define RT_LED_OFF (false) |
◆ RT_LED_ON
◆ rt_led_activity_indicate()
void rt_led_activity_indicate |
( |
const bool |
state | ) |
|
Function to indicate activity in program. Led is turned on while program is active and off while in sleep. Call ri_yield_indication_set to setup this function to be called when entering / leaving sleep for example.
- Parameters
-
[in] | state | True to indicate activity, false to indicate sleep. |
◆ rt_led_activity_led_get()
uint16_t rt_led_activity_led_get |
( |
void |
| ) |
|
Get LED which is used to indicate activity.
- Returns
- Led which is activity indicator, RI_GPIO_ID_UNUSED if none.
◆ rt_led_activity_led_set()
Set LED which is used to indicate activity.
This function can be called before GPIO or LEDs are initialized. Call with RI_GPIO_ID_UNUSED to disable activity indication.
- Parameters
-
[in] | led | LED to indicate activity with. |
- Return values
-
RD_SUCCESS | if valid led was set. |
RD_ERROR_INVALID_PARAM | if there is no pin in LED. |
◆ rt_led_blink_once()
Function to blink led once.
The function call is ignored if previous timer is already running.
This function requires ri_timer to be initialized. Only one led can blink at once. The function turns the led on in the beginning. The interrupt calls rt_led_blink_stop to turn the led off after set time interval.
- Parameters
-
[in] | led | LED to blink. |
[in] | interval_ms | Interval of blinking in milliseconds, min and max values come from timer interface. |
- Return values
-
RD_SUCCESS | Blinking was started. |
RD_ERROR_INVALID_STATE | If led is already blinking. |
RD_ERROR_RESOURCES | If timer cannot be allocated. |
RD_ERROR_INVALID_PARAM | If there is no pin in LED. |
◆ rt_led_blink_start()
Start blinking led at 50 % duty cycle at given interval.
This function requires ri_timer to be initialized. Only one led can blink at once, you must call rt_led_blink_stop before starting to blink another led.
- Parameters
-
[in] | led | LED to blink. |
[in] | interval_ms | Interval of blinking in milliseconds, min and max values come from timer interface. |
- Return values
-
RD_SUCCESS | Blinking was started. |
RD_ERROR_INVALID_STATE | If led is already blinking. |
RD_ERROR_RESOURCES | If timer cannot be allocated. |
RD_ERROR_INVALID_PARAM | If there is no pin in LED. |
◆ rt_led_blink_stop()
Stop blinking led and leave the pin as high-drive output in inactive state.
- Parameters
-
- Return values
-
RD_SUCCESS | Blinking was stopped. |
RD_ERROR_INVALID_STATE | If given LED is not blinking. |
◆ rt_led_init()
LED initialization function.
- Returns error if leds were already initialized.
- Initializes GPIO if GPIO wasn't initialized.
- returns error code if GPIO cannot be initialized
- Configures GPIOs as high-drive output and sets LEDs as inactive.
- Sets activity led to uninitialized
- Parameters
-
[in] | leds | Array of leds used in application. |
[in] | active_states | Array of gpio states where each led is active |
[in] | num_leds | number of leds in application. |
- Return values
-
RD_SUCCESS | if no errors occured. |
RD_ERROR_INVALID_STATE | if leds were already initialized. |
error | code from stack on other error. |
- Warning
- Behaviour is undefined if led list and state list are o different size than num_leds.
◆ rt_led_is_init()
bool rt_led_is_init |
( |
void |
| ) |
|
Check if LED task has been initialized.
- Return values
-
true | LED task is initialized. |
false | LED task is not initialized. |
◆ rt_led_uninit()
LED uninitialization function.
- Returns error if leds were already initialized.
- Configures GPIOs as high-z.
- Sets activity led to uninitialized
- Return values
-
RD_SUCCESS | if no errors occured. |
error | code from stack on other error. |
◆ rt_led_write()
LED write function. Set given LED ON or OFF.
- Parameters
-
[in] | led | LED to change, use constant from RUUVI_BOARDS |
[in] | state | true to turn led on, false to turn led off. |
- Return values
-
RD_SUCCESS | if value was written |
RD_ERROR_INVALID_PARAM | if GPIO pin is not led. |
RD_ERROR_INVALID_STATE | if GPIO task is not initialized. |