Fix and improve STM32F1 serial (#19464)
This commit is contained in:
committed by
Scott Lahteine
parent
449a31dea9
commit
9d02cedfed
@ -53,12 +53,12 @@ static bool is_printing_from_sd = false;
|
||||
static bool is_out_of_filament = false;
|
||||
|
||||
static void sendNewLine(void) {
|
||||
ANYCUBIC_LCD_SERIAL.write('\r');
|
||||
ANYCUBIC_LCD_SERIAL.write('\n');
|
||||
LCD_SERIAL.write('\r');
|
||||
LCD_SERIAL.write('\n');
|
||||
}
|
||||
|
||||
static void send(const char *str) {
|
||||
ANYCUBIC_LCD_SERIAL.print(str);
|
||||
LCD_SERIAL.print(str);
|
||||
}
|
||||
|
||||
static void sendLine(const char *str) {
|
||||
@ -68,7 +68,7 @@ static void sendLine(const char *str) {
|
||||
|
||||
static void send_P(PGM_P str) {
|
||||
while (const char c = pgm_read_byte(str++))
|
||||
ANYCUBIC_LCD_SERIAL.write(c);
|
||||
LCD_SERIAL.write(c);
|
||||
}
|
||||
|
||||
static void sendLine_P(PGM_P str) {
|
||||
@ -78,23 +78,23 @@ static void sendLine_P(PGM_P str) {
|
||||
|
||||
static void sendValue_P(PGM_P prefix, int value) {
|
||||
send_P(prefix);
|
||||
ANYCUBIC_LCD_SERIAL.print(value);
|
||||
LCD_SERIAL.print(value);
|
||||
}
|
||||
|
||||
static void sendValue_P(PGM_P prefix, float value) {
|
||||
send_P(prefix);
|
||||
ANYCUBIC_LCD_SERIAL.print(value);
|
||||
LCD_SERIAL.print(value);
|
||||
}
|
||||
|
||||
static void sendValueLine_P(PGM_P prefix, int value) {
|
||||
send_P(prefix);
|
||||
ANYCUBIC_LCD_SERIAL.print(value);
|
||||
LCD_SERIAL.print(value);
|
||||
sendNewLine();
|
||||
}
|
||||
|
||||
static void sendValueLine_P(PGM_P prefix, float value) {
|
||||
send_P(prefix);
|
||||
ANYCUBIC_LCD_SERIAL.print(value);
|
||||
LCD_SERIAL.print(value);
|
||||
sendNewLine();
|
||||
}
|
||||
|
||||
@ -426,8 +426,8 @@ namespace ExtUI {
|
||||
static char rxBuffer[RX_LEN_MAX+1];
|
||||
static uint8_t rxLen = 0;
|
||||
|
||||
while (ANYCUBIC_LCD_SERIAL.available()) {
|
||||
const char c = ANYCUBIC_LCD_SERIAL.read();
|
||||
while (LCD_SERIAL.available()) {
|
||||
const char c = LCD_SERIAL.read();
|
||||
switch (c) {
|
||||
case '\r': case '\n':
|
||||
if (rxLen > 0 && rxLen <= RX_LEN_MAX) {
|
||||
@ -466,7 +466,10 @@ namespace ExtUI {
|
||||
}
|
||||
|
||||
void onStartup() {
|
||||
ANYCUBIC_LCD_SERIAL.begin(115200);
|
||||
#ifndef LCD_BAUDRATE
|
||||
#define LCD_BAUDRATE 115200
|
||||
#endif
|
||||
LCD_SERIAL.begin(LCD_BAUDRATE);
|
||||
sendNewLine();
|
||||
SENDLINE_PGM("J17"); // Reset
|
||||
delay_ms(10);
|
||||
|
@ -59,12 +59,12 @@ char *itostr2(const uint8_t &x) {
|
||||
}
|
||||
|
||||
static void sendNewLine(void) {
|
||||
ANYCUBIC_LCD_SERIAL.write('\r');
|
||||
ANYCUBIC_LCD_SERIAL.write('\n');
|
||||
LCD_SERIAL.write('\r');
|
||||
LCD_SERIAL.write('\n');
|
||||
}
|
||||
|
||||
static void send(const char *str) {
|
||||
ANYCUBIC_LCD_SERIAL.print(str);
|
||||
LCD_SERIAL.print(str);
|
||||
}
|
||||
|
||||
static void sendLine(const char *str) {
|
||||
@ -74,7 +74,7 @@ static void sendLine(const char *str) {
|
||||
|
||||
static void send_P(PGM_P str) {
|
||||
while (const char c = pgm_read_byte(str++))
|
||||
ANYCUBIC_LCD_SERIAL.write(c);
|
||||
LCD_SERIAL.write(c);
|
||||
}
|
||||
|
||||
static void sendLine_P(PGM_P str) {
|
||||
@ -576,8 +576,8 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
|
||||
|
||||
void AnycubicTFTClass::GetCommandFromTFT() {
|
||||
char *starpos = NULL;
|
||||
while (ANYCUBIC_LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) {
|
||||
serial3_char = ANYCUBIC_LCD_SERIAL.read();
|
||||
while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) {
|
||||
serial3_char = LCD_SERIAL.read();
|
||||
if (serial3_char == '\n' ||
|
||||
serial3_char == '\r' ||
|
||||
serial3_char == ':' ||
|
||||
@ -639,11 +639,11 @@ void AnycubicTFTClass::GetCommandFromTFT() {
|
||||
float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y);
|
||||
float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z);
|
||||
SEND_PGM("A5V X: ");
|
||||
ANYCUBIC_LCD_SERIAL.print(xPostition);
|
||||
LCD_SERIAL.print(xPostition);
|
||||
SEND_PGM(" Y: ");
|
||||
ANYCUBIC_LCD_SERIAL.print(yPostition);
|
||||
LCD_SERIAL.print(yPostition);
|
||||
SEND_PGM(" Z: ");
|
||||
ANYCUBIC_LCD_SERIAL.print(zPostition);
|
||||
LCD_SERIAL.print(zPostition);
|
||||
SENDLINE_PGM("");
|
||||
}
|
||||
break;
|
||||
|
@ -59,23 +59,13 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83;
|
||||
bool dguslcd_local_debug; // = false;
|
||||
#endif
|
||||
|
||||
#define dgusserial DGUS_SERIAL
|
||||
|
||||
void DGUSDisplay::InitDisplay() {
|
||||
dgusserial.begin(DGUS_BAUDRATE);
|
||||
|
||||
if (true
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
&& !recovery.valid()
|
||||
#endif
|
||||
)
|
||||
RequestScreen(
|
||||
#if ENABLED(SHOW_BOOTSCREEN)
|
||||
DGUSLCD_SCREEN_BOOT
|
||||
#else
|
||||
DGUSLCD_SCREEN_MAIN
|
||||
#endif
|
||||
);
|
||||
#ifndef LCD_BAUDRATE
|
||||
#define LCD_BAUDRATE 115200
|
||||
#endif
|
||||
LCD_SERIAL.begin(LCD_BAUDRATE);
|
||||
if (TERN1(POWER_LOSS_RECOVERY, !recovery.valid()))
|
||||
RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN));
|
||||
}
|
||||
|
||||
void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) {
|
||||
@ -89,7 +79,7 @@ void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t values
|
||||
strend = true;
|
||||
x = ' ';
|
||||
}
|
||||
dgusserial.write(x);
|
||||
LCD_SERIAL.write(x);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,41 +123,41 @@ void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t val
|
||||
strend = true;
|
||||
x = ' ';
|
||||
}
|
||||
dgusserial.write(x);
|
||||
LCD_SERIAL.write(x);
|
||||
}
|
||||
}
|
||||
|
||||
void DGUSDisplay::ProcessRx() {
|
||||
|
||||
#if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS)
|
||||
if (!dgusserial.available() && dgusserial.buffer_overruns()) {
|
||||
if (!LCD_SERIAL.available() && LCD_SERIAL.buffer_overruns()) {
|
||||
// Overrun, but reset the flag only when the buffer is empty
|
||||
// We want to extract as many as valid datagrams possible...
|
||||
DEBUG_ECHOPGM("OVFL");
|
||||
rx_datagram_state = DGUS_IDLE;
|
||||
//dgusserial.reset_rx_overun();
|
||||
dgusserial.flush();
|
||||
//LCD_SERIAL.reset_rx_overun();
|
||||
LCD_SERIAL.flush();
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t receivedbyte;
|
||||
while (dgusserial.available()) {
|
||||
while (LCD_SERIAL.available()) {
|
||||
switch (rx_datagram_state) {
|
||||
|
||||
case DGUS_IDLE: // Waiting for the first header byte
|
||||
receivedbyte = dgusserial.read();
|
||||
receivedbyte = LCD_SERIAL.read();
|
||||
//DEBUG_ECHOPAIR("< ",x);
|
||||
if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN;
|
||||
break;
|
||||
|
||||
case DGUS_HEADER1_SEEN: // Waiting for the second header byte
|
||||
receivedbyte = dgusserial.read();
|
||||
receivedbyte = LCD_SERIAL.read();
|
||||
//DEBUG_ECHOPAIR(" ",x);
|
||||
rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE;
|
||||
break;
|
||||
|
||||
case DGUS_HEADER2_SEEN: // Waiting for the length byte
|
||||
rx_datagram_len = dgusserial.read();
|
||||
rx_datagram_len = LCD_SERIAL.read();
|
||||
DEBUG_ECHOPAIR(" (", rx_datagram_len, ") ");
|
||||
|
||||
// Telegram min len is 3 (command and one word of payload)
|
||||
@ -175,10 +165,10 @@ void DGUSDisplay::ProcessRx() {
|
||||
break;
|
||||
|
||||
case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive.
|
||||
if (dgusserial.available() < rx_datagram_len) return;
|
||||
if (LCD_SERIAL.available() < rx_datagram_len) return;
|
||||
|
||||
Initialized = true; // We've talked to it, so we defined it as initialized.
|
||||
uint8_t command = dgusserial.read();
|
||||
uint8_t command = LCD_SERIAL.read();
|
||||
|
||||
DEBUG_ECHOPAIR("# ", command);
|
||||
|
||||
@ -186,7 +176,7 @@ void DGUSDisplay::ProcessRx() {
|
||||
unsigned char tmp[rx_datagram_len - 1];
|
||||
unsigned char *ptmp = tmp;
|
||||
while (readlen--) {
|
||||
receivedbyte = dgusserial.read();
|
||||
receivedbyte = LCD_SERIAL.read();
|
||||
DEBUG_ECHOPAIR(" ", receivedbyte);
|
||||
*ptmp++ = receivedbyte;
|
||||
}
|
||||
@ -229,19 +219,19 @@ void DGUSDisplay::ProcessRx() {
|
||||
}
|
||||
}
|
||||
|
||||
size_t DGUSDisplay::GetFreeTxBuffer() { return DGUS_SERIAL_GET_TX_BUFFER_FREE(); }
|
||||
size_t DGUSDisplay::GetFreeTxBuffer() { return SERIAL_GET_TX_BUFFER_FREE(); }
|
||||
|
||||
void DGUSDisplay::WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen) {
|
||||
dgusserial.write(DGUS_HEADER1);
|
||||
dgusserial.write(DGUS_HEADER2);
|
||||
dgusserial.write(payloadlen + 3);
|
||||
dgusserial.write(cmd);
|
||||
dgusserial.write(adr >> 8);
|
||||
dgusserial.write(adr & 0xFF);
|
||||
LCD_SERIAL.write(DGUS_HEADER1);
|
||||
LCD_SERIAL.write(DGUS_HEADER2);
|
||||
LCD_SERIAL.write(payloadlen + 3);
|
||||
LCD_SERIAL.write(cmd);
|
||||
LCD_SERIAL.write(adr >> 8);
|
||||
LCD_SERIAL.write(adr & 0xFF);
|
||||
}
|
||||
|
||||
void DGUSDisplay::WritePGM(const char str[], uint8_t len) {
|
||||
while (len--) dgusserial.write(pgm_read_byte(str++));
|
||||
while (len--) LCD_SERIAL.write(pgm_read_byte(str++));
|
||||
}
|
||||
|
||||
void DGUSDisplay::loop() {
|
||||
|
Reference in New Issue
Block a user