Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
recursiveforte committed Jul 19, 2024
1 parent f7771a4 commit 5786cd9
Show file tree
Hide file tree
Showing 15 changed files with 749 additions and 142 deletions.
2 changes: 1 addition & 1 deletion firmware/spade/docker/dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.19

RUN apk add git python3 clang make cmake entr uglify-js gcc-arm-none-eabi g++-arm-none-eabi gdb-multiarch
RUN apk add git python3 clang make cmake entr uglify-js gcc-arm-none-eabi g++-arm-none-eabi gdb-multiarch gcc

COPY ./importBuildRepos.sh /opt/importBuildRepos.sh

Expand Down
2 changes: 1 addition & 1 deletion firmware/spade/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-void-pointer-to-int-cast -Wno-int-to-void-pointer-cast -Wno-pointer-sign -Werror=implicit-function-declaration")

add_executable(spade "${SPADE_TARGET}/main.c")
Expand Down
37 changes: 18 additions & 19 deletions firmware/spade/src/rpi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
pico_sdk_init()
add_definitions(-DSPADE_EMBEDDED -DSPADE_AUDIO -DPICO_NO_BI_PROGRAM_BUILD_DATE)
set(DCMAKE_BUILD_TYPE Release)
add_definitions(-DSPADE_EMBEDDED -DSPADE_AUDIO -DPICO_NO_BI_PROGRAM_BUILD_DATE -DPICO_USE_STACK_GUARDS)
set(DCMAKE_BUILD_TYPE Debug)
target_compile_definitions(spade PRIVATE
# compile time configuration of I2S
PICO_AUDIO_I2S_MONO_INPUT=1
USE_AUDIO_I2S=1
PICO_AUDIO_I2S_DATA_PIN=9
PICO_AUDIO_I2S_CLOCK_PIN_BASE=10
# PICO_DEFAULT_UART=0
# PICO_DEFAULT_UART_TX_PIN=28
# PICO_DEFAULT_UART_RX_PIN=29
# compile time configuration of I2S
PICO_AUDIO_I2S_MONO_INPUT=1
USE_AUDIO_I2S=1
PICO_AUDIO_I2S_DATA_PIN=9
PICO_AUDIO_I2S_CLOCK_PIN_BASE=10
# PICO_DEFAULT_UART=0
# PICO_DEFAULT_UART_TX_PIN=28
# PICO_DEFAULT_UART_RX_PIN=29
)

target_link_libraries(spade PRIVATE
pico_stdlib
pico_audio_i2s
pico_multicore
hardware_spi
hardware_timer
hardware_pwm
hardware_adc
pico_stdlib
pico_audio_i2s
pico_multicore
hardware_spi
hardware_timer
hardware_pwm
hardware_adc
)

pico_enable_stdio_usb(spade 1)
pico_enable_stdio_uart(spade 0)

# create map/bin/hex file etc.
pico_add_extra_outputs(spade)

pico_add_extra_outputs(spade)
Binary file modified firmware/spade/src/rpi/jerry/lib/libjerry-core.a
Binary file not shown.
Binary file modified firmware/spade/src/rpi/jerry/lib/libjerry-ext.a
Binary file not shown.
Binary file modified firmware/spade/src/rpi/jerry/lib/libjerry-port-default.a
Binary file not shown.
11 changes: 6 additions & 5 deletions firmware/spade/src/rpi/jerry/refresh.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cd ~/jerryscript_build
rm -rf example-*

# CMAKE_ASM_COMPILER=arm-none-eabi-gcc
# CMAKE_C_COMPILER=arm-none-eabi-gcc
# CMAKE_CXX_COMPILER=arm-none-eabi-g++
# CMAKE_LINKER=arm-none-eabi-ld
# CMAKE_OBJCOPY=arm-none-eabi-objcopy
export CC=arm-none-eabi-gcc
export CMAKE_ASM_COMPILER=arm-none-eabi-gcc
export CMAKE_C_COMPILER=arm-none-eabi-gcc
export CMAKE_CXX_COMPILER=arm-none-eabi-g++
export CMAKE_LINKER=arm-none-eabi-ld
export CMAKE_OBJCOPY=arm-none-eabi-objcopy

# --debug \
python3 jerryscript/tools/build.py \
Expand Down
245 changes: 182 additions & 63 deletions firmware/spade/src/rpi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ typedef struct {
uint8_t last_state;
uint8_t ring_i;
} ButtonState;
// W, S, A, D, I, K, J, L
uint button_pins[] = { 5, 7, 6, 8, 12, 14, 13, 15 };
static ButtonState button_states[ARR_LEN(button_pins)] = {0};

Expand Down Expand Up @@ -248,6 +249,25 @@ static int load_new_scripts(void) {
}
#endif

typedef enum {
NEW_SLOT,
RUN_GAME,
DELETE_CONFIRM
} Welcome_Screen;

int count_digits(uint32_t number) {
if (number < 10) return 1;
if (number < 100) return 2;
if (number < 1000) return 3;
if (number < 10000) return 4;
if (number < 100000) return 5;
if (number < 1000000) return 6;
if (number < 10000000) return 7;
if (number < 100000000) return 8;
if (number < 1000000000) return 9;
return 10;
}

