Merge pull request #2525 from jepler/runcpm

Updates to the code for the Runcpm-pico guide
This commit is contained in:
Anne Barela 2023-06-12 16:17:58 -04:00 committed by GitHub
commit e659987db5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 33 deletions

View file

@ -5,6 +5,7 @@
// pio-usb is required for rp2040 host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
#include "pico/stdlib.h"
// Pin D+ for host, D- = D+ + 1
#ifndef PIN_USB_HOST_DP
@ -34,20 +35,14 @@ void loop() {
void setup1() {
// override tools menu CPU frequency setting
set_sys_clock_khz(120'000, true);
#if 0
while ( !Serial ) delay(10); // wait for native usb
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
#endif
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
uint32_t cpu_hz = clock_get_hz(clk_sys);
if ( cpu_hz != 120000000UL && cpu_hz != 240000000UL ) {
while ( !Serial ) delay(10); // wait for native usb
Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
while (1) delay(1);
}
#ifdef PIN_5V_EN
pinMode(PIN_5V_EN, OUTPUT);
digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
@ -68,9 +63,11 @@ void setup1() {
int old_ascii = -1;
uint32_t repeat_timeout;
const uint32_t repeat_time = 150;
// this matches Linux default of 500ms to first repeat, 1/20s thereafter
const uint32_t default_repeat_time = 50;
const uint32_t initial_repeat_time = 500;
void send_ascii(uint8_t code) {
void send_ascii(uint8_t code, uint32_t repeat_time=default_repeat_time) {
old_ascii = code;
repeat_timeout = millis() + repeat_time;
if (code > 32 && code < 127) {
@ -86,9 +83,8 @@ void loop1()
uint32_t now = millis();
uint32_t deadline = repeat_timeout - now;
if (old_ascii >= 0 && deadline > INT32_MAX) {
repeat_timeout += repeat_time;
deadline = repeat_timeout - now;
send_ascii(old_ascii);
deadline = repeat_timeout - now;
} else if (old_ascii < 0) {
deadline = UINT32_MAX;
}
@ -133,7 +129,7 @@ const char * const lut[] = {
"!@#$%^&*()", /* 0 - shifted numeric keys */
"\r\x1b\10\t -=[]\\#;'`,./", /* 1 - symbol keys */
"\n\x1b\177\t _+{}|~:\"~<>?", /* 2 - shifted */
"\3\4\2\1", /* 3 - arrow keys RLDU */
"\12\13\10\22", /* 3 - arrow keys RLDU */
"/*-+\n1234567890.", /* 4 - keypad w/numlock */
"/*-+\n\xff\2\xff\4\xff\3\xff\1\xff\xff.", /* 5 - keypad w/o numlock */
};
@ -217,7 +213,7 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
}
if (ctrl) code &= 0x1f;
if (alt) code ^= 0x80;
send_ascii(code);
send_ascii(code, initial_repeat_time);
break;
}
}

View file

@ -515,7 +515,7 @@ uint8 _getch(void) {
uint8 _getche(void) {
uint8 ch = _getch();
Serial.write(ch);
_putch(ch);
return(ch);
}

View file

@ -91,7 +91,7 @@
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
// #define CCPHEAD "\r\nRunCPM Version " VERSION " (CP/M " STR(TPASIZE) "K)\r\n"
#define CCPHEAD "\r\nRunCPM [\e[1mv" VERSION "\e[0m] => CCP:[\e[1m" CCPname "\e[0m] TPA:[\e[1m" STR(TPASIZE) "K\e[0m]\r\n"
#define CCPHEAD "\r\nRunCPM [" TEXT_BOLD "v" VERSION TEXT_NORMAL "] => CCP:[" TEXT_BOLD CCPname TEXT_NORMAL "] TPA:" TEXT_BOLD STR(TPASIZE) "K" TEXT_NORMAL "\r\n"
#define NOSLASH // Will translate '/' to '_' on filenames to prevent directory errors

View file

@ -4,23 +4,26 @@
// SPDX-License-Identifier: MIT
#include <SdFat.h> // SDFat - Adafruit Fork
#include <Adafruit_TinyUSB.h>
#include <PicoDVI.h>
#include "../../console.h"
#include "../../arduino_hooks.h"
#undef USE_DISPLAY
#ifndef USE_DISPLAY
#define USE_DISPLAY (1)
#endif
#ifndef USE_MSC
#define USE_MSC (0)
#endif
#if USE_DISPLAY
DVItext1 display(DVI_RES_800x240p60, adafruit_feather_dvi_cfg);
DVItext1 display(DVI_RES_800x240p30, adafruit_feather_dvi_cfg);
#endif
#define SPI_CLOCK (20'000'000)
#define SD_CS_PIN (10)
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
DedicatedSpiCard blockdevice;
FatFileSystem SD; // Filesystem object from SdFat
Adafruit_USBD_MSC usb_msc; // USB mass storage object
// =========================================================================================
// Define Board-Data
@ -34,6 +37,8 @@ Adafruit_USBD_MSC usb_msc; // USB mass storage object
// FUNCTIONS REQUIRED FOR USB MASS STORAGE ---------------------------------
#if USE_MSC
Adafruit_USBD_MSC usb_msc; // USB mass storage object
static bool msc_changed = true; // Is set true on filesystem changes
// Callback on READ10 command.
@ -54,11 +59,7 @@ void msc_flush_cb(void) {
digitalWrite(LED_BUILTIN, LOW);
msc_changed = true;
}
void _puthex32(uint32_t x) {
_puthex16(x >> 16);
_puthex16(x & 0xffff);
}
#endif
#if USE_DISPLAY
uint16_t underCursor = ' ';
@ -97,14 +98,16 @@ bool kbhit_serial1(void) {
bool port_init_early() {
#if USE_DISPLAY
// vreg_set_voltage(VREG_VOLTAGE_1_30);
vreg_set_voltage(VREG_VOLTAGE_1_20);
delay(10);
if (!display.begin()) { return false; }
_putch_hook = putch_display;
#endif
_getch_hook = getch_serial1;
_kbhit_hook = kbhit_serial1;
// USB mass storage / filesystem setup (do BEFORE Serial init)
if (!blockdevice.begin(SD_CONFIG)) { _puts("!blockdevice.begin()"); return false; }
if (!blockdevice.begin(SD_CONFIG)) { _puts("Failed to initialize SD card"); return false; }
#if USE_MSC
// Set disk vendor id, product id and revision
usb_msc.setID("Adafruit", "Internal Flash", "1.0");
// Set disk size, block size is 512 regardless of blockdevice page size
@ -112,8 +115,9 @@ bool port_init_early() {
usb_msc.setReadWriteCallback(msc_read_cb, msc_write_cb, msc_flush_cb);
usb_msc.setUnitReady(true); // MSC is ready for read/write
if (!usb_msc.begin()) {
_puts("!usb_msc.begin()"); return false;
_puts("Failed to initialize USB MSC"); return false;
}
#endif
return true;
}

View file

@ -5,8 +5,6 @@
// only AVR and ARM CPU
// #include <MemoryFree.h>
#include "globals.h"
// =========================================================================================
// Guido Lehwalder's Code-Revision-Number
// =========================================================================================
@ -16,10 +14,21 @@
#include <SdFat.h> // One SD library to rule them all - Greinman SdFat from Library Manager
#include <Adafruit_SPIFlash.h>
#include <Adafruit_TinyUSB.h>
#ifndef USE_VT100
#define USE_VT100 (0)
#endif
#if USE_VT100
#define TEXT_BOLD "\033[1m"
#define TEXT_NORMAL "\033[0m"
#else
#define TEXT_BOLD ""
#define TEXT_NORMAL ""
#endif
#include "globals.h"
// =========================================================================================
// Board definitions go into the "hardware" folder, if you use a board different than the
@ -133,7 +142,7 @@ void setup(void) {
// { _puts("Recognized " TEXT_BOLD "#" TEXT_NORMAL " key as pressed! :)\r\n\r\n");
// }
_puts("CP/M Emulator " TEXT_BOLD "v" VERSION "" TEXT_NORMAL " by " TEXT_BOLD "Marcelo Dantas\e[0m\r\n");
_puts("CP/M Emulator " TEXT_BOLD "v" VERSION "" TEXT_NORMAL " by " TEXT_BOLD "Marcelo Dantas" TEXT_NORMAL "\r\n");
_puts("----------------------------------------------\r\n");
_puts(" running on [" TEXT_BOLD BOARD_TEXT TEXT_NORMAL "]\r\n");
_puts("----------------------------------------------\r\n");