The Speeduino firmware aspires to a common, unified approach to code layout based on the guidelines on this page. Any pull requests or submissions should align with these recommendations as much as possible.
Speeduino strives for compliance to the MISRA C:2012 coding standard and many of the conventions below are to align with this. A full description of the requirments of MISRA C:2012 is beyond the scope of this document, but the code does include a MISRA scanning script based on cppcheck that you can use to verify your code changes.
A MISRA scanning script is available for reviewing the current violations in the code.
Requirements:
Usage:
speeduino/misra
directory of the source code./check_misra.sh
with any of the below optional arguments:
-s
, --source=
: Source code directory to scan (Defaults to ../speeduino/
)-e
, --exts=
: File extensions (Defaults to ino
)-o
, --out=
: Output directory (Defaults to .results
)-c
, --cppcheck=
: Location of cppcheck binary (No default, assumes cppcheck
is within the users $PATH
-q
, --quiet
: Quiet, will not output the scan results to stout, only to the results fileWithin code files (.ino
), items must be arranged in the following sequence:
#include
)#define
)In a C header (.h
) file items must be arranged in the following sequence:
#include
)#define
)All names should be meaningful and follow existing usage patterns if present.
Speeduino uses UK/Australian English rather than US. Names and comments should reflect this.
Item | Standard | Example |
---|---|---|
Functions | camelCase, lowercase first letter, no spaces or _ | readSensor(); |
Variables | Same as functions | sensorValue = 0; |
Anonymous variables (eg some loop counters) | Single lowercase letter (Preferred order or use: x, y, z, i) | x++; |
Constants | UPPER_CASE, words joined with _ | #define TWO_SQUARED 4 |
void readSensors()
{
analogRead(sensor1);
analogRead(sensor2);
}
if(fanEnabled) { digitalWrite(fanPin, HIGH); }
true
and false
). Eg:
if(isEnabled == 1)
if(isEnabled)