aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/infinity_ergodox/infinity_ergodox.c65
-rw-r--r--keyboards/infinity_ergodox/lcd_backlight_hal.c84
-rw-r--r--quantum/visualizer/visualizer.mk3
3 files changed, 65 insertions, 87 deletions
diff --git a/keyboards/infinity_ergodox/infinity_ergodox.c b/keyboards/infinity_ergodox/infinity_ergodox.c
index 85054775e..87ed40fab 100644
--- a/keyboards/infinity_ergodox/infinity_ergodox.c
+++ b/keyboards/infinity_ergodox/infinity_ergodox.c
@@ -2,6 +2,7 @@
2#include "ch.h" 2#include "ch.h"
3#include "hal.h" 3#include "hal.h"
4#include "serial_link/system/serial_link.h" 4#include "serial_link/system/serial_link.h"
5#include "lcd_backlight.h"
5 6
6void init_serial_link_hal(void) { 7void init_serial_link_hal(void) {
7 PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2); 8 PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
@@ -9,3 +10,67 @@ void init_serial_link_hal(void) {
9 PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3); 10 PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
10 PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3); 11 PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
11} 12}
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
21#define RGB_PORT PORTC
22#define RGB_PORT_GPIO GPIOC
23
24// Base FTM clock selection (72 MHz system clock)
25// @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period
26// Higher pre-scalar will use the most power (also look the best)
27// Pre-scalar calculations
28// 0 - 72 MHz -> 549 Hz
29// 1 - 36 MHz -> 275 Hz
30// 2 - 18 MHz -> 137 Hz
31// 3 - 9 MHz -> 69 Hz (Slightly visible flicker)
32// 4 - 4 500 kHz -> 34 Hz (Visible flickering)
33// 5 - 2 250 kHz -> 17 Hz
34// 6 - 1 125 kHz -> 9 Hz
35// 7 - 562 500 Hz -> 4 Hz
36// Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced
37// Which will reduce the brightness range
38#define PRESCALAR_DEFINE 0
39
40void lcd_backlight_hal_init(void) {
41 // Setup Backlight
42 SIM->SCGC6 |= SIM_SCGC6_FTM0;
43 FTM0->CNT = 0; // Reset counter
44
45 // PWM Period
46 // 16-bit maximum
47 FTM0->MOD = 0xFFFF;
48
49 // Set FTM to PWM output - Edge Aligned, Low-true pulses
50#define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0)
51 CHANNEL_RED.CnSC = CNSC_MODE;
52 CHANNEL_GREEN.CnSC = CNSC_MODE;
53 CHANNEL_BLUE.CnSC = CNSC_MODE;
54
55 // System clock, /w prescalar setting
56 FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
57
58 CHANNEL_RED.CnV = 0;
59 CHANNEL_GREEN.CnV = 0;
60 CHANNEL_BLUE.CnV = 0;
61
62 RGB_PORT_GPIO->PDDR |= (1 << RED_PIN);
63 RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN);
64 RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN);
65
66#define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4)
67 RGB_PORT->PCR[RED_PIN] = RGB_MODE;
68 RGB_PORT->PCR[GREEN_PIN] = RGB_MODE;
69 RGB_PORT->PCR[BLUE_PIN] = RGB_MODE;
70}
71
72void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
73 CHANNEL_RED.CnV = r;
74 CHANNEL_GREEN.CnV = g;
75 CHANNEL_BLUE.CnV = b;
76}
diff --git a/keyboards/infinity_ergodox/lcd_backlight_hal.c b/keyboards/infinity_ergodox/lcd_backlight_hal.c
deleted file mode 100644
index 05fc810b4..000000000
--- a/keyboards/infinity_ergodox/lcd_backlight_hal.c
+++ /dev/null
@@ -1,84 +0,0 @@
1/*
2Copyright 2016 Fred Sundvik <fsundvik@gmail.com>
3Jun Wako <wakojun@gmail.com>
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "lcd_backlight.h"
19#include "hal.h"
20
21#define RED_PIN 1
22#define GREEN_PIN 2
23#define BLUE_PIN 3
24#define CHANNEL_RED FTM0->CHANNEL[0]
25#define CHANNEL_GREEN FTM0->CHANNEL[1]
26#define CHANNEL_BLUE FTM0->CHANNEL[2]
27
28#define RGB_PORT PORTC
29#define RGB_PORT_GPIO GPIOC
30
31// Base FTM clock selection (72 MHz system clock)
32// @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period
33// Higher pre-scalar will use the most power (also look the best)
34// Pre-scalar calculations
35// 0 - 72 MHz -> 549 Hz
36// 1 - 36 MHz -> 275 Hz
37// 2 - 18 MHz -> 137 Hz
38// 3 - 9 MHz -> 69 Hz (Slightly visible flicker)
39// 4 - 4 500 kHz -> 34 Hz (Visible flickering)
40// 5 - 2 250 kHz -> 17 Hz
41// 6 - 1 125 kHz -> 9 Hz
42// 7 - 562 500 Hz -> 4 Hz
43// Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced
44// Which will reduce the brightness range
45#define PRESCALAR_DEFINE 0
46
47void lcd_backlight_hal_init(void) {
48 // Setup Backlight
49 SIM->SCGC6 |= SIM_SCGC6_FTM0;
50 FTM0->CNT = 0; // Reset counter
51
52 // PWM Period
53 // 16-bit maximum
54 FTM0->MOD = 0xFFFF;
55
56 // Set FTM to PWM output - Edge Aligned, Low-true pulses
57#define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0)
58 CHANNEL_RED.CnSC = CNSC_MODE;
59 CHANNEL_GREEN.CnSC = CNSC_MODE;
60 CHANNEL_BLUE.CnSC = CNSC_MODE;
61
62 // System clock, /w prescalar setting
63 FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
64
65 CHANNEL_RED.CnV = 0;
66 CHANNEL_GREEN.CnV = 0;
67 CHANNEL_BLUE.CnV = 0;
68
69 RGB_PORT_GPIO->PDDR |= (1 << RED_PIN);
70 RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN);
71 RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN);
72
73#define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4)
74 RGB_PORT->PCR[RED_PIN] = RGB_MODE;
75 RGB_PORT->PCR[GREEN_PIN] = RGB_MODE;
76 RGB_PORT->PCR[BLUE_PIN] = RGB_MODE;
77}
78
79void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
80 CHANNEL_RED.CnV = r;
81 CHANNEL_GREEN.CnV = g;
82 CHANNEL_BLUE.CnV = b;
83}
84
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk
index 379496fb6..449957d63 100644
--- a/quantum/visualizer/visualizer.mk
+++ b/quantum/visualizer/visualizer.mk
@@ -34,9 +34,6 @@ endif
34 34
35ifdef LCD_BACKLIGHT_ENABLE 35ifdef LCD_BACKLIGHT_ENABLE
36SRC += $(VISUALIZER_DIR)/lcd_backlight.c 36SRC += $(VISUALIZER_DIR)/lcd_backlight.c
37ifndef EMULATOR
38SRC += lcd_backlight_hal.c
39endif
40OPT_DEFS += -DLCD_BACKLIGHT_ENABLE 37OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
41endif 38endif
42 39