Skip to content

Commit d6f2a1c

Browse files
committed
fixes for jem demo units
1 parent 6b5c31c commit d6f2a1c

File tree

6 files changed

+222
-7
lines changed

6 files changed

+222
-7
lines changed

boards/jembrick.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define J_OLED_CS 3
1414
#define J_OLED_RESET 4
1515
#define J_OLED_DC 5
16-
#define J_OLED_FRAME_PERIOD 5556
16+
#define J_OLED_FRAME_PERIOD 6600
1717

1818

1919
// --- UART ---

src/doom/d_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void D_DoAdvanceDemo (void)
626626
usergame = false; // no save / end game here
627627
paused = false;
628628
gameaction = ga_nothing;
629-
629+
/*
630630
#if !DOOM_TINY
631631
// The Ultimate Doom executable changed the demo sequence to add
632632
// a DEMO4 demo. Final Doom was based on Ultimate, so also
@@ -645,7 +645,11 @@ void D_DoAdvanceDemo (void)
645645
demosequence = (demosequence+1)%7;
646646
else
647647
demosequence = (demosequence+1)%6;
648-
648+
*/
649+
650+
// demo3 was causing trouble, so
651+
demosequence = (demosequence+1)%4;
652+
649653
switch (demosequence)
650654
{
651655
case 0:

src/i_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void D_DoomMain (void);
5151
#if PICO_ON_DEVICE
5252
#include "pico/binary_info.h"
5353
bi_decl(bi_3pins_with_names(PICO_AUDIO_I2S_DATA_PIN, "I2S DIN", PICO_AUDIO_I2S_CLOCK_PIN_BASE, "I2S BCK", PICO_AUDIO_I2S_CLOCK_PIN_BASE+1, "I2S LRCK"));
54+
extern void power_on_logo(void);
5455
#endif
5556

5657
int main(int argc, char **argv)
@@ -67,6 +68,7 @@ int main(int argc, char **argv)
6768
6869
set_sys_clock_khz(270000, true);
6970
*/
71+
power_on_logo();
7072
#if !USE_PICO_NET
7173
// debug ?
7274
// gpio_debug_pins_init();

src/pico/capsense.pio

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
2+
.program capsense_ext
3+
4+
mov isr, null
5+
6+
set y, 1
7+
in y, 1
8+
in null, 21
9+
mov y, isr
10+
11+
mov x, !null
12+
13+
resample:
14+
set pindirs, 0
15+
16+
busy:
17+
jmp pin done
18+
jmp x-- busy
19+
20+
done:
21+
set pindirs, 1
22+
set pins, 0
23+
24+
jmp y-- resample
25+
26+
mov isr, x
27+
push block
28+
29+
30+
.program capsense_int
31+
32+
mov isr, null
33+
34+
set y, 1
35+
in y, 1
36+
in null, 20
37+
mov y, isr
38+
39+
mov x, !null
40+
41+
resample:
42+
; count the time spent outside of the busy loop
43+
jmp y--, dec1
44+
jmp done
45+
46+
dec1:
47+
jmp y--, dec2
48+
jmp done
49+
50+
dec2:
51+
jmp y--, dec3
52+
jmp done
53+
54+
dec3:
55+
jmp y--, dec4
56+
jmp done
57+
58+
dec4:
59+
jmp y--, dec5
60+
jmp done
61+
62+
dec5:
63+
64+
65+
; set pin to input
66+
set pindirs, 0
67+
68+
busy:
69+
; wait until we see it come high
70+
jmp pin, high
71+
jmp y--, busy
72+
jmp done
73+
74+
high:
75+
; set pin to output and pull low
76+
set pindirs, 1
77+
set pins, 0
78+
79+
; count this cycle and repeat
80+
jmp x--, resample
81+
82+
83+
done:
84+
mov isr,x
85+
push block
86+
87+
88+
% c-sdk {
89+
90+
static inline uint capsense_program_offset(PIO pio) {
91+
#if JEMBRICK
92+
return pio_add_program(pio, &capsense_ext_program);
93+
#elif JEMRING
94+
return pio_add_program(pio, &capsense_int_program);
95+
#endif
96+
}
97+
98+
static inline void capsense_program_init(PIO pio, uint sm, uint offset, uint pin) {
99+
100+
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false);
101+
pio_gpio_init(pio, pin);
102+
gpio_disable_pulls(pin);
103+
gpio_set_dir(pin, GPIO_OUT);
104+
gpio_put(pin, 0);
105+
106+
#if JEMBRICK
107+
pio_sm_config c = capsense_ext_program_get_default_config(offset);
108+
#elif JEMRING
109+
pio_sm_config c = capsense_int_program_get_default_config(offset);
110+
#endif
111+
112+
sm_config_set_in_pins(&c, pin);
113+
sm_config_set_out_pins(&c, pin, 1);
114+
sm_config_set_set_pins(&c, pin, 1);
115+
sm_config_set_jmp_pin(&c, pin);
116+
sm_config_set_clkdiv(&c, 1.0f);
117+
118+
119+
pio_sm_init(pio, sm, offset, &c);
120+
pio_sm_set_enabled(pio, sm, true);
121+
}
122+
123+
static inline uint32_t capsense_program_read(PIO pio, uint sm) {
124+
static uint32_t count[8] = {1,2,3,4,5,6,7,8};
125+
126+
for (int i = 0; i < 5; ++i) {
127+
if (pio_sm_is_rx_fifo_empty(pio, sm)) {
128+
break;
129+
}
130+
count[sm] = 0 - pio_sm_get(pio, sm);
131+
}
132+
133+
return count[sm];
134+
}
135+
136+
%}

