MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LED

Overview

Data Structures

struct  led_pin_config_t
 The pin config struct of LED. More...
 
struct  led_rgb_config_t
 The pin config struct of rgb LED. More...
 
struct  led_monochrome_config_t
 The pin config struct of monochrome LED. More...
 
struct  led_config_t
 The config struct of LED. More...
 
struct  led_flash_config_t
 The flash config struct of LED. More...
 

Macros

#define LED_DIMMING_ENABLEMENT   (0U)
 Definition to determine whether enable dimming. More...
 
#define LED_COLOR_WHEEL_ENABLEMENT   (0U)
 Definition to determine whether enable color wheel. More...
 
#define LED_HANDLE_SIZE   ((16U * 3U) + 36U)
 Definition of LED handle size. More...
 
#define LED_HANDLE_DEFINE(name)   uint32_t name[((LED_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
 Defines the led handle. More...
 
#define LED_HANDLE_ARRAY_DEFINE(name, count)   uint32_t name[count][((LED_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
 Defines the led handle array. More...
 
#define LED_TIMER_INTERVAL   (100U)
 Definition of LED timer interval,unit is ms. More...
 
#define LED_DIMMING_UPDATE_INTERVAL   (100U)
 Definition of LED dimming update interval,unit is ms. More...
 
#define LED_FLASH_CYCLE_FOREVER   (0xFFFFFFFFU)
 Definition of LED flash cycle forever. More...
 
#define LED_BLIP_INTERVAL   (250U)
 Definition of LED blip interval,unit is ms. More...
 
#define LED_MAKE_COLOR(r, g, b)   ((led_color_t)((((led_color_t)b) << 16) | (((led_color_t)g) << 8) | ((led_color_t)r)))
 Definition to set LED color. More...
 

Typedefs

typedef void * led_handle_t
 The handle of LED.
 
typedef uint32_t led_color_t
 The color struct of LED.
 

Enumerations

enum  led_status_t {
  kStatus_LED_Success = kStatus_Success,
  kStatus_LED_Error = MAKE_STATUS(kStatusGroup_LED, 1),
  kStatus_LED_InvalidParameter = MAKE_STATUS(kStatusGroup_LED, 2)
}
 The status type of LED. More...
 
enum  led_flash_type_t { kLED_FlashOneColor = 0x00U }
 The flash type of LED. More...
 
enum  _led_color {
  kLED_Black = LED_MAKE_COLOR(0, 0, 0),
  kLED_Red = LED_MAKE_COLOR(255, 0, 0),
  kLED_Green = LED_MAKE_COLOR(0, 255, 0),
  kLED_Yellow = LED_MAKE_COLOR(255, 255, 0),
  kLED_Blue = LED_MAKE_COLOR(0, 0, 255),
  kLED_Pink = LED_MAKE_COLOR(255, 0, 255),
  kLED_Aquamarine = LED_MAKE_COLOR(0, 255, 255),
  kLED_White = LED_MAKE_COLOR(255, 255, 255)
}
 The color type of LED. More...
 
enum  led_type_t {
  kLED_TypeRgb = 0x01U,
  kLED_TypeMonochrome = 0x02U
}
 The type of LED. More...
 

Functions

led_status_t LED_Init (led_handle_t ledHandle, led_config_t *ledConfig)
 Initializes a LED with the LED handle and the user configuration structure. More...
 
led_status_t LED_Deinit (led_handle_t ledHandle)
 Deinitializes a LED instance. More...
 
led_status_t LED_SetColor (led_handle_t ledHandle, led_color_t ledRgbColor)
 Sets the LED color. More...
 
led_status_t LED_TurnOnOff (led_handle_t ledHandle, uint8_t turnOnOff)
 Turns on or off the LED. More...
 
led_status_t LED_Blip (led_handle_t ledHandle)
 Blips the LED. More...
 
led_status_t LED_Flash (led_handle_t ledHandle, led_flash_config_t *ledFlash)
 Flashes the LED. More...
 
