6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Thu Feb 16, 2017 4:35 pm

Kozuch wrote:I see that the flash driver is probably more sophisticated that what I thought it is... So there is no simple way of how to only output the hw sync signal without messing any of the AE and other stuff? I wont be actually using the flash physically at all (my scene will be outdoors, well lit, or too far away...).
No, it's designed as a flash driver, not a "random trigger pulse" driver.
Kozuch wrote:You say there are multiple pulses? How many and what do they mean? If I knew this I can probably filter these on my logger (which will be another RPi - I can sample GPIOs quite fast, right?) How long are the pulses? Can the preflash be disabled?
2 pulses.
The flash cycle requires a frame without flash and frame with preflash to compute how much difference the flash made to the scene, and with that it computes the flash intensity (fixed in this case), shutter speed, and gains to use for the capture. Being a rolling shutter camera you can't turn the flash on and correctly expose on a simple frame boundary, so there is an extra frame required. So you're looking at normally 3 frames total for the preflash sequence, with the pulse being approx 2 exposure times.
The flash pulse for the main capture should be an exposure time + a frame readout time.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Kozuch
Posts: 64
Joined: Sun Aug 10, 2014 10:35 am

Re: Camera flash driver released

Sat Feb 18, 2017 6:14 pm

Thanks for reply again!

I see you would probably dont like to see the driver "being abused" for other things :) but from what I read I get the expression that it may be usable for me actually... because if I do not use flash there will be no difference on 1st and 2nd frame (preflash) and the AE should meter correctly for such scenario (thinking that the flash is too weak to be noticed at all)? Can you agree with this?

Also regarding general driver operation - once the GPIO pins are set by updating the VideoCore device tree blob than the GPIOs are live regardless of how the camera is used (picamera, raspistill ...)? Also you say indicator/privacy light GPIO goes on AFTER exposure - do you know more precise timing? Is this same as CAPTURE_STARTED (edit: I meant CAPTURE_ENDED) event? Also, can the privacy light be used WITHOUT flash (I suppose so once you enable the indicator GPIO only)?

Before I found this flash driver I was also about to ask about if it is possible to detect the exposure moment from software (meaning raspistill.c)... I see you told sinc about the various MMAL events above - considering this type of detection (besides the flash driver) what is the best precision that can be achieved with these events? I want to go very low (goal is usec level). You say CAPTURE_ENDED has a 30 ms delay - way too long for me. What about using CAPTURE_STARTED with realtime Linux kernel?

PS. My reply lags because I have not gotten email notification for your second post...
Last edited by Kozuch on Mon Feb 20, 2017 1:50 pm, edited 1 time in total.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Mon Feb 20, 2017 11:31 am

When you start working 24 hours a day, 7 days a week, then feel free to start demanding responses to threads at weekends.
You posted this at 6pm Saturday evening GMT. A private message 11am Sunday morning is an unreasonable demand, and particularly as my sig includes the line "Please don't send PMs asking for support - use the forum.". You then also felt the need to request an update via an unrelated thread.

I may respond to some threads in the evening or over the weekend, but don't take that as any obligation on my part.
Technically forum support isn't even part of my job.
One person so far has ended up on my "foes list" so all their posts get hidden. Be reasonable or you are likely to end up there too.
Kozuch wrote:I see you would probably dont like to see the driver "being abused" for other things :) but from what I read I get the expression that it may be usable for me actually... because if I do not use flash there will be no difference on 1st and 2nd frame (preflash) and the AE should meter correctly for such scenario (thinking that the flash is too weak to be noticed at all)? Can you agree with this?
Probably.
Kozuch wrote:Also regarding general driver operation - once the GPIO pins are set by updating the VideoCore device tree blob than the GPIOs are live regardless of how the camera is used (picamera, raspistill ...)?
Define "live". They'll be configured as outputs so driven high or low based on whatever the driver last told it to do.
Kozuch wrote:Also you say indicator/privacy light GPIO goes on AFTER exposure - do you know more precise timing? Is this same as CAPTURE_STARTED event? Also, can the privacy light be used WITHOUT flash (I suppose so once you enable the indicator GPIO only)?
Yes, privacy light can be used without the flash. It is delayed so that the indiicator doesn't affect the captured frame. IIRC Timing is when the first lines of output have been produced, but I'm not going to bother following the code through.
Kozuch wrote:Before I found this flash driver I was also about to ask about if it is possible to detect the exposure moment from software (meaning raspistill.c)... I see you told sinc about the various MMAL events above - considering this type of detection (besides the flash driver) what is the best precision that can be achieved with these events? I want to go very low (goal is usec level). You say CAPTURE_ENDED has a 30 ms delay - way too long for me. What about using CAPTURE_STARTED with realtime Linux kernel?
usec is crazy resolution. 100mph = 44.7m/s, so even if you're 100ms out you'll be looking at 4.4m. The rolling shutter smears your capture over 66ms, so that's 3m. If you're moving then anything is going to be out. If you're not moving then that level of accuracy doesn't matter.

