Skip to content

uBit.power

Overview

Provides access power management on the micro:bit.

API

getPowerSource

MicroBitPowerSource
getPowerSource
()

Description

Attempts to determine the power source currently in use on this micro:bit. note: This will query the USB interface chip via I2C, and wait for completion.

Returns

the current power source used by this micro:bit


getPowerConsumption

uint32_t
getPowerConsumption
()

Description

Attempts to determine the instantaneous power consumption of this micro:bit. note: This will query the USB interface chip via I2C, and wait for completion.

Returns

the current power consumption of this micro:bit


getVersion

MicroBitVersion
getVersion
()

Description

Attempts to determine the USB interface chip version in use on this micro:bit. note: This will query the USB interface chip via I2C if necessary.

Returns

MicroBitUSBVersion information.


getUSBStatus

MicroBitUSBStatus
getUSBStatus
()

Description

Attempts to determine the status of the USB interface on this micro:bit. note: This will query the USB interface chip via I2C, and wait for completion.

Returns

the current status of the USB interface on this micro:bit


sendUIPMPacket

int
sendUIPMPacket
(
ManagedBuffer
packet)

Description
Parameters

ManagedBuffer
packet - The data to send

Returns

MICROBIT_OK on success, or an I2C related error code on failure.


recvUIPMPacket

ManagedBuffer
recvUIPMPacket
()

Description

Attempts to read a packet from the USB interface chip, either as a response to a prior request, or following an interrupt request.

Returns

A buffer containing the complete response.


awaitUIPMPacket

ManagedBuffer
awaitUIPMPacket
()

Description

Awaits a response to a previous requests to the USB interface chip. Up to MICROBIT_UIPM_MAX_RETRIES attempts will be made at ~1ms intervals.

Returns

A buffer containing the complete response.


writeProperty

ManagedBuffer
writeProperty
(
ManagedBuffer
request)

Description
Parameters

ManagedBuffer
request

Returns

MICROBIT_OK on success

ManagedBuffer
writeProperty
(
ManagedBuffer
request,
bool
ack)

Description
Parameters

ManagedBuffer
request

bool
ack

Returns

MICROBIT_OK on success


readProperty

ManagedBuffer
readProperty
(
int
property)

Description
Parameters

int
property

Returns

A response or error packet


nop

void
nop
()

Description

Perform a NULL opertion I2C transcation wit the interface chip. This is used to awken the KL27 interface chip from light sleep, as a work around for silicon errata in the KL27.


off

void
off
()

Description

Powers down the CPU and USB interface and enters STANDBY state. All user code and peripherals will cease operation. Device can subsequently be awoken only via a RESET. User program state will be lost and will restart from main().


deepSleep

void
deepSleep
(
uint32_t
milliSeconds)

Description

Powers down the CPU and USB interface and instructs peripherals to enter an inoperative low power state. However, all program state is preserved. CPU will deepsleep for the given period of time, before returning to normal operation.

note: ALL peripherals will be shutdown in this period. If you wish to keep peripherals active, simply use uBit.sleep();

Parameters

uint32_t
milliSeconds


awaitingPacket

void
awaitingPacket
(
bool
awaiting)

Description

Allows a subsystem to indicate that it is actively waiting for a I2C response from the KL27 (e.g. the USBFlashManager). If set, the PowerManager will defer polling of the KL27 control interface if an interrupt is asserted.

awaiting

true if a subsystem is awaiting a packet from the KL27, false otherwise.

Parameters

bool
awaiting - true if a subsystem is awaiting a packet from the KL27, false otherwise.


Component Constructor

Advanced users only

Do not use this unless you really know what you're doing. It's usually best to use uBit.

MicroBitPowerManager(
MicroBitI2C &
i2c,
MicroBitIO &
ioPins)

Description

Constructor. Create a software abstraction of a power manager.

i2c

the I2C bus to use to communicate with the micro:bit USB interface chip

ioPins

the IO pins in use on this device.

id

the unique EventModel id of this component. Defaults to: MICROBIT_ID_POWER_MANAGER

Parameters

MicroBitI2C &
i2c - the I2C bus to use to communicate with the micro:bit USB interface chip

MicroBitIO &
ioPins - the IO pins in use on this device.

MicroBitPowerManager(
MicroBitI2C &
i2c,
MicroBitIO &
ioPins,
uint16_t
id)

Description

Constructor. Create a software abstraction of a power manager.

i2c

the I2C bus to use to communicate with the micro:bit USB interface chip

ioPins

the IO pins in use on this device.

id

the unique EventModel id of this component. Defaults to: MICROBIT_ID_POWER_MANAGER

Parameters

MicroBitI2C &
i2c - the I2C bus to use to communicate with the micro:bit USB interface chip

MicroBitIO &
ioPins - the IO pins in use on this device.

uint16_t
id - the unique EventModel id of this component. Defaults to: MICROBIT_ID_POWER_MANAGER