Compare commits

...

4 Commits

  1. 10
      Makefile.conf
  2. 12
      examples/Makefile
  3. 75
      examples/main_testtone.cc
  4. 145
      examples/main_usbhost.cc

10
Makefile.conf

@ -1,5 +1,5 @@
#HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
-include build.conf
HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
-include $(HERE)/build.conf
TARGET_LIB = libdizzy.a
FLASH_TARGET ?= main_testtone
@ -10,7 +10,11 @@ DAISYSP_DIR ?= ../../heck_DaisySP
CXX_STANDARD ?= -std=c++17
CXXFLAGS += -Wall -Wno-unused -Wno-reorder-ctor -Wno-switch
CXXFLAGS += -fdiagnostics-color=always
CXXFLAGS += \
-fdiagnostics-color=always \
-fmessage-length=170 \
-fdiagnostics-path-format=inline-events \
-fdiagnostics-show-template-tree \
#APP_TYPE ?= BOOT_NONE
#LDFLAGS += -u_printf_float

12
examples/Makefile

@ -12,9 +12,19 @@ LDFLAGS += -ldizzy
SRC_EXCLUDED := \
main_minimal.c \
main_memtest1.cc \
main_adc.cc \
main_blink.cc \
main_cli.cc \
main_density.cc \
main_framework_proto1.cc \
main_framework_proto2.cc \
main_memtest1.cc \
test_bla.c
main_minimal.cc \
main_template_full.cc \
main_testtone.cc \
main_usbhost.cc \
SOURCES := $(wildcard *)
SOURCES := $(filter-out $(SRC_EXCLUDED), $(SOURCES))

75
examples/main_testtone.cc

@ -1,54 +1,41 @@
#include "types.hh"
#include "daisy_seed.h"
#include "daisysp.h"
namespace Heck {
namespace Constants {
}
ld::DaisySeed hw{};
dsp::Oscillator osc{};
namespace ld = daisy;
namespace dsp = daisysp;
void AudioCallback(
ld::AudioHandle::InterleavingInputBuffer in,
ld::AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
float osc_out;
osc.SetFreq(1000);
ld::DaisySeed seed{};
dsp::Oscillator osc_l{};
dsp::Oscillator osc_r{};
for (size_t i = 0; i < size; i += 2) {
osc.SetAmp(1.0);
osc_out = osc.Process();
osc_out *= 0.005;
out[i] = osc_out;
out[i + 1] = osc_out;
}
void AudioCallback(
ld::AudioHandle::InputBuffer in,
ld::AudioHandle::OutputBuffer out,
size_t size)
{
float osc_out{};
for (size_t i = 0; i < size; i++) {
out[0][i] = osc_l.Process() * 0.005;
out[1][i] = osc_r.Process() * 0.005;
}
}
void init()
{
hw.Configure();
hw.Init();
hw.SetAudioBlockSize(4);
float samplerate = hw.AudioSampleRate();
osc.Init(samplerate);
osc.SetWaveform(osc.WAVE_SIN);
osc.SetAmp(1.f);
osc.SetFreq(1000);
hw.StartAudio(AudioCallback);
}
int main(void)
{
// system init
seed.Configure();
seed.Init();
seed.SetAudioBlockSize(4);
float samplerate = seed.AudioSampleRate();
void mainloop()
{
for (;;) {}
}
} // namespace Heck
// application init
osc_l.Init(samplerate);
osc_l.SetFreq(300);
osc_r.Init(samplerate);
osc_r.SetFreq(400);
int main(void)
{
Heck::init();
Heck::mainloop();
// system main
seed.StartAudio(AudioCallback);
return 0;
}

145
examples/main_usbhost.cc

@ -0,0 +1,145 @@
/** Example of setting reading MIDI Input via USB Host
*
*
* This requires a USB-A connector
*
* This example will also log incoming messages to the serial port for general MIDI troubleshooting
*/
#include "daisy_seed.h"
#include "usbh_midi.h"
/** This prevents us from having to type "daisy::" in front of a lot of things. */
using namespace daisy;
/** Global Hardware access */
DaisySeed hw;
MidiUsbHandler midi;
USBHostHandle usbHost;
/** FIFO to hold messages as we're ready to print them */
FIFO<MidiEvent, 128> event_log;
void USBH_Connect(void* data)
{
hw.PrintLine("device connected");
}
void USBH_Disconnect(void* data)
{
hw.PrintLine("device disconnected");
}
void USBH_ClassActive(void* data)
{
if(usbHost.IsActiveClass(USBH_MIDI_CLASS))
{
hw.PrintLine("MIDI device class active");
MidiUsbHandler::Config midi_config;
midi_config.transport_config.periph = MidiUsbTransport::Config::Periph::HOST;
midi.Init(midi_config);
midi.StartReceive();
}
}
void USBH_Error(void* data)
{
hw.PrintLine("USB device error");
}
int main(void)
{
/** Initialize our hardware */
hw.Init();
hw.StartLog(true);
hw.PrintLine("MIDI USB Host start");
/** Configure USB host */
USBHostHandle::Config usbhConfig;
usbhConfig.connect_callback = USBH_Connect,
usbhConfig.disconnect_callback = USBH_Disconnect,
usbhConfig.class_active_callback = USBH_ClassActive,
usbhConfig.error_callback = USBH_Error,
usbHost.Init(usbhConfig);
usbHost.RegisterClass(USBH_MIDI_CLASS);
uint32_t now = System::GetNow();
uint32_t log_time = System::GetNow();
uint32_t blink_time = 0;
bool ledState = false;
hw.PrintLine("MIDI USB Host initialized");
/** Infinite Loop */
while(1)
{
now = System::GetNow();
if (now > blink_time)
{
hw.SetLed(ledState);
ledState = !ledState;
if (usbHost.GetPresent())
blink_time = now + 400;
else
blink_time = now + 80;
}
/** Run USB host process */
usbHost.Process();
if(usbHost.IsActiveClass(USBH_MIDI_CLASS) && midi.RxActive())
{
/** Process MIDI in the background */
midi.Listen();
/** Loop through any MIDI Events */
while(midi.HasEvents())
{
MidiEvent msg = midi.PopEvent();
/** Handle messages as they come in
* See DaisyExamples for some examples of this
*/
switch(msg.type)
{
case NoteOn:
// Do something on Note On events
{
uint8_t bytes[3] = {0x90, 0x00, 0x00};
bytes[1] = msg.data[0];
bytes[2] = msg.data[1];
midi.SendMessage(bytes, 3);
}
break;
default: break;
}
/** Regardless of message, let's add the message data to our queue to output */
event_log.PushBack(msg);
}
/** Now separately, every 5ms we'll print the top message in our queue if there is one */
if(now - log_time > 5)
{
log_time = now;
if(!event_log.IsEmpty())
{
auto msg = event_log.PopFront();
char outstr[128];
const char* type_str = MidiEvent::GetTypeAsString(msg);
sprintf(outstr,
"time:\t%ld\ttype: %s\tChannel: %d\tData MSB: "
"%d\tData LSB: %d\n",
now,
type_str,
msg.channel,
msg.data[0],
msg.data[1]);
hw.PrintLine(outstr);
}
}
}
}
}
Loading…
Cancel
Save