0002-add-sensor-ctrls.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. From a3756db6257742587da7e97546aa330ad363bfd1 Mon Sep 17 00:00:00 2001
  2. From: sw.multimedia <sw.multimedia@starfivetech.com>
  3. Date: Tue, 26 Oct 2021 12:29:30 +0800
  4. Subject: [PATCH 02/10] add sensor ctrls
  5. ---
  6. src/libcamera/pipeline/starfive/starfive.cpp | 118 ++++++++++++++++---
  7. 1 file changed, 99 insertions(+), 19 deletions(-)
  8. diff --git a/src/libcamera/pipeline/starfive/starfive.cpp b/src/libcamera/pipeline/starfive/starfive.cpp
  9. index 8797bdcb..f63af910 100644
  10. --- a/src/libcamera/pipeline/starfive/starfive.cpp
  11. +++ b/src/libcamera/pipeline/starfive/starfive.cpp
  12. @@ -370,7 +370,7 @@ public:
  13. bool match(DeviceEnumerator *enumerator) override;
  14. private:
  15. - int processControls(StarFiveCameraData *data, Request *request);
  16. + int processControls(StarFiveCameraData *data, const ControlList &controls);
  17. StarFiveCameraData *cameraData(Camera *camera)
  18. {
  19. @@ -620,6 +620,13 @@ int PipelineHandlerStarFive::start(Camera *camera, const ControlList *controls)
  20. LOG(STARFIVE, Debug) << __func__ << " bufferCount: " << count;
  21. + if (controls != nullptr) {
  22. + ret = processControls(data, *controls);
  23. + if (ret < 0)
  24. + return ret;
  25. + } else
  26. + LOG(STARFIVE, Debug) << __func__ << " start no controls";
  27. +
  28. ret = data->video_->importBuffers(count);
  29. if (ret < 0)
  30. return ret;
  31. @@ -672,43 +679,116 @@ void PipelineHandlerStarFive::stop(Camera *camera)
  32. }
  33. }
  34. -int PipelineHandlerStarFive::processControls(StarFiveCameraData *data, Request *request)
  35. +int PipelineHandlerStarFive::processControls(StarFiveCameraData *data, const ControlList &controls)
  36. {
  37. - LOG(STARFIVE, Debug) << __func__;
  38. + LOG(STARFIVE, Debug) << __func__ << ": test1 controls";
  39. + const ControlInfoMap &SensorControlsInfoMap = data->sensor_->controls();
  40. + ControlList SensorControls(SensorControlsInfoMap);
  41. - ControlList controls(data->sensor_->controls());
  42. -
  43. - for (auto it : request->controls()) {
  44. + for (auto it : controls) {
  45. unsigned int id = it.first;
  46. - unsigned int offset;
  47. - uint32_t cid;
  48. + unsigned int offset = 0;
  49. + uint32_t cid = 0;
  50. + int32_t value = 0;
  51. - if (id == controls::Brightness) {
  52. + switch (id) {
  53. + case controls::BRIGHTNESS:
  54. cid = V4L2_CID_BRIGHTNESS;
  55. offset = 128;
  56. - } else if (id == controls::Contrast) {
  57. + value = lroundf(it.second.get<float>() * 128 + offset);
  58. + LOG(STARFIVE, Debug) << "Brightness controls: " << id
  59. + << ", value: " << value;
  60. + break;
  61. + case controls::CONTRAST:
  62. cid = V4L2_CID_CONTRAST;
  63. offset = 0;
  64. - } else if (id == controls::Saturation) {
  65. + value = lroundf(it.second.get<float>() * 128 + offset);
  66. + LOG(STARFIVE, Debug) << "Contrast controls: " << id
  67. + << ", value: " << value;
  68. + break;
  69. + case controls::SATURATION:
  70. cid = V4L2_CID_SATURATION;
  71. offset = 0;
  72. - } else {
  73. - continue;
  74. + value = lroundf(it.second.get<float>() * 128 + offset);
  75. + LOG(STARFIVE, Debug) << "Saturation controls: " << id
  76. + << ", value: " << value;
  77. + break;
  78. + case controls::SHARPNESS:
  79. + cid = V4L2_CID_SHARPNESS;
  80. + offset = 0;
  81. + value = lroundf(it.second.get<float>() * 128 + offset);
  82. + LOG(STARFIVE, Debug) << "Sharpness controls: " << id
  83. + << ", value: " << value;
  84. + break;
  85. + case controls::COLOUR_GAINS:
  86. + cid = V4L2_CID_RED_BALANCE;
  87. + offset = 0;
  88. + value = lroundf(it.second.get<Span<const float>>()[0]);
  89. + LOG(STARFIVE, Debug) << "ColourGains controls: " << id
  90. + << ", COLOUR_GAINS RED value: " << value;
  91. + if (SensorControlsInfoMap.find(cid) != SensorControlsInfoMap.end())
  92. + SensorControls.set(cid, value);
  93. + else
  94. + LOG(STARFIVE, Debug)
  95. + << "SensorControls not supported controls: " << id;
  96. + cid = V4L2_CID_BLUE_BALANCE;
  97. + value = lroundf(it.second.get<Span<const float>>()[1]);
  98. + LOG(STARFIVE, Debug) << "COLOUR_GAINS BLUE value: " << value;
  99. + break;
  100. + case controls::AWB_ENABLE:
  101. + cid = V4L2_CID_AUTO_WHITE_BALANCE;
  102. + value = it.second.get<bool>();
  103. + LOG(STARFIVE, Debug) << "AwbMode controls: " << id
  104. + << ", value: " << value;
  105. + break;
  106. + case controls::EXPOSURE_VALUE:
  107. + cid = V4L2_CID_EXPOSURE;
  108. + offset = 0;
  109. + value = lroundf(it.second.get<float>());
  110. + LOG(STARFIVE, Debug) << "ExposureValue controls: " << id
  111. + << ", value: " << value;
  112. + break;
  113. + case controls::AE_ENABLE:
  114. + cid = V4L2_CID_EXPOSURE_AUTO;
  115. + value = it.second.get<bool>();
  116. + LOG(STARFIVE, Debug) << "AeExposureMode controls: " << id
  117. + << ", value: " << value;
  118. + break;
  119. + case controls::ANALOGUE_GAIN:
  120. + cid = V4L2_CID_ANALOGUE_GAIN;
  121. + offset = 0;
  122. + value = lroundf(it.second.get<float>());
  123. + LOG(STARFIVE, Debug) << "AnalogueGain controls: " << id
  124. + << ", value: " << value;
  125. + break;
  126. + case controls::DIGITAL_GAIN:
  127. + cid = V4L2_CID_GAIN;
  128. + offset = 0;
  129. + value = lroundf(it.second.get<float>());
  130. + LOG(STARFIVE, Debug) << "AnalogueGain controls: " << id
  131. + << ", value: " << value;
  132. + break;
  133. + default:
  134. + LOG(STARFIVE, Debug) << "default controls: " << id;
  135. + break;
  136. }
  137. - int32_t value = lroundf(it.second.get<float>() * 128 + offset);
  138. - controls.set(cid, std::clamp(value, 0, 255));
  139. + if (SensorControlsInfoMap.find(cid) != SensorControlsInfoMap.end())
  140. + SensorControls.set(cid, value);
  141. + else
  142. + LOG(STARFIVE, Debug) << "SensorControls not supported controls: " << id;
  143. +
  144. }
  145. - for (const auto &ctrl : controls)
  146. + for (const auto &ctrl : SensorControls)
  147. LOG(STARFIVE, Debug)
  148. << "Setting control " << utils::hex(ctrl.first)
  149. << " to " << ctrl.second.toString();
  150. - int ret = data->sensor_->setControls(&controls);
  151. + int ret = data->sensor_->setControls(&SensorControls);
  152. if (ret) {
  153. LOG(STARFIVE, Debug)
  154. - << "Failed to set controls: " << ret;
  155. + << "Failed to set sensor controls: " << ret;
  156. return ret < 0 ? ret : -EINVAL;
  157. }
  158. @@ -721,7 +801,7 @@ int PipelineHandlerStarFive::queueRequestDevice(Camera *camera, Request *request
  159. int error = 0;
  160. LOG(STARFIVE, Debug) << __func__;
  161. - int ret = processControls(data, request);
  162. + int ret = processControls(data, request->controls());
  163. if (ret < 0)
  164. return ret;
  165. --
  166. 2.25.1