Skip to content

Commit

Permalink
Bulk commit of everything contained in raspiraw.drop.5_26_18.zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Hermann-SW committed May 27, 2018
1 parent 7fe5f72 commit 7362b3b
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 70 deletions.
6 changes: 6 additions & 0 deletions adv7282m_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ struct sensor_def adv7282 = {

.gain_reg = 0,
.gain_reg_num_bits = 0,

.xos_reg = 0,
.xos_reg_num_bits = 0,

.yos_reg = 0,
.yos_reg_num_bits = 0,
};

#endif
6 changes: 6 additions & 0 deletions imx219_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ struct sensor_def imx219 = {

.gain_reg = 0x0157,
.gain_reg_num_bits = 8, //Only valid up to 230.

.xos_reg = 0x016C,
.xos_reg_num_bits = 12, // x_output_size [11:8] and [7:0] (imx219 datasheet)

.yos_reg = 0x016E,
.yos_reg_num_bits = 12, // y_output_size [11:8] and [7:0] (imx219 datasheet)
};

#endif
6 changes: 6 additions & 0 deletions ov5647_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,12 @@ struct sensor_def ov5647 = {

.gain_reg = 0x350A,
.gain_reg_num_bits = 10,

.xos_reg = 0x3808,
.xos_reg_num_bits = 12, // x_output_size [11:8] and [7:0] (ov5647 datasheet)

.yos_reg = 0x380A,
.yos_reg_num_bits = 12, // y_output_size [11:8] and [7:0] (ov5647 datasheet)
};

#endif
84 changes: 64 additions & 20 deletions raspiraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ struct sensor_def

uint16_t gain_reg;
int gain_reg_num_bits;

uint16_t xos_reg;
int xos_reg_num_bits;

uint16_t yos_reg;
int yos_reg_num_bits;
};


