From bea1aa6ee66a510dfbe9a14e6d3f8d201128ee9f Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sat, 18 Feb 2023 12:59:05 +0100 Subject: [PATCH 01/14] add support for timer and clkout --- adafruit_pcf8563.py | 84 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/adafruit_pcf8563.py b/adafruit_pcf8563.py index 9e507bb..bfe67d8 100644 --- a/adafruit_pcf8563.py +++ b/adafruit_pcf8563.py @@ -35,6 +35,10 @@ class is inherited by the chip-specific subclasses. **Notes:** #. Milliseconds are not supported by this RTC. +#. The alarm does not support seconds. It will always fire on full minutes. +#. This RTC only has a single timer. For compatibility reasons this + timer is nevertheless called `timerA`. This allows to replace the + PCF8563 with a PCF8523, which has two timers without changing the code. #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf """ @@ -46,8 +50,10 @@ class is inherited by the chip-specific subclasses. from adafruit_bus_device.i2c_device import I2CDevice from adafruit_register import i2c_bit +from adafruit_register import i2c_bits from adafruit_register import i2c_bcd_alarm from adafruit_register import i2c_bcd_datetime +from micropython import const try: import typing # pylint: disable=unused-import @@ -75,7 +81,9 @@ class PCF8563: alarm = i2c_bcd_alarm.BCDAlarmTimeRegister( 0x09, has_seconds=False, weekday_shared=False, weekday_start=0 ) - """Alarm time for the alarm.""" + """Alarm time for the alarm. Note that the value of the seconds-fields + is ignored, i.e. alarms only fire at full minutes. For short-term + alarms, use a timer instead.""" alarm_interrupt = i2c_bit.RWBit(0x01, 1) """True if the interrupt pin will output when alarm is alarming.""" @@ -83,18 +91,71 @@ class PCF8563: alarm_status = i2c_bit.RWBit(0x01, 3) """True if alarm is alarming. Set to False to reset.""" + timerA_enabled = i2c_bit.RWBit(0x0E, 7) + """True if the timer is enabled. Default is False.""" + + timerA_frequency = i2c_bits.RWBits(2, 0x0E, 0) + """Timer clock frequency. Default is 1/60Hz. + Possible values are as shown (selection value - frequency). + 00 - 4.096kHz + 01 - 64Hz + 10 - 1Hz + 11 - 1/60Hz + """ + TIMER_FREQ_4KHZ = const(0b00) + """Timer frequency of 4 KHz""" + TIMER_FREQ_64HZ = const(0b01) + """Timer frequency of 64 Hz""" + TIMER_FREQ_1HZ = const(0b10) + """Timer frequency of 1 Hz""" + TIMER_FREQ_1_60HZ = const(0b11) + """Timer frequency of 1/60 Hz""" + + timerA_value = i2c_bits.RWBits(7, 0x0F, 0) + """ Timer value (0-255). The default is undefined. + The total countdown duration is calcuated by + timerA_value/timerA_frequency. For a higher precision, use higher values + and frequencies, e.g. for a one minute timer you could use + value=1, frequency=1/60Hz or value=60, frequency=1Hz. The + latter will give better results. See the PCF85x3 User's Manual + for details.""" + + timerA_interrupt = i2c_bit.RWBit(0x01, 0) + """True if the interrupt pin will assert when timerA has elapsed. + Defaults to False.""" + + timerA_status = i2c_bit.RWBit(0x01, 2) + """True if timer has elapsed. Set to False to reset.""" + + timerA_pulsed = i2c_bit.RWBit(0x01, 4) + """True if timerA asserts INT as a pulse. The default + value False asserts INT permanently.""" + + clockout_enabled = i2c_bit.RWBit(0x0D, 7) + """True if clockout is enabled (default). To disable clockout, set to False""" + + clockout_frequency = i2c_bits.RWBits(2, 0x0D, 0) + """Clock output frequencies generated. Default is 32.768kHz. + Possible values are as shown (selection value - frequency). + 00 - 32.768khz + 01 - 1.024kHz + 10 - 0.032kHz (32Hz) + 11 - 0.001kHz (1Hz) + """ + + CLOCKOUT_FREQ_32KHZ = const(0b00) + """Clock frequency of 32 KHz""" + CLOCKOUT_FREQ_1KHZ = const(0b01) + """Clock frequency of 4 KHz""" + CLOCKOUT_FREQ_32HZ = const(0b10) + """Clock frequency of 32 Hz""" + CLOCKOUT_FREQ_1HZ = const(0b11) + """Clock frequency of 1 Hz""" + def __init__(self, i2c_bus: I2C) -> None: time.sleep(0.05) self.i2c_device = I2CDevice(i2c_bus, 0x51) - # Try and verify this is the RTC we expect by checking the timer B - # frequency control bits which are 1 on reset and shouldn't ever be - # changed. - buf = bytearray(2) - buf[0] = 0x12 - with self.i2c_device as i2c: - i2c.write_then_readinto(buf, buf, out_end=1, in_start=1) - @property def datetime(self) -> time.struct_time: """Gets the current date and time or sets the current date and time then starts the @@ -106,3 +167,8 @@ def datetime(self, value: time.struct_time) -> None: # Automatically sets lost_power to false. self.datetime_register = value self.datetime_compromised = False + + @property + def lost_power(self) -> Bool: + """Compatibility property for PCF8523-lib""" + return self.datetime_compromised From 19f377994741c152ec3d5c8b73b4df37a25cf5c1 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sat, 18 Feb 2023 13:16:00 +0100 Subject: [PATCH 02/14] fixed return-type of lost_power() --- adafruit_pcf8563.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8563.py b/adafruit_pcf8563.py index bfe67d8..51b1fa7 100644 --- a/adafruit_pcf8563.py +++ b/adafruit_pcf8563.py @@ -169,6 +169,6 @@ def datetime(self, value: time.struct_time) -> None: self.datetime_compromised = False @property - def lost_power(self) -> Bool: + def lost_power(self) -> bool: """Compatibility property for PCF8523-lib""" return self.datetime_compromised From 22378da3a85463eb563030d3b2b4e1de9c9aa9b8 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sat, 18 Feb 2023 13:23:13 +0100 Subject: [PATCH 03/14] change docstring to keep pylint happy --- adafruit_pcf8563.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8563.py b/adafruit_pcf8563.py index 51b1fa7..698f504 100644 --- a/adafruit_pcf8563.py +++ b/adafruit_pcf8563.py @@ -37,7 +37,7 @@ class is inherited by the chip-specific subclasses. #. Milliseconds are not supported by this RTC. #. The alarm does not support seconds. It will always fire on full minutes. #. This RTC only has a single timer. For compatibility reasons this - timer is nevertheless called `timerA`. This allows to replace the + timer is nevertheless called timerA. This allows to replace the PCF8563 with a PCF8523, which has two timers without changing the code. #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf From e469e5799922d2ddde57fed29b9a2373d0dbb70d Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sun, 19 Feb 2023 12:34:19 +0100 Subject: [PATCH 04/14] fixed number of timer-bits --- adafruit_pcf8563.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8563.py b/adafruit_pcf8563.py index 698f504..af00040 100644 --- a/adafruit_pcf8563.py +++ b/adafruit_pcf8563.py @@ -111,7 +111,7 @@ class PCF8563: TIMER_FREQ_1_60HZ = const(0b11) """Timer frequency of 1/60 Hz""" - timerA_value = i2c_bits.RWBits(7, 0x0F, 0) + timerA_value = i2c_bits.RWBits(8, 0x0F, 0) """ Timer value (0-255). The default is undefined. The total countdown duration is calcuated by timerA_value/timerA_frequency. For a higher precision, use higher values From c9904c138923e33879feedc6570bc5b290182ba5 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 2 Mar 2023 16:48:43 +0100 Subject: [PATCH 05/14] refactored timer-attributes to class 'Timer' --- adafruit_pcf8563.py | 45 +-------------- adafruit_pcf8563_timer.py | 112 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 43 deletions(-) create mode 100644 adafruit_pcf8563_timer.py diff --git a/adafruit_pcf8563.py b/adafruit_pcf8563.py index af00040..3babfe1 100644 --- a/adafruit_pcf8563.py +++ b/adafruit_pcf8563.py @@ -36,9 +36,8 @@ class is inherited by the chip-specific subclasses. #. Milliseconds are not supported by this RTC. #. The alarm does not support seconds. It will always fire on full minutes. -#. This RTC only has a single timer. For compatibility reasons this - timer is nevertheless called timerA. This allows to replace the - PCF8563 with a PCF8523, which has two timers without changing the code. +#. This RTC has a single timer. The class PCF8563_Timer implements the +interface to timer-specfic registers. #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf """ @@ -91,46 +90,6 @@ class PCF8563: alarm_status = i2c_bit.RWBit(0x01, 3) """True if alarm is alarming. Set to False to reset.""" - timerA_enabled = i2c_bit.RWBit(0x0E, 7) - """True if the timer is enabled. Default is False.""" - - timerA_frequency = i2c_bits.RWBits(2, 0x0E, 0) - """Timer clock frequency. Default is 1/60Hz. - Possible values are as shown (selection value - frequency). - 00 - 4.096kHz - 01 - 64Hz - 10 - 1Hz - 11 - 1/60Hz - """ - TIMER_FREQ_4KHZ = const(0b00) - """Timer frequency of 4 KHz""" - TIMER_FREQ_64HZ = const(0b01) - """Timer frequency of 64 Hz""" - TIMER_FREQ_1HZ = const(0b10) - """Timer frequency of 1 Hz""" - TIMER_FREQ_1_60HZ = const(0b11) - """Timer frequency of 1/60 Hz""" - - timerA_value = i2c_bits.RWBits(8, 0x0F, 0) - """ Timer value (0-255). The default is undefined. - The total countdown duration is calcuated by - timerA_value/timerA_frequency. For a higher precision, use higher values - and frequencies, e.g. for a one minute timer you could use - value=1, frequency=1/60Hz or value=60, frequency=1Hz. The - latter will give better results. See the PCF85x3 User's Manual - for details.""" - - timerA_interrupt = i2c_bit.RWBit(0x01, 0) - """True if the interrupt pin will assert when timerA has elapsed. - Defaults to False.""" - - timerA_status = i2c_bit.RWBit(0x01, 2) - """True if timer has elapsed. Set to False to reset.""" - - timerA_pulsed = i2c_bit.RWBit(0x01, 4) - """True if timerA asserts INT as a pulse. The default - value False asserts INT permanently.""" - clockout_enabled = i2c_bit.RWBit(0x0D, 7) """True if clockout is enabled (default). To disable clockout, set to False""" diff --git a/adafruit_pcf8563_timer.py b/adafruit_pcf8563_timer.py new file mode 100644 index 0000000..d971f02 --- /dev/null +++ b/adafruit_pcf8563_timer.py @@ -0,0 +1,112 @@ +# SPDX-FileCopyrightText: 2016 Philip R. Moyer and Radomir Dopieralski for Adafruit Industries. +# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2023 Bernhard Bablok +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_pcf8563_timer` - PCF8563 Timer module +=============================================== + +This class supports the timer of the PCF8563-based RTC in CircuitPython. + +Functions are included for reading and writing registers and manipulating +timer objects. + +The class supports stand-alone usage. In this case, pass an i2-bus object +to the constructor. If used together with the PCF8563 class (rtc), instantiate +the rtc-object first and then pass the i2c_device attribute of the rtc +to the constructor of the timer. + +Author(s): Bernhard Bablok +Date: November 2023 + +Implementation Notes +-------------------- + +**Hardware:** + +* `Seeeduino XIAO Expansion Board `_ + - Works With Adafruit QT Py (Product ID: 5033) + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware: https://github.com/adafruit/circuitpython/releases +* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register +* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + +**Notes:** + +#. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf + +""" + +__version__ = "0.0.0+auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCF8563.git" + +import time + +from adafruit_bus_device.i2c_device import I2CDevice +from adafruit_register import i2c_bit +from adafruit_register import i2c_bits +from micropython import const + +try: + import typing # pylint: disable=unused-import + from busio import I2C +except ImportError: + pass + + +class PCF8563_Timer: # pylint: disable=too-few-public-methods + """Interface to the timer of the PCF8563 RTC. + + :param I2C i2c_bus: The I2C bus object + """ + + timer_enabled = i2c_bit.RWBit(0x0E, 7) + """True if the timer is enabled. Default is False.""" + + timer_frequency = i2c_bits.RWBits(2, 0x0E, 0) + """Timer clock frequency. Default is 1/60Hz. + Possible values are as shown (selection value - frequency). + 00 - 4.096kHz + 01 - 64Hz + 10 - 1Hz + 11 - 1/60Hz + """ + TIMER_FREQ_4KHZ = const(0b00) + """Timer frequency of 4 KHz""" + TIMER_FREQ_64HZ = const(0b01) + """Timer frequency of 64 Hz""" + TIMER_FREQ_1HZ = const(0b10) + """Timer frequency of 1 Hz""" + TIMER_FREQ_1_60HZ = const(0b11) + """Timer frequency of 1/60 Hz""" + + timer_value = i2c_bits.RWBits(8, 0x0F, 0) + """ Timer value (0-255). The default is undefined. + The total countdown duration is calcuated by + timer_value/timer_frequency. For a higher precision, use higher values + and frequencies, e.g. for a one minute timer you could use + value=1, frequency=1/60Hz or value=60, frequency=1Hz. The + latter will give better results. See the PCF85x3 User's Manual + for details.""" + + timer_interrupt = i2c_bit.RWBit(0x01, 0) + """True if the interrupt pin will assert when timer has elapsed. + Defaults to False.""" + + timer_status = i2c_bit.RWBit(0x01, 2) + """True if timer has elapsed. Set to False to reset.""" + + timer_pulsed = i2c_bit.RWBit(0x01, 4) + """True if timer asserts INT as a pulse. The default + value False asserts INT permanently.""" + + def __init__(self, i2c: Union[I2C, I2CDevice]) -> None: + time.sleep(0.05) + if isinstance(i2c, I2CDevice): + self.i2c_device = i2c # reuse i2c_device (from PCF8563-instance) + else: + self.i2c_device = I2CDevice(i2c, 0x51) From 11db0b9b6d1a66d48f9cbc8e25d441587e8b4d7e Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sat, 4 Mar 2023 12:27:23 +0100 Subject: [PATCH 06/14] fixed typing import --- adafruit_pcf8563_timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8563_timer.py b/adafruit_pcf8563_timer.py index d971f02..a951f13 100644 --- a/adafruit_pcf8563_timer.py +++ b/adafruit_pcf8563_timer.py @@ -52,7 +52,7 @@ from micropython import const try: - import typing # pylint: disable=unused-import + from typing import Union from busio import I2C except ImportError: pass From 68eab73190b0c9f0c4cc3a7cb8f5e5873ee0628c Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sat, 4 Mar 2023 12:28:37 +0100 Subject: [PATCH 07/14] __init__(): sleep only when creating new I2CDevice --- adafruit_pcf8563_timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pcf8563_timer.py b/adafruit_pcf8563_timer.py index a951f13..5c51945 100644 --- a/adafruit_pcf8563_timer.py +++ b/adafruit_pcf8563_timer.py @@ -105,8 +105,8 @@ class PCF8563_Timer: # pylint: disable=too-few-public-methods value False asserts INT permanently.""" def __init__(self, i2c: Union[I2C, I2CDevice]) -> None: - time.sleep(0.05) if isinstance(i2c, I2CDevice): self.i2c_device = i2c # reuse i2c_device (from PCF8563-instance) else: + time.sleep(0.05) self.i2c_device = I2CDevice(i2c, 0x51) From 726bcbd5b78c35538cae30227d0e333c416dc1b3 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Wed, 15 Mar 2023 06:33:23 +0100 Subject: [PATCH 08/14] moved top-level files to (package) directory --- adafruit_pcf8563.py => adafruit_pcf8563/pcf8563.py | 0 adafruit_pcf8563_timer.py => adafruit_pcf8563/timer.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename adafruit_pcf8563.py => adafruit_pcf8563/pcf8563.py (100%) rename adafruit_pcf8563_timer.py => adafruit_pcf8563/timer.py (100%) diff --git a/adafruit_pcf8563.py b/adafruit_pcf8563/pcf8563.py similarity index 100% rename from adafruit_pcf8563.py rename to adafruit_pcf8563/pcf8563.py diff --git a/adafruit_pcf8563_timer.py b/adafruit_pcf8563/timer.py similarity index 100% rename from adafruit_pcf8563_timer.py rename to adafruit_pcf8563/timer.py From 1c18de910a86858a4f6722cb12a6c1285bd6edbe Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 17 Mar 2023 16:02:32 +0100 Subject: [PATCH 09/14] refactor code to module --- README.rst | 4 +- adafruit_pcf8563/clock.py | 93 ++++++++++++++++++++++++++++++++++ adafruit_pcf8563/pcf8563.py | 3 +- adafruit_pcf8563/timer.py | 8 +-- examples/pcf8563_simpletest.py | 4 +- pyproject.toml | 2 +- 6 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 adafruit_pcf8563/clock.py diff --git a/README.rst b/README.rst index 003cde2..03dbdb2 100644 --- a/README.rst +++ b/README.rst @@ -75,7 +75,7 @@ Of course, you must import the library to use it: .. code:: python import busio - import adafruit_pcf8563 + from adafruit_pcf8563.pcf8563 import PCF8563 import time All the Adafruit RTC libraries take an instantiated and active I2C object @@ -98,7 +98,7 @@ the RTC object: .. code:: python - rtc = adafruit_pcf8563.PCF8563(i2c_bus) + rtc = PCF8563(i2c_bus) Date and time ------------- diff --git a/adafruit_pcf8563/clock.py b/adafruit_pcf8563/clock.py new file mode 100644 index 0000000..61f2be1 --- /dev/null +++ b/adafruit_pcf8563/clock.py @@ -0,0 +1,93 @@ +# SPDX-FileCopyrightText: 2016 Philip R. Moyer and Radomir Dopieralski for Adafruit Industries. +# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2023 Bernhard Bablok +# +# SPDX-License-Identifier: MIT + +""" +`clock` - PCF8563 Clock module +============================== + +This class supports the clkout-feature of the PCF8563-based RTC in CircuitPython. + +Functions are included for reading and writing registers to configure +clklout frequency. + +The class supports stand-alone usage. In this case, pass an i2-bus object +to the constructor. If used together with the PCF8563 class (rtc), instantiate +the rtc-object first and then pass the i2c_device attribute of the rtc +to the constructor of the clock. + +Author(s): Bernhard Bablok +Date: March 2023 + +Implementation Notes +-------------------- + +**Hardware:** + +* `Seeeduino XIAO Expansion Board `_ + - Works With Adafruit QT Py (Product ID: 5033) + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware: https://github.com/adafruit/circuitpython/releases +* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register +* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + +**Notes:** + +#. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf + +""" + +__version__ = "0.0.0+auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCF8563.git" + +import time + +from adafruit_bus_device.i2c_device import I2CDevice +from adafruit_register import i2c_bit +from adafruit_register import i2c_bits +from micropython import const + +try: + from typing import Union + from busio import I2C +except ImportError: + pass + + +class Clock: # pylint: disable=too-few-public-methods + """Interface to the clkout of the PCF8563 RTC. + + :param I2C i2c_bus: The I2C bus object + """ + + clockout_enabled = i2c_bit.RWBit(0x0D, 7) + """True if clockout is enabled (default). To disable clockout, set to False""" + + clockout_frequency = i2c_bits.RWBits(2, 0x0D, 0) + """Clock output frequencies generated. Default is 32.768kHz. + Possible values are as shown (selection value - frequency). + 00 - 32.768khz + 01 - 1.024kHz + 10 - 0.032kHz (32Hz) + 11 - 0.001kHz (1Hz) + """ + + CLOCKOUT_FREQ_32KHZ = const(0b00) + """Clock frequency of 32 KHz""" + CLOCKOUT_FREQ_1KHZ = const(0b01) + """Clock frequency of 4 KHz""" + CLOCKOUT_FREQ_32HZ = const(0b10) + """Clock frequency of 32 Hz""" + CLOCKOUT_FREQ_1HZ = const(0b11) + """Clock frequency of 1 Hz""" + + def __init__(self, i2c: Union[I2C, I2CDevice]) -> None: + if isinstance(i2c, I2CDevice): + self.i2c_device = i2c # reuse i2c_device (from PCF8563-instance) + else: + time.sleep(0.05) + self.i2c_device = I2CDevice(i2c, 0x51) diff --git a/adafruit_pcf8563/pcf8563.py b/adafruit_pcf8563/pcf8563.py index 3babfe1..ba4bdf1 100644 --- a/adafruit_pcf8563/pcf8563.py +++ b/adafruit_pcf8563/pcf8563.py @@ -36,8 +36,9 @@ class is inherited by the chip-specific subclasses. #. Milliseconds are not supported by this RTC. #. The alarm does not support seconds. It will always fire on full minutes. -#. This RTC has a single timer. The class PCF8563_Timer implements the +#. This RTC has a single timer. The class Timer implements the interface to timer-specfic registers. +#. The class Clock implements the configuration of the clkout-pin. #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf """ diff --git a/adafruit_pcf8563/timer.py b/adafruit_pcf8563/timer.py index 5c51945..a036d4c 100644 --- a/adafruit_pcf8563/timer.py +++ b/adafruit_pcf8563/timer.py @@ -5,8 +5,8 @@ # SPDX-License-Identifier: MIT """ -`adafruit_pcf8563_timer` - PCF8563 Timer module -=============================================== +`timer` - PCF8563 Timer module +============================== This class supports the timer of the PCF8563-based RTC in CircuitPython. @@ -19,7 +19,7 @@ to the constructor of the timer. Author(s): Bernhard Bablok -Date: November 2023 +Date: March 2023 Implementation Notes -------------------- @@ -58,7 +58,7 @@ pass -class PCF8563_Timer: # pylint: disable=too-few-public-methods +class Timer: # pylint: disable=too-few-public-methods """Interface to the timer of the PCF8563 RTC. :param I2C i2c_bus: The I2C bus object diff --git a/examples/pcf8563_simpletest.py b/examples/pcf8563_simpletest.py index 8e82516..e45141b 100644 --- a/examples/pcf8563_simpletest.py +++ b/examples/pcf8563_simpletest.py @@ -12,13 +12,13 @@ import board import busio -import adafruit_pcf8563 +from adafruit_pcf8563.pcf8563 import PCF8563 # Change to the appropriate I2C clock & data pins here! i2c_bus = busio.I2C(board.SCL, board.SDA) # Create the RTC instance: -rtc = adafruit_pcf8563.PCF8563(i2c_bus) +rtc = PCF8563(i2c_bus) # Lookup table for names of days (nicer printing). days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") diff --git a/pyproject.toml b/pyproject.toml index d54fcbd..2f75f9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ classifiers = [ dynamic = ["dependencies", "optional-dependencies"] [tool.setuptools] -py-modules = ["adafruit_pcf8563"] +packages = ["adafruit_pcf8563"] [tool.setuptools.dynamic] dependencies = {file = ["requirements.txt"]} From 19b6b6ef92978c50bce3d42ea1d76ea598e95630 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sat, 18 Mar 2023 13:49:24 +0100 Subject: [PATCH 10/14] added all modules of package --- docs/api.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index 4931671..b211a32 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,3 +1,9 @@ -.. automodule:: adafruit_pcf8563 +.. automodule:: adafruit_pcf8563.pcf8563 + :members: + +.. automodule:: adafruit_pcf8563.timer + :members: + +.. automodule:: adafruit_pcf8563.clock :members: From b0ab3b4bb9927e2ee97068e28d090a3b89f744d4 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Sun, 19 Mar 2023 11:08:54 +0100 Subject: [PATCH 11/14] removed blank lines from docstring --- adafruit_pcf8563/clock.py | 1 - adafruit_pcf8563/pcf8563.py | 1 - adafruit_pcf8563/timer.py | 1 - 3 files changed, 3 deletions(-) diff --git a/adafruit_pcf8563/clock.py b/adafruit_pcf8563/clock.py index 61f2be1..830779d 100644 --- a/adafruit_pcf8563/clock.py +++ b/adafruit_pcf8563/clock.py @@ -38,7 +38,6 @@ **Notes:** #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf - """ __version__ = "0.0.0+auto.0" diff --git a/adafruit_pcf8563/pcf8563.py b/adafruit_pcf8563/pcf8563.py index ba4bdf1..cbcb1b7 100644 --- a/adafruit_pcf8563/pcf8563.py +++ b/adafruit_pcf8563/pcf8563.py @@ -40,7 +40,6 @@ class is inherited by the chip-specific subclasses. interface to timer-specfic registers. #. The class Clock implements the configuration of the clkout-pin. #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf - """ __version__ = "0.0.0+auto.0" diff --git a/adafruit_pcf8563/timer.py b/adafruit_pcf8563/timer.py index a036d4c..65fea23 100644 --- a/adafruit_pcf8563/timer.py +++ b/adafruit_pcf8563/timer.py @@ -38,7 +38,6 @@ **Notes:** #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf - """ __version__ = "0.0.0+auto.0" From 3665b2b64cea41f21b84944509fd93650c3438bf Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sun, 19 Mar 2023 12:28:09 -0400 Subject: [PATCH 12/14] fixing docs --- adafruit_pcf8563/pcf8563.py | 5 ++--- docs/conf.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/adafruit_pcf8563/pcf8563.py b/adafruit_pcf8563/pcf8563.py index cbcb1b7..69fdb40 100644 --- a/adafruit_pcf8563/pcf8563.py +++ b/adafruit_pcf8563/pcf8563.py @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT """ -`adafruit_pcf8563` - PCF8563 Real Time Clock module +`pcf8563` - PCF8563 Real Time Clock module ==================================================== This library supports the use of the PCF8563-based RTC in CircuitPython. It @@ -36,8 +36,7 @@ class is inherited by the chip-specific subclasses. #. Milliseconds are not supported by this RTC. #. The alarm does not support seconds. It will always fire on full minutes. -#. This RTC has a single timer. The class Timer implements the -interface to timer-specfic registers. +#. This RTC has a single timer. The class Timer implements the interface to timer-specfic registers. #. The class Clock implements the configuration of the clkout-pin. #. Datasheet: http://cache.nxp.com/documents/data_sheet/PCF8563.pdf """ diff --git a/docs/conf.py b/docs/conf.py index e3c23a7..6cd355a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -# autodoc_mock_imports = ["adafruit_bus_device", "adafruit_register"] +autodoc_mock_imports = ["adafruit_bus_device", "adafruit_register"] # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] From d8ac4088b68c266311c5829beb28e2e4297fc36d Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 28 Apr 2023 08:31:16 +0200 Subject: [PATCH 13/14] removed clkout-attributes (available from clock.py) --- adafruit_pcf8563/pcf8563.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/adafruit_pcf8563/pcf8563.py b/adafruit_pcf8563/pcf8563.py index 69fdb40..07a9c03 100644 --- a/adafruit_pcf8563/pcf8563.py +++ b/adafruit_pcf8563/pcf8563.py @@ -92,24 +92,6 @@ class PCF8563: clockout_enabled = i2c_bit.RWBit(0x0D, 7) """True if clockout is enabled (default). To disable clockout, set to False""" - clockout_frequency = i2c_bits.RWBits(2, 0x0D, 0) - """Clock output frequencies generated. Default is 32.768kHz. - Possible values are as shown (selection value - frequency). - 00 - 32.768khz - 01 - 1.024kHz - 10 - 0.032kHz (32Hz) - 11 - 0.001kHz (1Hz) - """ - - CLOCKOUT_FREQ_32KHZ = const(0b00) - """Clock frequency of 32 KHz""" - CLOCKOUT_FREQ_1KHZ = const(0b01) - """Clock frequency of 4 KHz""" - CLOCKOUT_FREQ_32HZ = const(0b10) - """Clock frequency of 32 Hz""" - CLOCKOUT_FREQ_1HZ = const(0b11) - """Clock frequency of 1 Hz""" - def __init__(self, i2c_bus: I2C) -> None: time.sleep(0.05) self.i2c_device = I2CDevice(i2c_bus, 0x51) From cd6e3194fb723f4190a199ba96b2546b1829a9ce Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 28 Apr 2023 08:36:38 +0200 Subject: [PATCH 14/14] removed unused imports --- adafruit_pcf8563/pcf8563.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_pcf8563/pcf8563.py b/adafruit_pcf8563/pcf8563.py index 07a9c03..7fd0e76 100644 --- a/adafruit_pcf8563/pcf8563.py +++ b/adafruit_pcf8563/pcf8563.py @@ -48,10 +48,8 @@ class is inherited by the chip-specific subclasses. from adafruit_bus_device.i2c_device import I2CDevice from adafruit_register import i2c_bit -from adafruit_register import i2c_bits from adafruit_register import i2c_bcd_alarm from adafruit_register import i2c_bcd_datetime -from micropython import const try: import typing # pylint: disable=unused-import