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

Added support for tm1829 based led strips #1297

Closed
wants to merge 24 commits into from
Closed

Conversation

sebi2k1
Copy link
Contributor

@sebi2k1 sebi2k1 commented May 16, 2016

  • Squashed into single commit
  • Added module documentation
  • Rebased on dev

@devsaurus
Copy link
Member

Thanks for the contribution @sebi2k1.
I don't have any TM1829 hardware available but since rework of the WS2812 driver finished recently with #1263, I'd like to review this PR along the learnings we gathered there.

Locking interrupts vs stability

The driver locks interrupts - will it lock them for more than 50 µs? Doing so can impact the overall system stability as discussed in #902 (comment). Also see How does the non-OS SDK structure execution for details regarding the timing requirements.

In case it compromises stability then please investigate for other techniques than bit-banging to implement the low-level protocol. Eg WS2812 uses UART1 on GPIO2 to decouple the CPU & system latencies from bit stream generation (introduced with #951). It's now considered compliant with the SDK guidelines.

Lua API

As far as I can see, this driver adopts a similar API than WS2812's previous variant. WS2812 was enhanced by a buffer sub-module (see #902 and #1263) that could also be applicable for TM1829. Do you see a change to adapt this as well (maybe in a second iteration)?

@@ -58,6 +58,7 @@
#define LUA_USE_MODULES_WIFI
//#define LUA_USE_MODULES_WS2801
//#define LUA_USE_MODULES_WS2812
#define LUA_USE_MODULES_TM1829
Copy link
Member

Choose a reason for hiding this comment

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

New modules need to be disabled by default and ordered alphabetically.

@marcelstoer
Copy link
Member

As per https://github.com/nodemcu/nodemcu-firmware/blob/dev/CONTRIBUTING.md#writing-documentation the documentation page needs to be registered in mkdocs.yml.

@marcelstoer
Copy link
Member

Maybe worth noting that we had a (discarded) TM1829 contribution before: #984.

@sebi2k1
Copy link
Contributor Author

sebi2k1 commented May 16, 2016

@marcelstoer My initial approach was similar to #984 (adapt timings, invert levels), but it failed due to some timing issue. I've optimised the algorithm to reduce memory access during timing critical section in favor of increased register use. I could verify the timing for 80/160MHz using an DSO and on my led strip.

Regarding bit bang vs UART. One bitstream takes roughly (2.4us * 24bits + 6us = 63,6us). So depending how much leds are in the daisy chain it might take much longer than 50us (e.g. 3ms on my 50 led controller strip). It might work to disable/enable ISR only when writing a single byte, longer gaps between each byte are fine if < 500us.

@devsaurus I already noticed the buffer implementation and I'm interested in adding support. For my current project no sophisticated animation are required, so adding buffer support is not a priority ATM. But I'll definitely look into this. Same is true for UART support.

@sebi2k1
Copy link
Contributor Author

sebi2k1 commented May 16, 2016

I integrated the requested changes and optimised the timing (one byte takes now 36us). To avoid long periods of disabled IRQs, IRQs are no longer locked for the complete frame but only for a single byte. Tested and verified here.

I cannot proceed with the UART support, since on my platform none of the TXDs is usable (GPIO2/GPIO15).

@@ -74,5 +74,6 @@ pages:
- 'wifi': 'en/modules/wifi.md'
- 'ws2801': 'en/modules/ws2801.md'
- 'ws2812': 'en/modules/ws2812.md'
- 'tm1829': 'en/modules/tm1829.md'
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for nagging but you should really study the contributing guidelines I pointed you to. The module list here is alphabetically sorted as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got ya. Was reading CONTRIBUTING.md from master branch initially and missed the whole docs/module stuff in dev branch.

@@ -58,6 +58,7 @@
#define LUA_USE_MODULES_WIFI
//#define LUA_USE_MODULES_WS2801
//#define LUA_USE_MODULES_WS2812
//#define LUA_USE_MODULES_TM1829
Copy link
Member

Choose a reason for hiding this comment

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

Should be on line 53...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as well.

@sebi2k1
Copy link
Contributor Author

sebi2k1 commented May 22, 2016

Are there any additional changes I have to made?

@Alkorin
Copy link
Contributor

Alkorin commented May 22, 2016

I'm not a big fan to loose memory and time to invert RGB <=> BRG values. It could be handled in LUA's side. Or directly handled by the developper as I did in the WS2812 driver. Anyway the memcpy is useless you could read in the input buffer and write in your new buffer.

Or as you expose only the "RGB" call, you could invert the values during streaming.

@sebi2k1
Copy link
Contributor Author

sebi2k1 commented May 22, 2016

Changing the order in C is likely more efficient than doing it in an interpreted language like LUA, but you are right the memcpy is useless it is just a leftover of the ws2801 driver I used to base my tm1829 support on. I will change that.

Are there any other changes you want me to do in order merge the pull request or do you not consider merging this pull request at all (e.g. cause of bitbanging)?

@marcelstoer
Copy link
Member

Are there any other changes you want me to do in order merge the pull request or do you not consider merging this pull request at all

I can't test this and I don't understand enough of the technical foundation (C, hardware). Once @Alkorin and @devsaurus are happy with the implementation (as they mainly drove #1263) and see merit in having this module I'd take that as a 👍 for merging. However, that should be done only after the upcoming dev-to-master snap.

@devsaurus
Copy link
Member

PR looks ok and the input from @Alkorin should be considered. Although I can't check on real hardware, it's also a 👍 from me for a merge after updating master.

@Alkorin
Copy link
Contributor

Alkorin commented May 22, 2016

I've checked the datasheets, it seems good.
From my point of vue, RGB is just a convention. I would prefer that the developper writes
tm1829.write(5, string.char(B,R,G,B,R,G)) and avoid malloc / copy in C code

Just said in your API that write() send bytes as-is and it's the developper responsability to put bytes in the correct order. Your repsonsability is just to avoid 0xFF on the first byte to use PWM mode.


#### Example
```lua
tm1829.write(5, string.char(255,0,0,255,0,0) -- turn the two first RGB leds to red using GPIO 5
Copy link
Contributor

@Alkorin Alkorin May 22, 2016

Choose a reason for hiding this comment

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

Missing ) to close the write()

@sebi2k1
Copy link
Contributor Author

sebi2k1 commented May 24, 2016

Ok, will do the requested changes.

sebi2k1 and others added 4 commits May 31, 2016 20:09
- Stop fighting against the SDK in terms of owning/writing the init_data block.
  NodeMCU included a default init_data block because originally the SDK did
  not, but by now it's not needed.

- Expose a way to reconfigure the ADC mode from Lua land. With most people
  using the cloud builder and not able to change the #define for byte 107
  this has been a pain point.

- Less confusion about which init_data has been used. Lua code can now simply
  state what mode it wants the ADC to be in, and not worry about the rest of
  the init_data complexities such as the init_data changing location due to
  flashing with wrong flash_size setting, or doing/not doing a chip-erase
  before loading new NodeMCU firmware.
@sebi2k1
Copy link
Contributor Author

sebi2k1 commented May 31, 2016

Let me reopen a clean PR.

@sebi2k1 sebi2k1 closed this May 31, 2016
@sebi2k1 sebi2k1 deleted the dev branch May 31, 2016 18:36
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.

7 participants