Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
udo-munk committed Sep 2, 2024
2 parents cc3a4e1 + 4498fbc commit 3cd55d9
Show file tree
Hide file tree
Showing 32 changed files with 823 additions and 65 deletions.
15 changes: 15 additions & 0 deletions doc/README-pico.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ on the breadbaord. The card drives can draw 100 mA, so better provide
sufficient GND. Also please note the two blocking capacitors, these are
to keep radio emissions low.

picoboard4:
I removed the monochrome LED and instead added a breakout board with a
WS2811 RGB LED. With this we can show stati of the machine by using
different colors, show access to the disk drives, or blink it from
the emulated CPU's. These RGB LED's need 5V power, which is available
at pin 40 comming from the USB connection. The data in pin is connected
to GPIO 14 and the 3.3V logic level from the GPIO is fine to program the
LED, a logic level shifter is not needed.

pico-rtc-*
I added a battery backed RTC, so that date and time stays current, without
the need to set it all the time. For my breadboard research system I used
the stackable module from Waveshare:
https://www.waveshare.com/wiki/Pico-RTC-DS3231

How to build the application for this board is explained in picosim/README.
Binary file added doc/pico-rtc-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/pico-rtc-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/pico-rtc-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/pico-rtc-4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/pico-rtc-5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/picoboard4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions picosim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ add_executable(${PROJECT_NAME}
${Z80PACK}/z80core/simz80.c
)

# generate the header file into the source tree
pico_generate_pio_header(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/WS2812.pio)

target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_SOURCE_DIR}
${Z80PACK}/iodevices
Expand All @@ -56,6 +59,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC

add_subdirectory(no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src FatFs)
add_subdirectory(stdio_msc_usb)
add_subdirectory(ds3231)

target_compile_definitions(${PROJECT_NAME} PRIVATE
PICO_STACK_SIZE=4096
Expand All @@ -78,13 +82,17 @@ target_compile_options(${PROJECT_NAME} PUBLIC -Wno-unused-parameter)

# for Pico
target_link_libraries(${PROJECT_NAME}
hardware_i2c
pico-ds3231
pico_stdlib
stdio_msc_usb
tinyusb_device
no-OS-FatFS-SD-SDIO-SPI-RPi-Pico
)
# for Pico W
#target_link_libraries(${PROJECT_NAME}
# hardware_i2c
# pico-ds3231
# pico_stdlib
# pico_cyw43_arch_none
# stdio_msc_usb
Expand Down
85 changes: 85 additions & 0 deletions picosim/WS2812.pio
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
;
; Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
;
; SPDX-License-Identifier: BSD-3-Clause
;

.program ws2812
.side_set 1

.define public T1 2
.define public T2 5
.define public T3 3

.lang_opt python sideset_init = pico.PIO.OUT_HIGH
.lang_opt python out_init = pico.PIO.OUT_HIGH
.lang_opt python out_shiftdir = 1

.wrap_target
bitloop:
out x, 1 side 0 [T3 - 1] ; Side-set still takes place when instruction stalls
jmp !x do_zero side 1 [T1 - 1] ; Branch on the bit we shifted out. Positive pulse
do_one:
jmp bitloop side 1 [T2 - 1] ; Continue driving high, for a long pulse
do_zero:
nop side 0 [T2 - 1] ; Or drive low, for a short pulse
.wrap

% c-sdk {
#include "hardware/clocks.h"

static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, float freq, bool rgbw) {

pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);

pio_sm_config c = ws2812_program_get_default_config(offset);
sm_config_set_sideset_pins(&c, pin);
sm_config_set_out_shift(&c, false, true, rgbw ? 32 : 24);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);

int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
sm_config_set_clkdiv(&c, div);

pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}

.program ws2812_parallel

.define public T1 2
.define public T2 5
.define public T3 3

.wrap_target
out x, 32
mov pins, !null [T1-1]
mov pins, x [T2-1]
mov pins, null [T3-2]
.wrap

% c-sdk {
#include "hardware/clocks.h"

static inline void ws2812_parallel_program_init(PIO pio, uint sm, uint offset, uint pin_base, uint pin_count, float freq) {
for(uint i=pin_base; i<pin_base+pin_count; i++) {
pio_gpio_init(pio, i);
}
pio_sm_set_consecutive_pindirs(pio, sm, pin_base, pin_count, true);

pio_sm_config c = ws2812_parallel_program_get_default_config(offset);
sm_config_set_out_shift(&c, true, true, 32);
sm_config_set_out_pins(&c, pin_base, pin_count);
sm_config_set_set_pins(&c, pin_base, pin_count);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);

int cycles_per_bit = ws2812_parallel_T1 + ws2812_parallel_T2 + ws2812_parallel_T3;
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
sm_config_set_clkdiv(&c, div);

pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}
25 changes: 19 additions & 6 deletions picosim/disks.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "sd-fdc.h"
#include "disks.h"
#include "rgbled.h"

FIL sd_file; /* at any time we have only one file open */
FRESULT sd_res; /* result code from FatFS */
Expand Down Expand Up @@ -268,22 +269,28 @@ BYTE read_sec(int drive, int track, int sector, WORD addr)
if ((stat = prep_io(drive, track, sector, addr)) != FDC_STAT_OK)
return stat;

put_pixel(0x440000); /* LED green */

/* read sector into memory */
sd_res = f_read(&sd_file, &dsk_buf[0], SEC_SZ, &br);
if (sd_res == FR_OK) {
if (br < SEC_SZ) { /* UH OH */
f_close(&sd_file);
return FDC_STAT_READ;
stat = FDC_STAT_READ;
} else {
f_close(&sd_file);
for (i = 0; i < SEC_SZ; i++)
dma_write(addr + i, dsk_buf[i]);
return FDC_STAT_OK;
stat = FDC_STAT_OK;
}
} else {
f_close(&sd_file);
return FDC_STAT_READ;
stat = FDC_STAT_READ;
}

sleep_us(300);
put_pixel(0x000000); /* LED off */
return stat;
}

/*
Expand All @@ -299,22 +306,28 @@ BYTE write_sec(int drive, int track, int sector, WORD addr)
if ((stat = prep_io(drive, track, sector, addr)) != FDC_STAT_OK)
return stat;

put_pixel(0x004400); /* LED red */

/* write sector to disk image */
for (i = 0; i < SEC_SZ; i++)
dsk_buf[i] = dma_read(addr + i);
sd_res = f_write(&sd_file, &dsk_buf[0], SEC_SZ, &br);
if (sd_res == FR_OK) {
if (br < SEC_SZ) { /* UH OH */
f_close(&sd_file);
return FDC_STAT_WRITE;
stat = FDC_STAT_WRITE;
} else {
f_close(&sd_file);
return FDC_STAT_OK;
stat = FDC_STAT_OK;
}
} else {
f_close(&sd_file);
return FDC_STAT_WRITE;
stat = FDC_STAT_WRITE;
}

sleep_us(300);
put_pixel(0x000000); /* LED off */
return stat;
}

/*
Expand Down
17 changes: 17 additions & 0 deletions picosim/ds3231/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_library(pico-ds3231 INTERFACE)

target_include_directories(pico-ds3231
INTERFACE
${CMAKE_CURRENT_LIST_DIR}
)

target_link_libraries(pico-ds3231
INTERFACE
hardware_i2c
)

target_sources(pico-ds3231
INTERFACE
${CMAKE_CURRENT_LIST_DIR}/ds3231.c
${CMAKE_CURRENT_LIST_DIR}/ds3231.h
)
Loading

0 comments on commit 3cd55d9

Please sign in to comment.