drone.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <stdint.h>
  2. #include "system.h"
  3. #include "display.h"
  4. #include "systick.h"
  5. #include "button.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include "unicore-mx/stm32/gpio.h"
  10. #include "unicore-mx/stm32/rcc.h"
  11. #include "ui.h"
  12. #include "timer.h"
  13. #include "led.h"
  14. #include "drone.h"
  15. #include "drums.h"
  16. #include "pot.h"
  17. #include "settings.h"
  18. #define MUTE { 0 , 0 }
  19. void drone_mute(void)
  20. {
  21. pot_set(0, 0);
  22. pot_set(1, 0);
  23. gpio_clear(GPIOE, GPIO2);
  24. gpio_clear(GPIOE, GPIO3);
  25. }
  26. void drone_beat(int pattern_pos)
  27. {
  28. static int test_lfo_step = 0;
  29. static int test_lfo = 0;
  30. int lfo_depth = 80;
  31. int lfo_rate = 7;
  32. int lfo_step = 2;
  33. int tgt_env;
  34. static struct drone_slot *pattern;
  35. struct drone_slot *key;
  36. pattern = Settings->drone[Settings->current_pattern].data;
  37. key = &pattern[pattern_pos];
  38. if ((key->pitch == 0) && (key->env == 0)) {
  39. pot_set(0, 99);
  40. pot_set(1, 0);
  41. gpio_clear(GPIOE, GPIO2);
  42. gpio_clear(GPIOE, GPIO3);
  43. return;
  44. }
  45. pot_set(0, 0);
  46. pot_set(1, 99);
  47. gpio_set(GPIOE, GPIO2);
  48. gpio_set(GPIOE, GPIO3);
  49. if ((pattern_pos % lfo_step) == 0) {
  50. if (test_lfo_step == 0) {
  51. test_lfo+=lfo_rate;
  52. if (test_lfo > lfo_depth)
  53. test_lfo_step = 1;
  54. } else {
  55. test_lfo-=lfo_rate;
  56. if (test_lfo < (0 - lfo_depth))
  57. test_lfo_step = 0;
  58. }
  59. }
  60. tgt_env = key->env + test_lfo;
  61. if (tgt_env < 0) {
  62. tgt_env = 0;
  63. test_lfo_step = 0;
  64. }
  65. if (tgt_env > 99) {
  66. tgt_env = 99;
  67. test_lfo_step = 1;
  68. }
  69. pot_set(0, key->pitch);
  70. pot_set(1, tgt_env);
  71. }
  72. #define TRIG_PIN (GPIO2 | GPIO3)
  73. void drone_init(void)
  74. {
  75. rcc_periph_clock_enable(RCC_GPIOE);
  76. gpio_mode_setup(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TRIG_PIN);
  77. gpio_set_output_options(GPIOE, GPIO_OTYPE_OD, GPIO_OSPEED_100MHZ, TRIG_PIN);
  78. gpio_clear(GPIOE, TRIG_PIN);
  79. }