- Notifications
You must be signed in to change notification settings - Fork1
Nim wrapper using c2nim for Arduino and MediaTek LinkIt One development
License
cfvescovo/Arduino-Nim
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a fork of the great repo "Ardunimo". I am working on this repository to make Arduino-Nim the standard library for Arduino and LinkIt in the new Nim programming language. The main goal is to improve the already excellent Ardunimo code to make it more stable and wider compatible with Arduino boards.
This is a first stab at Arduino programming on theLinkIt ONE development board from MediaTek using the brilliantprogramming language Nim.
This project basically consists of two Makefiles, one in thewrapper
subdirectory that can semi automatically generate the Nim wrapper of the Arduino and MediaTek libraries for the LinkIt ONE using the very usefulc2nim
tool. The other Makefile in the root directory is for compiling a Nim program using the wrapper and the SDK from MediaTek to produce a .vxp binary file that can be dropped into the USB disk on the board.
First we need to installNim (compiler and libs),nimble (package manager) andc2nim (wrapper generator tool). I recommend following installation instructions on the github repos but if you want that information condensed, below is the recipe. And for theultra lazy there is also a VagrantFile with this shell provisioning script, so you can just dovagrant up && vagrant ssh
to have a working environment.
# If in a fresh Ubuntusudo apt-get update && sudo apt-get upgradesudo apt-get install git unzip build-essential# Install Nim and bootstrap itgit clone https://github.com/nim-lang/Nim.gitcd Nimgit clone --depth 1 https://github.com/nim-lang/csourcescd csources && sh build.shcd ..bin/nim c koch./koch boot -d:release# Execute and also put the following line last in ~/.profileexport PATH="$HOME/Nim/bin:$HOME/.nimble/bin:$PATH"# Then install nimblenim e install_nimble.nims# Let it refresh the package listnimble refresh# Use nimble to install c2nimnimble install c2nim
- Clone this repo to your machine (or in the vagrant box),only tested on 64 bit Ubuntu 14.04. The Makefile presumes Nim was cloned to
$HOME/Nim
. - Download and install the needed ARM GCC and SDK by running:
cd ardunimo && make sdk
For the moment Ardunimo needs a patched Nim, copy the alloc.nim file to replace the one in your Nim installation:
cp wrapper/fixed/alloc.nim <whereverNimLives>/lib/system/alloc.nim
This enables GC to work using malloc.
In the repository there is a single trivial application -blink.nim
, you probably recognize it. To build it and run on your LinkIt One:
- Run
make
. If all is well it producesapp.vxp
in a few seconds about 85kb big. - Connect your LinkIt ONEin USB drive mode - the small switch closest to the USB cord should be towards the USB cable.
- Press the reset button on the side of the board (where the green LED is lit) and Ubuntu should automount it.
- Copy
app.vxp
to the MRE directory on the device. Also make sureautostart.txt
maps toapp.vxp
. - Flip the USB mode switch and press the reset button, no need to unplug the USB cable. This will start the application.
- After a few seconds the green LED on the board should start blinking.
Just writeother.nim
and make using:
make PROJECT=other.nim
Currentlyblink
,blink2
andnimicro
works.
I begun by following these two tutorials:
- http://www.instructables.com/id/Programming-LinkIt-One-in-Linux-no-WiNE/
- http://www.instructables.com/id/Using-LinkIt-One-with-Arduino-in-Linux/
Then various googling and staring at the Arduino IDE compilation log led me to produce this LinkIt ONE specific Makefile.
After messing around with c2nim for a while I put that into its own Makefile. That Makefile produces a partial Nim wrapper of the Arduino + MediaTek libraries.
- The wrapper is not complete (I just did what I needed) and in many places probably downright silly, as Andreas mentioned to me. :)
- Currently the GC can not be turned on (see nim.cfg), we don't know yet what is preventing it.
- We compile via Nim's C++ backend since Arduino libraries are C++ based.
- The
ardunimo.nim
is a hack I ended up doing so that setup/loop gets resolved properly. PRs appreciated. - The wrapper/src directory contains the SDK sourcesmodified for c2nim, these are not used when compiling.
- Some modifications I didn't manage to do in the src, then I manually edited the produced nim file and put it in wrapper/fixed.
About
Nim wrapper using c2nim for Arduino and MediaTek LinkIt One development
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- C62.4%
- C++35.3%
- Nim1.2%
- Objective-C0.7%
- Logos0.2%
- Assembly0.1%
- Other0.1%