Expand Down Expand Up @@ -169,6 +175,8 @@ enum {
CommandRegs,
CommandHinc,
CommandVinc,
CommandVoinc,
CommandHoinc,
CommandFps,
CommandWidth,
CommandHeight,
Expand Down Expand Up @@ -201,7 +209,9 @@ static COMMAND_LIST cmdline_commands[] =
{ CommandAwbGains, "-awbgains", "awbg", "Set the AWB gains to use.", 1 },
{ CommandRegs, "-regs", "r", "Change (current mode) regs", 0 },
{ CommandHinc, "-hinc", "hi", "Set horizontal odd/even inc reg", -1},
{ CommandVinc, "-vinc", "vi", "Set vertical odd/even inc reg", -1},
{ CommandVinc, "-vinc", "vi", "Set vertical odd/even inc reg", -1}, // ov5647
{ CommandVoinc, "-voinc", "voi","Set vertical odd inc reg", -1}, // imx219
{ CommandHoinc, "-hoinc", "hoi","Set horizontal odd inc reg", -1}, // imx219
{ CommandFps, "-fps", "f", "Set framerate regs", -1},
{ CommandWidth, "-width", "w", "Set current mode width", -1},
{ CommandHeight, "-height", "h", "Set current mode height", -1},
Expand Down Expand Up @@ -241,6 +251,8 @@ typedef struct {
char *regs;
int hinc;
int vinc;
int voinc;
int hoinc;
double fps;
int width;
int height;
Expand Down Expand Up @@ -751,6 +763,22 @@ static int parse_cmdline(int argc, char **argv, RASPIRAW_PARAMS_T *cfg)
i++;
break;

case CommandVoinc:
if (strlen(argv[i+1]) != 2 ||
sscanf(argv[i + 1], "%x", &cfg->voinc) != 1)
valid = 0;
else
i++;
break;

case CommandHoinc:
if (strlen(argv[i+1]) != 2 ||
sscanf(argv[i + 1], "%x", &cfg->hoinc) != 1)
valid = 0;
else
i++;
break;

case CommandFps:
if (sscanf(argv[i + 1], "%lf", &cfg->fps) != 1)
valid = 0;
Expand Down Expand Up @@ -862,6 +890,8 @@ int main(int argc, char** argv) {
.regs = NULL,
.hinc = -1,
.vinc = -1,
.voinc = -1,
.hoinc = -1,
.fps = -1,
.width = -1,
.height = -1,
Expand Down Expand Up @@ -949,14 +979,26 @@ int main(int argc, char** argv) {

if (cfg.hinc >= 0)
{
// TODO: handle modes different to ov5647 as well
modReg(sensor_mode, 0x3814, 0, 7, cfg.hinc, EQUAL);
if (!strcmp(sensor->name, "ov5647"))
modReg(sensor_mode, 0x3814, 0, 7, cfg.hinc, EQUAL);
}

if (cfg.vinc >= 0)
{
// TODO: handle modes different to ov5647 as well
modReg(sensor_mode, 0x3815, 0, 7, cfg.vinc, EQUAL);
if (!strcmp(sensor->name, "ov5647"))
modReg(sensor_mode, 0x3815, 0, 7, cfg.vinc, EQUAL);
}

if (cfg.voinc >= 0)
{
if (!strcmp(sensor->name, "imx219"))
modReg(sensor_mode, 0x0171, 0, 2, cfg.voinc, EQUAL);
}

if (cfg.hoinc >= 0)
{
if (!strcmp(sensor->name, "imx219"))
modReg(sensor_mode, 0x0170, 0, 2, cfg.hoinc, EQUAL);
}

if (cfg.fps > 0)
Expand All @@ -968,34 +1010,36 @@ int main(int argc, char** argv) {

if (cfg.width > 0)
{
sensor_mode->width = cfg.width;
// TODO: handle modes different to ov5647 as well
modReg(sensor_mode, 0x3808, 0, 3, cfg.width >>8, EQUAL);
modReg(sensor_mode, 0x3809, 0, 7, cfg.width &0xFF, EQUAL);
sensor_mode->width = cfg.width;
modReg(sensor_mode, sensor->xos_reg+0, 0, 3, cfg.width >>8, EQUAL);
modReg(sensor_mode, sensor->xos_reg+1, 0, 7, cfg.width &0xFF, EQUAL);
}

if (cfg.height > 0)
{
sensor_mode->height = cfg.height;
// TODO: handle modes different to ov5647 as well
modReg(sensor_mode, 0x380A, 0, 3, cfg.height >>8, EQUAL);
modReg(sensor_mode, 0x380B, 0, 7, cfg.height &0xFF, EQUAL);
modReg(sensor_mode, sensor->yos_reg+0, 0, 3, cfg.height >>8, EQUAL);
modReg(sensor_mode, sensor->yos_reg+1, 0, 7, cfg.height &0xFF, EQUAL);
}

if (cfg.left > 0)
{
// TODO: handle modes different to ov5647 as well
int val = cfg.left * (cfg.mode < 2 ? 1 : 1 << (cfg.mode / 2 - 1));
modReg(sensor_mode, 0x3800, 0, 3, val >>8, EQUAL);
modReg(sensor_mode, 0x3801, 0, 7, val &0xFF, EQUAL);
if (!strcmp(sensor->name, "ov5647"))
{
int val = cfg.left * (cfg.mode < 2 ? 1 : 1 << (cfg.mode / 2 - 1));
modReg(sensor_mode, 0x3800, 0, 3, val >>8, EQUAL);
modReg(sensor_mode, 0x3801, 0, 7, val &0xFF, EQUAL);
}
}

if (cfg.top > 0)
{
// TODO: handle modes different to ov5647 as well
int val = cfg.top * (cfg.mode < 2 ? 1 : 1 << (cfg.mode / 2 - 1));
modReg(sensor_mode, 0x3802, 0, 3, val >>8, EQUAL);
modReg(sensor_mode, 0x3803, 0, 7, val &0xFF, EQUAL);
if (!strcmp(sensor->name, "ov5647"))
{
int val = cfg.top * (cfg.mode < 2 ? 1 : 1 << (cfg.mode / 2 - 1));
modReg(sensor_mode, 0x3802, 0, 3, val >>8, EQUAL);
modReg(sensor_mode, 0x3803, 0, 7, val &0xFF, EQUAL);
}
}


Expand Down
25 changes: 25 additions & 0 deletions tools/1296x704_S
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi

echo "removing /dev/shm/out.*.raw"
rm -f /dev/shm/out.*.raw

fps=190
echo "capturing frames for ${1}ms with ${fps}fps requested"
raspiraw -md 5 -t $1 -ts tstamps.csv -hd0 hd0.32k --height 176 --top 0 --vinc F1 --fps $fps -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null

us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-`
l=`ls -l /dev/shm/out.*.raw | wc --lines`
echo "$l frames were captured at $((1000000 / $us))fps"

echo "frame delta time[us] distribution"
cut -f1 -d, tstamps.csv | sort -n | uniq -c

echo "after skip frame indices (middle column)"
grep "^[1-46-9]" tstamps.csv

skips=`grep "^[1-46-9]" 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"
25 changes: 2 additions & 23 deletions tools/1296x720_S
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
#!/bin/bash
echo "please use 1296x704_s instead"

if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi

echo "removing /dev/shm/out.*.raw"
rm -f /dev/shm/out.*.raw

fps=190
echo "capturing frames for ${1}ms with ${fps}fps requested"
raspiraw -md 5 -t $1 -ts tstamps.csv -hd0 hd0.32k --height 180 --top 0 --vinc F1 --fps $fps -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null

us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-`
l=`ls -l /dev/shm/out.*.raw | wc --lines`
echo "$l frames were captured at $((1000000 / $us))fps"

echo "frame delta time[us] distribution"
cut -f1 -d, tstamps.csv | sort -n | uniq -c

echo "after skip frame indices (middle column)"
grep "^[1-46-9]" tstamps.csv

skips=`grep "^[1-46-9]" 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"
# https://www.raspberrypi.org/forums/viewtopic.php?f=43&p=1319906#p1319906
25 changes: 25 additions & 0 deletions tools/1296x720_s
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi

echo "removing /dev/shm/out.*.raw"
rm -f /dev/shm/out.*.raw

fps=114
echo "capturing frames for ${1}ms with ${fps}fps requested"
raspiraw -md 5 -t $1 -ts tstamps.csv -hd0 hd0.32k --height 360 --top 0 --vinc 71 --fps $fps -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null

us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-`
l=`ls -l /dev/shm/out.*.raw | wc --lines`
echo "$l frames were captured at $((1000000 / $us))fps"

echo "frame delta time[us] distribution"
cut -f1 -d, tstamps.csv | sort -n | uniq -c

echo "after skip frame indices (middle column)"
grep "^[1-79]" tstamps.csv

skips=`grep "^[1-79]" 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"
25 changes: 2 additions & 23 deletions tools/1296x730_s
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
#!/bin/bash
echo "please use 1296x720_s instead"

if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi

echo "removing /dev/shm/out.*.raw"
rm -f /dev/shm/out.*.raw

fps=98
echo "capturing frames for ${1}ms with ${fps}fps requested"
raspiraw -md 5 -t $1 -ts tstamps.csv -hd0 hd0.32k --height 365 --top 0 --vinc 71 --fps $fps -sr 1 -o /dev/shm/out.%04d.raw 2>/dev/null >/dev/null

us=`cut -f1 -d, tstamps.csv | sort -n | uniq -c | sort -n | tail -1 | cut -b9-`
l=`ls -l /dev/shm/out.*.raw | wc --lines`
echo "$l frames were captured at $((1000000 / $us))fps"

echo "frame delta time[us] distribution"
cut -f1 -d, tstamps.csv | sort -n | uniq -c

echo "after skip frame indices (middle column)"
grep "^[2-9]" tstamps.csv

skips=`grep "^[2-9]" 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"
# https://www.raspberrypi.org/forums/viewtopic.php?f=43&p=1319906#p1319906
2 changes: 2 additions & 0 deletions tools/camera_i2c_
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cd `dirname $0`/.. && ./camera_i2c
11 changes: 11 additions & 0 deletions tools/camver
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
dt=`vcgencmd get_camera | grep "detected=1"`
if [ "$dt" = "" ]; then
echo "no camera detected"
else
cd ~/raspiraw ; ./camera_i2c 2>&1 | cat > /dev/null
v1=`i2cdetect -y 0 54 54 | grep " 36"` ; v2=`i2cdetect -y 0 16 16 | grep " 10"`
if [ "$v1" != "" ]; then echo -n "v1"; fi
if [ "$v2" != "" ]; then echo -n "v2"; fi
echo " camera found"
fi
Binary file modified tools/double
Binary file not shown.
21 changes: 17 additions & 4 deletions tools/double.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ int main(int argc, char *argv[])
{
FILE *src = fopen(argv[1],"rb");
char line[9999],m;
int w,h,f,i;
int w,h,f,i,j,x=(argc>2)?2:1;

assert(src);
fgets(line, 9999, src); assert(0 == strcmp(line, "P6\n") || 0 == strcmp(line, "P5\n"));
m=line[1];
fgets(line, 9999, src); assert(2 == sscanf(line, "%d %d", &w, &h));
fgets(line, 9999, src); assert(1 == sscanf(line, "%d", &f));
assert(3*w < 9999);
assert(9 <= printf("P%c\n%d %d\n%d\n",m,w,2*h,f));
assert(9 <= printf("P%c\n%d %d\n%d\n",m,w*x,2*h,f));

f = (m=='5') ? 1 : 3;

for(i=0; i<h; ++i)
{
assert(f*w == fread(line, 1, f*w, src));
assert(f*w == fwrite(line, 1, f*w, stdout));
assert(f*w == fwrite(line, 1, f*w, stdout));
if (x==2)
{
for(j=w-1; j>=0; --j)
{
if (f==1) { line[2*j]=line[2*j+1]=line[j]; }
else
{
line[2*j*f+0] = line[(2*j+1)*f+0] = line[j*f+0];
line[2*j*f+1] = line[(2*j+1)*f+1] = line[j*f+1];
line[2*j*f+2] = line[(2*j+1)*f+2] = line[j*f+2];
}
}
}
assert(f*w*x == fwrite(line, 1, f*w*x, stdout));
assert(f*w*x == fwrite(line, 1, f*w*x, stdout));
}

h=ftell(src); fseek(src, 0, SEEK_END); assert(h == ftell(src));
Expand Down
1 change: 1 addition & 0 deletions tools/raspiraw

0 comments on commit 7362b3b

Please sign in to comment.