Skip to content

Commit

Permalink
Merge pull request #18 from visrealm/dev
Browse files Browse the repository at this point in the history
0.4.3
  • Loading branch information
visrealm authored Oct 19, 2024
2 parents 8d696b6 + aae034f commit 947e958
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 48 deletions.
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Pico",
"includePath": [
"${workspaceFolder}/**",
"${userHome}/.pico-sdk/sdk/2.0.0/**"
],
"forcedInclude": [
"${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h",
"${userHome}/.pico-sdk/sdk/2.0.0/src/common/pico_base_headers/include/pico.h"
],
"defines": [],
"compilerPath": "${userHome}/.pico-sdk/toolchain/13_3_Rel1/bin/arm-none-eabi-gcc",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-arm"
}
],
"version": 4
}
16 changes: 16 additions & 0 deletions .vscode/cmake-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": "Pico",
"compilers": {
"C": "${userHome}/.pico-sdk/toolchain/13_2_Rel1/bin/arm-none-eabi-gcc.exe",
"CXX": "${userHome}/.pico-sdk/toolchain/13_2_Rel1/bin/arm-none-eabi-gcc.exe"
},
"toolchainFile": "${env:USERPROFILE}/.pico-sdk/sdk/2.0.0/cmake/preload/toolchains/pico_arm_cortex_m0plus_gcc.cmake",
"environmentVariables": {
"PATH": "${command:raspberry-pi-pico.getEnvPath};${env:PATH}"
},
"cmakeSettings": {
"Python3_EXECUTABLE": "${command:raspberry-pi-pico.getPythonPath}"
}
}
]
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"marus25.cortex-debug",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.vscode-serial-monitor",
"raspberry-pi.raspberry-pi-pico",
]
}
69 changes: 69 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug (Cortex-Debug)",
"cwd": "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"serverpath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
"device": "${command:raspberry-pi-pico.getChipUppercase}",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/${command:raspberry-pi-pico.getTarget}.cfg"
],
"svdFile": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
"runToEntryPoint": "main",
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
// Also works fine for flash binaries
"overrideLaunchCommands": [
"monitor reset init",
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
],
"openOCDLaunchCommands": [
"adapter speed 5000"
]
},
{
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
"cwd": "${workspaceRoot}",
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "external",
"gdbTarget": "localhost:3333",
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
"device": "${command:raspberry-pi-pico.getChipUppercase}",
"svdFile": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
"runToEntryPoint": "main",
// Give restart the same functionality as runToEntryPoint - main
"postRestartCommands": [
"break main",
"continue"
]
},
{
"name": "Pico Debug (C++ Debugger)",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${command:raspberry-pi-pico.launchTargetPath}",
"MIMode": "gdb",
"miDebuggerPath": "${command:raspberry-pi-pico.getGDBPath}",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"debugServerArgs": "-f interface/cmsis-dap.cfg -f target/${command:raspberry-pi-pico.getTarget}.cfg -c \"adapter speed 5000\"",
"serverStarted": "Listening on port .* for gdb connections",
"filterStderr": true,
"hardwareBreakpoints": {
"require": true,
"limit": 4
},
"preLaunchTask": "Flash",
"svdPath": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd"
},
]
}
58 changes: 58 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile Project",
"type": "process",
"isBuildCommand": true,
"command": "${userHome}/.pico-sdk/ninja/v1.12.1/ninja",
"args": ["-C", "${workspaceFolder}/build"],
"group": "build",
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"problemMatcher": "$gcc",
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1/ninja.exe"
}
},
{
"label": "Run Project",
"type": "process",
"command": "${env:HOME}/.pico-sdk/picotool/2.0.0/picotool/picotool",
"args": [
"load",
"${command:raspberry-pi-pico.launchTargetPath}",
"-fx"
],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/picotool/2.0.0/picotool/picotool.exe"
}
},
{
"label": "Flash",
"type": "process",
"command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"args": [
"-s",
"${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"-f",
"interface/cmsis-dap.cfg",
"-f",
"target/${command:raspberry-pi-pico.getTarget}.cfg",
"-c",
"adapter speed 5000; program \"${command:raspberry-pi-pico.launchTargetPath}\" verify reset exit"
],
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
}
}
]
}
22 changes: 19 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ cmake_minimum_required(VERSION 3.13)

