Skip to content

Commit

Permalink
Merge branch 'bugfix-2.0.x' into ender3v2_bugfix
Browse files Browse the repository at this point in the history
* bugfix-2.0.x: (248 commits)
  [cron] Bump distribution date (2021-03-11)
  Fix password menu stickiness before first auth (MarlinFirmware#21295)
  Lerdge-K TMC 2208/9 UART pins (MarlinFirmware#21299)
  Fix LERDGE 'extends' env references (MarlinFirmware#21305)
  Fix TouchMI stow in G34 (MarlinFirmware#21291)
  Fix MeatPack with per-serial-port instances (MarlinFirmware#21306)
  Tricked-out declaration
  Update MEATPACK test
  Number serial from 1 to match settings
  Clean up spaces and words
  Fix serial index types
  Add binary file transfer test
  fix meat pack internal buffer for multi serial
  [cron] Bump distribution date (2021-03-10)
  Fix LPC + TMC boot loop (MarlinFirmware#21298)
  Distinguish serial index from mask (MarlinFirmware#21287)
  Host Keepalive followup (MarlinFirmware#21290)
  [cron] Bump distribution date (2021-03-09)
  CUSTOM_USER_BUTTONS followup (MarlinFirmware#21284)
  Fix Host Keepalive serial target (MarlinFirmware#21283)
  ...

# Conflicts:
#	Marlin/Configuration.h
#	Marlin/Configuration_adv.h
  • Loading branch information
Michael authored and Michael committed Mar 11, 2021
2 parents b5c4ef2 + a73cff8 commit 022f395
Show file tree
Hide file tree
Showing 812 changed files with 25,842 additions and 11,782 deletions.
2 changes: 2 additions & 0 deletions Marlin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1203)
else ifeq ($(HARDWARE_MOTHERBOARD),1204)
# abee Scoovo X9H
else ifeq ($(HARDWARE_MOTHERBOARD),1205)
# Rambo ThinkerV2
else ifeq ($(HARDWARE_MOTHERBOARD),1206)

#
# Other ATmega1280, ATmega2560
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/HAL/AVR/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#include "../../inc/MarlinConfig.h"
#include "HAL.h"

#ifdef USBCON
DefaultSerial1 MSerial0(false, Serial);
#ifdef BLUETOOTH
BTSerial btSerial(false, bluetoothSerial);
#endif
#endif

// ------------------------
// Public Variables
// ------------------------
Expand Down
14 changes: 11 additions & 3 deletions Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,26 @@ typedef int8_t pin_t;

// Serial ports
#ifdef USBCON
#define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial)
#include "../../core/serial_hook.h"
typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
extern DefaultSerial1 MSerial0;
#ifdef BLUETOOTH
typedef ForwardSerial1Class< decltype(bluetoothSerial) > BTSerial;
extern BTSerial btSerial;
#endif

#define MYSERIAL1 TERN(BLUETOOTH, btSerial, MSerial0)
#else
#if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#define MYSERIAL0 customizedSerial1
#define MYSERIAL1 customizedSerial1

#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif
#define MYSERIAL1 customizedSerial2
#define MYSERIAL2 customizedSerial2
#endif
#endif

Expand Down
193 changes: 13 additions & 180 deletions Marlin/src/HAL/AVR/MarlinSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void MarlinSerial<Cfg>::flush() {
}

template<typename Cfg>
void MarlinSerial<Cfg>::write(const uint8_t c) {
size_t MarlinSerial<Cfg>::write(const uint8_t c) {
if (Cfg::TX_SIZE == 0) {

_written = true;
Expand All @@ -480,7 +480,7 @@ void MarlinSerial<Cfg>::write(const uint8_t c) {
// location". This makes sure flush() won't return until the bytes
// actually got written
B_TXC = 1;
return;
return 1;
}

const uint8_t i = (tx_buffer.head + 1) & (Cfg::TX_SIZE - 1);
Expand Down Expand Up @@ -510,6 +510,7 @@ void MarlinSerial<Cfg>::write(const uint8_t c) {
// Enable TX ISR - Non atomic, but it will eventually enable TX ISR
B_UDRIE = 1;
}
return 1;
}

template<typename Cfg>
Expand Down Expand Up @@ -556,161 +557,6 @@ void MarlinSerial<Cfg>::flushTX() {
}
}

/**
* Imports from print.h
*/

template<typename Cfg>
void MarlinSerial<Cfg>::print(char c, int base) {
print((long)c, base);
}

template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned char b, int base) {
print((unsigned long)b, base);
}

template<typename Cfg>
void MarlinSerial<Cfg>::print(int n, int base) {
print((long)n, base);
}

template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned int n, int base) {
print((unsigned long)n, base);
}

template<typename Cfg>
void MarlinSerial<Cfg>::print(long n, int base) {
if (base == 0) write(n);
else if (base == 10) {
if (n < 0) { print('-'); n = -n; }
printNumber(n, 10);
}
else
printNumber(n, base);
}

template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned long n, int base) {
if (base == 0) write(n);
else printNumber(n, base);
}

template<typename Cfg>
void MarlinSerial<Cfg>::print(double n, int digits) {
printFloat(n, digits);
}

template<typename Cfg>
void MarlinSerial<Cfg>::println() {
print('\r');
print('\n');
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(const String& s) {
print(s);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(const char c[]) {
print(c);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(char c, int base) {
print(c, base);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned char b, int base) {
print(b, base);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(int n, int base) {
print(n, base);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned int n, int base) {
print(n, base);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(long n, int base) {
print(n, base);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned long n, int base) {
print(n, base);
println();
}

template<typename Cfg>
void MarlinSerial<Cfg>::println(double n, int digits) {
print(n, digits);
println();
}

// Private Methods

template<typename Cfg>
void MarlinSerial<Cfg>::printNumber(unsigned long n, uint8_t base) {
if (n) {
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
int8_t i = 0;
while (n) {
buf[i++] = n % base;
n /= base;
}
while (i--)
print((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10)));
}
else
print('0');
}

template<typename Cfg>
void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
// Handle negative numbers
if (number < 0.0) {
print('-');
number = -number;
}

// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
LOOP_L_N(i, digits) rounding *= 0.1;
number += rounding;

// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
print(int_part);

// Print the decimal point, but only if there are digits beyond
if (digits) {
print('.');
// Extract digits from the remainder one at a time
while (digits--) {
remainder *= 10.0;
int toPrint = int(remainder);
print(toPrint);
remainder -= toPrint;
}
}
}

// Hookup ISR handlers
ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) {
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::store_rxd_char();
Expand All @@ -720,11 +566,9 @@ ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) {
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::_tx_udr_empty_irq();
}

// Preinstantiate
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>;

// Instantiate
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
// Because of the template definition above, it's required to instantiate the template to have all methods generated
template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT> >;
MSerialT customizedSerial1(MSerialT::HasEmergencyParser);

#ifdef SERIAL_PORT_2

Expand All @@ -737,12 +581,8 @@ MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>::_tx_udr_empty_irq();
}

// Preinstantiate
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>;

// Instantiate
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;

template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> >;
MSerialT2 customizedSerial2(MSerialT2::HasEmergencyParser);
#endif

#ifdef MMU2_SERIAL_PORT
Expand All @@ -755,12 +595,8 @@ MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>>::_tx_udr_empty_irq();
}

// Preinstantiate
template class MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>>;

// Instantiate
MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>> mmuSerial;

template class MarlinSerial< MMU2SerialCfg<MMU2_SERIAL_PORT> >;
MSerialT3 mmuSerial(MSerialT3::HasEmergencyParser);
#endif

#ifdef LCD_SERIAL_PORT
Expand All @@ -773,11 +609,8 @@ MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>>::_tx_udr_empty_irq();
}

// Preinstantiate
template class MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>>;

// Instantiate
MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>> lcdSerial;
template class MarlinSerial< LCDSerialCfg<LCD_SERIAL_PORT> >;
MSerialT4 lcdSerial(MSerialT4::HasEmergencyParser);

#if HAS_DGUS_LCD
template<typename Cfg>
Expand All @@ -796,7 +629,7 @@ MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;

// For AT90USB targets use the UART for BT interfacing
#if defined(USBCON) && ENABLED(BLUETOOTH)
HardwareSerial bluetoothSerial;
MSerialT5 bluetoothSerial(false);
#endif

#endif // __AVR__
Loading

0 comments on commit 022f395

Please sign in to comment.