Prusa MINI Firmware overview
SpindleLaser Class Reference

#include <spindle_laser.h>

Collaboration diagram for SpindleLaser:

Static Public Member Functions

static void init ()
 
static bool enabled ()
 
static void set_power (const cutter_power_t pwr)
 
static void refresh ()
 
static void set_enabled (const bool enable)
 
static void apply_power (const cutter_power_t inpow)
 
static void update_output ()
 
static void power_delay ()
 
static void set_direction (const bool)
 
static void disable ()
 
static void enable_forward ()
 
static void enable_reverse ()
 

Static Public Attributes

static cutter_power_t power
 

Member Function Documentation

◆ init()

void SpindleLaser::init ( )
static
39  {
40  OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_HIGH); // Init spindle to off
41  #if ENABLED(SPINDLE_CHANGE_DIR)
42  OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3)
43  #endif
44  #if ENABLED(SPINDLE_LASER_PWM)
47  #endif
48 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enabled()

static bool SpindleLaser::enabled ( )
static
52 { return !!power; }
Here is the caller graph for this function:

◆ set_power()

static void SpindleLaser::set_power ( const cutter_power_t  pwr)
static
54 { power = pwr; }
Here is the caller graph for this function:

◆ refresh()

static void SpindleLaser::refresh ( )
static
56 { apply_power(power); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_enabled()

static void SpindleLaser::set_enabled ( const bool  enable)
static
58  {
59  const bool was = enabled();
60  set_power(enable ? 255 : 0);
61  if (was != enable) power_delay();
62  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_power()

void SpindleLaser::apply_power ( const cutter_power_t  inpow)
static
64  {
65  static cutter_power_t last_power_applied = 0;
66  if (inpow == last_power_applied) return;
67  last_power_applied = inpow;
68  #if ENABLED(SPINDLE_LASER_PWM)
69  if (enabled()) {
70  #define _scaled(F) ((F - (SPEED_POWER_INTERCEPT)) * inv_slope)
71  constexpr float inv_slope = RECIPROCAL(SPEED_POWER_SLOPE),
72  min_ocr = _scaled(SPEED_POWER_MIN),
73  max_ocr = _scaled(SPEED_POWER_MAX);
74  int16_t ocr_val;
75  if (inpow <= SPEED_POWER_MIN) ocr_val = min_ocr; // Use minimum if set below
76  else if (inpow >= SPEED_POWER_MAX) ocr_val = max_ocr; // Use maximum if set above
77  else ocr_val = _scaled(inpow); // Use calculated OCR value
78  set_ocr(ocr_val & 0xFF); // ...limited to Atmel PWM max
79  }
80  else {
81  WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_HIGH); // Turn spindle off (active low)
83  }
84  #else
85  WRITE(SPINDLE_LASER_ENA_PIN, (SPINDLE_LASER_ACTIVE_HIGH) ? enabled() : !enabled());
86  #endif
87 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_output()

static void SpindleLaser::update_output ( )
static

◆ power_delay()

static void SpindleLaser::power_delay ( )
static
76  {
77  #if SPINDLE_LASER_POWERUP_DELAY || SPINDLE_LASER_POWERDOWN_DELAY
78  safe_delay(enabled() ? SPINDLE_LASER_POWERUP_DELAY : SPINDLE_LASER_POWERDOWN_DELAY);
79  #endif
80  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_direction()

static void SpindleLaser::set_direction ( const bool  )
static
85 {}
Here is the caller graph for this function:

◆ disable()

static void SpindleLaser::disable ( )
static
88 { set_enabled(false); }
Here is the call graph for this function:

◆ enable_forward()

static void SpindleLaser::enable_forward ( )
static
89 { set_direction(false); set_enabled(true); }
Here is the call graph for this function:

◆ enable_reverse()

static void SpindleLaser::enable_reverse ( )
static
90 { set_direction(true); set_enabled(true); }
Here is the call graph for this function:

Member Data Documentation

◆ power

cutter_power_t SpindleLaser::power
static
OUT_WRITE
#define OUT_WRITE(IO, V)
Definition: fastio.h:108
SpindleLaser::set_enabled
static void set_enabled(const bool enable)
Definition: spindle_laser.h:58
SpindleLaser::power
static cutter_power_t power
Definition: spindle_laser.h:48
RECIPROCAL
#define RECIPROCAL(x)
Definition: macros.h:273
SET_PWM
#define SET_PWM(IO)
Definition: fastio.h:103
SPINDLE_LASER_PWM_PIN
#define SPINDLE_LASER_PWM_PIN
Definition: pins_MEGACONTROLLER.h:162
SPINDLE_LASER_ENA_PIN
#define SPINDLE_LASER_ENA_PIN
Definition: pins_MEGACONTROLLER.h:163
cutter_power_t
uint8_t cutter_power_t
Definition: spindle_laser.h:42
pin_t
int8_t pin_t
Definition: HAL.h:65
SpindleLaser::set_power
static void set_power(const cutter_power_t pwr)
Definition: spindle_laser.h:54
SPINDLE_DIR_PIN
#define SPINDLE_DIR_PIN
Definition: pins_MEGACONTROLLER.h:164
SpindleLaser::set_direction
static void set_direction(const bool)
Definition: spindle_laser.h:85
SpindleLaser::power_delay
static void power_delay()
Definition: spindle_laser.h:76
SpindleLaser::enabled
static bool enabled()
Definition: spindle_laser.h:52
WRITE
#define WRITE(IO, V)
Definition: fastio.h:96
SpindleLaser::apply_power
static void apply_power(const cutter_power_t inpow)
Definition: spindle_laser.cpp:64
safe_delay
void safe_delay(millis_t ms)
Definition: utility.cpp:28
SPINDLE_LASER_PWM_OFF
#define SPINDLE_LASER_PWM_OFF
Definition: spindle_laser.cpp:37
analogWrite
void analogWrite(uint32_t ulPin, uint32_t ulValue)
Definition: wiring_analog.c:12