Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 60 additions & 21 deletions utils/cam/cam-configs/rpi5-gmsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@

# TPG

mbus_fmt_tpg = (640, 480, v4l2.BusFormat.RGB888_1X24)
fmt_tpg = (640, 480, v4l2.PixelFormats.BGR888)
mbus_fmt_tpg = (1920, 1080, v4l2.BusFormat.RGB888_1X24)
fmt_tpg = (1920, 1080, v4l2.PixelFormats.BGR888)


def gen_imx219_pixel(des_ent, des_src_pad, ch_index, cameras, port):
sensor_ent = cameras[port][1]
ser_ent = cameras[port][0]
assert sensor_ent is not None

return {
'media': MEDIA_DEVICE_NAME,
Expand Down Expand Up @@ -117,6 +118,7 @@ def gen_imx219_pixel(des_ent, des_src_pad, ch_index, cameras, port):
def gen_imx219_meta(des_ent, des_src_pad, ch_index, cameras, port):
sensor_ent = cameras[port][1]
ser_ent = cameras[port][0]
assert sensor_ent is not None

return {
'media': MEDIA_DEVICE_NAME,
Expand Down Expand Up @@ -188,7 +190,10 @@ def gen_imx219_meta(des_ent, des_src_pad, ch_index, cameras, port):
],
}

def gen_des_tpg(des_ent, des_src_pad, ch_index):
def gen_des_tpg(des_ent, des_src_pad, deser_tpg_pad, ch_index):
assert deser_tpg_pad is not None

