-
Notifications
You must be signed in to change notification settings - Fork 3
/
i2cCommands.h
120 lines (101 loc) · 3.63 KB
/
i2cCommands.h
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
/* NVIDIA CORPORATION gave permission to FLIR Systems, Inc to modify this code
* and distribute it as part of the ADAS GMSL Kit.
* http://www.flir.com/
* October-2019
*/
/* Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#ifndef _I2C_INTERFACE_
#define _I2C_INTERFACE_
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "nvmedia_core.h"
#include "nvmedia_surface.h"
#include "testutil_i2c.h"
#include "log_utils.h"
#define MAX_BUF_LENGTH 34 // to handle 32 byte data + 2 bytes sub address
#define MAX_NUM_COMMANDS 10000
#define MAX_NUM_GROUPS 10
typedef enum {
WRITE_REG_1 = 0, // 1 byte register address to write
WRITE_REG_2, // 2 byte register address to write
READ_REG_1, // 1 byte register address to read
READ_REG_2, // 2 byte register address to read
DELAY, // Delay between commands
I2C_DEVICE, // I2c device number
I2C_ERR, // I2c Error Check
SECTION_START, // Indicate the start of a group/preset registers section
SECTION_STOP, // Indicate the end of a group/preset registers section
READ_WRITE_REG_1, // 1 byte registers to read and write
READ_WRITE_REG_2, // 2 byte registers to read and write
} CommandType;
typedef enum {
DEFAULT = 0,
GROUP_REG,
PRESET_REG
} ProcessType;
typedef enum {
I2C_READ = 0,
I2C_WRITE
} I2cOperation;
typedef struct {
CommandType commandType;
ProcessType processType;
uint8_t buffer[MAX_BUF_LENGTH];
union {
uint32_t deviceAddress;
uint32_t delay;
int i2cDevice;
int triggerFrame;
NvMediaBool i2cErr;
};
uint8_t dataLength; // support multiple bytes data for i2c write
} Command;
typedef struct {
uint32_t firstCommand;
uint32_t numCommands;
} GroupData;
typedef struct {
Command commands[MAX_NUM_COMMANDS];
uint32_t numCommands;
} I2cCommands;
typedef struct {
GroupData groups[MAX_NUM_GROUPS];
uint32_t numGroups;
} I2cGroups;
NvMediaStatus
I2cSetupGroups(I2cCommands *allCommands,
I2cGroups *allGroups);
NvMediaStatus
I2cProcessCommands(I2cCommands *allCommands,
I2cOperation operation,
int i2cDevice);
uint8_t *
I2cSetupRegister(I2cCommands *allCommands,
CommandType type,
uint32_t deviceAddress,
uint8_t *regAddress,
uint8_t *valueToWrite,
uint32_t dataRegLen);
NvMediaStatus
I2cProcessGroup(I2cHandle handle,
I2cCommands *allCommands,
GroupData *grpData);
NvMediaStatus
I2cProcessInitialRegisters(I2cCommands *allCommands,
int i2cDevice);
uint32_t
I2cGetNumCommands(I2cCommands *allCommands);
void
I2cSetNumCommands(I2cCommands *allCommands,
uint32_t setNumCommands);
#endif