nvapi_sys/i2c.rs
1use status::NvAPI_Status;
2use handles::NvPhysicalGpuHandle;
3
4pub const NVAPI_MAX_SIZEOF_I2C_DATA_BUFFER: usize = 4096;
5pub const NVAPI_MAX_SIZEOF_I2C_REG_ADDRESS: usize = 4;
6pub const NVAPI_DISPLAY_DEVICE_MASK_MAX: usize = 24;
7pub const NVAPI_I2C_SPEED_DEPRECATED: u32 = 0xffff;
8
9nvenum! {
10 pub enum NV_I2C_SPEED / I2cSpeed {
11 NVAPI_I2C_SPEED_DEFAULT / Default = 0,
12 NVAPI_I2C_SPEED_3KHZ / _3Khz = 1,
13 NVAPI_I2C_SPEED_10KHZ / _10Khz = 2,
14 NVAPI_I2C_SPEED_33KHZ / _33Khz = 3,
15 NVAPI_I2C_SPEED_100KHZ / _100Khz = 4,
16 NVAPI_I2C_SPEED_200KHZ / _200Khz = 5,
17 NVAPI_I2C_SPEED_400KHZ / _400Khz = 6,
18 }
19}
20
21nvenum_display! {
22 I2cSpeed => {
23 _3Khz = "3 kHz",
24 _10Khz = "10 kHz",
25 _33Khz = "33 kHz",
26 _100Khz = "100 kHz",
27 _200Khz = "200 kHz",
28 _400Khz = "400 kHz",
29 _ = _,
30 }
31}
32
33nvstruct! {
34 /// Used in NvAPI_I2CRead() and NvAPI_I2CWrite()
35 pub struct NV_I2C_INFO_V1 {
36 /// The structure version.
37 pub version: u32,
38 /// The Display Mask of the concerned display.
39 pub displayMask: u32,
40 /// This flag indicates either the DDC port (TRUE) or the communication port
41 /// (FALSE) of the concerned display.
42 pub bIsDDCPort: u8,
43 /// The address of the I2C slave. The address should be shifted left by one. Fo
44 /// example, the I2C address 0x50, often used for reading EDIDs, would be stored
45 /// here as 0xA0. This matches the position within the byte sent by the master,
46 /// the last bit is reserved to specify the read or write direction.
47 pub i2cDevAddress: u8,
48 /// The I2C target register address. May be NULL, which indicates no register
49 /// address should be sent.
50 pub pbI2cRegAddress: *mut u8,
51 /// The size in bytes of target register address. If pbI2cRegAddress is NULL, this
52 /// field must be 0.
53 pub regAddrSize: u32,
54 /// The buffer of data which is to be read or written (depending on the command).
55 pub pbData: *mut u8,
56 /// The size of the data buffer, pbData, to be read or written.
57 pub cbSize: u32,
58 /// The target speed of the transaction (between 28Kbps to 40Kbps; not guaranteed).
59 ///
60 /// Deprecated in V2+. Must be set to `NVAPI_I2C_SPEED_DEPRECATED`.
61 pub i2cSpeed: u32,
62 }
63}
64
65#[cfg(target_pointer_width = "64")]
66const NV_I2C_INFO_V1_SIZE: usize = 4 * 2 + (1 * 2) + 6 + 8 + 4 + 4 + 8 + 4 * 2;
67#[cfg(target_pointer_width = "32")]
68const NV_I2C_INFO_V1_SIZE: usize = 4 * 2 + (1 * 2) + 2 + 4 + 4 + 4 + 4 * 2;
69
70nvstruct! {
71 /// Used in NvAPI_I2CRead() and NvAPI_I2CWrite()
72 pub struct NV_I2C_INFO_V2 {
73 /*
74 /// Must set `v1.i2cSpeed = NVAPI_I2C_SPEED_DEPRECATED`.
75 pub v1: NV_I2C_INFO_V1,
76 */
77 /// The structure version.
78 pub version: u32,
79 /// The Display Mask of the concerned display.
80 pub displayMask: u32,
81 /// This flag indicates either the DDC port (TRUE) or the communication port
82 /// (FALSE) of the concerned display.
83 pub bIsDDCPort: u8,
84 /// The address of the I2C slave. The address should be shifted left by one. Fo
85 /// example, the I2C address 0x50, often used for reading EDIDs, would be stored
86 /// here as 0xA0. This matches the position within the byte sent by the master,
87 /// the last bit is reserved to specify the read or write direction.
88 pub i2cDevAddress: u8,
89 /// The I2C target register address. May be NULL, which indicates no register
90 /// address should be sent.
91 pub pbI2cRegAddress: *mut u8,
92 /// The size in bytes of target register address. If pbI2cRegAddress is NULL, this
93 /// field must be 0.
94 pub regAddrSize: u32,
95 /// The buffer of data which is to be read or written (depending on the command).
96 pub pbData: *mut u8,
97 /// The size of the data buffer, pbData, to be read or written.
98 pub cbSize: u32,
99 /// Deprecated - must be set to `NVAPI_I2C_SPEED_DEPRECATED`.
100 pub i2cSpeed: u32,
101 /// The target speed of the transaction in (kHz) (Chosen from the enum `NV_I2C_SPEED`).
102 pub i2cSpeedKhz: NV_I2C_SPEED,
103 }
104}
105
106#[cfg(target_pointer_width = "64")]
107const NV_I2C_INFO_V2_SIZE: usize = NV_I2C_INFO_V1_SIZE + 4 + 4;
108#[cfg(target_pointer_width = "32")]
109const NV_I2C_INFO_V2_SIZE: usize = NV_I2C_INFO_V1_SIZE + 4;
110
111nvstruct! {
112 /// Used in NvAPI_I2CRead() and NvAPI_I2CWrite()
113 pub struct NV_I2C_INFO_V3 {
114 //pub v2: NV_I2C_INFO_V2,
115 /// The structure version.
116 pub version: u32,
117 /// The Display Mask of the concerned display.
118 pub displayMask: u32,
119 /// This flag indicates either the DDC port (TRUE) or the communication port
120 /// (FALSE) of the concerned display.
121 pub bIsDDCPort: u8,
122 /// The address of the I2C slave. The address should be shifted left by one. Fo
123 /// example, the I2C address 0x50, often used for reading EDIDs, would be stored
124 /// here as 0xA0. This matches the position within the byte sent by the master,
125 /// the last bit is reserved to specify the read or write direction.
126 pub i2cDevAddress: u8,
127 /// The I2C target register address. May be NULL, which indicates no register
128 /// address should be sent.
129 pub pbI2cRegAddress: *mut u8,
130 /// The size in bytes of target register address. If pbI2cRegAddress is NULL, this
131 /// field must be 0.
132 pub regAddrSize: u32,
133 /// The buffer of data which is to be read or written (depending on the command).
134 pub pbData: *mut u8,
135 /// The size of the data buffer, pbData, to be read or written.
136 pub cbSize: u32,
137 /// Deprecated - must be set to `NVAPI_I2C_SPEED_DEPRECATED`.
138 pub i2cSpeed: u32,
139 /// The target speed of the transaction in (kHz) (Chosen from the enum `NV_I2C_SPEED`).
140 pub i2cSpeedKhz: NV_I2C_SPEED,
141 /// The portid on which device is connected (remember to set bIsPortIdSet if this value is set)
142 ///
143 /// Optional for pre-Kepler
144 pub portId: u8,
145 /// set this flag on if and only if portid value is set
146 pub bIsPortIdSet: u32,
147 }
148}
149
150const NV_I2C_INFO_V3_SIZE: usize = NV_I2C_INFO_V2_SIZE + 1 + 3 + 4;
151
152pub type NV_I2C_INFO = NV_I2C_INFO_V3;
153
154nvversion! { NV_I2C_INFO_VER1(NV_I2C_INFO_V1 = NV_I2C_INFO_V1_SIZE, 1) }
155nvversion! { NV_I2C_INFO_VER2(NV_I2C_INFO_V2 = NV_I2C_INFO_V2_SIZE, 2) }
156nvversion! { NV_I2C_INFO_VER3(NV_I2C_INFO_V3 = NV_I2C_INFO_V3_SIZE, 3) }
157nvversion! { NV_I2C_INFO_VER = NV_I2C_INFO_VER3 }
158
159nvapi! {
160 pub type NvAPI_I2CReadFn = extern "C" fn(hPhysicalGpu: NvPhysicalGpuHandle, pI2cInfo: *mut NV_I2C_INFO) -> NvAPI_Status;
161
162 /// This function reads the data buffer from the I2C port.
163 /// The I2C request must be for a DDC port: pI2cInfo->bIsDDCPort = 1.
164 ///
165 /// A data buffer size larger than 16 bytes may be rejected if a register address is specified. In such a case,
166 /// NVAPI_ARGUMENT_EXCEED_MAX_SIZE would be returned.
167 ///
168 /// If a register address is specified (i.e. regAddrSize is positive), then the transaction will be performed in
169 /// the combined format described in the I2C specification. The register address will be written, followed by
170 /// reading into the data buffer.
171 ///
172 /// # Returns
173 ///
174 /// - `NVAPI_OK`: Completed request
175 /// - `NVAPI_ERROR`: Miscellaneous error occurred.
176 /// - `NVAPI_HANDLE_INVALIDATED`: Handle passed has been invalidated (see user guide).
177 /// - `NVAPI_EXPECTED_PHYSICAL_GPU_HANDLE`: Handle passed is not a physical GPU handle.
178 /// - `NVAPI_INCOMPATIBLE_STRUCT_VERSION`: Structure version is not supported.
179 /// - `NVAPI_INVALID_ARGUMENT`: argument does not meet specified requirements
180 /// - `NVAPI_ARGUMENT_EXCEED_MAX_SIZE`: an argument exceeds the maximum
181 pub unsafe fn NvAPI_I2CRead;
182}
183
184nvapi! {
185 pub type NvAPI_I2CWriteFn = extern "C" fn(hPhysicalGpu: NvPhysicalGpuHandle, pI2cInfo: *mut NV_I2C_INFO) -> NvAPI_Status;
186
187 /// This function writes the data buffer to the I2C port.
188 ///
189 /// The I2C request must be for a DDC port: pI2cInfo->bIsDDCPort = 1.
190 ///
191 /// A data buffer size larger than 16 bytes may be rejected if a register address is specified. In such a case,
192 /// NVAPI_ARGUMENT_EXCEED_MAX_SIZE would be returned.
193 ///
194 /// If a register address is specified (i.e. regAddrSize is positive), then the register address will be written
195 /// and the data buffer will immediately follow without a restart.
196 ///
197 /// # Returns
198 ///
199 /// - `NVAPI_OK`: Completed request
200 /// - `NVAPI_ERROR`: Miscellaneous error occurred.
201 /// - `NVAPI_HANDLE_INVALIDATED`: Handle passed has been invalidated (see user guide).
202 /// - `NVAPI_EXPECTED_PHYSICAL_GPU_HANDLE`: Handle passed is not a physical GPU handle.
203 /// - `NVAPI_INCOMPATIBLE_STRUCT_VERSION`: Structure version is not supported.
204 /// - `NVAPI_INVALID_ARGUMENT`: Argument does not meet specified requirements
205 /// - `NVAPI_ARGUMENT_EXCEED_MAX_SIZE`: exceeds the maximum
206 pub unsafe fn NvAPI_I2CWrite;
207}
208
209/// Undocumented API
210pub mod private {
211 use status::NvAPI_Status;
212 use handles::NvPhysicalGpuHandle;
213 use super::NV_I2C_SPEED;
214
215 nvstruct! {
216 /// Used in NvAPI_I2CRead() and NvAPI_I2CWrite()
217 pub struct NV_I2C_INFO_EX_V3 {
218 /// The structure version.
219 pub version: u32,
220 /// The Display Mask of the concerned display.
221 pub displayMask: u32,
222 /// This flag indicates either the DDC port (TRUE) or the communication port
223 /// (FALSE) of the concerned display.
224 pub bIsDDCPort: u8,
225 /// The address of the I2C slave. The address should be shifted left by one. Fo
226 /// example, the I2C address 0x50, often used for reading EDIDs, would be stored
227 /// here as 0xA0. This matches the position within the byte sent by the master,
228 /// the last bit is reserved to specify the read or write direction.
229 pub i2cDevAddress: u8,
230 /// The I2C target register address. May be NULL, which indicates no register
231 /// address should be sent.
232 pub pbI2cRegAddress: *mut u8,
233 /// The size in bytes of target register address. If pbI2cRegAddress is NULL, this
234 /// field must be 0.
235 pub regAddrSize: u32,
236 /// The buffer of data which is to be read or written (depending on the command).
237 pub pbData: *mut u8,
238 /// bytes to read ??? seems required on write too
239 pub pbRead: u32,
240 /// The size of the data buffer, pbData, to be read or written.
241 pub cbSize: u32,
242 /// The target speed of the transaction in (kHz) (Chosen from the enum `NV_I2C_SPEED`).
243 pub i2cSpeedKhz: NV_I2C_SPEED,
244 /// The portid on which device is connected (remember to set bIsPortIdSet if this value is set)
245 ///
246 /// Optional for pre-Kepler
247 pub portId: u8,
248 /// set this flag on if and only if portid value is set
249 pub bIsPortIdSet: u32,
250 }
251 }
252
253 #[cfg(target_pointer_width = "64")]
254 const NV_I2C_INFO_EX_V3_SIZE: usize = 4 * 2 + (1 * 2) + 6 + 8 + 4 + 4 + 8 + 4 * 3 + 1 + 3 + 4 + 4;
255 #[cfg(target_pointer_width = "32")]
256 const NV_I2C_INFO_EX_V3_SIZE: usize = 4 * 2 + (1 * 2) + 2 + 4 + 4 + 4 + 4 * 3 + 1 + 3 + 4;
257
258 pub type NV_I2C_INFO_EX = NV_I2C_INFO_EX_V3;
259
260 nvversion! { NV_I2C_INFO_EX_VER3(NV_I2C_INFO_EX_V3 = NV_I2C_INFO_EX_V3_SIZE, 3) }
261 nvversion! { NV_I2C_INFO_EX_VER = NV_I2C_INFO_EX_VER3 }
262
263 nvapi! {
264 pub type NvAPI_I2CReadExFn = extern "C" fn(hPhysicalGpu: NvPhysicalGpuHandle, pI2cInfo: *mut NV_I2C_INFO_EX, pData: *mut u32) -> NvAPI_Status;
265
266 /// Undocumented function. `pData` is often `{ 1, 0 }`?
267 pub unsafe fn NvAPI_I2CReadEx;
268 }
269
270 nvapi! {
271 pub type NvAPI_I2CWriteExFn = extern "C" fn(hPhysicalGpu: NvPhysicalGpuHandle, pI2cInfo: *mut NV_I2C_INFO_EX, pData: *mut u32) -> NvAPI_Status;
272
273 /// Undocumented function. `pData` is often `{ 1, 0 }`?
274 pub unsafe fn NvAPI_I2CWriteEx;
275 }
276}