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.

121 lines
3.0KB

  1. // Copyright 2014 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 "stmlib/utils/dsp.h"
  26. #include "stmlib/utils/ring_buffer.h"
  27. #include "stmlib/system/system_clock.h"
  28. #include "peaks/drivers/dac.h"
  29. #include "peaks/drivers/gate_input.h"
  30. #include "peaks/drivers/system.h"
  31. #include "peaks/processors.h"
  32. #include "peaks/ui.h"
  33. using namespace peaks;
  34. using namespace stmlib;
  35. Adc adc;
  36. Dac dac;
  37. GateInput gate_input;
  38. Leds leds;
  39. Switches switches;
  40. System sys;
  41. Ui ui;
  42. extern "C" {
  43. void HardFault_Handler(void) { while (1); }
  44. void MemManage_Handler(void) { while (1); }
  45. void BusFault_Handler(void) { while (1); }
  46. void UsageFault_Handler(void) { while (1); }
  47. void NMI_Handler(void) { }
  48. void SVC_Handler(void) { }
  49. void DebugMon_Handler(void) { }
  50. void PendSV_Handler(void) { }
  51. void __cxa_pure_virtual() { while (1); }
  52. }
  53. extern "C" {
  54. uint16_t counter = 0;
  55. void SysTick_Handler() {
  56. ui.Poll();
  57. }
  58. void TIM1_UP_IRQHandler(void) {
  59. static int16_t cv_1;
  60. static int16_t cv_2;
  61. static uint8_t control;
  62. // DAC refresh at 48kHz
  63. if (TIM_GetITStatus(TIM1, TIM_IT_Update) == RESET) {
  64. return;
  65. }
  66. TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
  67. if (dac.ready()) {
  68. dac.Write(32767 - cv_1, 32767 - cv_2);
  69. ui.set_leds_brightness(cv_1, cv_2);
  70. control = gate_input.Read() | ui.ReadPanelGateState();
  71. cv_1 = processors[0].Process(control);
  72. } else {
  73. cv_2 = processors[1].Process(control >> 4);
  74. }
  75. dac.Update();
  76. }
  77. }
  78. void Init() {
  79. sys.Init(F_CPU / 96000 - 1, true);
  80. system_clock.Init();
  81. gate_input.Init();
  82. dac.Init();
  83. processors[0].Init(0);
  84. processors[1].Init(1);
  85. ui.Init();
  86. sys.StartTimers();
  87. }
  88. int main(void) {
  89. Init();
  90. while (1) {
  91. // Faster rate than 1kHz, but no need to be faster than the buffer
  92. // fill rate.
  93. ui.PollPots();
  94. ui.DoEvents();
  95. processors[0].Buffer();
  96. processors[1].Buffer();
  97. }
  98. }