9#define DTCMRAM __attribute__((section(".dtcmram_bss")))
10#define D2RAM __attribute__((section(".d2_bss")))
11#define D2RAM2 __attribute__((section(".d2r2_bss")))
12#define ITCMRAM __attribute__((section(".itcmram_bss")))
20static constexpr int kMaxBlockSize = 96;
25static daisy::LedDriverPca9685<2, true>::DmaBuffer DMA_BUFFER_MEM_SECTION
33daisy::USBHostHandle
usb;
138 for(
int i = 0; i <
CV_LAST; i++)
181 hw_version = GetBoardRevision();
190 cal_save_flag_ =
false;
191 for(
int i = 0; i <
CV_LAST; i++)
193 cv_offsets_[i] = 0.f;
195 LoadCalibrationData();
212 seed.ChangeAudioCallback(cb);
216 void StartAudio(daisy::AudioHandle::InterleavingAudioCallback cb)
224 seed.ChangeAudioCallback(cb);
236 uint32_t target_freq,
237 void *data =
nullptr)
239 daisy::TimerHandle::Config timcfg;
240 timcfg.periph = daisy::TimerHandle::Config::Peripheral::TIM_5;
241 timcfg.dir = daisy::TimerHandle::Config::CounterDir::UP;
242 auto tim_base_freq = daisy::System::GetPClk2Freq();
243 auto tim_target_freq = target_freq;
244 auto tim_period = tim_base_freq / tim_target_freq;
245 timcfg.period = tim_period;
246 timcfg.enable_irq =
true;
247 tim5_handle.Init(timcfg);
248 tim5_handle.SetCallback(cb, data);
261 daisy::SaiHandle::Config::SampleRate srval;
262 size_t new_blocksize = 96;
266 srval = daisy::SaiHandle::Config::SampleRate::SAI_16KHZ;
269 srval = daisy::SaiHandle::Config::SampleRate::SAI_32KHZ;
272 srval = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
275 srval = daisy::SaiHandle::Config::SampleRate::SAI_96KHZ;
279 srval = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
283 seed.SetAudioSampleRate(srval);
284 seed.SetAudioBlockSize(new_blocksize);
285 seed.StartAudio(current_cb_);
296 seed.SetAudioSampleRate(samplerate);
305 daisy::SaiHandle::Config::SampleRate srval;
309 srval = daisy::SaiHandle::Config::SampleRate::SAI_16KHZ;
312 srval = daisy::SaiHandle::Config::SampleRate::SAI_32KHZ;
315 srval = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
318 srval = daisy::SaiHandle::Config::SampleRate::SAI_96KHZ;
321 srval = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
324 seed.SetAudioSampleRate(srval);
333 seed.SetAudioBlockSize(blocksize);
363 void WriteLeds() { led_driver_.SwapBuffersAndTransmit(); }
373 LedIdx led = LedMap[idx];
375 led_driver_.SetLed(led.r, r);
376 led_driver_.SetLed(led.g, g);
377 led_driver_.SetLed(led.b, b);
386 SetLed(idx, c.Red(), c.Green(), c.Blue());
403 for(
int i = 0; i <
SW_LAST; i++)
419 for(
int i = 0; i <
CV_LAST; i++)
454 for(
int i = 0; i <
CV_LAST; i++)
462 for(
int i = 0; i <
SW_LAST; i++)
478 daisy::USBHostHandle::ConnectCallback connect_cb =
nullptr,
479 daisy::USBHostHandle::DisconnectCallback disconnect_cb =
nullptr,
480 daisy::USBHostHandle::ClassActiveCallback class_active_cb =
nullptr,
481 daisy::USBHostHandle::ErrorCallback error_cb =
nullptr,
482 void *userdata =
nullptr)
485 daisy::USBHostHandle::Config usbcfg;
486 usbcfg.connect_callback = connect_cb;
487 usbcfg.disconnect_callback = disconnect_cb;
488 usbcfg.class_active_callback = class_active_cb;
489 usbcfg.error_callback = error_cb;
490 usbcfg.userdata = userdata;
494 daisy::FatFSInterface::Config fsi_cfg;
495 fsi_cfg.media = daisy::FatFSInterface::Config::MEDIA_USB;
507 return voct_cal.ProcessInput(
cv[
CV_WARP].Value());
519 return cv[cv_idx].Value() - cv_offsets_[cv_idx];
521 return cv[cv_idx].Value();
540 voct_cal.Record(warp_v1_, warp_v3_);
541 cal_save_flag_ =
true;
549 voct_cal.SetData(scale, offset);
557 voct_cal.GetData(scale, offset);
563 for(
int i = 0; i <
CV_LAST; i++)
565 cv_offsets_[i] = data[i];
572 for(
int i = 0; i <
CV_LAST; i++)
574 data[i] = cv_offsets_[i];
605 static constexpr uint32_t kCalibrationDataOffset = 4096;
616 const LedIdx LedMap[
LED_LAST] = {{0, 1, 2},
629 enum class HardwareVersion
637 daisy::LedDriverPca9685<2, true> led_driver_;
640 daisy::AudioHandle::AudioCallback current_cb_;
642 daisy::TimerHandle tim5_handle;
643 daisy::I2CHandle i2c;
644 daisy::Pcm3060 codec;
646 HardwareVersion hw_version;
649 float warp_v1_, warp_v3_;
650 daisy::VoctCalibration voct_cal;
656 void ConfigureAudio()
659 if(hw_version == HardwareVersion::REV3)
661 daisy::I2CHandle::Config codec_i2c_config;
662 codec_i2c_config.periph
663 = daisy::I2CHandle::Config::Peripheral::I2C_1;
664 codec_i2c_config.pin_config = {
seed.GetPin(11),
seed.GetPin(12)};
665 codec_i2c_config.speed
666 = daisy::I2CHandle::Config::Speed::I2C_400KHZ;
667 codec_i2c_config.mode = daisy::I2CHandle::Config::Mode::I2C_MASTER;
669 i2c.Init(codec_i2c_config);
672 daisy::SaiHandle::Config sai_cfg;
673 sai_cfg.periph = daisy::SaiHandle::Config::Peripheral::SAI_2;
674 sai_cfg.sr = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
675 sai_cfg.bit_depth = daisy::SaiHandle::Config::BitDepth::SAI_24BIT;
676 sai_cfg.a_sync = daisy::SaiHandle::Config::Sync::SLAVE;
677 sai_cfg.b_sync = daisy::SaiHandle::Config::Sync::MASTER;
678 sai_cfg.a_dir = daisy::SaiHandle::Config::Direction::RECEIVE;
679 sai_cfg.b_dir = daisy::SaiHandle::Config::Direction::TRANSMIT;
680 sai_cfg.pin_config.fs =
seed.GetPin(27);
681 sai_cfg.pin_config.mclk =
seed.GetPin(24);
682 sai_cfg.pin_config.sck =
seed.GetPin(28);
683 sai_cfg.pin_config.sa =
seed.GetPin(26);
684 sai_cfg.pin_config.sb =
seed.GetPin(25);
686 daisy::SaiHandle sai_2_handle;
687 sai_2_handle.Init(sai_cfg);
688 daisy::AudioHandle::Config audio_cfg;
689 audio_cfg.blocksize = 48;
691 = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
692 audio_cfg.postgain = 1.0f;
693 seed.audio_handle.Init(audio_cfg, sai_2_handle);
699 daisy::Pin deemp_pin(daisy::PORTB, 11);
700 deemp.Init(deemp_pin, daisy::GPIO::Mode::OUTPUT);
703 seed.audio_handle.SetOutputCompensation(0.8785f);
708 void ConfigureControls()
710 if(hw_version == HardwareVersion::REV3)
713 daisy::AdcChannelConfig cfg[
CV_LAST + 1];
715 for(
int i = 0; i <
CV_LAST; i++)
717 cfg[i].InitSingle(
seed.GetPin(17 + i));
727 for(
size_t i = 0; i <
CV_LAST; i++)
741 pin =
seed.GetPin(23);
752 cfg[
CV_TIME].InitSingle(daisy::seed::A3);
753 cfg[
CV_MIX].InitSingle(daisy::seed::A4);
755 cfg[
CV_BLUR].InitSingle(daisy::seed::A6);
756 cfg[
CV_WARP].InitSingle(daisy::seed::A7);
763 for(
size_t i = 0; i <
CV_LAST; i++)
773 dsy_gpio_pin freeze_pin = daisy::seed::D26;
782 dsy_gpio_pin revpin =
seed.GetPin(14);
789 daisy::I2CHandle::Config codec_i2c_config;
790 codec_i2c_config.periph = daisy::I2CHandle::Config::Peripheral::I2C_1;
791 codec_i2c_config.pin_config = {
seed.GetPin(11),
seed.GetPin(12)};
792 codec_i2c_config.speed = daisy::I2CHandle::Config::Speed::I2C_1MHZ;
793 codec_i2c_config.mode = daisy::I2CHandle::Config::Mode::I2C_MASTER;
794 i2c.Init(codec_i2c_config);
797 led_driver_.Init(i2c, {0x00, 0x01}, led_dma_buffer_a, led_dma_buffer_b);
803 HardwareVersion GetBoardRevision()
805 daisy::GPIO version_gpio;
806 version_gpio.Init(daisy::seed::D2,
807 daisy::GPIO::Mode::INPUT,
808 daisy::GPIO::Pull::PULLUP);
810 auto pinstate = version_gpio.Read();
811 version_gpio.DeInit();
813 return HardwareVersion::REV3;
815 return HardwareVersion::REV4;
819 void LoadCalibrationData()
821 daisy::PersistentStorage<CalibrationData> cal_storage(
seed.qspi);
822 CalibrationData default_cal;
823 cal_storage.Init(default_cal, kCalibrationDataOffset);
824 auto &cal_data = cal_storage.GetSettings();
Hardware support class for the Qu-Bit Aurora This should be created, and intitialized at the beginnin...
Definition: aurora.h:159
void ClearLeds()
sets all RGB LEDs to off state This can be called from the top of wherever LEDs are periodically set ...
Definition: aurora.h:350
daisy::Switch switches[SW_LAST]
Definition: aurora.h:588
void ProcessAnalogControls()
filters all analog controls (knobs and CVs) This is called from ProcessAllControls,...
Definition: aurora.h:412
void SetAudioSampleRate(int samplerate)
sets the audio sample rate. Audio must be stopped for this to work properly
Definition: aurora.h:303
void StartAudio(daisy::AudioHandle::AudioCallback cb)
Starts a specified audio callback Data is non-interleaved (i.e. {{L0, L1, ... , LN},...
Definition: aurora.h:202
void StopAudio()
Stops Audio.
Definition: aurora.h:289
void UpdateHidRates()
Update HidRates for new Callback rate when samplerate/blocksize change.
Definition: aurora.h:452
float GetKnobValue(int ctrl) const
returns a 0-1 value for the given knob control
Definition: aurora.h:427
void ChangeAudioCallback(daisy::AudioHandle::InterleavingAudioCallback cb)
Changes current callback to a new interleaved callback.
Definition: aurora.h:222
bool ReadyToSaveCal() const
Checks to see if calibration has been completed and needs to be saved.
Definition: aurora.h:579
Hardware()
Empty Constructor Call Init from main to initialize.
Definition: aurora.h:164
void CalibrateV1(float v1)
called during a customized calibration UI to record the 1V value
Definition: aurora.h:532
float AudioCallbackRate() const
returns the rate in Hz that the audio callback gets called
Definition: aurora.h:340
~Hardware()
Empty Destructor This object should span the life of the program.
Definition: aurora.h:169
void SetTestLed(bool state)
sets the state of the LED on the daisy itself
Definition: aurora.h:343
void GetWarpCalData(float &scale, float &offset)
Gets the current calibration data for 1V/Octave over Warp CV typically used to prepare data for stori...
Definition: aurora.h:555
void StartAudio(daisy::AudioHandle::InterleavingAudioCallback cb)
Starts a specified Interleaving audio callback.
Definition: aurora.h:216
void ProcessAllControls()
filters and debounces all control This should be run once per audio callback.
Definition: aurora.h:392
const daisy::Switch & GetButton(int idx) const
returns a reference to a given momentary switch Example Usage: bool state = hw.GetButton(SW_FREEZE)....
Definition: aurora.h:434
size_t AudioBlockSize()
returns the number of samples to process in each audio callback
Definition: aurora.h:337
void PrepareMedia(daisy::USBHostHandle::ConnectCallback connect_cb=nullptr, daisy::USBHostHandle::DisconnectCallback disconnect_cb=nullptr, daisy::USBHostHandle::ClassActiveCallback class_active_cb=nullptr, daisy::USBHostHandle::ErrorCallback error_cb=nullptr, void *userdata=nullptr)
starts the mounting process for USB Drive use if it is present
Definition: aurora.h:477
void SetLed(Leds idx, daisy::Color c)
Sets the Color value of an LED.
Definition: aurora.h:384
bool GetGateTrig(int idx)
returns true if the gate input just went high This is expected to be checked only once per audio call...
Definition: aurora.h:444
void ClearSaveCalFlag()
signal the cal-save flag to clear once calibration data has been written to ext. flash memory
Definition: aurora.h:582
void ChangeSampleRate(int sr)
Updates the samplerate to one of the allowed target samplerates. This function stops the audio comple...
Definition: aurora.h:259
void SetWarpCalData(float scale, float offset)
Sets the calibration data for 1V/Octave over Warp CV typically set after reading stored data from ext...
Definition: aurora.h:547
float GetCvValue(int cv_idx)
gets calibrated offset-adjusted CV Value from the hardware.
Definition: aurora.h:516
void SetAudioBlockSize(size_t blocksize)
sets the number of samples to process in each audio callback
Definition: aurora.h:331
void GetCvOffsetData(float *data)
Fills an array with the offset data currently being used.
Definition: aurora.h:570
bool GetGateState(int idx)
returns true if the gate input is currently high
Definition: aurora.h:449
void WriteLeds()
Writes the state of all LEDs to the hardware This can be called from a fixed interval in the main loo...
Definition: aurora.h:363
void DelayMs(size_t del)
delay function; same as System::Delay(), and should not be called from any interrupt callbacks (LowPr...
Definition: aurora.h:529
void StartLowPriorityCallback(daisy::TimerHandle::PeriodElapsedCallback cb, uint32_t target_freq, void *data=nullptr)
Definition: aurora.h:235
daisy::AnalogControl controls[KNOB_LAST]
Definition: aurora.h:594
daisy::DaisySeed seed
Definition: aurora.h:597
daisy::AnalogControl cv[CV_LAST]
Definition: aurora.h:585
float AudioSampleRate()
returns the sample rate in Hz of the audio engine
Definition: aurora.h:328
void ProcessDigitalControls()
filters and debounces digital controls (switches) This is called from ProcessAllControls,...
Definition: aurora.h:401
float GetWarpVoct()
Return a MIDI note number value from -60 to 60 corresponding to the -5V to 5V input range of the Warp...
Definition: aurora.h:505
void SetLed(Leds idx, float r, float g, float b)
Sets the RGB value of a given LED.
Definition: aurora.h:371
void SetCvOffsetData(float *data)
Sets the cv offset from an externally array of data.
Definition: aurora.h:561
void Init(bool boost=true)
Initialize the hardware. Call this function at the start of main()
Definition: aurora.h:178
void ChangeAudioCallback(daisy::AudioHandle::AudioCallback cb)
Changes current callback to a new non-interleaved callback.
Definition: aurora.h:209
void CalibrateV3(float v3)
called during a customized calibration UI to record the 3V value and set that calibraiton has complet...
Definition: aurora.h:537
daisy::GateIn gates[GATE_LAST]
Definition: aurora.h:591
void SetAudioSampleRate(daisy::SaiHandle::Config::SampleRate samplerate)
sets the audio sample rate. Audio must be stopped for this to work properly
Definition: aurora.h:294
daisy::FatFSInterface fatfs_interface
global accessor to the FatFS interface. This is left global so that it is guaranteed to be within the...
Definition: aurora.h:39
Leds
indexed accessors for RGB LEDs Example usage: hw.SetLed(LED_FREEZE, 0.f, 0.f, 1.f);
Definition: aurora.h:100
@ LED_5
Definition: aurora.h:107
@ LED_BOT_2
Definition: aurora.h:110
@ LED_1
Definition: aurora.h:103
@ LED_BOT_3
Definition: aurora.h:111
@ LED_REVERSE
Definition: aurora.h:101
@ LED_6
Definition: aurora.h:108
@ LED_BOT_1
Definition: aurora.h:109
@ LED_LAST
Definition: aurora.h:112
@ LED_2
Definition: aurora.h:104
@ LED_FREEZE
Definition: aurora.h:102
@ LED_4
Definition: aurora.h:106
@ LED_3
Definition: aurora.h:105
ControlCVs
indexed accessors for CV controls Example usage: float val = hw.GetCvValue(CV_ATMOSPHERE);
Definition: aurora.h:61
@ CV_ATMOSPHERE
Definition: aurora.h:62
@ CV_MIX
Definition: aurora.h:64
@ CV_BLUR
Definition: aurora.h:66
@ CV_LAST
Definition: aurora.h:68
@ CV_REFLECT
Definition: aurora.h:65
@ CV_WARP
Definition: aurora.h:67
@ CV_TIME
Definition: aurora.h:63
Switches
indexed accessors for momentary switches Example usage: bool state = hw.GetSwitch(SW_FREEZE)....
Definition: aurora.h:76
@ SW_REVERSE
Definition: aurora.h:78
@ SW_SHIFT
Definition: aurora.h:79
@ SW_FREEZE
Definition: aurora.h:77
@ SW_LAST
Definition: aurora.h:80
daisy::USBHostHandle usb
global USB host handle accessor This is left global so that it is guaranteed to be within the AXI SRA...
Definition: aurora.h:33
Gates
indexed accessors for momentary switches Example usage: bool trig = hw.GetGateTrig(GATE_FREEZE);
Definition: aurora.h:88
@ GATE_REVERSE
Definition: aurora.h:90
@ GATE_LAST
Definition: aurora.h:91
@ GATE_FREEZE
Definition: aurora.h:89
ControlKnobs
indexed accessors for knob controls Example usage: float val = hw.GetKnobValue(KNOB_TIME);
Definition: aurora.h:46
@ KNOB_WARP
Definition: aurora.h:52
@ KNOB_ATMOSPHERE
Definition: aurora.h:50
@ KNOB_BLUR
Definition: aurora.h:51
@ KNOB_LAST
Definition: aurora.h:53
@ KNOB_MIX
Definition: aurora.h:49
@ KNOB_REFLECT
Definition: aurora.h:48
@ KNOB_TIME
Definition: aurora.h:47
Calibration data container for Aurora This data is calibrated from the Qu-Bit default Aurora firmware...
Definition: aurora.h:120
float warp_offset
Definition: aurora.h:122
bool operator==(const CalibrationData &rhs)
checks sameness
Definition: aurora.h:126
CalibrationData()
Definition: aurora.h:121
float warp_scale
Definition: aurora.h:122
bool operator!=(const CalibrationData &rhs)
Not equal operator.
Definition: aurora.h:148
float cv_offset[CV_LAST]
Definition: aurora.h:123