# compile-time options

set(PICO9918_VERSION "0.4.2")
set(PICO9918_VERSION "0.4.3")
set(PICO9918_PCB_MAJOR_VER 0)
set(PICO9918_PCB_MINOR_VER 4)

set(PICO9918_SCANLINES 1)

# SCART RGBs options
set(PICO9918_SCART_RGBS 0) # 1 for RGBs, 0 for VGA
set(PICO9918_SCART_PAL 0) # 1 for PAL 576i, 0 for NTSC 480i

# end compile-time options


Expand All @@ -21,9 +25,19 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (${PICO9918_SCART_RGBS})
if (${PICO9918_SCART_PAL})
set(PICO9918_OUTPUT_STR "rgbs-pal576i")
else()
set(PICO9918_OUTPUT_STR "rgbs-ntsc480i")
endif()
else()
set(PICO9918_OUTPUT_STR "vga")
endif()

string(REPLACE "." "-" PICO9918_VERSION_STR "${PICO9918_VERSION}")

set(PICO9918_BINARY_SUFFIX -pcb-v${PICO9918_PCB_MAJOR_VER}-${PICO9918_PCB_MINOR_VER}-${PICO9918_GIT_BRANCH}-build-${PICO9918_VERSION_STR})
set(PICO9918_BINARY_SUFFIX -pcb-v${PICO9918_PCB_MAJOR_VER}-${PICO9918_PCB_MINOR_VER}-${PICO9918_OUTPUT_STR}-build-${PICO9918_VERSION_STR})

if (${PICO9918_SCANLINES})
set(PICO9918_BINARY_SUFFIX ${PICO9918_BINARY_SUFFIX}-sl)
Expand Down Expand Up @@ -55,12 +69,14 @@ pico_add_extra_outputs(${PROGRAM})
pico_enable_stdio_usb(${PROGRAM} 0)
pico_enable_stdio_uart(${PROGRAM} 0)

pico_set_binary_type(${PROGRAM} copy_to_ram) # TOO SLOW TO BOOT
pico_set_binary_type(${PROGRAM} copy_to_ram)

add_definitions(-DPICO9918_VERSION="${PICO9918_VERSION}")
add_definitions(-DPICO9918_PCB_MAJOR_VER=${PICO9918_PCB_MAJOR_VER})
add_definitions(-DPICO9918_PCB_MINOR_VER=${PICO9918_PCB_MINOR_VER})
add_definitions(-DPICO9918_SCANLINES=${PICO9918_SCANLINES})
add_definitions(-DPICO9918_SCART_RGBS=${PICO9918_SCART_RGBS})
add_definitions(-DPICO9918_SCART_PAL=${PICO9918_SCART_PAL})

add_definitions(-DPICO_DISABLE_SHARED_IRQ_HANDLERS=1)
#add_definitions(-DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1)
Expand Down
32 changes: 24 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
* https://www.aliexpress.com/item/1005007066733934.html
*/

#define PCB_MAJOR_VERSION 0
#define PCB_MINOR_VERSION 4
#define PCB_MAJOR_VERSION PICO9918_PCB_MAJOR_VER
#define PCB_MINOR_VERSION PICO9918_PCB_MINOR_VER

#define GPIO_CD7 14
#define GPIO_CSR tmsRead_CSR_PIN // defined in tms9918.pio
Expand Down Expand Up @@ -97,9 +97,16 @@

#define TMS_CRYSTAL_FREQ_HZ 10738635.0f

#define PICO_CLOCK_PLL 1260000000
#define PICO_CLOCK_PLL_DIV1 5
#define PICO_CLOCK_PLL_DIV2 1
#if PICO9918_SCART_RGBS // for 15kHz
#define PICO_CLOCK_PLL 1536000000
#define PICO_CLOCK_PLL_DIV1 3
#define PICO_CLOCK_PLL_DIV2 2
#else // for 31.46875 kHz
#define PICO_CLOCK_PLL 1260000000
#define PICO_CLOCK_PLL_DIV1 5
#define PICO_CLOCK_PLL_DIV2 1
#endif

