avr-rust / ruduino

Reusable components for the Arduino Uno.
Apache License 2.0
695 stars 49 forks source link

WIP: Support for autogenerated mcu cores #4

Closed dylanmckay closed 5 years ago

dylanmckay commented 6 years ago

It should be possible to do something like this

extern crate arduino;
use arduino::{Pin, HardwareSpi};
use arduino::cores::atmega328p;

trait Netlist {
    type PushButton: Pin;
    type Led: Pin;
    type Spi: HardwareSpi;
}

struct ATmega328p;

impl Netlist for ATmega328p {
    type PushButton = atmega328p::PORTB3;
    type Led = atmega328p::PORTB4;
    type Spi = atmega328p::SPI;
}

fn start<N: Netlist>() {
    N::PushButton::set_input();
    N::Led::set_output();
    N::Spi::setup_master();

   loop {
        // delay
        M::Led::set_high();
        // delay
        M::Led::set_low();
    }
}

This would allow users to easily mix-and-match supported microcontrollers, provided the microcontroller has enough GPIOs, etc.

pusherofbrooms commented 6 years ago

There's some great stuff in this PR. Is there any help needed to get it across the finish line? I'd like to use some of the features in https://github.com/pusherofbrooms/rust-arduino-examples without using the extra special branch. I like that this PR eliminates the std boiler plate.

dylanmckay commented 6 years ago

Is there any help needed to get it across the finish line?

At the moment, it adds autogenerated core functionality side-by-side with the current arduino master. It's a bit strange having two different implementations of the library, and so I think that if we can get feature parity with current master with the new implementation, that should be good.

IIRC, I did most of the work to get it feature complete - I think the SPI stuff is still to be done?

dylanmckay commented 6 years ago

Alright, this is now feature complete with the current master branch as far as I can tell.

Still need to do some cleanups, and the whole serial module is still using the old atmega328-specific constant tables (rather than the autogenerated core stuff). The serial module can stay that way for now though

dylanmckay commented 6 years ago

This is ready for some more eyes again @shepmaster @pusherofbrooms @Restioson

dylanmckay commented 5 years ago

I'm going to merge this now to stop faffing about. It's much easier for people to build utop what is here when it is in master, rather than my private fork. I've looked over it locally, cleaned it up a lot. It should work on https://docs.rs too, automatically assuming atmega328p.

dylanmckay commented 5 years ago

Docs on docs.rs.