API reference
ctsgen3.i2c.i2c
I2C_ADDR = 98
module-attribute
Default 7-bit I2C address of the CTS device.
HEADER_SIZE = 4
module-attribute
Bytes in the I2C protocol header (feature, command, length LSB/MSB).
CRC_SIZE = 2
module-attribute
Bytes used for CRC at the end of each I2C packet.
I2C_SPEED = 100
module-attribute
I2C speed in kHz for FT4222 initialization.
FEATURE_CTS = 128
module-attribute
CTS supported commands
CMD_CTS_RESET = 1
module-attribute
Soft-reset the CTS
CMD_CTS_GET_I2C_STATUS = 2
module-attribute
Get the I2C bus status
CMD_CTS_CV_RESET = 3
module-attribute
Soft-reset CV
FEATURE_MEM_REG = 138
module-attribute
Register memory access
CMD_MEM_READ = 1
module-attribute
Read from memory
CMD_MEM_WRITE = 2
module-attribute
Write to memory
I2CSlaveInterface
Interface to communicate with a CTS-compatible I2C slave device using FT4222. Handles packet formatting, CRC validation, and memory read/write operations.
Source code in src/ctsgen3/i2c/i2c.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
CRCError
Raised when CRC validation fails in I2C transfer.
Source code in src/ctsgen3/i2c/i2c.py
151 152 | |
init_i2c()
Initializes FT4222 as an I2C master and sets read/write timeouts.
Raises:
| Type | Description |
|---|---|
FT4222DeviceError
|
If initialization or timeout setting fails. |
Source code in src/ctsgen3/i2c/i2c.py
154 155 156 157 158 159 160 161 162 | |
close_i2c()
Initializes FT4222 as an I2C master and sets read/write timeouts.
Raises:
| Type | Description |
|---|---|
FT4222DeviceError
|
If initialization or timeout setting fails. |
Source code in src/ctsgen3/i2c/i2c.py
164 165 166 167 168 169 170 171 | |
set_timeouts(read_timeout_ms, write_timeout_ms)
Update read and write timeouts for FT4222 I2C operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
read_timeout_ms
|
int
|
Read timeout in milliseconds. |
required |
write_timeout_ms
|
int
|
Write timeout in milliseconds. |
required |
Source code in src/ctsgen3/i2c/i2c.py
173 174 175 176 177 178 179 180 181 182 183 | |
wait_for_i2c_idle(timeout=0.5, poll_interval=0.001)
Wait for the I2C controller to become IDLE before sending a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Max time in seconds to wait. |
0.5
|
poll_interval
|
float
|
Interval between status polls. |
0.001
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if idle detected, False if timeout occurs. |
Source code in src/ctsgen3/i2c/i2c.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
print_i2c_status(status_byte)
Decode and print human-readable I²C status flags.
Source code in src/ctsgen3/i2c/i2c.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
raw_write(raw_packet)
Send exactly these bytes, CRC or no CRC, directly on the bus.
Source code in src/ctsgen3/i2c/i2c.py
264 265 266 267 268 269 270 | |
write(feature, command, length, payload)
Send a command packet to the slave device via I2C.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
int
|
Feature ID. |
required |
command
|
int
|
Command ID. |
required |
length
|
int
|
Length of payload. |
required |
payload
|
bytes
|
Payload data. |
required |
Source code in src/ctsgen3/i2c/i2c.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
read(feature, command, read_length, payload)
Send a command and read back a response from the slave.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
int
|
Feature ID. |
required |
command
|
int
|
Command ID. |
required |
read_length
|
int
|
Expected length of memory data. |
required |
payload
|
bytes
|
Payload to send with request. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Response payload excluding header and CRC. |
Source code in src/ctsgen3/i2c/i2c.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
write_mem(feature, mem_address, mem_data)
Write a memory region on the device via feature command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
int
|
Feature register index. |
required |
mem_address
|
int
|
16-bit memory address to write. |
required |
mem_data
|
bytes
|
data to write to memory. |
required |
Source code in src/ctsgen3/i2c/i2c.py
316 317 318 319 320 321 322 323 324 325 326 327 328 | |
read_mem(feature, mem_address, mem_length)
Read a memory region from the device via feature command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
int
|
Feature register index. |
required |
mem_address
|
int
|
16-bit memory address to read from. |
required |
mem_length
|
int
|
Number of bytes to read from memory. This will be different from the packet payload length! |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Raw memory contents. |
Source code in src/ctsgen3/i2c/i2c.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |