Skip to content

Commit

Permalink
Initial version (1.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonsmartins committed Dec 13, 2021
0 parents commit 3d1054d
Show file tree
Hide file tree
Showing 18 changed files with 1,727 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Backup files
*.s#?
*.b#?
*.l#?
*.b$?
*.s$?
*.l$?

# Eagle project file
# It contains a serial number and references to the file structure
# on your computer.
# comment the following line if you want to have your project file included.
eagle.epf

# Autorouter files
*.pro
*.job

# CAM files
*.$$$
*.cmp
*.ly2
*.l15
*.sol
*.plc
*.stc
*.sts
*.crc
*.crs

*.dri
*.drl
*.gpi
*.pls
*.ger
*.xln

*.drd
*.drd.*

*.s#*
*.b#*

*.info

*.eps

# file locks introduced since 7.x
*.lck

*.hex
437 changes: 437 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# MIDI-USB Adapter
Cable for interconnecting musical instruments with MIDI interface to PC, via USB port.

![MIDI-USB Adapter](/img/DSC08286.JPG)

Project site: [MIDI-USB Adapter Project](https://www.robsonmartins.com/content/eletr/projects/midiusb)

[![CC BY-NC-SA 4.0][cc-by-nc-sa-shield]][cc-by-nc-sa]

This work is licensed under a
[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa].

[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa]

[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/
[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png
[cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg
18 changes: 18 additions & 0 deletions firmware/src/MidiUsbAdapter/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MidiUsbAdapter</name>
<comment></comment>
<projects>
<project>JalLib</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.felix.jal.eclipse.plugin.JalBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.felix.jal.eclipse.plugin.JalNature</nature>
</natures>
</projectDescription>
58 changes: 58 additions & 0 deletions firmware/src/MidiUsbAdapter/midiserial.jal
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- ----------------------------------------------------------------------------
-- Title: MIDI-USB Adapter
-- http://www.robsonmartins.com/eletr/midiusb/
--
-- Author: Robson Martins
-- http://www.robsonmartins.com
--
-- ----------------------------------------------------------------------------
-- variables
var bit led_midi_out_req = OFF
var bit led_midi_in_req = OFF

-- ----------------------------------------------------------------------------
-- setup uart hardware
const serial_hw_baudrate = 31_250
include serial_hardware
serial_hw_init()

-- ----------------------------------------------------------------------------
-- procedures and functions
-- ----------------------------------------------------------------------------

-- Returns true if a byte was received from serial port,
-- otherwise returns false.
-- @param[out] data Received data
function serialReadByte(byte out data) return bit is
var bit result
result = serial_hw_read(data)
if (result) then
led_midi_in_req = ON
led_midi_in = ON
end if
return result
end function

-- Writes a byte to serial port, blocking.
-- @param[in] data Data to sent
procedure serialWriteByte(byte in data) is
serial_hw_write(data)
led_midi_out_req = ON
led_midi_out = ON
end procedure

-- Refreshes the leds status.
procedure serialRefreshLeds() is
if (!led_midi_out_req) then
led_midi_out = OFF
else
led_midi_out = ON
led_midi_out_req = OFF
end if
if (!led_midi_in_req) then
led_midi_in = OFF
else
led_midi_in = ON
led_midi_in_req = OFF
end if
end procedure
59 changes: 59 additions & 0 deletions firmware/src/MidiUsbAdapter/midiusb.jal
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- ----------------------------------------------------------------------------
-- Title: MIDI-USB Adapter
-- http://www.robsonmartins.com/eletr/midiusb/
--
-- Author: Robson Martins
-- http://www.robsonmartins.com
--
-- ----------------------------------------------------------------------------

include usb_defs
-- defines a custom product string
const byte USB_STRING2[34] =
{
34, -- bLength
USB_DT_STRING, -- bDescriptorType
"U", 0x00,
"S", 0x00,
"B", 0x00,
"-", 0x00,
"M", 0x00,
"I", 0x00,
"D", 0x00,
"I", 0x00,
" ", 0x00,
"A", 0x00,
"d", 0x00,
"a", 0x00,
"p", 0x00,
"t", 0x00,
"e", 0x00,
"r", 0x00
}

-- ----------------------------------------------------------------------------
-- setup USB-MIDI
include usb_midi
usb_midi_init()

-- ----------------------------------------------------------------------------
-- procedures and functions
-- ----------------------------------------------------------------------------

-- Keeps the USB communcation alive.
procedure usbMidiFlush() is
usb_midi_flush()
end procedure

-- Returns true if a byte was received from USB MIDI,
-- otherwise returns false.
-- @param[out] data Received data
function usbMidiReadByte(byte out data) return bit is
return usb_midi_parsed_read(data)
end function

-- Writes a byte to USB MIDI, blocking.
-- @param[in] data Data to sent
procedure usbMidiWriteByte(byte in data) is
usb_midi_parsed_write(data)
end procedure
111 changes: 111 additions & 0 deletions firmware/src/MidiUsbAdapter/midiusbadapter.jal
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
-- ----------------------------------------------------------------------------
-- Title: MIDI-USB Adapter
-- http://www.robsonmartins.com/eletr/midiusb/
--
-- Author: Robson Martins
-- http://www.robsonmartins.com
--
-- JALv2 Compiler: 2.4o
--
-- Description: Firmware do Adaptador MIDI-USB
--
-- Sources:
-- midiusbadapter.jal : main program
-- midiserial.jal : uart routines
-- midiusb.jal : usb-midi routines
-- usb_midi.jal : usb-midi jal based library
--
-- Notes:
-- - File creation date/time: Fri May 25 23:59:22 BRT 2012.
-- ----------------------------------------------------------------------------
-- don't remove this line! (needed for jal eclipse plugin)
--;@main
-- ----------------------------------------------------------------------------
include 18f13k50 -- target PICmicro
-- ----------------------------------------------------------------------------
-- Resonator or crystal connected to pins OSC1 and OSC2.
pragma target clock 48_000_000 -- oscillator frequency
-- ----------------------------------------------------------------------------
-- configuration memory settings (fuses)
pragma target CPUDIV P1 -- cpu system clock (no divide)
pragma target USBDIV P1 -- usb clock (no divide)
pragma target OSC HS -- HS crystal or resonator
pragma target PLLEN P4 -- oscillator multiplied by 4 (pll enabled)
pragma target FCMEN DISABLED -- Fail-safe clock monitor
pragma target IESO DISABLED -- Internal-external switchover
pragma target PWRTE DISABLED -- power up timer
pragma target BROWNOUT DISABLED -- no brownout detection
pragma target WDT DISABLED -- no watchdog
pragma target MCLR EXTERNAL -- external reset
pragma target LVP DISABLED -- no low-voltage programming
pragma target XINST ENABLED -- extended instruction set
pragma target HFOFST ENABLED -- clock held off until hfintosc is stable
pragma target DEBUG DISABLED -- background debugging
pragma target CP0 DISABLED -- code block 0 not protected
pragma target CP1 DISABLED -- code block 1 not protected
pragma target CPB DISABLED -- bootblock code not write protected
pragma target WRT0 DISABLED -- table writeblock 0 not protected
pragma target WRT1 DISABLED -- table write block 1 not protected
pragma target WRTB DISABLED -- bootblock not write protected
pragma target WRTC DISABLED -- config not write protected
pragma target EBTR0 DISABLED -- table read block 0 not protected
pragma target EBTR1 DISABLED -- table read block 1 not protected
pragma target EBTRB DISABLED -- boot block not protected
-- ----------------------------------------------------------------------------

enable_digital_io() -- make all pins digital I/O
include delay -- delay routines

-- ----------------------------------------------------------------------------
-- port/pin map
PORTA_direction = ALL_INPUT
PORTB_direction = ALL_INPUT
PORTC_direction = ALL_OUTPUT
-- led pins
var bit led_midi_out is pin_C6
var bit led_midi_in is pin_C7
-- ----------------------------------------------------------------------------
-- setup the timer0_isr_interval library
const word timer0_isr_rate = 1000 -- 1 kHz isr rate
const DELAY_SLOTS = 1 -- support 1 delay at the same time
include timer0_isr_interval -- timer0 isr routines

-- ----------------------------------------------------------------------------
-- constants
const word MIDI_LED_DELAY = 40 -- MIDI LED On, in ms

-- ----------------------------------------------------------------------------
include midiserial -- Serial UART routines
include midiusb -- USB MIDI routines
-- ----------------------------------------------------------------------------
-- variables
var byte data

-- ----------------------------------------------------------------------------
-- main program
timer0_isr_init() -- init timer0 isr

forever loop

usbMidiFlush() -- usb tasks alive

-- ----------------------------------------------------------------------
-- slot led
if (check_delay(0)) then
set_delay(0, 1000 / MIDI_LED_DELAY)
serialRefreshLeds()
end if

-- ----------------------------------------------------------------------
-- get MIDI data from uart (midi in) and send to usb
if (serialReadByte(data)) then
usbMidiWriteByte(data)
end if

-- ----------------------------------------------------------------------
-- get MIDI data from usb and send to uart (midi out)
if (usbMidiReadByte(data)) then
serialWriteByte(data)
end if

end loop
Loading

0 comments on commit 3d1054d

Please sign in to comment.