Skip to content

add support for timer and clkout #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 28, 2023
Merged

Conversation

bablokb
Copy link
Contributor

@bablokb bablokb commented Feb 18, 2023

This add support for the builtin timer and for signal generation using the CLKOUT-pin

@tannewt
Copy link
Member

tannewt commented Feb 21, 2023

Thanks for the PR! Any idea how much memory these additions take? I wonder if we should add them with a subclass.

@bablokb
Copy link
Contributor Author

bablokb commented Feb 21, 2023

Is gc.mem_free() exact enough to answer this question?

@tannewt
Copy link
Member

tannewt commented Feb 22, 2023

Yup! Please call gc.collect() before it.

@bablokb
Copy link
Contributor Author

bablokb commented Feb 24, 2023

Test code is:

import gc
import board
import busio

PIN_SDA  = board.GP2
PIN_SCL  = board.GP3

gc.collect()
print("free mem before import: %s" % gc.mem_free())

from adafruit_pcf8563 import PCF8563
gc.collect()
print("free mem after import: %s" % gc.mem_free())

i2c = busio.I2C(PIN_SCL,PIN_SDA)
rtc = PCF8563(i2c)
gc.collect()
print("free mem after constructor: %s" % gc.mem_free())

The new implementation uses 1840 extra bytes (after object creation), comparing py-files.

BTW: pressing repeatedly CTRL-D to reload the program will result in different results. So the state does not seem to be reset deterministically.

I could refactor the timer-code to a separate class and add a get_timer() method. The timer-class would then implement all the timer-specific register access. Note that I have a similar pull-request for the PCF8523: adafruit/Adafruit_CircuitPython_PCF8523#30 which then should probably also be implemented like this.

@tannewt
Copy link
Member

tannewt commented Feb 28, 2023

BTW: pressing repeatedly CTRL-D to reload the program will result in different results. So the state does not seem to be reset deterministically.

How much does it vary?

I could refactor the timer-code to a separate class and add a get_timer() method. The timer-class would then implement all the timer-specific register access.

I would add a separate timer class in a separate file (in the same file it'll still be loaded into ram.) You could then have that class subclass the regular one or take it into the constructor. I wouldn't have the main class construct the timer class for you.

Note that I have a similar pull-request for the PCF8523: adafruit/Adafruit_CircuitPython_PCF8523#30 which then should probably also be implemented like this.

👍

@bablokb
Copy link
Contributor Author

bablokb commented Feb 28, 2023

How much does it vary?

As far as I remember about 1K.

I would add a separate timer class in a separate file (in the same file it'll still be loaded into ram.) You could then have that class subclass the regular one or take it into the constructor. I wouldn't have the main class construct the timer class for you.

The timer-class should go into a separate class for sure. But I don't see any necessity to subclass the regular one or even use an instance of it. Both the rtc-class and the timer-class are more or less facades for specific registers of an I2C-device with fixed address and the timer-class would not share or even depend on anything of the rtc-class (n.b. the timer doesn't even need a correct time to be set in the rtc).

I will post an updated version of the PR for discussion.

@tannewt
Copy link
Member

tannewt commented Feb 28, 2023

I will post an updated version of the PR for discussion.

Sounds good! That's a good point.

As far as I remember about 1K.

Weird. That seems like a lot. I'd expect it to be pretty deterministic.

@bablokb
Copy link
Contributor Author

bablokb commented Mar 2, 2023

This refactors the timer-code to it's own class. Probably the pyproject.toml needs some care too. Normally I would expect multipe files/classes within module (i.e. the adafruit_pcf8563 should be a directory), but that would break existing code.

@bablokb
Copy link
Contributor Author

bablokb commented Mar 5, 2023

The CI tests fail now because of two toplevel files and recommend to merge them into a single file. Or to create a subdirectory). But as noted above, this would break the imports of existing code.

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Mar 6, 2023

I think making the subdirectory so that adafruit_pcf8563/ is a directory instead of .py file is the way to go.

It will cause a change to the import statement in code that uses it, but we can make sure to update all of our example code at the same time, and release it with a major version number increase to indicate the incompatibility.

Having two python library files in the root of the repo causes issues with other parts of the infrastructure and surrounding tools. Many of them assume it will either be single file, or folder with base name and multiple files inside.

@bablokb
Copy link
Contributor Author

bablokb commented Mar 6, 2023

I fully agree. Note that a similar PR for the 8523 would probably affect far more people because of the existing PCF8523 breakout. But I don't think there is a better solution.

@bablokb
Copy link
Contributor Author

bablokb commented Mar 10, 2023

Any ideas on how to reach a consensus on what to do?

@tannewt
Copy link
Member

tannewt commented Mar 10, 2023

I agree with @FoamyGuy's suggestions.

@bablokb
Copy link
Contributor Author

bablokb commented Mar 10, 2023

Ok, fine. So I will post a new version of the PR moving the files to a subdirectory. Once that is fine, I will also rework the PR for the 8523.

@bablokb
Copy link
Contributor Author

bablokb commented Mar 19, 2023

I don't understand the problem of the CI, it states

docstring of adafruit_pcf8563.pcf8563:33:Enumerated list ends without a blank line;

but there is a blank linke after line 33 and it is also an area I did not touch.

@jposada202020
Copy link
Contributor

@bablokb I created bablokb#1 with the necessary changes. you coudl either change it in your branch or merge my pull request in your branch. sphinx is sometimes... well sphinx :)

@bablokb
Copy link
Contributor Author

bablokb commented Apr 27, 2023

Is there a reason (except lack of time) why this PR is not merged?

@jposada202020
Copy link
Contributor

Sorry about that, I could merge. @tannewt and @FoamyGuy any comments?

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this fell off my radar. Feel free to ping me if I haven't replied in over a business day.

One suggestion. Looks good otherwise and will need to be a major release.

@bablokb
Copy link
Contributor Author

bablokb commented Apr 28, 2023

I have removed the clokout-attributes with one exception: I left clokout_enabled. This is because the CLKOUT is active on POR, but the PCF85x3 user's manual recommends to disable it to minimize power-consumption.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@tannewt tannewt merged commit bec2491 into adafruit:main Apr 28, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 29, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI to 1.0.6 from 1.0.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_NeoPixel_SPI#36 from RossK1/adding_type_hints
  > Add upload url to release action
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCF8563 to 2.0.0 from 1.0.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCF8563#6 from bablokb/4upstream
  > Add upload url to release action
  > Add .venv to .gitignore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.11.2 from 3.11.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#113 from tekktrik/fix/typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_FancyLED to 1.4.15 from 1.4.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_FancyLED#30 from SebastienFauque/feature/typingLEDs
  > Add upload url to release action
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants