Skip to content

Commit

Permalink
0.0.1-ALPHA
Browse files Browse the repository at this point in the history
  • Loading branch information
LouDnl committed Sep 19, 2024
1 parent ccfae87 commit 941e988
Show file tree
Hide file tree
Showing 16 changed files with 2,948 additions and 0 deletions.
135 changes: 135 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
####
# USBSID-Pico is a RPi Pico (RP2040) based board for interfacing one or two
# MOS SID chips and/or hardware SID emulators over (WEB)USB with your computer,
# phone or ASID supporting player
#
# CMakeLists.txt
# This file is part of USBSID-Pico (https://github.com/LouDnl/USBSID-Pico)
# File author: LouD
#
# Copyright (c) 2024 LouD
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
####
cmake_minimum_required(VERSION 3.17)

set(PROJECT_NAME usbsidpico) # projectname
set(PROJECT_VERSION "0.0.1-ALPHA")
set(CMAKE_BUILD_TYPE Debug) # build with debug symbols
set(TINYUSB_PATH ${PICO_SDK_PATH}/lib/tinyusb)

### Executables
list(APPEND FILENAMES
${PROJECT_NAME}-singlesid
${PROJECT_NAME}-singleskpico
${PROJECT_NAME}-dualsid
${PROJECT_NAME}-skpico-singlesid
${PROJECT_NAME}-dualskpico
${PROJECT_NAME}-dualskpico-mixed)
list(APPEND SIDTYPES 0 1 2 3 4 5)

# default environment options
set(SOURCEFILES
${CMAKE_CURRENT_LIST_DIR}/src/usbsid.c
${CMAKE_CURRENT_LIST_DIR}/src/gpio.c
${CMAKE_CURRENT_LIST_DIR}/src/midi.c
${CMAKE_CURRENT_LIST_DIR}/src/asid.c
${CMAKE_CURRENT_LIST_DIR}/src/mcu.c
${CMAKE_CURRENT_LIST_DIR}/src/usb_descriptors.c)
# COMPILE_OPTS -Wall -Werror -Wno-maybe-uninitialized -save-temps -fverbose-asm)
set(COMPILE_OPTS PRIVATE -Wno-maybe-uninitialized -fverbose-asm)
set(TARGET_LL
pico_stdlib
pico_unique_id
pico_multicore
pico_stdio_usb
pico_usb_reset_interface
tinyusb_device
tinyusb_board
hardware_clocks
hardware_resets
hardware_uart
hardware_pwm
hardware_pio)
set(PIO ${CMAKE_CURRENT_LIST_DIR}/src/clock.pio)
set(PIO_RGB ${CMAKE_CURRENT_LIST_DIR}/src/ws2812.pio)
set(TARGET_INCLUDE_DIRS PRIVATE
.
src
$ENV{PICO_SDK_PATH}/lib/tinyusb/hw
$ENV{PICO_SDK_PATH}/lib/tinyusb/src)

# rp2040 sdk
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
include($ENV{PICO_EXTRAS_PATH}/external/pico_extras_import.cmake)

# project
project(${PROJECT_NAME} C CXX ASM)

# init sdk
pico_sdk_init()

include_directories(".")

foreach(FILENAME SIDTYPE IN ZIP_LISTS FILENAMES SIDTYPES)
# set filename
set(BUILD ${FILENAME})
message(STATUS "Building ${FILENAME} with SIDTYPE=${SIDTYPE}")
# executable
add_executable(${BUILD} ${SOURCEFILES})
# pio addition
pico_generate_pio_header(${BUILD} ${PIO})
# source files to compile
target_sources(${BUILD} PUBLIC ${SOURCEFILES})
target_compile_options(${BUILD} ${COMPILE_OPTS})
target_compile_definitions(${BUILD} PRIVATE USBSID SIDTYPES=${SIDTYPE})
# tell the linker what libraries to link
target_link_libraries(${BUILD} ${TARGET_LL})
# target sid types
target_include_directories(${BUILD} ${TARGET_INCLUDE_DIRS})
pico_set_program_name(${BUILD} "USBSIDPico")
pico_set_program_version(${BUILD} $PROJECT_VERSION)
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(${BUILD})
# enable uart output, disable usb output
pico_enable_stdio_uart(${BUILD} 1)
pico_enable_stdio_usb(${BUILD} 0)
endforeach()

