Format Code Style Only

This commit is contained in:
Christophe De Wagter
2017-11-09 17:32:22 +01:00
parent 6fafcaaae9
commit a797fcbf33
3 changed files with 139 additions and 140 deletions
+96 -97
View File
@@ -68,104 +68,104 @@ struct video_config_t bottom_camera = {
//I2C_BUF_LEN must be higher then size of these patch lines //I2C_BUF_LEN must be higher then size of these patch lines
#define MT9V117_PATCH_LINE_NUM 13 #define MT9V117_PATCH_LINE_NUM 13
static uint8_t patch_line1[] = { static uint8_t patch_line1[] = {
0xf0, 0x00, 0x72, 0xcf, 0xff, 0x00, 0x3e, 0xd0, 0x92, 0x00, 0xf0, 0x00, 0x72, 0xcf, 0xff, 0x00, 0x3e, 0xd0, 0x92, 0x00,
0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0xb1, 0x10, 0x92, 0x05, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0xb1, 0x10, 0x92, 0x05,
0xb1, 0x11, 0x92, 0x04, 0xb1, 0x12, 0x70, 0xcf, 0xff, 0x00, 0xb1, 0x11, 0x92, 0x04, 0xb1, 0x12, 0x70, 0xcf, 0xff, 0x00,
0x30, 0xc0, 0x90, 0x00, 0x7f, 0xe0, 0xb1, 0x13, 0x70, 0xcf, 0x30, 0xc0, 0x90, 0x00, 0x7f, 0xe0, 0xb1, 0x13, 0x70, 0xcf,
0xff, 0xff, 0xe7, 0x1c, 0x88, 0x36, 0x09, 0x0f, 0x00, 0xb3 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x36, 0x09, 0x0f, 0x00, 0xb3
}; };
static uint8_t patch_line2[] = { static uint8_t patch_line2[] = {
0xf0, 0x30, 0x69, 0x13, 0xe1, 0x80, 0xd8, 0x08, 0x20, 0xca, 0xf0, 0x30, 0x69, 0x13, 0xe1, 0x80, 0xd8, 0x08, 0x20, 0xca,
0x03, 0x22, 0x71, 0xcf, 0xff, 0xff, 0xe5, 0x68, 0x91, 0x35, 0x03, 0x22, 0x71, 0xcf, 0xff, 0xff, 0xe5, 0x68, 0x91, 0x35,
0x22, 0x0a, 0x1f, 0x80, 0xff, 0xff, 0xf2, 0x18, 0x29, 0x05, 0x22, 0x0a, 0x1f, 0x80, 0xff, 0xff, 0xf2, 0x18, 0x29, 0x05,
0x00, 0x3e, 0x12, 0x22, 0x11, 0x01, 0x21, 0x04, 0x0f, 0x81, 0x00, 0x3e, 0x12, 0x22, 0x11, 0x01, 0x21, 0x04, 0x0f, 0x81,
0x00, 0x00, 0xff, 0xf0, 0x21, 0x8c, 0xf0, 0x10, 0x1a, 0x22 0x00, 0x00, 0xff, 0xf0, 0x21, 0x8c, 0xf0, 0x10, 0x1a, 0x22
}; };
static uint8_t patch_line3[] = { static uint8_t patch_line3[] = {
0xf0, 0x60, 0x10, 0x44, 0x12, 0x20, 0x11, 0x02, 0xf7, 0x87, 0xf0, 0x60, 0x10, 0x44, 0x12, 0x20, 0x11, 0x02, 0xf7, 0x87,
0x22, 0x4f, 0x03, 0x83, 0x1a, 0x20, 0x10, 0xc4, 0xf0, 0x09, 0x22, 0x4f, 0x03, 0x83, 0x1a, 0x20, 0x10, 0xc4, 0xf0, 0x09,
0xba, 0xae, 0x7b, 0x50, 0x1a, 0x20, 0x10, 0x84, 0x21, 0x45, 0xba, 0xae, 0x7b, 0x50, 0x1a, 0x20, 0x10, 0x84, 0x21, 0x45,
0x01, 0xc1, 0x1a, 0x22, 0x10, 0x44, 0x70, 0xcf, 0xff, 0x00, 0x01, 0xc1, 0x1a, 0x22, 0x10, 0x44, 0x70, 0xcf, 0xff, 0x00,
0x3e, 0xd0, 0xb0, 0x60, 0xb0, 0x25, 0x7e, 0xe0, 0x78, 0xe0 0x3e, 0xd0, 0xb0, 0x60, 0xb0, 0x25, 0x7e, 0xe0, 0x78, 0xe0
}; };
static uint8_t patch_line4[] = { static uint8_t patch_line4[] = {
0xf0, 0x90, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x12, 0xf0, 0x90, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x12,
0x72, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x8a, 0x57, 0x20, 0x04, 0x72, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x8a, 0x57, 0x20, 0x04,
0x0f, 0x80, 0x00, 0x00, 0xff, 0xf0, 0xe2, 0x80, 0x20, 0xc5, 0x0f, 0x80, 0x00, 0x00, 0xff, 0xf0, 0xe2, 0x80, 0x20, 0xc5,
0x01, 0x61, 0x20, 0xc5, 0x03, 0x22, 0xb1, 0x12, 0x71, 0xcf, 0x01, 0x61, 0x20, 0xc5, 0x03, 0x22, 0xb1, 0x12, 0x71, 0xcf,
0xff, 0x00, 0x3e, 0xd0, 0xb1, 0x04, 0x7e, 0xe0, 0x78, 0xe0 0xff, 0x00, 0x3e, 0xd0, 0xb1, 0x04, 0x7e, 0xe0, 0x78, 0xe0
}; };
static uint8_t patch_line5[] = { static uint8_t patch_line5[] = {
0xf0, 0xc0, 0x70, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x57, 0xf0, 0xc0, 0x70, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x57,
0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x13, 0xea, 0x84, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x13, 0xea, 0x84,
0xb8, 0xa9, 0x78, 0x10, 0xf0, 0x03, 0xb8, 0x89, 0xb8, 0x8c, 0xb8, 0xa9, 0x78, 0x10, 0xf0, 0x03, 0xb8, 0x89, 0xb8, 0x8c,
0xb1, 0x13, 0x71, 0xcf, 0xff, 0x00, 0x30, 0xc0, 0xb1, 0x00, 0xb1, 0x13, 0x71, 0xcf, 0xff, 0x00, 0x30, 0xc0, 0xb1, 0x00,
0x7e, 0xe0, 0xc0, 0xf1, 0x09, 0x1e, 0x03, 0xc0, 0xc1, 0xa1 0x7e, 0xe0, 0xc0, 0xf1, 0x09, 0x1e, 0x03, 0xc0, 0xc1, 0xa1
}; };
static uint8_t patch_line6[] = { static uint8_t patch_line6[] = {
0xf0, 0xf0, 0x75, 0x08, 0x76, 0x28, 0x77, 0x48, 0xc2, 0x40, 0xf0, 0xf0, 0x75, 0x08, 0x76, 0x28, 0x77, 0x48, 0xc2, 0x40,
0xd8, 0x20, 0x71, 0xcf, 0x00, 0x03, 0x20, 0x67, 0xda, 0x02, 0xd8, 0x20, 0x71, 0xcf, 0x00, 0x03, 0x20, 0x67, 0xda, 0x02,
0x08, 0xae, 0x03, 0xa0, 0x73, 0xc9, 0x0e, 0x25, 0x13, 0xc0, 0x08, 0xae, 0x03, 0xa0, 0x73, 0xc9, 0x0e, 0x25, 0x13, 0xc0,
0x0b, 0x5e, 0x01, 0x60, 0xd8, 0x06, 0xff, 0xbc, 0x0c, 0xce, 0x0b, 0x5e, 0x01, 0x60, 0xd8, 0x06, 0xff, 0xbc, 0x0c, 0xce,
0x01, 0x00, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0x5a, 0x03, 0x20 0x01, 0x00, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0x5a, 0x03, 0x20
}; };
static uint8_t patch_line7[] = { static uint8_t patch_line7[] = {
0xf1, 0x20, 0xd9, 0x01, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0xb6, 0xf1, 0x20, 0xd9, 0x01, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0xb6,
0x03, 0x20, 0xd9, 0x01, 0x8d, 0x14, 0x08, 0x17, 0x01, 0x91, 0x03, 0x20, 0xd9, 0x01, 0x8d, 0x14, 0x08, 0x17, 0x01, 0x91,
0x8d, 0x16, 0xe8, 0x07, 0x0b, 0x36, 0x01, 0x60, 0xd8, 0x07, 0x8d, 0x16, 0xe8, 0x07, 0x0b, 0x36, 0x01, 0x60, 0xd8, 0x07,
0x0b, 0x52, 0x01, 0x60, 0xd8, 0x11, 0x8d, 0x14, 0xe0, 0x87, 0x0b, 0x52, 0x01, 0x60, 0xd8, 0x11, 0x8d, 0x14, 0xe0, 0x87,
0xd8, 0x00, 0x20, 0xca, 0x02, 0x62, 0x00, 0xc9, 0x03, 0xe0 0xd8, 0x00, 0x20, 0xca, 0x02, 0x62, 0x00, 0xc9, 0x03, 0xe0
}; };
static uint8_t patch_line8[] = { static uint8_t patch_line8[] = {
0xf1, 0x50, 0xc0, 0xa1, 0x78, 0xe0, 0xc0, 0xf1, 0x08, 0xb2, 0xf1, 0x50, 0xc0, 0xa1, 0x78, 0xe0, 0xc0, 0xf1, 0x08, 0xb2,
0x03, 0xc0, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x40, 0x75, 0xcf, 0x03, 0xc0, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x40, 0x75, 0xcf,
0xff, 0xff, 0xe5, 0x68, 0x95, 0x17, 0x96, 0x40, 0x77, 0xcf, 0xff, 0xff, 0xe5, 0x68, 0x95, 0x17, 0x96, 0x40, 0x77, 0xcf,
0xff, 0xff, 0xe5, 0x42, 0x95, 0x38, 0x0a, 0x0d, 0x00, 0x01, 0xff, 0xff, 0xe5, 0x42, 0x95, 0x38, 0x0a, 0x0d, 0x00, 0x01,
0x97, 0x40, 0x0a, 0x11, 0x00, 0x40, 0x0b, 0x0a, 0x01, 0x00 0x97, 0x40, 0x0a, 0x11, 0x00, 0x40, 0x0b, 0x0a, 0x01, 0x00
}; };
static uint8_t patch_line9[] = { static uint8_t patch_line9[] = {
0xf1, 0x80, 0x95, 0x17, 0xb6, 0x00, 0x95, 0x18, 0xb7, 0x00, 0xf1, 0x80, 0x95, 0x17, 0xb6, 0x00, 0x95, 0x18, 0xb7, 0x00,
0x76, 0xcf, 0xff, 0xff, 0xe5, 0x44, 0x96, 0x20, 0x95, 0x15, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x44, 0x96, 0x20, 0x95, 0x15,
0x08, 0x13, 0x00, 0x40, 0x0e, 0x1e, 0x01, 0x20, 0xd9, 0x00, 0x08, 0x13, 0x00, 0x40, 0x0e, 0x1e, 0x01, 0x20, 0xd9, 0x00,
0x95, 0x15, 0xb6, 0x00, 0xff, 0xa1, 0x75, 0xcf, 0xff, 0xff, 0x95, 0x15, 0xb6, 0x00, 0xff, 0xa1, 0x75, 0xcf, 0xff, 0xff,
0xe7, 0x1c, 0x77, 0xcf, 0xff, 0xff, 0xe5, 0x46, 0x97, 0x40 0xe7, 0x1c, 0x77, 0xcf, 0xff, 0xff, 0xe5, 0x46, 0x97, 0x40
}; };
static uint8_t patch_line10[] = { static uint8_t patch_line10[] = {
0xf1, 0xb0, 0x8d, 0x16, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x48, 0xf1, 0xb0, 0x8d, 0x16, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x48,
0x8d, 0x37, 0x08, 0x0d, 0x00, 0x81, 0x96, 0x40, 0x09, 0x15, 0x8d, 0x37, 0x08, 0x0d, 0x00, 0x81, 0x96, 0x40, 0x09, 0x15,
0x00, 0x80, 0x0f, 0xd6, 0x01, 0x00, 0x8d, 0x16, 0xb7, 0x00, 0x00, 0x80, 0x0f, 0xd6, 0x01, 0x00, 0x8d, 0x16, 0xb7, 0x00,
0x8d, 0x17, 0xb6, 0x00, 0xff, 0xb0, 0xff, 0xbc, 0x00, 0x41, 0x8d, 0x17, 0xb6, 0x00, 0xff, 0xb0, 0xff, 0xbc, 0x00, 0x41,
0x03, 0xc0, 0xc0, 0xf1, 0x0d, 0x9e, 0x01, 0x00, 0xe8, 0x04 0x03, 0xc0, 0xc0, 0xf1, 0x0d, 0x9e, 0x01, 0x00, 0xe8, 0x04
}; };
static uint8_t patch_line11[] = { static uint8_t patch_line11[] = {
0xf1, 0xe0, 0xff, 0x88, 0xf0, 0x0a, 0x0d, 0x6a, 0x01, 0x00, 0xf1, 0xe0, 0xff, 0x88, 0xf0, 0x0a, 0x0d, 0x6a, 0x01, 0x00,
0x0d, 0x8e, 0x01, 0x00, 0xe8, 0x7e, 0xff, 0x85, 0x0d, 0x72, 0x0d, 0x8e, 0x01, 0x00, 0xe8, 0x7e, 0xff, 0x85, 0x0d, 0x72,
0x01, 0x00, 0xff, 0x8c, 0xff, 0xa7, 0xff, 0xb2, 0xd8, 0x00, 0x01, 0x00, 0xff, 0x8c, 0xff, 0xa7, 0xff, 0xb2, 0xd8, 0x00,
0x73, 0xcf, 0xff, 0xff, 0xf2, 0x40, 0x23, 0x15, 0x00, 0x01, 0x73, 0xcf, 0xff, 0xff, 0xf2, 0x40, 0x23, 0x15, 0x00, 0x01,
0x81, 0x41, 0xe0, 0x02, 0x81, 0x20, 0x08, 0xf7, 0x81, 0x34 0x81, 0x41, 0xe0, 0x02, 0x81, 0x20, 0x08, 0xf7, 0x81, 0x34
}; };
static uint8_t patch_line12[] = { static uint8_t patch_line12[] = {
0xf2, 0x10, 0xa1, 0x40, 0xd8, 0x00, 0xc0, 0xd1, 0x7e, 0xe0, 0xf2, 0x10, 0xa1, 0x40, 0xd8, 0x00, 0xc0, 0xd1, 0x7e, 0xe0,
0x53, 0x51, 0x30, 0x34, 0x20, 0x6f, 0x6e, 0x5f, 0x73, 0x74, 0x53, 0x51, 0x30, 0x34, 0x20, 0x6f, 0x6e, 0x5f, 0x73, 0x74,
0x61, 0x72, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x61, 0x72, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d,
0x69, 0x6e, 0x67, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x0a, 0x69, 0x6e, 0x67, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
static uint8_t patch_line13[] = { static uint8_t patch_line13[] = {
0xf2, 0x40, 0xff, 0xff, 0xe8, 0x28, 0xff, 0xff, 0xf0, 0xe8, 0xf2, 0x40, 0xff, 0xff, 0xe8, 0x28, 0xff, 0xff, 0xf0, 0xe8,
0xff, 0xff, 0xe8, 0x08, 0xff, 0xff, 0xf1, 0x54 0xff, 0xff, 0xe8, 0x08, 0xff, 0xff, 0xf1, 0x54
}; };
/* Patch lines structure */ /* Patch lines structure */
@@ -175,19 +175,19 @@ struct mt9v117_patch_t {
}; };
static const struct mt9v117_patch_t mt9v117_patch_lines[MT9V117_PATCH_LINE_NUM] = { static const struct mt9v117_patch_t mt9v117_patch_lines[MT9V117_PATCH_LINE_NUM] = {
{patch_line1, sizeof(patch_line1)}, {patch_line1, sizeof(patch_line1)},
{patch_line2, sizeof(patch_line2)}, {patch_line2, sizeof(patch_line2)},
{patch_line3, sizeof(patch_line3)}, {patch_line3, sizeof(patch_line3)},
{patch_line4, sizeof(patch_line4)}, {patch_line4, sizeof(patch_line4)},
{patch_line5, sizeof(patch_line5)}, {patch_line5, sizeof(patch_line5)},
{patch_line6, sizeof(patch_line6)}, {patch_line6, sizeof(patch_line6)},
{patch_line7, sizeof(patch_line7)}, {patch_line7, sizeof(patch_line7)},
{patch_line8, sizeof(patch_line8)}, {patch_line8, sizeof(patch_line8)},
{patch_line9, sizeof(patch_line9)}, {patch_line9, sizeof(patch_line9)},
{patch_line10, sizeof(patch_line10)}, {patch_line10, sizeof(patch_line10)},
{patch_line11, sizeof(patch_line11)}, {patch_line11, sizeof(patch_line11)},
{patch_line12, sizeof(patch_line12)}, {patch_line12, sizeof(patch_line12)},
{patch_line13, sizeof(patch_line13)} {patch_line13, sizeof(patch_line13)}
}; };
/** /**
@@ -199,20 +199,17 @@ static void write_reg(struct mt9v117_t *mt, uint16_t addr, uint32_t val, uint16_
mt->i2c_trans.buf[1] = addr & 0xFF; mt->i2c_trans.buf[1] = addr & 0xFF;
// Fix sigdness based on length // Fix sigdness based on length
if(len == 1) { if (len == 1) {
mt->i2c_trans.buf[2] = val & 0xFF; mt->i2c_trans.buf[2] = val & 0xFF;
} } else if (len == 2) {
else if(len == 2) {
mt->i2c_trans.buf[2] = (val >> 8) & 0xFF; mt->i2c_trans.buf[2] = (val >> 8) & 0xFF;
mt->i2c_trans.buf[3] = val & 0xFF; mt->i2c_trans.buf[3] = val & 0xFF;
} } else if (len == 4) {
else if(len == 4) {
mt->i2c_trans.buf[2] = (val >> 24) & 0xFF; mt->i2c_trans.buf[2] = (val >> 24) & 0xFF;
mt->i2c_trans.buf[3] = (val >> 16) & 0xFF; mt->i2c_trans.buf[3] = (val >> 16) & 0xFF;
mt->i2c_trans.buf[4] = (val >> 8) & 0xFF; mt->i2c_trans.buf[4] = (val >> 8) & 0xFF;
mt->i2c_trans.buf[5] = val & 0xFF; mt->i2c_trans.buf[5] = val & 0xFF;
} } else {
else {
printf("[MT9V117] write_reg with incorrect length %d\r\n", len); printf("[MT9V117] write_reg with incorrect length %d\r\n", len);
} }
@@ -233,8 +230,8 @@ static uint32_t read_reg(struct mt9v117_t *mt, uint16_t addr, uint16_t len)
i2c_transceive(mt->i2c_periph, &mt->i2c_trans, MT9V117_ADDRESS, 2, len); i2c_transceive(mt->i2c_periph, &mt->i2c_trans, MT9V117_ADDRESS, 2, len);
/* Fix sigdness */ /* Fix sigdness */
for(uint8_t i =0; i < len; i++) { for (uint8_t i = 0; i < len; i++) {
ret |= mt->i2c_trans.buf[len-i-1] << (8*i); ret |= mt->i2c_trans.buf[len - i - 1] << (8 * i);
} }
return ret; return ret;
} }
@@ -283,7 +280,7 @@ static inline void mt9v117_write_patch(struct mt9v117_t *mt)
/* Write patch */ /* Write patch */
for (uint8_t i = 0; i < MT9V117_PATCH_LINE_NUM; ++i) { for (uint8_t i = 0; i < MT9V117_PATCH_LINE_NUM; ++i) {
// Copy buffer // Copy buffer
for(uint8_t j = 0; j < mt9v117_patch_lines[i].len; ++j) { for (uint8_t j = 0; j < mt9v117_patch_lines[i].len; ++j) {
mt->i2c_trans.buf[j] = mt9v117_patch_lines[i].data[j]; mt->i2c_trans.buf[j] = mt9v117_patch_lines[i].data[j];
} }
@@ -298,14 +295,14 @@ static inline void mt9v117_write_patch(struct mt9v117_t *mt)
write_reg(mt, MT9V117_COMMAND, MT9V117_COMMAND_OK | MT9V117_COMMAND_APPLY_PATCH, 2); write_reg(mt, MT9V117_COMMAND, MT9V117_COMMAND_OK | MT9V117_COMMAND_APPLY_PATCH, 2);
/* Wait for command OK */ /* Wait for command OK */
for(uint8_t retries = 100; retries > 0; retries--) { for (uint8_t retries = 100; retries > 0; retries--) {
/* Wait 10ms */ /* Wait 10ms */
usleep(10000); usleep(10000);
/* Check the command */ /* Check the command */
uint16_t cmd = read_reg(mt, MT9V117_COMMAND, 2); uint16_t cmd = read_reg(mt, MT9V117_COMMAND, 2);
if((cmd & MT9V117_COMMAND_APPLY_PATCH) == 0) { if ((cmd & MT9V117_COMMAND_APPLY_PATCH) == 0) {
if((cmd & MT9V117_COMMAND_OK) == 0) { if ((cmd & MT9V117_COMMAND_OK) == 0) {
printf("[MT9V117] Applying patch failed (No OK)\r\n"); printf("[MT9V117] Applying patch failed (No OK)\r\n");
} }
return; return;
@@ -316,7 +313,8 @@ static inline void mt9v117_write_patch(struct mt9v117_t *mt)
} }
/* Configure the sensor */ /* Configure the sensor */
static inline void mt9v117_config(struct mt9v117_t *mt) { static inline void mt9v117_config(struct mt9v117_t *mt)
{
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_X_ADDR_START_OFFSET, 16, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_X_ADDR_START_OFFSET, 16, 2);
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_X_ADDR_END_OFFSET, 663, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_X_ADDR_END_OFFSET, 663, 2);
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_Y_ADDR_START_OFFSET, 8, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_Y_ADDR_START_OFFSET, 8, 2);
@@ -324,7 +322,7 @@ static inline void mt9v117_config(struct mt9v117_t *mt) {
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_CPIPE_LAST_ROW_OFFSET, 243, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_CPIPE_LAST_ROW_OFFSET, 243, 2);
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_OFFSET, 283, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_OFFSET, 283, 2);
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CONTROL_READ_MODE_OFFSET, write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CONTROL_READ_MODE_OFFSET,
MT9V117_CAM_SENSOR_CONTROL_Y_SKIP_EN, 2); MT9V117_CAM_SENSOR_CONTROL_Y_SKIP_EN, 2);
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_MAX_FDZONE_60_OFFSET, 1, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_MAX_FDZONE_60_OFFSET, 1, 2);
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_TARGET_FDZONE_60_OFFSET, 1, 2); write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_SENSOR_CFG_TARGET_FDZONE_60_OFFSET, 1, 2);
@@ -396,8 +394,9 @@ void mt9v117_init(struct mt9v117_t *mt)
/* See if the device is there and correct */ /* See if the device is there and correct */
uint16_t chip_id = read_reg(mt, MT9V117_CHIP_ID, 2); uint16_t chip_id = read_reg(mt, MT9V117_CHIP_ID, 2);
if(chip_id != MT9V117_CHIP_ID_RESP) { if (chip_id != MT9V117_CHIP_ID_RESP) {
printf("[MT9V117] Didn't get correct response from CHIP_ID (expected: 0x%04X, got: 0x%04X)\r\n", MT9V117_CHIP_ID_RESP, chip_id); printf("[MT9V117] Didn't get correct response from CHIP_ID (expected: 0x%04X, got: 0x%04X)\r\n", MT9V117_CHIP_ID_RESP,
chip_id);
return; return;
} }
@@ -423,22 +422,22 @@ void mt9v117_init(struct mt9v117_t *mt)
/* Enable ITU656 */ /* Enable ITU656 */
write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_OUTPUT_FORMAT_OFFSET, write_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_OUTPUT_FORMAT_OFFSET,
read_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_OUTPUT_FORMAT_OFFSET, 2) | read_var(mt, MT9V117_CAM_CTRL_VAR, MT9V117_CAM_OUTPUT_FORMAT_OFFSET, 2) |
MT9V117_CAM_OUTPUT_FORMAT_BT656_ENABLE, 2); MT9V117_CAM_OUTPUT_FORMAT_BT656_ENABLE, 2);
/* Apply the configuration */ /* Apply the configuration */
write_var(mt, MT9V117_SYSMGR_VAR, MT9V117_SYSMGR_NEXT_STATE_OFFSET, MT9V117_SYS_STATE_ENTER_CONFIG_CHANGE, 1); write_var(mt, MT9V117_SYSMGR_VAR, MT9V117_SYSMGR_NEXT_STATE_OFFSET, MT9V117_SYS_STATE_ENTER_CONFIG_CHANGE, 1);
write_reg(mt, MT9V117_COMMAND, MT9V117_COMMAND_OK | MT9V117_COMMAND_SET_STATE, 2); write_reg(mt, MT9V117_COMMAND, MT9V117_COMMAND_OK | MT9V117_COMMAND_SET_STATE, 2);
/* Wait for command OK */ /* Wait for command OK */
for(uint8_t retries = 100; retries > 0; retries--) { for (uint8_t retries = 100; retries > 0; retries--) {
/* Wait 10ms */ /* Wait 10ms */
usleep(10000); usleep(10000);
/* Check the command */ /* Check the command */
uint16_t cmd = read_reg(mt, MT9V117_COMMAND, 2); uint16_t cmd = read_reg(mt, MT9V117_COMMAND, 2);
if((cmd & MT9V117_COMMAND_SET_STATE) == 0) { if ((cmd & MT9V117_COMMAND_SET_STATE) == 0) {
if((cmd & MT9V117_COMMAND_OK) == 0) { if ((cmd & MT9V117_COMMAND_OK) == 0) {
printf("[MT9V117] Switching config failed (No OK)\r\n"); printf("[MT9V117] Switching config failed (No OK)\r\n");
} }
+5 -5
View File
@@ -18,11 +18,11 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file boards/bebop/mt9v117.h * @file boards/bebop/mt9v117.h
* *
* Initialization and configuration of the MT9V117 CMOS Chip * Initialization and configuration of the MT9V117 CMOS Chip
*/ */
#ifndef MT9V117_H #ifndef MT9V117_H
#define MT9V117_H #define MT9V117_H
@@ -607,7 +607,8 @@ void image_show_flow(struct image_t *img, struct flow_t *vectors, uint16_t point
* @param[in] dx The gradient in x-direction * @param[in] dx The gradient in x-direction
* @param[in] dy The gradient in y-direction * @param[in] dy The gradient in y-direction
*/ */
void image_gradient_pixel(struct image_t *img, struct point_t *loc, int method, int *dx, int* dy) { void image_gradient_pixel(struct image_t *img, struct point_t *loc, int method, int *dx, int *dy)
{
// create the simple and sobel filter only once: // create the simple and sobel filter only once:
int gradient_x, gradient_y, index; int gradient_x, gradient_y, index;
@@ -620,48 +621,47 @@ void image_gradient_pixel(struct image_t *img, struct point_t *loc, int method,
uint8_t add_ind = pixel_width - 1; uint8_t add_ind = pixel_width - 1;
// check if all pixels will fall in the image: // check if all pixels will fall in the image:
if(loc->x >= 1 && (loc->x + 1) < img->w && loc->y >= 1 && (loc->y + 1) < img->h ) { if (loc->x >= 1 && (loc->x + 1) < img->w && loc->y >= 1 && (loc->y + 1) < img->h) {
if(method == 0) { if (method == 0) {
// ************* // *************
// Simple method // Simple method
// ************* // *************
// dx: // dx:
index = loc->y * img->w * pixel_width + (loc->x-1) * pixel_width; index = loc->y * img->w * pixel_width + (loc->x - 1) * pixel_width;
gradient_x -= (int) img_buf[index+add_ind]; gradient_x -= (int) img_buf[index + add_ind];
index = loc->y * img->w * pixel_width + (loc->x+1) * pixel_width; index = loc->y * img->w * pixel_width + (loc->x + 1) * pixel_width;
gradient_x += (int) img_buf[index+add_ind]; gradient_x += (int) img_buf[index + add_ind];
// dy: // dy:
index = (loc->y-1) * img->w * pixel_width + loc->x * pixel_width; index = (loc->y - 1) * img->w * pixel_width + loc->x * pixel_width;
gradient_y -= (int) img_buf[index+add_ind]; gradient_y -= (int) img_buf[index + add_ind];
index = (loc->y+1) * img->w * pixel_width + loc->x * pixel_width; index = (loc->y + 1) * img->w * pixel_width + loc->x * pixel_width;
gradient_y += (int) img_buf[index+add_ind]; gradient_y += (int) img_buf[index + add_ind];
} } else {
else {
// ***** // *****
// Sobel // Sobel
// ***** // *****
static int Sobel[9] = {-1, 0, 1, -2, 0, 2, -1, 0, 1}; static int Sobel[9] = { -1, 0, 1, -2, 0, 2, -1, 0, 1};
static int total_sobel = 8; static int total_sobel = 8;
int filt_ind_y = 0; int filt_ind_y = 0;
int filt_ind_x; int filt_ind_x;
for (int x = -1; x <= 1; x++) { for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
index = (loc->y + y) * img->w * pixel_width + (loc->x+x) * pixel_width; index = (loc->y + y) * img->w * pixel_width + (loc->x + x) * pixel_width;
if(x!=0) { if (x != 0) {
filt_ind_x = (x+1)%3 + (y+1)*3; filt_ind_x = (x + 1) % 3 + (y + 1) * 3;
gradient_x += Sobel[filt_ind_x] * (int) img_buf[index+add_ind]; gradient_x += Sobel[filt_ind_x] * (int) img_buf[index + add_ind];
} }
if(y!=0) { if (y != 0) {
gradient_y += Sobel[filt_ind_y] * (int) img_buf[index+add_ind]; gradient_y += Sobel[filt_ind_y] * (int) img_buf[index + add_ind];
} }
filt_ind_y++; filt_ind_y++;
}
} }
gradient_x /= total_sobel; }
gradient_x /= total_sobel;
} }
} }