This is a port of the mruby/c tutorial Chapter 03 to the mbed environment.

Dependencies:   mbed

For details, refer to the following.

http://www.s-itoc.jp/activity/research/mrubyc/mrubyc_tutorial/436

Note:There is a change in rtt0.h from the original source in the mruby/c. It was necessary for inclusion in C ++ source.

Revision:
0:33feccbba3ff
diff -r 000000000000 -r 33feccbba3ff main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 15 01:03:35 2017 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+
+#include "mrubyc/hal/hal.h"
+#include "mrubyc/mrubyc.h"
+
+DigitalIn mybutton(USER_BUTTON);
+DigitalOut myled(LED1);
+RawSerial mysci(USBTX, USBRX);
+
+extern const uint8_t sample1[];
+extern const uint8_t sample2[];
+
+int hal_write(int fd, const void *buf, size_t nbytes)
+{
+    return mysci.write((const uint8_t *)buf, (int)nbytes, NULL, SERIAL_EVENT_TX_COMPLETE);
+}
+
+int hal_flush(int fd)
+{
+    char char1 = 0;
+    while (mysci.readable()) 
+    { 
+        char1 = mysci.getc();
+    }
+    return 0;
+}
+
+void hal_delay(mrb_vm *vm, mrb_value *v)
+{
+    wait_ms((int)GET_INT_ARG(0));
+}
+
+void hal_led(mrb_vm *vm, mrb_value *v)
+{
+    myled = (int)GET_INT_ARG(0);
+}
+
+void hal_button(mrb_vm *vm, mrb_value *v)
+{
+    int sw = mybutton;
+    SET_INT_RETURN(sw);
+}
+
+int main() {
+    mysci.baud(115200);                     // 115Kbps
+    mysci.format(8, Serial::None, 1);       // 8bt, none parity, stop bit 1
+    mrbc_init();
+    mrbc_define_method(0, mrbc_class_object, "led1_write", hal_led);
+    mrbc_define_method(0, mrbc_class_object, "delay", hal_delay);
+    mrbc_define_method(0, mrbc_class_object, "sw1_read", hal_button);
+    mrbc_create_task( sample1, 0 );
+    mrbc_create_task( sample2, 0 );
+    
+    mrbc_run();
+    
+}
+ 
\ No newline at end of file