generation.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "config.h"
  3. #include "buttons.h"
  4. #include <stdint.h>
  5. #define FXP_SCALING 4000
  6. #define DIV_ROUND(a,b) (((a)+(b)/2)/(b))
  7. static const int32_t MIN_FREQ1 = 7000;
  8. static const int32_t MAX_FREQ1 = 30000;
  9. static const int32_t MIN_FREQ3 = 1000000;
  10. static const int32_t MAX_FREQ3 = 3000000;
  11. static const int32_t MIN_D1D2 = 0.005 * FXP_SCALING;//0.5%
  12. static const int32_t MAX_D1D2 = 0.495 * FXP_SCALING;//49.5%
  13. static const int32_t MAX_PH3 = 3000;
  14. typedef enum {
  15. ENABLE_FORCE_NONE = 0,
  16. ENABLE_FORCE_ENABLE,
  17. ENABLE_FORCE_DISABLE
  18. } enable_force_t;
  19. typedef struct {
  20. uint32_t f1;//Hz
  21. uint32_t _period1;//steps
  22. uint32_t D1;//4000/100%
  23. uint32_t _duty1;//steps
  24. uint32_t D2;//4000/100%
  25. uint32_t _duty2;//steps
  26. uint32_t Ph2;//4000steps/360*
  27. uint32_t _phase2;//steps
  28. uint32_t Ph3;//4000steps/360*
  29. uint32_t f3;//Hz
  30. uint32_t _period3;//steps
  31. uint32_t D3;//*0.1%
  32. uint32_t N3;//n
  33. enable_force_t ena;
  34. } tweaked_params_s;
  35. typedef struct {
  36. union {
  37. uint32_t data[14];
  38. tweaked_params_s regs;
  39. };
  40. } tweaked_params_union_s;
  41. void init_params(tweaked_params_s * pParams);
  42. uint32_t validate_generation_values(tweaked_params_s * pParams);
  43. void update_three_signal_values(tweaked_params_s * pParams, wb_mailbox_button_regs_t * pButtons);
  44. void inc_f1(tweaked_params_s * pParams, uint32_t val);
  45. void dec_f1(tweaked_params_s * pParams, uint32_t val);