From 1016cc3abc77c2b1821d42f35f2eca378d013119 Mon Sep 17 00:00:00 2001 From: fruchti Date: Sat, 24 Jan 2026 12:03:33 +0100 Subject: [PATCH 1/2] Parse VS and VN HPGL commands --- stm32f103t8u6/build_number.txt | 2 +- stm32f103t8u6/src/hpgl.c | 39 ++++++++++++++++++++++++++++++++++ stm32f103t8u6/src/hpgl.h | 1 + stm32f103t8u6/src/pwm_output.c | 7 +++++- stm32f103t8u6/src/pwm_output.h | 5 +++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/stm32f103t8u6/build_number.txt b/stm32f103t8u6/build_number.txt index b4eed3b..8c0a186 100644 --- a/stm32f103t8u6/build_number.txt +++ b/stm32f103t8u6/build_number.txt @@ -1 +1 @@ -358 +363 diff --git a/stm32f103t8u6/src/hpgl.c b/stm32f103t8u6/src/hpgl.c index 9c0d593..bb93ed6 100644 --- a/stm32f103t8u6/src/hpgl.c +++ b/stm32f103t8u6/src/hpgl.c @@ -22,6 +22,9 @@ typedef enum HPGL_Parser_ReceivingX, HPGL_Parser_ReceivingY, + // Receiving velocity value + HPGL_Parser_ReceivingVelocity, + HPGL_Parser_Error, } HPGL_ParserState_t; @@ -45,6 +48,8 @@ void HPGL_Poll(void) static bool waiting_for_movement_queue = false; + static unsigned char current_velocity = OUTPUT_DEFAULT_VELOCITY; + if(waiting_for_movement_queue) { if(!HPGL_EnqueueMovement(waiting_movement)) @@ -100,6 +105,7 @@ void HPGL_Poll(void) // Initialise HPGL_ParseErrorCounter = 0; // No parameters expected for this one + current_velocity = OUTPUT_DEFAULT_VELOCITY; state = HPGL_Parser_Idle; break; @@ -111,6 +117,7 @@ void HPGL_Poll(void) case INST('P', 'U'): // Movement with pen up current_movement.pen_down = false; + current_movement.velocity = current_velocity; current_movement.x = 0; current_movement.y = 0; state = HPGL_Parser_ReceivingX; @@ -119,11 +126,24 @@ void HPGL_Poll(void) case INST('P', 'D'): // Movement with pen down current_movement.pen_down = true; + current_movement.velocity = current_velocity; current_movement.x = 0; current_movement.y = 0; state = HPGL_Parser_ReceivingX; break; + case INST('V', 'N'): + // Reset velocity to default + current_velocity = OUTPUT_DEFAULT_VELOCITY; + state = HPGL_Parser_Idle; + break; + + case INST('V', 'S'): + // Velocity set + current_velocity = 0; + state = HPGL_Parser_ReceivingVelocity; + break; + default: // Unsupported instruction HPGL_ParseErrorCounter++; @@ -213,6 +233,25 @@ void HPGL_Poll(void) } break; + case HPGL_Parser_ReceivingVelocity: + if(character == ';' || character == '\n') + { + // Command finished + state = HPGL_Parser_Idle; + } + else if(character >= '0' && character <= '9') + { + unsigned int digit = character - '0'; + current_velocity = current_velocity * 10 + digit; + } + else + { + // The VS command could come with a pen number after a comma. + // This is currently unsupported. + state = HPGL_Parser_Error; + } + break; + case HPGL_Parser_Error: // Exit error state only after end of command if(character == '\n' || character == ';') diff --git a/stm32f103t8u6/src/hpgl.h b/stm32f103t8u6/src/hpgl.h index afb49e9..00b39e1 100644 --- a/stm32f103t8u6/src/hpgl.h +++ b/stm32f103t8u6/src/hpgl.h @@ -5,6 +5,7 @@ typedef struct { bool pen_down; + unsigned char velocity; unsigned int x; unsigned int y; } HPGL_Movement_t; diff --git a/stm32f103t8u6/src/pwm_output.c b/stm32f103t8u6/src/pwm_output.c index 6aa5898..b7e9226 100644 --- a/stm32f103t8u6/src/pwm_output.c +++ b/stm32f103t8u6/src/pwm_output.c @@ -30,7 +30,7 @@ static Output_Coordinate_t Output_CurrentLineStart = {0, 0}; static Output_Coordinate_t Output_CurrentLineEnd = {0, 0}; static unsigned int Output_CurrentLineLength; static unsigned int Output_CurrentLinePosition; -static unsigned int Output_CurrentVelocity = OUTPUT_LENGTH_SCALE / 3; +static unsigned int Output_CurrentVelocity = OUTPUT_DEFAULT_VELOCITY; bool Output_EnqueueMovement(HPGL_Movement_t movement) { @@ -52,6 +52,10 @@ bool Output_EnqueueMovement(HPGL_Movement_t movement) { movement.y = OUTPUT_COORDINATE_LIMIT; } + if(movement.velocity > OUTPUT_MAXIMUM_VELOCITY) + { + movement.velocity = OUTPUT_MAXIMUM_VELOCITY; + } memcpy(Output_BufferWrite, &movement, sizeof(HPGL_Movement_t)); Output_BufferWrite++; @@ -128,6 +132,7 @@ static bool Output_FetchNextPoint(void) Output_CurrentLineEnd.x - Output_CurrentLineStart.x, Output_CurrentLineEnd.y - Output_CurrentLineStart.y); Output_CurrentLinePosition = 0; + Output_CurrentVelocity = movement->velocity; Output_BufferRead++; if(Output_BufferRead >= Output_Buffer + CONFIG_BUFFER_MOVEMENTS) diff --git a/stm32f103t8u6/src/pwm_output.h b/stm32f103t8u6/src/pwm_output.h index 70896f6..7fa7356 100644 --- a/stm32f103t8u6/src/pwm_output.h +++ b/stm32f103t8u6/src/pwm_output.h @@ -17,6 +17,11 @@ // overflows during coordinate calculations. #define OUTPUT_LENGTH_SCALE (1 << 3) +// If no velocity is sett via a ‘VS’ command or ‘VN’ is invoked, use this +// velocity setting +#define OUTPUT_DEFAULT_VELOCITY (OUTPUT_LENGTH_SCALE / 3) +#define OUTPUT_MAXIMUM_VELOCITY (OUTPUT_LENGTH_SCALE) // TODO: Check value + // Delay after initiating pen-up/-down before continuing movements #define OUTPUT_PEN_UP_DELAY 200 // In movement timer ticks #define OUTPUT_PEN_DOWN_DELAY 20 // In movement timer ticks From 697789558b151640584e38240a0477d5ba7e507c Mon Sep 17 00:00:00 2001 From: fruchti Date: Thu, 29 Jan 2026 19:55:35 +0100 Subject: [PATCH 2/2] Fix dependency file generation --- stm32f103t8u6-bootloader/build_number.txt | 2 +- stm32f103t8u6-bootloader/makefile | 2 +- stm32f103t8u6/build_number.txt | 2 +- stm32f103t8u6/makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stm32f103t8u6-bootloader/build_number.txt b/stm32f103t8u6-bootloader/build_number.txt index e5a135a..0187835 100644 --- a/stm32f103t8u6-bootloader/build_number.txt +++ b/stm32f103t8u6-bootloader/build_number.txt @@ -1 +1 @@ -445 +446 diff --git a/stm32f103t8u6-bootloader/makefile b/stm32f103t8u6-bootloader/makefile index a8eaea8..4ebd0f9 100644 --- a/stm32f103t8u6-bootloader/makefile +++ b/stm32f103t8u6-bootloader/makefile @@ -58,7 +58,7 @@ $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(filter-out $(EXCLUDE_SOURC $(addprefix $(BUILD_DIR)/,$(addsuffix .d,$(basename $(filter-out $(EXCLUDE_SOURCES),$(notdir $(wildcard $(1)/*.c)))))): $(BUILD_DIR)/%.d: $(1)/%.c @#echo " DP $$@" - $(Q)set -e; rm -f $$@; $$(CC) -MM $$(CFLAGS) $$< > $$@.$$$$$$$$; sed 's,\($$*\)\.o[ :]*,build\/\1.o $$@ : ,g' < $$@.$$$$$$$$ > $$@; rm -f $$@.$$$$$$$$ + $(Q)set -e; rm -f $$@; $$(CC) -MM $$(CFLAGS) $$< > $$@.$$$$$$$$; sed 's,\(.*\)\.o[ :]*,build\/\1.o $$@ : ,g' < $$@.$$$$$$$$ > $$@; rm -f $$@.$$$$$$$$ endef $(foreach directory,$(SOURCE_DIRS),$(eval $(call define_compile_rules,$(directory)))) diff --git a/stm32f103t8u6/build_number.txt b/stm32f103t8u6/build_number.txt index b4eed3b..cf7ff50 100644 --- a/stm32f103t8u6/build_number.txt +++ b/stm32f103t8u6/build_number.txt @@ -1 +1 @@ -358 +359 diff --git a/stm32f103t8u6/makefile b/stm32f103t8u6/makefile index 268ada9..5de7a9f 100644 --- a/stm32f103t8u6/makefile +++ b/stm32f103t8u6/makefile @@ -66,7 +66,7 @@ endif define define_compile_rule $(addprefix $(BUILD_DIR)/,$(notdir $(1:.c=.d))): $(1) @#echo " DP $$@" - $(Q)set -e; rm -f $$@; $$(CC) -MM $$(CFLAGS) $$< > $$@.$$$$$$$$; sed 's,\($$*\)\.o[ :]*,build\/\1.o $$@ : ,g' < $$@.$$$$$$$$ > $$@; rm -f $$@.$$$$$$$$ + $(Q)set -e; rm -f $$@; $$(CC) -MM $$(CFLAGS) $$< > $$@.$$$$$$$$; sed 's,\(.*\)\.o[ :]*,build\/\1.o $$@ : ,g' < $$@.$$$$$$$$ > $$@; rm -f $$@.$$$$$$$$ $(addprefix $(BUILD_DIR)/,$(notdir $(1:.c=.o))): $(1) @echo " CC $$@" $(Q)$$(CC) $$(CFLAGS) -o $$@ -c $$<