Skip to content

drivers/ws281x: add VT100 backend for native#12793

Merged
benpicco merged 3 commits intoRIOT-OS:masterfrom
benpicco:ws281x_vt100
Feb 10, 2020
Merged

drivers/ws281x: add VT100 backend for native#12793
benpicco merged 3 commits intoRIOT-OS:masterfrom
benpicco:ws281x_vt100

Conversation

@benpicco
Copy link
Copy Markdown
Contributor

@benpicco benpicco commented Nov 23, 2019

Contribution description

To quickly iterate on animations it is handy to being able to simulate the output on native.
This adds a VT100 terminal backend to the ws281x driver that outputs the colors straight to the terminal.
It should work with any sufficiently modern terminal emulator.

Testing procedure

run tests/driver_ws281x on native.

Issues/PRs references

@benpicco benpicco added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 23, 2019
@benpicco benpicco requested a review from maribu November 23, 2019 08:34
@benpicco
Copy link
Copy Markdown
Contributor Author

Meh, it looks like there is currently no way to have two disjunctive FEATURES_REQUIREDs and that ifneq ($(BOARD),native) hack doesn't fly with Murdock.

@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 23, 2019

You can use features optional and in the second recursive round of dependency resolution the optional feature becomes used, if it is available

USEMODULE += ws281x_atmega
endif
# fall back to VT100 terminal output if no other
# backend is availiable.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
# backend is availiable.
# backend is available.

USEMODULE += xtimer
endif

ifneq (,$(filter ws281x_vt100,$(USEMODULE)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This block should be moved to drivers/Makefile.include

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But it looks so out of place there. 😮

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The idea of the Makefile.dep is to set/resolve the dependencies of a module in the build. Makefile.include should contain code for setting build configuration variables. For me, CFLAGS is a build configuration variable, so it should be in drivers/Makefile.include.
git grep gives an opposite result as what I just said but I think the already existing CFLAGS defined in Makefile.dep should be moved in Makefile.include.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the cleanest option would be to have those defines in a header file. Via CFLAGS, those defines are available for every module and compilation unit, even though they are only needed for the ws281x module.

I see to options for using a header file for this:

a) A common header, let's say ws281x_backend.h, which uses #ifdef MODULE_WS281X_<BACKEND> to provide the required defines.
b) A separated ws281x_backend.h for each backend located at drivers/ws281x/include/<BACKEND_NAME>/ws281x_backend.h. And Makefile.include is used to add drivers/ws281x/include/<BACKEND_NAME> to INCLUDES for the used backend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The simpler the better - I prefer option a).

@benpicco
Copy link
Copy Markdown
Contributor Author

benpicco commented Nov 23, 2019

You can use features optional and in the second recursive round of dependency resolution the optional feature becomes used, if it is available

But then arch_avr8 is still required.
If both features are optional it will also build (and fail) if neither is available.

How about just using the printf() version as a fallback if no other backend is available? It will work on any board, it's just not what most users would expect 😆

@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 23, 2019

Like this:

ifneq (,$(filter ws281x,$(USEMODULE)))
  FEATURES_OPTIONAL += arch_avr8 arch_native
  ifeq (,$(filter ws281x_%,$(USEMODULE)))
    ifneq (,$(filter arch_avr8,$(FEATURES_USED))) 
      USEMODULE += ws281x_atmega
    endif
    ifneq (,$(filter arch_avr8,$(FEATURES_USED))) 
      USEMODULE += ws281x_vt100
    endif
  USEMODULE += xtimer
endif

@maribu
Copy link
Copy Markdown
Member

maribu commented Nov 23, 2019

You need to overwrite the ws281x_init() in order to not init the GPIO

@benpicco
Copy link
Copy Markdown
Contributor Author

Like this

That's what I did in 0b661f7

The problem is in the test Makefile.

@@ -1,4 +1,4 @@
BOARD ?= atmega328p
BOARD ?= native
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about adding:

ifneq (native,$(BOARD))
  FEATURES_REQUIRED := arch_avr8
endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's what I tried first.

The problem is that Murdock then parsed the file differently than make would (not sure which script is responsible for it) and ended up building it for all platforms, ignoring the conditional FEATURES_REQUIRED.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Murdock uses make info-boards-supported to get the list of supported boards. In the worst case, we would need to add FEATURES_PROVIDED += ws281x_backend to cpu/atmega_common/Makefile.features and to cpu/native/Makefile.features and require that... But I'm not really thrilled but that idea.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem is that Murdock then parsed the file differently than make would (not sure which script is responsible for it) and ended up building it for all platforms, ignoring the conditional FEATURES_REQUIRED.

No, the issue is that the main application Makefile always gets fully evaluated before info-boards-supported, independent of Murdock.

So the if native: require avr thing needs to be somewhere in Makefile.dep. (It seems weird to begin with, though though. 😉 )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So the if native: require avr thing needs to be somewhere in Makefile.dep. (It seems weird to begin with, though though. )

That will work for native, but what if we add that SPI backed?
Testing the contents of FEATURES_PROVIDED is not allowed and I'd rather not maintain a BOARD_PROVIDES_SPI list shiver

Copy link
Copy Markdown
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

ACK. Code looks good and the animations work quite well on the terminal :-D

@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 10, 2020
@maribu
Copy link
Copy Markdown
Member

maribu commented Feb 10, 2020

I think I finally worked up the review backlog I was carrying around :-)

To quickly iterate on animations it is handy to being able to simulate
the output on native.

This adds a VT100 terminal backend to the ws281x driver that outputs
the colors straight to the terminal.
@benpicco
Copy link
Copy Markdown
Contributor Author

Thank you for all the reviews! 😄

benpicco and others added 2 commits February 10, 2020 14:45
Also add an additional newline before each test title to improve
the rendering on native console output.
This brings the backend-dependant init() function in line with
`WS281X_HAVE_PREPARE_TRANSMISSION` and `WS281X_HAVE_END_TRANSMISSION`.
@benpicco benpicco merged commit 4f8114a into RIOT-OS:master Feb 10, 2020
@benpicco benpicco deleted the ws281x_vt100 branch February 10, 2020 17:23
@leandrolanzieri leandrolanzieri added this to the Release 2020.04 milestone Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants