Skip to content

Commit

Permalink
Upgrade picoruby
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Nov 14, 2024
1 parent cc29aed commit c10abe5
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 122 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Change log

## 0.10.0 on 2024/11/17

Almost one year has passed since the last release. We have been working on improving the PRK Firmware!

### Breaking Change 💣
- No breaking change in this release

### New Feature 🎉
- On startup, if you connect a terminal emulator to com port, you can skip starting the keyboard task by pressing `s` according to the message on the terminal
- This feature is useful when your `keymap.rb` breaks and hangs up the keyboard
- Note that `s` key should be sent from the other keyboard that is working fine. This means you have to have multiple keyboards⌨⌨⌨⌨

### Improvement 🔈
- Replace PicoRuby with a totally new one:
- The Ruby parser is now Prism!
- Many bugs are fixed in the virtual machine and libraries
- Stability should be improved a lot🤞

Please report if you find any bugs!

## 0.9.23 on 2023/11/19

### require
Expand Down
24 changes: 20 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.24)
# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)
include(pico_extras_import.cmake)

#####################################################
# project specific configuration from here
Expand Down Expand Up @@ -48,6 +49,14 @@ 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()

add_compile_options(-Wall
# int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-format
-Wno-unused-function
-Wno-maybe-uninitialized
-fshort-enums
)

