diff --git a/README.md b/README.md index f053c30..21c0f4a 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,11 @@ USB webcam (the board presenting as UVC) lives in [`usbif`](https://github.com/PyDevices/usbif)'s `examples/usbif_webcam.py`, which sources frames from this module when a camera is present. -Known hole: [`available()` always returns True](https://github.com/PyDevices/cameraif/issues/1). +`available()` answers whether this firmware can open a camera at all: it is +true when at least one `esp_cam_sensor` driver was linked in, and false on a +build with no `CONFIG_CAMERA_` enabled and on every non-P4 target. It +does not say whether a sensor is plugged in -- that is what constructing a +`Camera` tells you, with a message. ## Performance, measured diff --git a/src/mod_cameraif.c b/src/mod_cameraif.c index b1c9ad2..15291ac 100644 --- a/src/mod_cameraif.c +++ b/src/mod_cameraif.c @@ -1321,8 +1321,26 @@ static MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &cameraif_locals_dict ); +// A probe that cannot fail is not a probe. Reaching this branch already means +// the firmware was built for a target with a MIPI-CSI controller, so what is +// left to ask is whether any sensor driver was linked into it: esp_cam_sensor +// drivers register themselves in the detect section walked by the open path +// above, and with no CONFIG_CAMERA_ (plus its AUTO_DETECT option) the +// section is empty and no camera can ever be found on a perfectly good bus. +// +// That is not hypothetical. It is exactly the state a P4 build lands in when +// the option is missed, and this module then reports it as "no camera sensor +// answered on SCCB" -- a wiring-shaped error for a build-configuration cause, +// which is the confusion micropython.cmake's note was written about and which +// this function exists to end. +// +// It deliberately does NOT touch the bus. available() is asked before any pins +// are known -- board_peripherals calls it before it passes sda/scl -- so it +// could not probe honestly even if it wanted to, and "is a sensor plugged in" +// is already answered, with a message, by constructing a Camera. static mp_obj_t cameraif_available(void) { - return mp_const_true; + return mp_obj_new_bool(&__esp_cam_sensor_detect_fn_array_start + < &__esp_cam_sensor_detect_fn_array_end); } static MP_DEFINE_CONST_FUN_OBJ_0(cameraif_available_obj, cameraif_available);