forked from PAWPAW-Mirror/lib_xua
Initial test FW app for MIDI
This commit is contained in:
113
tests/test_midi/src/app_midi_simple.xc
Normal file
113
tests/test_midi/src/app_midi_simple.xc
Normal file
@@ -0,0 +1,113 @@
|
||||
// Copyright 2017-2022 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
/* A very simple *example* of a USB audio application (and as such is un-verified for production)
|
||||
*
|
||||
* It uses the main blocks from the lib_xua
|
||||
*
|
||||
* - 2 channels out I2S only
|
||||
* - No DFU
|
||||
* - I2S only
|
||||
*
|
||||
*/
|
||||
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <xclib.h>
|
||||
|
||||
#include "xua.h"
|
||||
#include "xud_device.h"
|
||||
#include "midiinparse.h"
|
||||
#include "midioutparse.h"
|
||||
|
||||
on tile[MIDI_TILE] : port p_midi_tx = XS1_PORT_4C;
|
||||
#if(MIDI_RX_PORT_WIDTH == 4)
|
||||
on tile[MIDI_TILE] : buffered in port:4 p_midi_rx = XS1_PORT_1F;
|
||||
#elif(MIDI_RX_PORT_WIDTH == 1)
|
||||
on tile[MIDI_TILE] : buffered in port:1 p_midi_rx = XS1_PORT_1F;
|
||||
#endif
|
||||
#define CLKBLK_MIDI XS1_CLKBLK_2
|
||||
on tile[MIDI_TILE] : clock clk_midi = CLKBLK_MIDI;
|
||||
|
||||
|
||||
/* Port declarations for I2C to config ADC's */
|
||||
on tile[0]: port p_scl = XS1_PORT_1L;
|
||||
on tile[0]: port p_sda = XS1_PORT_1M;
|
||||
|
||||
/* See hwsupport.xc */
|
||||
void ctrlPort();
|
||||
|
||||
#define CABLE_NUM 0
|
||||
|
||||
#define NOTE_ON 0x90
|
||||
#define PITCH 60
|
||||
#define VELOCITY 80
|
||||
|
||||
void test(chanend c_midi){
|
||||
printf("Test\n");
|
||||
|
||||
struct midi_in_parse_state mips;
|
||||
reset_midi_state(mips);
|
||||
|
||||
unsigned valid = 0;
|
||||
unsigned tx_data = 0;
|
||||
{valid, tx_data} = midi_in_parse(mips,CABLE_NUM, NOTE_ON);
|
||||
printf("Valid: %d data: %u\n", valid, tx_data);
|
||||
{valid, tx_data} = midi_in_parse(mips, CABLE_NUM, PITCH);
|
||||
printf("Valid: %d data: %u\n", valid, tx_data);
|
||||
{valid, tx_data} = midi_in_parse(mips, CABLE_NUM, VELOCITY);
|
||||
printf("Valid: %d data: %u\n", valid, tx_data);
|
||||
|
||||
|
||||
char midi[3];
|
||||
unsigned size = 0;
|
||||
{midi[0], midi[1], midi[2], size} = midi_out_parse(tx_data);
|
||||
printf("size: %d data: 0x%x 0x%x 0x%x\n", size, midi[0], midi[1], midi[2]);
|
||||
|
||||
|
||||
int is_ack;
|
||||
unsigned int datum;
|
||||
|
||||
unsigned count = 0;
|
||||
while(1){
|
||||
select{
|
||||
case midi_get_ack_or_data(c_midi, is_ack, datum):
|
||||
printf("ACK: %d Datum: 0x%x\n", is_ack, datum);
|
||||
count++;
|
||||
if(count == 3){
|
||||
delay_microseconds(200); // Allow frame to complete
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
outuint(c_midi, byterev(tx_data));
|
||||
printf("SEND TO MIDI\n");
|
||||
delay_milliseconds(2); // 30 bits at 31.25 kbps is 0.96ms
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
chan c_midi;
|
||||
|
||||
|
||||
par
|
||||
{
|
||||
on tile[0]: test(c_midi);
|
||||
on tile[1]: usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0);
|
||||
|
||||
|
||||
on tile[0]: ctrlPort();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
43
tests/test_midi/src/hwsupport.xc
Normal file
43
tests/test_midi/src/hwsupport.xc
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2017-2024 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include "xua.h"
|
||||
|
||||
|
||||
on tile[0]: out port p_ctrl = XS1_PORT_8D;
|
||||
|
||||
/* p_ctrl:
|
||||
* [0:3] - Unused
|
||||
* [4] - EN_3v3_N
|
||||
* [5] - EN_3v3A
|
||||
* [6] - EXT_PLL_SEL (CS2100:0, SI: 1)
|
||||
* [7] - MCLK_DIR (Out:0, In: 1)
|
||||
*/
|
||||
#define EXT_PLL_SEL__MCLK_DIR (0x80)
|
||||
|
||||
/* Note, this runs on Tile[0] */
|
||||
void ctrlPort()
|
||||
{
|
||||
// Drive control port to turn on 3V3 and set MCLK_DIR
|
||||
// Note, "soft-start" to reduce current spike
|
||||
// Note, 3v3_EN is inverted
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
p_ctrl <: EXT_PLL_SEL__MCLK_DIR | 0x30; /* 3v3: off, 3v3A: on */
|
||||
delay_microseconds(5);
|
||||
p_ctrl <: EXT_PLL_SEL__MCLK_DIR | 0x20; /* 3v3: on, 3v3A: on */
|
||||
delay_microseconds(5);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configures the external audio hardware at startup. Note this runs on Tile[1] */
|
||||
void AudioHwInit()
|
||||
{
|
||||
}
|
||||
|
||||
/* Configures the external audio hardware for the required sample frequency */
|
||||
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC)
|
||||
{
|
||||
}
|
||||
|
||||
28
tests/test_midi/src/xua_conf.h
Normal file
28
tests/test_midi/src/xua_conf.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2017-2022 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef _XUA_CONF_H_
|
||||
#define _XUA_CONF_H_
|
||||
|
||||
#define NUM_USB_CHAN_OUT 2 /* Number of channels from host to device */
|
||||
#define NUM_USB_CHAN_IN 0 /* Number of channels from device to host */
|
||||
#define I2S_CHANS_DAC 2 /* Number of I2S channels out of xCORE */
|
||||
#define I2S_CHANS_ADC 0 /* Number of I2S channels in to xCORE */
|
||||
#define MCLK_441 (512 * 44100) /* 44.1kHz family master clock frequency */
|
||||
#define MCLK_48 (512 * 48000) /* 48kHz family master clock frequency */
|
||||
#define MIN_FREQ 48000 /* Minimum sample rate */
|
||||
#define MAX_FREQ 48000 /* Maximum sample rate */
|
||||
|
||||
#define EXCLUDE_USB_AUDIO_MAIN
|
||||
|
||||
#define MIDI 1
|
||||
#define MIDI_TILE 1
|
||||
#define VENDOR_STR "XMOS"
|
||||
#define VENDOR_ID 0x20B1
|
||||
#define PRODUCT_STR_A2 "XUA Example"
|
||||
#define PRODUCT_STR_A1 "XUA Example"
|
||||
#define PID_AUDIO_1 1
|
||||
#define PID_AUDIO_2 2
|
||||
#define XUA_DFU_EN 0 /* Disable DFU (for simplicity of example */
|
||||
|
||||
#endif
|
||||
8
tests/test_midi/src/xud_conf.h
Normal file
8
tests/test_midi/src/xud_conf.h
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#include "xua_conf.h"
|
||||
|
||||
/* TODO */
|
||||
#define XUD_UAC_NUM_USB_CHAN_OUT NUM_USB_CHAN_OUT
|
||||
#define XUD_UAC_NUM_USB_CHAN_IN NUM_USB_CHAN_IN
|
||||
Reference in New Issue
Block a user