#define PICO_CLOCK_HZ (PICO_CLOCK_PLL / PICO_CLOCK_PLL_DIV1 / PICO_CLOCK_PLL_DIV2)

#define TMS_PIO pio1
Expand Down Expand Up @@ -206,7 +213,7 @@ static inline void disableTmsPioInterrupts()
static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uint16_t* pixels)
{

#if 1
#if 0
// better compile-time optimizations if we hard-code these
#define VIRTUAL_PIXELS_X 640
#define VIRTUAL_PIXELS_Y 240
Expand Down Expand Up @@ -394,7 +401,7 @@ void tmsPioInit()
sm_config_set_out_pins(&readConfig, GPIO_CD7, 8);
sm_config_set_in_shift(&readConfig, false, false, 32); // L shift
sm_config_set_out_shift(&readConfig, true, false, 32); // R shift
sm_config_set_clkdiv(&readConfig, 1.0f);
sm_config_set_clkdiv(&readConfig, 4.0f);

pio_sm_init(TMS_PIO, tmsReadSm, tmsReadProgram, &readConfig);
pio_sm_set_enabled(TMS_PIO, tmsReadSm, true);
Expand Down Expand Up @@ -446,10 +453,19 @@ int main(void)

/* then set up VGA output */
VgaInitParams params = { 0 };

#if PICO9918_SCART_RGBS
#if PICO9918_SCART_PAL
params.params = vgaGetParams(RGBS_PAL_720_576i_50HZ);
#else
params.params = vgaGetParams(RGBS_NTSC_720_480i_60HZ);
#endif
#else // VGA
params.params = vgaGetParams(VGA_640_480_60HZ);

/* virtual size will be 640 x 320 to accomodate 80-column mode */
/* virtual size will be 640 x 240 to accomodate 80-column mode */
setVgaParamsScaleY(&params.params, 2);
#endif

/* set vga scanline callback to generate tms9918 scanlines */
params.scanlineFn = tmsScanline;
Expand Down
Binary file modified src/res/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/vga/vga-modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,37 @@ VgaParams vgaGetParams(VgaMode mode)
params.vSyncParams.backPorchPixels = 38;
params.vSyncParams.syncHigh = true;
break;

case RGBS_PAL_720_576i_50HZ:
params.pixelClockKHz = 13500;
params.hSyncParams.displayPixels = 720;
params.hSyncParams.frontPorchPixels = 22;
params.hSyncParams.syncPixels = 64;
params.hSyncParams.backPorchPixels = 74;
params.hSyncParams.syncHigh = false;

params.vSyncParams.displayPixels = 576 / 2; // halving since... interlaced
params.vSyncParams.frontPorchPixels = 8;
params.vSyncParams.syncPixels = 3; // this should be 2.5
params.vSyncParams.backPorchPixels = 14;
params.vSyncParams.syncHigh = false;
break;

case RGBS_NTSC_720_480i_60HZ:
params.pixelClockKHz = 13500;
params.hSyncParams.displayPixels = 720;
params.hSyncParams.frontPorchPixels = 22;
params.hSyncParams.syncPixels = 64;
params.hSyncParams.backPorchPixels = 74;
params.hSyncParams.syncHigh = false;

params.vSyncParams.displayPixels = 480 / 2; // halving since... interlaced
params.vSyncParams.frontPorchPixels = 3;
params.vSyncParams.syncPixels = 3;
params.vSyncParams.backPorchPixels = 17; // this should be 16.5
params.vSyncParams.syncHigh = false;
break;

}

if (params.pixelClockKHz && params.hSyncParams.displayPixels && params.vSyncParams.displayPixels)
Expand Down
2 changes: 2 additions & 0 deletions src/vga/vga-modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ typedef enum
VGA_800_600_60HZ,
VGA_1024_768_60HZ,
VGA_1280_1024_60HZ,
RGBS_PAL_720_576i_50HZ,
RGBS_NTSC_720_480i_60HZ,
} VgaMode;


Expand Down
Loading

0 comments on commit 947e958

Please sign in to comment.