You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.7KB

  1. // Copyright 2013 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. #include <stm32f10x_conf.h>
  25. #include "streams/drivers/adc.h"
  26. #include "streams/drivers/dac.h"
  27. #include "streams/drivers/pwm.h"
  28. #include "streams/drivers/system.h"
  29. #include "streams/cv_scaler.h"
  30. #include "streams/processor.h"
  31. #include "streams/ui.h"
  32. using namespace streams;
  33. using namespace stmlib;
  34. Adc adc;
  35. CvScaler cv_scaler;
  36. Dac dac;
  37. Processor processor[2];
  38. Pwm pwm;
  39. System sys;
  40. Ui ui;
  41. // Default interrupt handlers.
  42. extern "C" {
  43. void HardFault_Handler() { while (1); }
  44. void MemManage_Handler() { while (1); }
  45. void BusFault_Handler() { while (1); }
  46. void UsageFault_Handler() { while (1); }
  47. void NMI_Handler() { }
  48. void SVC_Handler() { }
  49. void DebugMon_Handler() { }
  50. void PendSV_Handler() { }
  51. }
  52. extern "C" {
  53. void SysTick_Handler() {
  54. // SysTick is at 4kHz to get a fast bargraph refresh.
  55. ui.Poll();
  56. }
  57. }
  58. void Process(uint16_t* cv) {
  59. for (uint8_t i = 0; i < 2; ++i) {
  60. uint16_t gain = 0;
  61. uint16_t frequency = 65535;
  62. processor[i].Process(
  63. cv_scaler.audio_sample(i),
  64. cv_scaler.excite_sample(i),
  65. &gain,
  66. &frequency);
  67. if (ui.calibrating()) {
  68. gain = 0;
  69. frequency = 65535;
  70. }
  71. dac.Write(i, cv_scaler.ScaleGain(i, gain));
  72. pwm.Write(i, 65535 - frequency);
  73. }
  74. }
  75. void Init() {
  76. sys.Init(true);
  77. adc.Init(false, &Process);
  78. cv_scaler.Init(&adc);
  79. dac.Init();
  80. pwm.Init();
  81. processor[0].Init(0);
  82. processor[1].Init(1);
  83. ui.Init(&adc, &cv_scaler, &processor[0]);
  84. sys.StartTimers();
  85. adc.Start();
  86. }
  87. int main(void) {
  88. Init();
  89. while (1) {
  90. ui.DoEvents();
  91. }
  92. }