Skip to content

Commit

Permalink
Merge pull request #43 from fbergama/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chregu82 authored Sep 16, 2020
2 parents e3fbfc2 + e9f0821 commit 159502f
Show file tree
Hide file tree
Showing 34 changed files with 455 additions and 199 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ RPI ?= 1

ARMGNU ?= arm-none-eabi
ifeq ($(strip $(RPI)),1)
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -mno-unaligned-access -fsigned-char -march=armv6j -mtune=arm1176jzf-s -DRPI=1
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -fsigned-char -march=armv6j -mtune=arm1176jzf-s -DRPI=1
else ifeq ($(strip $(RPI)),2)
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -mno-unaligned-access -fsigned-char -march=armv7-a -mtune=cortex-a7 -DRPI=2
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -fsigned-char -march=armv7-a -mtune=cortex-a7 -DRPI=2
else ifeq ($(strip $(RPI)),3)
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -mno-unaligned-access -fsigned-char -march=armv8-a -mtune=cortex-a53 -DRPI=3
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -fsigned-char -march=armv8-a -mtune=cortex-a53 -DRPI=3
else
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -mno-unaligned-access -fsigned-char -march=armv8-a -mtune=cortex-a53 -DRPI=4
CFLAGS = -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -fsigned-char -march=armv8-a -mtune=cortex-a53 -DRPI=4
endif

## Important!!! asm.o must be the first object to be linked!
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,26 @@ There's a [example](shapes/sample/anim_dinos.txt) for a moving dinosaur (after f

## Graphics performance

If you want to do graphics, get a Pi Zero. Multi core Pi's like the models 2 - 4 are much slower if only one core is used like PiGFX does.
Since we have cache enabled now on the Pi, the speed is more or less the same on every model. In most cases it's probably faster to not enable DMA.

Graphics which are drawn on a multiple of 4 pixels x-position draw much faster than on a multiple of 2 or 1. You will also get more speed if your image has a width of a multiple of 4. Drawing solid is faster than drawing transparent.
Graphics which are drawn on a multiple of 4 pixels x-position draw faster than on a multiple of 2 or 1. You will also get more speed if your image has a width of a multiple of 4. Drawing solid is faster than drawing transparent.

This is a table that shows the time for drawing a 400x300 pixel image on different x-positions.
This is a table that shows the time for drawing a 400x300 pixel image on different x-positions. This is an example for getting an idea.

|Pi Gen. |Aligned 4 px |Aligned 2 px |unaligned |DMA enabled
|------- |------------ |------------ |--------- |-----------
|1 (zero) |20.8ms |40.4ms |53.0ms |12.5ms
|2 |46.9ms |90.8ms |114.5ms |14.2ms
|3 |50.1ms |93.9ms |122.1ms |14.1ms
|4 |33.4ms |64.9ms |144.4ms |5.4ms
|1 (zero) |4.7ms |9.3ms |10.5ms |3.9ms
|2 |1.9ms |2.1ms |2.6ms |5.2ms
|3 |2.2ms |2.7ms |3.8ms |5.2ms
|4 |0.9ms |1.6ms |3.3ms |4.9ms

## Collision detection

At the time a sprite is defined, the borders of the sprite are used for detecting collisions with other sprites, so this is always a rectangle. A collision is reported if 2 sprites touch or overlap. Collisions with lower sprite indexes are detected first.

Collision detection takes place at the time a sprite is defined or moved. This sprite is checked against all other active sprites. All detected collisions are reported.

