adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
453 stars 340 forks source link

Update busio to avoid always triggering frequency warning #713

Closed makermelissa closed 1 year ago

makermelissa commented 1 year ago

I realized the reason the warning was commented out before #708 is because busio uses a default frequency value of 100000 which will always trigger the warning. This will fix it so if the user isn't trying to set the frequency to something besides the default, it won't trigger the warning.

tannewt commented 1 year ago

Is this the default speed for linux too? Can you read what speed linux is set to somehow?

caternuson commented 1 year ago

Is this the default speed for linux too?

yep

Can you read what speed linux is set to somehow?

hmmm...maybe? here's a pi example:

pi@raspberrypi:~ $ python3
Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> with open('/sys/bus/i2c/devices/i2c-1/of_node/clock-frequency','rb') as fp:
...     raw = fp.read()
... 
>>> print(raw)
b'\x00\x01\x86\xa0'
>>> struct.unpack(">I", raw)
(100000,)
>>>

not sure how universal that is across linux distros though