Git Product home page Git Product logo

rs-embedded-fish's Introduction

This is one of the first programs I have written in Rust, so it may be a little rough around the edges.

This is an embedded Rust program which runs on the Longan Nano board, and displays an animated fish tank on the Longan Nano's. The Longan Nano is a RISC-V development board which only costs $4.90, and comes with a tiny color LCD and a plastic case.

This program uses the embedded-graphics crate, so it should be fairly easy to port to other microcontrollers and displays, as long as the microcontroller is supported by Rust, and the display is supported by embedded-graphics.

The Longan Nano is supported by the longan-nano crate, which I previously tried out in a blog post.

Longan Nano running fish tank program

video

Instructions

Install Rust if you haven't already:

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ source $HOME/.cargo/env
$ which rustc
/home/ppelleti/.cargo/bin/rustc
$ rustc --version
rustc 1.46.0 (04488afe3 2020-08-24)

Add support for RISC-V to Rust:

$ rustup target add riscv32imac-unknown-none-elf

Install a RISC-V toolchain. On Ubuntu 20.04, I installed the gcc-riscv64-unknown-elf package, which actually supports both 32-bit and 64-bit RISC-V processors.

$ sudo apt-get install gcc-riscv64-unknown-elf

Install a version of dfu-util from May 2020 or later. At the time of this writing, that means installing from source:

$ cd ~/src
$ git clone git://git.code.sf.net/p/dfu-util/dfu-util
$ cd dfu-util
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install

Now we can build the fish program. Building with --release is necessary, because the debug version of the program is too big to fit in the Longan Nano's flash!

$ cd ~/src
$ git clone https://github.com/ppelleti/rs-embedded-fish
$ cd rs-embedded-fish
$ cargo build --release

If you installed a different RISC-V toolchain (such as a 32-bit only one), your objcopy will probably have a different name than mine.

$ riscv64-unknown-elf-objcopy -O binary target/riscv32imac-unknown-none-elf/release/rs-embedded-fish fish.bin

Finally, while holding down the "BOOT" button, plug the Longan Nano into a USB port on the computer. Then upload the program:

$ sudo dfu-util -a 0 -s 0x08000000:leave -D fish.bin

The fish tank should start running automatically, as soon as dfu-util is done.

License

The code I have written is made available under the Apache 2.0 license.

The fish images were created by Ferenc Hechler for his AndroFish Android game. According to its F-droid page, AndroFish is also licensed under the Apache 2.0 license.

I've copied a few lines of code from the examples in the longan-nano crate, which is licensed under the ISC License.

rs-embedded-fish's People

Contributors

ppelleti avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.