Skip to content

Instantly share code, notes, and snippets.

@kbingham
Created April 20, 2023 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbingham/f7f77ab01ebd83ae4dd4e0f24273f4af to your computer and use it in GitHub Desktop.
Save kbingham/f7f77ab01ebd83ae4dd4e0f24273f4af to your computer and use it in GitHub Desktop.
Check for keywords in a V4L2 Subdevice driver
#!/usr/bin/awk -f
function initialiseControls(ids, keys, controls)
{
split(ids, keys)
for (i in keys) {
controls[keys[i]] = "--------"
# Track the maximum key length
len = length(keys[i])
if (len > maxKeyLength)
maxKeyLength = len
}
}
BEGIN {
maxKeyLength = 0
print "Processing " ARGV[1]
# Required Media Controller support
mc = " \
MEDIA_ENT_F_CAM_SENSOR \
V4L2_SUBDEV_FL_HAS_DEVNODE \
MEDIA_BUS_FMT_* \
"
initialiseControls(mc, mcKeys, mcIdentifiers)
# Required controls that libcamera can not create a camera without
mandatory = " \
V4L2_CID_EXPOSURE \
V4L2_CID_HBLANK \
V4L2_CID_PIXEL_RATE \
V4L2_CID_VBLANK \
"
initialiseControls(mandatory, mandatoryKeys, mandatoryControls)
# Track support for Selection APIs
selection = " \
v4l2_ctrl_new_fwnode_properties \
.get_selection \
V4L2_SEL_TGT_CROP_BOUNDS \
V4L2_SEL_TGT_CROP_DEFAULT \
V4L2_SEL_TGT_CROP \
"
initialiseControls(selection, selectionKeys, selectionControls)
# Optionally provided controls that add functionality
optional = " \
V4L2_CID_CAMERA_ORIENTATION \
V4L2_CID_CAMERA_SENSOR_ROTATION \
V4L2_CID_ANALOGUE_GAIN \
V4L2_CID_GAIN \
V4L2_CID_TEST_PATTERN \
"
initialiseControls(optional, optionalKeys, optionalControls)
}
function findKeys(line, keys, list)
{
for (i in keys)
if ( line ~ keys[i] )
{ list[keys[i]] = "found" }
}
# Search for identifiers in the input, and record when they are found
{
findKeys($0, mcKeys, mcIdentifiers)
findKeys($0, mandatoryKeys, mandatoryControls)
findKeys($0, selectionKeys, selectionControls)
findKeys($0, optionalKeys, optionalControls)
}
# Report results to the caller.
#
# Identify if there are any keys that were not found.
# This could be extended to exit with a failure
# if a required key is not located.
function reportControls(controls, message) {
print message
missing = 0
for (c in controls) {
printf " - %-*s : %s\n", maxKeyLength, c, controls[c]
if (controls[c] == "--------")
missing = 1
}
if (missing) {
print "Failed to find some keys"
}
print ""
return missing
}
END {
reportControls(mcIdentifiers, "Media Controller Support:")
reportControls(mandatoryControls, "Mandatory Controls:")
reportControls(selectionControls, "Selection Controls and fwnode properties (will become mandatory):")
reportControls(optionalControls, "Optional Controls:")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment