adafruit / Adafruit_Blinka

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

Add frequency property to busio.SPI #161

Closed caternuson closed 5 years ago

caternuson commented 5 years ago

From CircuitPython API: https://circuitpython.readthedocs.io/en/4.x/shared-bindings/busio/SPI.html#busio.SPI.frequency

On a CircuitPython board:

Adafruit CircuitPython 4.1.0 on 2019-08-02; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> spi = board.SPI()
>>> spi.frequency
250000
>>> 

On a Blinka board (RPi):

pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> spi = board.SPI()
>>> spi.frequency
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SPI' object has no attribute 'frequency'
>>> 
ladyada commented 5 years ago

woops - yeah, you can initialize the frequency but not set/get it after - wanna do that?

caternuson commented 5 years ago

Just to clarify - should be a read only property.

Adafruit CircuitPython 4.1.0 on 2019-08-02; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> spi = board.SPI()
>>> spi.frequency
250000
>>> spi.frequency = 6000000
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SPI' object has no attribute 'frequency'
>>> 

I think setting requires using configure(), via baudrate: https://circuitpython.readthedocs.io/en/4.x/shared-bindings/busio/SPI.html#busio.SPI.configure

ladyada commented 5 years ago

yep!

caternuson commented 5 years ago

Added with #164