Skip to content
Open
Show file tree
Hide file tree
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
78 changes: 78 additions & 0 deletions common/beagleplay-sdcard-preparation.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
\section{Prepare the SD card}

Our SD card needs to be split in two partitions:

\begin{itemize}

\item A first partition for the bootloader. It needs to comply with
the requirements of the AM62x SoC so that the ROM code can find
the bootloader in this partition. It should be a FAT32 partition.
We will store the bootloader files (\code{tiboot3.bin},
\code{tispl.bin_unsigned} and \code{u-boot.img}), the kernel image
(\code{Image}) and the Device Tree
(\code{k3-am625-beagleplay.dtb}).

\item A second partition for the root filesystem. It can use
whichever filesystem type you want, but for our system, we'll use
{\em ext4}.

\end{itemize}

First, let's identify under what name your SD card is identified in
your system: look at the output of \code{cat /proc/partitions} and
find your SD card. In general, if you use the internal SD card reader
of a laptop, it will be \code{mmcblk0}, while if you use an external
USB SD card reader, it will be \code{sdX} (i.e. \code{sdb}, \code{sdc},
etc.). {\bf Be careful: \code{/dev/sda} is generally the hard drive of
your machine!}

If your SD card is \code{/dev/mmcblk0}, then the partitions inside the
SD card are named \code{/dev/mmcblk0p1}, \code{/dev/mmcblk0p2}, etc.

To format your SD card, do the following steps:

\begin{enumerate}

\item Unmount all partitions of your SD card (they are generally
automatically mounted by Ubuntu)

\item Erase the beginning of the SD card to ensure that the existing
partitions are not going to be mistakenly detected:\\
\code{sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=16}.

\item Create the two partitions.

\begin{itemize}

\item Start the \code{cfdisk} tool for that:\\
\code{sudo cfdisk /dev/mmcblk0}

\item Choose the {\em dos} partition table type

\item Create a first small partition (128 MB), primary, with type
\code{c} ({\em W95 FAT32 (LBA)}) and mark it bootable

\item Create a second partition, also primary, with the rest of the
available space, with type \code{83} ({\em Linux}).

\item Exit \code{cfdisk}

\end{itemize}

\item Format the first partition as a {\em FAT32} filesystem:\\
\code{sudo mkfs.vfat -F 32 -n boot /dev/mmcblk0p1}

\item Format the second partition as an {\em ext4} filesystem:\\
\code{sudo mkfs.ext4 -L rootfs -E nodiscard /dev/mmcblk0p2}

\begin{itemize}
\item \code{-L} assigns a volume name to the partition
\item \code{-E nodiscard} disables bad block discarding. While this
should be a useful option for cards with bad blocks, skipping
this step saves long minutes in SD cards.
\end{itemize}
\end{enumerate}

Remove the SD card and insert it again, the two partitions should be
mounted automatically, in \code{/media/$USER/boot} and
\code{/media/$USER/rootfs}.
2 changes: 2 additions & 0 deletions common/buildroot-beagleplay-labs-vars.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\def\board{beagleplay}
\def\boarddescription{BeaglePlay}
23 changes: 23 additions & 0 deletions lab-data/buildroot-beagleplay/buildroot-appdev/myapp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <libconfig.h>

int main(void)
{
config_t cfg;
config_setting_t *setting;
const char *str;

config_init(&cfg);

if (config_read_file(&cfg, "myapp.cfg") == CONFIG_FALSE)
{
fprintf(stderr, "Cannot open config file\n");
config_destroy(&cfg);
exit(1);
}

printf("Config file successfully opened\n");

return 0;
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
diff --git a/nInvaders.c b/nInvaders.c
index 793139c2e171..8ded1e292455 100644
--- a/nInvaders.c
+++ b/nInvaders.c
@@ -22,9 +22,12 @@
*/


+#include <linux/joystick.h>
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
+#include <time.h>
#include "nInvaders.h"
#include "player.h"
#include "aliens.h"
@@ -35,6 +38,7 @@
int lives;
long score;
int status; // status handled in timer
+int resend;

#define GAME_LOOP 1
#define GAME_NEXTLEVEL 2
@@ -127,6 +131,58 @@ void drawscore()
statusDisplay(level, score, lives);
}

+int td()
+{
+ static struct timespec t0;
+ struct timespec t1;
+ double dt;
+
+ clock_gettime(CLOCK_MONOTONIC, &t1);
+ dt = t1.tv_nsec - t0.tv_nsec;
+ t0 = t1;
+
+ return dt > 500000;
+}
+
+int getjs()
+{
+ static int fd = -1;
+ struct js_event js;
+
+ if (fd == -1) {
+ fd = open("/dev/input/js0", O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ return -1;
+ }
+
+ read(fd, &js, sizeof(struct js_event));
+
+ switch (js.type & ~JS_EVENT_INIT) {
+ case JS_EVENT_AXIS:
+ if (js.number == 0 && js.value < 0) {
+ resend |= 1 << 0;
+ return KEY_LEFT;
+ } else if (js.number == 0 && js.value > 0) {
+ resend |= 1 << 1;
+ return KEY_RIGHT;
+ } else if (js.number == 0 && js.value == 0) {
+ resend &= ~0x3;
+ }
+ break;
+ case JS_EVENT_BUTTON:
+ if (js.number == 2 && js.value == 1) {
+ resend |= 1 << 2;
+ return ' ';
+ } else if (js.number == 2 && js.value == 0) {
+ resend &= ~0x4;
+ } else if (js.number == 5 && js.value == 1) {
+ return 'p';
+ }
+ break;
+ }
+
+ return EOF;
+}

/**
* reads input from keyboard and do action
@@ -136,7 +192,9 @@ void readInput()
int ch;
static int lastmove;

- ch = getch(); // get key pressed
+ ch = getch();
+ if (ch == EOF)
+ ch = getjs();

switch (status) {

@@ -273,6 +331,17 @@ void handleTimer()
if (player_shot_counter++ >= 1) {player_shot_counter=0;} // speed of player shot
if (aliens_move_counter++ >= weite) {aliens_move_counter=0;} // speed of aliend
if (ufo_move_counter++ >= 3) {ufo_move_counter=0;} // speed of ufo
+
+
+ if (td()) {
+ if (resend & (1 << 0))
+ playerMoveLeft();
+ else if (resend & (1 << 1))
+ playerMoveRight();
+ if (resend & (1 << 2))
+ playerLaunchMissile();
+
+ }

refreshScreen();
break;
@@ -336,6 +405,8 @@ int main(int argc, char **argv)

evaluateCommandLine(argc, argv); // evaluate command line parameters
graphicEngineInit(); // initialize graphic engine
+
+ nodelay(stdscr, TRUE);

// set up timer/ game handling
setUpTimer();
Loading
Loading