Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8129b25

Browse files
committed
Rick's update1
1 parent 9018d33 commit 8129b25

File tree

10 files changed

+369
-8
lines changed

10 files changed

+369
-8
lines changed

README.md

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,36 @@ Dov Grobgeld
44
55
Last edited: 2024-09-11 Wed
66

7+
Contributor: Rick Bronson
8+
79
# License
810

911
All files in this repository are licensed under the following BSD License. See ![LICENSE](./LICENSE)
1012

1113
# Intro
1214

13-
The R36S is a very powerful little handheld computer, that comes with the Linux based ArkOS Open Source operating system preinstalled. The system is built with emulation in mind, but as it is a standard Linux based system, it is quite straightforward to write native programs and games for it.
15+
The R36S is a very powerful little handheld computer, that comes with the Ubuntu Linux based ArkOS Open Source operating system preinstalled. The system is built with emulation in mind, but as it is a standard Linux based system, it is quite straightforward to write native programs and games for it.
16+
The hardware make up of the R36S is:
17+
18+
- Rockchip RK3326 Quad-core ARM Cortex-A35 CPU with GPU
19+
- One Gigabyte Micron DDR RAM
20+
- RK817 PMIC with RTC and CODEC
21+
- TCS7191A Class-D audio power amplifier
22+
- ME4057 Lithium Ion Battery Linear Charger
23+
- 3.5-inch LCD panel (640 x 480) is Sitronix ST7703 or Elida KD35T133 or clone of
24+
- One or two SD Card slots, headphone output, one charging USB-C, one USB-C OTG
25+
26+
Here is a photo of the main PCB:
27+
28+
![board-pic](hardware/r36s-board1.png)
1429

1530
This repo will explore what is needed to program the system in C. Note that in addition, you can use almost any program that Linux supports and which has SDL bindings. E.g. C++, python, and zig.
1631

1732
# Connecting
1833

1934
In order to program the R36S you first need to connect to it from your computer by carrying out the folloiwing steps.
2035

