Giter VIP home page Giter VIP logo

bela-rs's Introduction

bela-rs

Safe Rust wrapper for the Bela microcontroller API.

Setup

For this, you will need a Bela microcontroller with compiled libbela.so libraries, the Rust programming language, and the relevant ABI files.

You can download the arm-linux-gnueabihf for all platforms at the linaro site, or likely through your package manager of choice.

Dependencies

It's possible to link this crate against either padenot's bela-sys crate or andrewcsmith/bela-sys. The difference between the two is mainly in that padenot uses a vendored version of the bela.rs and header files, while the andrewcsmith version generates its own headers using bindgen and a local copy of all the relevant header files. This is significantly more complicated to set up.

padenot/bela-sys is tested on OSX and Linux, while andrewcsmith/bela-sys is tested on Windows 10 Professional.

Design

bela-rs aims to be a safe wrapper around the core Bela functionality, but there are a few opinionated design choices to take advantage of specific capabilities of Rust. The first of these is runtime guarantees about the userData void* passed to every call of render, setup, or cleanup. The global function calls to the Bela are managed by a Bela struct.

Second, the lifecycle functions (render, setup, cleanup) are not globally defined functions, but rather are defined as closures that are passed to every call in the lifecycle. This allows the programmer to use features in closures such as capturing outside variables, and mutating state on each call.

Third, the auxiliary tasks are also closures, and are separated into callback functions and arguments to be passed to the first call.

Example

// Short extract of code from examples/hello.rs, where phasor is some arbitrary
// data that is passed to each render, setup, and cleanup call.
let user_data = AppData::new(phasor, &mut render, Some(&mut setup), Some(&mut cleanup));
let mut settings = InitSettings::default();
// The .run call blocks until interrupted, returning a Result
Bela::new(user_data).run(&mut settings) 

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.