10000 samd: Allow using default devices for UART, I2C and SPI. by robert-hh · Pull Request #16735 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

samd: Allow using default devices for UART, I2C and SPI. #16735

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 6 commits into from
Mar 3, 2025

Conversation

robert-hh
Copy link
Contributor

Summary

Some of the SAMD boards show pin names for UART, I2C and SPI on their silkscreen. At these
boards Pin name aliases existed already to use e.g. "SCL" or "TX" as pin name wherever a Pin had to be specified. This PR allows to omit the device ID and Pin definitions in the constructor if
the default device is going to be used. So the default UART, I2C or SPI device can be instantiated
with:

from machine import UART, I2C, SPI
uart = UART()
i2c = I2C()
spi = SPI()

The documentation was updated accordingly to reflect the changes and fix bugs.

Testing

The change has been tested to return the proper device with:

Adafruit Feather M0
Adafruit Feather M4
Adafruit ItsyBitsy M0
Adafruit ItsyBitsy M4
Adafruit Metro Express M4
Adafruit Trinket M0
Adafruit QT PY
Seeed XIAO SAMD21
Seeed WIO terminal
Minisam M4
Sparkfun SAMD51 Thing plus

It has been tested to raise an error if the device is NOT fully specified with the SAMD Generic builds.

Copy link
github-actions bot commented Feb 11, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:  +352 +0.131% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@robert-hh robert-hh changed the title samd: Allow using devices for UART, I2C and SPI. samd: Allow using default devices for UART, I2C and SPI. Feb 15, 2025
@robert-hh robert-hh force-pushed the samd_default_pin branch 2 times, most recently from aefc63d to 92be84c Compare February 28, 2025 08:26
@robert-hh robert-hh force-pushed the samd_default_pin branch 2 times, most recently from 9abc2d4 to 8c21b89 Compare March 1, 2025 15:33
If a board configures a default I2C instance and/or SCL/SDA pins, then
these no longer need to be given in the constructor.  This allows the user
to easily construct the default I2C instance via `machine.I2C()` and that
will work on the default pins as designated on the board silkscreen.

Signed-off-by: robert-hh <robert@hammelrath.com>
If a board configures a default SPI instance and/or SCK/MOSI/MISO pins,
then the user can create a default SPI object using `machine.SPI()`.

Also, if MISO is not going to be used, then MISO can be set to `None` with
`miso=None`.

Signed-off-by: robert-hh <robert@hammelrath.com>
If a board configures a default UART instance and/or TX/RX pins then the
user can create a default UART object using `machine.UART()`.

Signed-off-by: robert-hh <robert@hammelrath.com>
These were missing and are needed to support UART/I2C/SPI default pins.

Signed-off-by: robert-hh <robert@hammelrath.com>
In combination with the defautl Pins the default device can now be
instantiated e.g. as: uart = UART().  Similar for I2C and SPI.

Signed-off-by: robert-hh <robert@hammelrath.com>
Changes are:
- Add the RX/TX pins to the table.  In most cases these are the D0/D1 pins.
- Document the ability for the instantiation of the default devices without
  submitting ID or pins.
- Improve the example script creating the pin list to show multiple name
  assigments to the same pin.
- Fix errors in the pinout document.

Signed-off-by: robert-hh <robert@hammelrath.com>
Copy link
Member
@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

Thanks for updating. I tested this on ADAFRUIT_ITSYBITSY_M0_EXPRESS and it works well.

I think this is a really nice improvement to the user experience, you no longer need to know about instance IDs to get started using the board. You can just create the default I2C/UART/SPI and it'll work correctly on the pins printed on the silkscreen. You only need to know about instance IDs if you want to delve deeper.

@dpgeorge dpgeorge merged commit 016ae19 into micropython:master Mar 3, 2025
9 checks passed
@robert-hh
Copy link
Contributor Author

Thank you for your careful review and merging. Yes, it's more convenient now. I had to look up the ID numbers myself when testing with one of the rarely used boards.

@robert-hh robert-hh deleted the samd_default_pin branch March 3, 2025 08:45
@dpgeorge
Copy link
Member
dpgeorge commented Mar 3, 2025

Thank you for your careful review and merging.

You're welcome! I did massage the commits a little before merging, because there were some review fix-ups in latter commits that belonged in earlier commits.

@robert-hh
Contributor Author

I did massage the commits a little before merging, because there were some review fix-ups in latter commits that belonged in earlier commits.

Thank you. I noticed that and was confused at first. It looks better now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0