ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_task_led.h File Reference
#include "ruuvi_driver_error.h"
#include "ruuvi_interface_gpio.h"
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define RT_LED_ON   (true)
 turn led on More...
 
#define RT_LED_OFF   (false)
 turn led off More...
 

Functions

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. More...
 
rd_status_t rt_led_uninit (void)
 LED uninitialization function. More...
 
rd_status_t rt_led_write (const ri_gpio_id_t led, const bool state)
 LED write function. Set given LED ON or OFF. More...
 
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. More...
 
rd_status_t rt_led_activity_led_set (const ri_gpio_id_t led)
 Set LED which is used to indicate activity. More...
 
uint16_t rt_led_activity_led_get (void)
 Get LED which is used to indicate activity. More...
 
rd_status_t rt_led_blink_start (const ri_gpio_id_t led, const uint16_t interval_ms)
 Start blinking led at 50 % duty cycle at given interval. More...
 
rd_status_t rt_led_blink_once (const ri_gpio_id_t led, const uint16_t interval_ms)
 Function to blink led once. More...
 
rd_status_t rt_led_blink_stop (const ri_gpio_id_t led)
 Stop blinking led and leave the pin as high-drive output in inactive state. More...
 
bool rt_led_is_init (void)
 Check if LED task has been initialized. More...
 

Detailed Description

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2020-01-27

LED control.

Typical usage:

err_code = rt_gpio_init();
err_code = rt_led_init();
err_code = rt_led_write (RUUVI_BOARD_LED_GREEN, RUUVI_BOARD_LEDS_ACTIVE_STATE);
err_code = rt_led_activity_led_set (RUUVI_BOARD_LED_GREEN);
_do_stuff_();
err_code = rt_led_uninit();
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.

Macro Definition Documentation

◆ RT_LED_OFF

#define RT_LED_OFF   (false)

turn led off

Definition at line 53 of file ruuvi_task_led.h.

◆ RT_LED_ON

#define RT_LED_ON   (true)

turn led on

Definition at line 51 of file ruuvi_task_led.h.

Function Documentation

◆ 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]stateTrue 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()

rd_status_t rt_led_activity_led_set ( const ri_gpio_id_t  led)

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]ledLED to indicate activity with.
Return values
RD_SUCCESSif valid led was set.
RD_ERROR_INVALID_PARAMif there is no pin in LED.

◆ rt_led_blink_once()

rd_status_t rt_led_blink_once ( const ri_gpio_id_t  led,
const uint16_t  interval_ms 
)

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]ledLED to blink.
[in]interval_msInterval of blinking in milliseconds, min and max values come from timer interface.
Return values
RD_SUCCESSBlinking was started.
RD_ERROR_INVALID_STATEIf led is already blinking.
RD_ERROR_RESOURCESIf timer cannot be allocated.
RD_ERROR_INVALID_PARAMIf there is no pin in LED.

◆ rt_led_blink_start()

rd_status_t rt_led_blink_start ( const ri_gpio_id_t  led,
const uint16_t  interval_ms 
)

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]ledLED to blink.
[in]interval_msInterval of blinking in milliseconds, min and max values come from timer interface.
Return values
RD_SUCCESSBlinking was started.
RD_ERROR_INVALID_STATEIf led is already blinking.
RD_ERROR_RESOURCESIf timer cannot be allocated.
RD_ERROR_INVALID_PARAMIf there is no pin in LED.

◆ rt_led_blink_stop()

rd_status_t rt_led_blink_stop ( const ri_gpio_id_t  led)

Stop blinking led and leave the pin as high-drive output in inactive state.

Parameters
[in]ledLED to stop.
Return values
RD_SUCCESSBlinking was stopped.
RD_ERROR_INVALID_STATEIf given LED is not blinking.

◆ rt_led_init()

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.

  • 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]ledsArray of leds used in application.
[in]active_statesArray of gpio states where each led is active
[in]num_ledsnumber of leds in application.
Return values
RD_SUCCESSif no errors occured.
RD_ERROR_INVALID_STATEif leds were already initialized.
errorcode 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
trueLED task is initialized.
falseLED task is not initialized.

◆ rt_led_uninit()

rd_status_t rt_led_uninit ( void  )

LED uninitialization function.

  • Returns error if leds were already initialized.
  • Configures GPIOs as high-z.
  • Sets activity led to uninitialized
Return values
RD_SUCCESSif no errors occured.
errorcode from stack on other error.

◆ rt_led_write()

rd_status_t rt_led_write ( const ri_gpio_id_t  led,
const bool  state 
)

LED write function. Set given LED ON or OFF.

Parameters
[in]ledLED to change, use constant from RUUVI_BOARDS
[in]statetrue to turn led on, false to turn led off.
Return values
RD_SUCCESSif value was written
RD_ERROR_INVALID_PARAMif GPIO pin is not led.
RD_ERROR_INVALID_STATEif GPIO task is not initialized.