Skip to content

Commit dc73003

Browse files
authored
Merge pull request #5 from visrealm/dev
v0.4.0
2 parents 833314b + 990720d commit dc73003

File tree

14 files changed

+1127
-750
lines changed

14 files changed

+1127
-750
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ set(BUILD_SHARED_LIBS OFF)
1010

1111
set(PROJECT pico9918)
1212

13+
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/boards )
14+
set(PICO_BOARD "pico9918_v04")
15+
1316
project(${PROJECT} C CXX)
1417

1518
add_definitions(-DPICO_BUILD=1)

src/boards/pico9918_v04.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
// -----------------------------------------------------
8+
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
9+
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
10+
// -----------------------------------------------------
11+
12+
// This header may be included by other board headers as "boards/pico.h"
13+
14+
#ifndef _BOARDS_PICO_H
15+
#define _BOARDS_PICO_H
16+
17+
// For board detection
18+
#define PICO9918
19+
20+
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
21+
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 32
22+
#endif
23+
24+
// --- UART ---
25+
#ifndef PICO_DEFAULT_UART
26+
#define PICO_DEFAULT_UART 0
27+
#endif
28+
#ifndef PICO_DEFAULT_UART_TX_PIN
29+
#define PICO_DEFAULT_UART_TX_PIN 0
30+
#endif
31+
#ifndef PICO_DEFAULT_UART_RX_PIN
32+
#define PICO_DEFAULT_UART_RX_PIN 1
33+
#endif
34+
35+
// --- LED ---
36+
#ifndef PICO_DEFAULT_LED_PIN
37+
#define PICO_DEFAULT_LED_PIN 25
38+
#endif
39+
// no PICO_DEFAULT_WS2812_PIN
40+
41+
// --- I2C ---
42+
#ifndef PICO_DEFAULT_I2C
43+
#define PICO_DEFAULT_I2C 0
44+
#endif
45+
#ifndef PICO_DEFAULT_I2C_SDA_PIN
46+
#define PICO_DEFAULT_I2C_SDA_PIN 4
47+
#endif
48+
#ifndef PICO_DEFAULT_I2C_SCL_PIN
49+
#define PICO_DEFAULT_I2C_SCL_PIN 5
50+
#endif
51+
52+
// --- SPI ---
53+
#ifndef PICO_DEFAULT_SPI
54+
#define PICO_DEFAULT_SPI 0
55+
#endif
56+
#ifndef PICO_DEFAULT_SPI_SCK_PIN
57+
#define PICO_DEFAULT_SPI_SCK_PIN 18
58+
#endif
59+
#ifndef PICO_DEFAULT_SPI_TX_PIN
60+
#define PICO_DEFAULT_SPI_TX_PIN 19
61+
#endif
62+
#ifndef PICO_DEFAULT_SPI_RX_PIN
63+
#define PICO_DEFAULT_SPI_RX_PIN 16
64+
#endif
65+
#ifndef PICO_DEFAULT_SPI_CSN_PIN
66+
#define PICO_DEFAULT_SPI_CSN_PIN 17
67+
#endif
68+
69+
// --- FLASH ---
70+
71+
#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1
72+
73+
#ifndef PICO_FLASH_SPI_CLKDIV
74+
#define PICO_FLASH_SPI_CLKDIV 2
75+
#endif
76+
77+
#ifndef PICO_FLASH_SIZE_BYTES
78+
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
79+
#endif
80+
81+
// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads)
82+
#define PICO_SMPS_MODE_PIN 23
83+
84+
#ifndef PICO_RP2040_B0_SUPPORTED
85+
#define PICO_RP2040_B0_SUPPORTED 1
86+
#endif
87+
88+
// The GPIO Pin used to read VBUS to determine if the device is battery powered.
89+
#ifndef PICO_VBUS_PIN
90+
#define PICO_VBUS_PIN 24
91+
#endif
92+
93+
// The GPIO Pin used to monitor VSYS. Typically you would use this with ADC.
94+
// There is an example in adc/read_vsys in pico-examples.
95+
#ifndef PICO_VSYS_PIN
96+
#define PICO_VSYS_PIN 29
97+
#endif
98+
99+
#endif

src/main.c

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
*/
6464

6565
#define PCB_MAJOR_VERSION 0
66-
#define PCB_MINOR_VERSION 3
66+
#define PCB_MINOR_VERSION 4
6767

6868
#define GPIO_CD0 14
6969
#define GPIO_CSR tmsRead_CSR_PIN // defined in tms9918.pio
@@ -105,7 +105,9 @@
105105
#define TMS_IRQ PIO1_IRQ_0
106106

107107

108-
/* file globals */
108+
109+
110+
/* file globals */
109111

