pm - Power Management#

Adapted Air780E/Air700E Air780EP Air601 Air101/Air103 Air105 ESP32C3 ESP32S3

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view the demo example of pm

Example

--[[
Introduction to Sleep Mode

-- IDLE Normal operation mode
-- LIGHT Light sleep mode:
        CPU Pause
        RAM Maintain power supply
        Timer/network event/IO interrupt can wake up automatically
        Program continues to run after wake-up
        GPIO hold level
-- DEEP Deep sleep mode
        CPU Pause
        Core RAM Power Down, Reserved RAM Maintains Power
        Ordinary GPIO power down, peripheral driver power down
        AON_GPIO Keep the level before sleep
        dtimer Timer can wake up
        wakeup Feet can be awakened
        After waking up, the program runs from the beginning, and all the runtime data before hibernation is lost.
-- HIB Sleep mode
        CPU Pause
        RAM Power down, keep RAM also power down
        Ordinary GPIO power down, peripheral driver power down
        AON_GPIO Keep the level before sleep
        dtimer Timer can wake up
        wakeup Feet can be awakened
        After waking up, the program runs from the beginning, and all the runtime data before hibernation is lost.

For some modules, such as Air780E, DEEP/HIB makes no difference to user code

RTC is always running except pm.shutdown(), unless power is lost
]]

-- Timer wake-up, please use pm.dtimerStart()
-- wakeup Wake up
    -- Such as Air101/Air103, there is an independent wakeup pin, no need to configure, can directly control the wake-up
    -- As in the Air780E series, there are multiple wakeup available. Configure virtual GPIO for wakeup configuration through gpio.setup(32)

pm.request(pm.IDLE) -- Request to enter different sleep modes by switching different values
-- Corresponding to the Air780E series, it does not necessarily enter the sleep mode immediately after execution. If there is no subsequent data transmission requirement, you can enter the flight mode first and then sleep quickly.

Constant#

constant

type

explanation

pm.NONE

number

No sleep mode

pm.IDLE

number

IDLE Mode

pm.LIGHT

number

LIGHT Mode

pm.DEEP

number

DEEP Mode

pm.HIB

number

HIB Mode

pm.USB

number

USB Power

pm.GPS

number

GPS Power

pm.GPS_ANT

number

GPS The antenna power supply, active antenna is required.

pm.CAMERA

number

camera Power supply, CAM_VCC output

pm.DAC_EN

number

Air780E And Air600E DAC_EN (LDO_CTL of the new hardware manual, same PIN, naming change), note that the default configuration of audio will automatically use this pin to control CODEC enable

pm.LDO_CTL

number

Air780E And Air600E LDO_CTL (DAC_EN of the old hardware manual, same PIN, naming change),Air780EP LDO_CTL, note that the default configuration of audio will automatically use this pin to control CODEC enable

pm.PWK_MODE

number

Whether to turn on the powerkey filtering mode of ec618, true on, note that reset becomes direct shutdown in filtering mode

pm.WORK_MODE

number

ec618 Energy saving mode, 0~3,0 completely off, 1 performance priority, 2 balance, 3 extreme power consumption

pm.IOVL

number

All GPIO high-level voltage controls, currently available only in the ec618 series

pm.request(mode)#

Request to enter the specified sleep mode

Parameters

Incoming Value Type

Explanation

int

Sleep mode, for example pm.IDLE/LIGHT/DEEP/HIB.

Return Value

return value type

explanation

boolean

The processing result, even if the return is successful, will not necessarily enter, nor will it enter immediately.

Examples

-- Request to enter sleep mode
--[[
IDLE   Normal operation, that is, no sleep
LIGHT  Light sleep, CPU stop, RAM hold, peripheral hold, interruptible wake-up. Some models support continuous operation from sleep
DEEP   Deep sleep, CPU stops, RAM power down, only special pins keep the level before sleep, most pins cannot wake up the device.
HIB    Complete sleep, CPU stop, RAM power down, only reset/special wake pin can wake up the device.
]]

pm.request(pm.HIB)

pm.dtimerStart(id, timeout)#

Start the bottom timer, which is still in effect in sleep mode. Trigger only once

Parameters

Incoming Value Type

Explanation

int

Timer id, usually 0-3

int

Timing duration, in milliseconds

Return Value

return value type

explanation

boolean

Processing results

Examples

-- Add an underlying timer
pm.dtimerStart(0, 300 * 1000) -- 5 Wake up after minutes
-- Air780E/Air780EP Series
-- id = 0 Or id = 1 is, the maximum sleep duration is 2.5 hours
-- id = 2 Or id = 3 is, the maximum sleep duration is 3 months

pm.dtimerStop(id)#

Turn off the underlying timer

Parameters

Incoming Value Type

Explanation

int

Timer id

Return Value

None

Examples

-- Turn off the underlying timer
pm.dtimerStop(0) -- Turn off the underlying timer with id = 0

pm.dtimerCheck(id)#

Check if the underlying timer is running

Parameters

Incoming Value Type

Explanation

int

Timer id

Return Value

return value type

explanation

boolean

Processing results, true is still running, false is not running

number

If running, the remaining running time, in milliseconds (bsp support required)

Examples

-- Check if the underlying timer is running
pm.dtimerCheck(0) -- Check the underlying timer with id = 0

