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 Adafruit MatrixPortal S3 board def & update protomatter #8056

Merged
merged 5 commits into from
Jun 14, 2023

Conversation

jepler
Copy link
Member

@jepler jepler commented Jun 1, 2023

tested:

  • board.LED
  • neopixel as status LED
  • i2c scan finds lis3dh sensor
  • psram capacity
  • rgb matrix o_O

not tested:

  • the gpio pins
  • samd51 after protomatter update
  • esp32-s2 after protomatter update
  • rp2040 after protomatter update

Introduce new board properties for matrixportal-style boards:

  • MTX_COMMON
  • MTX_ADDRESS

These are intended to simplify use of the RGBMatrix constructor:

matrix = RGBMatrix(..., addr_pins=MTX_ADDRESS[:3], **MTX_COMMON)

removing the need for sending in the following individual parameters:

  • rgb_pins
  • clock_pin
  • latch_pin
  • output_enable_pins

... and making construction of a 16/32/64-row display easy by slicing a tuple of all address pins rather than writing out the individual pins. If it works out it'll be ported back to the matrixportal m4 as well.

tested:
 * board.LED
 * neopixel as status LED
 * i2c scan finds lis3dh sensor
 * psram capacity

not tested:
 * rgb matrix      o_O
 * the gpio pins

Introduce new `board` properties for matrixportal-style boards:
 * MTX_COMMON
 * MTX_ADDRESS

These are intended to simplify use of the RGBMatrix constructor:
```py
matrix = RGBMatrix(..., addr_pins=MTX_ADDRESS[:3], **MTX_COMMON)
```
removing the need for sending in the following individual parameters:
 * rgb_pins
 * clock_pin
 * latch_pin
 * output_enable_pins
and making construction of a 16/32/64-row display easy by slicing a tuple
of all address pins rather than writing out the individual pins. If it
works out it'll be ported back to the matrixportal m4 as well.
@jepler jepler requested a review from makermelissa June 1, 2023 22:24
@jepler
Copy link
Member Author

jepler commented Jun 1, 2023

@ladyada fyi

@makermelissa
Copy link
Collaborator

makermelissa commented Jun 2, 2023

I'm trying to build this on my system (and it very well could be my particular setup), but am running into this error when building:

