new file mode 100644
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2025, matthias.fend@emfend.at
+ *
+ * Flash controls helpers for pipeline handlers
+ */
+
+#pragma once
+
+#include <libcamera/controls.h>
+
+#include "libcamera/internal/camera_flash.h"
+
+namespace libcamera {
+
+class FlashControl
+{
+public:
+ static void updateFlashControls(CameraFlash *flash, ControlInfoMap::Map &controls);
+ static void handleFlashControls(CameraFlash *flash, ControlList &controls, ControlList &metadata);
+};
+
+} /* namespace libcamera */
new file mode 100644
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2025, matthias.fend@emfend.at
+ *
+ * Flash controls helpers for pipeline handlers
+ */
+
+#include "libcamera/internal/flash_control.h"
+
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
+
+namespace libcamera {
+
+void FlashControl::updateFlashControls(CameraFlash *flash, ControlInfoMap::Map &controls)
+{
+ if (!flash)
+ return;
+
+ controls[&controls::draft::FlashMode] = ControlInfo(controls::draft::FlashModeValues, controls::draft::FlashModeNone);
+ controls[&controls::draft::FlashIntensity] = flash->getFlashIntensityInfo();
+ controls[&controls::draft::FlashTimeout] = flash->getFlashTimeoutInfo();
+ controls[&controls::draft::FlashStrobeSource] = ControlInfo(controls::draft::FlashStrobeSourceValues, controls::draft::FlashStrobeSourceSoftware);
+ controls[&controls::draft::FlashStrobe] = ControlInfo(controls::draft::FlashStrobeValues);
+ controls[&controls::draft::FlashTorchIntensity] = flash->getTorchIntensityInfo();
+}
+
+void FlashControl::handleFlashControls(CameraFlash *flash, ControlList &controls, ControlList &metadata)
+{
+ if (!flash)
+ return;
+
+ const auto &flashMode = controls.get(controls::draft::FlashMode);
+ if (flashMode) {
+ CameraFlash::Mode mode;
+
+ switch (*flashMode) {
+ case controls::draft::FlashModeFlash:
+ mode = CameraFlash::Mode::Flash;
+ break;
+ case controls::draft::FlashModeTorch:
+ mode = CameraFlash::Mode::Torch;
+ break;
+ case controls::draft::FlashModeNone:
+ default:
+ mode = CameraFlash::Mode::None;
+ break;
+ }
+
+ flash->setMode(mode);
+ }
+
+ const auto &flashIntensity = controls.get<int32_t>(controls::draft::FlashIntensity);
+ if (flashIntensity)
+ flash->setFlashIntensity(*flashIntensity);
+
+ const auto &flashTimeout = controls.get<int32_t>(controls::draft::FlashTimeout);
+ if (flashTimeout)
+ flash->setFlashTimeout(*flashTimeout);
+
+ const auto &flashStrobeSource = controls.get(controls::draft::FlashStrobeSource);
+ if (flashStrobeSource) {
+ CameraFlash::StrobeSource source;
+
+ switch (*flashStrobeSource) {
+ case controls::draft::FlashStrobeSourceExternal:
+ source = CameraFlash::StrobeSource::External;
+ break;
+ case controls::draft::FlashStrobeSourceSoftware:
+ default:
+ source = CameraFlash::StrobeSource::Software;
+ break;
+ }
+
+ flash->setStrobeSource(source);
+ }
+
+ const auto &flashStrobe = controls.get(controls::draft::FlashStrobe);
+ if (flashStrobe) {
+ switch (*flashStrobe) {
+ case controls::draft::FlashStrobeEnum::FlashStrobeStart:
+ flash->startStrobe();
+ break;
+ case controls::draft::FlashStrobeEnum::FlashStrobeStop:
+ flash->stopStrobe();
+ break;
+ default:
+ break;
+ }
+ }
+
+ const auto &flashTorchIntensity = controls.get<int32_t>(controls::draft::FlashTorchIntensity);
+ if (flashTorchIntensity)
+ flash->setTorchIntensity(*flashTorchIntensity);
+
+ metadata.set(controls::draft::FlashMode, flash->getMode());
+ metadata.set(controls::draft::FlashIntensity, flash->getFlashIntensity());
+ metadata.set(controls::draft::FlashTimeout, flash->getFlashTimeout());
+ metadata.set(controls::draft::FlashStrobeSource, flash->getStrobeSource());
+ metadata.set(controls::draft::FlashTorchIntensity, flash->getTorchIntensity());
+}
+
+} /* namespace libcamera */
@@ -31,6 +31,7 @@ libcamera_internal_sources = files([
'device_enumerator.cpp',
'device_enumerator_sysfs.cpp',
'dma_buf_allocator.cpp',
+ 'flash_control.cpp',
'formats.cpp',
'ipa_controls.cpp',
'ipa_data_serializer.cpp',
Add a set of helpers that pipeline handlers can use to deal with camera flash devices. This mainly involves mapping controls to the flash device and vice versa. Signed-off-by: Matthias Fend <matthias.fend@emfend.at> --- include/libcamera/internal/flash_control.h | 23 +++++++ src/libcamera/flash_control.cpp | 103 +++++++++++++++++++++++++++++ src/libcamera/meson.build | 1 + 3 files changed, 127 insertions(+)