├── .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 | 2 | Céu-Arduino Documentation 3 | 4 | 5 |

6 |

Manual

7 | 10 |

Tutorial

11 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | Céu-Arduino Documentation 2 |

3 | 4 | # Manual 5 | 6 | - [v0.20](out/manual/v0.20/) 7 | 8 | # Tutorial 9 | 10 | -------------------------------------------------------------------------------- /docs/manual/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | rm -Rf out/ 3 | mkdir -p out/ 4 | cd v0.20/ && mkdocs build --clean && mv site/ ../out/v0.20/ 5 | cd v0.20/ && mkdocs build --clean && mkdocs2pandoc > ceu-arduino-v0.20.md && pandoc ceu-arduino-v0.20.md -o ceu-arduino-v0.20.pdf && mv site/ ../out/v0.20/ 6 | -------------------------------------------------------------------------------- /docs/manual/v0.20/README.md: -------------------------------------------------------------------------------- 1 | The Reference Manual of Céu-Arduino uses MkDocs: 2 | 3 | http://www.mkdocs.org/ 4 | 5 | ``` 6 | $ mkdocs build 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /docs/manual/v0.20/ceu-arduino-v0.20.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceu-lang/ceu-arduino/31ae9d2a28ece72d1219673deda84a70e6c801c3/docs/manual/v0.20/ceu-arduino-v0.20.md -------------------------------------------------------------------------------- /docs/manual/v0.20/ceu-arduino-v0.20.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceu-lang/ceu-arduino/31ae9d2a28ece72d1219673deda84a70e6c801c3/docs/manual/v0.20/ceu-arduino-v0.20.pdf -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/devices/index.md: -------------------------------------------------------------------------------- 1 | # Device Drivers 2 | 3 | There are device drivers implemented in Céu-Arduino. These drivers can be implemented in one of the two [modes of operation](../modes/index.md). 4 | 5 | {!devices/polling/index.md!} 6 | 7 | {!devices/interrupts/index.md!} 8 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/devices/interrupts/analog.md: -------------------------------------------------------------------------------- 1 | # Analog to Digital Converter 2 | 3 | Céu-Arduino provides asynchronous reads of analog values. This driver provides users with events and a data structure for full control of the driver as well as an abstraction which encapsulates the procedure. 4 | 5 | ## Output Events 6 | 7 | ### ADC_REQUEST 8 | 9 | ```ceu 10 | output (pin) ADC_REQUEST 11 | ``` 12 | 13 | - Parameters: 14 | - `pin` | `integer` : pin to queue read 15 | 16 | Queues an analog read for the specified analog pin. 17 | 18 | The example below starts a conversion for `A0`: 19 | 20 | ```ceu 21 | ... 22 | emit ADC_REQUEST(0); 23 | ... 24 | ``` 25 | 26 | ## Input Events 27 | 28 | ### ADC_DONE 29 | 30 | ```ceu 31 | input (none) ADC_DONE 32 | ``` 33 | 34 | Marks the end of a read. Can be used for synchronization. 35 | 36 | The example below keeps a LED connected to `PIN_01` on while the read is in progress: 37 | 38 | ```ceu 39 | ... 40 | emit ADC_REQUEST(1); 41 | emit PIN_01(on); 42 | await ADC_DONE; 43 | emit PIN_01(off); 44 | ... 45 | ``` 46 | 47 | ## Data Abstractions 48 | 49 | There is a data structure which carries all information about the read state for each pin. The structure is a vector of [`ADC_Channel`](#adc_channel) named `channels`. There is an instance of [`ADC_Channel`](#adc_channel) in `channels` for each analog read pin available on the board (5 for the Arduino Uno). 50 | 51 | ### ADC_Channel 52 | 53 | ```ceu 54 | data ADC_Channel with 55 | var bool is_available = false; 56 | var bool is_busy = false; 57 | var int value; 58 | end 59 | ``` 60 | 61 | - Fields: 62 | - `is_available` : Whether or not there is read value available 63 | - `is_busy` : Whether or not a read is in progress 64 | - `value` : Value of latest conversion, in case `is_available` is set 65 | 66 | This data structure carries all information about a pin read state. It should be used to get the actual value of the read and to monitor the state of the conversion. 67 | 68 | The `is_available` flag is only set when a conversion is done for that pin. Since [`ADC_DONE`](#adc_done) is emitted at the end of every conversion, the flag provides a way to differentiate between conversion results. 69 | 70 | **Clearing the flag is the user's responsability.** 71 | 72 | The `is_busy` flag is for the driver's internal usage. It asserts that there are not more than one [`await Analog()`](#analog) for the same pin at a same given time. 73 | 74 | **If the application enters two [`await Analog()`](#analog) simultaneously, the application will raise an error** 75 | 76 | The example below reads the conversion value for pin `A2`: 77 | 78 | ```ceu 79 | ... 80 | emit ADC_REQUEST(2); 81 | await ADC_DONE; 82 | var int recv = channels[2].value; 83 | ... 84 | ``` 85 | The code below provides a safer alternative to the code above since it deals with simultaneous reads: 86 | 87 | ```ceu 88 | ... 89 | emit ADC_REQUEST(2); 90 | await ADC_DONE until channels[2].is_available; 91 | var int recv = channels[2].value; 92 | channels[2].is_available = false; 93 | ... 94 | ``` 95 | 96 | ## Code/Await Abstractions 97 | 98 | ### Analog 99 | 100 | Performs a full analog read. 101 | 102 | ```ceu 103 | code/await Analog (var int channel) -> int do 104 | _ceu_dbg_assert(outer.channels[channel].is_busy == false); 105 | outer.channels[channel].is_busy = true; 106 | do finalize with 107 | outer.channels[channel].is_busy = false; 108 | end 109 | emit ADC_REQUEST(channel); 110 | await ADC_DONE until outer.channels[channel].is_available; 111 | outer.channels[channel].is_available = false; 112 | escape outer.channels[channel].value; 113 | end 114 | ``` 115 | 116 | - Parameters: 117 | - `channel` : analog pin for which to perform the read 118 | 119 | The example below reads the value from analog pins 3 and 4, concurrently: 120 | 121 | ```ceu 122 | ... 123 | par/and do 124 | var int recv_3 = await Analog(3); 125 | with 126 | var int recv_4 = await Analog(4); 127 | end 128 | ... 129 | ``` 130 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/devices/interrupts/index.md: -------------------------------------------------------------------------------- 1 | ## Interrupt Mode Drivers 2 | 3 | These drivers are implemented using interrupts. They provide events which enable the application to take advantadge of computing cycles using `await`s. This means that the application waits for the interrupt to notify it of the end of a reaction, using `ceu_input` calls or `code/await` abstractions. 4 | 5 | {!devices/interrupts/analog.md!} 6 | 7 | {!devices/interrupts/spi.md!} 8 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/devices/interrupts/spi.md: -------------------------------------------------------------------------------- 1 | # SPI 2 | 3 | Céu-Arduino provides SPI configuration and byte transfers using input and output events as well as `code/await` abstractions which encapsulate the procedures. 4 | 5 | This driver used pins 10, 11, 12 and 13 for the Arduino Uno, as they are SS, MOSI, MISO and SCLK, respectively. 6 | 7 | ## Output Events 8 | 9 | ### SPI_BEGIN 10 | 11 | ```ceu 12 | output (none) SPI_BEGIN 13 | ``` 14 | 15 | Enables the SPI module. Needs to be emitted before any SPI operation. 16 | 17 | The example below enables the SPI module: 18 | 19 | ```ceu 20 | ... 21 | emit SPI_BEGIN; 22 | ... 23 | ``` 24 | ### SPI_END 25 | 26 | ```ceu 27 | output (none) SPI_END 28 | ``` 29 | 30 | Disables the SPI module in case no other device is using it. 31 | 32 | The example below enables the SPI module from two different parts of the code and then disable it at different times: 33 | 34 | ```ceu 35 | ... 36 | par/and do 37 | emit SPI_BEGIN; 38 | await 1s; 39 | emit SPI_END; 40 | with 41 | emit SPI_BEGIN; 42 | await 10s; 43 | emit SPI_END; 44 | end 45 | ... 46 | ``` 47 | 48 | The module is only trully disabled after 10s in this example. 49 | 50 | ### SPI_TRANSACTION_BEGIN 51 | 52 | ```ceu 53 | output (freq,bitOrder,dataMode) SPI_TRANSACTION_BEGIN; 54 | ``` 55 | 56 | - Parameters: 57 | - `freq` | `u32` : frequency the SPI clock will operate in 58 | - `bitOrder` | `u8` : Order in which bits will be shifted in. Possible values are `_MSBFIRST` and `_LSBFIRST`, for Most Significant Bit First and Least Significant Bit First. More information [here](https://en.wikipedia.org/wiki/Most_significant_bit#Most_Significant_Bit_First_vs_Least_Significant_Bit_First). 59 | - `dataMode` | `u8` : SPI mode of operation. Possible values are `_SPI_MODE0`, `_SPI_MODE1`, `_SPI_MODE2`, `_SPI_MODE3`. More information [here](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_numbers). 60 | 61 | Gets control of the driver while configuring it. Has to be called before transfering any bytes. It's the users responsability to not emit a subsequent `SPI_TRANSACTION_BEGIN` before emitting a correspondent [`SPI_TRANSACTION_END`](#spi_transaction_end). 62 | 63 | The example below gets control of the driver for 10 seconds, with the configuration of 1400000 Hz, Most Significant Bit First and SPI Mode of Operation "0": 64 | 65 | ```ceu 66 | ... 67 | emit SPI_BEGIN; 68 | emit SPI_TRANSACTION_BEGIN(1400000,_SPI_MSBFIRST,_SPI_MODE0); 69 | await 10s; 70 | emit SPI_TRANSACTION_END; 71 | ... 72 | ``` 73 | 74 | ### SPI_TRANSACTION_END 75 | 76 | ```ceu 77 | output (none) SPI_TRANSACTION_END 78 | ``` 79 | 80 | Yeilds control of the driver. Has to be called before a subsequent emit to [`SPI_TRANSACTION_BEGIN`](#spi_transaction_begin). Failing to do so will cause the application to crash. 81 | 82 | ### SPI_TRANSFER_REQUEST 83 | 84 | ```ceu 85 | output (value?) SPI_TRANSFER_REQUEST; 86 | ``` 87 | 88 | - Parameters: 89 | - `value` | `u8?` : Byte to transmit to slave. 90 | 91 | Starts a transfer, transmitting `value` if passed as a parameter. It is the responsability of the application to not call a subsequent `SPI_TRANSFER_REQUEST` before the driver emits the correspondent [`SPI_TRANSFER_DONE`](#spi_transfer_done). 92 | 93 | The example below transmits a byte to the slave: 94 | 95 | ```ceu 96 | ... 97 | emit SPI_BEGIN; 98 | emit SPI_TRANSACTION_BEGIN; 99 | var u8 value = 0xAB; 100 | emit SPI_TRANSFER_REQUEST(value); 101 | await SPI_TRANSFER_DONE; 102 | emit SPI_TRANSACTION_END; 103 | emit SPI_END; 104 | ... 105 | ``` 106 | 107 | ## Input Events 108 | 109 | ### SPI_TRANSFER_DONE 110 | 111 | ```ceu 112 | input (u8) SPI_TRANSFER_DONE; 113 | ``` 114 | 115 | Marks the end of a byte transfer, returning the byte received from the slave. 116 | 117 | The example below reads a byte from the slave: 118 | 119 | ```ceu 120 | ... 121 | emit SPI_BEGIN; 122 | emit SPI_TRANSACTION_BEGIN; 123 | emit SPI_TRANSFER_REQUEST(_); 124 | var u8 recv = await SPI_TRANSFER_DONE; 125 | emit SPI_TRANSACTION_END; 126 | emit SPI_END; 127 | ... 128 | ``` 129 | ## Internal Events 130 | 131 | ### spi_transaction_done 132 | 133 | ```ceu 134 | event none spi_transaction_done; 135 | ``` 136 | 137 | Marks the end of a transaction. Used internally by the driver for synchronization. 138 | 139 | ## Code/Await Abstractions 140 | 141 | ### SPI_Begin 142 | 143 | ```ceu 144 | code/await SPI_Begin (none) -> none do 145 | emit SPI_BEGIN; 146 | do finalize with 147 | emit SPI_END; 148 | end 149 | await FOREVER; 150 | end 151 | ``` 152 | 153 | Enables the SPI module. 154 | 155 | The example below enables the SPI module for 10 seconds: 156 | 157 | ```ceu 158 | watching SPI_Begin do 159 | await 10s; 160 | end 161 | ``` 162 | 163 | As the watching block reaches the end of execution, the `do finalize with` block in the code/await abstraction executes, disabling the module. 164 | 165 | ### SPI_Transaction 166 | 167 | ```ceu 168 | code/await SPI_Transaction (var u32 freq, var u8 byte_order, var u8 mode) -> none do 169 | if outer.spi_transaction_busy then 170 | await outer.spi_transaction_end until outer.spi_transaction_busy == false; 171 | end 172 | emit SPI_TRANSACTION_BEGIN(freq,byte_order,mode); 173 | do finalize with 174 | emit SPI_TRANSACTION_END; 175 | emit outer.spi_transaction_end; 176 | end 177 | await FOREVER; 178 | end 179 | ``` 180 | - Parameters: 181 | - `freq` | `u32` : frequency the SPI clock will operate in 182 | - `bit_order` | `u8` : Order in which bits will be shifted in. Possible values are `_MSBFIRST` and `_LSBFIRST`, for Most Significant Bit First and Least Significant Bit First. More information [here](https://en.wikipedia.org/wiki/Most_significant_bit#Most_Significant_Bit_First_vs_Least_Significant_Bit_First). 183 | - `mode` | `u8` : SPI mode of operation. Possible values are `_SPI_MODE0`, `_SPI_MODE1`, `_SPI_MODE2`, `_SPI_MODE3`. More information [here](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_numbers) 184 | 185 | Gets control of the driver while configuring it. In case the driver is busy, awaits until can get control of driver. 186 | 187 | The example below gets control of the driver for 10 seconds, with the configuration of 1400000 Hz, Most Significant Bit First and SPI Mode of Operation "0": 188 | 189 | ```ceu 190 | ... 191 | watching SPI_Begin() do 192 | watching SPI_Transaction(1400000,_SPI_MSBFIRST,_SPI_MODE0) do 193 | await 10s; 194 | end 195 | end 196 | ... 197 | ``` 198 | 199 | Similar to [`SPI_Begin`](#spi_begin), when the watching block reaches the end of execution, the `do finalize with` block in the code/await abstraction executes, yielding control of the driver. 200 | 201 | ### SPI_Transfer 202 | 203 | ```ceu 204 | code/await SPI_Transfer (var u8? value) -> u8 do 205 | if value? == true then 206 | emit SPI_TRANSFER_REQUEST(value!); 207 | else 208 | emit SPI_TRANSFER_REQUEST(_); 209 | end 210 | var u8 recv = await SPI_TRANSFER_DONE; 211 | escape recv; 212 | end 213 | ``` 214 | 215 | - Parameters: 216 | - `value` | `u8?` : Byte to transmit to slave. 217 | 218 | Starts a transfer, transmitting `value` if passed as a parameter and returning the value received from the slave. 219 | 220 | The example below transmits a byte to the slave and reads what was received: 221 | 222 | ```ceu 223 | ... 224 | watching SPI_Begin() do 225 | watching SPI_Transaction(1400000,_SPI_MSBFIRST,_SPI_MODE0) do 226 | var u8 recv = await SPI_Transfer(0xAB); 227 | end 228 | end 229 | ... 230 | ``` 231 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/devices/polling/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceu-lang/ceu-arduino/31ae9d2a28ece72d1219673deda84a70e6c801c3/docs/manual/v0.20/docs/devices/polling/index.md -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/digital_pins/index.md: -------------------------------------------------------------------------------- 1 | # Digital Pins 2 | 3 | Céu-Arduino supports `emit` and `await` statements for digital pins in output 4 | and input modes, respectively. 5 | 6 | {!digital_pins/inputs.md!} 7 | 8 | {!digital_pins/outputs.md!} 9 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/digital_pins/inputs.md: -------------------------------------------------------------------------------- 1 | ## Input Pins 2 | 3 | A program can `await` a change in a digital pin configured as input and acquire 4 | its current value: 5 | 6 | ``` 7 | input int PIN_02; 8 | var int v = await PIN_02; 9 | ``` 10 | 11 | In the [interrupt mode](../modes/#interrupts), the pin requires a driver to 12 | generate the input: 13 | 14 | ```ceu 15 | #include "arduino/isr/pin-02.ceu" 16 | input int PIN_02; 17 | var int v = await PIN_02; 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/digital_pins/outputs.md: -------------------------------------------------------------------------------- 1 | ## Output Pins 2 | 3 | A program can `emit` a change to a digital pin configured as output. 4 | 5 | ### Digital Output 6 | 7 | For digital output, the pin number requires the prefix `PIN_`: 8 | 9 | ``` 10 | output int PIN_13; 11 | emit PIN_13(HIGH); 12 | ``` 13 | 14 | ### PWM Output 15 | 16 | For PWM output, the pin number requires the prefix `PWM_`: 17 | 18 | ``` 19 | output u8 PWM_13; 20 | emit PWM_13(127); 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/index.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Céu-Arduino supports the development of Arduino applications in the programming 4 | language [Céu](http://www.ceu-lang.org/). 5 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/license.md: -------------------------------------------------------------------------------- 1 | License 2 | ======= 3 | 4 | Céu-Arduino is distributed under the MIT license reproduced below: 5 | 6 | ``` 7 | Copyright (C) 2012-2017 Francisco Sant'Anna 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 13 | of the Software, and to permit persons to whom the Software is furnished to do 14 | so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | ``` 27 | 28 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/modes/index.md: -------------------------------------------------------------------------------- 1 | # Modes of Operation 2 | 3 | A mode of operation specifies how Céu-Arduino captures events from the 4 | environment (e.g., pin changes) and redirects them to the Céu application. 5 | 6 | Céu-Arduino supports the *polling* and *interrupt-based* modes of operation. 7 | 8 | The polling mode is the default mode of operation. 9 | 10 | The modes of operation are implemented in C and are part of Céu-Arduino. 11 | Each mode is described in pseudo-code as follows. 12 | 13 | {!modes/polling.md!} 14 | 15 | {!modes/interrupts.md!} 16 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/modes/interrupts.md: -------------------------------------------------------------------------------- 1 | ## Interrupts 2 | 3 | In the *interrupt-based mode* of Céu-Arduino, all input is done in Céu itself 4 | through `async/isr` blocks. 5 | Emitting an input event from an `async/isr` only sets a flag which is then 6 | checked in the Arduino loop: 7 | 8 | ```c 9 | void setup () { 10 | ceu_start(); 11 | while () { 12 | ceu_input(CEU_INPUT__NONE, NULL, CEU_WCLOCK_INACTIVE); 13 | if () { // interrupts off 14 | ceu_input(, <...>); // interrupts on 15 | } 16 | #ifdef CEU_FEATURES_ISR_SLEEP 17 | else if (!) { 18 | 19 | } 20 | #endif 21 | } 22 | ceu_stop(); 23 | while (1); /* freezes arduino */ 24 | } 25 | 26 | void loop () { /* never reached */ } 27 | ``` 28 | 29 | To comply with the synchronous semantics of Céu, all `ceu_input` calls are 30 | serialized in the loop. 31 | 32 | If the macro `CEU_FEATURES_ISR_SLEEP` is defined, the Arduino enters in the 33 | `SLEEP_MODE_IDLE` 34 | [sleep mode](http://playground.arduino.cc/Learning/ArduinoSleepCode) 35 | after each reaction. 36 | 37 | Interrupts are disabled only while checking for occurring inputs. 38 | Hence, `async/isr` blocks and synchronous code may be concurrent and require 39 | `atomic` blocks. 40 | 41 | An `async/isr` in Céu-Arduino requires two arguments: 42 | 43 | - the interrupt number (i.e., the index in the interrupt vector) 44 | - the interrupt trigger mode (i.e., when the interrupt should be triggered) 45 | 46 | The interrupt trigger mode is only used for digital pin interrupts: 47 | 48 | 49 | 50 | The example that follows executes the code marked as `<...>` whenever the value 51 | of *pin 2* changes: 52 | 53 | ``` 54 | spawn async/isr [_digitalPinToInterrupt(2),_CHANGE] do 55 | <...> 56 | end 57 | ``` 58 | 59 | ### Input Events 60 | 61 | Drivers: 62 | 63 | - [`pin-02`](https://github.com/fsantanna/ceu-arduino/blob/master/include/arduino/isr/pin-02.ceu): 64 | `TODO` 65 | - [`timer`](https://github.com/fsantanna/ceu-arduino/blob/master/include/arduino/isr/timer.ceu): 66 | `TODO` 67 | - [`usart`](https://github.com/fsantanna/ceu-arduino/blob/master/include/arduino/isr/usart.ceu): 68 | `TODO` 69 | 70 | ### Compilation 71 | 72 | Applications that use interrupts have to be compiled with `CEU_ISR=true`: 73 | 74 | ``` 75 | $ make CEU_ISR=true CEU_SRC= 76 | ``` 77 | 78 | -------------------------------------------------------------------------------- /docs/manual/v0.20/docs/modes/polling.md: -------------------------------------------------------------------------------- 1 | ## Polling 2 | 3 | The *polling mode* of Céu-Arduino continually checks for changes in the 4 | environment in an infinite loop: 5 | 6 | ```c 7 | void setup () { 8 | ceu_start(); 9 | while () { 10 | ceu_input(CEU_INPUT__NONE, NULL,