src/pico/i_input.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ bi_decl(bi_program_feature("USB keyboard support"));
4747
#endif
4848

4949
#if JEMBRICK
50-
#define ACCELEROMETER_SUPPORT 1
51-
#define PIO_CAPSENSE 1
50+
//#define ACCELEROMETER_SUPPORT 1
51+
//#define PIO_CAPSENSE 1
5252
#endif
5353

5454
#if JEMRING
@@ -97,6 +97,11 @@ static uint32_t capsense_window = 2048;
9797
#define ACC_ADDR 15
9898
static bool acc_dir[6] = {0};
9999

100+
int TranslateKey(int scancode);
101+
static int GetLocalizedKey(int scancode);
102+
#define WITH_SHIFT 0x8000
103+
104+
100105
void acc_press(int tilt, int scancode, int mod, int axis) {
101106
if (tilt > 5) {
102107
if (!acc_dir[axis]) {

src/pico/i_video.c

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static void __not_in_flash_func(free_buffer_callback)() {
370370
#define FRAME_PERIOD J_OLED_FRAME_PERIOD
371371

372372
// some oleds need 2 park lines, but that's not as robust
373-
#define PARK_LINES 1
373+
#define PARK_LINES 2
374374

375375
static const uint8_t command_initialise[] = {
376376
0xAE, //display off
@@ -418,6 +418,74 @@ uint8_t byte_reverse(uint8_t b) {
418418
return b;
419419
}
420420

421+
void power_on_logo(void) {
422+
// get the logo up on screen using conservative settings and no greyscale trickery, as proof of life
423+
424+
gpio_init(J_OLED_CS);
425+
gpio_set_dir(J_OLED_CS, GPIO_OUT);
426+
gpio_put(J_OLED_CS, 0);
427+
428+
gpio_init(J_OLED_RESET);
429+
gpio_set_dir(J_OLED_RESET, GPIO_OUT);
430+
gpio_put(J_OLED_RESET, 0);
431+
432+
gpio_init(J_OLED_DC);
433+
gpio_set_dir(J_OLED_DC, GPIO_OUT);
434+
gpio_put(J_OLED_DC, 0);
435+
436+
gpio_put(J_OLED_RESET, 1);
437+
sleep_ms(1);
438+
gpio_put(J_OLED_RESET, 0);
439+
sleep_ms(10);
440+
gpio_put(J_OLED_RESET, 1);
441+
442+
gpio_set_function(PICO_DEFAULT_SPI_SCK_PIN, GPIO_FUNC_SPI);
443+
gpio_set_function(PICO_DEFAULT_SPI_TX_PIN, GPIO_FUNC_SPI);
444+
spi_init(spi0, 115200);
445+
spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
446+
447+
gpio_put(J_OLED_CS, 1);
448+
gpio_put(J_OLED_DC, 0);
449+
gpio_put(J_OLED_CS, 0);
450+
451+
const uint8_t cmd_init[] = {
452+
0xAE, 0x20, 0x00, 0x40, 0xA1, 0xA8, 0x27, 0xC8, 0xD3, 0x00, 0xDA, 0x12, 0xD5, 0xF0, 0xD9, 0x11, 0xDB, 0x20, 0x81, 0x7F,
453+
0xA4, 0xA6, 0x8D, 0x14, 0xAD, 0x30, 0x21, 0x1C, 0x63, 0x22, 0x00, 0x04, 0xAF
454+
};
455+
spi_write_blocking(spi0, cmd_init, sizeof(cmd_init));
456+
457+
gpio_put(J_OLED_CS, 1);
458+
gpio_put(J_OLED_DC, 1);
459+
gpio_put(J_OLED_CS, 0);
460+
461+
const uint8_t dat_logo[] = {
462+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0x02, 0x02, 0x02, 0xe2, 0x22, 0x22, 0x22, 0xe2, 0x02, 0x02, 0x04, 0xfc,
463+
0x00, 0xfc, 0x02, 0x02, 0x02, 0xe2, 0x22, 0x22, 0x22, 0xe2, 0x02, 0x02, 0x02, 0xfc, 0x00, 0xfc, 0x02, 0x02, 0x02, 0xe2,
464+
0x22, 0x22, 0x22, 0xe2, 0x02, 0x02, 0x02, 0xfc, 0x00, 0x02, 0xfe, 0x02, 0x02, 0x02, 0x0c, 0x30, 0xc0, 0xc0, 0x30, 0x0c,
465+
0x02, 0x02, 0x02, 0x02, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
466+
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x40, 0xa0, 0x00, 0xff, 0x00, 0xff, 0x00, 0x40, 0x80, 0xff, 0x00, 0x00,
467+
0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
468+
0x00, 0x00, 0xff, 0xa0, 0x40, 0xf0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
469+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xa8, 0x54, 0xbf, 0x60, 0xb0, 0x58, 0xaf,
470+
0x55, 0x2a, 0x80, 0xff, 0x00, 0x7f, 0xc0, 0x95, 0x2a, 0x57, 0xa8, 0x50, 0xa0, 0x7f, 0x28, 0x90, 0xc0, 0x7f, 0x00, 0x7f,
471+
0xc0, 0x90, 0x28, 0x7f, 0xa0, 0x50, 0xa8, 0x57, 0x2a, 0x95, 0xc0, 0x7f, 0x00, 0x80, 0xff, 0x2a, 0x55, 0xff, 0x03, 0x3c,
472+
0xd5, 0x2a, 0xd4, 0x38, 0x07, 0xff, 0x50, 0xa0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
473+
0x00, 0x00, 0x00, 0xff, 0x00, 0x2a, 0x95, 0xca, 0x65, 0x32, 0x19, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
474+
0x03, 0x06, 0x0c, 0x19, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x0c, 0x19, 0x0c, 0x06,
475+
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x0f, 0x00, 0x00, 0x03, 0x0c, 0x03, 0x00, 0x00, 0xff, 0x55, 0xaa,
476+
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x06, 0x03, 0x01, 0x00,
477+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
478+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
479+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
480+
};
481+
482+
spi_write_blocking(spi0, dat_logo, sizeof(dat_logo));
483+
484+
gpio_put(J_OLED_CS, 1);
485+
486+
//sleep_ms(2000);
487+
}
488+
421489
static void display_driver_init() {
422490

423491
gpio_init(J_OLED_CS);
@@ -438,7 +506,7 @@ static void display_driver_init() {
438506

439507
gpio_set_function(PICO_DEFAULT_SPI_SCK_PIN, GPIO_FUNC_SPI);
440508
gpio_set_function(PICO_DEFAULT_SPI_TX_PIN, GPIO_FUNC_SPI);
441-
spi_init(spi0, 62500000);
509+
spi_init(spi0, 60000000);
442510
spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
443511

444512
gpio_put(J_OLED_CS, 1);

0 commit comments

Comments
 (0)