Skip to content

Commit

Permalink
Merge pull request #2 from buzden/no-intermediate-c
Browse files Browse the repository at this point in the history
Using Arduino's C-functions with no intermediate C lib
  • Loading branch information
stepcut authored May 13, 2020
2 parents a090364 + 68d2c3e commit 07f8839
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.ibc
*.o
/build-*
/[A-Z]*.c
19 changes: 13 additions & 6 deletions Blink.idr
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion Idris.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 0 additions & 26 deletions idris_arduino.c

This file was deleted.

4 changes: 0 additions & 4 deletions idris_arduino.h

This file was deleted.

0 comments on commit 07f8839

Please sign in to comment.