Merge pull request #297 from PavelSindler/second_serial
Turn on second serial line from settings menu
This commit is contained in:
commit
303d9468ff
8 changed files with 68 additions and 23 deletions
|
@ -82,6 +82,7 @@
|
|||
#define EEPROM_DIR_DEPTH (EEPROM_POWER_COUNT-1)
|
||||
#define EEPROM_DIRS (EEPROM_DIR_DEPTH-80) //8 chars for each dir name, max 10 levels
|
||||
#define EEPROM_SD_SORT (EEPROM_DIRS - 1) //0 -time, 1-alpha, 2-none
|
||||
#define EEPROM_SECOND_SERIAL_ACTIVE (EEPROM_SD_SORT - 1)
|
||||
|
||||
//TMC2130 configuration
|
||||
#define EEPROM_TMC_AXIS_SIZE //axis configuration block size
|
||||
|
|
|
@ -67,17 +67,17 @@ FORCE_INLINE void store_char(unsigned char c)
|
|||
}
|
||||
}
|
||||
#ifndef SNMM
|
||||
SIGNAL(USART2_RX_vect)
|
||||
SIGNAL(USART1_RX_vect)
|
||||
{
|
||||
if (selectedSerialPort == 1) {
|
||||
// Test for a framing error.
|
||||
if (UCSR2A & (1<<FE2)) {
|
||||
if (UCSR1A & (1<<FE1)) {
|
||||
// Characters received with the framing errors will be ignored.
|
||||
// Dummy register read (discard)
|
||||
(void)(*(char *)UDR2);
|
||||
(void)(*(char *)UDR1);
|
||||
} else {
|
||||
// Read the input register.
|
||||
unsigned char c = UDR2;
|
||||
unsigned char c = UDR1;
|
||||
store_char(c);
|
||||
|
||||
}
|
||||
|
@ -129,20 +129,20 @@ void MarlinSerial::begin(long baud)
|
|||
|
||||
if (selectedSerialPort == 1) { //set up also the second serial port
|
||||
if (useU2X) {
|
||||
UCSR2A = 1 << U2X2;
|
||||
UCSR1A = 1 << U2X1;
|
||||
baud_setting = (F_CPU / 4 / baud - 1) / 2;
|
||||
} else {
|
||||
UCSR2A = 0;
|
||||
UCSR1A = 0;
|
||||
baud_setting = (F_CPU / 8 / baud - 1) / 2;
|
||||
}
|
||||
|
||||
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
|
||||
UBRR2H = baud_setting >> 8;
|
||||
UBRR2L = baud_setting;
|
||||
UBRR1H = baud_setting >> 8;
|
||||
UBRR1L = baud_setting;
|
||||
|
||||
sbi(UCSR2B, RXEN2);
|
||||
sbi(UCSR2B, TXEN2);
|
||||
sbi(UCSR2B, RXCIE2);
|
||||
sbi(UCSR1B, RXEN1);
|
||||
sbi(UCSR1B, TXEN1);
|
||||
sbi(UCSR1B, RXCIE1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -154,9 +154,9 @@ void MarlinSerial::end()
|
|||
cbi(M_UCSRxB, M_RXCIEx);
|
||||
|
||||
#ifndef SNMM
|
||||
cbi(UCSR2B, RXEN2);
|
||||
cbi(UCSR2B, TXEN2);
|
||||
cbi(UCSR2B, RXCIE2);
|
||||
cbi(UCSR1B, RXEN1);
|
||||
cbi(UCSR1B, TXEN1);
|
||||
cbi(UCSR1B, RXCIE1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class MarlinSerial //: public Stream
|
|||
{
|
||||
return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
/*
|
||||
FORCE_INLINE void write(uint8_t c)
|
||||
{
|
||||
while (!((M_UCSRxA) & (1 << M_UDREx)))
|
||||
|
@ -109,7 +109,20 @@ class MarlinSerial //: public Stream
|
|||
|
||||
M_UDRx = c;
|
||||
}
|
||||
|
||||
*/
|
||||
void write(uint8_t c)
|
||||
{
|
||||
if (selectedSerialPort == 0) {
|
||||
while (!((M_UCSRxA) & (1 << M_UDREx)))
|
||||
;
|
||||
M_UDRx = c;
|
||||
}
|
||||
else if (selectedSerialPort == 1) {
|
||||
while (!((UCSR1A) & (1 << UDRE1)))
|
||||
;
|
||||
UDR1 = c;
|
||||
}
|
||||
}
|
||||
|
||||
void checkRx(void)
|
||||
{
|
||||
|
@ -135,14 +148,14 @@ class MarlinSerial //: public Stream
|
|||
}
|
||||
}
|
||||
} else if(selectedSerialPort == 1) {
|
||||
if((UCSR2A & (1<<RXC2)) != 0) {
|
||||
if((UCSR1A & (1<<RXC1)) != 0) {
|
||||
// Test for a framing error.
|
||||
if (UCSR2A & (1<<FE2)) {
|
||||
if (UCSR1A & (1<<FE1)) {
|
||||
// Characters received with the framing errors will be ignored.
|
||||
// The temporary variable "c" was made volatile, so the compiler does not optimize this out.
|
||||
volatile unsigned char c = UDR2;
|
||||
volatile unsigned char c = UDR1;
|
||||
} else {
|
||||
unsigned char c = UDR2;
|
||||
unsigned char c = UDR1;
|
||||
int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
|
||||
// if we should be storing the received character into the location
|
||||
// just before the tail (meaning that the head would advance to the
|
||||
|
|
|
@ -818,13 +818,14 @@ void setup()
|
|||
EEPROM_read_B(EEPROM_FARM_NUMBER, &farm_no);
|
||||
if ((farm_mode == 0xFF && farm_no == 0) || (farm_no == 0xFFFF)) farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode
|
||||
if (farm_no == 0xFFFF) farm_no = 0;
|
||||
|
||||
selectedSerialPort = eeprom_read_byte((uint8_t*)EEPROM_SECOND_SERIAL_ACTIVE);
|
||||
if (selectedSerialPort == 0xFF) selectedSerialPort = 0;
|
||||
if (farm_mode)
|
||||
{
|
||||
prusa_statistics(8);
|
||||
selectedSerialPort = 1;
|
||||
}
|
||||
else
|
||||
selectedSerialPort = 0;
|
||||
MYSERIAL.begin(BAUDRATE);
|
||||
fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream
|
||||
stdout = uartout;
|
||||
|
|
|
@ -1524,6 +1524,16 @@ const char * const MSG_SD_WRITE_TO_FILE_LANG_TABLE[1] PROGMEM = {
|
|||
MSG_SD_WRITE_TO_FILE_EN
|
||||
};
|
||||
|
||||
const char MSG_SECOND_SERIAL_OFF_EN[] PROGMEM = "2nd USART [off]";
|
||||
const char * const MSG_SECOND_SERIAL_OFF_LANG_TABLE[1] PROGMEM = {
|
||||
MSG_SECOND_SERIAL_OFF_EN
|
||||
};
|
||||
|
||||
const char MSG_SECOND_SERIAL_ON_EN[] PROGMEM = "2nd USART [on]";
|
||||
const char * const MSG_SECOND_SERIAL_ON_LANG_TABLE[1] PROGMEM = {
|
||||
MSG_SECOND_SERIAL_ON_EN
|
||||
};
|
||||
|
||||
const char MSG_SELFTEST_EN[] PROGMEM = "Selftest ";
|
||||
const char * const MSG_SELFTEST_LANG_TABLE[1] PROGMEM = {
|
||||
MSG_SELFTEST_EN
|
||||
|
|
|
@ -518,6 +518,10 @@ extern const char* const MSG_SD_WORKDIR_FAIL_LANG_TABLE[1];
|
|||
#define MSG_SD_WORKDIR_FAIL LANG_TABLE_SELECT_EXPLICIT(MSG_SD_WORKDIR_FAIL_LANG_TABLE, 0)
|
||||
extern const char* const MSG_SD_WRITE_TO_FILE_LANG_TABLE[1];
|
||||
#define MSG_SD_WRITE_TO_FILE LANG_TABLE_SELECT_EXPLICIT(MSG_SD_WRITE_TO_FILE_LANG_TABLE, 0)
|
||||
extern const char* const MSG_SECOND_SERIAL_OFF_LANG_TABLE[1];
|
||||
#define MSG_SECOND_SERIAL_OFF LANG_TABLE_SELECT_EXPLICIT(MSG_SECOND_SERIAL_OFF_LANG_TABLE, 0)
|
||||
extern const char* const MSG_SECOND_SERIAL_ON_LANG_TABLE[1];
|
||||
#define MSG_SECOND_SERIAL_ON LANG_TABLE_SELECT_EXPLICIT(MSG_SECOND_SERIAL_ON_LANG_TABLE, 0)
|
||||
extern const char* const MSG_SELFTEST_LANG_TABLE[1];
|
||||
#define MSG_SELFTEST LANG_TABLE_SELECT_EXPLICIT(MSG_SELFTEST_LANG_TABLE, 0)
|
||||
extern const char* const MSG_SELFTEST_AXIS_LANG_TABLE[LANG_NUM];
|
||||
|
|
|
@ -376,4 +376,6 @@
|
|||
#define(length=17, lines=1) MSG_SORT_ALPHA "Sort: [Alphabet]"
|
||||
#define(length=17, lines=1) MSG_SORT_NONE "Sort: [None]"
|
||||
#define(length=20, lines=1) MSG_SORTING "Sorting files"
|
||||
#define(length=20, lines=4) MSG_FILE_CNT "Some files will not be sorted. Max. No. of files in 1 folder for sorting is 100."
|
||||
#define(length=20, lines=4) MSG_FILE_CNT "Some files will not be sorted. Max. No. of files in 1 folder for sorting is 100."
|
||||
#define(length=17, lines=1) MSG_SECOND_SERIAL_ON "2nd USART [on]"
|
||||
#define(length=17, lines=1) MSG_SECOND_SERIAL_OFF "2nd USART [off]"
|
||||
|
|
|
@ -3372,6 +3372,13 @@ void lcd_temp_calibration_set() {
|
|||
lcd_goto_menu(lcd_settings_menu, 10);
|
||||
}
|
||||
|
||||
void lcd_second_serial_set() {
|
||||
if(selectedSerialPort == 1) selectedSerialPort = 0;
|
||||
else selectedSerialPort = 1;
|
||||
eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
|
||||
lcd_goto_menu(lcd_settings_menu, 11);
|
||||
}
|
||||
|
||||
void lcd_calibrate_pinda() {
|
||||
enquecommand_P(PSTR("G76"));
|
||||
lcd_return_to_status();
|
||||
|
@ -3735,6 +3742,13 @@ static void lcd_settings_menu()
|
|||
else {
|
||||
MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set);
|
||||
}
|
||||
if (selectedSerialPort == false) {
|
||||
MENU_ITEM(function, MSG_SECOND_SERIAL_OFF, lcd_second_serial_set);
|
||||
}
|
||||
else {
|
||||
MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set);
|
||||
}
|
||||
|
||||
if (SilentModeMenu == 0) {
|
||||
MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue