Skip to content

Add microbit v2 split crates #44

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 1 commit into from
May 10, 2021

Conversation

robyoung
Copy link
Contributor

@robyoung robyoung commented May 8, 2021

Relates to #27 and #41

Add support for micro:bit v2

This change is a major rewrite. The crate is split into a multi-crate workspace organised in a similar way to nrf-rs/nrf-hal.

  • microbit-common almost all the code, feature flagged for the different major board versions (V1 and V2).
  • microbit the V1 board support crate
  • microbit-v2 the V2 board support crate
  • xtask cargo xtask crate for running CI accross the different versions.
  • examples/* the examples now need to be crates as they may support both versions

Code changes to support micro:bit V2

Add features v1 and v2. Originally they were microbit-v1 and microbit-v2, however having the feature name the same as the crate name requires the namespaced-features cargo feature which basically restricts us to nightly.

Add micro:bit v2 support to display module

This was hard and I am not super happy with the solution. It is much more bit twiddling than I am comfortable with.

The issue that made it so difficult is that on the microbit v2 the column pins are on the P0 and P1 ports so all the row wise writes have to be split across the two ports.

Get microbit v2 led examples working

  • Create a new v2 gpio module and conditionally use v1 or v2
  • Move NUM_ROWS and NUM_COLS consts into gpio module so they can differ between v1 and v2
  • Move degrading the LED pins into the gpio module so it can differ between v1 and v2

The code for the nonblocking display is a nightmare. The columns are split between the two GPIO ports so the cols argument to
display_row_leds needs to be split between the two ports. This is a bit painful but doable. The bit that is really confusing me is that columns 2 and 3 seem to be swapped.

CI changes

I have mostly copied CI from nrf-rs/nrf-hal with some minor differences. I didn't like having to list all the examples in the CI so it derives the features and targets required for each example from the cargo manifest. Copying nrf-hal also meant getting the doc tests building as well which is nice. For the docs I've favoured complexity in the source for the sake of docs that are clearer.

Examples changes

The microbit-v2 crate does not yet support serial so I have chosen to favour probe-run and defmt for all the examples except those that are specifically about serial communication (those now just run on the v1 crate). I have not ported over the examples that I could not get working (receivedcf77 and the magnetometer ones). I plan on implementing the magnetometer for both versions in the near future so examples for that will hopefully come back soon.

@robyoung robyoung force-pushed the add-microbit-v2-split-crates branch 8 times, most recently from 4fc54c0 to a8d5fe6 Compare May 10, 2021 16:04
@robyoung robyoung force-pushed the add-microbit-v2-split-crates branch from a8d5fe6 to 7b0379d Compare May 10, 2021 19:57
@robyoung robyoung mentioned this pull request May 10, 2021
3 tasks
@robyoung robyoung force-pushed the add-microbit-v2-split-crates branch 2 times, most recently from f5037f9 to bbdf218 Compare May 10, 2021 20:34
@robyoung robyoung marked this pull request as ready for review May 10, 2021 20:35
This change is a major rewrite. The crate is split into a
multi-crate workspace layed out in a similar way to nrf-rs/nrf-hal.

- `microbit-common` almost all the code, feature flagged for the
  different major board versions (V1 and V2).
- `microbit` the V1 board support crate
- `microbit-v2` the V2 board support crate
- `xtask` cargo xtask crate for running CI accross the different
  versions.
- `examples/*` the examples now need to be crates as they may support
  both versions

Code changes to support micro:bit V2
------------------------------------

Add features `v1` and `v2`. Originally they were `microbit-v1` and
`microbit-v2`, however having the feature name the same as the crate
name requires the namespaced-features cargo feature which basically
restricts us to nightly.

Add microbit v2 support to display module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This was hard and I am not super happy with the solution. It is much
more bit twiddling than I am comfortable with.

The issue that made it so difficult is that on the microbit v2 the
column pins are on the P0 and P1 ports so all the row wise writes have
to be split accross the two ports.

Get microbit v2 led examples working
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Create a new v2 gpio module and conditionally use v1 or v2
- Move NUM_ROWS and NUM_COLS consts into gpio module so they can differ
  between v1 and v2
- Move degrading the LED pins into the gpio module so it can differ
  between v1 and v2

The code for the nonblocking display is a nightmare. The columns are
split between the two GPIO ports so the cols argument to
`display_row_leds` needs to be split between the two ports. This is a
bit painful but doable. The bit that is really confusing me is that
columns 2 and 3 seem to be swapped.

CI changes
----------

I have mostly copied CI from nrf-rs/nrf-hal with some minor differences.
I didn't like having to list all the examples in the CI so it derives
the features and targets required for each example from the cargo
manifest. Copying nrf-hal also meant getting the doc tests building as
well which is nice. For the docs I've favoured complexity in the source
for the sake of docs that are clearer.

Examples changes
----------------

The microbit-v2 crate does not yet support serial so I have chosen to
favour probe-run and defmt for all the examples except those that are
specifically about serial communication (those now just run on the v1
crate). I have not ported over the examples that I could not get working
(receivedcf77 and the magnetometer ones). I plan on implementing the
magnetometer for both versions in the near future so examples for that
will hopefully come back soon.
@robyoung robyoung force-pushed the add-microbit-v2-split-crates branch from bbdf218 to dbbdd1c Compare May 10, 2021 20:38
@robyoung robyoung requested a review from therealprof May 10, 2021 20:39
@robyoung
Copy link
Contributor Author

One thing not addressed is the memory.x file. I'm not sure how that works.

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

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

Looks excellent. Thanks a lot!

bors r+

@therealprof
Copy link
Contributor

One thing not addressed is the memory.x file. I'm not sure how that works.

Don't worry about this for now. Only some numbers change.

@bors
Copy link
Contributor

bors bot commented May 10, 2021

Build succeeded:

@bors bors bot merged commit 3049f8a into nrf-rs:main May 10, 2021
@robyoung robyoung mentioned this pull request May 14, 2021
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