From 85ce625a0b51d49aacf37b64223e832d1d21f193 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Thu, 18 Jul 2019 23:42:29 +0200
Subject: [PATCH] fix(api): code style

---
 epicardium/api/interrupt-receiver.c | 30 ++++++++++----------
 epicardium/api/interrupt-sender.c   | 37 +++++++++++++------------
 epicardium/epicardium.h             |  2 +-
 epicardium/main.c                   |  2 +-
 epicardium/modules/serial.c         |  9 +++---
 pycardium/modules/interrupt.c       | 43 +++++++++++++++++------------
 pycardium/mphalport.c               | 24 ++++++++--------
 7 files changed, 78 insertions(+), 69 deletions(-)

diff --git a/epicardium/api/interrupt-receiver.c b/epicardium/api/interrupt-receiver.c
index 87fa8c352..95c5038d1 100644
--- a/epicardium/api/interrupt-receiver.c
+++ b/epicardium/api/interrupt-receiver.c
@@ -3,33 +3,33 @@
 #include "api/common.h"
 #include "epicardium.h"
 
-void api_interrupt_handler_ctrl_c   (api_int_id_t id) __attribute__ ((weak, alias("api_interrupt_handler_default")));
-void api_interrupt_handler_bhi160   (api_int_id_t id) __attribute__ ((weak, alias("api_interrupt_handler_default")));
+void api_interrupt_handler_ctrl_c(api_int_id_t id)
+	__attribute__((weak, alias("api_interrupt_handler_default")));
+void api_interrupt_handler_bhi160(api_int_id_t id)
+	__attribute__((weak, alias("api_interrupt_handler_default")));
 
 /* Timer Interrupt used for control char notification */
 void TMR5_IRQHandler(void)
 {
 	TMR_IntClear(MXC_TMR5);
 
-    switch(API_CALL_MEM->int_id) {
-        case API_INT_CTRL_C:
-            api_interrupt_handler_ctrl_c(API_CALL_MEM->int_id);
-        break;
-        case API_INT_BHI160:
-            api_interrupt_handler_bhi160(API_CALL_MEM->int_id);
-        break;
-    }
+	switch (API_CALL_MEM->int_id) {
+	case API_INT_CTRL_C:
+		api_interrupt_handler_ctrl_c(API_CALL_MEM->int_id);
+		break;
+	case API_INT_BHI160:
+		api_interrupt_handler_bhi160(API_CALL_MEM->int_id);
+		break;
+	}
 
-    API_CALL_MEM->int_id = 0;
+	API_CALL_MEM->int_id = 0;
 }
 
-__attribute__((weak))
-void api_interrupt_handler_catch_all(api_int_id_t id)
+__attribute__((weak)) void api_interrupt_handler_catch_all(api_int_id_t id)
 {
 }
 
 void api_interrupt_handler_default(api_int_id_t id)
 {
-    api_interrupt_handler_catch_all(id);
+	api_interrupt_handler_catch_all(id);
 }
-
diff --git a/epicardium/api/interrupt-sender.c b/epicardium/api/interrupt-sender.c
index fb4cb1458..3714c2797 100644
--- a/epicardium/api/interrupt-sender.c
+++ b/epicardium/api/interrupt-sender.c
@@ -6,35 +6,36 @@ static bool enabled[API_INT_MAX + 1];
 
 void api_interrupt_trigger(api_int_id_t id)
 {
-    if(id <= API_INT_MAX) {
-        if(enabled[id]) {
-            while(API_CALL_MEM->int_id);
-            API_CALL_MEM->int_id = id;
-            TMR_TO_Start(MXC_TMR5, 1, 0);
-        }
-    }
+	if (id <= API_INT_MAX) {
+		if (enabled[id]) {
+			while (API_CALL_MEM->int_id)
+				;
+			API_CALL_MEM->int_id = id;
+			TMR_TO_Start(MXC_TMR5, 1, 0);
+		}
+	}
 }
 
 void api_interrupt_init(void)
 {
-    int i;
-    API_CALL_MEM->int_id = 0;
+	int i;
+	API_CALL_MEM->int_id = 0;
 
-    for(i=0; i <= API_INT_MAX; i++) {
-        enabled[i] = false;
-    }
+	for (i = 0; i <= API_INT_MAX; i++) {
+		enabled[i] = false;
+	}
 }
 
 void api_interrupt_enable(api_int_id_t int_id)
 {
-    if(int_id <= API_INT_MAX) {
-        enabled[int_id] = true;
-    }
+	if (int_id <= API_INT_MAX) {
+		enabled[int_id] = true;
+	}
 }
 
 void api_interrupt_disable(api_int_id_t int_id)
 {
-    if(int_id <= API_INT_MAX) {
-        enabled[int_id] = false;
-    }
+	if (int_id <= API_INT_MAX) {
+		enabled[int_id] = false;
+	}
 }
diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h
index 5d9af78e4..4a7cc404c 100644
--- a/epicardium/epicardium.h
+++ b/epicardium/epicardium.h
@@ -2,6 +2,7 @@
 #define _EPICARDIUM_H
 #include <stdint.h>
 
+/* clang-format off */
 #define API_INT_CTRL_C  1
 #define API_INT_BHI160  2
 #define API_INT_MAX     API_INT_BHI160
@@ -10,7 +11,6 @@
 #define API(id, def) def
 #endif
 
-/* clang-format off */
 #define API_UART_WRITE         0x1
 #define API_UART_READ          0x2
 #define API_LEDS_SET           0x3
diff --git a/epicardium/main.c b/epicardium/main.c
index 94bcdd01d..6f91854eb 100644
--- a/epicardium/main.c
+++ b/epicardium/main.c
@@ -47,7 +47,7 @@ int main(void)
 
 	cdcacm_init();
 	fatfs_init();
-    api_interrupt_init();
+	api_interrupt_init();
 
 	printf("=> Initializing tasks ...\n");
 
diff --git a/epicardium/modules/serial.c b/epicardium/modules/serial.c
index aa46f233c..2ac138127 100644
--- a/epicardium/modules/serial.c
+++ b/epicardium/modules/serial.c
@@ -13,7 +13,6 @@
 #include "epicardium.h"
 #include "api/interrupt-sender.h"
 
-
 /* Task ID for the serial handler */
 TaskHandle_t serial_task_id = NULL;
 
@@ -58,13 +57,13 @@ static void enqueue_char(char chr)
 {
 	if (chr == 0x3) {
 		/* Control-C */
-        api_interrupt_trigger(API_INT_CTRL_C);
+		api_interrupt_trigger(API_INT_CTRL_C);
 	}
 
-    if (chr == 0x0e) {
+	if (chr == 0x0e) {
 		/* Control-N */
-        api_interrupt_trigger(API_INT_BHI160);
-    }
+		api_interrupt_trigger(API_INT_BHI160);
+	}
 
 	if (xQueueSend(read_queue, &chr, 100) == errQUEUE_FULL) {
 		/* Queue overran, wait a bit */
diff --git a/pycardium/modules/interrupt.c b/pycardium/modules/interrupt.c
index 92bc3dcbb..45ee55c38 100644
--- a/pycardium/modules/interrupt.c
+++ b/pycardium/modules/interrupt.c
@@ -9,40 +9,46 @@ mp_obj_t bhi160_callback = NULL;
 
 static void interrupt_set(api_int_id_t id, mp_obj_t func)
 {
-    // TODO: maintain list of interrupts callbacks
-    if(id == API_INT_BHI160) {
-        bhi160_callback = func;
-    }
+	// TODO: maintain list of interrupts callbacks
+	if (id == API_INT_BHI160) {
+		bhi160_callback = func;
+	}
 }
 
 void api_interrupt_handler_catch_all(api_int_id_t id)
 {
-    // TODO: iterate over registered callbacks
-    if(id == API_INT_BHI160) {
-        if(bhi160_callback) {
-            mp_sched_schedule(bhi160_callback, MP_OBJ_NEW_SMALL_INT(0));
-        }
-    }
+	// TODO: iterate over registered callbacks
+	if (id == API_INT_BHI160) {
+		if (bhi160_callback) {
+			mp_sched_schedule(
+				bhi160_callback, MP_OBJ_NEW_SMALL_INT(0)
+			);
+		}
+	}
 }
 
 STATIC mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj)
 {
-    // TODO: check argument types
+	// TODO: check argument types
 	api_int_id_t id = mp_obj_get_int(id_in);
-    interrupt_set(id, callback_obj);
+	interrupt_set(id, callback_obj);
 	return mp_const_none;
 }
 
 STATIC mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in)
 {
-    // TODO: check argument types
+	// TODO: check argument types
 	api_int_id_t id = mp_obj_get_int(id_in);
-    api_interrupt_enable(id);
+	api_interrupt_enable(id);
 	return mp_const_none;
 }
 
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(interrupt_set_callback_obj, mp_interrupt_set_callback);
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(interrupt_enable_callback_obj, mp_interrupt_enable_callback);
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(
+	interrupt_set_callback_obj, mp_interrupt_set_callback
+);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(
+	interrupt_enable_callback_obj, mp_interrupt_enable_callback
+);
 
 STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = {
 	{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_interrupt) },