foreach(FILENAME SIDTYPE IN ZIP_LISTS FILENAMES SIDTYPES)
# override filename for rgb compile
set(FILENAME ${FILENAME}-rgb)
# set filename
set(BUILD ${FILENAME})
message(STATUS "Building ${FILENAME} with SIDTYPE=${SIDTYPE}")
# executable
add_executable(${BUILD} ${SOURCEFILES})
# pio addition
pico_generate_pio_header(${BUILD} ${PIO})
pico_generate_pio_header(${BUILD} ${PIO_RGB})
# source files to compile
target_sources(${BUILD} PUBLIC ${SOURCEFILES})
target_compile_options(${BUILD} ${COMPILE_OPTS})
target_compile_definitions(${BUILD} PRIVATE USBSID SIDTYPES=${SIDTYPE} USE_RGB=1)
# tell the linker what libraries to link
target_link_libraries(${BUILD} ${TARGET_LL})
# target sid types
target_include_directories(${BUILD} ${TARGET_INCLUDE_DIRS})
pico_set_program_name(${BUILD} "USBSIDPico")
pico_set_program_version(${BUILD} $PROJECT_VERSION)
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(${BUILD})
# enable uart output, disable usb output
pico_enable_stdio_uart(${BUILD} 1)
pico_enable_stdio_usb(${BUILD} 0)
endforeach()
97 changes: 97 additions & 0 deletions src/asid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* USBSID-Pico is a RPi Pico (RP2040) based board for interfacing one or two
* MOS SID chips and/or hardware SID emulators over (WEB)USB with your computer,
* phone or ASID supporting player
*
* asid.c
* This file is part of USBSID-Pico (https://github.com/LouDnl/USBSID-Pico)
* File author: LouD
*
* The contents of this file are based upon and heavily inspired by the sourcecode from
* TherapSID by Twisted Electrons: https://github.com/twistedelectrons/TherapSID
* TeensyROM by Sensorium Embedded: https://github.com/SensoriumEmbedded/TeensyROM
* SID Factory II by Chordian: https://github.com/Chordian/sidfactory2
*
* Any licensing conditions from either of the above named sources automatically
* apply to this code
*
* Copyright (c) 2024 LouD
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include "midi.h"
#include "asid.h"
#include "usbsid.h"


void handle_asid_message(uint8_t sid ,uint8_t* buffer, int size)
{
(void)size; /* unused at the moment */

unsigned int reg = 0;
for (uint8_t mask = 0; mask < 4; mask++) { /* no more then 4 masks */
for (uint8_t bit = 0; bit < 7; bit++) { /* each packet has 7 bits ~ stoopid midi */
if (buffer[mask + 3] & (1 << bit)) { /* 3 byte message, skip 3 each round and add the bit */
uint8_t register_value = buffer[reg + 11]; /* get the value to write from the buffer */
if(buffer[mask + 7] & (1 << bit)) { /* if anything higher then 0 */
register_value |= 0x80; /* the register_value needs its 8th MSB bit */
}
uint8_t address = asid_sid_registers[mask * 7 + bit];
handle_asidbuffer_task((address |= sid), register_value);
reg++;
}
}
}
}

void decode_asid_message(uint8_t* buffer, int size)
{
switch(buffer[2]) {
case 0x4C:
/* Play start */
midimachine.bus = CLAIMED;
break;
case 0x4D:
/* Play stop */
midimachine.bus = FREE;
break;
case 0x4F:
/* Display characters */
break;
case 0x4E:
handle_asid_message(0, buffer, size);
break;
case 0x50:
handle_asid_message(32, buffer, size);
break;
case 0x51:
handle_asid_message(64, buffer, size);
break;
case 0x60:
midimachine.fmopl = 1;
#if defined(SIDTYPE1)
/* Not implemented yet */
#endif
default:
break;
}
}

void process_sysex(uint8_t* buffer, int size) // NOTE: UNNESCESSARY OVERHEAD IF ASID ONLY
{
if (buffer[1] == 0x2D) { /* 0x2D = ASID sysex message */
decode_asid_message(buffer, size);
} // room for other sysex protocols
}
79 changes: 79 additions & 0 deletions src/asid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* USBSID-Pico is a RPi Pico (RP2040) based board for interfacing one or two
* MOS SID chips and/or hardware SID emulators over (WEB)USB with your computer,
* phone or ASID supporting player
*
* asid.h
* This file is part of USBSID-Pico (https://github.com/LouDnl/USBSID-Pico)
* File author: LouD
*
* The contents of this file are based upon and heavily inspired by the sourcecode from
* TherapSID by Twisted Electrons: https://github.com/twistedelectrons/TherapSID
* TeensyROM by Sensorium Embedded: https://github.com/SensoriumEmbedded/TeensyROM
* SID Factory II by Chordian: https://github.com/Chordian/sidfactory2
*
* Any licensing conditions from either of the above named sources automatically
* apply to this code
*
* Copyright (c) 2024 LouD
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef _ASID_H_
#define _ASID_H_
#pragma once

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


static const uint8_t asid_sid_registers[] =
{
/* register, bit */
0x00, // 0
0x01, // 1
0x02, // 2
0x03, // 3
0x05, // 4
0x06, // 5
0x07, // 6
0x08, // 7
0x09, // 8
0x0a, // 9
0x0c, // 10
0x0d, // 11
0x0e, // 12
0x0f, // 13
0x10, // 14
0x11, // 15
0x13, // 16
0x14, // 17
0x15, // 18
0x16, // 19
0x17, // 20
0x18, // 21
0x04, // 22
0x0b, // 23
0x12, // 24
0x04, // 25 <= secondary for reg 04
0x0b, // 26 <= secondary for reg 11
0x12, // 27 <= secondary for reg 18
};

void process_sysex(uint8_t *buffer, int size);

#endif /* _ASID_H_ */
51 changes: 51 additions & 0 deletions src/clock.pio
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
;
; USBSID-Pico is a RPi Pico (RP2040) based board for interfacing one or two
; MOS SID chips and/or hardware SID emulators over (WEB)USB with your computer,
; phone or ASID supporting player
;
; clock.pio
; This file is part of USBSID-Pico (https://github.com/LouDnl/USBSID-Pico)
; File author: LouD
;
; Source: https://forums.raspberrypi.com/viewtopic.php?t=355595#p2131828
; Source: https://parthssharma.github.io/Pico/PIOSquareWave.html
;
; Any licensing conditions from either of the above named sources automatically
; apply to this code
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, version 2.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
; Description:
; Repeatedly get one word of data from the TX FIFO, stalling when the FIFO is
; empty. Write the least significant bit to the OUT pin group.
;
.program clock

.wrap_target ;Free 0 cycle unconditional jump
set pins, 1 ;Drive pin high, binary 1 <--- 250 ns execution time with 4MHz clock
set pins, 2 ;Drive pin low, binary 0 <--- 250 ns ;total 500 ns period
.wrap


%c-sdk{
/* Program to initialize the PIO */
static inline void clock_program_init(PIO pio, uint sm, uint offset, uint pin, float clk_div){
pio_sm_config c = clock_program_get_default_config(offset); /* Get default configurations for the PIO state machine */
sm_config_set_set_pins(&c, pin, 2); /* Set the state machine configurations on the given pin */
sm_config_set_clkdiv(&c, clk_div); /* Set the state machine clock divider */
pio_gpio_init(pio, pin); /* Setup the function select for a GPIO pin to use output from the given PIO instance */
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); /* Use a state machine to set the pin direction for one pins for the PIO instance */
pio_sm_init(pio, sm, offset, &c); /* Resets the state machine to a consistent state, and configures it */
pio_sm_set_enabled(pio, sm, true); /* Enable or disable a PIO state machine */
}
%}
Loading

0 comments on commit 941e988

Please sign in to comment.