Skip to content

[RFC][DNM] First Draft #1

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 9 commits into from
Nov 4, 2018
Merged

Conversation

microbuilder
Copy link
Contributor

First draft of a helper class for the AT command based Bluefruit LE SPI friend.

@tannewt tannewt self-requested a review November 1, 2018 00:03
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 pretty good! Just a couple comments. Thanks!

Introduction
============

.. image:: https://readthedocs.org/projects/adafruit-circuitpython-bluefruitspi/badge/?version=latest
Copy link
Member

Choose a reason for hiding this comment

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

Super nitpicky but the portion after the circuitpython piece should match the GitHub repo. So, I'd recommend dropping the friend from the github url. That way our adabot checks can match them all up.

COMMAND = const(0x10) # Command message
RESPONSE = const(0x20) # Response message
ALERT = const(0x40) # Alert message
ERROR = const(0x80) # Error message
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest removing these consts. It's a micropythonism that doesn't do anything in this case. (It only works on globals with names that start with _)

Copy link
Member

Choose a reason for hiding this comment

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

im redoing these as all plain consts since we only use them internally

pass

# Configure SPI for 4MHz
self._spi.configure(baudrate=4000000, phase=0, polarity=0)
Copy link
Member

Choose a reason for hiding this comment

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

Give these args to SPIDevice() and it'll manage it for you (it sets it each transaction in case its a shared bus.)

Copy link
Member

Choose a reason for hiding this comment

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

done!


# Check out the SPI bus
while not self._spi.try_lock():
pass
Copy link
Member

Choose a reason for hiding this comment

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

Do you have to lock across these multiple transactions? Otherwise I'd suggest using a context manager to manage the transaction using SPIDevice.

        with self._spi as spi:
            spi.write(self._buf_tx, end=len(cmd) + 4)

Copy link
Member

Choose a reason for hiding this comment

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

ditto


# Wait up to 200ms for a response
timeout = 0.2
while timeout > 0.0 and self._irq is False:
Copy link
Member

Choose a reason for hiding this comment

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

this should be self._irq.value

@ladyada
Copy link
Member

ladyada commented Nov 2, 2018

hey i updated this code to use contexts for SPI, seems to work without debug, i also made the digitalio stuff a little more 'pythonic' the way we like to do em. i dont know how to adapt a PR with a new PR so here's the file, you can just paste it over

adafruit_bluefruitspi.txt

@ladyada
Copy link
Member

ladyada commented Nov 2, 2018

added reset connection, some wrappers

@microbuilder what we need next is data rx and tx which i think are wholy new packet types right? also commands need to be really short to fit into an SDEP 16 byte packet, can we split that up? AT+GAPDEVNAME= is a good test

code.txt
adafruit_bluefruitspi.txt

@ladyada
Copy link
Member

ladyada commented Nov 4, 2018

im going to merge, then do my updates to fix the above

@ladyada ladyada merged commit 50d78b0 into adafruit:master Nov 4, 2018
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.

3 participants