The project involves two boards: the CYW920829M2EVK-02, which connects to a game controller via Bluetooth Low Energy (BLE), and the KIT_XMC71_EVK_LITE_V1. It supports either a 3rd generation or higher Xbox controller or Infineon’s XENSIV game controller, transmitting data through a CAN FD bus with the CAN FD Shield TLE9371VSJ to the KIT_XMC71_EVK_LITE_V1 board. The latter processes the data and uses a custom graphic adapter, the XMC71_EVK_DisplayAdapter_V11, to display a demo game, inspired by Pong, on a screen.
Before running the code, ensure that all the hardware components are properly connected and configured. Follow these steps to set up the hardware:
1. Connect the XMC71_EVK_DisplayAdapter_V11 to KIT_XMC71_EVK_LITE_V1 by connecting the J23 header of the XMC71 kit to the J23 header of the Display Adapter.
2. Connect the CAN FD Shield TLE9371VSJ to CYW920829M2EVK-02:
- Connect the 5V and GND pins to the respective power pins on the evaluation board
- Connect RxD to P5.0 and TxD to P5.1
3. Connect the CAN FD Shield TLE9371VSJ to KIT_XMC71_EVK_LITE_V1:
- Connect the CANL and CANH pins of the shield via jumpers to the appropriate pins in the CAN FD header J14 of KIT_XMC71_EVK_LITE_V1 (pin names on the bottom side of the board)
To operate the project, follow these steps:
1. Flash the Code
To flash the code for either project using ModusToolbox (done here for XMC71_CAN_and_Display, but it is the same for both) follow these steps
- Download the.zip file for the project from the beginning of the article.
- Extract the contents of the.zip file to a folder on your computer.
- Open the Eclipse IDE for ModusToolbox.
- In the Quick Panel under Start, click on "Import Existing Application In-Place".
- Select the folder you extracted in Step 1.
- Once the project is loaded, click on the "Build Project" button under the project name.
- Connect the appropriate board to your computer.
- Click on the Run button under Launches, this will flash the code onto the board.
2. Pair the Devices
Now that both boards are flashed, it's time to pair the controller with them. Follow these steps:
- Power on both boards. You should see the waiting screen with the text "Waiting for controller to connect..." and the instructions to connect displayed.
- In case you are using the Xbox controller, turn it on by pressing the Xbox button (numbered 5 on the Xbox controller figure) and put it into pairing mode by holding the pair button (6 on the controller figure) for a few seconds, until the Xbox button starts blinking rapidly.
- For the XENSIV game controller, all you have to do is turn it on and it will start advertising automatically.
- Press the USER BTN1 button on the CYW920829M2EVK-02 board
- Wait a few seconds for the pairing process to complete.
- In the case of the Xbox controller, a red LED will light up on CYW920829M2EVK-02. To complete pairing, hold the pair button once again until the Xbox button stops blinking and stays steady on.
- For the XENSIV controller, when pairing is complete the controller displays “Successfully paired to …” and a green LED on the controller shines.
Upon successful connection establishment, the CYW920829M2EVK-02 starts transmitting packets. When the KIT_XMC71_EVK_LITE_V1 begins receiving these packets, the display will change to show the title screen. This screen will display the Infineon logo and logos of partner companies involved in creating the XMC71_EVK_DisplayAdapter_V11 custom board. After a few seconds, the demo will begin. We will describe the controller buttons with their Xbox names first and XENSIV in parenthesis. The buttons that serve the same purpose in each controller are numbered the same in the controller figures above.
Using the Demo- The demo consists of two modules:The help screen module displays the project's name and details the available user inputs:The Pong module is a simplified version of the classic Pong game and can be played by one or two players, using one controller. It consists of two screens. The game screen displays the actual game and, when one of the players loses, a game over screen is shown.
- To control the game, you can use:RB (R1) (number 2 in the controller figure) to start/restart the game.LB (L1) (number 1 in the controller figure) to go to the help screen.The left and right sticks (buttons 4 and 5 respectively in the controller figure) to control the respective paddles in the Pong module.
Below are pictures of the screens for reference (Xbox instructions).
A diagram showing the general flow of the software in this project can be found below. It shows the general simplified operation of both projects and their interaction. Names in upper case and with underscore represent states in the program’s internal finite-state machine.
By default, the controller data is sent every 50 milliseconds. This can be altered in the CONTROLLER_STATUS_PERIOD_MS
in the file Bluetooth_LE_Game_Controller\source\app_communication\app_communication.h
The Pong game logic consists of two states:
1. PONG_PLAY: In this state, the paddle positions are updated based on user inputs, and collisions are managed. The game also checks for a game over condition, setting the gameOver flag when the paddle fails to hit the ba
2. PONG_OVER: In this state, the player is shown a text indicating the end of the game and how to restart.
The infinite loop of the program includes a function called runAndUpdateGameState()
, which uses a switch/case structure to manage the states illustrated in Diagram 1. This function handles transitions between states and calls the appropriate functions to render each screen on the display.
Additionally, the gameModuleHandler()
function is responsible for managing transitions between modules. It registers when the RB (R1) and LB (L1) buttons are pressed and triggers the change of demos when they are released.
Please have a look how to it works by watching the following videos
SummaryThis project combines several embedded features that might be interesting for your next project:
- Connecting a Game controller via Bluetooth LE (BLE) to your system
- Bridging BLE to CAN network
- Driving a display
Very Special thanks to Caio for his software support and code example development of this project.
Go ahead and realize your idea! Stay safe!
Holger & Caio
Comments
Please log in or sign up to comment.