diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73deb59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.ibc +*.o +/build-* diff --git a/Blink.idr b/Blink.idr index 0f04223..20b890f 100644 --- a/Blink.idr +++ b/Blink.idr @@ -1,16 +1,18 @@ module Main +%include C "idris_arduino.h" + digitalWrite : Int -> Int -> IO () -digitalWrite pin val = mkForeign (FFun "idrard_digitalWrite" [FInt, FInt] FUnit) pin val +digitalWrite pin val = foreign FFI_C "idrard_digitalWrite" (Int -> Int -> IO ()) pin val pinMode : Int -> Int -> IO () -pinMode pin mode = mkForeign (FFun "idrard_pinMode" [FInt, FInt] FUnit) pin mode +pinMode pin mode = foreign FFI_C "idrard_pinMode" (Int -> Int -> IO ()) pin mode delay : Int -> IO () -delay ms = mkForeign (FFun "idrard_delay" [FInt] FUnit) ms +delay ms = foreign FFI_C "idrard_delay" (Int -> IO ()) ms blink : Int -> Int -> IO () -blink pin ms = mkForeign (FFun "idrard_blink" [FInt, FInt] FUnit) pin ms +blink pin ms = foreign FFI_C "idrard_blink" (Int -> Int -> IO ()) pin ms main : IO () main = diff --git a/Idris.mk b/Idris.mk index 7d47f1e..30f0acc 100644 --- a/Idris.mk +++ b/Idris.mk @@ -1,9 +1,18 @@ -IDRIS_CFLAGS += -I$(IDRIS_RTS_PATH) -I$(IDRIS_RTS_PATH)/arduino -EXTRA_FLAGS = $(IDRIS_CFLAGS) -DFORCE_ALIGNMENT -DIDRIS_TARGET_OS=\"none\" -DIDRIS_TARGET_TRIPLE=\"arduino\" +IDRIS_INCLUDES += -I$(IDRIS_RTS_PATH) -I$(IDRIS_RTS_PATH)/arduino +CFLAGS += $(IDRIS_INCLUDES) + +IDRIS_RTS_CFLAGS = -DFORCE_ALIGNMENT -DIDRIS_TARGET_OS=\"none\" -DIDRIS_TARGET_TRIPLE=\"arduino\" NO_CORE_MAIN_CPP := "true" -RTS_OBJS = $(OBJDIR)/rts/arduino/idris_main.o $(OBJDIR)/rts/idris_gc.o $(OBJDIR)/rts/idris_rts.o $(OBJDIR)/rts/idris_bitstring.o $(OBJDIR)/rts/idris_gmp.o $(OBJDIR)/rts/idris_heap.o $(OBJDIR)/rts/mini-gmp.o +RTS_OBJS = \ + $(OBJDIR)/rts/arduino/idris_main.o \ + $(OBJDIR)/rts/idris_gc.o \ + $(OBJDIR)/rts/idris_rts.o \ + $(OBJDIR)/rts/idris_bitstring.o \ + $(OBJDIR)/rts/idris_gmp.o \ + $(OBJDIR)/rts/idris_heap.o \ + $(OBJDIR)/rts/mini-gmp.o OTHER_OBJS += $(RTS_OBJS) $(IDRIS_MAIN:.idr=.o) @@ -15,4 +24,4 @@ include $(ARDUINO_MAKEFILE_PATH) # Idris rts files $(OBJDIR)/rts/%.o: $(IDRIS_RTS_PATH)/%.c $(COMMON_DEPS) | $(OBJDIR) @$(MKDIR) $(dir $@) - $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $(IDRIS_C_FLAGS) $< -o $@ + $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $(IDRIS_RTS_CFLAGS) $< -o $@ diff --git a/Makefile.example b/Makefile.example new file mode 100644 index 0000000..f8a35da --- /dev/null +++ b/Makefile.example @@ -0,0 +1,12 @@ +ADRUINO_DIR=/usr/share/arduino +AVR_TOOLS_DIR=/usr +AVRDUDE_CONF=/etc/avrdude.conf +IDRIS_RTS_PATH=rts +ARDUINO_MAKEFILE_PATH=/usr/share/arduino/Arduino.mk + +IDRIS_MAIN=Blink.idr + +BOARD_TAG=mega +BOARD_SUB=atmega2560 + +include Idris.mk diff --git a/README.md b/README.md index 82ac962..84b11e7 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,9 @@ Next you will need to update the `Makefile` in this directory. You will need to set the following variables: * `ARDUINO_DIR` = *where you unpacked the Arduino software* - * `BOARD_TAG` = *your board* + * `AVR_TOOLS_DIR` = *dir containing `bin/avr-gcc` unless it is shipped with the Arduino software* + * `AVRDUDE_CONF` = *path to `avrdude.conf` unless avrdude is shipped with the Arduino software* + * `BOARD_TAG` and `BOARD_SUB` = *your board name (e.g., uno, mega) and subname (if applicable, e.g. atmega2560 for mega)* * `IDRIS_RTS_PATH` = *path to the source for the RTS. Could point to the git source or to the copy of the files installed by cabal* * `ARDUINO_MAKEFILE_PATH` = *path to the `Arduino.mk` from step 2*