From 891e3120b41ae206002ba76e737d9b13bd327a29 Mon Sep 17 00:00:00 2001
From: Paul Elder <paul.elder@ideasonboard.com>
Date: Tue, 5 Jun 2018 22:47:06 +0900
Subject: uvc-gadget.sh: add function to create frame size

Currently there are a set of files that need to be written to in
configfs to instantiate a single frame size of a UVC function. Add a
function create_frame() to do this in one call.

There is no delete_frame() since delete_uvc() will delete the frame
settings. Previously delete_uvc() only deleted the single frame size, so
this has been changed to a wildcard to catch all frame sizes.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 scripts/uvc-gadget.sh | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/scripts/uvc-gadget.sh b/scripts/uvc-gadget.sh
index 46cc384..6c528f5 100755
--- a/scripts/uvc-gadget.sh
+++ b/scripts/uvc-gadget.sh
@@ -85,6 +85,27 @@ delete_msd() {
 	echo "OK"
 }
 
+create_frame() {
+	# Example usage:
+	# create_frame <function name> <width> <height>
+
+	FUNCTION=$1
+	WIDTH=$2
+	HEIGHT=$3
+
+	wdir=functions/$FUNCTION/streaming/uncompressed/u/${HEIGHT}p
+
+	mkdir -p $wdir
+	echo $WIDTH > $wdir/wWidth
+	echo $HEIGHT > $wdir/wHeight
+	echo $(( $WIDTH * $HEIGHT * 2 )) > $wdir/dwMaxVideoFrameBufferSize
+	cat <<EOF > $wdir/dwFrameInterval
+666666
+100000
+5000000
+EOF
+}
+
 create_uvc() {
 	# Example usage:
 	#	create_uvc <target config> <function name>
@@ -94,12 +115,9 @@ create_uvc() {
 
 	echo "	Creating UVC gadget functionality : $FUNCTION"
 	mkdir functions/$FUNCTION
-	mkdir -p functions/$FUNCTION/streaming/uncompressed/u/360p
-	cat <<EOF > functions/$FUNCTION/streaming/uncompressed/u/360p/dwFrameInterval
-666666
-1000000
-5000000
-EOF
+
+	create_frame $FUNCTION 640 360
+
 	mkdir functions/$FUNCTION/streaming/header/h
 	cd functions/$FUNCTION/streaming/header/h
 	ln -s ../../uncompressed/u
@@ -134,7 +152,7 @@ delete_uvc() {
 	rm functions/$FUNCTION/control/class/*/h
 	rm functions/$FUNCTION/streaming/class/*/h
 	rm functions/$FUNCTION/streaming/header/h/u
-	rmdir functions/$FUNCTION/streaming/uncompressed/u/360p
+	rmdir functions/$FUNCTION/streaming/uncompressed/u/*/
 	rmdir functions/$FUNCTION/streaming/uncompressed/u
 	rmdir functions/$FUNCTION/streaming/header/h
 	rmdir functions/$FUNCTION/control/header/h
-- 
cgit v1.2.3