110112
static uint8_t nextValue = 0; /* TMS9918A read-ahead value */
111113
static bool currentInt = false; /* current interrupt state */
@@ -191,7 +193,6 @@ static inline void disableTmsPioInterrupts()
191193
__dmb();
192194
}
193195

194-
195196
/*
196197
* generate a single VGA scanline (called by vgaLoop(), runs on proc1)
197198
*/
@@ -211,6 +212,9 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
211212
const uint32_t vBorder = (VIRTUAL_PIXELS_Y - TMS9918_PIXELS_Y) / 2;
212213
const uint32_t hBorder = (VIRTUAL_PIXELS_X - TMS9918_PIXELS_X * 2) / 2;
213214

215+
static int frameCount = 0;
216+
static int logoOffset = 100;
217+
214218
uint16_t bg = tms9918PaletteBGR12[vrEmuTms9918RegValue(TMS_REG_FG_BG_COLOR) & 0x0f];
215219

216220
/*** top and bottom borders ***/
@@ -226,24 +230,37 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
226230
* : 430 bytes
227231
* format: 16-bit abgr palette, 2bpp indexed image
228232
*/
229-
if (y >= vBorder + TMS9918_PIXELS_Y + 12)
233+
if (frameCount < 600)
230234
{
231-
y -= vBorder + TMS9918_PIXELS_Y + 12;
232-
if (y < splashHeight)
235+
if (y == 0)
236+
{
237+
++frameCount;
238+
if (frameCount & 0x01)
239+
{
240+
if (frameCount < 200 && logoOffset > 12) --logoOffset;
241+
else if (frameCount > 500) ++logoOffset;
242+
}
243+
}
244+
245+
if (y < (VIRTUAL_PIXELS_Y - 1))
233246
{
234-
uint8_t* splashPtr = splash + (y * splashWidth / 4);
235-
for (int x = 4; x < 4 + splashWidth; x += 4)
247+
y -= vBorder + TMS9918_PIXELS_Y + logoOffset;
248+
if (y < splashHeight)
236249
{
237-
uint8_t c = *(splashPtr++);
238-
uint8_t p0 = (c & 0xc0);
239-
uint8_t p1 = (c & 0x30);
240-
uint8_t p2 = (c & 0x0c);
241-
uint8_t p3 = (c & 0x03);
242-
243-
if (p0) { pixels[x] = splash_pal[(p0 >> 6)]; }
244-
if (p1) { pixels[x + 1] = splash_pal[(p1 >> 4)]; }
245-
if (p2) { pixels[x + 2] = splash_pal[(p2 >> 2)]; }
246-
if (p3) { pixels[x + 3] = splash_pal[p3]; }
250+
uint8_t* splashPtr = splash + (y * splashWidth / 4);
251+
for (int x = 4; x < 4 + splashWidth; x += 4)
252+
{
253+
uint8_t c = *(splashPtr++);
254+
uint8_t p0 = (c & 0xc0);
255+
uint8_t p1 = (c & 0x30);
256+
uint8_t p2 = (c & 0x0c);
257+
uint8_t p3 = (c & 0x03);
258+
259+
if (p0) { pixels[x] = splash_pal[(p0 >> 6)]; }
260+
if (p1) { pixels[x + 1] = splash_pal[(p1 >> 4)]; }
261+
if (p2) { pixels[x + 2] = splash_pal[(p2 >> 2)]; }
262+
if (p3) { pixels[x + 3] = splash_pal[p3]; }
263+
}
247264
}
248265
}
249266
}
@@ -348,6 +365,9 @@ uint initClock(uint gpio, float freqHz)
348365
*/
349366
void tmsPioInit()
350367
{
368+
irq_set_exclusive_handler(TMS_IRQ, pio_irq_handler);
369+
irq_set_enabled(TMS_IRQ, true);
370+
351371
uint tmsWriteProgram = pio_add_program(TMS_PIO, &tmsWrite_program);
352372

353373
pio_sm_config writeConfig = tmsWrite_program_get_default_config(tmsWriteProgram);
@@ -357,6 +377,7 @@ void tmsPioInit()
357377

358378
pio_sm_init(TMS_PIO, tmsWriteSm, tmsWriteProgram, &writeConfig);
359379
pio_sm_set_enabled(TMS_PIO, tmsWriteSm, true);
380+
pio_set_irq0_source_enabled(TMS_PIO, pis_sm0_rx_fifo_not_empty, true);
360381

361382
uint tmsReadProgram = pio_add_program(TMS_PIO, &tmsRead_program);
362383

@@ -375,9 +396,6 @@ void tmsPioInit()
375396

376397
pio_sm_init(TMS_PIO, tmsReadSm, tmsReadProgram, &readConfig);
377398
pio_sm_set_enabled(TMS_PIO, tmsReadSm, true);
378-
irq_set_exclusive_handler(TMS_IRQ, pio_irq_handler);
379-
irq_set_enabled(TMS_IRQ, true);
380-
pio_set_irq0_source_enabled(TMS_PIO, pis_sm0_rx_fifo_not_empty, true);
381399
pio_set_irq0_source_enabled(TMS_PIO, pis_sm1_rx_fifo_not_empty, true);
382400

383401
pio_sm_put(TMS_PIO, tmsReadSm, 0x000000ff);
@@ -406,7 +424,6 @@ void proc1Entry()
406424
}
407425

408426

409-
410427
/*
411428
* main entry point
412429
*/
@@ -438,10 +455,10 @@ int main(void)
438455
vgaInit(params);
439456

440457
/* signal proc1 that we're ready to start the display */
441-
multicore_fifo_push_timeout_us(0, 0);
458+
multicore_fifo_push_blocking(0);
442459

443460
/* twiddle our thumbs - everything from this point on
444-
is handled by interrupts and PIOs */
461+
is handled by interrupts and PIOs */;
445462
while (1)
446463
{
447464
tight_loop_contents();

src/res/splash.png

5 Bytes
Loading

test/CMakeLists.txt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
set(PROGRAM pico9918test)
1+
cmake_minimum_required(VERSION 3.12)
22

3-
add_executable(${PROGRAM})
4-
5-
# generate image array source files from png images
6-
visrealm_generate_bindata_source(${PROGRAM} breakout res/BREAKOUT.* )
7-
8-
pico_generate_pio_header(${PROGRAM} ${CMAKE_CURRENT_LIST_DIR}/clocks.pio)
9-
10-
target_sources(${PROGRAM} PRIVATE test.c font.c)
11-
12-
pico_add_extra_outputs(${PROGRAM})
13-
14-
target_link_libraries(${PROGRAM} PUBLIC
15-
pico_stdlib
16-
hardware_pio)
3+
add_subdirectory(host)
4+
#add_subdirectory(qc)
175

test/host/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(PROGRAM pico9918test)
2+
3+
add_executable(${PROGRAM})
4+
5+
# generate image array source files from png images
6+
visrealm_generate_bindata_source(${PROGRAM} breakout res/BREAKOUT.* )
7+
8+
pico_generate_pio_header(${PROGRAM} ${CMAKE_CURRENT_LIST_DIR}/clocks.pio)
9+
10+
target_sources(${PROGRAM} PRIVATE test.c font.c)
11+
12+
pico_add_extra_outputs(${PROGRAM})
13+
14+
target_link_libraries(${PROGRAM} PUBLIC
15+
pico_stdlib
16+
hardware_pio)
17+
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
/*
2-
* Project: pico9918
3-
*
4-
* Copyright (c) 2024 Troy Schrapel
5-
*
6-
* This code is licensed under the MIT license
7-
*
8-
* https://github.com/visrealm/pico9918
9-
*
10-
*/
11-
12-
.program clock
13-
pull block
14-
.wrap_target
15-
set pins, 1
16-
mov x, osr
17-
onDelay:
18-
jmp x-- onDelay
19-
set pins, 0
20-
mov x, osr
21-
offDelay:
22-
jmp x-- offDelay
23-
.wrap
24-
25-
26-
% c-sdk {
27-
28-
void clock_program_init(PIO pio, uint sm, uint offset, uint pin) {
29-
pio_gpio_init(pio, pin);
30-
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
31-
pio_sm_config c = clock_program_get_default_config(offset);
32-
sm_config_set_set_pins(&c, pin, 1);
33-
pio_sm_init(pio, sm, offset, &c);
34-
}
35-
%}
1+
/*
2+
* Project: pico9918
3+
*
4+
* Copyright (c) 2024 Troy Schrapel
5+
*
6+
* This code is licensed under the MIT license
7+
*
8+
* https://github.com/visrealm/pico9918
9+
*
10+
*/
11+
12+
.program clock
13+
pull block
14+
.wrap_target
15+
set pins, 1
16+
mov x, osr
17+
onDelay:
18+
jmp x-- onDelay
19+
set pins, 0
20+
mov x, osr
21+
offDelay:
22+
jmp x-- offDelay
23+
.wrap
24+
25+
26+
% c-sdk {
27+
28+
void clock_program_init(PIO pio, uint sm, uint offset, uint pin) {
29+
pio_gpio_init(pio, pin);
30+
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
31+
pio_sm_config c = clock_program_get_default_config(offset);
32+
sm_config_set_set_pins(&c, pin, 1);
33+
pio_sm_init(pio, sm, offset, &c);
34+
}
35+
%}

0 commit comments

Comments
 (0)