Library ec618

To use this library in your code:

import ec618
EC618 chip-specific helpers.
Addressing model
On the EC618, Pin numbers are physical pad indices from 1 through 48, not logical GPIO numbers. Pads are unambiguous: each one is a single physical pin on the chip. A few pads share a GPIO controller bit, so addressing by GPIO number alone is ambiguous in those cases.
Most user code should use the helpers on Ec618:

Classes

Helpers for EC618 pin addressing and peripheral construction.

Identifies one of the EC618's six physical, input-only wake sources.

Globals

The shortest duration supported by deep-sleep.

Reset by the always-on (sleep-manager) watchdog.

Reset after a failed runtime assertion in the platform.

Reset because the battery voltage was too low.

Reset triggered by the cellular processor (CP).

Reset to apply a firmware-over-the-air update.

Reset after a hard fault (see the fault dump on the console).

Reset after the CPU locked up.

Normal reset after waking from deep sleep (sleep2) or hibernate.

Reset after power was (re)applied (cold boot).

Software reset (an explicit system reset request).

Reset because the temperature was too high.

The reset reason could not be determined.

Reset attributed to a hardware watchdog.
Note: the application watchdog in the ec618.watchdog library does not produce this. Its reset is an autonomous hardware reset that the chip reports as RESET-POWER-ON.

Reset attributed to a watchdog via a software-recorded reason.
Note: the application watchdog in the ec618.watchdog library does not produce this. Its reset is an autonomous hardware reset that the chip reports as RESET-POWER-ON.

Woke by the charger (VBUS) detection.

WAKEUP0, Air780E module pin 101.

WAKEUP1 on the VBUS function, Air780E module pin 61.

WAKEUP2 on the USIM_DET function, Air780E module pin 79.

WAKEUP3 on PAD40 / GPIO20.

WAKEUP4 on PAD41 / GPIO21.

WAKEUP5 on PAD42 / GPIO22.

Woke from sleep by activity on the low-power UART (UART1).

Woke from sleep by USB activity.

Woke from deep sleep by an AON wakeup pad.

Cold boot: power was (re)applied, or a reset that isn't a sleep wake.

Woke by the PWRKEY pin.

Woke from deep sleep by the RTC deep-sleep timer (see deep-sleep).

Functions

Returns the flashed base's identity ("base-v<N>+<fingerprint>"), or "base-unknown" for a base without an id record.
The device never activates a slot linked against a different base.

configure-wakeup-input input/WakeupInput --pos-edge/bool=false --neg-edge/bool=false --pull-up/bool=false --pull-down/bool=false -> none
Configures a physical wake input as a deep-sleep wake source.
At least one of pos-edge and neg-edge must be set. The configuration takes effect at the next deep-sleep. The wake is a reboot, and wakeup-cause reports WAKEUP-PAD on the boot it causes.
The pulls belong to the approximately 2 V wake-input domain. They are independent of ordinary GPIO pulls and the AON GPIO supply.

configure-wakeup-pad pad/int --pos-edge/bool=false --neg-edge/bool=false --pull-up/bool=false --pull-down/bool=false -> none
Configures an AON wakeup pad as a deep-sleep wake source.
The pad must be the physical PAD number of one of the three ordinary GPIO wake pads:
  • PAD40 / Ec618.gpio 20 / wakeup input 3.
  • PAD41 / Ec618.gpio 21 / wakeup input 4.
  • PAD42 / Ec618.gpio 22 / wakeup input 5.
Other pins are rejected. Use configure-wakeup-input for the dedicated WAKEUP-INPUT-0 through WAKEUP-INPUT-2 package functions.
The configuration only takes effect at the next deep-sleep: an edge of the enabled polarity (pos-edge / neg-edge, at least one required) then ends the hibernate early. The wake is a reboot; wakeup-cause reports WAKEUP-PAD on the boot it causes. pull-up / pull-down select the pad's internal pull while asleep.

Returns the UART id (0/1/2) that the firmware redirects print output to, or -1 if the print redirect was disabled at build time (CONFIG_TOIT_EC618_PRINT_UART=0).
Use this to adapt to the console selected in the running firmware. Opening the selected print UART through Ec618 fails with ALREADY_IN_USE, unless the firmware permits the port to adopt the console.

deep-sleep duration/Duration -> none
Enters deep sleep for the specified duration and does not return. Exiting deep sleep causes the device to start over from main.
Durations shorter than DEEP-SLEEP-MIN-DURATION are increased to that duration. Use reset instead when no sleep is intended.
Durations longer than one hardware-timer interval are split across hibernate cycles. Intermediate timer wakes re-enter hibernate without starting the Toit VM, and configured wakeup pads remain armed. A non-timer wake cancels the remaining duration and starts the device normally.

Disables the physical wake input as a deep-sleep wake source.

Disables pad as a deep-sleep wake source.
The supported pins are the same as for configure-wakeup-pad.

reset -> none
Resets the EC618 and does not return.

Returns the reason for the most recent reset of the application processor.
The result is one of the RESET-* constants (RESET-POWER-ON, RESET-WATCHDOG-HARDWARE, ...). Use reset-reason-name to turn it into a human-readable string.

Returns a human-readable name for the given reset reason.
The reason should be one of the RESET-* constants, typically the result of reset-reason. Unrecognized values are formatted as "reset-<n>".

Attaches a console/control UART to the freshly staged OTA.
The id selects UART 0, 1 or 2; 0xff disables the redirect. This function must be called after the new image has been committed and before it is rebooted on trial; otherwise it throws. The change takes effect when the trial boots. Validation promotes the new console with the image, while rollback restores the previous image's console.

Returns what woke the chip at the most recent boot.
The result is one of the WAKEUP-* constants (WAKEUP-POWER-ON, WAKEUP-RTC, ...). Use wakeup-cause-name to turn it into a human-readable string.
The EC618 reports reset-reason as RESET-POWER-ON even after a wake from deep sleep, so this is the call that tells a deep-sleep wake (by timer or wakeup pad) apart from a cold boot.

Returns a human-readable name for the given wakeup cause.
The cause should be one of the WAKEUP-* constants, typically the result of wakeup-cause. Unrecognized values are formatted as "wakeup-<n>".

Returns the live levels of the AON wakeup inputs as a bitmask.
Bits 3, 4, and 5 are PAD40, PAD41, and PAD42 respectively (EC618 GPIO20, GPIO21, and GPIO22). Bits 0, 1, and 2 are WAKEUP0 (module pin 101), VBUS/WAKEUP1 (module pin 61), and USIM_DET/WAKEUP2 (module pin 79).