-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcci_read.c
138 lines (118 loc) · 3.82 KB
/
cci_read.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* cci_read: command line utility for monoSensor sensor
* Copyright (c) 2017, Inforce Computing Inc.
*
* Author : Akhil Xavier <akhilxavier@inforcecomputing.com>
*
* This program "WriteMac.py" is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; only version 2 of the License .
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdio.h>
#include <dlfcn.h>
#include <math.h>
#include <asm-generic/errno-base.h>
#include <poll.h>
#include "sensor.h"
#include "modules.h"
#include "mct_pipeline.h"
#include "mct_module.h"
#include "module_sensor.h"
#include "mct_stream.h"
#include <media/msm_cam_sensor.h>
#define H2C_DATA_8BIT 1
#define H2C_DATA_16BIT 2
#define H2C_DATA_32BIT 4
enum msm_camera_i2c_cmd_type {
MSM_CAMERA_I2C_CMD_WRITE,
MSM_CAMERA_I2C_CMD_POLL,
};
uint32_t parse_i2c_address(const char *address_arg)
{
long address;
char *end;
address = strtol(address_arg, &end, 0);
if (*end || !*address_arg) {
printf("Error:address is not a number!\n");
return -1;
}
return address;
}
uint32_t parse_i2c_data(const char *address_arg)
{
long data;
char *end;
data = strtol(address_arg, &end, 0);
if (*end || !*address_arg) {
printf("Error:data entered is not valid !!!!\n");
return -1;
}
return data;
}
uint32_t parse_i2c_type(const char *address_arg)
{
long dt;
char *end;
dt = strtol(address_arg, &end, 0);
if (*end || !*address_arg) {
printf("Error:data type invalid!!!\n");
return -1;
}
return dt;
}
int main(int argc, char *argv[])
{
int fd;
struct sensorb_cfg_data *cdata;
struct sensor_ctrl_t *ctrl;
uint16_t r_addr = 0;
struct msm_camera_i2c_read_config *monoSensor_read_settings = NULL;
cdata = malloc(sizeof(struct sensorb_cfg_data));
monoSensor_read_settings = malloc(sizeof(struct msm_camera_i2c_read_config));
if (!cdata || !monoSensor_read_settings) {
printf("malloc failed\n");
goto ERROR;
}
/*Checking required parameters */
if(argc < 3){
printf("Enter all the required parameters in the below format:\n");
printf("./cci_read <slavaddr> <addr> <no of bytes> \n");
printf("\t\tExample: ./cci_read 0x0004 2\t\t\n");
goto ERROR;
}
/* Open subdev */
fd = open("/dev/v4l-subdev16", O_RDWR);
if (fd < 0) {
printf("Device open /dev/v4l-subdev16 failed \n");
goto ERROR;
}
monoSensor_read_settings->reg_addr = parse_i2c_address(argv[1]);
if(monoSensor_read_settings->reg_addr >=0) {
printf("Register to read = 0x%x\n",monoSensor_read_settings->reg_addr);
} else {
printf("Enter Valid Register address !!!\n");
goto ERROR;
}
monoSensor_read_settings->data_type = parse_i2c_type(argv[2]);
if(monoSensor_read_settings->data_type == 1 || monoSensor_read_settings->data_type == 2) {
printf("No. of Bytes = %d\n",monoSensor_read_settings->data_type);
} else {
printf("Invalid No of bytes Enter 1/2 !!!\n");
goto ERROR;
}
cdata->cfgtype = CFG_READ_MONO_REG;
cdata->cfg.setting = monoSensor_read_settings;
if (ioctl(fd, VIDIOC_MSM_SENSOR_CFG, cdata) < 0) {
printf(" IOCTL call failed !!!\n");
goto ERROR;
}
printf("\t\t\t!!!! READ SUCCESS - Read Value = 0x%x !!!!\t\t\t\n", monoSensor_read_settings->data);
return 0;
ERROR:
printf(" Program failed .. Exiting !!!\n");
return 0;
}