Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default: $(TARGET)
ALLTARGETS = $(filter-out common,$(notdir $(wildcard target/tx/*/*)))

# The supported transmitters
TXS ?= devo6 devo7e devo7e-256 devo8 devo10 devo12e devo12 devof7 devof7-XMS devof4 devof4-XMS devof12e devof12e-XMS at9 at10 t8sg t8sg_v2 t8sg_v2_plus ir8m
TXS ?= devo6 devo7e devo7e-256 devo8 devo10 devo12e devo12 devof7 devof7-XMS devof4 devof4-XMS devof12e devof12e-XMS at9 at10 t8sg_v1 t8sg_v2 t8sg_v2_plus ir8m

#Filter non-existant emus
EMUS = $(foreach dir,$(TXS:%=emu_%),$(if $(wildcard target/$(dir)),$(dir),))
Expand Down
31 changes: 15 additions & 16 deletions src/pages/128x64x1/tx_configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ static u16 current_selected = 0; // do not put current_selected into pagemem as
static int size_cb(int absrow, void *data)
{
(void)data;
if (absrow >= ITEM_BACKLIGHT && HAS_OLED_DISPLAY) {
// This will hide the backlight row
absrow++;
}
switch(absrow) {
#if SUPPORT_MULTI_LANGUAGE
case ITEM_LANG:
#else
case ITEM_MODE:
#endif
case ITEM_BUZZ:
#if !HAS_OLED_DISPLAY
case ITEM_BACKLIGHT:
#else
case ITEM_CONTRAST:
#endif
case ITEM_PREALERT:
case ITEM_TELEMTEMP:
return 2;
Expand All @@ -88,6 +88,10 @@ static int row_cb(int absrow, int relrow, int y, void *data)
void *but_str = NULL;
u8 x = LARGE_SEL_X_OFFSET;

if (absrow >= ITEM_BACKLIGHT && HAS_OLED_DISPLAY) {
// This will hide the backlight row
absrow++;
}
switch(absrow) {
#if SUPPORT_MULTI_LANGUAGE
case ITEM_LANG:
Expand Down Expand Up @@ -142,20 +146,15 @@ static int row_cb(int absrow, int relrow, int y, void *data)
label = _tr_noop("PwrDn alert");
value = _music_shutdown_cb; x = MED_SEL_X_OFFSET;
break;
#if !HAS_OLED_DISPLAY
case ITEM_BACKLIGHT:
title = _tr_noop("LCD settings");
label = _tr_noop("Backlight");
value = backlight_select_cb; x = SMALL_SEL_X_OFFSET;
break;
#endif
case ITEM_CONTRAST:
#if HAS_OLED_DISPLAY
title = _tr_noop("LCD settings");
#endif
label = _tr_noop("Contrast");
value = _contrast_select_cb; x = SMALL_SEL_X_OFFSET;
break;
case ITEM_BACKLIGHT:
label = _tr_noop("Backlight");
value = backlight_select_cb; x = SMALL_SEL_X_OFFSET;
break;
case ITEM_DIMTIME:
label = _tr_noop("Dimmer time");
value = auto_dimmer_time_cb; x = SMALL_SEL_X_OFFSET;
Expand Down Expand Up @@ -229,9 +228,9 @@ static const char *_contrast_select_cb(guiObject_t *obj, int dir, void *data)
0, 10, dir, 1, 1, &changed);
if (changed) {
LCD_Contrast(Transmitter.contrast);
#if HAS_OLED_DISPLAY
Transmitter.backlight = Transmitter.contrast;
#endif
if (HAS_OLED_DISPLAY) {
Transmitter.backlight = Transmitter.contrast;
}
}
if (Transmitter.contrast == 0)
return _tr("Off");
Expand Down
6 changes: 1 addition & 5 deletions src/pages/common/_tx_configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ enum {
ITEM_BATT,
ITEM_ALARM_INTV,
ITEM_PWRDN_ALARM,
#if !HAS_OLED_DISPLAY
ITEM_BACKLIGHT,
#endif
ITEM_CONTRAST,
ITEM_BACKLIGHT,
ITEM_DIMTIME,
ITEM_DIMVAL,
ITEM_PREALERT,
Expand Down Expand Up @@ -184,7 +182,6 @@ static const char *modeselect_cb(guiObject_t *obj, int dir, void *data)
return tempstring;
}

#if !HAS_OLED_DISPLAY
static const char *backlight_select_cb(guiObject_t *obj, int dir, void *data)
{
(void)data;
Expand All @@ -199,7 +196,6 @@ static const char *backlight_select_cb(guiObject_t *obj, int dir, void *data)
sprintf(tempstring, "%d", Transmitter.backlight);
return tempstring;
}
#endif

static const char *common_select_cb(guiObject_t *obj, int dir, void *data)
{
Expand Down
42 changes: 10 additions & 32 deletions src/target/drivers/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,25 @@

#include "common.h"

#if !HAS_OLED_DISPLAY
#include "target/drivers/mcu/stm32/rcc.h"
#include "target/drivers/mcu/stm32/tim.h"
#include "oled.h"
#include "lcd.h"

void BACKLIGHT_Init()
{
rcc_periph_clock_enable(get_rcc_from_pin(BACKLIGHT_TIM.pin));
GPIO_setup_input(BACKLIGHT_TIM.pin, ITYPE_FLOAT);

// Configure Backlight PWM
rcc_periph_clock_enable(get_rcc_from_port(BACKLIGHT_TIM.tim));
timer_set_mode(BACKLIGHT_TIM.tim, TIM_CR1_CKD_CK_INT,
TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
timer_set_period(BACKLIGHT_TIM.tim, 0x2CF);
timer_set_prescaler(BACKLIGHT_TIM.tim, 0);
timer_generate_event(BACKLIGHT_TIM.tim, TIM_EGR_UG);
timer_set_oc_mode(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch), TIM_OCM_PWM1);
timer_enable_oc_preload(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch));

timer_set_oc_polarity_high(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch));
timer_enable_oc_output(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch));

timer_enable_preload(BACKLIGHT_TIM.tim);
if (HAS_OLED_DISPLAY) {
_oled_backlight_init();
} else {
_lcd_backlight_init();
}
}

void BACKLIGHT_Brightness(unsigned brightness)
{
timer_disable_counter(BACKLIGHT_TIM.tim);
if (brightness == 0) {
// Turn off Backlight
GPIO_setup_input(BACKLIGHT_TIM.pin, ITYPE_FLOAT);
} else if (brightness > 9) {
// Turn on Backlight full
GPIO_setup_output(BACKLIGHT_TIM.pin, OTYPE_PUSHPULL);
GPIO_pin_set(BACKLIGHT_TIM.pin);
if (HAS_OLED_DISPLAY) {
_oled_backlight_brightness(brightness);
} else {
GPIO_setup_output_af(BACKLIGHT_TIM.pin, OTYPE_PUSHPULL, BACKLIGHT_TIM.tim);
u32 duty_cycle = 720 * brightness / 10;
timer_set_oc_value(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch), duty_cycle);
timer_enable_counter(BACKLIGHT_TIM.tim);
_lcd_backlight_brightness(brightness);
}
}

#endif // !HAS_OLED_DISPLAY
39 changes: 39 additions & 0 deletions src/target/drivers/backlight/lcd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

static void _lcd_backlight_init()
{
rcc_periph_clock_enable(get_rcc_from_pin(BACKLIGHT_TIM.pin));
GPIO_setup_input(BACKLIGHT_TIM.pin, ITYPE_FLOAT);

// Configure Backlight PWM
rcc_periph_clock_enable(get_rcc_from_port(BACKLIGHT_TIM.tim));
timer_set_mode(BACKLIGHT_TIM.tim, TIM_CR1_CKD_CK_INT,
TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
timer_set_period(BACKLIGHT_TIM.tim, 0x2CF);
timer_set_prescaler(BACKLIGHT_TIM.tim, 0);
timer_generate_event(BACKLIGHT_TIM.tim, TIM_EGR_UG);
timer_set_oc_mode(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch), TIM_OCM_PWM1);
timer_enable_oc_preload(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch));

timer_set_oc_polarity_high(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch));
timer_enable_oc_output(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch));

timer_enable_preload(BACKLIGHT_TIM.tim);
}

static void _lcd_backlight_brightness(unsigned brightness)
{
timer_disable_counter(BACKLIGHT_TIM.tim);
if (brightness == 0) {
// Turn off Backlight
GPIO_setup_input(BACKLIGHT_TIM.pin, ITYPE_FLOAT);
} else if (brightness > 9) {
// Turn on Backlight full
GPIO_setup_output(BACKLIGHT_TIM.pin, OTYPE_PUSHPULL);
GPIO_pin_set(BACKLIGHT_TIM.pin);
} else {
GPIO_setup_output_af(BACKLIGHT_TIM.pin, OTYPE_PUSHPULL, BACKLIGHT_TIM.tim);
u32 duty_cycle = 720 * brightness / 10;
timer_set_oc_value(BACKLIGHT_TIM.tim, TIM_OCx(BACKLIGHT_TIM.ch), duty_cycle);
timer_enable_counter(BACKLIGHT_TIM.tim);
}
}
28 changes: 28 additions & 0 deletions src/target/drivers/backlight/oled.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Deviation is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Deviation. If not, see <http://www.gnu.org/licenses/>.
*/

/* These are defined in 128x64x1_oled_ssd1306.h */
void OLED_Backlight();
void OLED_Backlight_Brightness(unsigned brightness);

static void _oled_backlight_init()
{
OLED_Backlight();
}

static void _oled_backlight_brightness(unsigned brightness)
{
OLED_Backlight_Brightness(brightness);
}
55 changes: 55 additions & 0 deletions src/target/drivers/display/8080/128x64x1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Deviation is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Deviation. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include "common.h"
#include "gui/gui.h"
#include "target/drivers/mcu/stm32/fsmc.h"

#define LCD_CONTRAST_FUNC(contrast) (0x20 + contrast * 0xC / 10)

#define LCD_CMD_ADDR ((uint32_t)FSMC_BANK1_BASE) /* Register Address */
#define LCD_DATA_ADDR ((uint32_t)FSMC_BANK1_BASE + 0x10000) /* Data Address */

#define LCD_CMD *(volatile uint8_t *)(LCD_CMD_ADDR)
#define LCD_DATA *(volatile uint8_t *)(LCD_DATA_ADDR)

inline static void LCD_Cmd(unsigned cmd)
{
LCD_CMD = cmd;
}

inline static void LCD_Data(unsigned data)
{
LCD_DATA = data;
}
#define LCD_CONTRAST_FUNC(contrast) (0x20 + contrast * 0xC / 10)

static void lcd_init_ports()
{
_fsmc_init(
8,
0x10000, /*only bit 16 of addr */
FSMC_NOE | FSMC_NWE | FSMC_NE1, /* Not connected */
FSMC_BANK1,
/* Normal mode, write enable, 8 bit access, SRAM, bank enabled */
FSMC_BCR_FACCEN | FSMC_BCR_WREN | FSMC_BCR_MBKEN,
/* Data Setup > 90ns, Address Setup = 2xHCLK to ensure no output collision in 6800
mode since LCD E and !CS always active */
FSMC_BTR_DATASTx(7) | FSMC_BTR_ADDHLDx(0) | FSMC_BTR_ADDSETx(2),
0);
}

#include "../spi/128x64x1_common.h"
Loading