led_status_t LED_Dimming (led_handle_t ledHandle, uint16_t dimmingPeriod, uint8_t increasement)
 Adjusts the brightness of the LED. More...
 
led_status_t LED_EnterLowpower (led_handle_t ledHandle)
 Prepares to enter low power consumption. More...
 
led_status_t LED_ExitLowpower (led_handle_t ledHandle)
 Restores from low power consumption. More...
 

Data Structure Documentation

struct led_pin_config_t

Data Fields

uint8_t dimmingEnable
 dimming enable, 0 - disable, 1 - enable
 
uint8_t port
 GPIO Port.
 
uint8_t pin
 GPIO Pin.
 
uint8_t pinStateDefault
 GPIO Pin voltage when LED is off (0 - low level, 1 - high level) More...
 
uint32_t sourceClock
 The clock source of the PWM module.
 
uint8_t instance
 PWM instance of the pin.
 
uint8_t channel
 PWM channel of the pin.
 

Field Documentation

uint8_t led_pin_config_t::pinStateDefault

The Pin voltage when LED is off (0 - low level, 1 - high level)

struct led_rgb_config_t

Data Fields

led_pin_config_t redPin
 Red pin setting.
 
led_pin_config_t greenPin
 Green pin setting.
 
led_pin_config_t bluePin
 Blue pin setting.
 
struct led_monochrome_config_t

Data Fields

led_pin_config_t monochromePin
 Monochrome pin setting.
 
struct led_config_t
struct led_flash_config_t

Data Fields

uint32_t times
 Flash times, LED_FLASH_CYCLE_FOREVER for forever.
 
uint16_t period
 Flash period, unit is ms.
 
led_flash_type_t flashType
 Flash type, one color or color wheel. More...
 
uint8_t duty
 Duty of the LED on for one period (duration = duty * period / 100). More...
 

Field Documentation

led_flash_type_t led_flash_config_t::flashType

Refer to led_flash_type_t

uint8_t led_flash_config_t::duty

Macro Definition Documentation

#define LED_DIMMING_ENABLEMENT   (0U)

Enable or disable the dimming feature

#define LED_COLOR_WHEEL_ENABLEMENT   (0U)

Enable or disable the color wheel feature

#define LED_HANDLE_SIZE   ((16U * 3U) + 36U)
#define LED_HANDLE_DEFINE (   name)    uint32_t name[((LED_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]

This macro is used to define a 4 byte aligned led handle. Then use "(led_handle_t)name" to get the led handle.

The macro should be global and could be optional. You could also define led handle by yourself.

This is an example,

