├── .gitignore ├── HISTORY ├── Makefile ├── Makefile.conf ├── README.md ├── docs ├── Makefile ├── index.html ├── index.md ├── manual │ ├── Makefile │ └── v0.20 │ │ ├── README.md │ │ ├── ceu-arduino-v0.20.md │ │ ├── ceu-arduino-v0.20.pdf │ │ ├── docs │ │ ├── devices │ │ │ ├── index.md │ │ │ ├── interrupts │ │ │ │ ├── analog.md │ │ │ │ ├── index.md │ │ │ │ └── spi.md │ │ │ └── polling │ │ │ │ └── index.md │ │ ├── digital_pins │ │ │ ├── index.md │ │ │ ├── inputs.md │ │ │ └── outputs.md │ │ ├── index.md │ │ ├── license.md │ │ ├── modes │ │ │ ├── index.md │ │ │ ├── interrupts.md │ │ │ └── polling.md │ │ └── serial_communication │ │ │ └── index.md │ │ └── mkdocs.yml └── out │ └── manual │ └── v0.20 │ ├── __init__.py │ ├── __init__.pyc │ ├── base.html │ ├── breadcrumbs.html │ ├── css │ ├── highlight.css │ ├── theme.css │ └── theme_extra.css │ ├── digital_pins │ └── index.html │ ├── fonts │ ├── fontawesome-webfont.eot │ ├── fontawesome-webfont.svg │ ├── fontawesome-webfont.ttf │ └── fontawesome-webfont.woff │ ├── footer.html │ ├── img │ └── favicon.ico │ ├── index.html │ ├── js │ ├── highlight.pack.js │ ├── jquery-2.1.1.min.js │ ├── modernizr-2.8.3.min.js │ └── theme.js │ ├── license │ └── index.html │ ├── mkdocs │ ├── js │ │ ├── lunr-0.5.7.min.js │ │ ├── mustache.min.js │ │ ├── require.js │ │ ├── search-results-template.mustache │ │ ├── search.js │ │ └── text.js │ └── search_index.json │ ├── modes │ └── index.html │ ├── search.html │ ├── searchbox.html │ ├── serial_communication │ └── index.html │ ├── site │ ├── __init__.py │ ├── __init__.pyc │ ├── base.html │ ├── breadcrumbs.html │ ├── css │ │ ├── highlight.css │ │ ├── theme.css │ │ └── theme_extra.css │ ├── digital_pins │ │ └── index.html │ ├── fonts │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff │ ├── footer.html │ ├── img │ │ └── favicon.ico │ ├── index.html │ ├── js │ │ ├── highlight.pack.js │ │ ├── jquery-2.1.1.min.js │ │ ├── modernizr-2.8.3.min.js │ │ └── theme.js │ ├── license │ │ └── index.html │ ├── mkdocs │ │ ├── js │ │ │ ├── lunr-0.5.7.min.js │ │ │ ├── mustache.min.js │ │ │ ├── require.js │ │ │ ├── search-results-template.mustache │ │ │ ├── search.js │ │ │ └── text.js │ │ └── search_index.json │ ├── modes │ │ └── index.html │ ├── search.html │ ├── searchbox.html │ ├── serial_communication │ │ └── index.html │ ├── sitemap.xml │ ├── toc.html │ └── versions.html │ ├── sitemap.xml │ ├── toc.html │ └── versions.html ├── env ├── env.ino ├── threads.h └── types.h ├── examples ├── blink-01.ceu ├── blink-02.ceu ├── button-01.ceu ├── pwm-01.ceu └── usart-01.ceu ├── include └── arduino │ └── arduino.ceu ├── libraries └── Makefile └── make.sh /.gitignore: -------------------------------------------------------------------------------- 1 | libraries/*/ 2 | ignore/ 3 | gd2/ 4 | _ceu_* 5 | *_m4 6 | *.exe 7 | *.swp 8 | *.swo 9 | *.a 10 | *.o 11 | *.hex 12 | *.elf 13 | -------------------------------------------------------------------------------- /HISTORY: -------------------------------------------------------------------------------- 1 | * v0.8 (jun'14) 2 | (*) first release 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.conf 2 | 3 | # make ARD_BOARD=mega ARD_CPU=atmega2560 ARD_PORT=/dev/ttyACM1 CEU_SRC=... 4 | # make ARD_BOARD=pro ARD_CPU=8MHzatmega328 ARD_PORT=/dev/ttyUSB0 CEU_SRC=... 5 | # make ARD_BOARD=pro ARD_CPU=8MHzatmega328 ARD_PORT=/dev/ttyUSB0 CEU_SRC=... 6 | # make ARD_ARCH=samd ARD_BOARD=arduino_zero_native CEU_SRC=... 7 | 8 | ifndef ENV 9 | ENV = env 10 | endif 11 | 12 | ifdef CEU_SRC 13 | CEU_SRC_ = $(CEU_SRC) 14 | ifneq ("$(wildcard $(CEU_SRC)/main.ceu)","") 15 | CEU_SRC_ = $(CEU_SRC)/main.ceu 16 | endif 17 | else 18 | $(error missing `CEU_SRC` path to compile) 19 | endif 20 | 21 | PRESERVE = --preserve-temp-files 22 | 23 | ARD_ARCH_UPPER = $(shell echo $(ARD_ARCH) | tr a-z A-Z) 24 | ARD_CPU_UPPER = $(shell echo $(ARD_CPU) | tr a-z A-Z) 25 | ARD_BOARD_UPPER = $(shell echo $(ARD_BOARD) | tr a-z A-Z) 26 | 27 | LIBRARIES := $(sort $(dir $(wildcard libraries/*/))) 28 | CEU_INCS = $(addprefix -I./, $(addsuffix $(ARD_ARCH)/$(ARD_BOARD)/$(ARD_CPU), $(LIBRARIES))) \ 29 | $(addprefix -I./, $(addsuffix $(ARD_ARCH)/$(ARD_BOARD), $(LIBRARIES))) \ 30 | $(addprefix -I./, $(addsuffix $(ARD_ARCH), $(LIBRARIES))) \ 31 | $(addprefix -I./, $(LIBRARIES)) \ 32 | -I ./include \ 33 | -I $(CEU_DIR)/include \ 34 | 35 | CEU_PM = -DCEU_PM 36 | 37 | ifdef ARD_CPU 38 | ARD_CPU_ := :cpu=$(ARD_CPU) 39 | endif 40 | 41 | ifdef ARD_ARCH_ 42 | ARD_ARCH := $(ARD_ARCH_) 43 | endif 44 | 45 | ifdef ARD_BOARD_ 46 | ARD_BOARD := $(ARD_BOARD_) 47 | endif 48 | 49 | ifdef ARD_PORT_ 50 | ARD_PORT := $(ARD_PORT_) 51 | endif 52 | 53 | ARD_PREFS = --pref compiler.cpp.extra_flags="$(CEU_INCS) $(CEU_DEFS) $(CEU_PM)" 54 | 55 | all: ceu c 56 | 57 | # ifdef IDE 58 | # endif 59 | 60 | ifndef IDE 61 | c: 62 | $(ARD_EXE) --verbose $(PRESERVE) $(ARD_PREFS) \ 63 | --board arduino:$(ARD_ARCH):$(ARD_BOARD)$(ARD_CPU_) \ 64 | --port $(ARD_PORT) \ 65 | --upload $(ENV)/env.ino 66 | 67 | ceu: 68 | $(CEU_EXE) --pre --pre-args="-include ./include/arduino/arduino.ceu -include ./libraries/arch-$(ARD_ARCH)/$(ARD_ARCH).ceu $(CEU_INCS) -include pm.ceu $(CEU_DEFS) -DCEUMAKER_ARDUINO -DARDUINO_ARCH_$(ARD_ARCH_UPPER) -DARDUINO_MCU_$(ARD_MCU_UPPER) -DARDUINO_BOARD_$(ARD_BOARD_UPPER) $(CEU_PM)" \ 69 | --pre-input="$(CEU_SRC_)" \ 70 | --ceu --ceu-err-unused=pass --ceu-err-uninitialized=pass \ 71 | --ceu-line-directives=true \ 72 | --ceu-features-lua=false --ceu-features-thread=false \ 73 | --ceu-features-isr=static \ 74 | $(CEU_FEATURES) \ 75 | --env --env-types=$(ENV)/types.h \ 76 | --env-output=$(ENV)/_ceu_app.c.h 77 | pre: 78 | ceu --pre --pre-args="-include ./include/arduino/arduino.ceu -include ./libraries/arch-$(ARD_ARCH)/$(ARD_ARCH).ceu $(CEU_INCS) $(CEU_DEFS) -DCEUMAKER_ARDUINO -DARDUINO_ARCH_$(ARD_ARCH_UPPER) -DARDUINO_MCU_$(ARD_MCU_UPPER) -DARDUINO_BOARD_$(ARD_BOARD_UPPER)" --pre-input="$(CEU_SRC_)" 79 | endif 80 | 81 | .PHONY: all ceu c 82 | -------------------------------------------------------------------------------- /Makefile.conf: -------------------------------------------------------------------------------- 1 | CEU_EXE = ceu 2 | CEU_DIR = $(error set path to ceu directory) 3 | ARD_EXE = arduino 4 | ARD_ARCH = avr 5 | ARD_BOARD = uno 6 | ARD_PORT = /dev/ttyACM* 7 | #CEU_FEATURES = --ceu-features-async=true 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Céu-Arduino supports the development of Arduino applications in the programming 2 | language Céu: 3 | 4 | - Source Code: https://github.com/ceu-lang/ceu-arduino/ 5 | 6 | - Chat: https://gitter.im/fsantanna/ceu 7 | 8 | [Arduino](https://www.arduino.cc/) Arduino is an open-source project that 9 | created microcontroller-based kits for building digital devices and interactive 10 | objects that can sense and control physical devices. 11 | 12 | Céu is a reactive language that aims to offer a higher-level and safer 13 | alternative to C: 14 | 15 | - Home Page: http://www.ceu-lang.org/ 16 | - Source code: https://github.com/ceu-lang/ceu/ 17 | 18 | Céu-Arduino empowers the development of Arduino applications with the following 19 | extensions: 20 | 21 | - Awaiting events in direct/sequential style. 22 | 23 | - Parallel lines of execution with 24 | - safe abortion; 25 | - deterministic behavior (in contrast with threads). 26 | - Asynchronous loops for heavy computations. 27 | - Interrupt-driven operation mode (optional and experimental). 28 | - Seamless integration with standard Arduino (e.g., `analogRead`, `random`, 29 | etc). 30 | 31 | Install 32 | ======= 33 | 34 | ## Install Arduino 35 | 36 | Requires `arduino-1.5` or higher: 37 | 38 | https://www.arduino.cc/ 39 | 40 | ## Install Céu: 41 | 42 | https://github.com/ceu-lang/ceu/ 43 | 44 | ## Clone Céu-Arduino: 45 | 46 | ``` 47 | $ git clone https://github.com/ceu-lang/ceu-arduino 48 | $ cd ceu-arduino/ 49 | ``` 50 | 51 | ## Configure: 52 | 53 | Edit the `Makefile.conf` to set your configurations and preferences: 54 | 55 | ``` 56 | $ gedit Makefile.conf 57 | ``` 58 | 59 | ## Clone the Libraries: 60 | 61 | ``` 62 | $ cd libraries/ 63 | $ make clone 64 | ``` 65 | 66 | Each library provides documentation in separate: 67 | 68 | https://github.com/ceu-arduino/ 69 | 70 | Use 71 | === 72 | 73 | Run `make` with the file you want to compile & upload: 74 | 75 | ``` 76 | $ make CEU_SRC=examples/blink-01.ceu 77 | ``` 78 | 79 | This example blinks the on-board LED every second. 80 | 81 | Certify that your Arduino is connected to the USB. 82 | 83 | Examples 84 | ======== 85 | 86 | The `examples/` directory contains a number of examples. 87 | 88 | Blinking a LED 89 | -------------- 90 | 91 | 95 | 96 | The example `blink-01.ceu` assumes that a LED is connected to *pin 13*. 97 | 98 | The program is an infinite `loop` that intercalates between turning the LED 99 | *on* and *off* in intervals of 1 second: 100 | 101 | ``` 102 | #include "out.ceu" // uses GPIO (OUT_13) 103 | #include "wclock.ceu" // uses timers (await 1s) 104 | 105 | output high/low OUT_13; // declares OUT_13 an output pin 106 | 107 | loop do // runs an infinite loop that 108 | emit OUT_13(high); // - turns the LED on 109 | await 1s; // - awaits 1 second 110 | emit OUT_13(low); // - turns the LED off 111 | await 1s; // - awaits another 1 second 112 | end // - repeats 113 | ``` 114 | 115 | 128 | 129 | Switching a LED 130 | --------------- 131 | 132 | 135 | 136 | The example `button-01.ceu` requires a simple circuit with a switch button 137 | connected to *pin 2*. 138 | 139 | The program waits for changes on *pin 2* (the switch), copying its value to 140 | *pin 13* (the LED): 141 | 142 | ``` 143 | #include "out.ceu" 144 | #include "int0.ceu" // declares input `INT0` (UNO=D2, MEGA=D21) 145 | 146 | output high/low OUT_13; 147 | 148 | var high/low v = call INT0_Get(); // gets current value of the pin 149 | emit OUT_13(v); // sets the LED to this value 150 | 151 | loop do 152 | await INT0; // waits for a pin change event 153 | v = call INT0_Get(); // gets the new state of the pin 154 | emit OUT_13(v); // sets the LED to this value 155 | end 156 | 157 | ``` 158 | 159 | 167 | 168 | Blinking in Parallel 169 | -------------------- 170 | 171 | 174 | 175 | The example `blink-02.ceu` requires two additional LEDs connected to 176 | *pins 11 and 12*. 177 | 178 | The program blinks the LEDs with different frequencies, in parallel: 179 | 180 | ``` 181 | #include "out.ceu" 182 | #include "wclock.ceu" 183 | 184 | output high/low OUT_11; 185 | output high/low OUT_12; 186 | output high/low OUT_13; 187 | 188 | par do 189 | loop do 190 | emit OUT_11(high); 191 | await 1s; 192 | emit OUT_11(low); 193 | await 1s; 194 | end 195 | with 196 | loop do 197 | emit OUT_12(high); 198 | await 500ms; 199 | emit OUT_12(low); 200 | await 500ms; 201 | end 202 | with 203 | loop do 204 | emit OUT_13(high); 205 | await 250ms; 206 | emit OUT_13(low); 207 | await 250ms; 208 | end 209 | end 210 | ``` 211 | 212 | 216 | 217 | Fading a LED 218 | ------------ 219 | 220 | The example `pwm-01.ceu` assumes that an LED is connected to *pin 06*. 221 | 222 | The program fades the LED from `0` to `255` and from `255` to `0` in two 223 | consecutive loops: 224 | 225 | ``` 226 | #include "pwm.ceu" 227 | #include "wclock.ceu" 228 | 229 | loop do 230 | var int i; 231 | loop i in [0->255] do 232 | spawn Pwm(6, i); 233 | await 5ms; 234 | end 235 | loop i in [0<-255] do 236 | spawn Pwm(6, i); 237 | await 5ms; 238 | end 239 | end 240 | ``` 241 | 242 | Serial Echo 243 | ----------- 244 | 245 | The example `usart-01.ceu` reads and write strings from and to the serial in a 246 | continuous loop: 247 | 248 | ``` 249 | #include "usart.ceu" 250 | 251 | spawn USART_Init(9600); 252 | 253 | loop do 254 | var[20] byte str = []; 255 | await USART_Rx(&str, _); 256 | await USART_Tx(&str); 257 | end 258 | ``` 259 | 260 | 272 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | rm -Rf out/ 3 | mkdir out/ 4 | pandoc index.md > index.html 5 | cd manual/ && make 6 | mv manual/out/ out/manual/ 7 | 8 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 |