infinity.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "infinity.h"
  2. #include "ch.h"
  3. #include "hal.h"
  4. #include "serial_link/system/serial_link.h"
  5. #ifdef VISUALIZER_ENABLE
  6. #include "lcd_backlight.h"
  7. #endif
  8. void init_serial_link_hal(void) {
  9. PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
  10. PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2);
  11. PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
  12. PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
  13. }
  14. #define RED_PIN 1
  15. #define GREEN_PIN 2
  16. #define BLUE_PIN 3
  17. #define CHANNEL_RED FTM0->CHANNEL[0]
  18. #define CHANNEL_GREEN FTM0->CHANNEL[1]
  19. #define CHANNEL_BLUE FTM0->CHANNEL[2]
  20. #define RGB_PORT PORTC
  21. #define RGB_PORT_GPIO GPIOC
  22. // Base FTM clock selection (72 MHz system clock)
  23. // @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period
  24. // Higher pre-scalar will use the most power (also look the best)
  25. // Pre-scalar calculations
  26. // 0 - 72 MHz -> 549 Hz
  27. // 1 - 36 MHz -> 275 Hz
  28. // 2 - 18 MHz -> 137 Hz
  29. // 3 - 9 MHz -> 69 Hz (Slightly visible flicker)
  30. // 4 - 4 500 kHz -> 34 Hz (Visible flickering)
  31. // 5 - 2 250 kHz -> 17 Hz
  32. // 6 - 1 125 kHz -> 9 Hz
  33. // 7 - 562 500 Hz -> 4 Hz
  34. // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced
  35. // Which will reduce the brightness range
  36. #define PRESCALAR_DEFINE 0
  37. #ifdef VISUALIZER_ENABLE
  38. void lcd_backlight_hal_init(void) {
  39. // Setup Backlight
  40. SIM->SCGC6 |= SIM_SCGC6_FTM0;
  41. FTM0->CNT = 0; // Reset counter
  42. // PWM Period
  43. // 16-bit maximum
  44. FTM0->MOD = 0xFFFF;
  45. // Set FTM to PWM output - Edge Aligned, Low-true pulses
  46. #define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0)
  47. CHANNEL_RED.CnSC = CNSC_MODE;
  48. CHANNEL_GREEN.CnSC = CNSC_MODE;
  49. CHANNEL_BLUE.CnSC = CNSC_MODE;
  50. // System clock, /w prescalar setting
  51. FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
  52. CHANNEL_RED.CnV = 0;
  53. CHANNEL_GREEN.CnV = 0;
  54. CHANNEL_BLUE.CnV = 0;
  55. RGB_PORT_GPIO->PDDR |= (1 << RED_PIN);
  56. RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN);
  57. RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN);
  58. #define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4)
  59. RGB_PORT->PCR[RED_PIN] = RGB_MODE;
  60. RGB_PORT->PCR[GREEN_PIN] = RGB_MODE;
  61. RGB_PORT->PCR[BLUE_PIN] = RGB_MODE;
  62. }
  63. void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
  64. CHANNEL_RED.CnV = r;
  65. CHANNEL_GREEN.CnV = g;
  66. CHANNEL_BLUE.CnV = b;
  67. }
  68. #endif
  69. __attribute__ ((weak))
  70. void matrix_init_user(void) {
  71. }
  72. __attribute__ ((weak))
  73. void matrix_scan_user(void) {
  74. }
  75. void matrix_init_kb(void) {
  76. // put your keyboard start-up code here
  77. // runs once when the firmware starts up
  78. matrix_init_user();
  79. }
  80. void matrix_scan_kb(void) {
  81. // put your looping keyboard code here
  82. // runs every cycle (a lot)
  83. matrix_scan_user();
  84. }
  85. void ergodox_board_led_on(void){
  86. }
  87. void ergodox_right_led_1_on(void){
  88. }
  89. void ergodox_right_led_2_on(void){
  90. }
  91. void ergodox_right_led_3_on(void){
  92. }
  93. void ergodox_right_led_on(uint8_t led){
  94. }
  95. void ergodox_board_led_off(void){
  96. }
  97. void ergodox_right_led_1_off(void){
  98. }
  99. void ergodox_right_led_2_off(void){
  100. }
  101. void ergodox_right_led_3_off(void){
  102. }
  103. void ergodox_right_led_off(uint8_t led){
  104. }
  105. #ifdef ONEHAND_ENABLE
  106. __attribute__ ((weak))
  107. const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
  108. {{0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}},
  109. {{0, 10}, {1, 10}, {2, 10}, {3, 10}, {4, 10}},
  110. {{0, 11}, {1, 11}, {2, 11}, {3, 11}, {4, 11}},
  111. {{0, 12}, {1, 12}, {2, 12}, {3, 12}, {4, 12}},
  112. {{0, 13}, {1, 13}, {2, 13}, {3, 13}, {4, 13}},
  113. {{0, 14}, {1, 14}, {2, 14}, {3, 14}, {4, 14}},
  114. {{0, 15}, {1, 15}, {2, 15}, {3, 15}, {4, 15}},
  115. {{0, 16}, {1, 16}, {2, 16}, {3, 16}, {4, 16}},
  116. {{0, 17}, {1, 17}, {2, 17}, {3, 17}, {4, 17}},
  117. {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}},
  118. {{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}},
  119. {{0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}},
  120. {{0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}},
  121. {{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}},
  122. {{0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}},
  123. {{0, 6}, {1, 6}, {2, 6}, {3, 6}, {4, 6}},
  124. {{0, 7}, {1, 7}, {2, 7}, {3, 7}, {4, 7}},
  125. {{0, 8}, {1, 8}, {2, 8}, {3, 8}, {4, 8}},
  126. };
  127. #endif