Skip to content

Commit

Permalink
Merge branch 'ne2000'
Browse files Browse the repository at this point in the history
  • Loading branch information
polpo committed Nov 23, 2024
2 parents 1761be1 + cf944fa commit 0f5bdc3
Show file tree
Hide file tree
Showing 16 changed files with 1,713 additions and 27 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ jobs:
runs-on: ubuntu-22.04
env:
BUILD_TYPE: "Release"
PICOSDK_VER: "1.5.1"
PICOEXTRA_VER: "sdk-1.5.1"
PICOSDK_VER: "2.0.0"
PICOEXTRA_VER: "sdk-2.0.0"
# The Pico-SDK will listen to these environment vars
PICOTOOL_FETCH_FROM_GIT_PATH: ${{github.workspace}}/pico/picotool
PICO_SDK_PATH: ${{github.workspace}}/pico/pico-sdk
PICO_EXTRAS_PATH: ${{github.workspace}}/pico/pico-extras
OUTPUT_DIR: ${{github.workspace}}/binaries
Expand All @@ -20,7 +21,7 @@ jobs:
- name: Install Arm GNU Toolchain (arm-none-eabi-gcc)
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '13.2.Rel1'
release: '13.3.Rel1'

# Since we reference stable versions of Pico-SDK and pico-extras, we can cache their downloads.
# If this were to reference changing branches (like "master"), this caching step must be removed!!!
Expand Down Expand Up @@ -49,18 +50,27 @@ jobs:
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build

- name: Patch Pico SDK to allow LTO
run: sed -i 's/WRAPPER_FUNC(x) __wrap_/WRAPPER_FUNC(x) __attribute__((used)) __wrap_/' ${{env.PICO_SDK_PATH}}/src/rp2_common/pico_platform/include/pico/platform.h
# - name: Patch Pico SDK to allow LTO
# run: sed -i 's/WRAPPER_FUNC(x) __wrap_/WRAPPER_FUNC(x) __attribute__((used)) __wrap_/' ${{env.PICO_SDK_PATH}}/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h

- name: Build Mega Firmware
shell: bash
working-directory: ${{github.workspace}}/build
run: |
mkdir -p $OUTPUT_DIR
cmake $GITHUB_WORKSPACE/sw -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPROJECT_TYPE="MULTIFW" -DUSE_LTO=1
cmake $GITHUB_WORKSPACE/sw -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPROJECT_TYPE="MULTIFW" #-DUSE_LTO=1
cmake --build . --config $BUILD_TYPE --parallel $(nproc)
cp picogus.uf2 $OUTPUT_DIR/picogus.uf2
- name: Build NE2000 Firmware
shell: bash
working-directory: ${{github.workspace}}/build
run: |
mkdir -p $OUTPUT_DIR
cmake $GITHUB_WORKSPACE/sw -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPROJECT_TYPE="NE2K" -DPICO_BOARD=picow_fast #-DUSE_LTO=1
cmake --build . --config $BUILD_TYPE --parallel $(nproc)
cp pg-ne2k.uf2 $OUTPUT_DIR/pg-ne2k.uf2
# will generate PicoGUS Firmwares.zip as downloadable artifact with all .uf2 files
- name: Upload All Firmwares
uses: actions/upload-artifact@v4
Expand Down
15 changes: 12 additions & 3 deletions common/picogus.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ typedef enum {
TANDY_MODE = 4,
CMS_MODE = 5,
SB_MODE = 6,
USB_MODE = 7
USB_MODE = 7,
NE2000_MODE = 8
} card_mode_t;

