News

19/02/2020

A Classic Snake Game in Rust

Arkadiusz Morawski

Thaumatec

The goal of this project was to experiment with Rust bare-metal programming by implementing a simple game. The chosen hardware platform was STM32F4DISCOVERY. It is similar to F3 DISCOVERY from the official embedded Rust tutorial however, it has some additional features like analog-digital converter required for the snake to be controlled with a joystick. The game is displayed on a 96×64 OLED screen using the SSD1331 controller and SPI interface. In the process of development and debugging two additional versions of the game were created: one with text-based UI for running the game in a terminal and the other one using a game engine called Quicksilver. Quicksilver is capable of targeting WebAssembly, which means the same game can be played both on the microcontroller and in a web browser. Implementation of the game. Embedded HAL  hides a lot of details and allows us to interact with the hardware on a relatively high level of abstraction.
Some remarkable issues are:

* Development without OS and allocator requires #![no_std] flag but Rust’s native test framework depends on standard library facilities. To keep unit tests in the same file as the source code (which is Rust’s convention), a conditional compilation was required.

* Lack of dynamic memory allocation makes it difficult to parameterize application code with the size of “things” – everything has to be set at compile time. It is a problem when unit testing or targeting different screen sizes. The easy solution for this would be to use a feature named const generics which, unfortunately, is not yet fully implemented in Rust. Luckily there is a workaround in the form of crate generic_array, but overall Rust still has to catch up with C++ in this subject.

* Important thing one has to remember when developing with Rust is that the difference in performance between debug and release versions is huge. In the case of this game and microcontroller, the debug version was unusable.

 

For more information follow the link below:

https://github.com/g-bartoszek/snake

read case studies

Smart healthcare

​Smart healthcare is one of the toughest but also fastest growing industries. A Silicon Valley start-up with a strong background in medical surgery and Thaumatec…
read more

Smart streetlight system

The City of Amsterdam has been very actively engaged in smart city development. Upgrading the street lighting infrastructure with new technology was high on the…
read more

Mobile LoRa gateway

Thaumatec built the solar-powered Lora Gateway because we believe, that this device can solve a lot of global problems and help many businesses.
read more

Wrocław the smart(est) city

Thaumatec has a strong partnership with top-class universities like Wrocław University of Technology and Science and the most respected business networks like DSP Valley from…
read more

Smart robot for elderly care

​AI is the most exciting field ever, especially since the creation of robots. Thaumatec was lucky (and qualified) to be assigned to work on a…
read more

Smart sleep tracker

The consequences of sleeping deprivation can affect many, so a solution was formed for this problem and Thaumatec helped in the making. Read our story…
read more

LoRa Communication Module for Drones

LoRa communication module for drones Lora is one of the most promising IoT technologies that deliver communication for areas where availability of power grid is…
read more

Biometric identity

Biometric identity products deliver effortless, fast, and highly accurate biometric enrollment and identification. Designed for high throughput identification and verification, in other words, these products…
read more

Smart security system

Hago Next, a cleaning company that provides services to public places like train stops, was searching for the ideal partner to provide them with IoT…
read more

Do you need a help with choosing a service?

Contact us, we'll help you.

Contact us
coretech thingworx life expander FMC intuitive
Copyrights © Thaumatec 2022