zmk driver for PIXART PAW3222 optical sensor
0

Configure Feed

Select the types of activity you want to include in your feed.

Improve device readiness checks and adjust power initialization delays

+26 -10
+26 -10
src/paw3222.c
··· 319 319 const struct paw32xx_config *cfg = dev->config; 320 320 uint8_t val; 321 321 int ret; 322 + int retry_count = 10; 322 323 323 - ret = paw32xx_read_reg(dev, PAW32XX_PRODUCT_ID1, &val); 324 - if (ret < 0) { 325 - return ret; 326 - } 324 + // Check if the device is ready 325 + while (retry_count--) { 326 + ret = paw32xx_read_reg(dev, PAW32XX_PRODUCT_ID1, &val); 327 + if (ret < 0) { 328 + if (retry_count == 0) { 329 + return ret; 330 + } 331 + k_sleep(K_MSEC(100)); // Wait before retrying 332 + continue; 333 + } 327 334 328 - if (val != PRODUCT_ID_PAW32XX) { 329 - LOG_ERR("Invalid product id: %02x", val); 330 - return -ENOTSUP; 335 + if (val != PRODUCT_ID_PAW32XX) { 336 + LOG_ERR("Invalid product id: %02x", val); 337 + 338 + if (retry_count == 0) { 339 + return -ENODEV; // Device not ready after retries 340 + } 341 + k_sleep(K_MSEC(100)); // Wait before retrying 342 + continue; 343 + } 344 + else { 345 + break; // Device is ready 346 + } 331 347 } 332 348 333 349 ret = paw32xx_update_reg(dev, PAW32XX_CONFIGURATION, CONFIGURATION_RESET, CONFIGURATION_RESET); ··· 372 388 return ret; 373 389 } 374 390 375 - // Wait 0.5 seconds before turning on power 376 - k_sleep(K_MSEC(500)); 391 + // Wait 0.01 seconds before turning on power 392 + k_sleep(K_MSEC(10)); 377 393 378 394 // Now turn on power 379 395 ret = gpio_pin_set_dt(&cfg->power_gpio, 1); ··· 383 399 } 384 400 385 401 // Wait for power stabilization 386 - k_sleep(K_MSEC(10)); 402 + k_sleep(K_MSEC(500)); 387 403 } 388 404 #endif 389 405