Skip to content

Commit

Permalink
rpi5-gmsl: allocate channel indices dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Demon000 committed Feb 12, 2025
1 parent 95845fa commit 588c3cd
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions utils/cam-configs/rpi5-gmsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
fmt_tpg = (640, 480, v4l2.PixelFormats.BGR888)


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

Expand Down Expand Up @@ -87,18 +87,18 @@ def gen_imx219_pixel(des_ent, des_src_pad, cameras, port):
{
'entity': CSI2_NAME,
'routing': [
{ 'src': (0, port), 'dst': (1 + port, 0) },
{ 'src': (0, port), 'dst': (1 + ch_index, 0) },
],
'pads': [
{ 'pad': (0, port), 'fmt': mbus_fmt_imx219 },
{ 'pad': (1 + port, 0), 'fmt': mbus_fmt_imx219 },
{ 'pad': (1 + ch_index, 0), 'fmt': mbus_fmt_imx219 },
],
},
],

'devices': [
{
'entity': f'rp1-cfe-csi2-ch{port}',
'entity': f'rp1-cfe-csi2-ch{ch_index}',
'fmt': fmt_pix,
'kms-format': v4l2.PixelFormats.RGB565,
},
Expand All @@ -108,11 +108,11 @@ def gen_imx219_pixel(des_ent, des_src_pad, cameras, port):
{ 'src': (sensor_ent, 0), 'dst': (ser_ent, 0) },
{ 'src': (ser_ent, 1), 'dst': (des_ent, port) },
{ 'src': (des_ent, des_src_pad), 'dst': (CSI2_NAME, 0) },
{ 'src': (CSI2_NAME, 1 + port), 'dst': (f'rp1-cfe-csi2-ch{port}', 0) },
{ 'src': (CSI2_NAME, 1 + ch_index), 'dst': (f'rp1-cfe-csi2-ch{ch_index}', 0) },
],
}

def gen_imx219_meta(des_ent, des_src_pad, 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]

Expand Down Expand Up @@ -159,18 +159,18 @@ def gen_imx219_meta(des_ent, des_src_pad, cameras, port):
{
'entity': CSI2_NAME,
'routing': [
{ 'src': (0, port + 4), 'dst': (1 + port + 2, 0) },
{ 'src': (0, port + 4), 'dst': (1 + ch_index, 0) },
],
'pads': [
{ 'pad': (0, port + 4), 'fmt': mbus_fmt_imx219_meta },
{ 'pad': (1 + port + 2, 0), 'fmt': mbus_fmt_imx219_meta },
{ 'pad': (1 + ch_index, 0), 'fmt': mbus_fmt_imx219_meta },
],
},
],

'devices': [
{
'entity': f'rp1-cfe-csi2-ch{port + 2}',
'entity': f'rp1-cfe-csi2-ch{ch_index}',
'fmt': fmt_pix_imx219_meta,
'embedded': True,
'display': False,
Expand All @@ -182,11 +182,11 @@ def gen_imx219_meta(des_ent, des_src_pad, cameras, port):
{ 'src': (sensor_ent, 0), 'dst': (ser_ent, 0) },
{ 'src': (ser_ent, 1), 'dst': (des_ent, port) },
{ 'src': (des_ent, des_src_pad), 'dst': (CSI2_NAME, 0) },
{ 'src': (CSI2_NAME, 1 + port + 2), 'dst': (f'rp1-cfe-csi2-ch{port + 2}', 0) },
{ 'src': (CSI2_NAME, 1 + ch_index), 'dst': (f'rp1-cfe-csi2-ch{ch_index}', 0) },
],
}

