<span class=navbar-toggler-icon></span></button><div class="collapse navbar-collapse" id=navbarToggler><ul class="navbar-nav mr-auto mt-2 mt-lg-0"><li class=nav-item><a class=nav-link href=/about.html>About</a></li><li class=nav-item><a class=nav-link href=/blog.html>Blog</a></li><li class=nav-item><a class=nav-link href=/gallery.html>Gallery</a></li><li class=nav-item><a class=nav-link href=/download.html>Download</a></li><li class=nav-item><a class=nav-link href=/docs.html>Documentation</a></li><li class=nav-item><a class=nav-link href=/community.html>Community</a></li></ul></div></nav><div class="position-relative overflow-hidden p-3 p-md-5 m-md-3 text-center bg-dark bg-grid"><div class="p-lg-1 mx-auto my-1 text-white text-left"><h1 class="title font-weight-normal">Ready<br>RUN "BLOG"<br>> Porting the EndBASIC console to an LCD█</h1></div></div><article class=container><p class="text-muted text-right">Published on: April 26, 2024</p><p>Hello again Blog System/5 and sorry for the radio silence for the last couple of months. I had been writing too much in here and neglecting my side projects so I <em>needed</em> to get back to them. And now that I’ve made significant progress on cool new features for <a href=https://www.endbasic.dev/>EndBASIC</a>, it’s time to write about them a little!</p><p>One of the defining characteristics of EndBASIC is its hybrid console: what looks like a simple text terminal at first glance can actually render overlapping graphics and text <em>at the same time</em>. This is a feature that I believe is critical to simplify learning and it first appeared with <a href=/2021/11/endbasic-0.8.html>the 0.8 release</a> back in 2021.</p><figure><img src=/images/2024-04-26-endbasic-hybrid-console.png width=100%><figcaption>EndBASIC's hybrid console running in the web browser, rendering text and overlapping graphics at once, all controlled from the built-in command prompt.</figcaption></figure><p>A few months before that, I had added support for simple GPIO manipulation in <a href=/2021/02/endbasic-0.6.html>the 0.6 release</a> and, around that same time, I impulse-bought a tiny LCD for the Raspberry Pi with the hope of making the console work on it. But life happened and I lost momentum on the project… until recently.</p><p>In this post, I’ll guide you through the process of porting the EndBASIC hybrid console to the ST7735s 1.44" LCD shown below, which sports a resolution of 128x128 pixels, a D-pad, and 3 other buttons. I will cover the prerequisite work to make the port possible, dig into the GPIO and SPI interface of an LCD, outline the design for a fast rendering engine, and conclude with pointers for you to build your own “developer kit”. Let’s go!</p><figure><a href="https://www.amazon.com/gp/product/B077Z7DWW1?ie=UTF8&psc=1&linkCode=ll1&tag=&linkId=7a97236b22ca32377d308871eedde6fc&language=en_US&ref_=as_li_ss_tl"><img src=/images/2024-04-26-st7735s-box.jpg width=100%></a><figcaption>The <a href="https://www.amazon.com/gp/product/B077Z7DWW1?ie=UTF8&psc=1&linkCode=ll1&tag=&linkId=7a97236b22ca32377d308871eedde6fc&language=en_US&ref_=as_li_ss_tl">ST7735s 1.44" LCD</a>. Photo from back when I first unboxed this little device... on February 7th, 2021.</figcaption></figure><h1 id=previous-implementation>Previous implementation</h1><p>Even though I had plans to support graphics in the EndBASIC console from the very beginning, the first versions of the product did <em>not</em> support graphics. That fact didn’t prevent me from defining a <code>Console</code> abstraction anyway because I needed to support various operating systems and, more importantly, write <a href=https://jmmv.dev/2020/12/unit-testing-a-console-app.html>unit tests for the console</a>. Such abstraction was a straightforward trait representing text-only operations, like this:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-rust data-lang=rust><span class=line><span class=cl><span class=k>trait</span><span class=w> </span><span class=n>Console</span><span class=w> </span><span class=p>{</span><span class=w>
0 commit comments