hackndev/zinc — pull request #90 by bgamari (2014-07-05 16:20:30+00:00)
Title: [WIP] Improved ioreg macro

This is the beginning of a syntax extension to generate register definitions with bitfields.

```rust
#![feature(phase)]
#[phase(plugin)] extern crate macro_ioreg;

// Example register definitions:
ioregs!(Channel,
SC: struct {
pad(16), // 16 bits of padding
CHF: !bool(1), // ! denotes read-only
CHIE: bool(1), // parentheticals gives the width of the field
MSB: bool, // but (1) is the default
MSA: bool,
ELSB: bool,
ELSA: bool,
pad(1),
DMA: bool,
},
CV: u16,
)

ioregs!(FTM,
SC: struct {
pad(24),
TOF: bool,
TOIE: bool,
CPWMS: bool,
CLKS: enum {NO_CLOCK=0x0, SYSTEM=0x1, FIXED_FREQ=0x2, EXTERNAL=0x3,}(2),
PRESCALE: uint(5),
},
pad(16),
CNT: u16,
pad(16),
MOD: u16,
CH: Channel[8],
pad(16),
CNTIN: u16,
pad(24),
STATUS: struct {
CH: bool[8], // packed array
},
)
```