logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

muse.c (2314B)


  1. #include "muse.h"
  2. #include <stdbool.h>
  3. enum { MUSE_OFF, MUSE_ON, MUSE_C_1_2, MUSE_C1, MUSE_C2, MUSE_C4, MUSE_C8, MUSE_C3, MUSE_C6, MUSE_B1, MUSE_B2, MUSE_B3, MUSE_B4, MUSE_B5, MUSE_B6, MUSE_B7, MUSE_B8, MUSE_B9, MUSE_B10, MUSE_B11, MUSE_B12, MUSE_B13, MUSE_B14, MUSE_B15, MUSE_B16, MUSE_B17, MUSE_B18, MUSE_B19, MUSE_B20, MUSE_B21, MUSE_B22, MUSE_B23, MUSE_B24, MUSE_B25, MUSE_B26, MUSE_B27, MUSE_B28, MUSE_B29, MUSE_B30, MUSE_B31 };
  4. bool number_of_ones_to_bool[16] = {1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
  5. uint8_t muse_interval[4] = {MUSE_B7, MUSE_B19, MUSE_B3, MUSE_B28};
  6. uint8_t muse_theme[4] = {MUSE_B8, MUSE_B23, MUSE_B18, MUSE_B17};
  7. bool muse_timer_1bit = 0;
  8. uint8_t muse_timer_2bit = 0;
  9. uint8_t muse_timer_2bit_counter = 0;
  10. uint8_t muse_timer_4bit = 0;
  11. uint32_t muse_timer_31bit = 0;
  12. bool bit_for_value(uint8_t value) {
  13. switch (value) {
  14. case MUSE_OFF:
  15. return 0;
  16. case MUSE_ON:
  17. return 1;
  18. case MUSE_C_1_2:
  19. return muse_timer_1bit;
  20. case MUSE_C1:
  21. return (muse_timer_4bit & 1);
  22. case MUSE_C2:
  23. return (muse_timer_4bit & 2);
  24. case MUSE_C4:
  25. return (muse_timer_4bit & 4);
  26. case MUSE_C8:
  27. return (muse_timer_4bit & 8);
  28. case MUSE_C3:
  29. return (muse_timer_2bit & 1);
  30. case MUSE_C6:
  31. return (muse_timer_2bit & 2);
  32. default:
  33. return muse_timer_31bit & (1UL << (value - MUSE_B1));
  34. }
  35. }
  36. uint8_t muse_clock_pulse(void) {
  37. bool top = number_of_ones_to_bool[bit_for_value(muse_theme[0]) + (bit_for_value(muse_theme[1]) << 1) + (bit_for_value(muse_theme[2]) << 2) + (bit_for_value(muse_theme[3]) << 3)];
  38. if (muse_timer_1bit == 0) {
  39. if (muse_timer_2bit_counter == 0) {
  40. muse_timer_2bit = (muse_timer_2bit + 1) % 4;
  41. }
  42. muse_timer_2bit_counter = (muse_timer_2bit_counter + 1) % 3;
  43. muse_timer_4bit = (muse_timer_4bit + 1) % 16;
  44. muse_timer_31bit = (muse_timer_31bit << 1) + top;
  45. }
  46. muse_timer_1bit = (muse_timer_1bit + 1) % 2;
  47. return bit_for_value(muse_interval[0]) + (bit_for_value(muse_interval[1]) << 1) + (bit_for_value(muse_interval[2]) << 2) + (bit_for_value(muse_interval[3]) << 3);
  48. }