Merge pull request #2325 from opentx/jivarofad/M2560
LCD driver for stock and M2560
This commit is contained in:
+13
-7
@@ -57,6 +57,10 @@ PCB = 9X
|
||||
# PCB revision
|
||||
PCBREV =
|
||||
|
||||
# LCD
|
||||
# Values: DEFAULT, ST7565P, ST7565R, ERC12864FSF, ST7920
|
||||
LCD = DEFAULT
|
||||
|
||||
# Enable JETI-Telemetry or FrSky Telemetry reception on UART0
|
||||
# For this option you need to modify your hardware!
|
||||
# More information at [insertURLhere]
|
||||
@@ -696,13 +700,7 @@ ifeq ($(PCB), MEGA2560)
|
||||
BITMAPS += bitmaps/9X/splash.lbm bitmaps/9X/asterisk.lbm bitmaps/9X/about.lbm
|
||||
GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_diagkeys.cpp gui/$(GUIDIRECTORY)/menu_general_diaganas.cpp
|
||||
|
||||
# LCD driver
|
||||
# Values: ST7565P(default), ST7565R
|
||||
LCD = ST7565P
|
||||
ifeq ($(LCD), ST7565R)
|
||||
CPPDEFS += -DLCD_ST7565R
|
||||
endif
|
||||
EXTRABOARDSRC = targets/common_avr/adc_driver.cpp targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
|
||||
EXTRABOARDSRC = targets/common_avr/adc_driver.cpp targets/stock/lcd_driver.cpp targets/common_avr/telemetry_driver.cpp
|
||||
|
||||
ifeq ($(SDCARD), YES)
|
||||
EXTRABOARDSRC += $(FATFSDIR)/ff.c $(FATFSDIR)/fattime.c $(FATFSDIR)/option/ccsbcs.c targets/gruvin9x/diskio.cpp
|
||||
@@ -1087,6 +1085,14 @@ ifeq ($(TURNIGY_TRANSMITTER_FIX), YES)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(LCD), ST7565R)
|
||||
CPPDEFS += -DLCD_ST7565R
|
||||
else ifeq ($(LCD), ERC12864FSF)
|
||||
CPPDEFS += -DLCD_ERC12864FSF
|
||||
else ifeq ($(LCD), ST7920)
|
||||
CPPDEFS += -DLCD_ST7920
|
||||
endif
|
||||
|
||||
ifeq ($(AUTOSWITCH), YES)
|
||||
CPPDEFS += -DAUTOSWITCH
|
||||
endif
|
||||
|
||||
@@ -48,7 +48,7 @@ inline void boardInit()
|
||||
DDRE = 0b00000010; PORTE = 0b11111100; // 7:N/A, 6:N/A, 5:RENC1_B, 4:RENC1_A, 3:N/A, 2:N/A, 1:TELEM_TX, 0:TELEM_RX
|
||||
DDRF = 0b00000000; PORTF = 0b11111111; // 7-0:Trim switch inputs
|
||||
DDRG = 0b00000000; PORTG = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:TCut_SW, 1:Gear_SW, 0: RudDr_SW
|
||||
DDRH = 0b00011000; PORTH = 0b11110110; // 7:N/A, 6:RFPw, 5:JackPres, 4:HoldPw, 3:Speaker, 2:N/A, 1:N/A, 0:Haptic
|
||||
DDRH = 0b00011000; PORTH = 0b11110110; // 7:N/A, 6:RF_Activated, 5:DSC_Activated, 4:Hold_Pwower, 3:Speaker, 2:N/A, 1:N/A, 0:Haptic
|
||||
DDRJ = 0b00000000; PORTJ = 0b11111111; // 7:N/A, 6:N/A, 5:N/A, 4:N/A, 3:N/A, 2:N/A, 1:RENC2_push, 0:RENC1_push
|
||||
DDRK = 0b00000000; PORTK = 0b00000000; // Analogic input (no pull-ups)
|
||||
DDRL = 0b00000000; PORTL = 0b11111111; // 7:TRN_SW 6:EleDR_SW, 5:ESC, 4:MENU 3:Keyb_Left, 2:Keyb_Right, 1:Keyb_Up, 0:Keyb_Down
|
||||
@@ -98,7 +98,7 @@ uint8_t pwrCheck()
|
||||
|
||||
void pwrOff()
|
||||
{
|
||||
PORTH = 0xEF; // PortH-4 set to 0
|
||||
PORTH &= ~0x10; // PortH-4 set to 0
|
||||
}
|
||||
|
||||
FORCEINLINE uint8_t keyDown()
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
#define PAUSE_PPMIN_INTERRUPT() TIMSK3 &= ~(1<<ICIE3)
|
||||
#define RESUME_PPMIN_INTERRUPT() TIMSK3 |= (1<<ICIE3)
|
||||
|
||||
#define SLAVE_MODE() ~PINH & (1<<INP_H_RF_POW)
|
||||
#define SLAVE_MODE() ~PINH & (1<<INP_H_RF_Activated)
|
||||
#define JACK_PPM_OUT() PORTB |= (1<<OUT_B_SIM_CTL)
|
||||
#define JACK_PPM_IN() PORTB &= ~(1<<OUT_B_SIM_CTL)
|
||||
#define __BACKLIGHT_ON PORTC |= (1<<OUT_C_LIGHT)
|
||||
@@ -133,9 +133,9 @@ void sdPoll10ms(void);
|
||||
# define INP_D_I2C_SDA 0
|
||||
# define INP_E_TELEM_RX 1
|
||||
# define OUT_E_TELEM_TX 0
|
||||
# define INP_H_RF_POW 6
|
||||
//#define INP_H_ 5 //reserved JACKPRES
|
||||
//#define INP_H_ 4 //reserved HOLDPWR
|
||||
# define INP_H_RF_Activated 6
|
||||
//#define INP_H_ 5 //reserved DSC_Activated, for pwrCheck()
|
||||
//#define INP_H_ 4 //reserved Hold_Power, for pwrCheck()
|
||||
# define OUT_H_Speaker 3
|
||||
# define OUT_H_HAPTIC 0
|
||||
|
||||
|
||||
@@ -36,18 +36,11 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define delay_1us() _delay_us(1)
|
||||
#define delay_2us() _delay_us(2)
|
||||
void delay_1_5us(uint16_t ms)
|
||||
{
|
||||
for (uint16_t i=0; i<ms; i++) delay_1us();
|
||||
}
|
||||
|
||||
void lcdSendCtl(uint8_t val)
|
||||
{
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
|
||||
#ifdef LCD_MULTIPLEX
|
||||
DDRA = 0xFF; // set LCD_DAT pins to output
|
||||
DDRA = 0xFF; //Set LCD_DAT pins to output
|
||||
#endif
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_A0);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
|
||||
@@ -56,7 +49,7 @@ void lcdSendCtl(uint8_t val)
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
|
||||
#ifdef LCD_MULTIPLEX
|
||||
DDRA = 0x00; // set LCD_DAT pins to input
|
||||
DDRA = 0x00; //Set LCD_DAT pins to input
|
||||
#endif
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
|
||||
}
|
||||
@@ -72,10 +65,11 @@ volatile uint8_t LcdLock ;
|
||||
|
||||
const static pm_uchar lcdInitSequence[] PROGMEM =
|
||||
{
|
||||
#ifdef LCD_ST7565R
|
||||
//ST7565 eq. : KS0713, SED1565, S6B1713, SPLC501C, NT7532 /34 /38, TL03245
|
||||
#if defined(LCD_ST7565R)
|
||||
0xE2, //Initialize the internal functions
|
||||
0xAE, //DON = 0: display OFF
|
||||
0xA0, //ADC = 0: normal direction(SEG132->SEG1)
|
||||
0xA0, //ADC = 0: normal direction (SEG132->SEG1)
|
||||
0xA6, //REV = 0: non-reverse display
|
||||
0xA4, //EON = 0: normal display. non-entire
|
||||
0xA2, //Select LCD bias
|
||||
@@ -85,11 +79,11 @@ const static pm_uchar lcdInitSequence[] PROGMEM =
|
||||
0x81, //Set reference voltage Mode
|
||||
0x22, //24 SV5 SV4 SV3 SV2 SV1 SV0 = 0x18
|
||||
0xAF, //DON = 1: display ON
|
||||
0x60 //sets the display start line to zero
|
||||
#elif LCD_ERC12864FSF
|
||||
0x60 //Set the display start line to zero
|
||||
#elif defined(LCD_ERC12864FSF)
|
||||
0xE2, //Initialize the internal functions
|
||||
0xAE, //DON = 0: display OFF
|
||||
0xA1, //ADC = 1: reverse direction(SEG132->SEG1)
|
||||
0xA1, //ADC = 1: reverse direction (SEG132->SEG1)
|
||||
0xA6, //REV = 0: non-reverse display
|
||||
0xA4, //EON = 0: normal display. non-entire
|
||||
0xA3, //Select LCD bias
|
||||
@@ -99,7 +93,13 @@ const static pm_uchar lcdInitSequence[] PROGMEM =
|
||||
0x81, //Set reference voltage Mode
|
||||
0x2D, //24 SV5 SV4 SV3 SV2 SV1 SV0
|
||||
0xAF //DON = 1: display ON
|
||||
#else
|
||||
#elif defined(LCD_ST7920)
|
||||
0x30, //Set 8-bit interface
|
||||
0x36, //Repeat with graphics bit set to ON
|
||||
0x0C, //Display ON, cursor and blink OFF
|
||||
0x01, //Clear display, reset address
|
||||
0x06 //Display ON, no cursor
|
||||
#else //ST7565P (default 9x LCD)
|
||||
0xE2, //Initialize the internal functions
|
||||
0xAE, //DON = 0: display OFF
|
||||
0xA1, //ADC = 1: reverse direction(SEG132->SEG1)
|
||||
@@ -117,62 +117,104 @@ const static pm_uchar lcdInitSequence[] PROGMEM =
|
||||
|
||||
inline void lcdInit()
|
||||
{
|
||||
// /home/thus/txt/datasheets/lcd/KS0713.pdf
|
||||
// ~/txt/flieger/ST7565RV17.pdf from http://www.glyn.de/content.asp?wdid=132&sid=
|
||||
|
||||
LCD_LOCK();
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD_RES
|
||||
delay_2us();
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); // f524 sbi 0x15, 2 IOADR-PORTC_LCD_CTRL; 21 1
|
||||
delay_1_5us(1500);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RES); //LCD reset
|
||||
_delay_us(2);
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_RES); //LCD normal operation
|
||||
#ifdef LCD_ST7920
|
||||
_delay_ms(40);
|
||||
#else
|
||||
_delay_us(1500);
|
||||
#endif
|
||||
for (uint8_t i=0; i<DIM(lcdInitSequence); i++) {
|
||||
lcdSendCtl(pgm_read_byte(&lcdInitSequence[i])) ;
|
||||
#ifdef LCD_ST7920
|
||||
_delay_us(80);
|
||||
#endif
|
||||
}
|
||||
#ifdef LCD_ERC12864FSF
|
||||
g_eeGeneral.contrast = 0x2D;
|
||||
#else
|
||||
g_eeGeneral.contrast = 0x22;
|
||||
#endif
|
||||
#ifdef LCD_ERC12864FSF
|
||||
g_eeGeneral.contrast = 0x2D;
|
||||
#else
|
||||
g_eeGeneral.contrast = 0x22;
|
||||
#endif
|
||||
LCD_UNLOCK();
|
||||
}
|
||||
|
||||
void lcdSetRefVolt(uint8_t val)
|
||||
{
|
||||
LCD_LOCK();
|
||||
lcdSendCtl(0x81);
|
||||
lcdSendCtl(val);
|
||||
LCD_UNLOCK();
|
||||
#ifndef LCD_ST7920 //No contrast setting for ST7920
|
||||
LCD_LOCK();
|
||||
lcdSendCtl(0x81);
|
||||
lcdSendCtl(val);
|
||||
LCD_UNLOCK();
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcdRefresh()
|
||||
{
|
||||
LCD_LOCK();
|
||||
#ifdef LCD_ST7920
|
||||
uint8_t x_addr = 0;
|
||||
uint8_t y_addr = 0;
|
||||
uint16_t line_offset = 0;
|
||||
uint8_t col_offset = 0;
|
||||
uint16_t byte_offset = 0;
|
||||
uint8_t bit_count = 0;
|
||||
for(uint8_t y=0; y < 64; y++) {
|
||||
x_addr = 0;
|
||||
//Convert coordinates to weirdly-arranged 128x64 screen (the ST7920 is mapped for 256x32 displays)
|
||||
if (y > 31)
|
||||
{
|
||||
y_addr = y - 32; //Because there are only 31 addressable lines in the ST7920
|
||||
x_addr += 8; //so we overflow x (7 visible bytes per line) to reach the bottom half
|
||||
}else{
|
||||
y_addr = y;
|
||||
}
|
||||
lcdSendCtl( 0x80 | y_addr ); //Set Vertical Address
|
||||
_delay_us(49);
|
||||
lcdSendCtl( 0x80 | x_addr ); //Set Horizontal Address
|
||||
_delay_us(49);
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0); //HIGH RS and LOW RW will put the LCD to
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW); //Write data register mode
|
||||
bit_count = y & 0x07; //Count from 0 bis 7 -> 0=0, 1=1..7=7, 8=0, 9=1...
|
||||
col_offset = 1 << bit_count; //Build a value for a AND operation with the vorrect bitposition
|
||||
line_offset = ( y / 8 ) * 128; //On the ST7565 there are 8 lines with each 128 bytes width
|
||||
for (coord_t x=0; x < 16; x++) { //Walk through 16 bytes form left to right (128 Pixel)
|
||||
byte_offset = line_offset + ( x * 8 ); //Calculate the position of the first byte im array
|
||||
//adressing the bytes sequential and shift the bits at the correct position, afterwards a OR operation to get all bits in one byte
|
||||
//the position of the LSB is the left-most position of the byte to the ST7920
|
||||
PORTA_LCD_DAT = (((displayBuf[byte_offset] & col_offset) >> bit_count) << 7) | (((displayBuf[byte_offset + 1] & col_offset) >> bit_count) << 6) | (((displayBuf[byte_offset + 2] & col_offset) >> bit_count ) << 5) | (((displayBuf[byte_offset + 3] & col_offset) >> bit_count ) << 4) | (((displayBuf[byte_offset + 4] & col_offset) >> bit_count ) << 3) | (((displayBuf[byte_offset + 5] & col_offset) >> bit_count ) << 2) | (((displayBuf[byte_offset + 6] & col_offset) >> bit_count ) << 1) | (((displayBuf[byte_offset + 7] & col_offset) >> bit_count ) << 0);
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
|
||||
_delay_us(8);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
|
||||
_delay_us(49);
|
||||
}
|
||||
}
|
||||
#else //All other LCD
|
||||
uint8_t *p=displayBuf;
|
||||
for(uint8_t y=0; y < 8; y++) {
|
||||
|
||||
#ifdef LCD_ST7565R
|
||||
lcdSendCtl(0x01);
|
||||
#else
|
||||
lcdSendCtl(0x04);
|
||||
#endif
|
||||
|
||||
lcdSendCtl(0x10); //column addr 0
|
||||
lcdSendCtl( y | 0xB0); //page addr y
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
|
||||
#ifdef LCD_MULTIPLEX
|
||||
DDRA = 0xFF; // set LCD_DAT pins to output
|
||||
#endif
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
|
||||
for (coord_t x=LCD_W; x>0; --x) {
|
||||
PORTA_LCD_DAT = *p++;
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
|
||||
}
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
|
||||
for(uint8_t y=0; y < 8; y++) {
|
||||
#ifdef LCD_ST7565R
|
||||
lcdSendCtl(0x01);
|
||||
#else
|
||||
lcdSendCtl(0x04);
|
||||
#endif
|
||||
lcdSendCtl(0x10); //Column addr 0
|
||||
lcdSendCtl( y | 0xB0); //Page addr y
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_CS1);
|
||||
#ifdef LCD_MULTIPLEX
|
||||
DDRA = 0xFF; //Set LCD_DAT pins to output
|
||||
#endif
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_RnW);
|
||||
for (coord_t x=LCD_W; x>0; --x) {
|
||||
PORTA_LCD_DAT = *p++;
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_E);
|
||||
PORTC_LCD_CTRL &= ~(1<<OUT_C_LCD_E);
|
||||
}
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_A0);
|
||||
PORTC_LCD_CTRL |= (1<<OUT_C_LCD_CS1);
|
||||
}
|
||||
#endif
|
||||
LCD_UNLOCK();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user