static const char *modenames[8] = {
static const char *modenames[9] = {
"INVALID",
"GUS",
"ADLIB",
"MPU",
"TANDY",
"CMS",
"SB",
"USB"
"USB",
"NE2000"
};

#define MODE_MAGIC 0x00 // Magic string
Expand All @@ -62,6 +64,13 @@ static const char *modenames[8] = {
#define MODE_MOUSEPROTO 0x41 // Mouse protocol
#define MODE_MOUSERATE 0x42 // Mouse report rate
#define MODE_MOUSESEN 0x43 // Mouse sensitivity
#define MODE_NE2KPORT 0x50 // NE2000 Base port
#define MODE_WIFISSID 0x51 // NE2000 SSID
#define MODE_WIFIPASS 0x52 // NE2000 password
#define MODE_WIFIAPPLY 0x53 // NE2000 password
#define MODE_WIFISTAT 0x54 // NE2000 wifi status
#define MODE_WIFISCAN 0x55 // NE2000 wifi scan

#define MODE_DEFAULTS 0xE0 // Select reset to defaults register
#define MODE_SAVE 0xE1 // Select save settings register
#define MODE_REBOOT 0xE2 // Select reboot register
Expand Down
97 changes: 95 additions & 2 deletions pgusinit/pgusinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../common/picogus.h"

static void banner(void) {
printf("PicoGUSinit v3.1.0 (c) 2024 Ian Scott - licensed under the GNU GPL v2\n");
printf("PicoGUSinit v3.2.0 (c) 2024 Ian Scott - licensed under the GNU GPL v2\n");
}


Expand Down Expand Up @@ -73,6 +73,15 @@ static void usage(char *argv0, card_mode_t mode, bool print_all) {
printf(" (increase for smoother cursor movement, decrease for lower CPU load)\n");
printf(" /mousesen n - set mouse sensitivity (256 - 100%, 128 - 50%, 512 - 200%)\n");
}
if (mode == NE2000_MODE || print_all) {
// "................................................................................\n"
printf("NE2000/WiFi settings:\n");
printf(" /ne2kport x - set the base port of the NE2000. Default: 300\n");
printf(" /wifissid abc - set the WiFi SSID to abc\n");
printf(" /wifipass xyz - set the WiFi WPA/WPA2 password/key to xyz\n");
printf(" /wifinopass - unset the WiFi password to connect to an open access point\n");
printf(" /wifistatus - print current WiFi status\n");
}
}

static const char* mouse_protocol_str[] = {
Expand Down Expand Up @@ -349,6 +358,43 @@ static int write_firmware(const char* fw_filename) {
return 0;
}

static void wifi_printStatus(void)
{
outp(CONTROL_PORT, 0xCC); // Knock on the door...
outp(CONTROL_PORT, MODE_WIFISTAT); // Select WiFi status mode
outp(DATA_PORT_HIGH, 0); // Write to start getting the status

printf("WiFi status: ");
uint16_t try = 0;
char c;
while (c = inp(DATA_PORT_HIGH)) {
if (c == 255) {
if (++try == 10000) {
printf("Error getting WiFI status\n");
break;
} else {
continue;
}
}
putchar(c);
}
putchar('\n');
}

static void send_string(uint8_t mode, char* str, int16_t max_len)
{
outp(CONTROL_PORT, 0xCC); // Knock on the door...
outp(CONTROL_PORT, mode);
char chr;
for (int i = 0; i < max_len; ++i) {
if (str[i] == 0) { // End of string
break;
}
outp(DATA_PORT_HIGH, str[i]);
}
outp(DATA_PORT_HIGH, 0);
}

#define process_bool_opt(option) \
if (i + 1 >= argc) { \
usage(argv[0], mode, false); \
Expand Down Expand Up @@ -378,6 +424,9 @@ int main(int argc, char* argv[]) {
uint8_t enable_joystick = 0;
uint8_t wtvol;
char fw_filename[256] = {0};
char wifi_ssid[33] = {0};
char wifi_pass[64] = {0};
bool nopass = false;
card_mode_t mode;
char mode_name[8] = {0};
int fw_num = 8;
Expand All @@ -389,7 +438,7 @@ int main(int argc, char* argv[]) {
outp(CONTROL_PORT, MODE_MAGIC); // Select magic string register
if (inp(DATA_PORT_HIGH) != 0xDD) {
err_pigus();
return 99;
//return 99;
};
printf("PicoGUS detected: ");
print_firmware_string();
Expand All @@ -409,6 +458,7 @@ int main(int argc, char* argv[]) {
}
return write_firmware(fw_filename);
}
printf("arg: %s\n", argv[i]);
++i;
}

Expand Down Expand Up @@ -603,6 +653,38 @@ int main(int argc, char* argv[]) {
}
outp(CONTROL_PORT, MODE_MOUSERATE);
outp(DATA_PORT_HIGH, tmp_uint8);
// NE2000/WiFi options /////////////////////////////////////////////////////////////////
} else if (stricmp(argv[i], "/ne2kport") == 0) {
process_port_opt(tmp_uint16);
outp(CONTROL_PORT, MODE_NE2KPORT); // Select NE2000 port register
outpw(DATA_PORT_LOW, tmp_uint16); // Write port
} else if (stricmp(argv[i], "/wifistatus") == 0) {
wifi_printStatus();
} else if (stricmp(argv[i], "/wifissid") == 0) {
if (i + 1 >= argc) {
usage(argv[0], mode, false);
return 255;
}
e = sscanf(argv[++i], "%32s", wifi_ssid);
if (e != 1) {
usage(argv[0], mode, false);
return 4;
}
send_string(MODE_WIFISSID, wifi_ssid, 32);
} else if (stricmp(argv[i], "/wifipass") == 0) {
if (i + 1 >= argc) {
usage(argv[0], mode, false);
return 255;
}
e = sscanf(argv[++i], "%63s", wifi_pass);
if (e != 1) {
usage(argv[0], mode, false);
return 4;
}
send_string(MODE_WIFIPASS, wifi_pass, 63);
} else if (stricmp(argv[i], "/wifinopass") == 0) {
nopass = true;
send_string(MODE_WIFIPASS, "", 1);
} else {
printf("Unknown option: %s\n", argv[i]);
usage(argv[0], mode, false);
Expand All @@ -627,6 +709,11 @@ int main(int argc, char* argv[]) {
return reboot_to_firmware(fw_num, permanent);
}

if (wifi_ssid[0] || wifi_pass[0] || nopass) {
outp(CONTROL_PORT, MODE_WIFIAPPLY);
outp(DATA_PORT_HIGH, 0);
}

outp(CONTROL_PORT, MODE_HWTYPE); // Select hardware type register
board_type_t board_type = inp(DATA_PORT_HIGH);
if (board_type == PICO_BASED) {
Expand Down Expand Up @@ -733,6 +820,12 @@ int main(int argc, char* argv[]) {
printf("(AdLib port disabled)\n");
}
break;
case NE2000_MODE:
outp(CONTROL_PORT, MODE_NE2KPORT); // Select port register
tmp_uint16 = inpw(DATA_PORT_LOW); // Get port
printf("Running in NE2000 mode on port %x\n", tmp_uint16);
wifi_printStatus();
break;
default:
printf("Running in unknown mode (maybe upgrade pgusinit?)\n");
break;
Expand Down
40 changes: 35 additions & 5 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

cmake_minimum_required(VERSION 3.13)

set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR})
if(NOT PICO_BOARD)
set(PICO_BOARD "picogus2")
message("PICO_BOARD not set, defaulting to ${PROJECT_TYPE}")
endif()
set(PICO_COPY_TO_RAM 1)

# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
Expand All @@ -22,10 +28,6 @@ set(CMAKE_CXX_STANDARD 17)

include(pico_extras_import.cmake)

set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR})
set(PICO_BOARD picogus2)
set(PICO_COPY_TO_RAM 1)

# Tell the Pico SDK to use our local tinyusb instead of the one included in the SDK
# This is needed to support tusb_xinput
set(PICO_TINYUSB_PATH ${CMAKE_CURRENT_LIST_DIR}/tinyusb)
Expand Down Expand Up @@ -176,7 +178,7 @@ endfunction()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tusb_xinput)
add_subdirectory(rp2040-psram)
add_subdirectory(opl)

add_subdirectory(ne2000)

################################################################################
# Build GUS firmware
Expand Down Expand Up @@ -311,6 +313,31 @@ function(build_usb TARGET_NAME MULTIFW)
endfunction()


function(build_ne2k TARGET_NAME MULTIFW)
config_target(${TARGET_NAME} ${MULTIFW})
pico_set_program_name(${TARGET_NAME} "picogus-ne2k")
# set(USB_JOYSTICK FALSE)
# set(PICO_BOARD PICO_W) # For now, until USB Dongle
# set(PICO_BOARD picow-fast)
#set(PICO_CYW43_SUPPORTED "1")
#pico_register_common_scope_var(PICO_CYW43_SUPPORTED)
target_compile_definitions(${TARGET_NAME} PRIVATE
NE2000=1
PICOW=1
# CYW43_RESOURCE_ATTRIBUTE="__in_flash()"
CYW43_CONFIG_FILE="cyw43_firmware.h"
CYW43_PIO_CLOCK_DIV_INT=3
)
target_sources(${TARGET_NAME} PRIVATE
ne2000play.cpp
)
target_link_libraries(
${TARGET_NAME}
ne2000
)
endfunction()


