#include <math.h>
#include <string.h>
#include "hal.h"
#include "protocol.h"
#include "state_machine.h"
#include "settings.h"
Data Structures | |
struct | spindle_reg_t |
Structure for holding spindle registration data. More... | |
struct | spindle_sys_t |
Structure for holding data about an enabled spindle. More... | |
Functions | |
spindle_id_t | spindle_register (const spindle_ptrs_t *spindle, const char *name) |
Register a spindle with the core. More... | |
spindle_num_t | spindle_enable (spindle_id_t spindle_id) |
Enable a spindle and make it available for use by gcode. More... | |
bool | spindle_select (spindle_id_t spindle_id) |
Enables a spindle and sets it as default spindle (spindle number 0). More... | |
spindle_ptrs_t * | spindle_get_hal (spindle_id_t spindle_id, spindle_hal_t hal) |
Get the handlers (function pointers) etc. associated with the spindle. More... | |
spindle_id_t | spindle_get_default (void) |
Get the spindle id of the default spindle (spindle number 0). More... | |
spindle_cap_t | spindle_get_caps (bool active) |
Get the merged spindle capabilities of all registered spindles. More... | |
const char * | spindle_get_name (spindle_id_t spindle_id) |
Get the registered name of a spindle. More... | |
void | spindle_update_caps (spindle_ptrs_t *spindle, spindle_pwm_t *pwm_caps) |
Update the capabilities of a registered PWM spindle. May be used by the driver on spindle initialization or when spindle settings has been changed. More... | |
uint8_t | spindle_get_count (void) |
Get number of registered spindles. More... | |
void | spindle_bind_encoder (const spindle_data_ptrs_t *encoder_data) |
bool | spindle_set_at_speed_range (spindle_ptrs_t *spindle, spindle_data_t *spindle_data, float rpm) |
bool | spindle_enumerate_spindles (spindle_enumerate_callback_ptr callback, void *data) |
Enumerate registered spindles by calling a callback function for each of them. More... | |
bool | spindle_is_enabled (spindle_num_t spindle_num) |
Check if a spindle is enabled and available or not. More... | |
spindle_ptrs_t * | spindle_get (spindle_num_t spindle_num) |
Get the handlers (function pointers) etc. associated with an enabled spindle. More... | |
spindle_id_t | spindle_add_null (void) |
Register a null spindle that has no connection to the outside world. This is done automatically on startup if no spindle can be succesfully enabled. More... | |
void | spindle_set_override (spindle_ptrs_t *spindle, override_t speed_override) |
Set spindle speed override. More... | |
bool | spindle_set_state (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) |
Immediately sets spindle running state with direction and spindle rpm, if enabled. Called by g-code parser spindle_sync(), parking retract and restore, g-code program end, sleep, and spindle stop override. More... | |
bool | spindle_sync (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) |
G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails if an abort or check-mode is active. If the spindle supports at speed functionality it will wait for it to reach the speed and raise an alarm if the speed is not reached within the timeout period. More... | |
bool | spindle_restore (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) |
Restore spindle running state with direction, enable, spindle RPM and appropriate delay. More... | |
float | spindle_set_rpm (spindle_ptrs_t *spindle, float rpm, override_t override_pct) |
Calculate and set programmed RPM according to override and max/min limits. More... | |
void | spindle_all_off (void) |
Turn off all enabled spindles. More... | |
bool | spindle_is_on (void) |
Check if any of the enabled spindles is running. More... | |
bool | spindle_precompute_pwm_values (spindle_ptrs_t *spindle, spindle_pwm_t *pwm_data, spindle_settings_t *settings, uint32_t clock_hz) |
Precompute PWM values for faster conversion. More... | |
spindle_id_t spindle_add_null | ( | void | ) |
Register a null spindle that has no connection to the outside world. This is done automatically on startup if no spindle can be succesfully enabled.
void spindle_all_off | ( | void | ) |
Turn off all enabled spindles.
void spindle_bind_encoder | ( | const spindle_data_ptrs_t * | encoder_data | ) |
spindle_num_t spindle_enable | ( | spindle_id_t | spindle_id | ) |
Enable a spindle and make it available for use by gcode.
spindle_id | spindle id as a spindle_id_t. |
NOTE: up to N_SYS_SPINDLE spindles can be enabled at a time.
bool spindle_enumerate_spindles | ( | spindle_enumerate_callback_ptr | callback, |
void * | data | ||
) |
Enumerate registered spindles by calling a callback function for each of them.
callback | pointer to a spindle_enumerate_callback_ptr type function. |
data | pointer to optional data to pass to the callback function. |
spindle_ptrs_t* spindle_get | ( | spindle_num_t | spindle_num | ) |
Get the handlers (function pointers) etc. associated with an enabled spindle.
spindle_num | spindle number as a spindle_num_t. |
NOTE: do not modify the returned structure!
spindle_cap_t spindle_get_caps | ( | bool | active | ) |
Get the merged spindle capabilities of all registered spindles.
active | true to return active capabilities, false to return default capabilities. |
uint8_t spindle_get_count | ( | void | ) |
Get number of registered spindles.
spindle_id_t spindle_get_default | ( | void | ) |
Get the spindle id of the default spindle (spindle number 0).
spindle_ptrs_t* spindle_get_hal | ( | spindle_id_t | spindle_id, |
spindle_hal_t | hal | ||
) |
Get the handlers (function pointers) etc. associated with the spindle.
spindle_id | spindle id as a spindle_id_t. |
hal | a spindle_hal_t enum value: SpindleHAL_Raw - get the read only version as supplied at registration SpindleHAL_Configured - get the version with run-time modifications applied by the spindle driver. SpindleHAL_Active - get the enabled version available from gcode. Can be overriden by event handlers prior to activation. |
NOTE: do not modify the returned structure!
const char* spindle_get_name | ( | spindle_id_t | spindle_id | ) |
Get the registered name of a spindle.
spindle_id | spindle id as a spindle_id_t. |
bool spindle_is_enabled | ( | spindle_num_t | spindle_num | ) |
Check if a spindle is enabled and available or not.
spindle_num | spindle number as a spindle_num_t. |
bool spindle_is_on | ( | void | ) |
Check if any of the enabled spindles is running.
bool spindle_precompute_pwm_values | ( | spindle_ptrs_t * | spindle, |
spindle_pwm_t * | pwm_data, | ||
spindle_settings_t * | settings, | ||
uint32_t | clock_hz | ||
) |
Precompute PWM values for faster conversion.
spindle | pointer to a spindle_ptrs_t structure. |
pwm_data | pointer to a spindle_pwm_t structure, to hold the precomputed values. |
clock_hz | timer clock frequency used for PWM generation. |
spindle_id_t spindle_register | ( | const spindle_ptrs_t * | spindle, |
const char * | name | ||
) |
Register a spindle with the core.
spindle | pointer to a spindle_ptrs_t structure. |
name | pointer to a null terminated string. |
NOTE: The first spindle registered will become the default active spindle. NOTE: up to N_SPINDLE spindles can be registered at a time.
bool spindle_restore | ( | spindle_ptrs_t * | spindle, |
spindle_state_t | state, | ||
float | rpm | ||
) |
Restore spindle running state with direction, enable, spindle RPM and appropriate delay.
spindle | pointer to a spindle_ptrs_t structure. |
state | a spindle_state_t structure. |
rpm | the spindle RPM to set. |
bool spindle_select | ( | spindle_id_t | spindle_id | ) |
Enables a spindle and sets it as default spindle (spindle number 0).
spindle_id | spindle id as a spindle_id_t. |
bool spindle_set_at_speed_range | ( | spindle_ptrs_t * | spindle, |
spindle_data_t * | spindle_data, | ||
float | rpm | ||
) |
void spindle_set_override | ( | spindle_ptrs_t * | spindle, |
override_t | speed_override | ||
) |
Set spindle speed override.
spindle | pointer to a spindle_ptrs_t structure. |
speed_override | override as a percentage of the programmed RPM. |
NOTE: Unlike motion overrides, spindle overrides do not require a planner reinitialization.
float spindle_set_rpm | ( | spindle_ptrs_t * | spindle, |
float | rpm, | ||
override_t | override_pct | ||
) |
Calculate and set programmed RPM according to override and max/min limits.
spindle | pointer to a spindle_ptrs_t structure. |
rpm | the programmed RPM. |
override_pct | override value in percent. |
bool spindle_set_state | ( | spindle_ptrs_t * | spindle, |
spindle_state_t | state, | ||
float | rpm | ||
) |
Immediately sets spindle running state with direction and spindle rpm, if enabled. Called by g-code parser spindle_sync(), parking retract and restore, g-code program end, sleep, and spindle stop override.
spindle | pointer to a spindle_ptrs_t structure. |
state | a spindle_state_t structure. |
rpm | the spindle RPM to set. |
bool spindle_sync | ( | spindle_ptrs_t * | spindle, |
spindle_state_t | state, | ||
float | rpm | ||
) |
G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails if an abort or check-mode is active. If the spindle supports at speed functionality it will wait for it to reach the speed and raise an alarm if the speed is not reached within the timeout period.
spindle | pointer to a spindle_ptrs_t structure. |
state | a spindle_state_t structure. |
rpm | the spindle RPM to set. |
void spindle_update_caps | ( | spindle_ptrs_t * | spindle, |
spindle_pwm_t * | pwm_caps | ||
) |
Update the capabilities of a registered PWM spindle. May be used by the driver on spindle initialization or when spindle settings has been changed.
spindle | pointer to a spindle_ptrs_t structure. |
pwm_caps | pointer to a spindle_pwm_t structure. |