Skip to content

Commit

Permalink
Merge pull request #16 from picoruby/msc_disk
Browse files Browse the repository at this point in the history
Msc disk
  • Loading branch information
hasumikin authored Sep 9, 2021
2 parents 538f5ac + a1b573f commit 0863eae
Show file tree
Hide file tree
Showing 23 changed files with 1,029 additions and 209 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 2021/09/10
### BIG BIG IMPROVEMENT 🍣
- You no longer need any compiler toolchain!!!
- No longer detaching USB cable every time amending your keymap, too!!!
- See README.md 👀

## 2021/08/17
### Breaking Change 💣
- Code upgraded to correspond to the newest pico-sdk as of today. Please upgrade your pico-sdk
Expand Down
77 changes: 61 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,83 @@ include(pico_sdk_import.cmake)

project(prk_firmware)

add_definitions(-DMRBC_USE_HAL_RP2040 -DMRBC_REQUIRE_32BIT_ALIGNMENT -DMAX_REGS_SIZE=256 -DMAX_SYMBOLS_COUNT=500 -DMAX_VM_COUNT=10)
add_definitions(
-DNDEBUG
-DMRBC_USE_HAL_RP2040
-DMRBC_REQUIRE_32BIT_ALIGNMENT
-DMAX_REGS_SIZE=256
-DMAX_SYMBOLS_COUNT=500
-DMAX_VM_COUNT=10
)
if(PRK_NO_MSC)
add_definitions(-DPRK_NO_MSC)
endif()

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# rest of your project
#####################################################
# 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)
set (PRK_VERSION 0.9.0)
set (PRK_BUILDDATE ${CMAKE_BUILDDATE})
set (PRK_REVISION ${CMAKE_REVISION})
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h")

if(PRK_NO_MSC)
set(PROJECT "prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-no_msc")
else()
set(PROJECT "prk_firmware-${PRK_VERSION}-${PRK_BUILDDATE}-${PRK_REVISION}")
endif()

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib)

add_executable(prk_firmware
add_executable(${PROJECT}
src/main.c
src/msc_disk.c
src/usb_descriptors.c
src/gpio.c
src/usb.c
src/uart.c
src/ws2812.c
src/rotary_encoder.c
lib/picoruby/cli/sandbox.c
)

pico_generate_pio_header(prk_firmware ${CMAKE_CURRENT_LIST_DIR}/src/uart_tx.pio)
pico_generate_pio_header(prk_firmware ${CMAKE_CURRENT_LIST_DIR}/src/ws2812.pio)
pico_generate_pio_header(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/src/uart_tx.pio)
pico_generate_pio_header(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/src/ws2812.pio)

set(RBC ${CMAKE_CURRENT_SOURCE_DIR}/lib/picoruby/build/bin/host-production/alloc_libc/picorbc)
#set(RBC RBENV_VERSION=mruby-3.0.0 mrbc)
#set(RBC RBENV_VERSION=mruby-3.0.0 mrbc) # In case of PicoRuby compiler enbugged 😵

add_custom_target(steep
COMMAND bundle exec steep -h || bundle install
COMMAND ${CMAKE_COMMAND} -E env PROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} rake steep
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ruby
)

if(PRK_NO_MSC)
add_custom_target(keymap
COMMAND ${RBC} -Bkeymap ${PROJECT_BINARY_DIR}/../keymap.rb
COMMAND mv ${PROJECT_BINARY_DIR}/../keymap.c ./
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ruby/lib
)
else()
add_custom_target(keymap)
endif()

add_custom_target(ruby
COMMAND ${RBC} -Bcore core.rb
COMMAND ${RBC} -Bkeyboard keyboard.rb
COMMAND ${RBC} -Brgb rgb.rb
COMMAND ${RBC} -Brotary_encoder rotary_encoder.rb
COMMAND ${RBC} -Btud tud.rb
COMMAND ${RBC} -Brgb_task rgb_task.rb
COMMAND ${RBC} -Bkeymap ${PROJECT_BINARY_DIR}/../keymap.rb
COMMAND mv ${PROJECT_BINARY_DIR}/../keymap.c ./
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ruby/lib
)

