Skip to content

Commit f3726ea

Browse files
committed
SQLite3 and MSC_SD work!
1 parent e505937 commit f3726ea

File tree

6 files changed

+50
-22
lines changed

6 files changed

+50
-22
lines changed

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ add_definitions(
1212
-DMRBC_REQUIRE_32BIT_ALIGNMENT
1313
-DMAX_REGS_SIZE=256
1414
-DMAX_VM_COUNT=255
15-
-DMAX_SYMBOLS_COUNT=2000
15+
-DMAX_SYMBOLS_COUNT=1800
1616
-DMRBC_CONVERT_CRLF
1717
-DMRBC_USE_MATH
1818
-DPICORBC_PTR_SIZE=4
@@ -28,18 +28,23 @@ set (PRK_REVISION ${CMAKE_REVISION})
2828
configure_file ("${CMAKE_SOURCE_DIR}/include/version.h.in" "${CMAKE_SOURCE_DIR}/include/version.h")
2929

3030
if(DEFINED ENV{PICORUBY_NO_MSC})
31+
set (MSC_NAME NO_MSC)
3132
add_definitions(-DPICORUBY_NO_MSC)
32-
project("prk_firmware-no_msc-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
33+
elseif(DEFINED ENV{PICORUBY_MSC_SD})
34+
set (MSC_NAME MSC_SD)
35+
add_definitions(-DPICORUBY_MSC_SD)
3336
else()
37+
set (MSC_NAME MSC_FLASH)
3438
add_definitions(-DPICORUBY_MSC_FLASH)
35-
if(DEFINED ENV{PICORUBY_SQLITE3})
36-
add_definitions(-DPICORUBY_SQLITE3)
37-
project("prk_firmware-sqlite3-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
38-
else()
39-
project("prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
40-
endif()
4139
endif()
4240

41+
if(DEFINED ENV{PICORUBY_SQLITE3})
42+
set (MSC_NAME ${MSC_NAME}-SQLITE3)
43+
add_definitions(-DPICORUBY_SQLITE3)
44+
endif()
45+
46+
project("prk_firmware-${MSC_NAME}-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
47+
4348
# Initializing the Raspberry Pi Pico SDK should happen after project created
4449
pico_sdk_init()
4550

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ desc "build production with SQLite3 and SD card"
4444
task :sqlite3 do
4545
ENV['PICORUBY_SQLITE3'] = '1'
4646
ENV['PICORUBY_SD_CARD'] = '1'
47+
ENV['PICORUBY_MSC_SD'] = '1'
4748
Rake::Task[:all].invoke
4849
end
4950

mrblib/usb_task.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
if PICORUBY_MSC == "MSC_SD"
2+
require "spi"
3+
end
14
require "keyboard"
25

36
ENV = {}
@@ -11,9 +14,19 @@
1114

1215
Keyboard.mount_volume
1316

17+
keymap_updated_at = -1
18+
1419
while true
1520
USB.tud_task
1621
if Keyboard.autoreload_ready?
17-
Keyboard.restart
22+
if File.exist?("/keymap.rb")
23+
unixtime = File::Stat.new("/keymap.rb").mtime.to_i
24+
if unixtime != keymap_updated_at
25+
Keyboard.restart
26+
keymap_updated_at = unixtime
27+
else
28+
Keyboard.autoreload_off
29+
end
30+
end
1831
end
1932
end

src/main.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
#endif
3333

3434
#if defined(PICORUBY_SQLITE3)
35-
#define MEMORY_SIZE (1024*190)
35+
#define MEMORY_SIZE (1024*203)
3636
#else
37-
#define MEMORY_SIZE (1024*200)
37+
#define MEMORY_SIZE (1024*207)
3838
#endif
3939

4040
static uint8_t memory_pool[MEMORY_SIZE];
@@ -57,21 +57,26 @@ tud_msc_write10_complete_cb(uint8_t lun)
5757
autoreload_state = AUTORELOAD_READY;
5858
}
5959

60-
#endif /* PICORUBY_NO_MSC */
60+
#endif /* !PICORUBY_NO_MSC */
6161

6262
static void
6363
prk_init_picoruby(void)
6464
{
65+
mrbc_vm *vm = mrbc_vm_open(NULL);
6566
/* CONST */
6667
mrbc_sym sym_id = mrbc_str_to_symid("SIZEOF_POINTER");
6768
mrbc_set_const(sym_id, &mrbc_integer_value(PICORBC_PTR_SIZE));
68-
sym_id = mrbc_str_to_symid("PICORUBY_NO_MSC");
69-
#ifdef PICORUBY_NO_MSC
70-
mrbc_set_const(sym_id, &mrbc_true_value());
71-
#else
72-
mrbc_set_const(sym_id, &mrbc_false_value());
69+
sym_id = mrbc_str_to_symid("PICORUBY_MSC");
70+
mrbc_value picoruby_msc = mrbc_string_new_cstr(vm,
71+
#if defined(PICORUBY_NO_MSC)
72+
"NO_MSC"
73+
#elif defined(PICORUBY_MSC_FLASH)
74+
"MSC_FLASH"
75+
#elif defined(PICORUBY_MSC_SD)
76+
"MSC_SD"
7377
#endif
74-
mrbc_vm *vm = mrbc_vm_open(NULL);
78+
);
79+
mrbc_set_const(sym_id, &picoruby_msc);
7580
sym_id = mrbc_str_to_symid("PRK_DESCRIPTION");
7681
mrbc_value prk_desc = mrbc_string_new_cstr(vm, PRK_DESCRIPTION);
7782
mrbc_set_const(sym_id, &prk_desc);

tinyusb/tusb_config.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@
103103
// HID buffer size Should be sufficient to hold ID (if any) + Data
104104
#define CFG_TUD_HID_EP_BUFSIZE 64
105105

106-
// It is normaly 512, but we use 4096 to avoid cache coherency problem
107-
// on writing flash
108-
#define CFG_TUD_MSC_EP_BUFSIZE 4096
106+
#if defined(PICORUBY_MSC_FLASH)
107+
#define CFG_TUD_MSC_EP_BUFSIZE 4096
108+
#elif defined(PICORUBY_MSC_SD)
109+
#define CFG_TUD_MSC_EP_BUFSIZE 512
110+
#else
111+
#error PICORUBY_MSC_devicename must be defined
112+
#endif
109113

110114
// CDC FIFO size of TX and RX
111115
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

0 commit comments

Comments
 (0)