tpg_stream = 16
return {
'media': MEDIA_DEVICE_NAME,

Expand All @@ -197,22 +202,22 @@ def gen_des_tpg(des_ent, des_src_pad, ch_index):
{
'entity': des_ent,
'routing': [
{ 'src': (8, 0), 'dst': (des_src_pad, 0) },
{ 'src': (deser_tpg_pad, 0), 'dst': (des_src_pad, tpg_stream) },
],
'pads': [
{ 'pad': (8, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (des_src_pad, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (deser_tpg_pad, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (des_src_pad, tpg_stream), 'fmt': mbus_fmt_tpg },
],
},

# CSI-2 RX
{
'entity': CSI2_NAME,
'routing': [
{ 'src': (0, 0), 'dst': (1 + ch_index, 0) },
{ 'src': (0, tpg_stream), 'dst': (1 + ch_index, 0) },
],
'pads': [
{ 'pad': (0, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (0, tpg_stream), 'fmt': mbus_fmt_tpg },
{ 'pad': (1 + ch_index, 0), 'fmt': mbus_fmt_tpg },
],
},
Expand All @@ -234,6 +239,8 @@ def gen_des_tpg(des_ent, des_src_pad, ch_index):
def gen_ser_tpg(des_ent, des_src_pad, ch_index, cameras, port):
ser_ent = cameras[port][0]

ser_tpg_stream = 2
des_tpg_stream = port + 8
return {
'media': MEDIA_DEVICE_NAME,

Expand All @@ -242,41 +249,41 @@ def gen_ser_tpg(des_ent, des_src_pad, ch_index, cameras, port):
{
'entity': ser_ent,
'routing': [
{ 'src': (2, 0), 'dst': (1, 0) },
{ 'src': (2, 0), 'dst': (1, ser_tpg_stream) },
],
'pads': [
{ 'pad': (2, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (1, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (1, ser_tpg_stream), 'fmt': mbus_fmt_tpg },
],
},
# Deserializer
{
'entity': des_ent,
'routing': [
{ 'src': (port, 0), 'dst': (des_src_pad, port) },
{ 'src': (port, ser_tpg_stream), 'dst': (des_src_pad, des_tpg_stream) },
],
'pads': [
{ 'pad': (port, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (des_src_pad, port), 'fmt': mbus_fmt_tpg },
{ 'pad': (port, ser_tpg_stream), 'fmt': mbus_fmt_tpg },
{ 'pad': (des_src_pad, des_tpg_stream), 'fmt': mbus_fmt_tpg },
],
},

# CSI-2 RX
{
'entity': CSI2_NAME,
'routing': [
{ 'src': (0, port), 'dst': (1 + ch_index, 0) },
{ 'src': (0, des_tpg_stream), 'dst': (1 + ch_index, 0) },
],
'pads': [
{ 'pad': (0, port), 'fmt': mbus_fmt_tpg },
{ 'pad': (0, des_tpg_stream), 'fmt': mbus_fmt_tpg },
{ 'pad': (1 + ch_index, 0), 'fmt': mbus_fmt_tpg },
],
},
],

'devices': [
{
'entity': f'rp1-cfe-csi2-ch{port}',
'entity': f'rp1-cfe-csi2-ch{ch_index}',
'fmt': fmt_tpg,
},
],
Expand All @@ -288,6 +295,21 @@ def gen_ser_tpg(des_ent, des_src_pad, ch_index, cameras, port):
],
}

def gen_empty_ser(cameras, port):
ser_ent = cameras[port][0]

return {
'media': MEDIA_DEVICE_NAME,

'subdevs': [
# Serializer
{
'entity': ser_ent,
'routing': [],
},
],
}

# Find serializers and sensors connected to the deserializer
def find_devices(mdev_name, deser_regex):
md = v4l2.MediaDevice(*mdev_name)
Expand All @@ -296,13 +318,19 @@ def find_devices(mdev_name, deser_regex):
assert deser

deser_src_pad = None
deser_tpg_pad = None
for p in deser.pads:
if p.is_source and len(p.links) == 1 and \
p.links[0].sink.entity.name == CSI2_NAME:
deser_src_pad = p.index
break
assert deser_src_pad is not None

for p in deser.pads:
if p.is_internal:
deser_tpg_pad = p.index
break

cameras = {}

for p in deser.pads:
Expand All @@ -315,43 +343,54 @@ def find_devices(mdev_name, deser_regex):
assert len(p.links) == 1

ser = p.links[0].source.entity
sensor = ser.pads[0].links[0].source.entity
sensor_name = None
if len(ser.pads[0].links) == 1:
sensor = ser.pads[0].links[0].source.entity
sensor_name = sensor.name

cameras[p.index] = (ser.name, sensor.name)
cameras[p.index] = (ser.name, sensor_name)

return deser.name, deser_src_pad, cameras
return deser.name, deser_src_pad, deser_tpg_pad, cameras

def get_configs(config_names):
des_name, des_src_pad, cameras = find_devices(MEDIA_DEVICE_NAME, DESER_REGEX)
des_name, des_src_pad, deser_tpg_pad, cameras = find_devices(MEDIA_DEVICE_NAME, DESER_REGEX)

cfgs = []
ch_index = 0
for i in cameras:
cam = f'cam{i}'
cam_meta = f'cam{i}-meta'
ser_tpg = f'ser{i}-tpg'
ser_in_use = False

if cam in config_names:
config_names.remove(cam)
cfg = gen_imx219_pixel(des_name, des_src_pad, ch_index, cameras, i)
cfgs.append(cfg)
ch_index += 1
ser_in_use = True

if cam_meta in config_names:
config_names.remove(cam_meta)
cfg = gen_imx219_meta(des_name, des_src_pad, ch_index, cameras, i)
cfgs.append(cfg)
ch_index += 1
ser_in_use = True

if ser_tpg in config_names:
cfg = gen_ser_tpg(des_name, des_src_pad, ch_index, cameras, i)
config_names.remove(ser_tpg)
cfgs.append(cfg)
ch_index += 1
ser_in_use = True

if not ser_in_use:
cfg = gen_empty_ser(cameras, i)
cfgs.append(cfg)

if 'des-tpg' in config_names:
config_names.remove('des-tpg')
cfg = gen_des_tpg(des_name, des_src_pad, ch_index)
cfg = gen_des_tpg(des_name, des_src_pad, deser_tpg_pad, ch_index)
cfgs.append(cfg)
ch_index += 1

Expand Down