CAPTURE_STARTED is just after the request is made to the camera pipeline, so probably around 40ms early.
There is no signal that is more accurate. There is something that may help, but it's not a priority so don't pester over it.

Next topic - this one has gone crazy.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Kozuch
Posts: 64
Joined: Sun Aug 10, 2014 10:35 am

Re: Camera flash driver released

Sat Feb 25, 2017 9:21 pm

Is the flash driver working with the new v2 camera board?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Sun Feb 26, 2017 8:50 am

Kozuch wrote:Is the flash driver working with the new v2 camera board?
It should be sensor independent.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

thegnnu
Posts: 157
Joined: Thu Oct 18, 2012 7:07 pm
Location: Bristol

Re: Camera flash driver released

Tue Mar 21, 2017 9:30 pm

wofwof42 wrote:This made it work. Many thanks! Here is a patch to RaspiStill.c for anyone else interested:

Code: Select all

--- a/host_applications/linux/apps/raspicam/RaspiStill.c
+++ b/host_applications/linux/apps/raspicam/RaspiStill.c
@@ -150,6 +150,8 @@ typedef struct
 
    RASPITEX_STATE raspitex_state; /// GL renderer state and parameters
 
+   MMAL_PARAM_FLASH_T flash; /// Flash mode
+
 } RASPISTILL_STATE;


 
 /** Struct used to pass information in encoder port userdata to callback
@@ -187,6 +189,7 @@ static void store_exif_tag(RASPISTILL_STATE *state, const char *exif_tag);
 #define CommandSettings     19
 #define CommandCamSelect    20
 #define CommandBurstMode    21
+#define CommandFlashMode    22
 
 static COMMAND_LIST cmdline_commands[] =
 {
@@ -212,6 +215,7 @@ static COMMAND_LIST cmdline_commands[] =
    { CommandSettings, "-settings",  "set","Retrieve camera settings and write to stdout", 0},
    { CommandCamSelect, "-camselect","cs", "Select camera <number>. Default 0", 1 },
    { CommandBurstMode, "-burst",    "bm", "Enable 'burst capture mode'", 0},   
+   { CommandFlashMode, "-flash",    "fl", "Flash mode to use (off, auto, on, redeye, fillin, torch)", 1},
 };
 
 static int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0]);
@@ -247,6 +251,22 @@ static struct
 
 static int next_frame_description_size = sizeof(next_frame_description) / sizeof(next_frame_description[0]);
 
+static struct
+{
+  const char *name;
+  MMAL_PARAM_FLASH_T mode;
+} flash_modes[] =
+{
+  {"off", MMAL_PARAM_FLASH_OFF},
+  {"auto", MMAL_PARAM_FLASH_AUTO},
+  {"on", MMAL_PARAM_FLASH_ON},
+  {"redeye", MMAL_PARAM_FLASH_REDEYE},
+  {"fillin", MMAL_PARAM_FLASH_FILLIN},
+  {"torch", MMAL_PARAM_FLASH_TORCH},
+};
+
+static int flash_modes_size = sizeof(flash_modes) / sizeof(flash_modes[0]);
+
 /**
  * Assign a default set of parameters to the state passed in
  *
@@ -290,6 +310,7 @@ static void default_status(RASPISTILL_STATE *state)
    state->settings = 0;
    state->cameraNum = 0;
    state->burstCaptureMode=0;
+   state->flash = MMAL_PARAM_FLASH_OFF;
 
    // Setup preview window defaults
    raspipreview_set_defaults(&state->preview_parameters);
@@ -622,6 +643,28 @@ static int parse_cmdline(int argc, const char **argv, RASPISTILL_STATE *state)
          state->burstCaptureMode=1;
          break;
 
+      case CommandFlashMode :
+      {
+         int len = strlen(argv[i + 1]);
+         valid = 0;
+
+         if (len)
+         {
+            int j;
+            for (j = 0;j < flash_modes_size;j++)
+            {
+               if (strcmp(argv[i + 1], flash_modes[j].name) == 0)
+               {
+                  state->flash = flash_modes[j].mode;
+                  valid = 1;
+                  i++;
+                  break;
+               }
+            }
+         }
+         break;
+      }
+
       default:
       {
          // Try parsing for any image specific parameters
@@ -1852,6 +1895,21 @@ int main(int argc, const char **argv)
                      mmal_port_parameter_set_boolean(state.camera_component->control,  MMAL_PARAMETER_CAMERA_BURST_CAPTURE, 1);
                   }
 
+                  if (state.flash != MMAL_PARAM_FLASH_OFF)
+                  {
+                     if (state.verbose)
+                        fprintf(stderr, "Enabling flash mode %x\n", state.flash);
+
+                     MMAL_PARAMETER_FLASH_T camera_flash = {{MMAL_PARAMETER_FLASH, sizeof(MMAL_PARAMETER_FLASH_T)}, state.flash};
+
+                     status = mmal_port_parameter_set(state.camera_component->control, &camera_flash.hdr);
+                     if (status != MMAL_SUCCESS)
+                     {
+                        vcos_log_error("Could not set camera flash : error %d", status);
+                        goto error;
+                     }
+                  }
+
                   if (state.verbose)
                      fprintf(stderr, "Starting capture %d\n", frame);
 
For me only two flash modes seem to actually do anything: ON and TORCH.
Has anybody got this patch to work as I am getting a few line error just wondered as it is over 2 years old if it would still work
would like to get the flash command working in raspistill.
TerryR

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Tue Mar 21, 2017 10:28 pm

thegnnu wrote:Has anybody got this patch to work as I am getting a few line error just wondered as it is over 2 years old if it would still work
would like to get the flash command working in raspistill.
Have you also made the necessary dt-blob.bin changes?
Scratch that, you had the other thread where you had it working from PiCamera.
I'll try to test it out tomorrow to validate your patch.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

hen
Posts: 11
Joined: Tue Apr 11, 2017 8:39 am

Re: Camera flash driver released

Tue Apr 11, 2017 10:38 am

Hi all,
thegnnu wrote:Has anybody got this patch to work as I am getting a few line error just wondered as it is over 2 years old if it would still work
would like to get the flash command working in raspistill.
On my compute module I've patched and recompiled latest version of raspistill and it seems to work, but I've not yet attached a real flash LED to the board, only a low power red LED to test the GPIOs.
6by9 wrote:I'll try to test it out tomorrow to validate your patch.
Maybe it's my mistake, but on a dual camera setup, regardless of what camera I am using, I see flashing the LED assigned to camera 0.
On dt-blob, I've assigned flash GPIOs as follows:

Code: Select all

            [email protected]_0_ENABLE {
               type = "internal";
               number = <38>;
            };
            [email protected]_0_INDICATOR {
               type = "absent";
            };
            [email protected]_1_ENABLE {
               type = "internal";
               number = <39>;
            };
            [email protected]_1_INDICATOR {
               type = "absent";
            };

With this configuration, it seems that the flash driver uses GPIO38 for both cams.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Tue Apr 11, 2017 1:15 pm

hen wrote:
thegnnu wrote:Has anybody got this patch to work as I am getting a few line error just wondered as it is over 2 years old if it would still work
would like to get the flash command working in raspistill.
On my compute module I've patched and recompiled latest version of raspistill and it seems to work, but I've not yet attached a real flash LED to the board, only a low power red LED to test the GPIOs.
6by9 wrote:I'll try to test it out tomorrow to validate your patch.
Maybe it's my mistake, but on a dual camera setup, regardless of what camera I am using, I see flashing the LED assigned to camera 0.
On dt-blob, I've assigned flash GPIOs as follows:

Code: Select all

            [email protected]_0_ENABLE {
               type = "internal";
               number = <38>;
            };
            [email protected]_0_INDICATOR {
               type = "absent";
            };
            [email protected]_1_ENABLE {
               type = "internal";
               number = <39>;
            };
            [email protected]_1_INDICATOR {
               type = "absent";
            };

With this configuration, it seems that the flash driver uses GPIO38 for both cams.
That is possible. The simple answer is I can't remember where the code ended up with regard assigning flashes to camera devices - on a mobile phone a front flash is almost unheard of, and that is where most of this code base has come from.
You'll have to give me a few days to find time to investigate.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

hen
Posts: 11
Joined: Tue Apr 11, 2017 8:39 am

Re: Camera flash driver released

Tue Apr 11, 2017 3:41 pm

6by9 wrote:on a mobile phone a front flash is almost unheard of, and that is where most of this code base has come from.
You'll have to give me a few days to find time to investigate.
Thank you 6by9,

I'm developing a stereo camera with a single LED flash, so for a coincidence, actual behavior is what I was looking for... ;)
Not knowing what should be the flash driver behavior when using two cams in stereo mode, I was thinking to create the flash drive signal by ORing FLASH_0_ENABLE and FLASH_1_ENABLE gpios, "just to be sure". Does this make any sense?

Out of curiosity: what should happen if I configure the same GPIO for both FLASH_0_ENABLE and FLASH_1_ENABLE?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Tue Apr 11, 2017 3:49 pm

hen wrote:I'm developing a stereo camera with a single LED flash, so for a coincidence, actual behavior is what I was looking for... ;)
Not knowing what should be the flash driver behavior when using two cams in stereo mode, I was thinking to create the flash drive signal by ORing FLASH_0_ENABLE and FLASH_1_ENABLE gpios, "just to be sure". Does this make any sense?
No, just drive your flash off FLASH_0_ENABLE.
You're going to be using LED illumination as it is a rolling shutter camera, so the flash is on for around 2 frame periods, and the exposure of the two sensors should be within about a millisecond, so good enough for most purposes.
With the stereo camera stack code using both cameras simultaneously from one camera component instance I would only expect a single instance of the flash driver to be opened anyway. The other is likely to be ignored.
hen wrote:Out of curiosity: what should happen if I configure the same GPIO for both FLASH_0_ENABLE and FLASH_1_ENABLE?
Whichever flash driver issued a GPIO state change last would be setting the state. There's no software arbitration or reference counting between them because it's a situation that makes little sense.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

hen
Posts: 11
Joined: Tue Apr 11, 2017 8:39 am

Re: Camera flash driver released

Tue Apr 11, 2017 4:23 pm

6by9 wrote:With the stereo camera stack code using both cameras simultaneously from one camera component instance I would only expect a single instance of the flash driver to be opened anyway. The other is likely to be ignored.
OK, thank you! So I can avoid that extra circuitry.

P.S. Just to avoid confusion, when I found the issue I was talking in my first post (about both cameras driving the same flash GPIO) I was testing cameras one by one, using "-cs" option.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7443
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera flash driver released

Tue Apr 11, 2017 4:26 pm

hen wrote:
6by9 wrote:With the stereo camera stack code using both cameras simultaneously from one camera component instance I would only expect a single instance of the flash driver to be opened anyway. The other is likely to be ignored.
OK, thank you! So I can avoid that extra circuitry.

P.S. Just to avoid confusion, when I found the issue I was talking in my first post (about both cameras driving the same flash GPIO) I was testing cameras one by one, using "-cs" option.
Yes I realise that, but if that isn't your prime use case then there's little point in me investigating it and fixing it.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

hen
Posts: 11
Joined: Tue Apr 11, 2017 8:39 am

Re: Camera flash driver released

Tue Apr 11, 2017 4:54 pm

6by9 wrote:Yes I realise that, but if that isn't your prime use case then there's little point in me investigating it and fixing it.
I agree. As I said, I'm more than happy with actual behavior... :D
Thanks again!

Return to “Camera board”