Skip to content

Commit

Permalink
Work on some D-codes support
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 2, 2020
1 parent 09e6f18 commit 9e79635
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ void HAL_init();
inline void HAL_clear_reset_source() { MCUSR = 0; }
inline uint8_t HAL_get_reset_source() { return MCUSR; }

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
extern "C" {
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/DUE/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ void sei(); // Enable interrupts
void HAL_clear_reset_source(); // clear reset reason
uint8_t HAL_get_reset_source(); // get reset reason

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

//
// ADC
//
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/ESP32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ void HAL_clear_reset_source();
// reset reason
uint8_t HAL_get_reset_source();

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

void _delay_ms(int delay);

#pragma GCC diagnostic push
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/LINUX/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ uint16_t HAL_adc_get_result();
inline void HAL_clear_reset_source(void) {}
inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

/* ---------------- Delay in cycles */
FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
Clock::delayCycles(x);
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/LPC1768/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255,
void HAL_clear_reset_source(void);
uint8_t HAL_get_reset_source(void);

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

// Add strcmp_P if missing
#ifndef strcmp_P
#define strcmp_P(a, b) strcmp((a), (b))
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/SAMD51/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ typedef int8_t pin_t;
void HAL_clear_reset_source(); // clear reset reason
uint8_t HAL_get_reset_source(); // get reset reason

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

//
// ADC
//
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ void HAL_clear_reset_source();
// Reset reason
uint8_t HAL_get_reset_source();

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

void _delay_ms(const int delay);

extern "C" char* _sbrk(int incr);
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ void HAL_clear_reset_source();
// Reset reason
uint8_t HAL_get_reset_source();

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

void _delay_ms(const int delay);

#pragma GCC diagnostic push
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/STM32_F4_F7/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ void HAL_clear_reset_source();
// Reset reason
uint8_t HAL_get_reset_source();

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

void _delay_ms(const int delay);

/*
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/TEENSY31_32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void HAL_clear_reset_source();
// Get the reason for the reset
uint8_t HAL_get_reset_source();

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }

#pragma GCC diagnostic push
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/TEENSY35_36/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void HAL_clear_reset_source();
// Reset reason
uint8_t HAL_get_reset_source();

inline uint8_t HAL_reboot() {} // reboot the board or restart the bootloader

FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }

#pragma GCC diagnostic push
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
#define WITHIN(N,L,H) ((N) >= (L) && (N) <= (H))
#define NUMERIC(a) WITHIN(a, '0', '9')
#define DECIMAL(a) (NUMERIC(a) || a == '.')
#define HEXCHR(a) (NUMERIC(a) ? (a) - '0' : WITHIN(a, 'a', 'f') ? ((a) - 'a' + 10) : WITHIN(a, 'A', 'F') ? ((a) - 'A' + 10) : -1)
#define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
#define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
#define COUNT(a) (sizeof(a)/sizeof(*a))
Expand Down
11 changes: 3 additions & 8 deletions Marlin/src/feature/e_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ class EmergencyParser {

case EP_N:
switch (c) {
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9': case '-': case ' ': break;
case '0' ... '9':
case '-': case ' ': break;
case 'M': state = EP_M; break;
default: state = EP_IGNORE;
}
Expand Down Expand Up @@ -153,10 +151,7 @@ class EmergencyParser {
case EP_M876S:
switch (c) {
case ' ': break;
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9':
case '0' ... '9':
state = EP_M876SN;
M876_reason = (uint8_t)(c - '0');
break;
Expand Down
92 changes: 91 additions & 1 deletion Marlin/src/gcode/gcode_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#if ENABLED(MARLIN_DEV_MODE)

#include "gcode.h"
#include "../module/settings.h"
#include "../libs/hex_print.h"
#include "../HAL/shared/eeprom_if.h"

/**
* Dn: G-code for development and testing
*
Expand All @@ -33,8 +37,94 @@
*/
void GcodeSuite::D(const int8_t dcode) {
switch (dcode) {
case -1: for (;;) { /*spin*/ }

case -1:
for (;;); // forever

case 0:
HAL_reboot();
break;

case 1:
// TODO: Zero or pattern-fill the EEPROM data
//settings.reset();
//settings.save();
HAL_reboot();
break;

case 2: { // D2 Read / Write SRAM
#define SRAM_SIZE 8192
uint8_t *adr = parser.uhexval('A');
uint16_t len = parser.ushortval('C', 1);
NOMORE(adr, SRAM_SIZE - 1);
NOMORE(len, SRAM_SIZE - adr);
if (parser.seenval('X')) {
// TODO: Write the hex bytes after the X
//while (len--) {
//}
}
else {
while (len--) print_hex_byte(adr++);
SERIAL_EOL();
}
} break;

case 3: { // D3 Read / Write EEPROM
uint8_t *adr = parser.uhexval('A');
uint16_t len = parser.ushortval('C', 1);
NOMORE(adr, MARLIN_EEPROM_SIZE - 1);
NOMORE(len, MARLIN_EEPROM_SIZE - adr);
if (parser.seenval('X')) {
// TODO: Write the hex bytes after the X
//while (len--) {
//}
}
else {
while (len--) {
// TODO: Read bytes from EEPROM
print_hex_byte(eeprom_read_byte(adr++));
}
SERIAL_EOL();
}
} break;

case 4: { // D4 Read / Write PIN
const uint8_t pin = parser.byteval('P');
const bool is_out = parser.boolval('F'),
val = parser.byteval('V', LOW);
if (parser.seenval('X')) {
// TODO: Write the hex bytes after the X
//while (len--) {
//}
}
else {
while (len--) {
// TODO: Read bytes from EEPROM
print_hex_byte(eeprom_read_byte(adr++));
}
SERIAL_EOL();
}
} break;

case 5: { // D4 Read / Write onboard Flash
#define FLASH_SIZE 1024
uint16_t adr = parser.uhexval('A');
uint16_t len = parser.ushortval('C', 1);
NOMORE(adr, FLASH_SIZE - 1);
NOMORE(len, FLASH_SIZE - adr);
if (parser.seenval('X')) {
// TODO: Write the hex bytes after the X
//while (len--) {
//}
}
else {
while (len--) {
// TODO: Read bytes from EEPROM
print_hex_byte(eeprom_read_byte(adr++));
}
SERIAL_EOL();
}
} break;
}
}

Expand Down
23 changes: 6 additions & 17 deletions Marlin/src/gcode/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ void GCodeParser::parse(char *p) {
starpos[1] = '\0';
}

#if ENABLED(GCODE_MOTION_MODES)
#if ENABLED(ARC_SUPPORT)
#define GTOP 3
#else
#define GTOP 1
#endif
#endif

#if ENABLED(MARLIN_DEV_MODE) || ANY(SWITCHING_TOOLHEAD, MAGNETIC_SWITCHING_TOOLHEAD, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
#define SIGNED_CODENUM 1
#endif
Expand Down Expand Up @@ -210,11 +202,8 @@ void GCodeParser::parse(char *p) {
while (*p == ' ') p++;

#if ENABLED(GCODE_MOTION_MODES)
if (letter == 'G' && (codenum <= GTOP || codenum == 5
#if ENABLED(G38_PROBE_TARGET)
|| codenum == 38
#endif
)
if (letter == 'G'
&& (codenum <= TERN(ARC_SUPPORT, 3, 1) || codenum == 5 || TERN0(G38_PROBE_TARGET, codenum == 38))
) {
motion_mode_codenum = codenum;
TERN_(USE_GCODE_SUBCODES, motion_mode_subcode = subcode);
Expand All @@ -225,12 +214,12 @@ void GCodeParser::parse(char *p) {

#if ENABLED(GCODE_MOTION_MODES)
#if ENABLED(ARC_SUPPORT)
case 'I': case 'J': case 'R':
case 'I' ... 'J': case 'R':
if (motion_mode_codenum != 2 && motion_mode_codenum != 3) return;
#endif
case 'P': case 'Q':
case 'P' ... 'Q':
if (motion_mode_codenum != 5) return;
case 'X': case 'Y': case 'Z': case 'E': case 'F':
case 'X' ... 'Z': case 'E' ... 'F':
if (motion_mode_codenum < 0) return;
command_letter = 'G';
codenum = motion_mode_codenum;
Expand All @@ -256,7 +245,7 @@ void GCodeParser::parse(char *p) {
#if ENABLED(EXPECTED_PRINTER_CHECK)
case 16:
#endif
case 23: case 28: case 30: case 117: case 118: case 928:
case 23: case 28: case 30: case 117 ... 118: case 928:
string_arg = unescape_string(p);
return;
default: break;
Expand Down
27 changes: 24 additions & 3 deletions Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class GCodeParser {
return valid_signless(p) || ((p[0] == '-' || p[0] == '+') && valid_signless(&p[1])); // [-+]?.?[0-9]
}

FORCE_INLINE static bool valid_number(const char * const p) {
// TODO: With MARLIN_DEV_MODE allow HEX values starting with "x"
return valid_float(p);
}

#if ENABLED(FASTER_GCODE_PARSER)

FORCE_INLINE static bool valid_int(const char * const p) {
Expand Down Expand Up @@ -142,8 +147,12 @@ class GCodeParser {
if (ind >= COUNT(param)) return false; // Only A-Z
const bool b = TEST32(codebits, ind);
if (b) {
char * const ptr = command_ptr + param[ind];
value_ptr = param[ind] && valid_float(ptr) ? ptr : nullptr;
if (param[ind]) {
char * const ptr = command_ptr + param[ind];
value_ptr = valid_number(ptr) ? ptr : nullptr;
}
else
value_ptr = nullptr;
}
return b;
}
Expand Down Expand Up @@ -198,7 +207,7 @@ class GCodeParser {
static inline bool seen(const char c) {
char *p = strgchr(command_args, c);
const bool b = !!p;
if (b) value_ptr = valid_float(&p[1]) ? &p[1] : nullptr;
if (b) value_ptr = valid_number(&p[1]) ? &p[1] : nullptr;
return b;
}

Expand Down Expand Up @@ -401,6 +410,18 @@ class GCodeParser {
static inline float linearval(const char c, const float dval=0) { return seenval(c) ? value_linear_units() : dval; }
static inline float celsiusval(const char c, const float dval=0) { return seenval(c) ? value_celsius() : dval; }

#if ENABLED(MARLIN_DEV_MODE)

static inline const uint8_t* hex_adr_val(const char c, const uint8_t * const dval=nullptr) {
if (!seen(c) || *value_ptr != 'x') return dval;
char *vp = value_ptr + 1;
uint8_t *out = nullptr;
for (; HEXCHR(*vp) >= 0, vp++)
out = (out << 8) | HEXCHR(*vp);
return out;
}

#endif
};

extern GCodeParser parser;
6 changes: 5 additions & 1 deletion Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#include "lcdprint.h"

#include "../sd/cardreader.h"
#include "../module/settings.h"

#include "../module/temperature.h"
#include "../module/planner.h"
#include "../module/motion.h"

#if HAS_LCD_MENU
#include "../module/settings.h"
#endif

#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "../feature/bedlevel/bedlevel.h"
#endif
Expand Down

0 comments on commit 9e79635

Please sign in to comment.