[bootlin/training-materials updates] master: Kernel labs: explain use the nunchuk in nInvaders (f8752c5f)

Michael Opdenacker michael.opdenacker at bootlin.com
Thu Apr 16 11:51:56 CEST 2020


Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/f8752c5f094f0fe6d244fe8236d515e183807457

>---------------------------------------------------------------

commit f8752c5f094f0fe6d244fe8236d515e183807457
Author: Michael Opdenacker <michael.opdenacker at bootlin.com>
Date:   Thu Apr 16 11:51:18 2020 +0200

    Kernel labs: explain use the nunchuk in nInvaders
    
    Signed-off-by: Michael Opdenacker <michael.opdenacker at bootlin.com>


>---------------------------------------------------------------

f8752c5f094f0fe6d244fe8236d515e183807457
 .../declare-classic-buttons.c                      | 13 ++++
 labs/kernel-i2c-input-interface/declare-x-and-y.c  |  4 ++
 .../kernel-i2c-input-interface.tex                 | 81 +++++++++++++++++++---
 3 files changed, 90 insertions(+), 8 deletions(-)

diff --git a/labs/kernel-i2c-input-interface/declare-classic-buttons.c b/labs/kernel-i2c-input-interface/declare-classic-buttons.c
new file mode 100644
index 00000000..552f3203
--- /dev/null
+++ b/labs/kernel-i2c-input-interface/declare-classic-buttons.c
@@ -0,0 +1,13 @@
+/* Classic buttons */
+
+set_bit(BTN_TL, input->keybit);
+set_bit(BTN_SELECT, input->keybit);
+set_bit(BTN_MODE, input->keybit);
+set_bit(BTN_START, input->keybit);
+set_bit(BTN_TR, input->keybit);
+set_bit(BTN_TL2, input->keybit);
+set_bit(BTN_B, input->keybit);
+set_bit(BTN_Y, input->keybit);
+set_bit(BTN_A, input->keybit);
+set_bit(BTN_X, input->keybit);
+set_bit(BTN_TR2, input->keybit);
diff --git a/labs/kernel-i2c-input-interface/declare-x-and-y.c b/labs/kernel-i2c-input-interface/declare-x-and-y.c
new file mode 100644
index 00000000..603e51b1
--- /dev/null
+++ b/labs/kernel-i2c-input-interface/declare-x-and-y.c
@@ -0,0 +1,4 @@
+set_bit(ABS_X, input->absbit);
+set_bit(ABS_Y, input->absbit);
+input_set_abs_params(input, ABS_X, 30, 220, 4, 8);
+input_set_abs_params(input, ABS_Y, 40, 200, 4, 8);
diff --git a/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex b/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
index 8d74a5ec..9d04b286 100644
--- a/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
+++ b/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
@@ -209,12 +209,77 @@ reported by \code{evtest}.
 
 \section{Going further}
 
-If you complete your lab before the others, you can:
+Stopping here is sufficient, but if you complete your lab before the
+others, you can try to achieve the below challenges (in any order):
 
-\begin{itemize}
-\item Add support for the nunchuk joystick and accelerometer coordinates.
-\item Support two nunchucks at the same time, by borrowing a one from
-      the instructor or from a fellow participant. Making sure that your
-      driver does indeed support multiple devices at the same time is
-      a good way to make sure it is implemented properly.
-\end{itemize}
+\subsection{Supporting multiple devices}
+
+Modify the driver and Device Tree to support two nunchuks at the same
+time. You can borrow another nunchuk from the instructor or from a fellow
+participant.
+
+Making sure that your driver does indeed support multiple devices at the
+same time is a good way to make sure it is implemented properly.
+
+\subsection{Use the nunchuk as a joystick in an ascii game}
+
+In this optional, challenge, you will extend the driver to expose
+the joystick part of the nunchuk, i.e. x and y coordinates.
+
+We will use the {\em nInvaders} game, which is already present in
+your root filesystem.
+
+\subsubsection{Connect through SSH}
+
+{\em nInvaders} will not work very well over the serial port,
+so you will need to log to your system through \code{ssh} in an
+ordinary terminal:
+
+\begin{verbatim}
+ssh root at 192.168.0.100
+\end{verbatim}
+
+You can already plan the \code{nInvaders} game with
+the keyboard!
+
+Note: if you get the error \code{Error opening terminal: xterm-256color.}
+when running \code{nInvaders}, issue first the
+\code{export TERM=xterm} command.
+
+\subsubsection{Recompile your kernel}
+
+Recompile your kernel with support for the joystick interface
+(\code{CONFIG_INPUT_JOYDEV}).
+
+Reboot to the new kernel.
+
+\subsubsection{Extend your driver}
+
+We are going to expose the joystick X and Y coordinates through
+the input device.
+
+Add the below code to the \code{probe} routine:
+\sourcecode{labs/kernel-i2c-input-interface/declare-x-and-y.c}
+
+See \kerneldochtml{input/input-programming} for details about
+the \kfunc{input_set_abs_params} function.
+
+For the joystick to be usable by the application, you will also
+need to declare {\em classic} buttons:
+
+\sourcecode{labs/kernel-i2c-input-interface/declare-classic-buttons.c}
+
+The next thing to do is to retrieve and report the joystick X and Y
+coordinates in the polling routine. This should be very straighforward.
+You will just need to go back to the nunchuk datasheet to find out
+which bytes contain the X and Y values.
+
+\subsubsection{Time to play}
+
+Recompile and reload your driver.
+
+You can now directly play {\em nInvaders}, only with your nunchuk.
+You'll quickly find how to move your ship, how to shoot and how
+to pause the game.
+
+Have fun!




More information about the training-materials-updates mailing list