From c667116bd4abe9f2ed70a5b56cc33ab5f214dbcb Mon Sep 17 00:00:00 2001
From: dequis <dx@dxzone.com.ar>
Date: Sat, 17 Jun 2023 19:10:40 +0200
Subject: [PATCH] Add p6 variants for the two top board styles

As requested by moon2. Spikes is the default as that's what p4 uses and
the current code handles decently, spirals is new in p6 and ideally
should have its own implementations for rad and phi, right now it has
placeholders.
---
 components/badge23/Kconfig    | 14 ++++++++++++
 components/badge23/captouch.c |  8 +++++++
 idf_ext.py                    |  3 ++-
 sdkconfig.p6                  |  1 +
 sdkconfig.p6spiral            | 43 +++++++++++++++++++++++++++++++++++
 5 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 sdkconfig.p6spiral

diff --git a/components/badge23/Kconfig b/components/badge23/Kconfig
index cc2007431a..8fe87d4d74 100644
--- a/components/badge23/Kconfig
+++ b/components/badge23/Kconfig
@@ -28,4 +28,18 @@ menu "Badge23 Config"
                   - Sticker with B6xx (xx being arbitrary digits) on the back
             bool "Prototype 6"
     endchoice
+
+    choice BADGE23_TOP_BOARD_STYLE
+        prompt "Badge23 top board style (mainly for proto6)"
+        default BADGE23_TOP_BOARD_SPIKES
+        config BADGE23_TOP_BOARD_SPIKES
+            help
+                Spikes between captouch pads
+            bool "Spikes"
+        config BADGE23_TOP_BOARD_SPIRALS
+            help
+                Spirals between captouch pads
+            bool "Spirals"
+    endchoice
+
 endmenu
diff --git a/components/badge23/captouch.c b/components/badge23/captouch.c
index 6163b0103e..053986283b 100644
--- a/components/badge23/captouch.c
+++ b/components/badge23/captouch.c
@@ -291,6 +291,7 @@ static void captouch_init_petals(){
 int32_t captouch_get_petal_rad(uint8_t petal){
     if(petal > 9) petal = 9;
     uint8_t cf = petals[petal].config_mask;
+    #if defined(CONFIG_BADGE23_TOP_BOARD_SPIKES)
     if(cf == 0b1110){ //CCW, CW, BASE
         int32_t left = petals[petal].cdc_values[PETAL_PAD_CCW];
         left -= petals[petal].amb_values[PETAL_PAD_CCW];
@@ -300,6 +301,9 @@ int32_t captouch_get_petal_rad(uint8_t petal){
         base -= petals[petal].amb_values[PETAL_PAD_BASE];
         return (left + right)/2 - base;
     }
+    #elif defined(CONFIG_BADGE23_TOP_BOARD_SPIRALS)
+        #error captouch_get_petal_rad not implemented for spirals
+    #endif
     if(cf == 0b111){ //CCW, CW, TIP
         int32_t left = petals[petal].cdc_values[PETAL_PAD_CCW];
         left -= petals[petal].amb_values[PETAL_PAD_CCW];
@@ -327,6 +331,7 @@ int32_t captouch_get_petal_rad(uint8_t petal){
 int32_t captouch_get_petal_phi(uint8_t petal){
     if(petal > 9) petal = 9;
     uint8_t cf = petals[petal].config_mask;
+    #if defined(CONFIG_BADGE23_TOP_BOARD_SPIKES)
     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];
@@ -334,6 +339,9 @@ int32_t captouch_get_petal_phi(uint8_t petal){
         right -= petals[petal].amb_values[PETAL_PAD_CW];
         return left - right;
     }
+    #elif defined(CONFIG_BADGE23_TOP_BOARD_SPIRALS)
+        #error captouch_get_petal_phi not implemented for spirals
+    #endif
     return 0;
 }
 
diff --git a/idf_ext.py b/idf_ext.py
index f4a31d7b89..df7432b87c 100644
--- a/idf_ext.py
+++ b/idf_ext.py
@@ -18,6 +18,7 @@ def action_extensions(base_actions, project_path=os.getcwd()):
         'p3': ['proto3'],
         'p4': ['proto4'],
         'p6': ['proto6'],
+        'p6spiral': ['proto6-spiral'],
     }
 
     def generation_callback(ctx, global_args, tasks):
@@ -60,7 +61,7 @@ def action_extensions(base_actions, project_path=os.getcwd()):
     extensions = {
         'global_options': [{
             'names': ['-g', '--generation'],
-            'help': 'Specify badge generation to build for (one of: proto1, proto3, proto4). Defaults to proto4.',
+            'help': 'Specify badge generation to build for (one of: proto1, proto3, proto4, proto6, proto6-spiral). Defaults to proto4.',
             'scope': 'shared',
             'multiple': False,
         }],
diff --git a/sdkconfig.p6 b/sdkconfig.p6
index 4f1324ff09..f8297878d4 100644
--- a/sdkconfig.p6
+++ b/sdkconfig.p6
@@ -40,3 +40,4 @@ CONFIG_LWIP_PPP_SUPPORT=y
 CONFIG_LWIP_PPP_PAP_SUPPORT=y
 CONFIG_LWIP_PPP_CHAP_SUPPORT=y
 CONFIG_BADGE23_HW_GEN_P6=y
+CONFIG_BADGE23_TOP_BOARD_SPIKES=y
diff --git a/sdkconfig.p6spiral b/sdkconfig.p6spiral
new file mode 100644
index 0000000000..4d8098e0a2
--- /dev/null
+++ b/sdkconfig.p6spiral
@@ -0,0 +1,43 @@
+CONFIG_APP_EXCLUDE_PROJECT_VER_VAR=y
+CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR=y
+CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
+CONFIG_ESPTOOLPY_NO_STUB=y
+CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
+CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
+CONFIG_ESPTOOLPY_AFTER_NORESET=y
+CONFIG_PARTITION_TABLE_CUSTOM=y
+CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="micropython/ports/esp32/partitions-8MiB.csv"
+CONFIG_COMPILER_OPTIMIZATION_PERF=y
+CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
+CONFIG_BT_ENABLED=y
+CONFIG_BT_NIMBLE_ENABLED=y
+CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4
+CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y
+CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
+CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB=y
+CONFIG_ESP32S3_DATA_CACHE_64KB=y
+CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y
+CONFIG_ESP32S3_SPIRAM_SUPPORT=y
+CONFIG_SPIRAM_MODE_OCT=y
+CONFIG_SPIRAM_TYPE_ESPPSRAM64=y
+CONFIG_SPIRAM_SPEED_80M=y
+CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
+CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536
+CONFIG_PM_ENABLE=y
+CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
+# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set
+# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set
+# CONFIG_ESP32_WIFI_IRAM_OPT is not set
+# CONFIG_ESP32_WIFI_RX_IRAM_OPT is not set
+CONFIG_FATFS_LFN_HEAP=y
+CONFIG_FATFS_API_ENCODING_UTF_8=y
+CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
+CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP=y
+CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
+CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
+CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
+CONFIG_LWIP_PPP_SUPPORT=y
+CONFIG_LWIP_PPP_PAP_SUPPORT=y
+CONFIG_LWIP_PPP_CHAP_SUPPORT=y
+CONFIG_BADGE23_HW_GEN_P6=y
+CONFIG_BADGE23_TOP_BOARD_SPIRALS=y
-- 
GitLab