From 365dcc18fbd98645585cdbe009f537ecdaa90c1a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 17 May 2022 21:21:00 +0200 Subject: WIP sercomm implementation - moved some module-specific constants to their respective header files - changed .clang-tidy to ignore global private global constants (starting with `_`) - suppressed some GCC warnings in bin.c and all pololu library warnings - added function signatures for sercomm protocol data generators - added endianness check in setup.c --- .clang-tidy | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to '.clang-tidy') diff --git a/.clang-tidy b/.clang-tidy index 054a943..4c8496f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,16 +1,18 @@ Checks: '-*,readability-identifier-naming' CheckOptions: + - { key: readability-identifier-naming.EnumCase, value: lower_case } + - { key: readability-identifier-naming.EnumPrefix, value: w2_e_ } - { key: readability-identifier-naming.FunctionCase, value: lower_case } - { key: readability-identifier-naming.FunctionPrefix, value: w2_ } - - { key: readability-identifier-naming.GlobalVariableCase, value: lower_case } - - { key: readability-identifier-naming.GlobalVariablePrefix, value: g_w2_ } - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.GlobalConstantIgnoredRegexp, value: _.* } - { key: readability-identifier-naming.GlobalConstantPrefix, value: W2_ } + - { key: readability-identifier-naming.GlobalVariableCase, value: lower_case } + - { key: readability-identifier-naming.GlobalVariableIgnoredRegexp, value: _.* } + - { key: readability-identifier-naming.GlobalVariablePrefix, value: g_w2_ } - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } - { key: readability-identifier-naming.MacroDefinitionPrefix, value: W2_ } - { key: readability-identifier-naming.StructCase, value: lower_case } - { key: readability-identifier-naming.StructPrefix, value: w2_s_ } - - { key: readability-identifier-naming.EnumCase, value: lower_case } - - { key: readability-identifier-naming.EnumPrefix, value: w2_e_ } # vim: ft=yaml -- cgit v1.2.3 From 2b75425070662b869c15673623df44e30ce43ebe Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 17 May 2022 21:28:08 +0200 Subject: code format --- .clang-tidy | 1 + robot/bin.c | 8 ++++---- robot/bin.h | 2 -- robot/consts.h | 1 - robot/errcatch.c | 4 ++-- robot/setup.c | 6 +++--- 6 files changed, 10 insertions(+), 12 deletions(-) (limited to '.clang-tidy') diff --git a/.clang-tidy b/.clang-tidy index 4c8496f..4dd70ad 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,6 +11,7 @@ CheckOptions: - { key: readability-identifier-naming.GlobalVariableIgnoredRegexp, value: _.* } - { key: readability-identifier-naming.GlobalVariablePrefix, value: g_w2_ } - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } + - { key: readability-identifier-naming.MacroDefinitionIgnoredRegexp, value: _.* } - { key: readability-identifier-naming.MacroDefinitionPrefix, value: W2_ } - { key: readability-identifier-naming.StructCase, value: lower_case } - { key: readability-identifier-naming.StructPrefix, value: w2_s_ } diff --git a/robot/bin.c b/robot/bin.c index 4261b50..4242edc 100644 --- a/robot/bin.c +++ b/robot/bin.c @@ -15,14 +15,14 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshift-count-overflow" uint32_t w2_bin_hton32(uint32_t h32) { - if(g_w2_endianness == W2_ENDIAN_BIG) return h32; - return ((h32 & _BYTE_0) << _SHIFT_3B) | ((h32 & _BYTE_1) << _SHIFT_1B) - | ((h32 & _BYTE_2) >> _SHIFT_1B) | ((h32 & _BYTE_3) >> _SHIFT_3B); + if (g_w2_endianness == W2_ENDIAN_BIG) return h32; + return ((h32 & _BYTE_0) << _SHIFT_3B) | ((h32 & _BYTE_1) << _SHIFT_1B) | + ((h32 & _BYTE_2) >> _SHIFT_1B) | ((h32 & _BYTE_3) >> _SHIFT_3B); } #pragma GCC diagnostic pop uint16_t w2_bin_hton16(uint16_t h16) { - if(g_w2_endianness == W2_ENDIAN_BIG) return h16; + if (g_w2_endianness == W2_ENDIAN_BIG) return h16; return ((h16 & _BYTE_0) << _SHIFT_1B) | ((h16 & _BYTE_1) >> _SHIFT_1B); } diff --git a/robot/bin.h b/robot/bin.h index 1f21f64..ccde132 100644 --- a/robot/bin.h +++ b/robot/bin.h @@ -9,7 +9,6 @@ typedef struct { extern uint8_t g_w2_endianness; - /** * helper file for binary data * @@ -24,4 +23,3 @@ uint16_t w2_bin_hton16(uint16_t h16); uint32_t w2_bin_ntoh32(uint32_t n32); /** convert 16-bit value from network (big-endian) to host endian */ uint16_t w2_bin_ntoh16(uint16_t n16); - diff --git a/robot/consts.h b/robot/consts.h index 3558da0..d74d034 100644 --- a/robot/consts.h +++ b/robot/consts.h @@ -8,4 +8,3 @@ #define W2_MAX_MODULE_CYCLE_MS (20) #define W2_SERIAL_BAUD (9600) #define W2_E_BUFFER_SIZE (16) - diff --git a/robot/errcatch.c b/robot/errcatch.c index 0f97566..1262a38 100644 --- a/robot/errcatch.c +++ b/robot/errcatch.c @@ -9,8 +9,8 @@ #include "orangutan_shim.h" w2_s_error *g_w2_error_buffer[W2_E_BUFFER_SIZE] = {}; -uint8_t g_w2_error_index = 0; -uint8_t g_w2_error_offset = 0; +uint8_t g_w2_error_index = 0; +uint8_t g_w2_error_offset = 0; void w2_errcatch_main() { while (g_w2_error_index != g_w2_error_offset) { diff --git a/robot/setup.c b/robot/setup.c index bdd5991..d040286 100644 --- a/robot/setup.c +++ b/robot/setup.c @@ -1,15 +1,15 @@ #include +#include "bin.h" #include "consts.h" #include "halt.h" #include "modes.h" #include "orangutan_shim.h" #include "setup.h" -#include "bin.h" // pointers for endianness check -static const uint16_t _test = 1; -static const uint8_t* _ptest = (uint8_t*)&_test; +static const uint16_t _test = 1; +static const uint8_t *_ptest = (uint8_t *)&_test; uint8_t g_w2_endianness; void w2_setup_main() { -- cgit v1.2.3