* LED_HANDLE_DEFINE(ledHandle);
*
Parameters
nameThe name string of the led handle.
#define LED_HANDLE_ARRAY_DEFINE (   name,
  count 
)    uint32_t name[count][((LED_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]

This macro is used to define a 4 byte aligned led handle array. Then use "(led_handle_t)name[0]" to get the first led handle.

The macro should be global and could be optional. You could also define these led handle by yourself.

This is an example,

* LED_HANDLE_ARRAY_DEFINE(ledHandleArray,1);
*
Parameters
nameThe name string of the led handle array.
#define LED_TIMER_INTERVAL   (100U)
#define LED_DIMMING_UPDATE_INTERVAL   (100U)
#define LED_FLASH_CYCLE_FOREVER   (0xFFFFFFFFU)
#define LED_BLIP_INTERVAL   (250U)
#define LED_MAKE_COLOR (   r,
  g,
 
)    ((led_color_t)((((led_color_t)b) << 16) | (((led_color_t)g) << 8) | ((led_color_t)r)))

Enumeration Type Documentation

Enumerator
kStatus_LED_Success 

Success.

kStatus_LED_Error 

Failed.

kStatus_LED_InvalidParameter 

Invalid parameter.

Enumerator
kLED_FlashOneColor 

Fast with one color.

enum _led_color
Enumerator
kLED_Black 

Black.

kLED_Red 

Red.

kLED_Green 

Green.

kLED_Yellow 

Yellow.

kLED_Blue 

Blue.

kLED_Pink 

Pink.

kLED_Aquamarine 

Aquamarine.

kLED_White 

White.

enum led_type_t
Enumerator
kLED_TypeRgb 

RGB LED.

kLED_TypeMonochrome 

Monochrome LED.

Function Documentation

led_status_t LED_Init ( led_handle_t  ledHandle,
led_config_t ledConfig 
)

This function configures the LED with user-defined settings. The user can configure the configuration structure. The parameter ledHandle is a pointer to point to a memory space of size LED_HANDLE_SIZE allocated by the caller. The LED supports two types LED, RGB and monochrome. Please refer to led_type_t. These two types can be set by using led_config_t. The LED also supports LED dimming mode.

Example below shows how to use this API to configure the LED. For monochrome LED,

* static LED_HANDLE_DEFINE(s_ledMonochromeHandle);
* led_config_t ledMonochromeConfig;
* ledMonochromeConfig.type = kLED_TypeMonochrome;
* ledMonochromeConfig.ledMonochrome.monochromePin.dimmingEnable = 0;
* ledMonochromeConfig.ledMonochrome.monochromePin.gpio.port = 0;
* ledMonochromeConfig.ledMonochrome.monochromePin.gpio.pin = 1;
* ledMonochromeConfig.ledMonochrome.monochromePin.gpio.pinStateDefault = 0;
* LED_Init((led_handle_t)s_ledMonochromeHandle, &ledMonochromeConfig);
*

For rgb LED,

* static LED_HANDLE_DEFINE(s_ledRgbHandle);
* led_config_t ledRgbConfig;
* ledRgbConfig.type = kLED_TypeRgb;
* ledRgbConfig.ledRgb.redPin.dimmingEnable = 0;
* ledRgbConfig.ledRgb.redPin.gpio.port = 0;
* ledRgbConfig.ledRgb.redPin.gpio.pin = 1;
* ledRgbConfig.ledRgb.redPin.gpio.pinStateDefault = 0;
* ledRgbConfig.ledRgb.greenPin.dimmingEnable = 0;
* ledRgbConfig.ledRgb.greenPin.gpio.port = 0;
* ledRgbConfig.ledRgb.greenPin.gpio.pin = 2;
* ledRgbConfig.ledRgb.greenPin.gpio.pinStateDefault = 0;
* ledRgbConfig.ledRgb.bluePin.dimmingEnable = 0;
* ledRgbConfig.ledRgb.bluePin.gpio.port = 0;
* ledRgbConfig.ledRgb.bluePin.gpio.pin = 3;
* ledRgbConfig.ledRgb.bluePin.gpio.pinStateDefault = 0;
* LED_Init((led_handle_t)s_ledRgbHandle, &ledRgbConfig);
*

For dimming monochrome LED,

* static LED_HANDLE_DEFINE(s_ledMonochromeHandle);
* led_config_t ledMonochromeConfig;
* ledMonochromeConfig.type = kLED_TypeMonochrome;
* ledMonochromeConfig.ledMonochrome.monochromePin.dimmingEnable = 1;
* ledMonochromeConfig.ledMonochrome.monochromePin.dimming.sourceClock = 48000000;
* ledMonochromeConfig.ledMonochrome.monochromePin.dimming.instance = 0;
* ledMonochromeConfig.ledMonochrome.monochromePin.dimming.channel = 1;
* ledMonochromeConfig.ledMonochrome.monochromePin.dimming.pinStateDefault = 0;
* LED_Init((led_handle_t)s_ledMonochromeHandle, &ledMonochromeConfig);
*

For multiple LEDs,

* static LED_HANDLE_ARRAY_DEFINE(s_ledArrayHandle, count);
* led_config_t ledArrayConfig[count];
* for(uint8_t i = 0; i < count; i++ )
* {
* ledArrayConfig[i].type = kLED_TypeMonochrome;
* ledArrayConfig[i].ledMonochrome.monochromePin.dimmingEnable = 1;
* ledArrayConfig[i].ledMonochrome.monochromePin.dimming.sourceClock = 48000000;
* ledArrayConfig[i].ledMonochrome.monochromePin.dimming.instance = 0;
* ledArrayConfig[i].ledMonochrome.monochromePin.dimming.channel = 1;
* ledArrayConfig[i].ledMonochrome.monochromePin.dimming.pinStateDefault = 0;
* LED_Init((led_handle_t)s_ledArrayHandle[i], &ledArrayConfig[i]);
* }
*
Parameters
ledHandlePointer to point to a memory space of size LED_HANDLE_SIZE allocated by the caller. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. You can define one handle in the following two ways: LED_HANDLE_DEFINE(ledHandle); or uint32_t ledHandle[((LED_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; You can define multiple handles in the following way: LED_HANDLE_ARRAY_DEFINE(ledHandleArray, count);
ledConfigPointer to user-defined configuration structure.
Return values
kStatus_LED_ErrorAn error occurred.
kStatus_LED_SuccessLED initialization succeed.
led_status_t LED_Deinit ( led_handle_t  ledHandle)

This function deinitializes the LED instance.

Parameters
ledHandleLED handle pointer.
Return values
kStatus_LED_SuccessLED de-initialization succeed.
led_status_t LED_SetColor ( led_handle_t  ledHandle,
led_color_t  ledRgbColor 
)

This function sets the LED color. The function only supports the RGB LED. The default color is kLED_White. Please refer to LED_MAKE_COLOR(r,g,b).

Parameters
ledHandleLED handle pointer.
ledRgbColorLED color.
Return values
kStatus_LED_ErrorAn error occurred.
kStatus_LED_SuccessColor setting succeed.
led_status_t LED_TurnOnOff ( led_handle_t  ledHandle,
uint8_t  turnOnOff 
)

This function turns on or off the led.

Parameters
ledHandleLED handle pointer.
turnOnOffSetting value, 1 - turns on, 0 - turns off.
Return values
kStatus_LED_ErrorAn error occurred.
kStatus_LED_SuccessSuccessfully turn on or off the LED.
led_status_t LED_Blip ( led_handle_t  ledHandle)

This function blips the led.

Parameters
ledHandleLED handle pointer.
Return values
kStatus_LED_ErrorAn error occurred.
kStatus_LED_SuccessSuccessfully blip the LED.
led_status_t LED_Flash ( led_handle_t  ledHandle,
led_flash_config_t ledFlash 
)

This function flashes the led. The flash configuration is passed by using led_flash_config_t.

Parameters
ledHandleLED handle pointer.
ledFlashLED flash configuration.
Return values
kStatus_LED_ErrorAn error occurred.
kStatus_LED_SuccessSuccessfully flash the LED.
led_status_t LED_Dimming ( led_handle_t  ledHandle,
uint16_t  dimmingPeriod,
uint8_t  increasement 
)

This function adjust the brightness of the LED.

Parameters
ledHandleLED handle pointer.
dimmingPeriodThe duration of the dimming (unit is ms).
increasementBrighten or dim (1 - brighten, 0 - dim).
Return values
kStatus_LED_ErrorAn error occurred.
kStatus_LED_SuccessSuccessfully adjust the brightness of the LED.
led_status_t LED_EnterLowpower ( led_handle_t  ledHandle)

This function is used to prepare to enter low power consumption.

Parameters
ledHandleLED handle pointer.
Return values
kStatus_LED_SuccessSuccessful operation.
led_status_t LED_ExitLowpower ( led_handle_t  ledHandle)

This function is used to restore from low power consumption.

Parameters
ledHandleLED handle pointer.
Return values
kStatus_LED_SuccessSuccessful operation.