Skip to content

Commit

Permalink
Merge pull request #171 from picoruby/sqlite3
Browse files Browse the repository at this point in the history
Sqlite3
  • Loading branch information
hasumikin authored May 22, 2023
2 parents d0bef2d + aa0409b commit 25bccb0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 71 deletions.
44 changes: 24 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ cmake_minimum_required(VERSION 3.24)
# note: this must happen before project()
include(pico_sdk_import.cmake)

#####################################################
# project specific configuration from here

add_definitions(
-DNDEBUG
-DMRBC_USE_HAL_RP2040
-DMRBC_REQUIRE_32BIT_ALIGNMENT
-DMAX_REGS_SIZE=256
-DMAX_VM_COUNT=255
-DMAX_SYMBOLS_COUNT=2000
-DMAX_SYMBOLS_COUNT=1800
-DMRBC_CONVERT_CRLF
-DMRBC_USE_MATH
-DPICORBC_PTR_SIZE=4
-DNO_CLOCK_GETTIME=1
)
if(PICORUBY_NO_MSC)
add_definitions(-DPICORUBY_NO_MSC)
else()
add_definitions(-DPICORUBY_MSC_FLASH)
endif()

#####################################################
# project specific configuration from here

execute_process (COMMAND date +%Y%m%d OUTPUT_VARIABLE CMAKE_BUILDDATE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE CMAKE_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand All @@ -33,19 +27,32 @@ set (PRK_BUILDDATE ${CMAKE_BUILDDATE})
set (PRK_REVISION ${CMAKE_REVISION})
configure_file ("${CMAKE_SOURCE_DIR}/include/version.h.in" "${CMAKE_SOURCE_DIR}/include/version.h")

if(PICORUBY_NO_MSC)
project("prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-no_msc")
if(DEFINED ENV{PICORUBY_NO_MSC})
set (MSC_NAME NO_MSC)
add_definitions(-DPICORUBY_NO_MSC)
elseif(DEFINED ENV{PICORUBY_MSC_SD})
set (MSC_NAME MSC_SD)
add_definitions(-DPICORUBY_MSC_SD)
else()
project("prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
set (MSC_NAME MSC_FLASH)
add_definitions(-DPICORUBY_MSC_FLASH)
endif()

if(DEFINED ENV{PICORUBY_SQLITE3})
set (MSC_NAME ${MSC_NAME}-SQLITE3)
add_definitions(-DPICORUBY_SQLITE3)
endif()

project("prk_firmware-${MSC_NAME}-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")

# Initializing the Raspberry Pi Pico SDK should happen after project created
pico_sdk_init()

file(GLOB SRCS src/*.c)
add_executable(${PROJECT_NAME}
${SRCS}
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/flash_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/sd_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/ports/rp2040/msc_disk.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-gpio/ports/rp2040/gpio.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-i2c/ports/rp2040/i2c.c
Expand All @@ -63,7 +70,10 @@ set(RBC ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/bin/picorbc)

# Ruby

if(PICORUBY_NO_MSC)
if(DEFINED ENV{PICORUBY_NO_MSC})
add_dependencies(${PROJECT_NAME}
keymap
)
add_custom_target(keymap
COMMAND ${RBC} -Bkeymap -o ./keymap.c ../keymap.rb
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
Expand Down Expand Up @@ -100,12 +110,6 @@ add_dependencies(${PROJECT_NAME}
${RUBY_TASK_FILES}
)

if(PICORUBY_NO_MSC)
add_dependencies(${PROJECT_NAME}
keymap
)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/tinyusb
${CMAKE_SOURCE_DIR}/lib/picoruby/include/hal_no_impl
Expand Down
76 changes: 39 additions & 37 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "fileutils"

MRUBY_CONFIG = "prk_firmware-cortex-m0plus"
ENV['MRUBY_CONFIG'] = "prk_firmware-cortex-m0plus"
PICO_SDK_TAG = "1.5.0"

task :default => :all
task :default => :production

task :setup do
sh "bundle install"
Expand All @@ -13,40 +13,54 @@ task :setup do
end
end

desc "build production"
task :all => [:libmruby, :test, :cmake_production, :build]
task :all => [:libmruby, :test, :cmake, :build]


desc "build debug (you may need to rake clean before this)"
task :debug => [:libmruby, :test, :cmake_debug, :build]
task :debug do
ENV['PICORUBY_DEBUG'] = '1'
ENV['-DCMAKE_BUILD_TYPE'] = 'Debug'
Rake::Task[:all].invoke
end

file "lib/picoruby" do
sh "git submodule update --init --recursive"
desc "build production"
task :production do
Rake::Task[:all].invoke
end

task :libmruby_no_msc => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "rake test"
sh "CFLAGS='-DPICORUBY_NO_MSC=1' MRUBY_CONFIG=#{MRUBY_CONFIG} rake"
desc "build PRK Firmware inclusive of keymap.rb (without mass storage)"
task :build_with_keymap, ['keyboard_name'] do |_t, args|
unless args.keyboard_name
raise "Argument `keyboard_name` missing.\nUsage: rake build_with_keymap[prk_meishi2]"
end
dir = "keyboards/#{args.keyboard_name}"
FileUtils.mkdir_p "#{dir}/build"
ENV['PICORUBY_NO_MSC'] = '1'
ENV['PRK_BUILD_DIR'] = "#{dir}/"
Rake::Task[:all].invoke
end

task :libmruby => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "rake test"
sh "MRUBY_CONFIG=#{MRUBY_CONFIG} rake"
end
desc "build production with SQLite3 and SD card"
task :sqlite3 do
ENV['PICORUBY_SQLITE3'] = '1'
ENV['PICORUBY_SD_CARD'] = '1'
ENV['PICORUBY_MSC_SD'] = '1'
Rake::Task[:all].invoke
end

def mruby_config
"MRUBY_CONFIG=#{MRUBY_CONFIG}"
file "lib/picoruby" do
sh "git submodule update --init --recursive"
end

task :cmake_debug do
sh "#{mruby_config} cmake -DCMAKE_BUILD_TYPE=Debug -B build"
task :libmruby => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "rake test"
sh "rake"
end
end

task :cmake_production do
sh "#{mruby_config} cmake -B build"
task :cmake do
sh "cmake -B #{ENV['PRK_BUILD_DIR']}build"
end

task :check_pico_sdk => :check_pico_sdk_path do
Expand All @@ -71,19 +85,7 @@ end

desc "build without cmake preparation"
task :build => :check_pico_sdk do
sh "cmake --build build"
end

desc "build PRK Firmware inclusive of keymap.rb (without mass storage)"
task :build_with_keymap, ['keyboard_name'] => [:libmruby_no_msc, :test] do |_t, args|
unless args.keyboard_name
raise "Argument `keyboard_name` missing.\nUsage: rake build_with_keymap[prk_meishi2]"
end
dir = "keyboards/#{args.keyboard_name}"
FileUtils.mkdir_p "#{dir}/build"
#sh "cmake -DPICORUBY_NO_MSC=1 -DCMAKE_BUILD_TYPE=Debug -B #{dir}/build"
sh "#{mruby_config} cmake -DPICORUBY_NO_MSC=1 -B #{dir}/build"
sh "cmake --build #{dir}/build"
sh "cmake --build #{ENV['PRK_BUILD_DIR']}build"
end

desc "clean built that includes keymap"
Expand Down Expand Up @@ -119,7 +121,7 @@ end
desc "clean built"
task :clean do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=#{MRUBY_CONFIG} rake clean"
sh "rake clean"
end
FileUtils.cd "build" do
FileUtils.rm_rf Dir.glob("prk_firmware-*.*")
Expand All @@ -134,7 +136,7 @@ end
desc "deep clean built"
task :deep_clean do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=#{MRUBY_CONFIG} rake deep_clean"
sh "rake deep_clean"
end
FileUtils.cd "build" do
FileUtils.rm_rf Dir.glob("*")
Expand Down
2 changes: 1 addition & 1 deletion lib/picoruby
Submodule picoruby updated 32 files
+2 −1 Rakefile
+0 −4 build_config/default.rb
+0 −2 build_config/mrubyc.rb
+16 −7 build_config/prk_firmware-cortex-m0plus.rb
+0 −26 build_config/r2p2-arm-bin.rb
+0 −2 build_config/r2p2-bin.rb
+8 −8 build_config/r2p2-cortex-m0plus.rb
+3 −5 build_config/sqlite3-test.rb
+7 −8 lib/picoruby/build.rb
+7 −24 mrbgems/picoruby-bin-sqlite3-test/mrbgem.rake
+36 −30 mrbgems/picoruby-bin-sqlite3-test/mrblib/app.rb
+13 −2 mrbgems/picoruby-bin-sqlite3-test/tools/sqlite3-test/sqlite3-test.c
+1 −0 mrbgems/picoruby-filesystem-fat/include/fat.h
+4 −0 mrbgems/picoruby-filesystem-fat/mrblib/fat.rb
+2 −0 mrbgems/picoruby-filesystem-fat/sig/fat.rbs
+11 −0 mrbgems/picoruby-filesystem-fat/src/fat.c
+33 −22 mrbgems/picoruby-prk-keyboard/mrblib/keyboard.rb
+10 −10 mrbgems/picoruby-prk-keyboard/sig/keyboard.rbs
+19 −0 mrbgems/picoruby-shell/mrblib/shell.rb
+1 −0 mrbgems/picoruby-shell/sig/shell.rbs
+12 −2 mrbgems/picoruby-sqlite3/include/sqlite3_prb_methods.h
+23 −22 mrbgems/picoruby-sqlite3/include/sqlite3_vfs_methods.h
+3 −2 mrbgems/picoruby-sqlite3/sig/database.rbs
+0 −23 mrbgems/picoruby-sqlite3/src/sqlite3_database.c
+74 −25 mrbgems/picoruby-sqlite3/src/sqlite3_prb_methods.c
+0 −10 mrbgems/picoruby-sqlite3/src/sqlite3_resultset.c
+0 −1 mrbgems/picoruby-sqlite3/src/sqlite3_sqlite3.c
+50 −99 mrbgems/picoruby-sqlite3/src/sqlite3_vfs_methods.c
+1 −0 mrbgems/picoruby-time-class/src/time.c
+4 −0 mrbgems/picoruby-vfs/mrblib/file.rb
+9 −0 mrbgems/picoruby-vfs/mrblib/vfs.rb
+1 −0 mrbgems/picoruby-vfs/sig/vfs.rbs
15 changes: 14 additions & 1 deletion mrblib/usb_task.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if PICORUBY_MSC == "MSC_SD"
require "spi"
end
require "keyboard"

ENV = {}
Expand All @@ -11,9 +14,19 @@

Keyboard.mount_volume

keymap_updated_at = -1

while true
USB.tud_task
if Keyboard.autoreload_ready?
Keyboard.restart
if File.exist?("/keymap.rb")
unixtime = File::Stat.new("/keymap.rb").mtime.to_i
if unixtime != keymap_updated_at
Keyboard.restart
keymap_updated_at = unixtime
else
Keyboard.autoreload_off
end
end
end
end
26 changes: 17 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
#include <keymap.c>
#endif


#define MEMORY_SIZE (1024*200)
#if defined(PICORUBY_SQLITE3)
#define MEMORY_SIZE (1024*203)
#else
#define MEMORY_SIZE (1024*207)
#endif

static uint8_t memory_pool[MEMORY_SIZE];

Expand All @@ -54,21 +57,26 @@ tud_msc_write10_complete_cb(uint8_t lun)
autoreload_state = AUTORELOAD_READY;
}

#endif /* PICORUBY_NO_MSC */
#endif /* !PICORUBY_NO_MSC */

static void
prk_init_picoruby(void)
{
mrbc_vm *vm = mrbc_vm_open(NULL);
/* CONST */
mrbc_sym sym_id = mrbc_str_to_symid("SIZEOF_POINTER");
mrbc_set_const(sym_id, &mrbc_integer_value(PICORBC_PTR_SIZE));
sym_id = mrbc_str_to_symid("PICORUBY_NO_MSC");
#ifdef PICORUBY_NO_MSC
mrbc_set_const(sym_id, &mrbc_true_value());
#else
mrbc_set_const(sym_id, &mrbc_false_value());
sym_id = mrbc_str_to_symid("PICORUBY_MSC");
mrbc_value picoruby_msc = mrbc_string_new_cstr(vm,
#if defined(PICORUBY_NO_MSC)
"NO_MSC"
#elif defined(PICORUBY_MSC_FLASH)
"MSC_FLASH"
#elif defined(PICORUBY_MSC_SD)
"MSC_SD"
#endif
mrbc_vm *vm = mrbc_vm_open(NULL);
);
mrbc_set_const(sym_id, &picoruby_msc);
sym_id = mrbc_str_to_symid("PRK_DESCRIPTION");
mrbc_value prk_desc = mrbc_string_new_cstr(vm, PRK_DESCRIPTION);
mrbc_set_const(sym_id, &prk_desc);
Expand Down
10 changes: 7 additions & 3 deletions tinyusb/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@
// HID buffer size Should be sufficient to hold ID (if any) + Data
#define CFG_TUD_HID_EP_BUFSIZE 64

// It is normaly 512, but we use 4096 to avoid cache coherency problem
// on writing flash
#define CFG_TUD_MSC_EP_BUFSIZE 4096
#if defined(PICORUBY_MSC_FLASH)
#define CFG_TUD_MSC_EP_BUFSIZE 4096
#elif defined(PICORUBY_MSC_SD)
#define CFG_TUD_MSC_EP_BUFSIZE 512
#else
#error PICORUBY_MSC_devicename must be defined
#endif

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

0 comments on commit 25bccb0

Please sign in to comment.