21-
1. Connect Wifi dongle to the right hand usb port
36+
1. Connect Wifi dongle to the right hand USB-C port. Not all WiFi dongles work, especially newer ones. Your best bet is Realtek or Ralink, the units that come with an internal WiFi module use a RTL8188.
2237
2. Navigate through EmulationStation (ES) to Options, and connect to your local Wifi, by choosing your SSID and entering your password.
2338
3. In the Options menu, choose "Enable remote services". This will only be needed the first time, as we will turn on this permanently. (See note about ssh connections below)
2439
4. After succesfully connecting, check the IP address you connected to through Options->Network Info
@@ -82,7 +97,7 @@ sudo systemctl enable sshd
8297
```
8398
2. Setup C and C++ environment. The arkos system comes with some of the system packages crippled, e.g. they are missing header files needed for C-compilation. The following command rectifies this as well as sets up additional system development packages that we need:
8499
```
85-
sudo apt-get install --reinstall libc6-dev libsdl2-dev linux-libc-dev g++ libstdc++-9-dev libsdl2-ttf-dev git python3 ninja-build cmake make python3
100+
sudo apt-get install --reinstall gdb libc6-dev libsdl2-dev linux-libc-dev g++ libstdc++-9-dev libsdl2-ttf-dev git python3 ninja-build cmake make python3 i2c-tools usbutils fbcat fbset mmc-utils libglew-dev libegl1-mesa-dev libgl1-mesa-dev libgles2-mesa-dev libglu1-mesa-dev fonts-liberation
86101
```
87102

88103
3. We are now ready to compile our first C-program. To do so, first clone this repository by git
@@ -111,15 +126,26 @@ This program writes "Hello world" to the console and quits.
111126
Our first hello world program was a command line program. But to write games, we want to have graphics. The R36S supports the standard graphics library SDL2. We can test compiling a SDL2 based c-program as follows:
112127

113128
```
114-
cd ~/git/r36-programming/cprog/hello-sdl2
129+
cd ~/git/r36s-programming/cprog/hello-sdl2
115130
mkdir build && cd build && cmake -GNinja ..
116131
ninja
117132
./hello-sdl2
118133
```
119134

120135
This worked, somehow, but our program "collides" with the use of the screen by ES, because our program and ES are both running at the same time.
121136

122-
To fix this we can exit emulator system by Menu→Quit→Quit Emulationstation. This will turn the EmulationStation off, until next time you reboot the R36S.
137+
To fix this we can exit emulator system by Menu→Quit→Quit Emulationstation. This will turn the EmulationStation off, until next time you reboot the R36S. If you want to permanently disable ES, then do:
138+
139+
```
140+
sudo systemctl disable emulationstation
141+
```
142+
143+
You can always bring it back by doing:
144+
145+
```
146+
sudo systemctl enable emulationstation
147+
```
148+
123149

124150
If we now rerun ./hello-sdl2, we get only our colorful SDL on the screen:
125151

@@ -208,7 +234,7 @@ The axes are mapped as follows:
208234

209235
To test this on your own, you can run the program `print-joystick`:
210236

211-
```sh
237+
```
212238
cd cprog/print-joystick
213239
mkdir build && cd build && cmake -GNinja ..
214240
ninja
@@ -217,6 +243,42 @@ ninja
217243

218244
Press Fn+Start to exit the program.
219245

246+
# SDL2 graphics with TTF font's
247+
248+
This example is a simple C++ program to put fonts using standard installable fonts on the screen:
249+
250+
251+
```
252+
cd ~/git/r36s-programming/cprog/ttf-fonts-sdl2
253+
make
254+
./HelloSDL2
255+
```
256+
We get some TTF fonts on the screen:
257+
![sdl-screenshot](images/ttf-font-screenshot.png)
258+
259+
# Playing audio
260+
261+
```sh
262+
alsamixer # set volume, ESC to exit
263+
aplay /usr/share/sounds/alsa/Rear_Right.wav
264+
```
265+
266+
# Reading the 4 GPIO ports
267+
268+
```sh
269+
cd ~/git/r36s-programming/cprog/devmem
270+
make
271+
sudo ./devmem2 0xff040000; sudo ./devmem2 0xff250000; sudo ./devmem2 0xff260000; sudo ./devmem2 0xff270000
272+
```
273+
274+
You can also turn on/off the green led (GPIO2 PB5 = 77) via:
275+
276+
```sh
277+
pin=77
278+
echo 0 > /sys/class/gpio/gpio$pin/value
279+
echo 1 > /sys/class/gpio/gpio$pin/value
280+
```
281+
220282
# Installing into EmulationStation
221283

222284
It is possible to setup EmulationStation to support our native games. This is done by modifying the following files:
@@ -276,12 +338,11 @@ python3 -m pip install pysdl2 pysdl2-dll
276338

277339
Note however that I get a warning about "source-only" when running a python sdl2 program. I'm not sure what this warning means.
278340

341+
279342
# Final thoughts
280343

281344
First of all, this repository, and this article is work in progress. I hope to expand it as time allows.
282345

283346
However, my intention was not to teach "everything". There are lots of material available on the net about Linux, SDL, git, game programming, and more. My intent was to try to put these into perspective with regards to the R36S.
284347

285348
Please let me know your feedback and comments!
286-
287-

cprog/devmem/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Makefile for R36S stuff
2+
CFLAGS=-c -Wall -O2
3+
LIBS = -lm
4+
PROG = devmem2
5+
INCLUDES = -I. -I/usr/include
6+
7+
devmem2: devmem2.c
8+
gcc devmem2.c -o devmem2
9+
10+
clean:
11+
rm -rf *o $(PROG)

cprog/devmem/devmem2.c

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* devmem2.c: Simple program to read/write from/to any location in memory.
3+
*
4+
* Copyright (C) 2000, Jan-Derk Bakker ([email protected])
5+
*
6+
*
7+
* This software has been developed for the LART computing board
8+
* (http://www.lart.tudelft.nl/). The development has been sponsored by
9+
* the Mobile MultiMedia Communications (http://www.mmc.tudelft.nl/)
10+
* and Ubiquitous Communications (http://www.ubicom.tudelft.nl/)
11+
* projects.
12+
*
13+
* The author can be reached at:
14+
*
15+
* Jan-Derk Bakker
16+
* Information and Communication Theory Group
17+
* Faculty of Information Technology and Systems
18+
* Delft University of Technology
19+
* P.O. Box 5031
20+
* 2600 GA Delft
21+
* The Netherlands
22+
*
23+
*
24+
* This program is free software; you can redistribute it and/or modify
25+
* it under the terms of the GNU General Public License as published by
26+
* the Free Software Foundation; either version 2 of the License, or
27+
* (at your option) any later version.
28+
*
29+
* This program is distributed in the hope that it will be useful,
30+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
31+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+
* GNU General Public License for more details.
33+
*
34+
* You should have received a copy of the GNU General Public License
35+
* along with this program; if not, write to the Free Software
36+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37+
*
38+
*/
39+
40+
#include <stdio.h>
41+
#include <stdlib.h>
42+
#include <unistd.h>
43+
#include <string.h>
44+
#include <errno.h>
45+
#include <signal.h>
46+
#include <fcntl.h>
47+
#include <ctype.h>
48+
#include <termios.h>
49+
#include <sys/types.h>
50+
#include <sys/mman.h>
51+
52+
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
53+
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
54+
55+
#define MAP_SIZE 4096UL
56+
#define MAP_MASK (MAP_SIZE - 1)
57+
58+
int main(int argc, char **argv) {
59+
int fd;
60+
void *map_base, *virt_addr;
61+
unsigned int read_result, writeval;
62+
off_t target;
63+
int access_type = 'w';
64+
65+
if(argc < 2) {
66+
fprintf(stderr, "\nUsage:\t%s { address } [ type [ data ] ]\n"
67+
"\taddress : memory address to act upon\n"
68+
"\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n"
69+
"\tdata : data to be written\n\n",
70+
argv[0]);
71+
exit(1);
72+
}
73+
target = strtoul(argv[1], 0, 0);
74+
75+
if(argc > 2)
76+
access_type = tolower(argv[2][0]);
77+
78+
79+
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
80+
// printf("/dev/mem opened.\n");
81+
fflush(stdout);
82+
83+
/* Map one page */
84+
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
85+
if(map_base == (void *) -1) FATAL;
86+
// printf("Memory mapped at address %p.\n", map_base);
87+
fflush(stdout);
88+
89+
virt_addr = map_base + (target & MAP_MASK);
90+
switch(access_type) {
91+
case 'b':
92+
read_result = *((unsigned char *) virt_addr);
93+
break;
94+
case 'h':
95+
read_result = *((unsigned short *) virt_addr);
96+
break;
97+
case 'w':
98+
read_result = *((unsigned long *) virt_addr);
99+
break;
100+
default:
101+
fprintf(stderr, "Illegal data type '%c'.\n", access_type);
102+
exit(2);
103+
}
104+
printf("Value at address 0x%X (%p): 0x%X\n", (int) target, virt_addr, (int) read_result);
105+
fflush(stdout);
106+
107+
if(argc > 3) {
108+
writeval = strtoul(argv[3], 0, 0);
109+
switch(access_type) {
110+
case 'b':
111+
*((unsigned char *) virt_addr) = writeval;
112+
read_result = *((unsigned char *) virt_addr);
113+
break;
114+
case 'h':
115+
*((unsigned short *) virt_addr) = writeval;
116+
read_result = *((unsigned short *) virt_addr);
117+
break;
118+
case 'w':
119+
*((unsigned long *) virt_addr) = writeval;
120+
read_result = *((unsigned long *) virt_addr);
121+
break;
122+
}
123+
printf("Written 0x%X; readback 0x%X\n", writeval, read_result);
124+
fflush(stdout);
125+
}
126+
127+
if(munmap(map_base, MAP_SIZE) == -1) FATAL;
128+
close(fd);
129+
return 0;
130+
}
131+

0 commit comments

Comments
 (0)