Commit Graph

14 Commits

Author SHA1 Message Date
puuu bcf60b43ee esp8266/modpybrtc.c: Implement machine.RTC.alarm_left()
Implementation of machine.RTC.alarm_left(), like described in the
documentation.
2016-10-05 12:20:30 +11:00
Damien George d09b6b9aa1 esp8266/modpybrtc: Use 64-bit arithmetic when computing alarm expiry. 2016-08-25 14:10:25 +10:00
puuu ee12581a35 esp8266: Let RTC work correctly after deepsleep.
By design, at wake up from deepsleep, the RTC timer will be reset, but
the data stored in RTC memory will not [1]. Therefore, we have to adjust
delta in RTC memory before going into deepsleep to get almost correct
time after waking up.

[1] http://bbs.espressif.com/viewtopic.php?t=1184#p4082
2016-06-06 10:51:12 +01:00
puuu cafdfb7af3 esp8266/modpybrtc: Handle RTC overflow.
ESP-SDK system_get_rtc_time() returns uint32 and therefore overflow
about every 7:45h.  Let's write the last state of system_get_rtc_time()
in RTC mem and use it to check for overflow. This commit require running
pyb_rtc_get_us_since_2000() at least once within 7 hours to avoid
overflow.
2016-06-03 14:37:49 +01:00
Damien George 752e952096 esp8266/rtc: Set RTC user memory length to 0 on first boot.
So that RTC.memory() returns b'' on power up if it was never set.

Fixes issue #2138.
2016-06-01 11:33:04 +01:00
Damien George 32d7cf6e44 esp8266: Implement basic deep-sleep capabilities.
Use the machine.deepsleep() function to enter the sleep mode.  Use the
RTC to configure the alarm to wake the device.

Basic use is the following:

    import machine

    # configure RTC's ALARM0 to wake device from deep sleep
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

    # do other things
    # ...

    # set ALARM0's alarm to wake after 10 seconds
    rtc.alarm(rtc.ALARM0, 10000)

    # enter deep-sleep state (system is reset upon waking)
    machine.deepsleep()

To detect if the system woke from a deep sleep use:

    if machine.reset_cause() == machine.DEEPSLEEP_RESET:
        print('woke from deep sleep')
2016-04-21 11:43:37 +01:00
Paul Sokolovsky a4c8ef9d16 esp8266: Reset "virtual RTC" on power on.
Initialize RTC period coefficients, etc. if RTC RAM doesn't contain valid
values. time.time() then will return number of seconds since power-on, unless
set to different timebase.

This reuses MEM_MAGIC for the purpose beyond its initial purpose (but the whole
modpybrtc.c need to be eventually reworked completely anyway).
2016-03-04 16:49:01 +02:00
Paul Sokolovsky a2e39a756c esp8266/modpybrtc: Simplify multiplication by fixed-point value. 2016-02-12 23:20:52 +02:00
Paul Sokolovsky 814b1ae3a9 esp8266/modpybrtc: pyb_rtc_memory(): Fix copy-paste error. 2016-02-08 21:39:33 +02:00
Damien George 5b3f0b7f39 py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
The first argument to the type.make_new method is naturally a uPy type,
and all uses of this argument cast it directly to a pointer to a type
structure.  So it makes sense to just have it a pointer to a type from
the very beginning (and a const pointer at that).  This patch makes
such a change, and removes all unnecessary casting to/from mp_obj_t.
2016-01-11 00:49:27 +00:00
Damien George 731f359292 all: Add py/mphal.h and use it in all ports.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
2015-10-31 19:14:30 +03:00
Damien George de8b585ab7 esp8266: Make pyb.RTC a type, and pyb.RTC() constructs an RTC object.
This is the standard way of doing things, one should construct a
peripheral object (even if it's a singleton).

See issue #1330.
2015-06-22 23:03:17 +01:00
Josef Gajdusek 40c6d57804 esp8266: Actually use the decimal part of system_rtc_clock_cali_proc() 2015-05-13 17:59:36 +02:00
Josef Gajdusek 103d12a877 esp8266: Add utime and pyb.RTC 2015-05-13 00:12:54 +01:00