Coder Social home page Coder Social logo

svd2zig's Introduction

SVD to Zig

This converts System View Description (SVD) files into Zig, providing a nice API against memory-mapped peripheral registers on embedded systems. It solves the same problem as svd2rust.

The generated Zig code has only been lightly tested on nRF52 hardware as part of my keyboard firmware. It's checked in under target/ so you can just download and run it if you want to get right to playing with nRF52 chips using Zig.

This project was a collaboration with Jamie Brandon, see his writeup on this project.

Usage example

The register API is defined by registers.zig, which is inlined at the top of the generated Zig files.

usingnamespace @import("register-generation/target/nrf52840.zig");

pub const led = .{ .port = p0, .pin = 11 };

fn main() void {

    //calling modify will preserve other fields of register
    led.port.pin_cnf[led.pin].modify(.{
        .dir = .output,
        .input = .disconnect,
    });
    
    //calling write will set unspecified fields to their reset value
    led.port.pin_cnf[led.pin].write(.{
        .dir = .input,
    });
    
}

Generating Zig definitions from SVD

The API and generation script assumes 32-bit word size and likely contains bugs and conceptual misunderstandings. Read the 300 lines of source and decide for yourself. It's written in Clojure because...hahaha I'm not going to try parsing XML in Zig =P

Run ./make.sh to download SVD files to vendor/ and generate formatted Zig definitions for every SVD found in that directory. You'll need clojure and zig on your path.

svd2zig's People

Contributors

lynaghk avatar

Watchers

James Cloos 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.