Professional Documents
Culture Documents
MapleLanguageReference
TheMaplecanbeprogrammedintheWiringlanguage,whichisthesamelanguageusedtoprogramthe
Arduinoboards.
C or C++ programmers may wish to skip to the Note for C/C++ Hackers or the Unix Toolchain
Quickstart.
Contents
MapleLanguageReference
MissingArduinoFeatures
UnimplementedArduinoFeatures
C++forMaple
NoteforC/C++Hackers
RecommendedReading
LookingforSomethingElse?:
SeetheMapleLibraryReferenceforextrabuiltinlibraries.
IfyouwanttouseCorC++,seetheUnixToolchainQuickstart.
IfyourelookingforsomethingfromtheCstandardlibrary(like atoi(),forinstance,seethis
FAQ.
LowleveldetailsareinlibmapleandthispagesRecommendedReading.
MapleLanguageReference
Thistableisasummaryofthemostimportantlanguagefeatures.SeetheCompleteLanguageIndexfor
acompletelisting.
Structure
setup()
loop()
ControlStructures
if/else
for
switch/case
while
do...while
break
continue
return
goto
Variables
Constants
HIGH|LOW
INPUT|OUTPUT
true|false
Constants
(integers,
floatingpoint)
Boardspecificvalues
DataTypes
The size of each
datatype,inbytes,
is
given
in
parentheses where
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
Functions
DigitalI/O
pinMode()
digitalWrite()
digitalRead()
togglePin()
toggleLED()
isButtonPressed()
waitForButtonPress()
AnalogI/O
analogRead()
pwmWrite()(analogWrite()
is also available, though its
1/7
11/12/2015
Furthersyntax
(semicolon)
{}(curlybraces)
//
(singleline
comment)
/* */ (multiline
comment)
#define
#include
appropriate.
Note: The word
type
is
(deliberately) not
supported.
useisdiscouraged)
AdvancedI/O
tone():TODO
noTone():TODO
shiftOut()
pulseIn():TODO
void
boolean(1byte)
Time
char(1byte)
unsignedchar(1byte)
millis()
ArithmeticOperators
byte(1byte)
micros()
int(4bytes)
delay()
=(assignment)
unsignedint(4bytes)
delayMicroseconds()
+(addition)
long (4 bytes), synonym
(subtraction)
forint
Math
*(multiplication)
unsigned long(4bytes),
/(division)
synonymforunsignedint
min()
%(modulo)
longlong(8bytes)
max()
unsigned long long (8
abs()
ComparisonOperators
bytes)
constrain()
float(4bytes)
map()
==(equalto)
double(8bytes)
pow()
!=(notequalto)
strings
sqrt()
<(lessthan)
arrays
>(greaterthan)
Trigonometry
enum
<= (less than or equal
numerictypes
to)
sin()
>= (greater than or
cos()
Conversion
equalto)
tan()
char()
BooleanOperators
RandomNumbers
byte()
int()
&&(and)
randomSeed()
long()
||(or)
random()
float()
!(not)
double()
BitsandBytes
PointerOperators
VariableScope&Qualifiers
lowByte()
*
dereference
highByte() is provided,
variables,scope
operator
though
its
use
is
static
&referenceoperator
discouraged.
volatile
bitRead()
const
BitwiseOperators
bitWrite()
bitSet()
Utilities
&(bitwiseand)
bitClear()
|(bitwiseor)
sizeof()
bit()
^(bitwisexor)
ASSERT()
~(bitwisenot)
ExternalInterrupts
<<(shiftleft)
>>(shiftright)
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
2/7
11/12/2015
CompoundOperators
++(increment)
(decrement)
+=(compoundadd)
=
(compound
subtract)
*=
(compound
multiply)
/=(compounddivide)
&=(compoundbitwise
and)
|= (compound bitwise
or)
ReferencePage
attachInterrupt()
detachInterrupt()
Interrupts
interrupts()
noInterrupts()
Communication
SerialUSB
Serial
Keywords
C++Keywords
MissingArduinoFeatures
analogReference()
ItisnotpossibletoimplementthisfunctionontheMaplehardware.Itwillbepossibleonthe
upcomingMapleNative.
word
ReadersfamiliarwiththeArduinoenvironmentmaynoticethatthe worddatatypeismissing
fromtheabovetableslistofdatatypes.Wechosenottoprovidethe worddatatypeon
theMaple.Ifyouwanta16bitunsignedinteger,usethe uint16typeinstead.
WhiletheMaplehas32bitwords,thewordsizeonanArduinoboardisonly16bits,and
codethatusesthe wordtypeislikelytorelyonthatfact.
Bynotsupporting word,youllgetacompileerrorwhenportingArduinocodetotheMaple
insteadofpotentiallyweird,hardtodebugruntimebehavior.
Ifyoureallymusthave word,youcanincludethefollowing typedefinyourprogram:
typedef uint16 word;
UnimplementedArduinoFeatures
ThefollowingWiring/ArduinofeaturesarecurrentlyunimplementedontheMaple.
tone()
noTone()
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
3/7
11/12/2015
pulseIn()
String
C++forMaple
IfyouhaventprogrammedinC++,orifyoujustneedtojogyourmemory,youmaywanttocheckout
ourLanguageIndex.ItprovidessomeintroductorycoverageofprogrammingideasandC++.
NoteforC/C++Hackers
This is a note for programmers comfortable with C or C++ who want a better understanding of the
differencesbetweenC++andtheWiringlanguage.
ThegoodnewsisthatthedifferencesarerelativelyfewWiringisjustathinwrapperaroundC++.Some
potentially better news is that the Maple can be programmed using a standard Unix toolchain, so if
youdratherstickwithgcc,make,andfriends,youcan.IfyoureusingtheUnixtoolchainandwantto
skippasttheWiringconveniencesandgetstraighttoregisters,youareencouragedtomoveontothe
libmapledocumentation.
AsketchistheIDEsnotionofaprojectitconsistsofoneormorefileswrittenintheWiringlanguage,
which is mostly the same as C++. The major difference between the two is that in Wiring, its not
necessarytodeclareglobalfunctionsbeforetheyareused.Thatis,thefollowingisvalidWiring,and f()
returns 5:
int f() {
return g();
}
int g() {
return 5;
}
Allofthefilesinasketchsharethesame(global)namespace.Thatis,thebehaviorisasifallofasketchs
fileswerepartofthesametranslationunit,sotheydonthavetoincludeoneanotherinordertoaccess
eachothersdefinitions.TheonlyothermajordifferencebetweenWiringandC++isthatWiringdoesnt
supportdynamicallyallocatedmemorythatis, newand deletewontwork.AsofJanuary15,2014,
Mapleonlyhas20KBRAM,anyway,soitsdoubtfulthatstaticallocationisnotwhatyouwant.
TheWiringlanguagealsodoesnotrequireyoutodefineyourown main method (infact, we currently
forbidyoufromdoingso).Instead,youarerequiredtodefinetwofunctions, setupand loop,withtype
signatures
void setup(void);
void loop(void);
Once a sketch is uploaded to a Maple and begins to run, setup() is called once, and then loop() is
calledrepeatedly.TheIDEcompilationprocessproceedsviaasourcetosourcetranslationfromthefiles
inasketchtoC++.
Thistranslationprocessfirstconcatenatesthesketchfiles,thenparsestheresulttoproducealistofall
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
4/7
11/12/2015
functions defined in the global scope. (We borrow this stage from the Arduino IDE, which in turn
borrowsitfromWiring.ItusesregularexpressionstoparseC++,whichis,ofcourse,BadandWrong.
Inthefuture,welldothiscorrectly,usingabetterparser.Untilthen,youhaveourapologies.)Theorder
inwhichtheindividualsketchfilesareconcatenatedisnotdefineditisunwisetowritecodethatdepends
onaparticularordering.
TheconcatenatedsketchfilesarethenappendedontoafilewhichincludesWProgram.h(whichincludes
thewirishandlibmaplelibraries,anddeclares setup()and loop()),andthenprovidesdeclarationsfor
all the function definitions found in the previous step. At this point, we have a file that is a valid C++
translationunit,butlacks main().Thefinalstepofcompilationprovides main(),whichbehavesroughly
like:
int main(void) {
// Call libmaple's built-in initialization routines
init();
// Perform the user's initialization
setup();
(Thetruthisalittlebitmorecomplicated,butnotbymuch).
Asanexample,considerasketchwithtwofiles.Thefirstfilecontains setup()and loop():
int the_pin;
void setup() {
the_pin = choose_a_pin();
pinMode(the_pin, OUTPUT);
}
void loop() {
togglePin(the_pin);
}
Thesecondfilecontainsthe(notveryuseful)implementationfor choose_a_pin():
int choose_a_pin() {
return random(5, 15);
}
Thentheresultsoftheconcatenationprocessmightbe
int the_pin;
void setup() {
the_pin = choose_a_pin();
pinMode(the_pin, OUTPUT);
}
void loop() {
togglePin(the_pin);
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
5/7
11/12/2015
}
int choose_a_pin(void);
int choose_a_pin() {
return random(5, 15);
}
Whichcouldplausiblybeturnedintothefinalsourcefile
#include "WProgram.h"
void setup(void);
void loop(void);
int choose_a_pin(void);
int the_pin;
void setup() {
the_pin = choose_a_pin();
pinMode(the_pin, OUTPUT);
}
void loop() {
togglePin(the_pin);
}
int choose_a_pin(void);
int choose_a_pin() {
return random(5, 15);
}
int main() {
init();
setup();
while (true) loop();
}
RecommendedReading
libmapleDocumentation
YourboardsBoardHardwareDocumentationpage
STDocumentation:
ReferenceManualRM0008(PDF).Thisisthemostimportantreferenceworkonthe
STM32 line, and covers the lowlevel hardware capabilities and interfaces in great
detail.
ProgrammingManual (PDF).This isan assemblylanguageandregister referencefor
theSTM32line.
ARMDocumentation:
CortexM3 Technical Reference Manual, Revision r1p1 (PDF). This ARM manual
specifiesmuchofthetheCortexM3Architecture,includinginstructiontimings.
newlibDocumentation
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
6/7
11/12/2015
http://static.leaflabs.com/pub/leaflabs/maple-docs/latest/language.html#language
7/7