ryansuchocki / microscheme

A Scheme subset for Atmel microcontrollers.
http://ryansuchocki.github.io/microscheme/
MIT License
300 stars 20 forks source link

Add plain ATmega32 model. #21

Open rekado opened 8 years ago

rekado commented 8 years ago

This adds a new ATmega32 model for non Arduino boards. The pin mappings expose all pins from ports A, B, C, and D. PORTC7 is used as the diagnosis LED pin (on the RN-control board all pins of PORTC are connected to LEDs).

This works for my RN-control board with an ATmega32.

rekado commented 8 years ago

ping :)

ryansuchocki commented 8 years ago

I'm a bit concerned about creating an arbitrary mapping between microscheme pin numbers, and real port/pins. For the arduino models this is fine, because the arbitrary mapping is printed on the boards, but for raw chips we need something more systematic. What do you think of doing it like this:

(define 2^ (vector 1 2 4 8 16 32 64 128))

(define (raw-pin port pin)
    (digital-state port (vector-ref 2^ pin)))

(define (set-raw-pin port pin)
    ...)

(define (set-raw-ddr port pin)
    ...)

(@if-model "ATmega32"
    (define PORTA #x39)
    (define PORTB #x36)
    (define PORTC #x33)
    (define PORTD #x30))
thatismatt commented 7 years ago

I had a similar issue where I wanted to use the LEDs on the Pro Micro's board. So @ryansuchocki , your suggestion would be great for me.

My current workaround is to use the LEO for the model, and call set-digital-state directly from my code. Which is fine, but not very "user friendly"!

Finally, thanks for the work on this Ryan. Are you planning to do any more work on it? As I'm considering using it on a project.