def gen_des_tpg(des_ent, des_src_pad):
def gen_des_tpg(des_ent, des_src_pad, ch_index):
return {
'media': MEDIA_DEVICE_NAME,

Expand All @@ -207,29 +207,29 @@ def gen_des_tpg(des_ent, des_src_pad):
{
'entity': CSI2_NAME,
'routing': [
{ 'src': (0, 0), 'dst': (1, 0) },
{ 'src': (0, 0), 'dst': (1 + ch_index, 0) },
],
'pads': [
{ 'pad': (0, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (1, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (1 + ch_index, 0), 'fmt': mbus_fmt_tpg },
],
},
],

'devices': [
{
'entity': 'rp1-cfe-csi2-ch0',
'entity': f'rp1-cfe-csi2-ch{ch_index}',
'fmt': fmt_tpg,
},
],

'links': [
{ 'src': (des_ent, des_src_pad), 'dst': (CSI2_NAME, 0) },
{ 'src': (CSI2_NAME, 1), 'dst': ('rp1-cfe-csi2-ch0', 0) },
{ 'src': (CSI2_NAME, 1 + ch_index), 'dst': (f'rp1-cfe-csi2-ch{ch_index}', 0) },
],
}

def gen_ser_tpg(des_ent, des_src_pad, cameras, port):
def gen_ser_tpg(des_ent, des_src_pad, ch_index, cameras, port):
ser_ent = cameras[port][0]

return {
Expand Down Expand Up @@ -263,11 +263,11 @@ def gen_ser_tpg(des_ent, des_src_pad, cameras, port):
{
'entity': CSI2_NAME,
'routing': [
{ 'src': (0, port), 'dst': (1 + port, 0) },
{ 'src': (0, port), 'dst': (1 + ch_index, 0) },
],
'pads': [
{ 'pad': (0, port), 'fmt': mbus_fmt_tpg },
{ 'pad': (1 + port, 0), 'fmt': mbus_fmt_tpg },
{ 'pad': (1 + ch_index, 0), 'fmt': mbus_fmt_tpg },
],
},
],
Expand All @@ -282,7 +282,7 @@ def gen_ser_tpg(des_ent, des_src_pad, cameras, port):
'links': [
{ 'src': (ser_ent, 1), 'dst': (des_ent, port) },
{ 'src': (des_ent, des_src_pad), 'dst': (CSI2_NAME, 0) },
{ 'src': (CSI2_NAME, 1 + port), 'dst': (f'rp1-cfe-csi2-ch{port}', 0) },
{ 'src': (CSI2_NAME, 1 + ch_index), 'dst': (f'rp1-cfe-csi2-ch{ch_index}', 0) },
],
}

Expand Down Expand Up @@ -319,17 +319,32 @@ def find_devices(mdev_name, deser_regex):

return deser.name, deser_src_pad, cameras

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

num_cameras = len(cameras)

configurations = {}
ch_index = 0
for i in range(num_cameras):
configurations[f'cam{i}'] = gen_imx219_pixel(des_name, des_src_pad, cameras, i)
configurations[f'cam{i}-meta'] = gen_imx219_meta(des_name, des_src_pad, cameras, i)
configurations[f'ser{i}-tpg'] = gen_ser_tpg(des_name, des_src_pad, cameras, i)
cam = f'cam{i}'
cam_meta = f'cam{i}-meta'
ser_tpg = f'ser{i}-tpg'

if cam in config_names:
configurations[cam] = gen_imx219_pixel(des_name, des_src_pad, ch_index, cameras, i)
ch_index += 1

if cam_meta in config_names:
configurations[cam_meta] = gen_imx219_meta(des_name, des_src_pad, ch_index, cameras, i)
ch_index += 1

if ser_tpg in config_names:
configurations[ser_tpg] = gen_ser_tpg(des_name, des_src_pad, ch_index, cameras, i)
ch_index += 1

configurations['des-tpg'] = gen_des_tpg(des_name, des_src_pad)
if 'des-tpg' in config_names:
configurations['des-tpg'] = gen_des_tpg(des_name, des_src_pad, ch_index)
ch_index += 1

return (configurations, ['cam0'])
return (configurations, config_names)

0 comments on commit 588c3cd

Please sign in to comment.