Skip to content
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

add support for micropython on RP2040 boards #14

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

add support for micropython on RP2040 boards #14

wants to merge 19 commits into from

Conversation

oclyke
Copy link

@oclyke oclyke commented Feb 4, 2021

what it do

  • adds a build script micropython/tools/qwiic-mpy/gen.py which can be used to generate and update bytecode (.mpy) files for micropython from the Qwiic_Py sources.
  • modifies .gitignore so that .mpy files are ignored except within the micropython/dist directory, so that users can access pre-compiled files
  • adds micropython/README.md which explains the basics of how to use everything

dependencies
add micropython RP2040 i2c driver - this is necessary b/c it contains the i2c driver for micropython/rp2040

status
✅ build script
✅ module compatibility with filesystem
✅ i2c driver seems to work
✅ device driver testing satisfactory
⚠️ additional boards can be added (non-blocking)

oclyke added 4 commits February 3, 2021 12:01
most systems are in place to make this a possibility.
- modules compiled to bytecode
- imports on target board functioning
- basic instructions written

what's next:
- testing
@oclyke oclyke requested review from a user and Wenn0101 February 4, 2021 01:00
@oclyke oclyke self-assigned this Feb 4, 2021
@oclyke
Copy link
Author

oclyke commented Feb 4, 2021

p.s. i have not included the pre-compiled binaries in the PR yet in case they change during testing. as a reviewer you will need to generate them yourself. fortunately it is as easy as:

  • make sure you have micropython and have built mpy-cross
    • cd raspberrypi/micropython/mpy-cross && make
  • run the generate script from the Qwiic_Py root directory and provide the -m flag to tell it where to find the mpy-cross executable
    • ./micropython/tools/qwiic-mpy/gen.py -m ~/raspberrypi/micropython/mpy-cross/mpy-cross

p.s.s. perhaps this script could make a good candidate for continuous integration

oclyke added 5 commits February 3, 2021 22:32
w/o issues copying binary files we are able to use the main ```__init__.py``` file from the Qwiic_Py repo, thus deduplicating code
all that is needed is to add the micropython_rp2040_i2c.py driver to the list of drivers, and also copy additional drivers to the target b/c they are imported within ```__init__.py```
updated instructions to point toward improved ```pico``` branch of rshell
also fix a few bugs with bytes/bytearray usage
@oclyke
Copy link
Author

oclyke commented Feb 15, 2021

latest pushes run on the rp2040, however there seems to be an issue with block reads that causes only zero to be read back. more information is needed at this time

oclyke added 3 commits February 15, 2021 14:44
@oclyke oclyke marked this pull request as ready for review February 16, 2021 21:09
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Comments/Feedback:

README

  • Start this with the general concept- this will install pre-compiled files onto your board
  • List out the supported boards ( - full names and links to the boards on our site)

Getting started section - keep it high-level, easy to follow. Specifically

  • Outline the use of rshell and the tweaks needed for it to work with the rp2040, and then just show the commands used to copy the files to the specific board. I'd include code sections fo each of our boards (SO someone can just copy and paste these commands).
  • Add any commands need to copy examples over
  • Show example running example using the RPEL

Below this, discuss details

  • how to create the mpy files
  • Contents and structure of the micropython folder ...etc

Basically, keep getting started at a high level, and make it the first section of the document. This is what most people will use.

MPY GENERATION

  • Should this be a GitHub action?

micropython/tools/qwiic_mpy/gen.py

  • rename to mpygen.py
  • Add comments and description to code.
  • Switch source to 4 space tabs, not 2

micropythong/tools/qwiic-mpy/push-driver

  • The names of these should follow the template rp2040_.rshell
  • All lower case
  • Note: the PiMicro is now the promicro

micropythong/src/qwiic_i2c/init.py

  • What does this exist??
  • A better solution is to add exception handling around the loads of the other platform drivers in the driver logic of the main qwiic_i2c repo. Basically a try-except-else block. where the driver is loaded in try, execution is a pass, and else adds the driver class to the "_drivers" list.
    I can provide further details if needed.

** Board Files **

  • Update the names of the board folders to be rp2040_ and all lower case.

@oclyke
Copy link
Author

oclyke commented Mar 11, 2021

addressing comments:

  • moved "supported platforms" to the end of README so bytecode explanation comes sooner
  • added clarification for rshell command usage
  • added step to upload board files
  • added README about board files in src/boards
  • vestigial file micropythong/src/qwiic_i2c/init.py removed (was holdover from previous issues)
  • comments added to trickier bits of mpygen.py

re: github actions

  • yes i think the mpygen.py script would be a good candidate to automate with ci. the generate-variants script from the Apollo3_Arduino repo shows one way to do this (though it is not necessarily the best way or even a good way for all i know)

note: at the moment i am unable to add demo output to the README - i am away from my test hw. i will get back to this as soon as i can however it should be possible for others to modify this PR so anyone else may add it if they have demo output handy

@andypiper
Copy link

Jumping in here with a question, as I’m working with MicroPython on ESP32. The board I have here has a Qwiic connector, would this PR be a starting point for having that supported in MP? / any progress on having this merged in general?

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.

2 participants