micropython/micropython — pull request #512 by dhylands (2014-04-20 07:17:21+00:00)
Title: RFC: Add reg module

So this is my initial take on adding register access.

I just realize that I forgot to hook this up, and it doesn't actually work on stmhal yet (I tested all of the logic that is here on the unix port).

So basically this would introduce

```python
pyb.reg.TIM1.BDTR = val
val = pyb.reg.TIM1.BDTR
val = pyb.reg.TIM1.BDTR_BKE
```

This also added the notion of bit fields for the registers.

What I don't like about this implementation is that there's no way to speed it up.

I can do:
```python
reg_base = pyb.reg.TIM1
reg_base.BDTR = val
```

But it still needs to perform a lookup on the register name and bitfield, if provided.

I was thinking that it might be better to generate field objects for each field, and then have

pyb.reg.TIM1.BDTR.BKE return a reg_field_t.
You could then do:
```python
bke = pyb.reg.TIM1.BDTR.BKE
bke.set(1)
```

I couldn't figure out any way to make bke = 1 work (but I might be missing something)

The cool thing is that this doesn't take up any RAM.

So I figured I get some feedback before taking this any further.