5 ms·
Using RP2040 PIO to drive a poorly-designed displa
- stefan_ 4y agoI like people that try to get the most out of the integrated peripherals in creative ways. It's a dying craft in a world where a 300 MHz "micro" is just a dollar away.
- ta988 4y agoWhat kind of 300MHz MCU can you find for a dollar?
- jrexilius 4y agowow. this is amazing work, and answers a question I've had for a while. Thanks for putting this out there!
- dmitrygr 4y ago> and answers a question I've had for a while I am curious, which?
- geerlingguy 4y agoPossibly "is the Waveshare display really that bad?" — as someone who's implemented a few projects with it but suffered from its terrible existing driver support... I know it's nice to see a more in-depth explanation of what makes it bad (and creatively working around that) in this post.
- jrexilius 4y agoIf it was possible to drive a touch interface and SPI display of that size from an MCU of that size/speed and still be responsive. I have only driven them from Pi Zeros, PocketBeagles and other much larger/faster systems, and still noticed some drag. Up to now, I've stuck to smaller displays without a touch layer for projects where I'm using the RP2040. [caveat: I am _not_ an embedded systems SWE so still figuring out where limitations are hardware vs. my knowledge]
- dmitrygr 4y agoNow you can use that display too :) As the driver uses no CPU, CPU speed doesn’t matter
- djmips 4y agoImpressive work. I hope the original designers of the RP2040 PIO system are well pleased.
- ta988 4y agoI hope they are. I also hope their next generation will have more PIOs and ideally a bit more instructions.
- dmitrygr 4y agoI only have one wish for PIOv2 in future chips: wire it up to the AHBlite bus as a target, behind a small cache, so i can make my own QSPI iface (or 8xSPI, or 16xSPI, or SDRAM, etc)
- ta988 4y agoThe RP2040 is a really capable little microcontroller. http://wiki.picosystem.com/ http://wiki.picosystem.com/ https://kilograham.github.io/rp2040-doom/ https://kilograham.github.io/rp2040-doom/
- gmiller123456 4y agoFYI, cheap = $15.99 US + shipping.
- dmitrygr 4y agoThe cheapest 160x160+ screen that can be bought off-the-shelf and has touch integrated. At least the cheapest I found. Also available on aliexpress for $12 and free shipping :) If you find a cheaper one, please let me know. I'll thank you.
- picture 4y agoIs there anything wrong with the ubiquitous ILI9488 3.5 in displays? I see some on aliexpress with resistive touch screen for below 6 dollars not including shipping. These are not integrated on a board but has 40 pin standard FPC connector, with some passives on the ribbon. (I personally prefer this over waveshare's pcbs) EDIT: 320 by 480 btw
- dmitrygr 4y agoNothing wrong with them, but that is too many pixels for my purpose. PalmOS 5.2 needs a minimum of 64KB of storage RAM, 128K of dynamic RAM, 32K for the kernel, AND a framebuffer to run, and RP2040 has too little RAM to handle a 320x480 display.
- pinchies 4y agoFascinating to see how the peripheral hardware resources can be used by someone smart who both knows what they are doing and thinks creatively. Very nice work. I do hope someone takes you up on making this neat PIO LCD api into a library for others to use!
- deleted 4y ago[deleted]
- codetiger 4y agoI've done something very similar and created a GL class to draw stuff. This was built specific to support Waveshare 240×320 display for my gaming console built on RP2040. https://github.com/codetiger/GameTiger-Console https://github.com/codetiger/GameTiger-Console
- TJSomething 4y agoI remember reading some PIO documentation that explained that PIOs were for handling all sorts of interfaces, from basic flash to cursed displays found on AliExpress.
- sgtnoodle 4y agoIt's neat that the author was able to completely offload the work to the PIO. I'm not sure I really understand what's so poor about this display's design, though? It sounds like it's just a framebuffer on a SPI bus. Even if you were stuck with a more limited DMA peripheral on a different MCU, you could poll the touch screen and interrupt on every scan line and do 30fps with fewer than 10khz interrupts, and have plenty of cpu cycles left over.
- dmitrygr 4y agoThe fact that touch and display are on the same SPI bus making it impossible to just set up a repeating DMA to the display. On a non-RP2040 it wouldn’t be possible to drive it easily. Most DMA units wouldn’t allow you to feed a scan line at a time and then poll touch. They aren’t that flexible. You’d be stuck with a lot of IRQs
- sgtnoodle 4y agoThe last time I worked with DMA was on an Atmel cortex-M7. Definitely a higher end MCU, though. It supported arbitrarily complex DMA chaining via linked lists in RAM. That being said, doing ~10Khz or so IRQs just to kick off a DMA transfer wouldn't have been much CPU in the grand scheme of things. For the touch input, is it necessary to truly sample at a high rate continuously, or is it more a need to oversample and take an average? If it's a need for oversampling, you could sample the touch screen between frames rather than interleaved between scanlines. Likewise, you could read from the SD card between frames as well. Writing to an SD card would be pretty terrible, given that cards often block for hundreds of milliseconds. Once again, awesome work with the PIO. I imagine you're running the display at its theoretical update limit unless you try overclocking?
- dmitrygr 4y agoBetween frames would be too rare for touch. You really do not want touch at just 45Hz. More samples are for averaging for smoothing. The touch controller here is noisy and the board layout waveshare did … does not follow the data sheet recommendations for lowering noise. Sd between refreshes is a poor idea for the reason you mention, yes. And yes screen interface is run as fast as it can as per data sheet. Overclocking the MCU wont help as we are not cycle bound there. Overclocking the SPI bus will work but not far. Past 70MHz it gets glitchy.
- m463 4y ago"Using RP2040 PIO to drive a poorly-designed displa" need a new modeline, the "y" fell off the back porch.
- nyanpasu64 4y agovideo nerd voice But the beginning of the blanking interval is the front porch...
- dale_glass 4y agoPerhaps this might have started as a display for 3D printers using Arduinos? Given that the Mega has a pitiful 8K RAM, it's not really suitable for driving displays in anything resembling a normal way. The way you get 3D printers with fancy graphics is that the display has another microcontroller attached, plus SD card software, and takes commands in the form of "Draw rectangle here", and "put this image there". Fortunately 3D printers seem to be transitioning towards hardware that's less insanely limited.
- londons_explore 4y ago> Fortunately 3D printers seem to be transitioning towards hardware that's less insanely limited. If you use some of these more powerful CPU'd printers, you find a problem... Typically the powerful CPU's run an OS (eg. FreeRTOS), and have multiple processes doing different things. However, the Marlin software which is common in the 3d printer world is designed to run bare metal. When you put it into an OS thread, it stutters and misses steps on the motors when moving fast. There are places in the code which are timing critical - eg. "this loop must complete in 168 clock cycles or fewer for correct operation". Modern CPU's might be far faster, but they aren't good at microsecond accurate timing. Rewriting marlin to not rely on being able to rely on such low latency stuff would be a lot of work.
- dale_glass 4y agoMarlin barely fits on the Arduino anymore, and that's why recent releases also target ARM and ESP32. In any case, my point is that the Atmel Arduino architecture is old and limited, and imposes a number of design constraints. There's hardware that's both better and cheaper out there now.
- indrora 4y agoThere is no such thing as the "Atmel Arduino" You're talking about AVR8, which is the ATMega328p and its children and siblings. There exists, though less popular, a complete rebuild of the AVR architecture in 32-bits called AVR32. The instruction set is different, the peripheral IO is different, but the design is similar. The AVR32 was powerful enough for quite some time to run a full fat Linux, though this was dropped for a handful of reasons.
- vrglvrglvrgl 4y ago[dead]
- Brian_K_White 4y agoI love this for it's example of what to use pio for as well as how to do it. Showpiece. Put it right into an ides built in examples/templates menu.