File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -216,11 +216,14 @@ proc blink_led() =
216216
217217 ## Open the LED Driver
218218 echo "Opening /dev/userleds"
219- var fd = c_open("/dev/userleds", O_WRONLY)
219+ let fd = c_open("/dev/userleds", O_WRONLY)
220220 if fd < 0:
221221 echo "Failed to open /dev/userleds"
222222 return
223223
224+ ## On Return: Close the LED Driver
225+ defer: c_close(fd)
226+
224227 ## Turn on LED
225228 echo "Set LED 0 to 1"
226229 var ret = c_ioctl(fd, ULEDIOC_SETALL, 1)
@@ -239,21 +242,22 @@ proc blink_led() =
239242 echo "ioctl(ULEDIOC_SETALL) failed"
240243 return
241244
242- ## Close the LED Driver
243- c_close(fd)
245+ ## Wait again
246+ echo "Waiting..."
247+ c_usleep(1000_000)
244248
245249## Main Function in Nim
246250proc hello_nim() {.exportc, cdecl.} =
247251
252+ ## On Return: Force the Garbage Collection
253+ defer: GC_runOrc()
254+
248255 ## Print something
249256 echo "Hello Nim!"
250257
251258 ## Blink the LED 20 times
252259 for loop in 0..19:
253260 blink_led()
254-
255- ## Finish
256- GC_runOrc()
257261```
258262
259263Which calls our barebones NuttX LED Driver for Ox64 BL808...
You can’t perform that action at this time.
0 commit comments