Use enums in stepper.{c,h}
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 20 Mar 2016 23:03:57 +0000 (16:03 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 20 Mar 2016 23:03:57 +0000 (16:03 -0700)
src/canonical_machine.h
src/plan/planner.h
src/stepper.h

index 93a31001aced29dc24374cee49209c4a499515ba..217f130668a1d68a1b1dde3441987f1f26846b06 100644 (file)
@@ -309,7 +309,7 @@ extern cmSingleton_t cm;               // canonical machine controller singleton
  */
 
 /// check alignment with messages in config.c / msg_stat strings
-enum cmCombinedState {
+typedef enum {
   COMBINED_INITIALIZING, // machine is initializing
   COMBINED_READY,        // machine is ready for use. Also null move STOP state
   COMBINED_ALARM,        // machine in soft alarm state
@@ -321,10 +321,10 @@ enum cmCombinedState {
   COMBINED_CYCLE,        // machine is running (cycling)
   COMBINED_HOMING,       // homing is treated as a cycle
   COMBINED_SHUTDOWN,     // machine in hard alarm state (shutdown)
-};
+} cmCombinedState_t;
 
 
-enum cmMachineState {
+typedef enum {
   MACHINE_INITIALIZING, // machine is initializing
   MACHINE_READY,        // machine is ready for use
   MACHINE_ALARM,        // machine in soft alarm state
@@ -332,46 +332,46 @@ enum cmMachineState {
   MACHINE_PROGRAM_END,  // program end
   MACHINE_CYCLE,        // machine is running (cycling)
   MACHINE_SHUTDOWN,     // machine in hard alarm state (shutdown)
-};
+} cmMachineState_t;
 
 
-enum cmCycleState {
+typedef enum {
   CYCLE_OFF,            // machine is idle
   CYCLE_MACHINING,      // in normal machining cycle
   CYCLE_PROBE,          // in probe cycle
   CYCLE_HOMING,         // homing is treated as a specialized cycle
-};
+} cmCycleState_t;
 
 
-enum cmMotionState {
+typedef enum {
   MOTION_STOP,          // motion has stopped
   MOTION_RUN,           // machine is in motion
   MOTION_HOLD           // feedhold in progress
-};
+} cmMotionState_t;
 
 
-enum cmFeedholdState {  // feedhold_state machine
+typedef enum {  // feedhold_state machine
   FEEDHOLD_OFF,         // no feedhold in effect
   FEEDHOLD_SYNC,        // start hold - sync to latest aline segment
   FEEDHOLD_PLAN,        // replan blocks for feedhold
   FEEDHOLD_DECEL,       // decelerate to hold point
   FEEDHOLD_HOLD,        // holding
   FEEDHOLD_END_HOLD     // end hold (transient state to OFF)
-};
+} cmFeedholdState_t;
 
 
-enum cmHomingState {    // applies to cm.homing_state
+typedef enum {    // applies to cm.homing_state
   HOMING_NOT_HOMED,     // machine is not homed (0=false)
   HOMING_HOMED,         // machine is homed (1=true)
   HOMING_WAITING        // machine waiting to be homed
-};
+} cmHomingState_t;
 
 
-enum cmProbeState {     // applies to cm.probe_state
+typedef enum {     // applies to cm.probe_state
   PROBE_FAILED,         // probe reached endpoint without triggering
   PROBE_SUCCEEDED,      // probe was triggered, cm.probe_results has position
   PROBE_WAITING         // probe is waiting to be started
-};
+} cmProbeState_t;
 
 
 /* The difference between NextAction and MotionMode is that NextAction is
@@ -379,7 +379,7 @@ enum cmProbeState {     // applies to cm.probe_state
  * MotionMode persists across blocks (as G modal group 1)
  */
 /// these are in order to optimized CASE statement
-enum cmNextAction {
+typedef enum {
   NEXT_ACTION_DEFAULT,                // Must be zero (invokes motion modes)
   NEXT_ACTION_SEARCH_HOME,            // G28.2 homing cycle
   NEXT_ACTION_SET_ABSOLUTE_ORIGIN,    // G28.3 origin set
@@ -395,10 +395,10 @@ enum cmNextAction {
   NEXT_ACTION_RESUME_ORIGIN_OFFSETS,  // G92.3
   NEXT_ACTION_DWELL,                  // G4
   NEXT_ACTION_STRAIGHT_PROBE          // G38.2
-};
+} cmNextAction_t;
 
 
-enum cmMotionMode {                   // G Modal Group 1
+typedef enum {                        // G Modal Group 1
   MOTION_MODE_STRAIGHT_TRAVERSE,      // G0 - straight traverse
   MOTION_MODE_STRAIGHT_FEED,          // G1 - straight feed
   MOTION_MODE_CW_ARC,                 // G2 - clockwise arc feed
@@ -414,10 +414,10 @@ enum cmMotionMode {                   // G Modal Group 1
   MOTION_MODE_CANNED_CYCLE_87,        // G87 - back boring
   MOTION_MODE_CANNED_CYCLE_88,        // G88 - boring, spindle stop, manual out
   MOTION_MODE_CANNED_CYCLE_89,        // G89 - boring, dwell, feed out
-};
+} cmMotionMode_t;
 
 
-enum cmModalGroup {   // Used for detecting gcode errors. See NIST section 3.4
+typedef enum {   // Used for detecting gcode errors. See NIST section 3.4
   MODAL_GROUP_G0,     // {G10,G28,G28.1,G92}       non-modal axis commands
   MODAL_GROUP_G1,     // {G0,G1,G2,G3,G80}         motion
   MODAL_GROUP_G2,     // {G17,G18,G19}             plane selection
@@ -434,29 +434,29 @@ enum cmModalGroup {   // Used for detecting gcode errors. See NIST section 3.4
   MODAL_GROUP_M7,     // {M3,M4,M5}                spindle turning
   MODAL_GROUP_M8,     // {M7,M8,M9}                coolant
   MODAL_GROUP_M9      // {M48,M49}                 speed/feed override switches
-};
+} cmModalGroup_t;
 
 #define MODAL_GROUP_COUNT (MODAL_GROUP_M9 + 1)
 
 // Note 1: Our G0 omits G4,G30,G53,G92.1,G92.2,G92.3 as these have no axis
 // components to error check
 
-enum cmCanonicalPlane { // canonical plane - translates to:
+typedef enum { // canonical plane - translates to:
   //                          axis_0    axis_1    axis_2
   CANON_PLANE_XY,     // G17    X          Y          Z
   CANON_PLANE_XZ,     // G18    X          Z          Y
   CANON_PLANE_YZ      // G19    Y          Z          X
-};
+} cmCanonicalPlane_t;
 
 
-enum cmUnitsMode {
+typedef enum {
   INCHES,        // G20
   MILLIMETERS,   // G21
   DEGREES        // ABC axes (this value used for displays only)
-};
+} cmUnitsMode_t;
 
 
-enum cmCoordSystem {
+typedef enum {
   ABSOLUTE_COORDS,                // machine coordinate system
   G54,                            // G54 coordinate system
   G55,                            // G55 coordinate system
@@ -464,78 +464,78 @@ enum cmCoordSystem {
   G57,                            // G57 coordinate system
   G58,                            // G58 coordinate system
   G59                             // G59 coordinate system
-};
+} cmCoordSystem_t;
 
 #define COORD_SYSTEM_MAX G59      // set this manually to the last one
 
 /// G Modal Group 13
-enum cmPathControlMode {
+typedef enum {
   /// G61 - hits corners but does not stop if it does not need to.
   PATH_EXACT_PATH,
   PATH_EXACT_STOP,                // G61.1 - stops at all corners
   PATH_CONTINUOUS                 // G64 and typically the default mode
-};
+} cmPathControlMode_t;
 
 
-enum cmDistanceMode {
+typedef enum {
   ABSOLUTE_MODE,                  // G90
   INCREMENTAL_MODE                // G91
-};
+} cmDistanceMode_t;
 
 
-enum cmFeedRateMode {
+typedef enum {
   INVERSE_TIME_MODE,              // G93
   UNITS_PER_MINUTE_MODE,          // G94
   UNITS_PER_REVOLUTION_MODE       // G95 (unimplemented)
-};
+} cmFeedRateMode_t;
 
 
-enum cmOriginOffset {
+typedef enum {
   ORIGIN_OFFSET_SET,      // G92 - set origin offsets
   ORIGIN_OFFSET_CANCEL,   // G92.1 - zero out origin offsets
   ORIGIN_OFFSET_SUSPEND,  // G92.2 - do not apply offsets, but preserve values
   ORIGIN_OFFSET_RESUME    // G92.3 - resume application of the suspended offsets
-};
+} cmOriginOffset_t;
 
 
-enum cmProgramFlow {
+typedef enum {
   PROGRAM_STOP,
   PROGRAM_END
-};
+} cmProgramFlow_t;
 
 
 /// spindle state settings (See hardware.h for bit settings)
-enum cmSpindleState {
+typedef enum {
   SPINDLE_OFF,
   SPINDLE_CW,
   SPINDLE_CCW
-};
+} cmSpindleState_t;
 
 
 /// mist and flood coolant states
-enum cmCoolantState {
+typedef enum {
   COOLANT_OFF,        // all coolant off
   COOLANT_ON,         // request coolant on or indicate both coolants are on
   COOLANT_MIST,       // indicates mist coolant on
   COOLANT_FLOOD       // indicates flood coolant on
-};
+} cmCoolantState_t;
 
 
 /// used for spindle and arc dir
-enum cmDirection {
+typedef enum {
   DIRECTION_CW,
   DIRECTION_CCW
-};
+} cmDirection_t;
 
 
 /// axis modes (ordered: see _cm_get_feed_time())
-enum cmAxisMode {
+typedef enum {
   AXIS_DISABLED,              // kill axis
   AXIS_STANDARD,              // axis in coordinated motion w/standard behaviors
   AXIS_INHIBITED,             // axis is computed but not activated
   AXIS_RADIUS,                // rotary axis calibrated to circumference
   AXIS_MODE_MAX
-}; // ordering must be preserved.
+} cmAxisMode_t; // ordering must be preserved.
 
 #define AXIS_MODE_MAX_LINEAR AXIS_INHIBITED
 #define AXIS_MODE_MAX_ROTARY AXIS_RADIUS
index fe7401886a5cc52d27777c9787db0741068c4e1d..69122b7a3c45d2dbf54c564c657ccbe1db9935a1 100644 (file)
 #include "util.h"
 #include "config.h"
 
-enum moveType {            // bf->move_type values
+typedef enum {             // bf->move_type values
   MOVE_TYPE_0,             // null move - does a no-op
   MOVE_TYPE_ALINE,         // acceleration planned line
   MOVE_TYPE_DWELL,         // delay with no movement
   MOVE_TYPE_COMMAND,       // general command
   MOVE_TYPE_JOG,           // interactive jogging
-};
+} moveType_t;
 
-enum moveState {
+typedef enum {
   MOVE_OFF,               // move inactive (MUST BE ZERO)
   MOVE_NEW,               // general value if you need an initialization
   MOVE_RUN,               // general run state (for non-acceleration moves)
   MOVE_SKIP_BLOCK         // mark a skipped block
-};
+} moveState_t;
 
-enum moveSection {
+typedef enum {
   SECTION_HEAD,           // acceleration
   SECTION_BODY,           // cruise
   SECTION_TAIL            // deceleration
-};
+} moveSection_t;
 #define SECTIONS 3
 
-enum sectionState {
+typedef enum {
   SECTION_OFF,            // section inactive
   SECTION_NEW,            // uninitialized section
   SECTION_1st_HALF,       // first half of S curve
   SECTION_2nd_HALF        // second half of S curve or running a BODY (cruise)
-};
+} sectionState_t;
 
 // Most of these factors are the result of a lot of tweaking.
 // Change with caution.
@@ -118,13 +118,13 @@ typedef void (*cm_exec_t)(float[], float[]);
 
 
 // All the enums that equal zero must be zero. Don't change this
-enum mpBufferState {              // bf->buffer_state values
+typedef enum {                    // bf->buffer_state values
   MP_BUFFER_EMPTY,                // struct is available for use (MUST BE 0)
   MP_BUFFER_LOADING,              // being written ("checked out")
   MP_BUFFER_QUEUED,               // in queue
   MP_BUFFER_PENDING,              // marked as the next buffer to run
   MP_BUFFER_RUNNING               // current running buffer
-};
+} mpBufferState_t;
 
 
 typedef struct mpBuffer {         // See Planning Velocity Notes
@@ -311,5 +311,3 @@ stat_t mp_dwell(const float seconds);
 // command.c functions
 void mp_queue_command(cm_exec_t cm_exec, float *value, float *flag);
 void mp_runtime_command(mpBuf_t *bf);
-
-
index 786410afdff2c2dbb018d5e686d21e9217c33623..f53f86d0615c96795684742af8e6d4e77d223ec3 100644 (file)
 
 #include "config.h"
 #include "status.h"
+#include "canonical_machine.h"
+#include "plan/planner.h"
 
 #include <stdbool.h>
 
-enum prepBufferState {
+typedef enum {
   PREP_BUFFER_OWNED_BY_LOADER, // staging buffer is ready for load
   PREP_BUFFER_OWNED_BY_EXEC    // staging buffer is being loaded
-};
+} prepBufferState_t;
 
 
 // Currently there is no distinction between IDLE and OFF (DEENERGIZED)
 // In the future IDLE will be powered at a low, torque-maintaining current
 // Used w/start and stop flags to sequence motor power
-enum motorPowerState {
+typedef enum {
   MOTOR_OFF,                    // motor stopped and deenergized
   MOTOR_IDLE,                   // motor stopped and may be partially energized
   MOTOR_RUNNING,                // motor is running (and fully energized)
   MOTOR_POWER_TIMEOUT_START,    // transition state to start power-down timeout
   MOTOR_POWER_TIMEOUT_COUNTDOWN // count down the time to de-energizing motors
-};
+} motorPowerState_t;
 
 
-enum cmMotorPowerMode {
+typedef enum {
   MOTOR_DISABLED,                 // motor enable is deactivated
   MOTOR_ALWAYS_POWERED,           // motor is always powered while machine is ON
   MOTOR_POWERED_IN_CYCLE,         // motor fully powered during cycles,
                                   // de-powered out of cycle
   MOTOR_POWERED_ONLY_WHEN_MOVING, // idles shortly after stopped, even in cycle
   MOTOR_POWER_MODE_MAX_VALUE      // for input range checking
-};
+} cmMotorPowerMode_t;
 
 
-enum {
+typedef enum {
   MOTOR_POLARITY_NORMAL,
   MOTOR_POLARITY_REVERSED
-};
+} cmMotorPolarity_t;
 
 
 /// Min/Max timeouts allowed for motor disable.  Allow for inertial stop.
@@ -305,11 +307,11 @@ enum {
  */
 
 // Per motor config structure
-typedef struct cfgMotor {
+typedef struct {
   uint8_t motor_map;             // map motor to axis
   uint16_t microsteps;           // microsteps to apply for each axis (ex: 8)
-  uint8_t polarity;              // 0=normal polarity, 1=reverse motor direction
-  uint8_t power_mode;            // See cmMotorPowerMode for enum
+  cmMotorPolarity_t polarity;
+  cmMotorPowerMode_t power_mode;
   float step_angle;              // degrees per whole step (ex: 1.8)
   float travel_rev;              // mm or deg of travel per motor revolution
   float steps_per_unit;          // microsteps per mm (or degree) of travel
@@ -318,22 +320,22 @@ typedef struct cfgMotor {
 
 
 /// stepper configs
-typedef struct stConfig {
+typedef struct {
   float motor_power_timeout;     // seconds before idle current
   cfgMotor_t mot[MOTORS];        // settings for motors 1-N
 } stConfig_t;
 
 
 /// Motor runtime structure. Used by step generation ISR (HI)
-typedef struct stRunMotor {      // one per controlled motor
-  uint8_t power_state;           // state machine for managing motor power
+typedef struct {                 // one per controlled motor
+  motorPowerState_t power_state; // state machine for managing motor power
   uint32_t power_systick;        // for next motor power state transition
 } stRunMotor_t;
 
 
 /// Stepper static values and axis parameters
-typedef struct stRunSingleton {
-  uint8_t move_type;
+typedef struct {
+  moveType_t move_type;
   bool busy;
   uint16_t dwell;
   stRunMotor_t mot[MOTORS];      // runtime motor structures
@@ -342,14 +344,14 @@ typedef struct stRunSingleton {
 
 /// Motor prep structure. Used by exec/prep ISR (LO) and read-only during load
 /// Must be careful about volatiles in this one
-typedef struct stPrepMotor {
+typedef struct {
   uint8_t timer_clock;           // clock divisor setting or zero for off
   uint16_t timer_period;         // clock period counter
   uint32_t steps;                // expected steps
 
   // direction and direction change
-  int8_t direction;              // travel direction corrected for polarity
-  uint8_t prev_direction;        // travel direction from previous segment run
+  cmDirection_t direction;       // travel direction corrected for polarity
+  cmDirection_t prev_direction;  // travel direction from previous segment run
   int8_t step_sign;              // set to +1 or -1 for encoders
 
   // step error correction
@@ -358,13 +360,13 @@ typedef struct stPrepMotor {
 } stPrepMotor_t;
 
 
-typedef struct stPrepSingleton {
-  volatile uint8_t buffer_state; // prep buffer state - owned by exec or loader
-  uint8_t move_type;             // move type
-  struct mpBuffer *bf;           // used for command moves
+typedef struct {
+  volatile prepBufferState_t buffer_state; // owned by exec or loader
+  moveType_t move_type;
+  struct mpBuffer *bf;                     // used for command moves
   uint16_t seg_period;
   uint32_t dwell;
-  stPrepMotor_t mot[MOTORS];     // prep time motor structs
+  stPrepMotor_t mot[MOTORS];               // prep time motor structs
 } stPrepSingleton_t;