aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format19
-rw-r--r--.clang-tidy25
-rw-r--r--stm32/makefile8
-rw-r--r--style.md45
4 files changed, 95 insertions, 2 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..f180135
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,19 @@
+---
+AccessModifierOffset: -4
+AlignConsecutiveAssignments: true
+AllowShortIfStatementsOnASingleLine: AllIfsAndElse
+AllowShortLoopsOnASingleLine: true
+BasedOnStyle: LLVM
+BreakBeforeBraces: Attach
+ColumnLimit: 180
+EmptyLineBeforeAccessModifier: Always
+IndentAccessModifiers: false
+IndentCaseLabels: true
+IndentWidth: 4
+Language: Cpp
+Standard: Cpp11
+TabWidth: 4
+UseTab: Always
+...
+
+# vim: ft=yaml
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..7a8470a
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,25 @@
+Checks: '-*,readability-identifier-naming'
+CheckOptions:
+ - { key: readability-identifier-naming.EnumCase, value: lower_case }
+ - { key: readability-identifier-naming.EnumPrefix, value: hh_e_ }
+ - { key: readability-identifier-naming.GlobalFunctionCase, value: lower_case }
+ - { key: readability-identifier-naming.GlobalFunctionPrefix, value: hh_ }
+ - { key: readability-identifier-naming.ClassCase, value: CamelCase }
+ - { key: readability-identifier-naming.ClassPrefix, value: hh }
+ - { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
+ - { key: readability-identifier-naming.ClassMethodPrefix, value: '' }
+ - { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
+ - { key: readability-identifier-naming.ClassMemberPrefix, value: '' }
+ - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
+ - { key: readability-identifier-naming.GlobalConstantIgnoredRegexp, value: _.* }
+ - { key: readability-identifier-naming.GlobalConstantPrefix, value: HH_ }
+ - { key: readability-identifier-naming.GlobalVariableCase, value: lower_case }
+ - { key: readability-identifier-naming.GlobalVariableIgnoredRegexp, value: _.* }
+ - { key: readability-identifier-naming.GlobalVariablePrefix, value: g_hh_ }
+ - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
+ - { key: readability-identifier-naming.MacroDefinitionIgnoredRegexp, value: _.* }
+ - { key: readability-identifier-naming.MacroDefinitionPrefix, value: HH_ }
+ - { key: readability-identifier-naming.StructCase, value: lower_case }
+ - { key: readability-identifier-naming.StructPrefix, value: hh_s_ }
+
+# vim: ft=yaml
diff --git a/stm32/makefile b/stm32/makefile
index 81f3ec9..22e956e 100644
--- a/stm32/makefile
+++ b/stm32/makefile
@@ -72,7 +72,7 @@ OBJS += lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc.o \
OBJS += idle_task_static_memory.o
OBJS += main.o
-.PHONY: flash clean
+.PHONY: flash clean format
$(TARGET).bin: $(TARGET).elf
$(OC) -O binary $< $@
@@ -96,10 +96,14 @@ $(TARGET).elf: $(OBJS)
flash: $(TARGET).bin
st-flash --reset write $(TARGET).bin 0x08000000
-compile_commands: clean
+compile_commands.json: clean
compiledb make -Bn
../scripts/compiledb-full-path-mingw.sh compile_commands.json
+format:
+ clang-format -i $(SRCS)
+ clang-tidy --fix-errors $(SRCS)
+
clean:
$(RM) $(TARGET).bin $(TARGET).elf $(OBJS)
diff --git a/style.md b/style.md
new file mode 100644
index 0000000..b81ba82
--- /dev/null
+++ b/style.md
@@ -0,0 +1,45 @@
+# code style
+
+this is a quick run-down of basic code style guidelines. code is expected to be
+formatted when a pull request is submitted.
+
+## general rules
+
+### style
+
+all of these can automatically be corrected using `make format`
+
+- indent using tab
+- tab display width (should) be equal to 2 spaces
+- symbols in snake case
+- file names in snake case
+- c++ classes are in CamelCase
+- open brackets on same line
+
+### naming
+
+most (but not all) naming convention errors can be corrected using `make
+format` too, but might cause incompatibility issues. make sure to commit code
+before formatting as a failsafe.
+
+- prefix symbols with `hh_` (e.g. `hh_game_loop_main`)
+- prefix global variables with `g_hh_` (e.g. `g_hh_example_global_variable`)
+- global constants are uppercase snake (e.g. `HH_SERIAL_BAUD`)
+- enum typedefs are prefixed with `hh_e_` (e.g. `hh_e_entity_state`)
+- struct typedefs are prefixed with `hh_s_` (e.g. `hh_s_bam_tile`)
+- custom typedefs are prefixed with `hh_` and suffixed with `_t` (e.g. `hh_bam_tile_t`)
+- library hooks that need specific symbol names are exempt from the naming
+ conventions (e.g. `main` or `HAL_UART_MspInit`)
+
+### others
+
+- document **how to use** code using doxygen-style comments in headers
+- document **what code is doing** using inline comments (where applicable)
+- don't write redundant comments (e.g. `int c = a + b; // add a and b`)
+
+## markdown
+
+### style
+
+- indent using spaces, align to text start
+