1In the interest of a clean and concise codebase that looks readable, it is hereby established that the code will follow these guidelines. 2Finding an example that does not obey these guidelines is not a cause for also disobeying them (it is a cause for fixing it, however) 3 4 5 0. Code will not be wrapped to 80 characters. We all have 24+ inch high-res displays. Let's use them. 6 That being said, this is not an endorsement of 500-character lines. Be reasonable. 7 1. File names shall be camel case and descriptive. Keep them short too. Eg: spi.h is better than 8 spiInterfaceDriver.h 9 2. All function names shall be camel-case, beginning with a lowercase letter. 10 3. All functions that are visibile in the global scope (outside their C file) shall begin with the 11 name of their module (gpio, pwm, os) 12 4. All functions not visible in the global scope shall be declared static 13 5. Functions taking no parameters shall be declated as (void) and not as () 14 6. All type names shall be camel-case, beginnign with a capital letter. 15 7. All types in the global scope shall begin with their module name. (GpioPullType, SpiDeviceHandle) 16 8. There should be *NO* globally-visible variables. All non-stack variables shall be declared 17 "static" and reside in one C file 18 9. All global variables in a given C file shall begin with "m" and then be in camel case. This is to 19 make it easier to identify them 2010. All variables shall be declared in the beginning of the block where they reside. This facilitates 21 easily looking over code and estimating memory use 2211. typedef is forbidden except for function pointer types. Do not typedef structs or unions. Use full 23 names - makes it easy to appreciate the cost (struct GpioHandle, union PwmDeviceData) 2412. Do not use short. char is allowed for actual printable strings only. Use uint8_t/uint16_t/ 25 uint32_t/uint64_t for clarity of intentions and clear delineation of size needed. 2613. int/unsigned int is allowed only for simple loop iterators only (or, if you must, as a return type 27 when you wish to return more than one error class). Do not assume ints are 32 bits. Or 64. Or 16. 2814. Do not use uint16_t/uint8_t for function parameters/return types. Gcc generates very bad code for 29 those cases and you will lose. However, uint8_t/uint16_t are ok to use in structs/unions 3015. All structures shall be packed to avoid space waste, as compiler is not allowed to pack them for 31 you. If you are not sure how to, sort members by size (uint64_t members first, then uint32_t 32 members, etc) 3316. Do not ever return structs or unions from functions. Pass a pointer and fill it in. Gcc will 34 optimize this better and it is better C 3517. All definitions/defines/structs/unions that are only used by one source file belong in that C 36 file. There is never a need for "myModule_priv.h" unless the module is made of a few C files 3718. Absolutely no "double" types are allowed. Absolutely no passing of "float" vars through var-args 38 (it converts to double) 3919. Absolutely no inline assembly unless you're in a folder under "cpu" or "variant". Allowed in 40 "platform" only if platform only supports one CPU type 4120. You may use whatever comment style suits your heart, as long as the compiler can live with it 4221. You may not change compiler flags in order to remove warnings or errors. They are there for a 43 reason, listen to them and fix the code instead. 4422. Whenever possible, hide struct definitions from global scope. Eg: gpio funcs return 45 "struct Gpio*". Actual struct Gpio definition is not public. Not only does this help with clean 46 code, it wil lwarn you if you accidentally try to derefernce it, or on purpiose try to access 47 internal private state. Also this allows platform-independence to continue. 4823. commit messages shall begin with module they touch and a colon, eg "spi: fix spi-dma on stm64" 4924. Do not divide 64-bit values. If you simply must, only do so by a constant, and use cpuMath.h. 50 This will be enforced at compile time and will fail your build. This is intentional as the power 51 and speed costs are substantial. 5225. Do not cast floats to 64-bit values or back, this is slow. Use floatRt.h. This will be enforced 53 at compile time and will fail your build. This is intentional as the power and speed costs are 54 substantial. 5526. Do not use types with uncertain sizes. NO size_t, ssize_t, etc. use uintXX_t or uintptr_t 56 57 5899. These guidelines will be kept updated as things come up/are decided 59