4 #include "serial_link/system/serial_link.h"
5 #ifdef VISUALIZER_ENABLE
6 #include "lcd_backlight.h"
9 void init_serial_link_hal(void) {
10 PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
11 PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2);
12 PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
13 PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
19 #define CHANNEL_RED FTM0->CHANNEL[0]
20 #define CHANNEL_GREEN FTM0->CHANNEL[1]
21 #define CHANNEL_BLUE FTM0->CHANNEL[2]
23 #define RGB_PORT PORTC
24 #define RGB_PORT_GPIO GPIOC
26 // Base FTM clock selection (72 MHz system clock)
27 // @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period
28 // Higher pre-scalar will use the most power (also look the best)
29 // Pre-scalar calculations
30 // 0 - 72 MHz -> 549 Hz
31 // 1 - 36 MHz -> 275 Hz
32 // 2 - 18 MHz -> 137 Hz
33 // 3 - 9 MHz -> 69 Hz (Slightly visible flicker)
34 // 4 - 4 500 kHz -> 34 Hz (Visible flickering)
35 // 5 - 2 250 kHz -> 17 Hz
36 // 6 - 1 125 kHz -> 9 Hz
37 // 7 - 562 500 Hz -> 4 Hz
38 // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced
39 // Which will reduce the brightness range
40 #define PRESCALAR_DEFINE 0
41 #ifdef VISUALIZER_ENABLE
42 void lcd_backlight_hal_init(void) {
44 SIM->SCGC6 |= SIM_SCGC6_FTM0;
45 FTM0->CNT = 0; // Reset counter
51 // Set FTM to PWM output - Edge Aligned, Low-true pulses
52 #define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0)
53 CHANNEL_RED.CnSC = CNSC_MODE;
54 CHANNEL_GREEN.CnSC = CNSC_MODE;
55 CHANNEL_BLUE.CnSC = CNSC_MODE;
57 // System clock, /w prescalar setting
58 FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
61 CHANNEL_GREEN.CnV = 0;
64 RGB_PORT_GPIO->PDDR |= (1 << RED_PIN);
65 RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN);
66 RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN);
68 #define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4)
69 RGB_PORT->PCR[RED_PIN] = RGB_MODE;
70 RGB_PORT->PCR[GREEN_PIN] = RGB_MODE;
71 RGB_PORT->PCR[BLUE_PIN] = RGB_MODE;
74 void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
76 CHANNEL_GREEN.CnV = g;
81 __attribute__ ((weak))
82 void matrix_init_user(void) {
85 __attribute__ ((weak))
86 void matrix_scan_user(void) {
90 void matrix_init_kb(void) {
91 // put your keyboard start-up code here
92 // runs once when the firmware starts up
97 void matrix_scan_kb(void) {
98 // put your looping keyboard code here
99 // runs every cycle (a lot)
104 void ergodox_board_led_on(void){
107 void ergodox_right_led_1_on(void){
110 void ergodox_right_led_2_on(void){
113 void ergodox_right_led_3_on(void){
116 void ergodox_right_led_on(uint8_t led){
119 void ergodox_board_led_off(void){
122 void ergodox_right_led_1_off(void){
125 void ergodox_right_led_2_off(void){
128 void ergodox_right_led_3_off(void){
131 void ergodox_right_led_off(uint8_t led){