stevenvar / OMicroB

An OCaml generic virtual machine for microcontrollers
Other
138 stars 23 forks source link

Better AVR switcher #15

Closed Vertmo closed 5 years ago

Vertmo commented 5 years ago

(this PR replaces #11)

TODO List

Abstract

I improved my work on a way to compile for different Avr devices (see #6). Previously, omicrob needed to be reconfigured (and recompiled) when targeting different devices. Now devices can be choosen when executing omicrob to compile a program. The device omicrob compiles (or flashes) for can be set using the -device parameter. Available devices can be listed using the -list-devices parameter. The current available devices are the Arduboy, the Arduino Uno and the Arduino Mega (same as before). The default selected device is the Arduboy.

Interfaces

From a user point a view, the interface doesn't really change much : PINs and registers, as well as some the functions write_register, read_register, set_bit, clear_bit and delay are still exposed through the Avr module. The [...]_of_pin functions, as well as the pin_mode, digital_read and digital_write functions are exposed through sub-modules following the signature AvrPins. The correct sub-module (depending on the device selected) is automatically opened when compiling a program using omicrob. Therefore, backward compatibility with previously written program should theoretically be preserved. The LiquidCrystal interfaces has changed a bit. Instead of simply opening the LiquidCrystal module, users now have to create an instance of LCD using the LiquidCrystal.MakeLCD functor : the module passed to this functor must contains a pin_mode and a digital_write method (usually passing the ones automatically imported for the correct micro-controller will do the trick). See this exemple. I'm not totally convinced of this interface, so if anyone has an idea on how to make it more practical, that would be appreciated !

Future changes

It will be possible, in the future, to add other AVR devices to omicrob, by editing the files:

Tests

It should be noted that I have only yet tested these changes with an Arduino Uno (being the only device I have at hand for the time being). I'll test these changes (using simple examples, like the one from tutorial 2 : buttons) on other devices as soon as I can.

Vertmo commented 5 years ago

This is redundant with #20