Commit d2868135 authored by Andrey Filippov's avatar Andrey Filippov

more paramteres controlled over querry string

parent a69b7a9b
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
-f /usr/local/verilog/x393_parameters.vh /usr/local/verilog/x393_cur_params_target.vh /usr/local/verilog/x393_localparams.vh -f /usr/local/verilog/x393_parameters.vh /usr/local/verilog/x393_cur_params_target.vh /usr/local/verilog/x393_localparams.vh
-l /usr/local/verilog/x393_cur_params_target.vh -l /usr/local/verilog/x393_cur_params_target.vh
-p PICKLE="/usr/local/verilog/x393_mcntrl.pickle -p PICKLE="/usr/local/verilog/x393_mcntrl.pickle
-c copy /usr/local/bin/imgsrv.py /www/pages
-i -i
\ No newline at end of file
...@@ -40,6 +40,13 @@ import sys ...@@ -40,6 +40,13 @@ import sys
path="/www/pages/img.jpeg" path="/www/pages/img.jpeg"
PORT=8888 PORT=8888
def communicate(port,snd_str):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', port))
sock.send(snd_str)
reply = sock.recv(16384) # limit reply to 16K
sock.close()
return reply
try: try:
qs=urlparse.parse_qs(os.environ['QUERY_STRING']) qs=urlparse.parse_qs(os.environ['QUERY_STRING'])
except: except:
...@@ -51,15 +58,22 @@ acquisition_parameters={ ...@@ -51,15 +58,22 @@ acquisition_parameters={
"file_path": "img.jpeg", "file_path": "img.jpeg",
"channel": "0", "channel": "0",
"cmode": "0", "cmode": "0",
"bayer": "None", "bayer": None,
"y_quality": "None", "y_quality": None,
"c_quality": "None", "c_quality": None,
"portrait": "None", "portrait": None,
"gamma": "None", "gamma": None,
"black": "None", "black": None,
"colorsat_blue":"None", "colorsat_blue":None,
"colorsat_red": "None", "colorsat_red": None,
"server_root": "/www/pages/", "server_root": "/www/pages/",
"gain_r": None,
"gain_gr": None,
"gain_gb": None,
"gain_b": None,
"expos": None,
"flip_x": None,
"flip_y": None,
"verbose": "0"} "verbose": "0"}
for k in qs: for k in qs:
if k == "cmode": if k == "cmode":
...@@ -69,6 +83,18 @@ for k in qs: ...@@ -69,6 +83,18 @@ for k in qs:
acquisition_parameters[k] = "0" acquisition_parameters[k] = "0"
else: else:
acquisition_parameters[k] = qs[k][0] acquisition_parameters[k] = qs[k][0]
#correct bayer (if specified) for flips
if ((not acquisition_parameters["bayer"] is None) and
((not acquisition_parameters["flip_x"] is None) or
(not acquisition_parameters["flip_y"] is None))):
ibayer= int (acquisition_parameters["bayer"])
if acquisition_parameters["flip_x"]:
if int (acquisition_parameters["flip_x"]):
ibayer ^= 1
if int (acquisition_parameters["flip_y"]):
ibayer ^= 2
acquisition_parameters["bayer"] = str(ibayer)
cmd_str = "jpeg_acquire_write %s %s %s %s %s %s %s %s %s %s %s %s %s"%( cmd_str = "jpeg_acquire_write %s %s %s %s %s %s %s %s %s %s %s %s %s"%(
str(acquisition_parameters["file_path"]), str(acquisition_parameters["file_path"]),
str(acquisition_parameters["channel"]), str(acquisition_parameters["channel"]),
...@@ -83,13 +109,51 @@ cmd_str = "jpeg_acquire_write %s %s %s %s %s %s %s %s %s %s %s %s %s"%( ...@@ -83,13 +109,51 @@ cmd_str = "jpeg_acquire_write %s %s %s %s %s %s %s %s %s %s %s %s %s"%(
str(acquisition_parameters["colorsat_red"]), str(acquisition_parameters["colorsat_red"]),
str(acquisition_parameters["server_root"]), str(acquisition_parameters["server_root"]),
str(acquisition_parameters["verbose"])) str(acquisition_parameters["verbose"]))
gains_exp_changed = False
geometry_changed = False
#change gains/exposure if needed
if ((not acquisition_parameters["gain_r"] is None) or
(not acquisition_parameters["gain_gr"] is None) or
(not acquisition_parameters["gain_gb"] is None) or
(not acquisition_parameters["gain_b"] is None) or
(not acquisition_parameters["expos"] is None)):
gains_exp_changed = True
gstr = "set_sensor_gains_exposure %s %s %s %s %s %s %s"%(
str(acquisition_parameters["channel"]),
str(acquisition_parameters["gain_r"]),
str(acquisition_parameters["gain_gr"]),
str(acquisition_parameters["gain_gb"]),
str(acquisition_parameters["gain_b"]),
str(acquisition_parameters["expos"]),
str(acquisition_parameters["verbose"]))
communicate(PORT, gstr)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #change flips if needed
sock.connect(('localhost', PORT)) if ((not acquisition_parameters["flip_x"] is None) or
sock.send(cmd_str) (not acquisition_parameters["flip_yr"] is None)):
reply = sock.recv(16384) # limit reply to 16K geometry_changed = True
sock.close() fstr = "set_sensor_flipXY %s %s %s %s"%(
str(acquisition_parameters["channel"]),
str(acquisition_parameters["flip_x"]),
str(acquisition_parameters["flip_y"]),
str(acquisition_parameters["verbose"]))
communicate(PORT, fstr)
#How many bad/non modified frames are to be skipped (just a guess)
skip_frames = 0
if geometry_changed:
skip_frames = 2
elif gains_exp_changed:
skip_frames = 1
if (str(acquisition_parameters["channel"])[0].upper() == 'A'):
channel_mask = 0x0f
else:
channel_mask = 1 << int(acquisition_parameters["channel"])
skip_str= "skip_frame %d"%(channel_mask)
for i in range(skip_frames):
communicate(PORT, skip_str)
# Now - get that image
reply = communicate(PORT,cmd_str)
if (acquisition_parameters["cmode"] =="5"): if (acquisition_parameters["cmode"] =="5"):
path = path.replace("jpeg","jp4") path = path.replace("jpeg","jp4")
......
...@@ -44,7 +44,7 @@ from argparse import ArgumentParser ...@@ -44,7 +44,7 @@ from argparse import ArgumentParser
#import argparse #import argparse
from argparse import RawDescriptionHelpFormatter from argparse import RawDescriptionHelpFormatter
import time import time
#import shutil
import socket import socket
import select import select
...@@ -476,8 +476,20 @@ USAGE ...@@ -476,8 +476,20 @@ USAGE
print ('\n"parameters" and "defines" list known defined parameters and macros') print ('\n"parameters" and "defines" list known defined parameters and macros')
print ("args.exception=%d, QUIET=%d"%(args.exceptions,QUIET)) print ("args.exception=%d, QUIET=%d"%(args.exceptions,QUIET))
print ("Enter 'R' to toggle show/hide command results, now it is %s"%(("OFF","ON")[showResult])) print ("Enter 'R' to toggle show/hide command results, now it is %s"%(("OFF","ON")[showResult]))
print ("Use 'socket_port' [PORT] to (re-)open socket on PORT (0 or no PORT - disable socket)") print ("Use 'socket_port [PORT]' to (re-)open socket on PORT (0 or no PORT - disable socket)")
# print ("Use 'copy <SRC> <DST> to copy files in file the system")
print ("Use 'pydev_predefines' to generate a parameter list to paste to vrlg.py, so Pydev will be happy") print ("Use 'pydev_predefines' to generate a parameter list to paste to vrlg.py, so Pydev will be happy")
elif lineList[0].upper() == 'R':
if len(lineList)>1:
if (lineList[1].upper() == "ON") or (lineList[1].upper() == "1") or (lineList[1].upper() == "TRUE"):
showResult=True
elif (lineList[1].upper() == "OFF") or (lineList[1].upper() == "0") or (lineList[1].upper() == "FALSE"):
showResult=False
else:
print ("Unrecognized parameter %s for 'R' command"%lineList[1])
else:
showResult = not showResult
print ("Show results mode is now %s"%(("OFF","ON")[showResult]))
elif (lineList[0].upper() == 'SOCKET_PORT') and (not soc_conn): # socket_conn): elif (lineList[0].upper() == 'SOCKET_PORT') and (not soc_conn): # socket_conn):
if socket_conn : # close old socket (if open) if socket_conn : # close old socket (if open)
print ("Closed socket on port %d"%(PORT)) print ("Closed socket on port %d"%(PORT))
...@@ -496,20 +508,9 @@ USAGE ...@@ -496,20 +508,9 @@ USAGE
print ('Bind failed. Error Code : %s Message %s'%( str(msg[0]),msg[1])) print ('Bind failed. Error Code : %s Message %s'%( str(msg[0]),msg[1]))
socket_conn = None # do not use sockets socket_conn = None # do not use sockets
continue continue
elif lineList[0].upper() == 'R': # elif lineList[0] == 'copy':
if len(lineList)>1: # shutil.copy2(lineList[1], lineList[2])
if (lineList[1].upper() == "ON") or (lineList[1].upper() == "1") or (lineList[1].upper() == "TRUE"):
showResult=True
elif (lineList[1].upper() == "OFF") or (lineList[1].upper() == "0") or (lineList[1].upper() == "FALSE"):
showResult=False
else:
print ("Unrecognized parameter %s for 'R' command"%lineList[1])
else:
showResult = not showResult
print ("Show results mode is now %s"%(("OFF","ON")[showResult]))
# elif (len(line) > len("help")) and (line[:len("help")]=='help'):
elif lineList[0] == 'help': elif lineList[0] == 'help':
# helpFilter=line[len('help'):].strip()
helpFilter=lineList[1] # should not fail helpFilter=lineList[1] # should not fail
try: try:
re.match(helpFilter,"") re.match(helpFilter,"")
......
...@@ -68,15 +68,15 @@ GLBL_MEMBRIDGE_END = None ...@@ -68,15 +68,15 @@ GLBL_MEMBRIDGE_END = None
GLBL_BUFFER_END = None GLBL_BUFFER_END = None
GLBL_WINDOW = None GLBL_WINDOW = None
SENSOR_INTERFACE_PARALLEL = "PAR12" #SENSOR_INTERFACE_PARALLEL = "PAR12"
SENSOR_INTERFACE_HISPI = "HISPI" #SENSOR_INTERFACE_HISPI = "HISPI"
# for now - single sensor type per interface # for now - single sensor type per interface
SENSOR_INTERFACES={SENSOR_INTERFACE_PARALLEL: {"mv":2800, "freq":24.0, "iface":"2V5_LVDS"}, SENSOR_INTERFACES={x393_sensor.SENSOR_INTERFACE_PARALLEL: {"mv":2800, "freq":24.0, "iface":"2V5_LVDS"},
SENSOR_INTERFACE_HISPI: {"mv":1820, "freq":24.444, "iface":"1V8_LVDS"}} x393_sensor.SENSOR_INTERFACE_HISPI: {"mv":1820, "freq":24.444, "iface":"1V8_LVDS"}}
SENSOR_DEFAULTS= {SENSOR_INTERFACE_PARALLEL: {"width":2592, "height":1944, "top":0, "left":0, "slave":0x48, "i2c_delay":100, "bayer":3}, SENSOR_DEFAULTS= {x393_sensor.SENSOR_INTERFACE_PARALLEL: {"width":2592, "height":1944, "top":0, "left":0, "slave":0x48, "i2c_delay":100, "bayer":3},
# SENSOR_INTERFACE_HISPI: {"width":4608, "height":3288, "top":0, "left":0, "slave":0x10, "i2c_delay":100}} # SENSOR_INTERFACE_HISPI: {"width":4608, "height":3288, "top":0, "left":0, "slave":0x10, "i2c_delay":100}}
SENSOR_INTERFACE_HISPI: {"width":4384, "height":3288, "top":0, "left":0, "slave":0x10, "i2c_delay":100, "bayer":2}} x393_sensor.SENSOR_INTERFACE_HISPI: {"width":4384, "height":3288, "top":0, "left":0, "slave":0x10, "i2c_delay":100, "bayer":2}}
class X393SensCmprs(object): class X393SensCmprs(object):
DRY_MODE = True # True DRY_MODE = True # True
...@@ -208,19 +208,19 @@ class X393SensCmprs(object): ...@@ -208,19 +208,19 @@ class X393SensCmprs(object):
print ("Turned on +3.3V power for sensors %s"%(("0, 1","2, 3")[sub_pair])) print ("Turned on +3.3V power for sensors %s"%(("0, 1","2, 3")[sub_pair]))
# time.sleep(0.1) # time.sleep(0.1)
def getSensorInterfaceType(self): # def getSensorInterfaceType(self):
""" # """
Get sensor interface type by reading status register 0xfe that is set to 0 for parallel and 1 for HiSPi # Get sensor interface type by reading status register 0xfe that is set to 0 for parallel and 1 for HiSPi
@return "PAR12" or "HISPI" # @return "PAR12" or "HISPI"
""" # """
return (SENSOR_INTERFACE_PARALLEL, SENSOR_INTERFACE_HISPI)[self.x393_axi_tasks.read_status(address=0xfe)] # "PAR12" , "HISPI" # return (SENSOR_INTERFACE_PARALLEL, SENSOR_INTERFACE_HISPI)[self.x393_axi_tasks.read_status(address=0xfe)] # "PAR12" , "HISPI"
def setupSensorsPowerClock(self,quiet=0): def setupSensorsPowerClock(self,quiet=0):
""" """
Set interface voltage for all sensors, clock for frequency and sensor power Set interface voltage for all sensors, clock for frequency and sensor power
for the interface matching bitstream file for the interface matching bitstream file
""" """
ifaceType = self.getSensorInterfaceType(); ifaceType = self.x393Sensor.getSensorInterfaceType();
if quiet == 0: if quiet == 0:
print ("Configuring sensor ports for interface type: \"%s\""%(ifaceType)) print ("Configuring sensor ports for interface type: \"%s\""%(ifaceType))
for sub_pair in (0,1): for sub_pair in (0,1):
...@@ -282,7 +282,7 @@ class X393SensCmprs(object): ...@@ -282,7 +282,7 @@ class X393SensCmprs(object):
@return True if all done, False if exited prematurely through exit_step @return True if all done, False if exited prematurely through exit_step
""" """
# @param compressor_left_margin - 0..31 - left margin for compressor (to the nearest 32-byte column) # @param compressor_left_margin - 0..31 - left margin for compressor (to the nearest 32-byte column)
sensorType = self.getSensorInterfaceType() sensorType = self.x393Sensor.getSensorInterfaceType()
if verbose > 0 : if verbose > 0 :
print ("Sensor port %d interface type: %s"%(num_sensor, sensorType)) print ("Sensor port %d interface type: %s"%(num_sensor, sensorType))
window = self.specify_window (window_width = window_width, window = self.specify_window (window_width = window_width,
...@@ -618,7 +618,7 @@ class X393SensCmprs(object): ...@@ -618,7 +618,7 @@ class X393SensCmprs(object):
global GLBL_WINDOW global GLBL_WINDOW
if GLBL_WINDOW is None: if GLBL_WINDOW is None:
GLBL_WINDOW = {} GLBL_WINDOW = {}
sensorType = self.getSensorInterfaceType() sensorType = self.x393Sensor.getSensorInterfaceType()
if verbose > 0 : if verbose > 0 :
print ("Sensor interface type: %s"%(sensorType)) print ("Sensor interface type: %s"%(sensorType))
if window_width is None: if window_width is None:
...@@ -697,7 +697,6 @@ class X393SensCmprs(object): ...@@ -697,7 +697,6 @@ class X393SensCmprs(object):
except: except:
colorsat_red = 2.0 # *0xb6 colorsat_red = 2.0 # *0xb6
GLBL_WINDOW = {"width": window_width, GLBL_WINDOW = {"width": window_width,
"height": window_height, "height": window_height,
"left": window_left, "left": window_left,
...@@ -747,7 +746,86 @@ class X393SensCmprs(object): ...@@ -747,7 +746,86 @@ class X393SensCmprs(object):
print ("membridge end = 0x%x"%(GLBL_MEMBRIDGE_END)) print ("membridge end = 0x%x"%(GLBL_MEMBRIDGE_END))
print ("membridge size = %d bytes"%(GLBL_MEMBRIDGE_END - GLBL_MEMBRIDGE_START)) print ("membridge size = %d bytes"%(GLBL_MEMBRIDGE_END - GLBL_MEMBRIDGE_START))
print ("memory buffer end = 0x%x"%(GLBL_BUFFER_END)) print ("memory buffer end = 0x%x"%(GLBL_BUFFER_END))
def setup_cmdmux (self):
#Will report frame number for each channel
"""
Configure status report for command sequencer to report 4 LSB of each channel frame number
with get_frame_numbers()
"""
self.x393_axi_tasks.program_status( # also takes snapshot
base_addr = vrlg.CMDSEQMUX_ADDR,
reg_addr = 0,
mode = 3, # input [1:0] mode;
seq_num = 0) #input [5:0] seq_num;
def get_frame_numbers(self):
"""
@return list of 4-bit frame numbers, per channel
"""
status = self.x393_axi_tasks.read_status(address = vrlg.CMDSEQMUX_STATUS)
frames = []
for i in range(4):
frames.append (int((status >> (4*i)) & 0xf))
return frames
def get_frame_number_i2c(self,
channel=0):
"""
@return frame number of the i2c sequencer for the specified channel
"""
try:
if (channel == all) or (channel[0].upper() == "A"): #all is a built-in function
frames=[]
for channel in range(4):
frames.append(self.get_frame_number_i2c(channel = channel))
return frames
except:
pass
status = self.x393_axi_tasks.read_status(
address = vrlg.SENSI2C_STATUS_REG_BASE + channel * vrlg.SENSI2C_STATUS_REG_INC + vrlg.SENSI2C_STATUS_REG_REL)
return int((status >> 12) & 0xf)
def skip_frame(self,
channel_mask,
loop_delay = 0.01,
timeout = 2.0):
old_frames = self.get_frame_numbers()
timeout_time = time.time() + timeout
frameno = -1
while time.time() < timeout_time :
new_frames = self.get_frame_numbers()
all_new=True
for chn in range(4):
if ((channel_mask >> chn) & 1):
if (old_frames[chn] == new_frames[chn]):
all_new = False
break
else:
frameno = new_frames[chn]
if all_new:
break;
return frameno # Frame number of the last new frame checked
def skip_frame_i2c(self,
channel_mask,
loop_delay = 0.01,
timeout = 2.0):
old_frames = self.get_frame_number_i2c("all")
timeout_time = time.time() + timeout
frameno = -1
while time.time() < timeout_time :
new_frames = self.get_frame_number_i2c("all")
all_new=True
for chn in range(4):
if ((channel_mask >> chn) & 1):
if (old_frames[chn] == new_frames[chn]):
all_new = False
break
else:
frameno = new_frames[chn]
if all_new:
break;
return frameno # Frame number of the last new frame checked
def setup_compressor(self, def setup_compressor(self,
chn, chn,
cmode = vrlg.CMPRS_CBIT_CMODE_JPEG18, cmode = vrlg.CMPRS_CBIT_CMODE_JPEG18,
...@@ -980,7 +1058,7 @@ class X393SensCmprs(object): ...@@ -980,7 +1058,7 @@ class X393SensCmprs(object):
""" """
global GLBL_CIRCBUF_CHN_SIZE, GLBL_CIRCBUF_STARTS, GLBL_CIRCBUF_END, GLBL_MEMBRIDGE_START, GLBL_MEMBRIDGE_END, GLBL_BUFFER_END, GLBL_WINDOW global GLBL_CIRCBUF_CHN_SIZE, GLBL_CIRCBUF_STARTS, GLBL_CIRCBUF_END, GLBL_MEMBRIDGE_START, GLBL_MEMBRIDGE_END, GLBL_BUFFER_END, GLBL_WINDOW
sensorType = self.getSensorInterfaceType() sensorType = self.x393Sensor.getSensorInterfaceType()
if verbose > 0 : if verbose > 0 :
print ("Sensor interface type: %s"%(sensorType)) print ("Sensor interface type: %s"%(sensorType))
window = self.specify_window (window_width = window_width, window = self.specify_window (window_width = window_width,
...@@ -1085,6 +1163,11 @@ class X393SensCmprs(object): ...@@ -1085,6 +1163,11 @@ class X393SensCmprs(object):
mode = 3, # input [1:0] mode; mode = 3, # input [1:0] mode;
seq_num = 0) # input [5:0] seq_num; seq_num = 0) # input [5:0] seq_num;
if verbose >0 :
print ("===================== CMDSEQMUX_SETUP =========================")
#Will report frame number for each channel
self.setup_cmdmux()
if exit_step == 2: return False if exit_step == 2: return False
if verbose >0 : if verbose >0 :
print ("===================== RTC_SETUP =========================") print ("===================== RTC_SETUP =========================")
...@@ -1186,7 +1269,7 @@ class X393SensCmprs(object): ...@@ -1186,7 +1269,7 @@ class X393SensCmprs(object):
early_release_0 = True, early_release_0 = True,
verbose = verbose) verbose = verbose)
if sensorType == SENSOR_INTERFACE_PARALLEL: if sensorType == x393_sensor.SENSOR_INTERFACE_PARALLEL:
self.x393Sensor.set_sensor_i2c_table_reg_wr ( self.x393Sensor.set_sensor_i2c_table_reg_wr (
num_sensor = num_sensor, num_sensor = num_sensor,
page = 0, page = 0,
...@@ -1229,7 +1312,7 @@ class X393SensCmprs(object): ...@@ -1229,7 +1312,7 @@ class X393SensCmprs(object):
bit_delay = i2c_delay, bit_delay = i2c_delay,
verbose = verbose) verbose = verbose)
elif sensorType == SENSOR_INTERFACE_HISPI: elif sensorType == x393_sensor.SENSOR_INTERFACE_HISPI:
for page in (0,1,2,3,4,5,6, # SMIA configuration registers for page in (0,1,2,3,4,5,6, # SMIA configuration registers
0x10,0x11,0x12,0x13,0x14, # SMIA limit registers 0x10,0x11,0x12,0x13,0x14, # SMIA limit registers
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, # Manufacturer registers 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, # Manufacturer registers
......
...@@ -40,6 +40,9 @@ import x393_utils ...@@ -40,6 +40,9 @@ import x393_utils
import time import time
import vrlg import vrlg
import x393_mcntrl import x393_mcntrl
#import x393_sens_cmprs
SENSOR_INTERFACE_PARALLEL = "PAR12"
SENSOR_INTERFACE_HISPI = "HISPI"
class X393Sensor(object): class X393Sensor(object):
DRY_MODE= True # True DRY_MODE= True # True
...@@ -47,6 +50,7 @@ class X393Sensor(object): ...@@ -47,6 +50,7 @@ class X393Sensor(object):
x393_mem=None x393_mem=None
x393_axi_tasks=None #x393X393AxiControlStatus x393_axi_tasks=None #x393X393AxiControlStatus
x393_utils=None x393_utils=None
verbose=1 verbose=1
def __init__(self, debug_mode=1,dry_mode=True, saveFileName=None): def __init__(self, debug_mode=1,dry_mode=True, saveFileName=None):
self.DEBUG_MODE= debug_mode self.DEBUG_MODE= debug_mode
...@@ -54,10 +58,18 @@ class X393Sensor(object): ...@@ -54,10 +58,18 @@ class X393Sensor(object):
self.x393_mem= X393Mem(debug_mode,dry_mode) self.x393_mem= X393Mem(debug_mode,dry_mode)
self.x393_axi_tasks= x393_axi_control_status.X393AxiControlStatus(debug_mode,dry_mode) self.x393_axi_tasks= x393_axi_control_status.X393AxiControlStatus(debug_mode,dry_mode)
self.x393_utils= x393_utils.X393Utils(debug_mode,dry_mode, saveFileName) # should not overwrite save file path self.x393_utils= x393_utils.X393Utils(debug_mode,dry_mode, saveFileName) # should not overwrite save file path
try: try:
self.verbose=vrlg.VERBOSE self.verbose=vrlg.VERBOSE
except: except:
pass pass
def getSensorInterfaceType(self):
"""
Get sensor interface type by reading status register 0xfe that is set to 0 for parallel and 1 for HiSPi
@return "PAR12" or "HISPI"
"""
return (SENSOR_INTERFACE_PARALLEL, SENSOR_INTERFACE_HISPI)[self.x393_axi_tasks.read_status(address=0xfe)] # "PAR12" , "HISPI"
def program_status_sensor_i2c( self, def program_status_sensor_i2c( self,
num_sensor, num_sensor,
mode, # input [1:0] mode; mode, # input [1:0] mode;
...@@ -477,6 +489,21 @@ class X393Sensor(object): ...@@ -477,6 +489,21 @@ class X393Sensor(object):
if verbose > 1: if verbose > 1:
print ("ta= 0x%x, td = 0x%x"%(ta,td)) print ("ta= 0x%x, td = 0x%x"%(ta,td))
def write_sensor_reg16(self,
num_sensor,
reg_addr16,
reg_data16):
"""
Write i2c register in immediate mode
@param num_sensor - sensor port number (0..3), or "all" - same to all sensors
@param reg_addr16 - 16-bit register address (page+low byte, for MT9F006 high byte is an 8-bit slave address = 0x90)
@param reg_data16 - 16-bit data to write to sesnor register
"""
self.write_sensor_i2c (num_sensor = num_sensor,
rel_addr = True,
addr = 0,
data = ((reg_addr16 & 0xffff) << 16) | (reg_data16 & 0xffff) )
def write_sensor_i2c (self, def write_sensor_i2c (self,
num_sensor, num_sensor,
rel_addr, rel_addr,
...@@ -564,7 +591,7 @@ class X393Sensor(object): ...@@ -564,7 +591,7 @@ class X393Sensor(object):
reg_addr, reg_addr,
indx = 1, indx = 1,
sa7 = 0x48, sa7 = 0x48,
verbose = 0): verbose = 1):
""" """
Read sequence of bytes available and print the result as a single hex number 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 num_sensor - sensor port number (0..3), or "all" - same to all sensors
...@@ -601,10 +628,107 @@ class X393Sensor(object): ...@@ -601,10 +628,107 @@ class X393Sensor(object):
d = 0 d = 0
for b in dl: for b in dl:
d = (d << 8) | (b & 0xff) d = (d << 8) | (b & 0xff)
fmt="i2c data[0x%02x:0x%x] = 0x%%0%dx"%(sa7,reg_addr,len(dl)*2) if verbose > 0:
print (fmt%(d)) fmt="i2c data[0x%02x:0x%x] = 0x%%0%dx"%(sa7,reg_addr,len(dl)*2)
print (fmt%(d))
return d
def set_sensor_flipXY(self,
num_sensor,
flip_x = False,
flip_y = False,
verbose = 1):
"""
Set sensor horizontal and vertical mirror (flip)
@param num_sensor - sensor number or "all"
@param flip_x - mirror image around vertical axis
@param flip_y - mirror image around horizontal axis
@param verbose - verbose level
"""
sensorType = self.getSensorInterfaceType()
if flip_x is None:
flip_x = False
if flip_y is None:
flip_y = False
if sensorType == "PAR12":
data = (0,0x8000)[flip_y] | (0,0x4000)[flip_x]
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x9020,
reg_data16 = data)
elif sensorType == "HISPI":
data = (0,0x8000)[flip_y] | (0,0x4000)[flip_x] | 0x41
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x3040,
reg_data16 = data)
else:
raise ("Unknown sensor type: %s"%(sensorType))
def set_sensor_gains_exposure(self,
num_sensor,
gain_r = None,
gain_gr = None,
gain_gb = None,
gain_b = None,
exposure = None,
verbose = 1):
"""
Set sensor analog gains (raw register values) and
exposure (in scan lines)
@param num_sensor - sensor number or "all"
@param gain_r - RED gain
@param gain_gr - GREEN in red row gain
@param gain_gb - GREEN in blue row gain
@param gain_b - BLUE gain
@param exposure - exposure time in scan lines
@param verbose - verbose level
"""
sensorType = self.getSensorInterfaceType()
if sensorType == "PAR12":
if not gain_r is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x902c,
reg_data16 = gain_r)
if not gain_gr is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x902b,
reg_data16 = gain_gr)
if not gain_gb is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x902e,
reg_data16 = gain_gb)
if not gain_b is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x902d,
reg_data16 = gain_b)
if not exposure is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x9009,
reg_data16 = exposure)
elif sensorType == "HISPI":
if not gain_r is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x208,
reg_data16 = gain_r)
if not gain_gr is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x206, # SMIA register
reg_data16 = gain_gr)
if not gain_gb is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x20c, # SMIA register
reg_data16 = gain_gb)
if not gain_b is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x20a, # SMIA register
reg_data16 = gain_b)
if not exposure is None:
self.write_sensor_reg16 (num_sensor = num_sensor,
reg_addr16 = 0x202, # SMIA register
reg_data16 = exposure)
else:
raise ("Unknown sensor type: %s"%(sensorType))
def set_sensor_io_ctl (self, def set_sensor_io_ctl (self,
num_sensor, num_sensor,
mrst = None, mrst = None,
......
...@@ -38,7 +38,7 @@ from x393_mem import X393Mem ...@@ -38,7 +38,7 @@ from x393_mem import X393Mem
from time import sleep from time import sleep
import vrlg # global parameters import vrlg # global parameters
import x393_axi_control_status import x393_axi_control_status
import shutil
DEFAULT_BITFILE="/usr/local/verilog/x393.bit" DEFAULT_BITFILE="/usr/local/verilog/x393.bit"
FPGA_RST_CTRL= 0xf8000240 FPGA_RST_CTRL= 0xf8000240
FPGA0_THR_CTRL=0xf8000178 FPGA0_THR_CTRL=0xf8000178
...@@ -290,4 +290,13 @@ class X393Utils(object): ...@@ -290,4 +290,13 @@ class X393Utils(object):
print ("Failed to write to %s"%(os.path.abspath(fileName))) print ("Failed to write to %s"%(os.path.abspath(fileName)))
else: else:
print(txt) print(txt)
def copy (self,
src,
dst):
"""
Copy files in the file system
@param src - source path
@param dst - destination path/directory
"""
shutil.copy2(src, dst)
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