int main() {
timer_hw->dbgpause = 0;

Expand All @@ -265,74 +285,173 @@ int main() {
jerry_init(JERRY_INIT_MEM_STATS);
init(sprite_free_jerry_object); // TODO: document

while(!save_read()) {
// No game stored in memory
strcpy(errorbuf, " \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" PLEASE UPLOAD \n"
" A GAME \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" sprig.hackclub.com \n");
render_errorbuf();
st7735_fill_start();
render(st7735_fill_send);
st7735_fill_finish();
// Start a core to listen for keypresses.
multicore_reset_core1();

load_new_scripts();
}
// update_save_version(); // init here to avoid irqs on other core

// Start a core to listen for keypresses.
multicore_launch_core1(core1_entry);
multicore_launch_core1(core1_entry);

/**
* We get a bunch of fake keypresses at startup, so we need to
* drain them from the FIFO queue.
*
* What really needs to be done here is to have button_init
* record when it starts so that we can ignore keypresses after
* that timestamp.
*/
sleep_ms(50);
while (multicore_fifo_rvalid()) multicore_fifo_pop_blocking();
/**
* We get a bunch of fake keypresses at startup, so we need to
* drain them from the FIFO queue.
*
* What really needs to be done here is to have button_init
* record when it starts so that we can ignore keypresses after
* that timestamp.
*/
sleep_ms(50);
while (multicore_fifo_rvalid()) multicore_fifo_pop_blocking();

/**
* Wait for a keypress to start the game.
*
* This is important so games with e.g. infinite loops don't
* brick the device as soon as they start up.
*/
while(!multicore_fifo_rvalid()) {
strcpy(errorbuf, " \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" PRESS ANY BUTTON \n"
" TO RUN \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" sprig.hackclub.com \n");
render_errorbuf();
st7735_fill_start();
render(st7735_fill_send);
st7735_fill_finish();
int games_i = 0;

load_new_scripts();
}
int games_len = 8;
Game* games = malloc(games_len * sizeof(Game));

Welcome_Screen welcome_state = NEW_SLOT;

for (;;) {

if (games_i >= games_len && games_i != 0) {
games_i = games_len - 1;
}

if (welcome_state == DELETE_CONFIRM) {
// no-op
} else if (games_len == 0) {
welcome_state = NEW_SLOT;
} else {
welcome_state = RUN_GAME;
set_game(games[games_i]);
}

/**
* Wait for a keypress to start the game.
* This is important so games with e.g. infinite loops don't
* brick the device as soon as they start up.
*/

if (multicore_fifo_rvalid()) {
uint32_t c = multicore_fifo_pop_blocking();

if (welcome_state == DELETE_CONFIRM) {
if (c == 7) { // S
welcome_state = RUN_GAME;
} else if (c == 5) { // W
delete_game(games[games_i]);
welcome_state = RUN_GAME;
continue;
}
} else if (c == 6) { // A
if (games_i > 0) games_i--;
} else if (c == 8) { // D
if (games_i < games_len - 1) games_i++;
} else if (c == 7 && welcome_state == RUN_GAME) { // S
welcome_state = DELETE_CONFIRM;
} else if (welcome_state == RUN_GAME && c == 5) { // other button
break;
}
}

games_len = get_games(&games, games_len);

switch (welcome_state) {
case NEW_SLOT:
strcpy(errorbuf, " \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" Please upload \n"
" a game. \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" sprig.hackclub.com \n"
);
break;
case RUN_GAME: {
char game_padding[] = " ";
char size_padding[] = " ";

game_padding[
20
- count_digits(games_i+1)
- count_digits(games_len)
- 8 // 7 at first + 1 slash
] = '\0';

size_padding[
20
- count_digits(GAME_SLOTS(games[games_i].size_b))
- count_digits(MAX_SLOTS)
- 8 // 7 at first + 1 slash
] = '\0';

// 6lines
char game_split_lines[] = {
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
};

for (int i = 0; i*17 < strlen(games[games_i].name); i++) { // 20 - 3 buffer = 17
memcpy(&game_split_lines[i*21 + 1], &games[games_i].name[i*17],
strlen(games[games_i].name) - i*17 < 17 ? strlen(games[games_i].name) - i*17 : 17);
}


sprintf(errorbuf,
" \n"
" \n"
"%s"
" \n"
" Game: %d/%d%s\n"
" Size: %lu/%d%s\n"
" \n"
" W: PLAY \n"
" S: DELETE \n"
" <- A , D -> \n",
game_split_lines,
games_i + 1, games_len, game_padding,
GAME_SLOTS(games[games_i].size_b), MAX_SLOTS, size_padding);
break;
}
case DELETE_CONFIRM: {
strcpy(errorbuf, " \n"
" \n"
" \n"
" \n"
" \n"
" Do you really \n"
" want to delete \n"
" this game? \n"
" \n"
" \n"
" W: confirm \n"
" S: exit \n"
" \n"
" \n"
" sprig.hackclub.com \n"
);
break;
}
}

render_errorbuf();
st7735_fill_start();
render(st7735_fill_send);
st7735_fill_finish();

load_new_scripts();
}

// Wow, we can actually run a game now!

Expand Down
Loading

0 comments on commit 5786cd9

Please sign in to comment.