################################################################################
# Build "multifw" - all firmwares in one UF2
if(PROJECT_TYPE STREQUAL "MULTIFW")
Expand Down Expand Up @@ -436,6 +463,9 @@ elseif(PROJECT_TYPE STREQUAL "CMS")
elseif(PROJECT_TYPE STREQUAL "USB")
set(FW_TARGET pg-usb)
build_usb(pg-usb FALSE)
elseif(PROJECT_TYPE STREQUAL "NE2K")
set(FW_TARGET pg-ne2k)
build_ne2k(pg-ne2k FALSE)
endif()

################################################################################
Expand Down
8 changes: 8 additions & 0 deletions sw/flash_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "flash_settings.h"
#include "hardware/flash.h"
#include "hardware/sync.h"
#include "hardware/clocks.h"
#include "pico/stdlib.h"
#include "pico/flash.h"

Expand Down Expand Up @@ -44,6 +45,13 @@ static const Settings defaultSettings = {
.protocol = 0,
.reportRate = 60,
.sensitivity = 0x100
},
.NE2K = {
.basePort = 0x300,
},
.WiFi = {
.ssid = {0},
.password = {0}
}
};

Expand Down
9 changes: 8 additions & 1 deletion sw/flash_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
#include <stdbool.h>

#define SETTINGS_MAGIC 0x70677573 // "pgus" in ascii
#define SETTINGS_VERSION 1
#define SETTINGS_VERSION 2

// Settings struct has generous padding for future settings by aligning to 4 bytes
typedef struct Settings {
Expand Down Expand Up @@ -49,6 +49,13 @@ typedef struct Settings {
uint8_t reportRate;
int16_t sensitivity;
} Mouse;
struct {
uint16_t basePort;
} NE2K;
struct {
char ssid[33];
char password[64];
} WiFi;
} Settings;


Expand Down
28 changes: 28 additions & 0 deletions sw/ne2000/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
add_library(ne2000 INTERFACE)

# if(NOT PICO_BOARD STREQUAL "PICO_W")
# message(FATAL_ERROR "NE2000 Requires Pico W")
# endif()



target_include_directories(ne2000 INTERFACE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/ne2000
)

target_sources(ne2000 INTERFACE
${CMAKE_CURRENT_LIST_DIR}/ne2000.c
)

target_link_libraries(ne2000 INTERFACE
pico_cyw43_arch_none
# pico_cyw43_arch_poll
)
# target_compile_definitions(pico_cyw43_arch_poll_headers INTERFACE
# CYW43_LWIP=0
# )
# target_compile_definitions(ne2000 INTERFACE
# CYW43_LWIP=0
# )

Loading

0 comments on commit 0f5bdc3

Please sign in to comment.