dtimerWkId()#

Check which timer the timed wake-up is. If it is not timed wake-up, return-1

Parameters

None

Return Value

return value type

explanation

int

The processing result> = 0 is the timer ID of this timing wake-up, and other errors indicate that the timing wake-up is not

Examples

local timer_id = pm.dtimerWkId()

pm.lastReson()#

Start-up reason, used to determine whether to start up from sleep module or power/reset

Parameters

None

Return Value

return value type

explanation

int

0-Power-on/reset boot, 1-RTC boot, 2-WakeupIn/Pad/IO boot, 3-unknown reason (Wakeup/RTC is possible) boot, currently only air101,air103 will have this return value

int

0-Normal boot (power on/reset),3-deep sleep boot, 4-sleep boot

int

Detailed reasons for reset and start-up: 0-powerkey or power-on start-up 1-charging or start-up after AT command download is completed 2-alarm clock start-up 3-software restart 4-unknown reason 5-RESET key 6-abnormal restart 7-tool control restart 8-internal watchdog restart 9-external restart 10-charging start-up

Examples

-- Which way is the boot
log.info("pm", "last power reson", pm.lastReson())

pm.force(mode)#

Force the specified sleep mode to ignore the effects of certain peripherals, such USB

Parameters

Incoming Value Type

Explanation

int

Sleep mode

Return Value

return value type

explanation

boolean

If the processing result is returned successfully, the high probability will immediately enter the sleep mode.

Examples

-- Request to enter sleep mode
pm.force(pm.HIB)
-- Corresponds to EC618 series (Air780E/Air700E, etc.), this operation will turn off USB communication
-- To turn on the USB after waking up, turn on the USB voltage
--pm.power(pm.USB, true)

pm.check()#

Check sleep state

Parameters

None

Return Value

return value type

explanation

boolean

Processing results, if you can successfully enter sleep, return true, otherwise return false

int

Return value at the bottom level. 0 represents the lowest level of sleep. Other values represent the lowest level of sleep.

Examples

-- Request to enter sleep mode, and then check if it can really sleep
pm.request(pm.HIB)
if pm.check() then
    log.info("pm", "it is ok to hib")
else
    -- Corresponds to EC618 series (Air780E/Air700E, etc.), this operation will turn off USB communication
    pm.force(pm.HIB) -- Forced Hibernation
    -- To turn on the USB after waking up, turn on the USB voltage
    --sys.wait(100)
    --pm.power(pm.USB, true)
end

pm.shutdown()#

Shutdown

Parameters

None

Return Value

return value type

explanation

nil

No return value

Examples

-- Currently only EC618 series (Air780E/Air600E/Air700E/Air780EG support)
-- Requires firmware compiled after 2022-12-22
pm.shutdown()

pm.reboot()#

Restart

Parameters

None

Return Value

return value type

explanation

nil

No return value

Examples

None


pm.power(id, onoff)#

Turn on the internal power control. Note that not all platforms are supported. Some platforms may support some options, depending on the hardware.

Parameters

Incoming Value Type

Explanation

int

Power control id,pm.USB pm.GPS and so on

boolean

or int Switch true/1 on, false/0 off, default off, some options support numerical values

Return Value

return value type

explanation

boolean

Processing result true succeeded, false failed

Examples

-- Turn off the USB power supply, otherwise turn it on true
pm.power(pm.USB, false) 

-- Air780EG,Power up the built-in GPS chip. Note that the Air780EG GPS and GPS_ANT are controlled together, so.
pm.power(pm.GPS, true)

-- EC618 Series open pwrkey boot anti-shake
-- Note: After opening, the reset key will turn off!!! Pwrkey to long press 2 seconds to boot
-- pm.power(pm.PWK_MODE, true)

-- EC618 Series PSM Low Power Settings
-- ec618 Energy saving mode, 0~3,0 completely off, 1 performance priority, 2 balance, 3 extreme power consumption
-- Detailed Access: https://airpsm.cn
-- pm.power(pm.WORK_MODE, 1)

pm.ioVol(id, val)#

IO High-level voltage control, currently only available in the EC618 series

Parameters

Incoming Value Type

Explanation

int

level id, currently only pm.IOVOL_ALL_GPIO

int

Level value in millivolts

Return Value

return value type

explanation

boolean

Processing result true succeeded, false failed

Examples

-- EC618 Series setting IO level, range 1650~2000,2650~3400, unit millivolt, step 50mv
-- For example Air780E/Air600E/Air700E/Air780EG
-- Note that the settings here take precedence over the configuration of the hardware IOSEL pin
-- However, the hardware configuration is still used when starting up until the API is called for configuration, so the io level will change.
-- pm.ioVol(pm.IOVOL_ALL_GPIO, 3300)    -- All GPIO high level outputs 3.3V
-- pm.ioVol(pm.IOVOL_ALL_GPIO, 1800)    -- All GPIO high level outputs 1.8V

pm.wakeupPin(pin,level)#

configure wake up pin (currently only esp series available)

Parameters

Incoming Value Type

Explanation

int/table

gpio Pin

int

Wake-up voltage optional, default low level wake-up

Return Value

return value type

explanation

boolean

Processing results

Examples

pm.wakeupPin(8,0)