A collision is reported as a keyboard input with this syntax: \ESC[#<idx1>;<idx2>c where idx1 is the sprite index you just defined or moved and idx2 is the sprite it collides with.
A collision is reported as a keyboard input with this syntax: \ESC[#-idx1-;-idx2-c where -idx1- is the sprite index you just defined or moved and -idx2- is the sprite it collides with.

## Compiling on Mac / Linux

Expand Down
Binary file modified bin/kernel.img
Binary file not shown.
Binary file modified bin/kernel7.img
Binary file not shown.
Binary file modified bin/kernel8-32.img
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/pigfx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ swapDelWithBackspace = 1 ; Substitute DEL (0x7F) with BACKSPACE (0x08)

[General]
showRC2014Logo = 0 ; Show the RC2014 logo at startup
disableGfxDMA = 0 ; Disable fast DMA memory access for graphics (if 1)
disableGfxDMA = 1 ; Disable fast DMA memory access for graphics (if 1)
disableCollision = 0 ; Disable sprite collision detection
Binary file modified bin/recovery7l.img
Binary file not shown.
47 changes: 45 additions & 2 deletions doc/6800_8080_IF.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
//////////////////////////////////////////
// PiGFX parallel interface description //
//////////////////////////////////////////
Based on the datasheet of RA8835
See https://www.newhavendisplay.com/app_notes/RA8835.pdf

----------------
Hardware Signals
----------------
The Pi must use 3.3V high level signals,
use a bidirectional level shifter if you use 5v signals.

The behaviour of the interface (8080 or 6800 style) is configurable in config.txt.

8080 Signal | 6800 Signal | Raspberry Pin | Description
--------------------------------------------------------------------------
/CS | /CS | GPIO 4 (Pin 7) | Chip Select (low active)
/RS | /RS | GPIO 18 (Pin 12) | Register Select (1 = Data, 0 = command)
/RS | /RS | GPIO 18 (Pin 12) | Register Select (1 = data, 0 = command)
/RD | E | GPIO 25 (Pin 22) | 8080 Read (low active) / 6800 Enable (high active)
/WR | R/W | GPIO 8 (Pin 24) | 8080 Write (low active) Input latched at rising edge / 6800 1=read 0=write Input latched at falling edge of E
D0 | D0 | GPIO 17 (Pin 11) | Data Bit 0
Expand All @@ -11,4 +25,33 @@
D4 | D4 | GPIO 9 (Pin 21) | Data Bit 4
D5 | D5 | GPIO 11 (Pin 23) | Data Bit 5
D6 | D6 | GPIO 23 (Pin 16) | Data Bit 6
D7 | D7 | GPIO 24 (Pin 18) | Data Bit 7
D7 | D7 | GPIO 24 (Pin 18) | Data Bit 7

---------------------------------
Discription of the 8080 interface
---------------------------------
If /CS is low, all data lines are in input / high impedance state.

Reading from the Pi:
On the falling edge of /RD the Pi starts to set its datalines,
considering the state of /RS and /CS. Data is read by the CPU on the
rising edge of /RD.

Writing to the Pi:
On the rising edge of /WR, the Pi latches the state of the databus,
considerung the state of /RS and /CS.


---------------------------------
Discription of the 6800 interface
---------------------------------
If /CS is low, all data lines are in input / high impedance state.

Reading from the Pi:
On the rising edge of E the Pi starts to set its datalines,
considering the state of /RS, /CS and R/W. Data is read by the CPU
on the falling edge of E.

Writing to the Pi
On the falling edfe of E, the Pi latches the state of the databus,
considering the state of /RS, /CS and R/W.
1 change: 1 addition & 0 deletions doc/terminal_codes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Cursor Control

<ESC>[?25l Cursor invisible
<ESC>[?25b Cursor blinking
<ESC>[?25h Cursor visible
<ESC>[H Move to 0-0
<ESC>[f Move to 0-0
Expand Down
2 changes: 1 addition & 1 deletion make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ call makeuspi %RPI%
set OOB= asm.o exceptionstub.o synchronize.o mmu.o pigfx.o uart.o irq.o utils.o gpio.o mbox.o prop.o board.o actled.o framebuffer.o console.o gfx.o dma.o nmalloc.o uspios_wrapper.o ee_printf.o stupid_timer.o block.o emmc.o c_utils.o mbr.o fat.o config.o ini.o ps2.o keyboard.o binary_assets.o
set LIBUSPI= uspi/lib/libuspi.a

set CFLAGS= -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -mno-unaligned-access -fsigned-char
set CFLAGS= -Wall -Wextra -O2 -g -nostdlib -nostartfiles -fno-stack-limit -ffreestanding -fsigned-char
if "%RPI%"=="1" (
set CFLAGS= %CFLAGS% -march=armv6j -mtune=arm1176jzf-s -DRPI=1
)
Expand Down
3 changes: 1 addition & 2 deletions makeall
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh
# We need to add the compiler option -mno-unaligned-access in uspi. If not, the compiler will generate halb-word accesses on odd memory addresses. RPI1 could handle this by enabling unaligned access in a CPU config register. However RPI2&3 have it already enabled, but need a enabled MMU with pagetables. They otherwise just crash.
for i in 1 2 3
do
cd uspi
echo -e "RASPPI = $i\nCFLAGS += -mno-unaligned-access" > Config.mk
echo "RASPPI = $i" > Config.mk
./makeall clean
./makeall
cd ..
Expand Down
2 changes: 1 addition & 1 deletion makeuspi.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set RPI=%1

set OOBUSPI= uspilibrary.o dwhcidevice.o dwhciregister.o dwhcixferstagedata.o usbconfigparser.o usbdevice.o usbdevicefactory.o usbendpoint.o usbrequest.o usbstandardhub.o devicenameservice.o macaddress.o usbfunction.o smsc951x.o lan7800.o string.o util.o usbmassdevice.o dwhciframeschednper.o dwhciframeschedper.o keymap.o usbkeyboard.o dwhcirootport.o usbmouse.o dwhciframeschednsplit.o usbgamepad.o synchronize.o usbstring.o usbmidi.o

set CFLAGS= -Wall -Wno-psabi -fsigned-char -fno-builtin -nostdinc -nostdlib -std=gnu99 -undef -mno-unaligned-access -DRASPPI=%RPI% -I ../include -O2
set CFLAGS= -Wall -Wno-psabi -fsigned-char -fno-builtin -nostdinc -nostdlib -std=gnu99 -undef -DRASPPI=%RPI% -I ../include -O2
if "%RPI%"=="1" (
set CFLAGS= %CFLAGS% -march=armv6j -mtune=arm1176jzf-s
)
Expand Down
2 changes: 1 addition & 1 deletion pigfx_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define PIGFX_MAJVERSION 1 /* Major version number */
#define PIGFX_MINVERSION 8 /* Minor version number */
#define PIGFX_BUILDVERSION 0 /* Build version. */
#define PIGFX_BUILDVERSION 1 /* Build version. */

/** Versions:

Expand Down
6 changes: 0 additions & 6 deletions sourceme.bash

This file was deleted.

2 changes: 1 addition & 1 deletion src/actled.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void set_130(const int on) {

msg->header.size = sizeof(*msg);
msg->header.code = 0;
msg->tag.id = UINT32_C(0x00038041);
msg->tag.id = MAILBOX_TAG_SET_GPIO_STATE;
msg->tag.size = sizeof(msg->value);
msg->tag.code = 0;
msg->value.request.pin = 130;
Expand Down
2 changes: 1 addition & 1 deletion src/asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _reset_h: .word _reset_
_data_abort_h: .word DataAbortStub
_unused_handler_h: .word hang
_interrupt_h: .word irq_handler_
_fast_interrupt_h: .word hang
_fast_interrupt_h: .word fiq_handler_

/* The bootloader starts, loads are executable, and enters */
/* execution at 0x8000 with the following values set. */
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void setDefaultConfig()
PiGfxConfig.skipBackspaceEcho = 0;
PiGfxConfig.swapDelWithBackspace = 1;
PiGfxConfig.showRC2014Logo = 0;
PiGfxConfig.disableGfxDMA = 0;
PiGfxConfig.disableGfxDMA = 1;
PiGfxConfig.disableCollision = 0;
pigfx_strcpy(PiGfxConfig.keyboardLayout, "us");
}
Expand Down
7 changes: 6 additions & 1 deletion src/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "utils.h"
#include "mbox.h"
#include "console.h"
#include "memory.h"


#define DMA_CS_OFFSET 0x00
Expand All @@ -32,13 +33,17 @@ typedef struct _DMA_Ctrl_Block
} DMA_Control_Block;


DMA_Control_Block __attribute__((aligned(0x100))) ctr_blocks[16];
// DMA Control block needs to be in a coherent section. We choose Coherent start + 2048 bytes
// Coherent start is already used by the mailbox
// control block needs to be aligned 256
DMA_Control_Block* ctr_blocks;
unsigned int curr_blk;

unsigned int channel;

void dma_init()
{
ctr_blocks = (DMA_Control_Block*)(MEM_COHERENT_REGION+0x800);
curr_blk = 0;
channel = 0;
// Enable DMA on used channel
Expand Down
62 changes: 38 additions & 24 deletions src/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ static const unsigned int xterm_colors[NB_PALETTE_ELE] = {
FB_RETURN_TYPE fb_init( unsigned int ph_w, unsigned int ph_h, unsigned int vrt_w, unsigned int vrt_h,
unsigned int bpp, void** pp_fb, unsigned int* pfbsize, unsigned int* pPitch )
{
#if ENABLED(FRAMEBUFFER_DEBUG)
unsigned int getPhysRes_w, getPhysRes_h;

// Get physical display size
if (fb_get_phys_res(&getPhysRes_w, &getPhysRes_h) != 0) return FB_GET_DISPLAY_SIZE_FAIL;
cout("Display size: ");cout_d(getPhysRes_w);cout("x");cout_d(getPhysRes_h);cout_endl();
#endif

// Set up the framebuffer and get one
// Set display size
typedef struct
Expand Down Expand Up @@ -194,7 +186,7 @@ FB_RETURN_TYPE fb_init( unsigned int ph_w, unsigned int ph_h, unsigned int vrt_w
msg->tag_virt_size.size = sizeof(msg->value_virt_size);
msg->tag_virt_size.code = 0;
msg->value_virt_size.request.display_w = vrt_w;
msg->value_virt_size.request.display_h = vrt_h;
msg->value_virt_size.request.display_h = vrt_h*2; // our virtual display is double the y size for implementing double buffering

msg->tag_colour_depth.id = MAILBOX_TAG_SET_COLOUR_DEPTH; // Set colour depth
msg->tag_colour_depth.size = sizeof(msg->value_colour_depth);
Expand Down Expand Up @@ -223,24 +215,9 @@ FB_RETURN_TYPE fb_init( unsigned int ph_w, unsigned int ph_h, unsigned int vrt_w
*pp_fb = (void*)mem_vc2arm(msg->value_get_buf.response.bufferaddr);
*pfbsize = msg->value_get_buf.response.buffersize;

#if ENABLED(FRAMEBUFFER_DEBUG)
cout("Set physical display size: ");cout_d(ph_w);cout("x");cout_d(ph_h);cout_endl();
cout("Response: ");cout_d(msg->value_phys_size.response.act_display_w);cout("x");cout_d(msg->value_phys_size.response.act_display_h);cout_endl();
cout("Set virtual display size: ");cout_d(vrt_w);cout("x");cout_d(vrt_h);cout_endl();
cout("Response: ");cout_d(msg->value_virt_size.response.act_display_w);cout("x");cout_d(msg->value_virt_size.response.act_display_h);cout_endl();
cout("Set colour depth: ");cout_d(bpp);cout(" bpp");cout_endl();
cout("Response: ");cout_d(msg->value_colour_depth.response.act_depth);cout(" bpp");cout_endl();
cout("Screen addr: ");cout_h((unsigned int)*pp_fb); cout_endl();
cout("Screen size: ");cout_d(*pfbsize); cout_endl();
#endif

// Get pitch (bytes per line)
if (fb_get_pitch(pPitch) != 0) return FB_INVALID_PITCH;

#if ENABLED(FRAMEBUFFER_DEBUG)
cout("Pitch: "); cout_d(*pPitch); cout_endl();
#endif

return FB_SUCCESS;
}

Expand Down Expand Up @@ -463,3 +440,40 @@ FB_RETURN_TYPE fb_get_pitch( unsigned int* pPitch )
return FB_SUCCESS;
}

FB_RETURN_TYPE fb_switch_framebuffer(unsigned int yOffset)
{
typedef struct {
mbox_msgheader_t header;
mbox_tagheader_t tag;

union {
struct {
uint32_t xOffset;
uint32_t yOffset;
}
request;
// No response.
}
value;

mbox_msgfooter_t footer;
}
message_t;

message_t* msg = (message_t*)MEM_COHERENT_REGION;

msg->header.size = sizeof(*msg);
msg->header.code = 0;
msg->tag.id = MAILBOX_TAG_SET_VIRTUAL_OFFSET;
msg->tag.size = sizeof(msg->value);
msg->tag.code = 0;
msg->value.request.xOffset = 0;
msg->value.request.yOffset = yOffset;
msg->footer.end = 0;

if (mbox_send(msg) != 0) {
return FB_ERROR;
}

return FB_SUCCESS;
}
1 change: 1 addition & 0 deletions src/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ FB_RETURN_TYPE fb_get_phys_res(unsigned int* pRes_w, unsigned int* pRes_h);
extern FB_RETURN_TYPE fb_set_grayscale_palette();
extern FB_RETURN_TYPE fb_set_xterm_palette();
FB_RETURN_TYPE fb_get_pitch( unsigned int* pPitch );
FB_RETURN_TYPE fb_switch_framebuffer(unsigned int yOffset);


#endif
Loading

0 comments on commit 159502f

Please sign in to comment.