file(GLOB SRCS src/*.c)
add_executable(${PROJECT_NAME}
${SRCS}
Expand All @@ -58,7 +67,13 @@ add_executable(${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-i2c/ports/rp2040/i2c.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-spi/ports/rp2040/spi.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-adc/ports/rp2040/adc.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-uart/ports/rp2040/uart.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-pwm/ports/rp2040/pwm.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-machine/ports/rp2040/machine.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-io-console/ports/rp2040/io-console.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-watchdog/ports/rp2040/watchdog.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-rng/ports/rp2040/rng.c
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-env/ports/rp2040/env.c
)

set(PICORBC ${CMAKE_SOURCE_DIR}/lib/picoruby/bin/picorbc)
Expand Down Expand Up @@ -114,11 +129,11 @@ add_dependencies(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/tinyusb
${CMAKE_SOURCE_DIR}/lib/picoruby/include/hal_no_impl
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-mrubyc/repos/mrubyc/src
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-mrubyc/lib/mrubyc/src
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems/picoruby-filesystem-fat/lib/ff14b/source
${CMAKE_SOURCE_DIR}/lib/picoruby/build/$ENV{MRUBY_CONFIG}/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/$ENV{MRUBY_CONFIG}/mruby-pico-compiler/include
${CMAKE_SOURCE_DIR}/lib/picoruby/mrbgems
${CMAKE_SOURCE_DIR}/lib/picoruby/build/repos/${BUILD_CONFIG}/mruby-compiler2/include
)

target_link_directories(${PROJECT_NAME} PRIVATE
Expand All @@ -131,15 +146,16 @@ target_link_libraries(${PROJECT_NAME}
tinyusb_device
tinyusb_board
hardware_pio
hardware_pwm
pico_multicore
hardware_sleep
hardware_flash
hardware_adc
hardware_uart
hardware_dma
hardware_sync
hardware_irq
hardware_i2c
hardware_spi
hardware_pwm
mruby
)

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'https://rubygems.org'

gem 'rake'
gem "mrubyc-test", ">= 0.9.1"
18 changes: 0 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
concurrent-ruby (1.2.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
minitest (5.18.0)
mrubyc-test (0.9.2)
activesupport (~> 7.0)
rufo (~> 0.12)
thor (~> 1.2)
rake (13.0.6)
rufo (0.15.1)
thor (1.2.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)

PLATFORMS
x86_64-linux

DEPENDENCIES
mrubyc-test (>= 0.9.1)
rake

BUNDLED WITH
Expand Down
4 changes: 0 additions & 4 deletions Guardfile

This file was deleted.

43 changes: 8 additions & 35 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
require "fileutils"

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

task :default => :production

task :setup do
sh "bundle install"
sh "git submodule update --init"
sh "git submodule update --init --recursive"
FileUtils.cd "lib/picoruby" do
sh "bundle install"
end
end

task :all => [:libmruby, :test, :cmake, :build]

task :all => [:libmruby, :cmake, :build]

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

desc "build production"
task :production do
ENV['CMAKE_BUILD_TYPE'] = 'Release'
Rake::Task[:all].invoke
end

Expand Down Expand Up @@ -55,12 +55,12 @@ end
task :libmruby => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=default rake test"
sh "MRUBY_CONFIG=#{ENV['MRUBY_CONFIG']} rake"
sh "rake"
end
end

task :cmake do
sh "cmake -B #{ENV['PRK_BUILD_DIR']}build"
sh "cmake -DCMAKE_BUILD_TYPE=#{ENV['CMAKE_BUILD_TYPE']} -B #{ENV['PRK_BUILD_DIR']}build"
end

task :check_pico_sdk => :check_pico_sdk_path do
Expand Down Expand Up @@ -96,28 +96,6 @@ task :clean_with_keymap , ['keyboard_name'] do |_t, args|
FileUtils.rm_r Dir.glob("keyboards/#{args.keyboard_name}/build/*")
end


desc "run :mrubyc_test"
task :test => %i(mrubyc_test)

desc "run unit test for ruby program"
task :mrubyc_test => :setup_test do
sh %q(MRUBYCFILE=test/Mrubycfile bundle exec mrubyc-test)
end

task :setup_test do
FileUtils.cd "test/models" do
Dir.glob("../../lib/picoruby/mrbgems/picoruby-prk-*").each do |dir|
Dir.glob("#{dir}/mrblib/*.rb").each do |model|
FileUtils.ln_sf model, File.basename(model)
end
end
FileUtils.ln_sf "../../lib/picoruby/mrbgems/picoruby-gpio/mrblib/gpio.rb", "gpio.rb"
FileUtils.ln_sf "../../lib/picoruby/mrbgems/picoruby-float-ext/mrblib/float.rb", "float.rb"
FileUtils.ln_sf "../../lib/picoruby/mrbgems/picoruby-music-macro-language/mrblib/mml.rb", "mml.rb"
end
end

desc "clean built"
task :clean do
FileUtils.cd "lib/picoruby" do
Expand Down Expand Up @@ -150,13 +128,8 @@ task :symlinks do
end
end

desc "run guard-process"
task :guard do
sh "bundle exec guard start -i"
end

# Add a new tag then push it
task :release => :test do
task :release do
git_status = `git status`
branch = git_status.split("\n")[0].match(/\AOn branch (.+)\z/)[1]
if branch != "master"
Expand Down
2 changes: 1 addition & 1 deletion lib/picoruby
Submodule picoruby updated 387 files
4 changes: 0 additions & 4 deletions mrblib/object-ext.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
class LoadError < StandardError
# ScriptError is the super class in CRuby
end

class Object

alias _puts puts
Expand Down
21 changes: 18 additions & 3 deletions mrblib/usb_task.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
require "machine"
require "watchdog"
Watchdog.disable
require 'env'

ENV["HOME"] = "/"
ENV["PWD"] = "/"

STDOUT = IO
STDIN = IO
STDIN.echo = false

if PICORUBY_MSC == "MSC_SD"
require "spi"
end
require "keyboard"

ENV = {}

200.times do
USB.tud_task
sleep_ms 2
Expand All @@ -17,6 +27,11 @@
while true
USB.tud_task
if Keyboard.autoreload_ready? && File.exist?("/keymap.rb")
Keyboard.restart
break unless Keyboard.restart
end
end

puts "Restart microcontroller when you want to reload keymap.rb"
while true
USB.tud_task
end
62 changes: 62 additions & 0 deletions pico_extras_import.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This is a copy of <PICO_EXTRAS_PATH>/external/pico_extras_import.cmake

# This can be dropped into an external project to help locate pico-extras
# It should be include()ed prior to project()

if (DEFINED ENV{PICO_EXTRAS_PATH} AND (NOT PICO_EXTRAS_PATH))
set(PICO_EXTRAS_PATH $ENV{PICO_EXTRAS_PATH})
message("Using PICO_EXTRAS_PATH from environment ('${PICO_EXTRAS_PATH}')")
endif ()

if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT))
set(PICO_EXTRAS_FETCH_FROM_GIT $ENV{PICO_EXTRAS_FETCH_FROM_GIT})
message("Using PICO_EXTRAS_FETCH_FROM_GIT from environment ('${PICO_EXTRAS_FETCH_FROM_GIT}')")
endif ()

if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT_PATH))
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH $ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH})
message("Using PICO_EXTRAS_FETCH_FROM_GIT_PATH from environment ('${PICO_EXTRAS_FETCH_FROM_GIT_PATH}')")
endif ()

if (NOT PICO_EXTRAS_PATH)
if (PICO_EXTRAS_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_EXTRAS_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
PICO_EXTRAS
GIT_REPOSITORY https://github.com/raspberrypi/pico-extras
GIT_TAG master
)
if (NOT PICO_EXTRAS)
message("Downloading PICO EXTRAS")
FetchContent_Populate(PICO_EXTRAS)
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
if (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pico-extras")
set(PICO_EXTRAS_PATH ${PICO_SDK_PATH}/../pico-extras)
message("Defaulting PICO_EXTRAS_PATH as sibling of PICO_SDK_PATH: ${PICO_EXTRAS_PATH}")
else()
message(FATAL_ERROR
"PICO EXTRAS location was not specified. Please set PICO_EXTRAS_PATH or set PICO_EXTRAS_FETCH_FROM_GIT to on to fetch from git."
)
endif()
endif ()
endif ()

set(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" CACHE PATH "Path to the PICO EXTRAS")
set(PICO_EXTRAS_FETCH_FROM_GIT "${PICO_EXTRAS_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO EXTRAS from git if not otherwise locatable")
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download EXTRAS")

get_filename_component(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_EXTRAS_PATH})
message(FATAL_ERROR "Directory '${PICO_EXTRAS_PATH}' not found")
endif ()

set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH} CACHE PATH "Path to the PICO EXTRAS" FORCE)

add_subdirectory(${PICO_EXTRAS_PATH} pico_extras)
11 changes: 3 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* PicoRuby */
#include <picorbc.h>
#include <picogem_init.c>

/* Raspi SDK */
Expand Down Expand Up @@ -32,16 +31,13 @@
#endif

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

static uint8_t memory_pool[MEMORY_SIZE];

/* extern in mruby-pico-compiler/include/debug.h */
int loglevel = LOGLEVEL_WARN;

int autoreload_state; /* from keyboard.h */

#ifndef PICORUBY_NO_MSC
Expand Down Expand Up @@ -83,9 +79,8 @@ prk_init_picoruby(void)
mrbc_raw_free(vm);
/* class Object */
picoruby_load_model(object_ext);
picoruby_init_require();
picoruby_init_require(vm);
prk_init_Machine();
prk_init_PicoRubyVM();
prk_init_USB();
}

Expand Down
Loading

0 comments on commit c10abe5

Please sign in to comment.