[851/851] Generating ld/sections.ld
FAILED: esp-idf/esp_system/ld/sections.ld /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/esp-idf/esp_system/ld/sections.ld
cd /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/esp-idf/esp_system && python /Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/tools/ldgen/ldgen.py --config /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/sdkconfig --fragments /Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_ringbuf/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/driver/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_pm/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_gdbstub/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/espcoredump/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_phy/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_system/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_system/app.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/xtensa/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_common/common.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_common/soc.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_event/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_wifi/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/lwip/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/log/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/heap/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_hw_support/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/app_trace/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/freertos/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/newlib/newlib.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/newlib/system_libs.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/soc/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/hal/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/spi_flash/linker.lf	/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/bt/linker.lf --input /Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/components/esp_system/ld/esp32s3/sections.ld.in --output /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/esp-idf/esp_system/ld/sections.ld --kconfig /Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/Kconfig --env-file /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/config.env --libraries-file /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/ldgen_libraries --objdump /usr/bin/objdump
Traceback (most recent call last):
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 1548, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 2622, in parseImpl
    if (instring[loc] == self.firstMatchChar and
        ~~~~~~~~^^^^^
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/tools/ldgen/entity.py", line 136, in add_sections_info
    results = parser.parseString(first_line, parseAll=True)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 1814, in parseString
    raise exc
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 1804, in parseString
    loc, tokens = self._parse( instring, 0 )
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 1548, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 3705, in parseImpl
    loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 1548, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 4067, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/melissa/.espressif/python_env/idf4.4_py3.11_env/lib/python3.11/site-packages/pyparsing.py", line 1550, in _parseNoCache
    raise ParseException( instring, len(instring), self.errmsg, self )
pyparsing.ParseException: Expected "In archive" (at char 1), (line:2, col:1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/tools/ldgen/ldgen.py", line 178, in <module>
    main()
  File "/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/tools/ldgen/ldgen.py", line 136, in main
    sections_infos.add_sections_info(dump)
  File "/Users/melissa/Developer/c/circuitpython/ports/espressif/esp-idf/tools/ldgen/entity.py", line 138, in add_sections_info
    raise ParseException('Parsing sections info for library ' + sections_info_dump.name + ' failed. ' + p.msg)
pyparsing.ParseException: Parsing sections info for library /Users/melissa/Developer/c/circuitpython/ports/espressif/build-adafruit_matrixportal_s3/esp-idf/esp-idf/esp_ringbuf/libesp_ringbuf.a failed. Expected "In archive" (at char 0), (line:1, col:1)
ninja: build stopped: subcommand failed.
make: *** [esp-idf-stamp] Error 1

Any ideas?

@makermelissa
Copy link
Collaborator

makermelissa commented Jun 2, 2023

Ok, I've gotten past that issue (plus a few more that I already figured out) and am now stuck on:

GEN build-adafruit_matrixportal_s3/genhdr/moduledefs.h
In file included from ../../py/obj.h:29,
                 from ../../shared-module/displayio/Bitmap.h:33,
                 from ../../shared-bindings/displayio/Bitmap.h:30,
                 from build-adafruit_matrixportal_s3/autogen_display_resources-en_US.c:2:
esp-idf/components/newlib/platform_include/assert.h:20:10: fatal error: sdkconfig.h: No such file or directory
 #include <sdkconfig.h>
          ^~~~~~~~~~~~~
compilation terminated.

@makermelissa
Copy link
Collaborator

Ok, I just tried again and this time it worked.

@makermelissa
Copy link
Collaborator

After testing, the CIRCUITPY drive appears, however there is no output to the matrix. I went ahead and ran one of the examples from the RGB Matrices Learn guide and plugged in the correct pins. After running the code, I'm getting ValueError: rgb_pins[0] is not on the same port as clock. I double-checked pin assignments and they appear correct. Looking at where it’s happening in CP (https://github.com/adafruit/circuitpython/blob/main/shared-bindings/rgbmatrix/RGBMatrix.c#L77), it looks like because the difference between the clock pin (2) and the RGB pins (42, 41, 40, 38, 39, 37) is larger than 32, the error is triggered.

It apparently works fine in protomatter in arduino. I looked further into this and apparently it has been updated to treat the ESP32-S2 and ESP32-S3 a bit different (https://github.com/adafruit/Adafruit_Protomatter/blob/master/src/core.c#L179-L185).

and re-organize so that esp32 s2/s3 don't do as much at reset

.. it's not necessary (because most data is in esp-idf managed memory)
and doing this saves me from having to debug why reconstruct isn't working
properly on that platform.

This needs to be tested on other platforms again before being merged!
@jepler jepler changed the title Add minimally tested Adafruit MatrixPortal S3 board def Add minimally tested Adafruit MatrixPortal S3 board def & update protomatter Jun 8, 2023
@jepler
Copy link
Member Author

jepler commented Jun 8, 2023

@makermelissa this now works without crashing for me on my test setup, including when I exit the REPL.

Part of testing this PR will need to be going back and testing all the other micros that have rgbmatrix because they may be affected by the protomatter update or my re-org of what happens during interpreter reset to preserve the display.

@jepler jepler force-pushed the matrixportal-s3 branch from e12db05 to 50951d8 Compare June 8, 2023 22:47
@ladyada
Copy link
Member

ladyada commented Jun 9, 2023

yay i will test on hardware once there are artifacts

@jepler jepler force-pushed the matrixportal-s3 branch from dfe8578 to 50951d8 Compare June 9, 2023 14:12
@makermelissa
Copy link
Collaborator

I tested and it's working great for the most part. The changes I made to the MatrixPortal library were successful. I did have 1 hard crash and it may not have been related to this PR. Basically, I was:

  1. I had a slots demo running
  2. renamed it to slots.py
  3. copied over a different code.py
  4. pressed Ctrl+D to soft reset the board

I tried the same thing a second time, but it just stopped doing anything once I renamed code.py. Anyway, it's pretty minor and unlikely to happen most of the time, so I wouldn't block this PR because of it since a simple reset fixes it.

Artifacts are there, so I'll continue testing with the other boards. For the ESP32-S2, I'll try and see if I can get a FeatherWing working with the ESP32-S2 Feather.

@makermelissa
Copy link
Collaborator

makermelissa commented Jun 10, 2023

Tested successfully using the following:
ESP32-S3 using the MatrixPortal S3
SAMD51 using the MatrixPortal M4
RP2040 using the Interstate 75
ESP32-S2 using the Adafruit Feather ESP32-S2 + Matrix FeatherWing

Note: I did not test with the new constructor. I just tested using the old one.

@jepler
Copy link
Member Author

jepler commented Jun 10, 2023

thank you so much for the extensive testing @makermelissa ! ❤️

@jepler
Copy link
Member Author

jepler commented Jun 10, 2023

I will mark this PR out of draft mode once the related PR in protomatter is merged:

@jepler jepler changed the title Add minimally tested Adafruit MatrixPortal S3 board def & update protomatter Add Adafruit MatrixPortal S3 board def & update protomatter Jun 10, 2023
@tannewt tannewt added this to the 8.2.0 milestone Jun 12, 2023
@makermelissa
Copy link
Collaborator

makermelissa commented Jun 12, 2023

While testing, I realized BUTTON_UP (IO6) and BUTTON_DOWN (IO7) are missing from board.

@makermelissa
Copy link
Collaborator

I'm not sure if it's necessary, but ACCELEROMETER_INTERRUPT (IO15 on the S3) is also not defined.

@makermelissa
Copy link
Collaborator

Since this was stopping me from continuing to test, I added these to my local source and built it successfully. Let me know if you'd like me to push a commit.

@jepler jepler marked this pull request as ready for review June 13, 2023 13:36
@jepler
Copy link
Member Author

jepler commented Jun 13, 2023

The PR within protomatter has been merged, so this is hopefully also ready @makermelissa

@jepler
Copy link
Member Author

jepler commented Jun 13, 2023

oops, your comments crossed with mine. Please do add those buttons to this PR if github will let you!

@makermelissa
Copy link
Collaborator

Ok, buttons added!

@makermelissa
Copy link
Collaborator

Let's wait until I finish testing the remaining guides before merging this in case I find something else.

@makermelissa
Copy link
Collaborator

Also, I also noticed while copying files it does this seizure-inducing flickering on the panel. I figure that it is due to whatever you needed to do to get CircuitPython not to crash.

@jepler
Copy link
Member Author

jepler commented Jun 13, 2023

On devices where the code & CIRCUITPY reside on the same flash chip, the erase cycle (esp_partition_erase_range in this case) prevents other code from running unless it's been specially placed in RAM. I suspect this probably hasn't been done. (I didn't do it!)

Are there any Arduino examples that combine protomatter & USB mass storage? If so, how do they behave when writing to mass storage?

@makermelissa
Copy link
Collaborator

After a quick search, it looks like this example may qualify: https://github.com/adafruit/Adafruit_Protomatter/tree/master/examples/animated_gif

I haven't run it yet, so I'm not sure about the behavior, but I'll let you know after I get to it.

@makermelissa
Copy link
Collaborator

The flickering happens with that example as well, so it should be fine.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

At this point with what I've tested, I think it should be good fine to add.

@jepler jepler merged commit 666fb94 into adafruit:main Jun 14, 2023
dhalbert pushed a commit to dhalbert/circuitpython that referenced this pull request Sep 19, 2023
Although this driver and associated hardware can be used on any board, it
makes to only freeze it for PYB and PYBD boards.  It can be easily copied
to any board if needed.

Fixes issue adafruit#8056.

Signed-off-by: Damien George <damien@micropython.org>
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