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
+18 -19
View File
@@ -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);
@@ -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;
} }
@@ -431,14 +430,14 @@ void mt9v117_init(struct mt9v117_t *mt)
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,43 +621,42 @@ 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++;
} }