drivers: nrf_rtc: Finalize docstrings
This commit is contained in:
parent
d5c629a9ac
commit
880083977c
2 changed files with 32 additions and 3 deletions
|
@ -44,7 +44,6 @@ Device drivers
|
||||||
|
|
||||||
.. automodule:: drivers.nrf_rtc
|
.. automodule:: drivers.nrf_rtc
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
|
||||||
|
|
||||||
.. automodule:: drivers.signal
|
.. automodule:: drivers.signal
|
||||||
:members:
|
:members:
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
# Copyright (C) 2020 Daniel Thompson
|
# Copyright (C) 2020 Daniel Thompson
|
||||||
|
|
||||||
""" Real Time Clock based on the nRF-family low power counter """
|
"""nRF-family RTC driver
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
"""
|
||||||
|
|
||||||
import machine
|
import machine
|
||||||
import time
|
import time
|
||||||
|
@ -17,9 +19,19 @@ import time
|
||||||
# return self.c
|
# return self.c
|
||||||
|
|
||||||
class RTC(object):
|
class RTC(object):
|
||||||
"""Real Time Clock based on the nRF-family low power counter."""
|
"""Real Time Clock based on the nRF-family low power counter.
|
||||||
|
|
||||||
|
.. automethod:: __init__
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, counter):
|
def __init__(self, counter):
|
||||||
|
"""Wrap an RTCounter to provide a fully fledged Real Time Clock.
|
||||||
|
|
||||||
|
If the PNVRAM is valid then we use it to initialize the RTC otherwise
|
||||||
|
we just make something up.
|
||||||
|
|
||||||
|
:param RTCounter counter: The RTCCounter channel to adopt.
|
||||||
|
"""
|
||||||
self.counter = counter
|
self.counter = counter
|
||||||
|
|
||||||
if machine.mem32[0x200039c0] == 0x1abe11ed and \
|
if machine.mem32[0x200039c0] == 0x1abe11ed and \
|
||||||
|
@ -34,6 +46,10 @@ class RTC(object):
|
||||||
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
|
self.set_localtime((2020, 3, 1, 3, 0, 0, 0, 0))
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
"""Check for counter updates.
|
||||||
|
|
||||||
|
:returns: True of the wall time has changed, False otherwise.
|
||||||
|
"""
|
||||||
newcount = self.counter.counter()
|
newcount = self.counter.counter()
|
||||||
split = newcount - self.lastcount
|
split = newcount - self.lastcount
|
||||||
if split == 0:
|
if split == 0:
|
||||||
|
@ -49,6 +65,12 @@ class RTC(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_localtime(self, t):
|
def set_localtime(self, t):
|
||||||
|
"""Set the current wall time.
|
||||||
|
|
||||||
|
:param sequence t:
|
||||||
|
Wall time formatted as (yyyy, mm, dd, HH, MM, SS), any
|
||||||
|
additional elements in sequence will be ignored.
|
||||||
|
"""
|
||||||
self.lastcount = self.counter.counter()
|
self.lastcount = self.counter.counter()
|
||||||
|
|
||||||
if len(t) < 8:
|
if len(t) < 8:
|
||||||
|
@ -66,10 +88,18 @@ class RTC(object):
|
||||||
machine.mem32[0x200039c4] = self.offset
|
machine.mem32[0x200039c4] = self.offset
|
||||||
|
|
||||||
def get_localtime(self):
|
def get_localtime(self):
|
||||||
|
"""Get the current time and date.
|
||||||
|
|
||||||
|
:returns: Wall time formatted as (yyyy, mm, dd, HH, MM, SS, wday, yday)
|
||||||
|
"""
|
||||||
self.update()
|
self.update()
|
||||||
return time.localtime(self.offset + (self._uptime >> 3))
|
return time.localtime(self.offset + (self._uptime >> 3))
|
||||||
|
|
||||||
def get_time(self):
|
def get_time(self):
|
||||||
|
"""Get the current time.
|
||||||
|
|
||||||
|
:returns: Wall time formatted as (HH, MM, SS)
|
||||||
|
"""
|
||||||
localtime = self.get_localtime()
|
localtime = self.get_localtime()
|
||||||
return localtime[3:6]
|
return localtime[3:6]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue