Commit 8a8dc145 authored by Andrey Filippov's avatar Andrey Filippov

improved printout of the i2c read data (print_sensor_i2c command)

parent e3d8632e
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -940,6 +940,7 @@ mem_save "/usr/local/verilog/memdump_chn0" 0x27a00000 0x01001000 ...@@ -940,6 +940,7 @@ mem_save "/usr/local/verilog/memdump_chn0" 0x27a00000 0x01001000
write_sensor_i2c 0 1 0 0x91900004 write_sensor_i2c 0 1 0 0x91900004
read_sensor_i2c 0 read_sensor_i2c 0
print_sensor_i2c 0
set_sensor_i2c_table_reg_wr 0 0x00 0x48 3 100 1 set_sensor_i2c_table_reg_wr 0 0x00 0x48 3 100 1
set_sensor_i2c_table_reg_wr 0 0x90 0x48 3 100 1 set_sensor_i2c_table_reg_wr 0 0x90 0x48 3 100 1
...@@ -947,6 +948,7 @@ set_sensor_i2c_table_reg_rd 0 0x01 0 2 100 1 ...@@ -947,6 +948,7 @@ set_sensor_i2c_table_reg_rd 0 0x01 0 2 100 1
set_sensor_i2c_table_reg_rd 0 0x91 0 2 100 1 set_sensor_i2c_table_reg_rd 0 0x91 0 2 100 1
======== ========
cd /usr/local/verilog/; test_mcntrl.py @hargs
measure_all "*DI" measure_all "*DI"
setup_all_sensors True None 0xf setup_all_sensors True None 0xf
set_sensor_io_ctl 0 None None None None None 0 0x4 set_sensor_io_ctl 0 None None None None None 0 0x4
...@@ -963,7 +965,17 @@ axi_write_single_w 0x696 0x079800a3 ...@@ -963,7 +965,17 @@ axi_write_single_w 0x696 0x079800a3
axi_write_single_w 0x686 0x079800a3 axi_write_single_w 0x686 0x079800a3
axi_write_single_w 0x6a6 0x079800a3 axi_write_single_w 0x6a6 0x079800a3
axi_write_single_w 0x6b6 0x079800a3 axi_write_single_w 0x6b6 0x079800a3
r
compressor_control all 2
jpeg_write "img.jpeg" all
write_sensor_i2c 0 1 0 0x91900004
print_sensor_i2c 0
#r
""" """
...@@ -514,11 +514,13 @@ class X393Sensor(object): ...@@ -514,11 +514,13 @@ class X393Sensor(object):
def read_sensor_i2c (self, def read_sensor_i2c (self,
num_sensor, num_sensor,
num_bytes = None): num_bytes = None,
verbose = 0):
""" """
Read sequence of bytes available Read sequence of bytes available
@param num_sensor - sensor port number (0..3), or "all" - same to all sensors @param num_sensor - sensor port number (0..3), or "all" - same to all sensors
@param num_bytes - number of bytes to read (None - all in FIFO) @param num_bytes - number of bytes to read (None - all in FIFO)
@verbose - verbose level
@return list of read bytes @return list of read bytes
""" """
ODDEVEN="ODDEVEN" ODDEVEN="ODDEVEN"
...@@ -547,7 +549,7 @@ class X393Sensor(object): ...@@ -547,7 +549,7 @@ class X393Sensor(object):
self. set_sensor_i2c_command ( self. set_sensor_i2c_command (
num_sensor = num_sensor, num_sensor = num_sensor,
advance_FIFO = True, advance_FIFO = True,
verbose = 1) verbose = verbose)
# wait until odd/even bit reverses (no timeout here) # wait until odd/even bit reverses (no timeout here)
while d[ODDEVEN] == oddeven: while d[ODDEVEN] == oddeven:
d = read_i2c_data(num_sensor) d = read_i2c_data(num_sensor)
...@@ -555,6 +557,52 @@ class X393Sensor(object): ...@@ -555,6 +557,52 @@ class X393Sensor(object):
break # read all that was requested (num_bytes == None will not get here) break # read all that was requested (num_bytes == None will not get here)
return rslt return rslt
def print_sensor_i2c (self,
num_sensor,
reg_addr,
indx = 1,
sa7 = 0x48,
verbose = 0):
"""
Read sequence of bytes available and print the result as a single hex number
@param num_sensor - sensor port number (0..3), or "all" - same to all sensors
@param reg_addr - register to read address 1/2 bytes (defined by previously set format)
@param indx - i2c command index in 1 256-entry table (defines here i2c delay, number of address bytes and number of data bytes)
@param sa7 - 7-bit i2c slave address
@param verbose - verbose level
"""
#clean up FIFO
dl = self.read_sensor_i2c (num_sensor = num_sensor,
num_bytes = None,
verbose = verbose)
if len(dl):
d = 0
for b in dl:
d = (d << 8) | (b & 0xff)
fmt="FIFO contained %d bytes i2c data = 0x%%0%dx"%(len(dl),len(dl*2))
print (fmt%(d))
#create and send i2c command in ASAP mode:
i2c_cmd = ((indx & 0xff) << 24) | (sa7 <<17) | (reg_addr & 0xffff)
#write_sensor_i2c 0 1 0 0x91900004
self.write_sensor_i2c(num_sensor = num_sensor,
rel_addr = 1,
addr = 0,
data = i2c_cmd)
time.sleep(0.05) # We do not know how many bytes are expected, so just wait long enough and hope all bytes are in fifo already
dl = self.read_sensor_i2c (num_sensor = num_sensor,
num_bytes = None,
verbose = verbose)
if len(dl):
d = 0
for b in dl:
d = (d << 8) | (b & 0xff)
fmt="i2c data[0x%02x:0x%x] = 0x%%0%dx"%(sa7,reg_addr,len(dl)*2)
print (fmt%(d))
def set_sensor_io_ctl (self, def set_sensor_io_ctl (self,
num_sensor, num_sensor,
mrst = None, mrst = None,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment