SLEEP LED

SLEEP LED Demo Code Support List

This chapter introduces the details of the SLEEP LED demo code.

SLEEP LED Demo for Breathe Mode

The description of SLEEP LED demo code 1 is shown in the following table.

SLEEP LED Demo Code 1 Description

Demo 1

sleep_led_demo.c

Sample Purpose

Demonstrate SLEEP LED breathe mode.

File Path

sdk\src\sample\io_demo\led\sleep_led_demo.c

Function Entry

sleep_led_breathe_demo()

Phase0 Parameters

Duty update time: 10ms

Phase0 output time: 500ms

Initial high level time: 0

Duty step time: 0.03125ms

Change direction: increase

Phase1 Parameters

Duty update time: 10ms

Phase1 output time: 500ms

Initial high level time: 3.125ms

Duty step time: 0.0625ms

Change direction: increase

Phase2 Parameters

Duty update time: 10ms

Phase2 output time: 500ms

Initial high level time: 6.25ms

Duty step time: 0.09375ms

Change direction: increase

Phase3 Parameters

Duty update time: 10ms

Phase3 output time: 500ms

Initial high level time: 9.375ms

Duty step time: 0.125ms

Change direction: increase

Phase4 Parameters

Duty update time: 10ms

Phase4 output time: 500ms

Initial high level time: 9.375ms

Duty step time: 0.03125ms

Change direction: decrease

Phase5 Parameters

Duty update time: 10ms

Phase5 output time: 500ms

Initial high level time: 6.25ms

Duty step time: 0.0625ms

Change direction: decrease

Phase6 Parameters

Duty update time: 10ms

Phase6 output time: 500ms

Initial high level time: 3.125ms

Duty step time: 0.09375ms

Change direction: decrease

Phase7 Parameters

Duty update time: 10ms

Phase7 output time: 500ms

Initial high level time: 0

Duty step time: 0

Change direction: decrease

Hardware Connection

As shown in SLEEP LED Demo Code Hardware Connection Diagram. On EVB, connect M0_1 to LED1 and connect M2_1 to LED2 and connect M2_2 to LED3.

Pin Definition

#define LED_OUT_0     ADC_1

#define LED_OUT_1     P2_1

#define LED_OUT_2     P2_2

Expected Result

LEDs turn from dark to bright and then from bright to dark in breathe mode.

The hardware connection of SLEEP LED demo code 1 is shown in the figure below.

../../../_images/SLEEP_LED_Demo_Hardware_Connection_Diagram.png

SLEEP LED Demo Code Hardware Connection Diagram

Functional Overview

SLEEP LED is used to control LED to make the effect of blinking light or breathing light.

Note

RTL87x3D and RTL87x3E support SLEEP LED. RTL87x3EP doesn’t support SLEEP LED.

Feature List

  • Support three channels.

  • Support blink mode and breathe mode.

  • 32KHz clock source.

  • 3 periods per channel in blink mode.

  • 8 phases per channel in breathe mode.

  • Support output level setting in idle state.

  • Support reverse output function.

  • Support period bypass in blink mode and phase bypass in breathe mode.

Note

If a default pull-up pin (P1_0/P1_1/P2_0/P3_0/P3_1) is set as a high active LED, or any other pull-down pin is set as a low active LED, it will blink when CPU reboots.

Breathe Mode

In breathe mode, one channel is divided into eight phases. As shown in the following figure, it is executed sequentially from phase0, and after the end of phase7, it goes to phase0 to continue the loop execution.

../../../_images/Schematic_Diagram_of_SLEEP_LED_Breathe_Mode.png

Schematic Diagram of SLEEP LED Breathe Mode

Note

  1. phase_timetick = prescale / 32000

  2. phase_uptate_rate[x]: duty update time = (phase_uptate_rate[x] + 1) * phase_timetick (x = 0, 1, 2, …, 7)

  3. phase_phase_tick[x]: The duration of the whole phase. phasex output time = phase_phase_tick[x] * phase_timetick (x = 0, 1, 2, …, 7)

  4. phase_initial_duty[x]: initial high level time = phase_initial_duty[x] / 32000 (x = 0, 1, 2, …, 7)

  5. phase_increase_duty[x]: The direction of each change of duty. 1: increase duty. 0: decrease duty. (x = 0, 1, 2, …, 7)

  6. phase_duty_step[x]: duty step time = phase_duty_step[x] / 32000 (x = 0, 1, 2, …, 7)

  7. After high level time increases to phase_timetick, it remains at phase_timetick.

  8. After high level time decreases to 0, it remains at 0.

  9. Low level time = phase_timetick - high level time

  10. If phase_phase_tick[x] is 0, this and subsequent phases are bypassed. For example, if phase_phase_tick[6] is 0, phase6 and phase7 are bypassed, it is executed sequentially from phase0, and after the end of phase5, it goes to phase0 to continue the loop execution.

