From 8bacaef950acdee06b5887697e45a3e3347e9f82 Mon Sep 17 00:00:00 2001 From: HermannSW Date: Thu, 28 May 2020 23:21:35 +0200 Subject: [PATCH 1/8] Fix imx477.h mode numers: 0123 -> 02103 --- imx477_modes.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/imx477_modes.h b/imx477_modes.h index a198632..46997f9 100644 --- a/imx477_modes.h +++ b/imx477_modes.h @@ -830,6 +830,22 @@ struct mode_def imx477_modes[] = { .term = {0, 0}, .black_level = 256, }, + { + .regs = imx477_2028x1080_regs, + .num_regs = NUM_ELEMENTS(imx477_2028x1080_regs), + .width = 2028, + .height = 1080, + .encoding = 0, + .order = BAYER_ORDER_RGGB, + .native_bit_depth = 12, + .image_id = 0x2C, + .data_lanes = 2, + .min_vts = 1134, + .line_time_ns = 0x31c4, + .timing = {0, 0, 0, 0, 0}, + .term = {0, 0}, + .black_level = 256, + }, { .regs = imx477_2028x1520_regs, .num_regs = NUM_ELEMENTS(imx477_2028x1520_regs), @@ -847,17 +863,17 @@ struct mode_def imx477_modes[] = { .black_level = 256, }, { - .regs = imx477_2028x1080_regs, - .num_regs = NUM_ELEMENTS(imx477_2028x1080_regs), - .width = 2028, - .height = 1080, + .regs = imx477_4056x3040_regs, + .num_regs = NUM_ELEMENTS(imx477_4056x3040_regs), + .width = 4056, + .height = 3040, .encoding = 0, .order = BAYER_ORDER_RGGB, .native_bit_depth = 12, .image_id = 0x2C, .data_lanes = 2, - .min_vts = 1134, - .line_time_ns = 0x31c4, + .min_vts = 3072, + .line_time_ns = 0x5dc0, .timing = {0, 0, 0, 0, 0}, .term = {0, 0}, .black_level = 256, From e5ccb56db58bc6e95cac20e47e322d0b94d62c9d Mon Sep 17 00:00:00 2001 From: HermannSW Date: Thu, 28 May 2020 23:35:40 +0200 Subject: [PATCH 2/8] Adjust tools/gifen.sh for HQ camera --- tools/gifenc.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/gifenc.sh b/tools/gifenc.sh index 662bb49..3a013f9 100755 --- a/tools/gifenc.sh +++ b/tools/gifenc.sh @@ -6,7 +6,8 @@ palette="/tmp/palette.png" #filters="fps=15,scale=320:-1:flags=lanczos" -filters="fps=25,scale=640:-1:flags=lanczos" +#filters="fps=25,scale=640:-1:flags=lanczos" +filters="fps=25,scale=1012:-1:flags=lanczos" ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2 From 18b74096d2bae7e06e8ab0daea4b6a81b7849d2f Mon Sep 17 00:00:00 2001 From: HermannSW Date: Thu, 28 May 2020 23:40:42 +0200 Subject: [PATCH 3/8] Make camera_i2c callable from everywhere --- camera_i2c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera_i2c b/camera_i2c index a977e5d..b009398 100755 --- a/camera_i2c +++ b/camera_i2c @@ -108,7 +108,7 @@ raspi-gpio set 45 a1 #shutdown # you need this one: https://github.com/6by9/rpi3-gpiovirtbuf #raspi-gpio set 41 1 -./rpi3-gpiovirtbuf s 133 1 +`dirname $0`/rpi3-gpiovirtbuf s 133 1 #LED #raspi-gpio set 32 1 i2cdetect -y 0 From 05f086b3ddb097a518257179b13db9ecec0bdb72 Mon Sep 17 00:00:00 2001 From: HermannSW Date: Thu, 28 May 2020 23:42:45 +0200 Subject: [PATCH 4/8] Do camera_i2c GPIO stuff for 4. kernel only, use i2c-10 for 5. kernel --- camera_i2c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/camera_i2c b/camera_i2c index b009398..aa358cb 100755 --- a/camera_i2c +++ b/camera_i2c @@ -6,6 +6,7 @@ # http://elinux.org/RPi_HardwareHistory#Board_Revision_History rev=`cat /proc/cpuinfo | grep Revision | awk '{print substr($NF,length($NF)-5,6)}'` +r=`uname -r | head --bytes 1` echo "setting GPIO for board revsion: $rev" case $rev in @@ -93,6 +94,9 @@ raspi-gpio set 2 dh 'a02082'|'a22082'|'a020d3'|'9020e0'|'a03111'|'b03111'|'c03111'|'a03112'|'b03112'|'c03112') echo "Raspberry Pi3B / Pi3B+ / 3A / 4B(1G/2G/4G)" +if [ "$r" = "4" ] +then +i2c=0 # https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=120702&start=100 # Pins 44&45 Alt1=i2c0, alt2=i2c1 # i2c0 can be on pins 0 and 1, so make sure they are not set to alt0 @@ -106,15 +110,23 @@ raspi-gpio set 44 a1 raspi-gpio set 45 ip raspi-gpio set 45 a1 #shutdown +else +i2c=10 +fi # you need this one: https://github.com/6by9/rpi3-gpiovirtbuf #raspi-gpio set 41 1 `dirname $0`/rpi3-gpiovirtbuf s 133 1 #LED #raspi-gpio set 32 1 -i2cdetect -y 0 +i2cdetect -y $i2c ;; *) echo "Failed: don't know how to set GPIO for this board!" ;; esac + +if [ "$r" = "5" ] +then +echo "Use 'raspiraw -y 10' to communicate with the sensor" +fi From 35bb4a83dd4feba7533356283e83a610d9eae547 Mon Sep 17 00:00:00 2001 From: HermannSW Date: Thu, 28 May 2020 23:47:37 +0200 Subject: [PATCH 5/8] Add simple tools for all HQ camera modes --- tools/1012x760 | 39 +++++++++++++++++++++++++++++++++++++++ tools/2028x1080 | 39 +++++++++++++++++++++++++++++++++++++++ tools/2028x1520 | 39 +++++++++++++++++++++++++++++++++++++++ tools/4056x3040 | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100755 tools/1012x760 create mode 100755 tools/2028x1080 create mode 100755 tools/2028x1520 create mode 100755 tools/4056x3040 diff --git a/tools/1012x760 b/tools/1012x760 new file mode 100755 index 0000000..33cd6e4 --- /dev/null +++ b/tools/1012x760 @@ -0,0 +1,39 @@ +#!/bin/bash + +if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi + +r=`uname -r | head --bytes 1` +if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi + +echo "removing /dev/shm/out.*.raw" +rm -f /dev/shm/out.*.raw + +if [ "$2" = "" ]; then fps=195; else fps=$2; fi +echo "capturing frames for ${1}ms with ${fps}fps requested" +raspiraw -md 4 -y $i2c -vf -hf -t $1 -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null + +grep -v ",0$" tstamps.dirty | grep -v ",-[0-9]*$" > tstamps.csv + +us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-` +l=`wc --lines tstamps.csv | cut -f1 -d\ ` +echo -e "$l frames were captured\nmajority framerate $((1000000 / $us))fps" + +echo "frame delta time[us] distribution" +cut -f1 -d, tstamps.csv | sort -n | uniq -c + +D=`echo "0123456789" | sed "s/\`echo $((1000000/$fps)) | cut -b1\`//"` + +echo "after skip frame indices (middle column)" +grep "^[$D]" tstamps.csv | sed "s/^/> /" + +skips=`grep "^[$D]" tstamps.csv | wc --lines | cut -f1 -d\ ` +stamps=`wc --lines tstamps.csv | cut -f1 -d\ ` +per=`expr \( 100 \* $skips \) / \( $skips + $stamps \)` +echo "$per% frame skips" + +fst=`head -1 tstamps.csv | cut -f3 -d,` +lst=`tail -1 tstamps.csv | cut -f3 -d,` +dif=`expr $lst - $fst` +dif2=`expr $dif / 2` +avg=`expr \( 1000000 \* \( $l - 1 \) + $dif2 \) / $dif` +echo "average framerate ${avg}fps" diff --git a/tools/2028x1080 b/tools/2028x1080 new file mode 100755 index 0000000..2d5d8ca --- /dev/null +++ b/tools/2028x1080 @@ -0,0 +1,39 @@ +#!/bin/bash + +if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi + +r=`uname -r | head --bytes 1` +if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi + +echo "removing /dev/shm/out.*.raw" +rm -f /dev/shm/out.*.raw + +if [ "$2" = "" ]; then fps=57; else fps=$2; fi +echo "capturing frames for ${1}ms with ${fps}fps requested" +raspiraw -md 1 -y $i2c -vf -hf -t $1 -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null + +grep -v ",0$" tstamps.dirty | grep -v ",-[0-9]*$" > tstamps.csv + +us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-` +l=`wc --lines tstamps.csv | cut -f1 -d\ ` +echo -e "$l frames were captured\nmajority framerate $((1000000 / $us))fps" + +echo "frame delta time[us] distribution" +cut -f1 -d, tstamps.csv | sort -n | uniq -c + +D=`echo "0123456789" | sed "s/\`echo $((1000000/$fps)) | cut -b1\`//"` + +echo "after skip frame indices (middle column)" +grep "^[$D]" tstamps.csv | sed "s/^/> /" + +skips=`grep "^[$D]" tstamps.csv | wc --lines | cut -f1 -d\ ` +stamps=`wc --lines tstamps.csv | cut -f1 -d\ ` +per=`expr \( 100 \* $skips \) / \( $skips + $stamps \)` +echo "$per% frame skips" + +fst=`head -1 tstamps.csv | cut -f3 -d,` +lst=`tail -1 tstamps.csv | cut -f3 -d,` +dif=`expr $lst - $fst` +dif2=`expr $dif / 2` +avg=`expr \( 1000000 \* \( $l - 1 \) + $dif2 \) / $dif` +echo "average framerate ${avg}fps" diff --git a/tools/2028x1520 b/tools/2028x1520 new file mode 100755 index 0000000..a48b006 --- /dev/null +++ b/tools/2028x1520 @@ -0,0 +1,39 @@ +#!/bin/bash + +if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi + +r=`uname -r | head --bytes 1` +if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi + +echo "removing /dev/shm/out.*.raw" +rm -f /dev/shm/out.*.raw + +if [ "$2" = "" ]; then fps=41; else fps=$2; fi +echo "capturing frames for ${1}ms with ${fps}fps requested" +raspiraw -md 2 -y $i2c -vf -hf -t $1 -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null + +grep -v ",0$" tstamps.dirty | grep -v ",-[0-9]*$" > tstamps.csv + +us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-` +l=`wc --lines tstamps.csv | cut -f1 -d\ ` +echo -e "$l frames were captured\nmajority framerate $((1000000 / $us))fps" + +echo "frame delta time[us] distribution" +cut -f1 -d, tstamps.csv | sort -n | uniq -c + +D=`echo "0123456789" | sed "s/\`echo $((1000000/$fps)) | cut -b1\`//"` + +echo "after skip frame indices (middle column)" +grep "^[$D]" tstamps.csv | sed "s/^/> /" + +skips=`grep "^[$D]" tstamps.csv | wc --lines | cut -f1 -d\ ` +stamps=`wc --lines tstamps.csv | cut -f1 -d\ ` +per=`expr \( 100 \* $skips \) / \( $skips + $stamps \)` +echo "$per% frame skips" + +fst=`head -1 tstamps.csv | cut -f3 -d,` +lst=`tail -1 tstamps.csv | cut -f3 -d,` +dif=`expr $lst - $fst` +dif2=`expr $dif / 2` +avg=`expr \( 1000000 \* \( $l - 1 \) + $dif2 \) / $dif` +echo "average framerate ${avg}fps" diff --git a/tools/4056x3040 b/tools/4056x3040 new file mode 100755 index 0000000..6d98a2a --- /dev/null +++ b/tools/4056x3040 @@ -0,0 +1,39 @@ +#!/bin/bash + +if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi + +r=`uname -r | head --bytes 1` +if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi + +echo "removing /dev/shm/out.*.raw" +rm -f /dev/shm/out.*.raw + +if [ "$2" = "" ]; then fps=11; else fps=$2; fi +echo "capturing frames for ${1}ms with ${fps}fps requested" +raspiraw -md 3 -y $i2c -vf -hf -t $1 -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null + +grep -v ",0$" tstamps.dirty | grep -v ",-[0-9]*$" > tstamps.csv + +us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-` +l=`wc --lines tstamps.csv | cut -f1 -d\ ` +echo -e "$l frames were captured\nmajority framerate $((1000000 / $us))fps" + +echo "frame delta time[us] distribution" +cut -f1 -d, tstamps.csv | sort -n | uniq -c + +D=`echo "0123456789" | sed "s/\`echo $((1000000/$fps)) | cut -b1\`//"` + +echo "after skip frame indices (middle column)" +grep "^[$D]" tstamps.csv | sed "s/^/> /" + +skips=`grep "^[$D]" tstamps.csv | wc --lines | cut -f1 -d\ ` +stamps=`wc --lines tstamps.csv | cut -f1 -d\ ` +per=`expr \( 100 \* $skips \) / \( $skips + $stamps \)` +echo "$per% frame skips" + +fst=`head -1 tstamps.csv | cut -f3 -d,` +lst=`tail -1 tstamps.csv | cut -f3 -d,` +dif=`expr $lst - $fst` +dif2=`expr $dif / 2` +avg=`expr \( 1000000 \* \( $l - 1 \) + $dif2 \) / $dif` +echo "average framerate ${avg}fps" From d05c4a62ae1f5996783c4c66843620a2c2e75da8 Mon Sep 17 00:00:00 2001 From: HermannSW Date: Fri, 29 May 2020 00:02:04 +0200 Subject: [PATCH 6/8] =?UTF-8?q?Correct=20line=5Ftime=5Fns=20from=2024000?= =?UTF-8?q?=C2=B5s=20to=2028571,=20based=20on=20raspistill=20I2C=20capture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imx477_modes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imx477_modes.h b/imx477_modes.h index 46997f9..67b288c 100644 --- a/imx477_modes.h +++ b/imx477_modes.h @@ -825,7 +825,7 @@ struct mode_def imx477_modes[] = { .image_id = 0x2C, .data_lanes = 2, .min_vts = 3072, - .line_time_ns = 0x5dc0, + .line_time_ns = 28571, .timing = {0, 0, 0, 0, 0}, .term = {0, 0}, .black_level = 256, @@ -873,7 +873,7 @@ struct mode_def imx477_modes[] = { .image_id = 0x2C, .data_lanes = 2, .min_vts = 3072, - .line_time_ns = 0x5dc0, + .line_time_ns = 28571, .timing = {0, 0, 0, 0, 0}, .term = {0, 0}, .black_level = 256, From 650d2fc6260990df8042b12ea6ab1b961198a623 Mon Sep 17 00:00:00 2001 From: HermannSW Date: Sun, 31 May 2020 19:53:12 +0200 Subject: [PATCH 7/8] Add long_exposure tool for HQ camera 12MP captures up to 239s exposure time. Tool allows to capture a single long_exposure, or many. --- imx477_modes.h | 1 + raspiraw.c | 14 ++++++++++++++ tools/long_exposure | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100755 tools/long_exposure diff --git a/imx477_modes.h b/imx477_modes.h index 67b288c..c686b80 100644 --- a/imx477_modes.h +++ b/imx477_modes.h @@ -457,6 +457,7 @@ struct sensor_regs imx477_4056x3040_regs[] = { {0x0205, 0x00}, {0x0340, 0x0c}, {0x0341, 0x00}, + {0x3100, 0x00}, {0x0100, 0x01}, }; diff --git a/raspiraw.c b/raspiraw.c index d527420..496688b 100644 --- a/raspiraw.c +++ b/raspiraw.c @@ -2371,6 +2371,20 @@ void update_regs(const struct sensor_def *sensor, struct mode_def *mode, int hfl if (sensor->exposure_reg && exposure != -1) { + if (strcmp(sensor->name, "imx477") == 0 && + mode->width == 4056 && + exposure <= 128*65535) + { + uint16_t shift_reg = 0x3100; + int shr = 0; + while (exposure > 65535) + { + ++shr; + exposure /= 2; + } + modReg(mode, shift_reg, 0, 2, shr, EQUAL); + } + if (exposure < 0 || exposure >= (1<exposure_reg_num_bits)) { vcos_log_error("Invalid exposure:%d, exposure range is 0 to %u!\n", diff --git a/tools/long_exposure b/tools/long_exposure new file mode 100755 index 0000000..23957f9 --- /dev/null +++ b/tools/long_exposure @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ "$1" = "" ]; then echo "format: `basename $0` us [#frames]"; exit; fi +if [ "$2" = "" ]; then frames=1; else frames=$2; fi + +r=`uname -r | head --bytes 1` +if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi + +echo "removing /dev/shm/out.*.raw" +rm -f /dev/shm/out.*.raw +touch /dev/shm/out.0000.raw + +raspiraw -md 3 --expus $1 -y $i2c -vf -hf -t $(( 1500 + ( $frames * $1 ) / 1000 )) -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null From ea458f9792517dfe7d55385a24d27cff9775cc2c Mon Sep 17 00:00:00 2001 From: HermannSW Date: Fri, 2 Oct 2020 19:22:12 +0200 Subject: [PATCH 8/8] Enable framerate for 4056x3040 tool --- tools/4056x3040 | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/4056x3040 b/tools/4056x3040 index 6d98a2a..54e93df 100755 --- a/tools/4056x3040 +++ b/tools/4056x3040 @@ -2,26 +2,35 @@ if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi +hd () { + echo -n $1 | sed "s/\(.\)/\1\xa/g" > /tmp/n + local l=`echo -n $1 | wc --bytes` + echo -n `head -n $(($l-2)) /tmp/n` | sed "s/ //g" + echo -n .`tail -n -2 /tmp/n` | sed "s/ //g" +} + r=`uname -r | head --bytes 1` if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi echo "removing /dev/shm/out.*.raw" rm -f /dev/shm/out.*.raw -if [ "$2" = "" ]; then fps=11; else fps=$2; fi +if [ "$2" = "" ]; then fps=11.38; else fps=$2; fi echo "capturing frames for ${1}ms with ${fps}fps requested" -raspiraw -md 3 -y $i2c -vf -hf -t $1 -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null +raspiraw -md 3 -y $i2c -vf -hf -t $1 --fps $fps -ts tstamps.dirty -hd0 hd0.32k -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null grep -v ",0$" tstamps.dirty | grep -v ",-[0-9]*$" > tstamps.csv us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-` l=`wc --lines tstamps.csv | cut -f1 -d\ ` -echo -e "$l frames were captured\nmajority framerate $((1000000 / $us))fps" +echo -en "$l frames were captured\nmajority framerate " +hd $((100000000 / $us)) +echo "fps" echo "frame delta time[us] distribution" cut -f1 -d, tstamps.csv | sort -n | uniq -c -D=`echo "0123456789" | sed "s/\`echo $((1000000/$fps)) | cut -b1\`//"` +D=`echo "0123456789" | sed "s/\`echo $us | cut -b1\`//"` echo "after skip frame indices (middle column)" grep "^[$D]" tstamps.csv | sed "s/^/> /" @@ -35,5 +44,7 @@ fst=`head -1 tstamps.csv | cut -f3 -d,` lst=`tail -1 tstamps.csv | cut -f3 -d,` dif=`expr $lst - $fst` dif2=`expr $dif / 2` -avg=`expr \( 1000000 \* \( $l - 1 \) + $dif2 \) / $dif` -echo "average framerate ${avg}fps" +avg=`expr \( 100000000 \* \( $l - 1 \) + $dif2 \) / $dif` +echo -n "average framerate " +hd ${avg} +echo "fps"