From a5e59148b651b6141acd1ae1e535ff029744e125 Mon Sep 17 00:00:00 2001
From: dequis <dx@dxzone.com.ar>
Date: Sun, 18 Jun 2023 20:19:00 +0200
Subject: [PATCH] Spirals win and become the new default for proto6

---
 components/badge23/Kconfig    |  2 +-
 components/badge23/captouch.c | 18 ++++++++++++++++--
 idf_ext.py                    |  6 +++---
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/components/badge23/Kconfig b/components/badge23/Kconfig
index 8fe87d4d74..9e01a7a2c2 100644
--- a/components/badge23/Kconfig
+++ b/components/badge23/Kconfig
@@ -31,7 +31,7 @@ menu "Badge23 Config"
 
     choice BADGE23_TOP_BOARD_STYLE
         prompt "Badge23 top board style (mainly for proto6)"
-        default BADGE23_TOP_BOARD_SPIKES
+        default BADGE23_TOP_BOARD_SPIRALS
         config BADGE23_TOP_BOARD_SPIKES
             help
                 Spikes between captouch pads
diff --git a/components/badge23/captouch.c b/components/badge23/captouch.c
index 053986283b..93130ccf28 100644
--- a/components/badge23/captouch.c
+++ b/components/badge23/captouch.c
@@ -302,7 +302,15 @@ int32_t captouch_get_petal_rad(uint8_t petal){
         return (left + right)/2 - base;
     }
     #elif defined(CONFIG_BADGE23_TOP_BOARD_SPIRALS)
-        #error captouch_get_petal_rad not implemented for spirals
+    if(cf == 0b1110){ //CCW, CW, BASE
+        int32_t left = petals[petal].cdc_values[PETAL_PAD_CCW];
+        left -= petals[petal].amb_values[PETAL_PAD_CCW];
+        int32_t right = petals[petal].cdc_values[PETAL_PAD_CW];
+        right -= petals[petal].amb_values[PETAL_PAD_CW];
+        int32_t base = petals[petal].cdc_values[PETAL_PAD_BASE];
+        base -= petals[petal].amb_values[PETAL_PAD_BASE];
+        return (left + right)/2 - base;
+    }
     #endif
     if(cf == 0b111){ //CCW, CW, TIP
         int32_t left = petals[petal].cdc_values[PETAL_PAD_CCW];
@@ -340,7 +348,13 @@ int32_t captouch_get_petal_phi(uint8_t petal){
         return left - right;
     }
     #elif defined(CONFIG_BADGE23_TOP_BOARD_SPIRALS)
-        #error captouch_get_petal_phi not implemented for spirals
+    if((cf == 0b1110) || (cf == 0b110) || (cf == 0b111)){ //CCW, CW, (BASE)
+        int32_t left = petals[petal].cdc_values[PETAL_PAD_CCW];
+        left -= petals[petal].amb_values[PETAL_PAD_CCW];
+        int32_t right = petals[petal].cdc_values[PETAL_PAD_CW];
+        right -= petals[petal].amb_values[PETAL_PAD_CW];
+        return left - right;
+    }
     #endif
     return 0;
 }
diff --git a/idf_ext.py b/idf_ext.py
index b6bf13cbd7..03703dac41 100644
--- a/idf_ext.py
+++ b/idf_ext.py
@@ -18,7 +18,7 @@ def action_extensions(base_actions, project_path=os.getcwd()):
         'p3': ['proto3'],
         'p4': ['proto4'],
         'p6': ['proto6'],
-        'p6spiral': ['proto6-spiral'],
+        'p6spike': ['proto6-spike'],
     }
 
     def generation_callback(ctx, global_args, tasks):
@@ -52,9 +52,9 @@ def action_extensions(base_actions, project_path=os.getcwd()):
         sdkconfig_defaults_path = os.path.join(project_path, 'sdkconfig.defaults')
         sdkconfig_generated_path = os.path.join(project_path, '.sdkconfig.defaults.generated')
         with open(sdkconfig_generated_path, 'w') as f:
-            if name == 'p6spiral':
+            if name == 'p6spike':
                 f.write('CONFIG_BADGE23_HW_GEN_P6=y\n')
-                f.write('CONFIG_BADGE23_TOP_BOARD_SPIRALS=y\n')
+                f.write('CONFIG_BADGE23_TOP_BOARD_SPIKES=y\n')
             else:
                 f.write(f'CONFIG_BADGE23_HW_GEN_{name.upper()}=y\n')
             with open(sdkconfig_defaults_path) as f2:
-- 
GitLab