diff --git a/config.c b/config.c index 8f81343..4db278e 100644 --- a/config.c +++ b/config.c @@ -26,7 +26,7 @@ #include "wiring_serial.h" #include -struct Settings settings; +settings_t settings; void reset_settings() { settings.steps_per_mm[0] = X_STEPS_PER_MM; @@ -62,7 +62,7 @@ int read_settings() { uint8_t version = eeprom_get_char(0); if (version != SETTINGS_VERSION) { return(FALSE); } // Read settings-record and check checksum - if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(struct Settings)))) { + if (!(memcpy_from_eeprom_with_checksum((char*)&settings, 1, sizeof(settings_t)))) { return(FALSE); } return(TRUE); @@ -70,7 +70,7 @@ int read_settings() { void write_settings() { eeprom_put_char(0, SETTINGS_VERSION); - memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(struct Settings)); + memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(settings_t)); } // A helper method to set settings from command line diff --git a/config.h b/config.h index 67dba49..cde5883 100644 --- a/config.h +++ b/config.h @@ -63,7 +63,7 @@ #define SETTINGS_VERSION 2 // Current global settings (persisted in EEPROM from byte 1 onwards) -struct Settings { +typedef struct { double steps_per_mm[3]; uint8_t microsteps; uint8_t pulse_microseconds; @@ -73,8 +73,8 @@ struct Settings { double mm_per_arc_segment; double acceleration; double max_jerk; -}; -extern struct Settings settings; +} settings_t; +extern settings_t settings; // Initialize the configuration subsystem (load settings from EEPROM) void config_init(); diff --git a/gcode.c b/gcode.c index 436543e..323b8a8 100644 --- a/gcode.c +++ b/gcode.c @@ -74,7 +74,7 @@ #define SPINDLE_DIRECTION_CW 0 #define SPINDLE_DIRECTION_CCW 1 -struct ParserState { +typedef struct { uint8_t status_code; uint8_t motion_mode; /* {G0, G1, G2, G3, G38.2, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89} */ @@ -87,10 +87,9 @@ struct ParserState { double position[3]; /* Where the interpreter considers the tool to be at this point in the code */ uint8_t tool; int16_t spindle_speed; /* RPM/100 */ - uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // The axes of the selected plane - -}; -struct ParserState gc; + uint8_t plane_axis_0, plane_axis_1, plane_axis_2; // The axes of the selected plane +} parser_state_t; +parser_state_t gc; #define FAIL(status) gc.status_code = status; diff --git a/stepper.c b/stepper.c index d4ca832..ce511e2 100644 --- a/stepper.c +++ b/stepper.c @@ -39,7 +39,7 @@ void set_step_events_per_minute(uint32_t steps_per_minute); #define MINIMUM_STEPS_PER_MINUTE 1200 #define CYCLES_PER_ACCELERATION_TICK ((TICKS_PER_MICROSECOND*1000000)/ACCELERATION_TICKS_PER_SECOND) -struct Block *current_block; // A convenience pointer to the block currently being traced +block_t *current_block; // A convenience pointer to the block currently being traced // Variables used by The Stepper Driver Interrupt uint8_t out_bits; // The next stepping-bits to be output diff --git a/stepper_plan.c b/stepper_plan.c index 2cbec52..0d6a7c2 100644 --- a/stepper_plan.c +++ b/stepper_plan.c @@ -60,7 +60,7 @@ #include "config.h" #include "wiring_serial.h" -struct Block block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions +block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions volatile int block_buffer_head; // Index of the next block to be pushed volatile int block_buffer_tail; // Index of the block to process now uint8_t acceleration_management; // Acceleration management active? @@ -113,7 +113,7 @@ inline double intersection_distance(double initial_rate, double final_rate, doub time --> */ -void calculate_trapezoid_for_block(struct Block *block, double entry_factor, double exit_factor) { +void calculate_trapezoid_for_block(block_t *block, double entry_factor, double exit_factor) { block->initial_rate = ceil(block->nominal_rate*entry_factor); int32_t final_rate = ceil(block->nominal_rate*entry_factor); int32_t acceleration_per_minute = block->rate_delta*ACCELERATION_TICKS_PER_SECOND*60.0; @@ -149,7 +149,7 @@ inline double max_allowable_speed(double acceleration, double target_velocity, d // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks. // This method will calculate the junction jerk as the euclidean distance between the nominal // velocities of the respective blocks. -inline double junction_jerk(struct Block *before, struct Block *after) { +inline double junction_jerk(block_t *before, block_t *after) { return(sqrt( pow(before->speed_x-after->speed_x, 2)+ pow(before->speed_y-after->speed_y, 2)+ @@ -158,7 +158,7 @@ inline double junction_jerk(struct Block *before, struct Block *after) { } // The kernel called by planner_recalculate() when scanning the plan from last to first entry. -void planner_reverse_pass_kernel(struct Block *previous, struct Block *current, struct Block *next) { +void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) { if(!current) { return; } double entry_factor = 1.0; @@ -197,7 +197,7 @@ void planner_reverse_pass_kernel(struct Block *previous, struct Block *current, // implements the reverse pass. void planner_reverse_pass() { auto int8_t block_index = block_buffer_head; - struct Block *block[3] = {NULL, NULL, NULL}; + block_t *block[3] = {NULL, NULL, NULL}; while(block_index != block_buffer_tail) { block[2]= block[1]; block[1]= block[0]; @@ -209,7 +209,7 @@ void planner_reverse_pass() { } // The kernel called by planner_recalculate() when scanning the plan from first to last entry. -void planner_forward_pass_kernel(struct Block *previous, struct Block *current, struct Block *next) { +void planner_forward_pass_kernel(block_t *previous, block_t *current, block_t *next) { if(!current) { return; } // If the previous block is an acceleration block, but it is not long enough to // complete the full speed change within the block, we need to adjust out entry @@ -229,7 +229,7 @@ void planner_forward_pass_kernel(struct Block *previous, struct Block *current, // implements the forward pass. void planner_forward_pass() { int8_t block_index = block_buffer_tail; - struct Block *block[3] = {NULL, NULL, NULL}; + block_t *block[3] = {NULL, NULL, NULL}; while(block_index != block_buffer_head) { block[0] = block[1]; @@ -246,8 +246,8 @@ void planner_forward_pass() { // updating the blocks. void planner_recalculate_trapezoids() { int8_t block_index = block_buffer_tail; - struct Block *current; - struct Block *next = NULL; + block_t *current; + block_t *next = NULL; while(block_index != block_buffer_head) { current = next; @@ -262,7 +262,7 @@ void planner_recalculate_trapezoids() { // Recalculates the motion plan according to the following algorithm: // -// 1. Go over every block in reverse order and calculate a junction speed reduction (i.e. Block.entry_factor) +// 1. Go over every block in reverse order and calculate a junction speed reduction (i.e. block_t.entry_factor) // so that: // a. The junction jerk is within the set limit // b. No speed reduction within one block requires faster deceleration than the one, true constant @@ -313,7 +313,7 @@ void plan_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_ // Rest here until there is room in the buffer. while(block_buffer_tail == next_buffer_head) { sleep_mode(); } // Prepare to set up new block - struct Block *block = &block_buffer[block_buffer_head]; + block_t *block = &block_buffer[block_buffer_head]; // Number of steps for each axis block->steps_x = labs(steps_x); block->steps_y = labs(steps_y); diff --git a/stepper_plan.h b/stepper_plan.h index 63cb42b..1fcbf5a 100644 --- a/stepper_plan.h +++ b/stepper_plan.h @@ -32,7 +32,7 @@ // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in // the source g-code and may never actually be reached if acceleration management is active. -struct Block { +typedef struct { // Fields used by the bresenham algorithm for tracing the line uint32_t steps_x, steps_y, steps_z; // Step count along each axis uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) @@ -52,9 +52,9 @@ struct Block { int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be positive) uint32_t accelerate_until; // The index of the step event on which to stop acceleration uint32_t decelerate_after; // The index of the step event on which to start decelerating -}; +} block_t; -extern struct Block block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions +extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions extern volatile int block_buffer_head; // Index of the next block to be pushed extern volatile int block_buffer_tail; // Index of the block to process now