Experimental implement SoftPWM for GH60
This commit is contained in:
parent
41182d2b35
commit
61051c74ee
@ -139,6 +139,7 @@ USB_6KRO_ENABLE = yes # USB 6key Rollover
|
|||||||
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
|
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
|
||||||
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
|
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
|
||||||
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
|
KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
|
||||||
|
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight
|
||||||
BREATHING_LED_ENABLE = yes # Enable breathing backlight
|
BREATHING_LED_ENABLE = yes # Enable breathing backlight
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include "backlight.h"
|
#include "backlight.h"
|
||||||
|
#ifdef SOFTPWM_LED_ENABLE
|
||||||
|
#include "softpwm_led.h"
|
||||||
|
#else
|
||||||
#include "breathing_led.h"
|
#include "breathing_led.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BACKLIGHT_ENABLE
|
#ifdef BACKLIGHT_ENABLE
|
||||||
|
|
||||||
@ -27,12 +31,14 @@ void backlight_enable(void);
|
|||||||
void backlight_disable(void);
|
void backlight_disable(void);
|
||||||
inline void backlight_set_raw(uint8_t raw);
|
inline void backlight_set_raw(uint8_t raw);
|
||||||
|
|
||||||
|
#ifndef SOFTPWM_LED_ENABLE
|
||||||
#ifdef GH60_REV_CHN
|
#ifdef GH60_REV_CHN
|
||||||
#else
|
#else
|
||||||
#define SOFTPWM_TIMER_TOP F_CPU/(256*64)
|
#define SOFTPWM_TIMER_TOP F_CPU/(256*64)
|
||||||
uint8_t softpwm_ocr = 0;
|
uint8_t softpwm_ocr = 0;
|
||||||
uint8_t softpwm_ocr_buff = 0;
|
uint8_t softpwm_ocr_buff = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static const uint8_t backlight_table[] PROGMEM = {
|
static const uint8_t backlight_table[] PROGMEM = {
|
||||||
0, 16, 128, 255
|
0, 16, 128, 255
|
||||||
@ -44,6 +50,16 @@ static const uint8_t backlight_table[] PROGMEM = {
|
|||||||
*/
|
*/
|
||||||
void backlight_enable(void)
|
void backlight_enable(void)
|
||||||
{
|
{
|
||||||
|
#ifdef SOFTPWM_LED_ENABLE
|
||||||
|
#if defined(GH60_REV_CHN)
|
||||||
|
DDRB |= (1<<PB6);
|
||||||
|
PORTB &= ~(1<<PB6);
|
||||||
|
#else
|
||||||
|
DDRF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
||||||
|
PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
||||||
|
#endif
|
||||||
|
softpwm_led_enable();
|
||||||
|
#else
|
||||||
#if defined(GH60_REV_CHN)
|
#if defined(GH60_REV_CHN)
|
||||||
// Turn on PWM
|
// Turn on PWM
|
||||||
DDRB |= (1<<PB6);
|
DDRB |= (1<<PB6);
|
||||||
@ -62,10 +78,19 @@ void backlight_enable(void)
|
|||||||
TIMSK1 |= (1<<OCIE1A);
|
TIMSK1 |= (1<<OCIE1A);
|
||||||
sei();
|
sei();
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void backlight_disable(void)
|
void backlight_disable(void)
|
||||||
{
|
{
|
||||||
|
#ifdef SOFTPWM_LED_ENABLE
|
||||||
|
softpwm_led_disable();
|
||||||
|
#if defined(GH60_REV_CHN)
|
||||||
|
DDRB &= ~(1<<PB6);
|
||||||
|
#else
|
||||||
|
DDRF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
#if defined(GH60_REV_CHN)
|
#if defined(GH60_REV_CHN)
|
||||||
// Turn off PWM
|
// Turn off PWM
|
||||||
cli();
|
cli();
|
||||||
@ -75,7 +100,7 @@ void backlight_disable(void)
|
|||||||
sei();
|
sei();
|
||||||
OCR1B = 0;
|
OCR1B = 0;
|
||||||
#else
|
#else
|
||||||
DDRF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
DDRF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
||||||
cli();
|
cli();
|
||||||
TCCR1B &= ~(1<<WGM12);
|
TCCR1B &= ~(1<<WGM12);
|
||||||
TCCR1B &= ~(1<<CS10);
|
TCCR1B &= ~(1<<CS10);
|
||||||
@ -83,6 +108,7 @@ void backlight_disable(void)
|
|||||||
sei();
|
sei();
|
||||||
OCR1A = 0;
|
OCR1A = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void backlight_set(uint8_t level)
|
void backlight_set(uint8_t level)
|
||||||
@ -120,22 +146,52 @@ void backlight_set(uint8_t level)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SOFTPWM_LED_ENABLE
|
||||||
#ifdef BREATHING_LED_ENABLE
|
#ifdef BREATHING_LED_ENABLE
|
||||||
void breathing_led_set_raw(uint8_t raw)
|
void breathing_led_set_raw(uint8_t raw)
|
||||||
{
|
{
|
||||||
backlight_set_raw(raw);
|
backlight_set_raw(raw);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
inline void backlight_set_raw(uint8_t raw)
|
inline void backlight_set_raw(uint8_t raw)
|
||||||
{
|
{
|
||||||
|
#ifdef SOFTPWM_LED_ENABLE
|
||||||
|
softpwm_led_set(raw);
|
||||||
|
#else
|
||||||
#if defined(GH60_REV_CHN)
|
#if defined(GH60_REV_CHN)
|
||||||
OCR1B = raw;
|
OCR1B = raw;
|
||||||
#else
|
#else
|
||||||
softpwm_ocr_buff = raw;
|
softpwm_ocr_buff = raw;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SOFTPWM_LED_ENABLE
|
||||||
|
|
||||||
|
void softpwm_led_on(void)
|
||||||
|
{
|
||||||
|
#if defined(GH60_REV_CHN)
|
||||||
|
PORTB |= (1<<PB6);
|
||||||
|
#else
|
||||||
|
PORTF &= ~(1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void softpwm_led_off(void)
|
||||||
|
{
|
||||||
|
#if defined(GH60_REV_CHN)
|
||||||
|
PORTB &= ~(1<<PB6);
|
||||||
|
#else
|
||||||
|
PORTF |= (1<<PF7 | 1<<PF6 | 1<<PF5 | 1<<PF4);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SOFTPWM_LED_ENABLE
|
||||||
#if defined(GH60_REV_CHN)
|
#if defined(GH60_REV_CHN)
|
||||||
#else
|
#else
|
||||||
ISR(TIMER1_COMPA_vect)
|
ISR(TIMER1_COMPA_vect)
|
||||||
@ -155,5 +211,6 @@ ISR(TIMER1_COMPA_vect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user