add_custom_target(ruby_2
add_custom_target(sandbox
COMMAND ${RBC} -Bbuffer buffer.rb
COMMAND ${RBC} -Bsandbox sandbox.rb
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/lib/picoruby/cli/ruby
Expand All @@ -58,29 +91,41 @@ add_custom_target(ruby_2
add_dependencies(ruby
steep
)

add_dependencies(prk_firmware
add_dependencies(${PROJECT}
picoruby
ruby
ruby_2
sandbox
)
if(PRK_NO_MSC)
add_dependencies(${PROJECT}
keymap
)
endif()

target_link_libraries(prk_firmware
target_link_libraries(${PROJECT}
pico_stdlib
tinyusb_device
tinyusb_board
picoruby
hardware_pio
hardware_pwm
pico_multicore
hardware_flash
)

include_directories(prk_firmware
include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/lib/picoruby/src/mrubyc/src
)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(prk_firmware)
pico_add_extra_outputs(${PROJECT})

add_custom_command(
TARGET ${PROJECT}
POST_BUILD
COMMAND gzip -k ${PROJECT}.uf2
COMMAND zip -r ${PROJECT}.uf2.zip ${PROJECT}.uf2
)
59 changes: 52 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _(left: Raspberry Pi Pico / right: Sparkfun Pro Micro RP2040)_
- [ ] Asymmetrical type. eg) ???
- [x] UART communication between left and right
- [ ] I2C communication between left and right
- [ ] Macros
- [x] Macros
- [ ] Media keys
- [x] RGBLED. An example on [picoruby/prk_crkbd](https://github.com/picoruby/prk_crkbd/blob/main/keymap.rb#L61-L76)
- [ ] OLED display
Expand All @@ -38,16 +38,43 @@ _(left: Raspberry Pi Pico / right: Sparkfun Pro Micro RP2040)_

### Getting started

There are two ways to install PRK Fiwmware:

1. [Using a release binary (recommended)](#Using-a-release-binary)
2. [Building a binary by yourself](Building-a-binary-by-yourself)

Anyhow, you should:

- Be knowledgeable how to install a UF2 file into Raspi Pico on [https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-c](https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-c)
- [https://learn.sparkfun.com/tutorials/pro-micro-rp2040-hookup-guide](https://learn.sparkfun.com/tutorials/pro-micro-rp2040-hookup-guide) will also be helpful if you use Sparkfun Pro Micro RP2040

#### Using a release binary

- Download the newest release binary from [Releases](https://github.com/picoruby/prk_firmware/releases)

- Unzip it. You should get a file that looks like `prk_firmware-0.9.0-20210910-xxxxxxxx.uf2`

- Flash the uf2 into RP2040

![](doc/images/drag_and_drop_1.png)

- `PRKFirmware` mass storage drive should be mounted, then drag and drop your `keymap.rb`

![](doc/images/drag_and_drop_2.png)

Your keyboard will automatically reboot. Enjoy!

#### Building a binary by yourself

You may not want PRK Firmware to be a mass storage device in case that your employer doesn't allow you to bring a USB memory 🙈

- Install CRuby (MRI) because "Static type checking" by [Steep](https://github.com/soutaro/steep) will be invoked in build process

- Setup Raspberry Pi Pico C/C++ SDK

- Follow the instructions on [https://github.com/raspberrypi/pico-sdk#quick-start-your-own-project](https://github.com/raspberrypi/pico-sdk#quick-start-your-own-project)
- Make sure you have `PICO_SDK_PATH` environment variable

- Be knowledgeable how to install a UF2 file into Raspi Pico on [https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-c](https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-c)

- [https://learn.sparkfun.com/tutorials/pro-micro-rp2040-hookup-guide](https://learn.sparkfun.com/tutorials/pro-micro-rp2040-hookup-guide) will also help you if you use Sparkfun Pro Micro RP2040

- Clone the `prk_firmware` (this repository) wherever you like

Expand All @@ -63,19 +90,37 @@ _(left: Raspberry Pi Pico / right: Sparkfun Pro Micro RP2040)_
git clone https://github.com/picoruby/prk_meishi2.git
```
- Edit `prk_meishi2/keymap.rb` as you wish
- Build with `cmake` and `make`
```
cd prk_meishi2/build
cmake ../../..
cmake -DPRK_NO_MSC=1 ../../..
make
```
(Defining PRK_NO_MSC macro will avoid implementing mass storage feature)
Now you should have `prk_firmware.uf2` file in `prk_firmware/keyboards/prk_meishi2/build/` directory.
Now you should have `prk_firmware-[version]-[date]-no_msc.uf2` file in `prk_firmware/keyboards/prk_meishi2/build/` directory which includes your keymap in code.
- Install that `.uf2` file into RP2040
### What if split type keyboard?
- Make sure installing your setup on both side
### Contributing
Fork, clone, patch and send a pull request.
#### Building uf2 of excluding-keymap-version
```
cd prk_firmware/build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
```
Then patch and send a pull request.
#### For those who are willing to contribute to PRK or write your own keymaps:
Expand Down
3 changes: 3 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.keep
!.gitignore
Empty file added build/.keep
Empty file.
Binary file added doc/images/drag_and_drop_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/drag_and_drop_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions include/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,26 @@
#endif

//------------- CLASS -------------//
#define CFG_TUD_CDC 0
#define CFG_TUD_MSC 0
#define CFG_TUD_CDC 1
#define CFG_TUD_MSC 1
#define CFG_TUD_HID 1
#define CFG_TUD_MIDI 0
#define CFG_TUD_VENDOR 0

// 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 512

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

// CDC Endpoint transfer buffer size, more is faster
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

#ifdef __cplusplus
}
#endif
Expand Down
34 changes: 0 additions & 34 deletions include/usb_descriptors.h

This file was deleted.

Loading

0 comments on commit 0863eae

Please sign in to comment.