Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIDI implementation #169

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ include(pico_sdk_import.cmake)
# project specific configuration from here

add_definitions(
-DMRBC_USE_HAL_RP2040
-DMRBC_REQUIRE_32BIT_ALIGNMENT
-DMAX_REGS_SIZE=256
-DMAX_VM_COUNT=255
-DMAX_SYMBOLS_COUNT=1800
-DMRBC_CONVERT_CRLF
-DMRBC_USE_MATH
-DMRBC_USE_FLOAT=2
-DPICORBC_PTR_SIZE=4
-DNO_CLOCK_GETTIME=1
)
Expand Down Expand Up @@ -58,6 +58,7 @@ 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-io-console/ports/rp2040/io-console.c
)

set(PICORBC ${CMAKE_SOURCE_DIR}/lib/picoruby/bin/picorbc)
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ task :setup_test do
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"
FileUtils.ln_sf "../../lib/picoruby/mrbgems/picoruby-mml2midi/mrblib/mml2midi.rb", "mml2midi.rb"
end
end

Expand Down
12 changes: 12 additions & 0 deletions include/midi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef MIDI_DEFINED_H_
#define MIDI_DEFINED_H_

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif /* MIDI_DEFINED_H_ */
2 changes: 1 addition & 1 deletion lib/picoruby
Submodule picoruby updated 276 files
118 changes: 0 additions & 118 deletions src/hal.c

This file was deleted.

18 changes: 18 additions & 0 deletions src/midi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <mrubyc.h>

#include "../include/midi.h"
#include "../include/usb_descriptors.h"
#include "picoruby-prk-midi/include/prk-midi.h"

uint8_t const cable_num = 0; // MIDI jack associated with USB endpoint
uint8_t packet[4];

void Midi_init(void)
{
while(tud_midi_available()) tud_midi_packet_read(packet);
}

void Midi_stream_write(uint8_t* packet, uint8_t len)
{
tud_midi_stream_write(cable_num, packet, len);
}
15 changes: 12 additions & 3 deletions src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tusb_desc_device_t desc_device =
.bNumConfigurations = 0x01
};

#define STRING_DESC_ARR_SIZE 6
#define STRING_DESC_ARR_SIZE 7

#define PRK_CONF_SIZE 64

Expand All @@ -47,6 +47,7 @@ static char const *string_desc_arr[STRING_DESC_ARR_SIZE] =
PRK_SERIAL, // 3: Serial
"PRK CDC", // 4: CDC Interface
"PRK MSC", // 5: MSC Interface
"PRK MIDI", // 6: MIDI Interface
};

// Invoked when received GET DEVICE DESCRIPTOR
Expand All @@ -61,9 +62,9 @@ tud_descriptor_device_cb(void)
//--------------------------------------------------------------------+

#ifdef PICORUBY_NO_MSC
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN)
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN + TUD_MIDI_DESC_LEN)
#else
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN + TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN)
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN + TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN + TUD_MIDI_DESC_LEN)
#endif

#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
Expand Down Expand Up @@ -112,6 +113,9 @@ tud_descriptor_device_cb(void)
#define EPNUM_HID_IN 0x84
#define EPNUM_JOYSTICK_IN 0x85

#define EPNUM_MIDI_OUT 0x06
#define EPNUM_MIDI_IN 0x86

uint8_t const desc_hid_report[] =
{
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )),
Expand All @@ -131,6 +135,8 @@ enum
ITF_NUM_CDC_DATA,
ITF_NUM_HID,
ITF_NUM_JOYSTICK,
ITF_NUM_MIDI,
ITF_NUM_MIDI_STREAMING,
#ifndef PICORUBY_NO_MSC
ITF_NUM_MSC,
#endif
Expand All @@ -145,6 +151,9 @@ uint8_t const desc_fs_configuration[] =
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),

// Interface number, string index, EP Out & EP In address, EP size
TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 6, EPNUM_MIDI_OUT, EPNUM_MIDI_IN, 64),

#ifndef PICORUBY_NO_MSC
// Interface number, string index, EP Out & EP In address, EP size
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
Expand Down
Loading