@@ -50,7 +56,9 @@ STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = {
 	{ MP_ROM_QSTR(MP_QSTR_enable_callback), MP_ROM_PTR(&interrupt_enable_callback_obj) },
 	{ MP_ROM_QSTR(MP_QSTR_BHI160), MP_OBJ_NEW_SMALL_INT(2) },
 };
-STATIC MP_DEFINE_CONST_DICT(interrupt_module_globals, interrupt_module_globals_table);
+STATIC MP_DEFINE_CONST_DICT(
+	interrupt_module_globals, interrupt_module_globals_table
+);
 
 // Define module object.
 const mp_obj_module_t interrupt_module = {
@@ -58,5 +66,6 @@ const mp_obj_module_t interrupt_module = {
 	.globals = (mp_obj_dict_t *)&interrupt_module_globals,
 };
 
+/* clang-format off */
 // Register the module to make it available in Python
 MP_REGISTER_MODULE(MP_QSTR_interrupt, interrupt_module, MODULE_INTERRUPT_ENABLED);
diff --git a/pycardium/mphalport.c b/pycardium/mphalport.c
index 0dedf72c5..b950f85fb 100644
--- a/pycardium/mphalport.c
+++ b/pycardium/mphalport.c
@@ -64,13 +64,13 @@ long _write(int fd, const char *buf, size_t cnt)
 
 void api_interrupt_handler_ctrl_c(void)
 {
-    /* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */
-    MP_STATE_VM(mp_pending_exception) =
-        MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
+	/* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */
+	MP_STATE_VM(mp_pending_exception) =
+		MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
 #if MICROPY_ENABLE_SCHEDULER
-    if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
-        MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
-    }
+	if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
+		MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
+	}
 #endif
 }
 
@@ -82,11 +82,11 @@ void mp_hal_set_interrupt_char(char c)
 		);
 	}
 
-	if(c == 0x03) {
-        api_interrupt_enable(API_INT_CTRL_C);
-    } else {
-        api_interrupt_disable(API_INT_CTRL_C);
-    }
+	if (c == 0x03) {
+		api_interrupt_enable(API_INT_CTRL_C);
+	} else {
+		api_interrupt_disable(API_INT_CTRL_C);
+	}
 }
 
 /******************************************************************************
@@ -135,7 +135,7 @@ mp_import_stat_t mp_import_stat(const char *path)
 mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
 {
 	/* TODO: Once fs is implemented, get this working as well */
-	mp_raise_NotImplementedError ("FS is not yet implemented");
+	mp_raise_NotImplementedError("FS is not yet implemented");
 	return mp_const_none;
 }
 MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
-- 
GitLab