{"results":{"result":{"added-files":{"code-health":0.0,"old-code-health":0.0,"files":[]},"external-review-url":"https://github.com/hathach/tinyusb/pull/3294","old-code-health":8.901123350601177,"modified-files":{"code-health":8.886460767914887,"old-code-health":8.901123350601177,"files":[{"file":"hw/bsp/lpc55/family.c","loc":205,"old-loc":181,"code-health":9.457298154557076,"old-code-health":9.581652546385712},{"file":"src/portable/ohci/ohci.c","loc":489,"old-loc":485,"code-health":8.64715266104035,"old-code-health":8.64715266104035}]},"removed-files":{"code-health":0.0,"old-code-health":0.0,"files":[]},"external-review-id":"3294","analysis-time":"2025-10-30T07:52:22Z","negative-impact-count":1,"suppressions":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"affected-hotspots":0,"commits":["83baf13dcbde66942419c03348cc88ef22575e32","88305b1b34160b4548609b78807be910944856ab","3f1f7140c4ad1991c8c1bf73a0864414da68a40d"],"is-negative-review":true,"negative-findings":{"number-of-types":1,"number-of-files-touched":1,"findings":[{"method":"board_init","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":"hw/bsp/lpc55/family.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?":false,"line":138,"what-changed":"board_init has a cyclomatic complexity of 9, 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"}]},"positive-impact-count":1,"repo":"tinyusb","code-health":8.886460767914887,"version":"3.0","authors":["hathach"],"directives":{"added":[],"removed":[]},"positive-findings":{"number-of-types":1,"number-of-files-touched":1,"findings":[{"method":"board_init","why-it-occurs":"Overly long functions make the code harder to read. The recommended maximum function length for the C language is 70 lines of code. Severity: Brain Method - Complex Method - Long Method.","name":"Large Method","file":"hw/bsp/lpc55/family.c","change-level":"improvement","is-hotspot?":false,"line":137,"what-changed":"board_init is no longer above the threshold for lines of code","how-to-fix":"We recommend to be careful here -- just splitting long functions don't necessarily make the code easier to read. Instead, look for natural chunks inside the functions that expresses a specific task or concern. Often, such concerns are indicated by a Code Comment followed by an if-statement. Use the [EXTRACT FUNCTION](https://refactoring.com/catalog/extractFunction.html) refactoring to encapsulate that concern.","change-type":"fixed"}]},"notices":{"number-of-types":0,"number-of-files-touched":0,"findings":[]},"external-review-provider":"GitHub"},"analysistime":"2025-10-30T07:52:22.000Z","project-name":"tinyusb","repository":"https://github.com/hathach/tinyusb.git"}}