Idle State

Call the SleepLed_SetIdleMode() API to set whether the channel outputs a high level or low level after the SLEEP LED is disabled.

Reverse Output Function

Each channel of SLEEP LED supports the reverse function. After the reverse function is enabled, the original waveform is reversed and output, the actual waveform is opposite to the set value.

Program Examples

Breathe Mode Operation Flow

The operation flow of SLEEP LED breathe mode is shown in the following figure.

../../../_images/SLEEP_LED_Breathe_Mode_Flow_Chart.png

SLEEP LED Breathe Mode Flow Chart

The codes below demonstrate the SLEEP LED breathe mode operation flow.

/* Clear all the Sleep LED registers to their default reset values */
SleepLed_Reset();

SLEEP_LED_InitTypeDef Led_Initsturcture;
/* Fill each SLEEP_LED_InitTypeDef member variable with its default value */
SleepLed_StructInit(&Led_Initsturcture);

/* Set clock division factor */
Led_Initsturcture.prescale                    = 320;
/* Set SLEEP LED mode */
Led_Initsturcture.mode                        = LED_BREATHE_MODE;
/* Set reverse output function */
Led_Initsturcture.polarity                    = LED_OUTPUT_NORMAL;
/* Set duty update time */
Led_Initsturcture.phase_uptate_rate[0]              = 0;
/* Set the duration of the whole phase */
Led_Initsturcture.phase_phase_tick[0]               = 50;
/* Set initial high level time */
Led_Initsturcture.phase_initial_duty[0]             = 0;
/* Set the direction of each change of duty */
Led_Initsturcture.phase_increase_duty[0]            = 1;
/* Set duty step when duty is updated */
Led_Initsturcture.phase_duty_step[0]                = 1;

/* Set phase1 parameters */
Led_Initsturcture.phase_uptate_rate[1]              = 0;
Led_Initsturcture.phase_phase_tick[1]               = 50;
Led_Initsturcture.phase_initial_duty[1]             = 100;
Led_Initsturcture.phase_increase_duty[1]            = 1;
Led_Initsturcture.phase_duty_step[1]                = 2;

/* Set phase2 parameters */
Led_Initsturcture.phase_uptate_rate[2]              = 0;
Led_Initsturcture.phase_phase_tick[2]               = 50;
Led_Initsturcture.phase_initial_duty[2]             = 200;
Led_Initsturcture.phase_increase_duty[2]            = 1;
Led_Initsturcture.phase_duty_step[2]                = 3;

/* Set phase3 parameters */
Led_Initsturcture.phase_uptate_rate[3]              = 0;
Led_Initsturcture.phase_phase_tick[3]               = 50;
Led_Initsturcture.phase_initial_duty[3]             = 300;
Led_Initsturcture.phase_increase_duty[3]            = 1;
Led_Initsturcture.phase_duty_step[3]                = 4;

/* Set phase4 parameters */
Led_Initsturcture.phase_uptate_rate[4]              = 0;
Led_Initsturcture.phase_phase_tick[4]               = 50;
Led_Initsturcture.phase_initial_duty[4]             = 300;
Led_Initsturcture.phase_increase_duty[4]            = 0;
Led_Initsturcture.phase_duty_step[4]                = 1;

/* Set phase5 parameters */
Led_Initsturcture.phase_uptate_rate[5]              = 0;
Led_Initsturcture.phase_phase_tick[5]               = 50;
Led_Initsturcture.phase_initial_duty[5]             = 200;
Led_Initsturcture.phase_increase_duty[5]            = 0;
Led_Initsturcture.phase_duty_step[5]                = 2;

/* Set phase6 parameters */
Led_Initsturcture.phase_uptate_rate[6]              = 0;
Led_Initsturcture.phase_phase_tick[6]               = 50;
Led_Initsturcture.phase_initial_duty[6]             = 100;
Led_Initsturcture.phase_increase_duty[6]            = 0;
Led_Initsturcture.phase_duty_step[6]                = 3;

/* Set phase7 parameters */
Led_Initsturcture.phase_uptate_rate[7]              = 0;
Led_Initsturcture.phase_phase_tick[7]               = 50;
Led_Initsturcture.phase_initial_duty[7]             = 0;
Led_Initsturcture.phase_increase_duty[7]            = 0;
Led_Initsturcture.phase_duty_step[7]                = 0;
/* Initialize channel 0 */
SleepLed_Init(LED_CHANNEL_0, &Led_Initsturcture);
/* Initialize channel 1 */
SleepLed_Init(LED_CHANNEL_1, &Led_Initsturcture);
/* Initialize channel 2 */
SleepLed_Init(LED_CHANNEL_2, &Led_Initsturcture);
/* Enable Sleep led */
SleepLed_Cmd(LED_CHANNEL_1 | LED_CHANNEL_0 | LED_CHANNEL_2, ENABLE);