{"results":{"result":{"added-files":{"code-health":0.0,"old-code-health":0.0,"files":[]},"external-review-url":"https://github.com/hathach/tinyusb/pull/3275","old-code-health":6.631046844921797,"modified-files":{"code-health":6.212977665039387,"old-code-health":6.631046844921797,"files":[{"file":"src/portable/synopsys/dwc2/dcd_dwc2.c","loc":755,"old-loc":700,"code-health":6.2129776650393875,"old-code-health":6.631046844921797}]},"removed-files":{"code-health":0.0,"old-code-health":0.0,"files":[]},"external-review-id":"3275","analysis-time":"2025-10-30T21:40:53Z","negative-impact-count":4,"suppressions":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"affected-hotspots":1,"commits":["e0a589cdcae6eaf790d05712a6f2b8c0352fb5fd","b9b1c6432a7be43297afb0a75621ece5fc63f3a5","82b0e2d0066ef1eea3b2bdeee0651c7519bc7f0a","beea882c6bcee352b5ff69446aef9fc43237bab0"],"is-negative-review":true,"negative-findings":{"number-of-types":2,"number-of-files-touched":1,"findings":[{"method":"dcd_int_handler","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the C language is a cyclomatic complexity lower than 9.","name":"Complex Method","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","refactoring-examples":[{"architectural-component-id":null,"author-name":"hathach","training-data":{"loc-added":"56","loc-deleted":"50","delta-cc-mean":"0.0","delta-cc-total":"0","delta-penalties":"1.494","delta-n-functions":"0","current-file-score":"9.6882083290695"},"author-email":"thach@tinyusb.org","commit-full-message":"add -Wno-error=format for espressif\nwrap up cdc_msc_hid_freertos","commit-date":"2023-09-26T12:09:36Z","current-rev":"f6ca86c3d","filename":"tinyusb/hw/bsp/nrf/family.c","previous-rev":"a7c136c03","commit-title":"tested cdc_msc_hid_freertos with samd51","language":"C","id":"9aa6bf46ecc8de9e66375157db1f153c3928a576","model-score":0.22,"author-id":null,"project-id":37161,"delta-file-score":0.44580856,"diff":"diff --git a/hw/bsp/nrf/family.c b/hw/bsp/nrf/family.c\nindex 6fcfd9476..3620bc8cc 100644\n--- a/hw/bsp/nrf/family.c\n+++ b/hw/bsp/nrf/family.c\n@@ -97,9 +97,4 @@ TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event) {\n #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421\n+static void max3421_init(void);\n static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);\n-\n-void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {\n-  if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;\n-\n-  tuh_int_handler(1);\n-}\n #endif\n@@ -193,46 +188,3 @@ void board_init(void) {\n #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421\n-  // MAX3421 need 3.3v signal (may not be needed)\n-  #if defined(UICR_REGOUT0_VOUT_Msk) && 0\n-  if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {\n-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;\n-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n-\n-    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;\n-\n-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;\n-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n-\n-    NVIC_SystemReset();\n-  }\n-  #endif\n-\n-  // manually manage CS\n-  nrf_gpio_cfg_output(MAX3421_CS_PIN);\n-  nrf_gpio_pin_write(MAX3421_CS_PIN, 1);\n-\n-  // USB host using max3421e usb controller via SPI\n-  nrfx_spim_config_t cfg = {\n-      .sck_pin        = MAX3421_SCK_PIN,\n-      .mosi_pin       = MAX3421_MOSI_PIN,\n-      .miso_pin       = MAX3421_MISO_PIN,\n-      .ss_pin         = NRFX_SPIM_PIN_NOT_USED,\n-      .ss_active_high = false,\n-      .irq_priority   = 3,\n-      .orc            = 0xFF,\n-      // default setting 4 Mhz, Mode 0, MSB first\n-      .frequency      = NRF_SPIM_FREQ_4M,\n-      .mode           = NRF_SPIM_MODE_0,\n-      .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,\n-  };\n-\n-  // no handler --> blocking\n-  nrfx_spim_init(&_spi, &cfg, NULL, NULL);\n-\n-  // max3421e interrupt pin\n-  nrfx_gpiote_init(1);\n-  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);\n-  in_config.pull = NRF_GPIO_PIN_PULLUP;\n-\n-  nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);\n-  nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);\n+  max3421_init();\n #endif\n@@ -319,2 +271,56 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) {\n \n+void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {\n+  if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;\n+  tuh_int_handler(1);\n+}\n+\n+static void max3421_init(void) {\n+  // MAX3421 need 3.3v signal (may not be needed)\n+//  #if defined(UICR_REGOUT0_VOUT_Msk)\n+//  if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {\n+//    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;\n+//    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n+//\n+//    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;\n+//\n+//    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;\n+//    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n+//\n+//    NVIC_SystemReset();\n+//  }\n+//  #endif\n+\n+  // manually manage CS\n+  nrf_gpio_cfg_output(MAX3421_CS_PIN);\n+  nrf_gpio_pin_write(MAX3421_CS_PIN, 1);\n+\n+  // USB host using max3421e usb controller via SPI\n+  nrfx_spim_config_t cfg = {\n+      .sck_pin        = MAX3421_SCK_PIN,\n+      .mosi_pin       = MAX3421_MOSI_PIN,\n+      .miso_pin       = MAX3421_MISO_PIN,\n+      .ss_pin         = NRFX_SPIM_PIN_NOT_USED,\n+      .ss_active_high = false,\n+      .irq_priority   = 3,\n+      .orc            = 0xFF,\n+      // default setting 4 Mhz, Mode 0, MSB first\n+      .frequency      = NRF_SPIM_FREQ_4M,\n+      .mode           = NRF_SPIM_MODE_0,\n+      .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,\n+  };\n+\n+  // no handler --> blocking\n+  nrfx_spim_init(&_spi, &cfg, NULL, NULL);\n+\n+  // max3421e interrupt pin\n+  nrfx_gpiote_init(1);\n+  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);\n+  in_config.pull = NRF_GPIO_PIN_PULLUP;\n+\n+  NVIC_SetPriority(GPIOTE_IRQn, 2);\n+\n+  nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);\n+  nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);\n+}\n+\n void tuh_max3421_int_api(uint8_t rhport, bool enabled) {\n","improvement-type":"Complex Method"}],"change-level":"warning","is-hotspot?":true,"line":1052,"what-changed":"dcd_int_handler increases in cyclomatic complexity from 13 to 20, threshold = 9","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"degraded"},{"method":"handle_epout_dma","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the C language is a cyclomatic complexity lower than 9.","name":"Complex Method","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","refactoring-examples":[{"architectural-component-id":null,"author-name":"hathach","training-data":{"loc-added":"56","loc-deleted":"50","delta-cc-mean":"0.0","delta-cc-total":"0","delta-penalties":"1.494","delta-n-functions":"0","current-file-score":"9.6882083290695"},"author-email":"thach@tinyusb.org","commit-full-message":"add -Wno-error=format for espressif\nwrap up cdc_msc_hid_freertos","commit-date":"2023-09-26T12:09:36Z","current-rev":"f6ca86c3d","filename":"tinyusb/hw/bsp/nrf/family.c","previous-rev":"a7c136c03","commit-title":"tested cdc_msc_hid_freertos with samd51","language":"C","id":"9aa6bf46ecc8de9e66375157db1f153c3928a576","model-score":0.22,"author-id":null,"project-id":37161,"delta-file-score":0.44580856,"diff":"diff --git a/hw/bsp/nrf/family.c b/hw/bsp/nrf/family.c\nindex 6fcfd9476..3620bc8cc 100644\n--- a/hw/bsp/nrf/family.c\n+++ b/hw/bsp/nrf/family.c\n@@ -97,9 +97,4 @@ TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event) {\n #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421\n+static void max3421_init(void);\n static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);\n-\n-void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {\n-  if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;\n-\n-  tuh_int_handler(1);\n-}\n #endif\n@@ -193,46 +188,3 @@ void board_init(void) {\n #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421\n-  // MAX3421 need 3.3v signal (may not be needed)\n-  #if defined(UICR_REGOUT0_VOUT_Msk) && 0\n-  if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {\n-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;\n-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n-\n-    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;\n-\n-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;\n-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n-\n-    NVIC_SystemReset();\n-  }\n-  #endif\n-\n-  // manually manage CS\n-  nrf_gpio_cfg_output(MAX3421_CS_PIN);\n-  nrf_gpio_pin_write(MAX3421_CS_PIN, 1);\n-\n-  // USB host using max3421e usb controller via SPI\n-  nrfx_spim_config_t cfg = {\n-      .sck_pin        = MAX3421_SCK_PIN,\n-      .mosi_pin       = MAX3421_MOSI_PIN,\n-      .miso_pin       = MAX3421_MISO_PIN,\n-      .ss_pin         = NRFX_SPIM_PIN_NOT_USED,\n-      .ss_active_high = false,\n-      .irq_priority   = 3,\n-      .orc            = 0xFF,\n-      // default setting 4 Mhz, Mode 0, MSB first\n-      .frequency      = NRF_SPIM_FREQ_4M,\n-      .mode           = NRF_SPIM_MODE_0,\n-      .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,\n-  };\n-\n-  // no handler --> blocking\n-  nrfx_spim_init(&_spi, &cfg, NULL, NULL);\n-\n-  // max3421e interrupt pin\n-  nrfx_gpiote_init(1);\n-  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);\n-  in_config.pull = NRF_GPIO_PIN_PULLUP;\n-\n-  nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);\n-  nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);\n+  max3421_init();\n #endif\n@@ -319,2 +271,56 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) {\n \n+void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {\n+  if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;\n+  tuh_int_handler(1);\n+}\n+\n+static void max3421_init(void) {\n+  // MAX3421 need 3.3v signal (may not be needed)\n+//  #if defined(UICR_REGOUT0_VOUT_Msk)\n+//  if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {\n+//    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;\n+//    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n+//\n+//    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;\n+//\n+//    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;\n+//    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n+//\n+//    NVIC_SystemReset();\n+//  }\n+//  #endif\n+\n+  // manually manage CS\n+  nrf_gpio_cfg_output(MAX3421_CS_PIN);\n+  nrf_gpio_pin_write(MAX3421_CS_PIN, 1);\n+\n+  // USB host using max3421e usb controller via SPI\n+  nrfx_spim_config_t cfg = {\n+      .sck_pin        = MAX3421_SCK_PIN,\n+      .mosi_pin       = MAX3421_MOSI_PIN,\n+      .miso_pin       = MAX3421_MISO_PIN,\n+      .ss_pin         = NRFX_SPIM_PIN_NOT_USED,\n+      .ss_active_high = false,\n+      .irq_priority   = 3,\n+      .orc            = 0xFF,\n+      // default setting 4 Mhz, Mode 0, MSB first\n+      .frequency      = NRF_SPIM_FREQ_4M,\n+      .mode           = NRF_SPIM_MODE_0,\n+      .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,\n+  };\n+\n+  // no handler --> blocking\n+  nrfx_spim_init(&_spi, &cfg, NULL, NULL);\n+\n+  // max3421e interrupt pin\n+  nrfx_gpiote_init(1);\n+  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);\n+  in_config.pull = NRF_GPIO_PIN_PULLUP;\n+\n+  NVIC_SetPriority(GPIOTE_IRQn, 2);\n+\n+  nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);\n+  nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);\n+}\n+\n void tuh_max3421_int_api(uint8_t rhport, bool enabled) {\n","improvement-type":"Complex Method"}],"change-level":"warning","is-hotspot?":true,"line":936,"what-changed":"handle_epout_dma increases in cyclomatic complexity from 9 to 10, threshold = 9","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"degraded"},{"method":"handle_bus_reset","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the C language is a cyclomatic complexity lower than 9.","name":"Complex Method","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","refactoring-examples":[{"architectural-component-id":null,"author-name":"hathach","training-data":{"loc-added":"56","loc-deleted":"50","delta-cc-mean":"0.0","delta-cc-total":"0","delta-penalties":"1.494","delta-n-functions":"0","current-file-score":"9.6882083290695"},"author-email":"thach@tinyusb.org","commit-full-message":"add -Wno-error=format for espressif\nwrap up cdc_msc_hid_freertos","commit-date":"2023-09-26T12:09:36Z","current-rev":"f6ca86c3d","filename":"tinyusb/hw/bsp/nrf/family.c","previous-rev":"a7c136c03","commit-title":"tested cdc_msc_hid_freertos with samd51","language":"C","id":"9aa6bf46ecc8de9e66375157db1f153c3928a576","model-score":0.22,"author-id":null,"project-id":37161,"delta-file-score":0.44580856,"diff":"diff --git a/hw/bsp/nrf/family.c b/hw/bsp/nrf/family.c\nindex 6fcfd9476..3620bc8cc 100644\n--- a/hw/bsp/nrf/family.c\n+++ b/hw/bsp/nrf/family.c\n@@ -97,9 +97,4 @@ TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event) {\n #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421\n+static void max3421_init(void);\n static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);\n-\n-void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {\n-  if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;\n-\n-  tuh_int_handler(1);\n-}\n #endif\n@@ -193,46 +188,3 @@ void board_init(void) {\n #if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421\n-  // MAX3421 need 3.3v signal (may not be needed)\n-  #if defined(UICR_REGOUT0_VOUT_Msk) && 0\n-  if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {\n-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;\n-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n-\n-    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;\n-\n-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;\n-    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n-\n-    NVIC_SystemReset();\n-  }\n-  #endif\n-\n-  // manually manage CS\n-  nrf_gpio_cfg_output(MAX3421_CS_PIN);\n-  nrf_gpio_pin_write(MAX3421_CS_PIN, 1);\n-\n-  // USB host using max3421e usb controller via SPI\n-  nrfx_spim_config_t cfg = {\n-      .sck_pin        = MAX3421_SCK_PIN,\n-      .mosi_pin       = MAX3421_MOSI_PIN,\n-      .miso_pin       = MAX3421_MISO_PIN,\n-      .ss_pin         = NRFX_SPIM_PIN_NOT_USED,\n-      .ss_active_high = false,\n-      .irq_priority   = 3,\n-      .orc            = 0xFF,\n-      // default setting 4 Mhz, Mode 0, MSB first\n-      .frequency      = NRF_SPIM_FREQ_4M,\n-      .mode           = NRF_SPIM_MODE_0,\n-      .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,\n-  };\n-\n-  // no handler --> blocking\n-  nrfx_spim_init(&_spi, &cfg, NULL, NULL);\n-\n-  // max3421e interrupt pin\n-  nrfx_gpiote_init(1);\n-  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);\n-  in_config.pull = NRF_GPIO_PIN_PULLUP;\n-\n-  nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);\n-  nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);\n+  max3421_init();\n #endif\n@@ -319,2 +271,56 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) {\n \n+void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {\n+  if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;\n+  tuh_int_handler(1);\n+}\n+\n+static void max3421_init(void) {\n+  // MAX3421 need 3.3v signal (may not be needed)\n+//  #if defined(UICR_REGOUT0_VOUT_Msk)\n+//  if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {\n+//    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;\n+//    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n+//\n+//    NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;\n+//\n+//    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;\n+//    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}\n+//\n+//    NVIC_SystemReset();\n+//  }\n+//  #endif\n+\n+  // manually manage CS\n+  nrf_gpio_cfg_output(MAX3421_CS_PIN);\n+  nrf_gpio_pin_write(MAX3421_CS_PIN, 1);\n+\n+  // USB host using max3421e usb controller via SPI\n+  nrfx_spim_config_t cfg = {\n+      .sck_pin        = MAX3421_SCK_PIN,\n+      .mosi_pin       = MAX3421_MOSI_PIN,\n+      .miso_pin       = MAX3421_MISO_PIN,\n+      .ss_pin         = NRFX_SPIM_PIN_NOT_USED,\n+      .ss_active_high = false,\n+      .irq_priority   = 3,\n+      .orc            = 0xFF,\n+      // default setting 4 Mhz, Mode 0, MSB first\n+      .frequency      = NRF_SPIM_FREQ_4M,\n+      .mode           = NRF_SPIM_MODE_0,\n+      .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,\n+  };\n+\n+  // no handler --> blocking\n+  nrfx_spim_init(&_spi, &cfg, NULL, NULL);\n+\n+  // max3421e interrupt pin\n+  nrfx_gpiote_init(1);\n+  nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);\n+  in_config.pull = NRF_GPIO_PIN_PULLUP;\n+\n+  NVIC_SetPriority(GPIOTE_IRQn, 2);\n+\n+  nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);\n+  nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);\n+}\n+\n void tuh_max3421_int_api(uint8_t rhport, bool enabled) {\n","improvement-type":"Complex Method"}],"change-level":"warning","is-hotspot?":true,"line":680,"what-changed":"handle_bus_reset has a cyclomatic complexity of 10, threshold = 9","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"introduced"},{"method":"dcd_int_handler","why-it-occurs":"A complex conditional is an expression inside a branch such as an <code>if</code>-statmeent which consists of multiple, logical operations. Example: <code>if (x.started() && y.running())</code>.Complex conditionals make the code even harder to read, and contribute to the Complex Method code smell. Encapsulate them.","name":"Complex Conditional","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","refactoring-examples":[{"diff":"diff --git a/complex_conditional.js b/complex_conditional.js\nindex c43da09584..94259ce874 100644\n--- a/complex_conditional.js\n+++ b/complex_conditional.js\n@@ -1,16 +1,34 @@\n function messageReceived(message, timeReceived) {\n-   // Ignore all messages which aren't from known customers:\n-   if (!message.sender &&\n-       customers.getId(message.name) == null) {\n+   // Refactoring #1: encapsulate the business rule in a\n+   // function. A clear name replaces the need for the comment:\n+   if (!knownCustomer(message)) {\n      log('spam received -- ignoring');\n      return;\n    }\n \n-  // Provide an auto-reply when outside business hours:\n-  if ((timeReceived.getHours() > 17) ||\n-      (timeReceived.getHours() < 8)) {\n+  // Refactoring #2: encapsulate the business rule.\n+  // Again, note how a clear function name replaces the\n+  // need for a code comment:\n+  if (outsideBusinessHours(timeReceived)) {\n     return autoReplyTo(message);\n   }\n \n   pingAgentFor(message);\n+}\n+\n+function outsideBusinessHours(timeReceived) {\n+  // Refactoring #3: replace magic numbers with\n+  // symbols that communicate with the code reader:\n+  const closingHour = 17;\n+  const openingHour = 8;\n+\n+  const hours = timeReceived.getHours();\n+\n+  // Refactoring #4: simple conditional rules can\n+  // be further clarified by introducing a variable:\n+  const afterClosing = hours > closingHour;\n+  const beforeOpening = hours < openingHour;\n+\n+  // Yeah -- look how clear the business rule is now!\n+  return afterClosing || beforeOpening;\n }\n\\ No newline at end of file\n","language":"c","improvement-type":"Complex Conditional"}],"change-level":"warning","is-hotspot?":true,"line":1151,"what-changed":"dcd_int_handler has 1 complex conditionals with 2 branches, threshold = 2","how-to-fix":"Apply the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring so that the complex conditional is encapsulated in a separate function with a good name that captures the business rule. Optionally, for simple expressions, introduce a new variable which holds the result of the complex conditional.","change-type":"introduced"}]},"positive-impact-count":3,"repo":"tinyusb","code-health":6.212977665039387,"version":"3.0","authors":["HiFiPhile"],"directives":{"added":[],"removed":[]},"positive-findings":{"number-of-types":2,"number-of-files-touched":1,"findings":[{"method":"edpt_disable","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the C language is a cyclomatic complexity lower than 9.","name":"Complex Method","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","change-level":"improvement","is-hotspot?":true,"line":283,"what-changed":"edpt_disable decreases in cyclomatic complexity from 15 to 14, threshold = 9","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"improved"},{"method":"edpt_schedule_packets","why-it-occurs":"A Complex Method has a high cyclomatic complexity. The recommended threshold for the C language is a cyclomatic complexity lower than 9.","name":"Complex Method","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","change-level":"improvement","is-hotspot?":true,"line":335,"what-changed":"edpt_schedule_packets decreases in cyclomatic complexity from 12 to 11, threshold = 9","how-to-fix":"There are many reasons for Complex Method. Sometimes, another design approach is beneficial such as a) modeling state using an explicit state machine rather than conditionals, or b) using table lookup rather than long chains of logic. In other scenarios, the function can be split using [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html). Just make sure you extract natural and cohesive functions. Complex Methods can also be addressed by identifying complex conditional expressions and then using the [DECOMPOSE CONDITIONAL](https://refactoring.com/catalog/decomposeConditional.html) refactoring.","change-type":"improved"},{"method":"handle_rxflvl_irq","why-it-occurs":"Deep nested logic means that you have control structures like if-statements or loops inside other control structures. Deep nested logic increases the cognitive load on the programmer reading the code. The human working memory has a maximum capacity of 3-4 items; beyond that threshold, we struggle with keeping things in our head. Consequently, deep nested logic has a strong correlation to defects and accounts for roughly 20% of all programming mistakes.\n\nCodeScene measures the maximum nesting depth inside each function. The deeper the nesting, the lower the code health. The threshold for the C language is  levels of nesting.","name":"Deep, Nested Complexity","file":"src/portable/synopsys/dwc2/dcd_dwc2.c","change-level":"improvement","is-hotspot?":true,"line":764,"what-changed":"handle_rxflvl_irq is no longer above the threshold for nested complexity depth","how-to-fix":"Occassionally, it's possible to get rid of the nested logic by [Replacing Conditionals with Guard Clauses](https://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html).\n\nAnother viable strategy is to identify smaller building blocks inside the nested chunks of logic and extract those responsibilities into smaller, cohesive, and well-named functions. The [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html) refactoring explains the steps.","change-type":"fixed"}]},"notices":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"external-review-provider":"GitHub"},"analysistime":"2025-10-30T21:40:53.000Z","project-name":"tinyusb","repository":"https://github.com/hathach/tinyusb.git"}}