diff --git a/.gitignore b/.gitignore index 73deb59..00945b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.ibc *.o /build-* +/[A-Z]*.c diff --git a/Blink.idr b/Blink.idr index 20b890f..f561bb7 100644 --- a/Blink.idr +++ b/Blink.idr @@ -1,20 +1,27 @@ module Main -%include C "idris_arduino.h" +%include C "Arduino.h" digitalWrite : Int -> Int -> IO () -digitalWrite pin val = foreign FFI_C "idrard_digitalWrite" (Int -> Int -> IO ()) pin val +digitalWrite pin val = foreign FFI_C "digitalWrite" (Int -> Int -> IO ()) pin val pinMode : Int -> Int -> IO () -pinMode pin mode = foreign FFI_C "idrard_pinMode" (Int -> Int -> IO ()) pin mode +pinMode pin mode = foreign FFI_C "pinMode" (Int -> Int -> IO ()) pin mode delay : Int -> IO () -delay ms = foreign FFI_C "idrard_delay" (Int -> IO ()) ms +delay ms = foreign FFI_C "delay" (Int -> IO ()) ms + +forever : Monad f => f a -> f b +forever x = do x + forever x blink : Int -> Int -> IO () -blink pin ms = foreign FFI_C "idrard_blink" (Int -> Int -> IO ()) pin ms +blink pin t = do digitalWrite pin 1 + delay t + digitalWrite pin 0 + delay t main : IO () main = do pinMode 13 1 - blink 13 30 + forever $ blink 13 300 diff --git a/Idris.mk b/Idris.mk index 30f0acc..26ff903 100644 --- a/Idris.mk +++ b/Idris.mk @@ -14,7 +14,8 @@ RTS_OBJS = \ $(OBJDIR)/rts/idris_heap.o \ $(OBJDIR)/rts/mini-gmp.o -OTHER_OBJS += $(RTS_OBJS) $(IDRIS_MAIN:.idr=.o) +LOCAL_C_SRCS += $(IDRIS_MAIN:.idr=.c) +OTHER_OBJS += $(RTS_OBJS) include $(ARDUINO_MAKEFILE_PATH) diff --git a/idris_arduino.c b/idris_arduino.c deleted file mode 100644 index 331ecf7..0000000 --- a/idris_arduino.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "idris_arduino.h" -void idrard_digitalWrite(int pin, int val) -{ - digitalWrite(pin, val); -} - -void idrard_pinMode(int pin, int mode) -{ - pinMode(pin, mode); -} - -void idrard_delay(int ms) { - delay(ms); -} - -void idrard_blink(int pin, int ms) { -// pinMode(pin, OUTPUT); - while(1) { - digitalWrite(pin, 1); - delay(ms); - digitalWrite(pin, 0); - delay(ms); - } -} - diff --git a/idris_arduino.h b/idris_arduino.h deleted file mode 100644 index 39e676f..0000000 --- a/idris_arduino.h +++ /dev/null @@ -1,4 +0,0 @@ -void idrard_digitalWrite(int pin, int val); -void idrard_pinMode(int pin, int mode); -void idrard_delay(int ms); -void idrard_blink(int pin, int ms);