Prusa MINI Firmware overview
spindle_laser.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 /**
25  * feature/spindle_laser.h
26  * Support for Laser Power or Spindle Power & Direction
27  */
28 
29 #include "../inc/MarlinConfig.h"
30 
31 #if ENABLED(SPINDLE_FEATURE)
32  #define _MSG_CUTTER(M) MSG_SPINDLE_##M
33 #else
34  #define _MSG_CUTTER(M) MSG_LASER_##M
35 #endif
36 #define MSG_CUTTER(M) _MSG_CUTTER(M)
37 
38 #if SPEED_POWER_MAX > 255
39  typedef uint16_t cutter_power_t;
40  #define CUTTER_MENU_TYPE uint16_5
41 #else
43  #define CUTTER_MENU_TYPE uint8
44 #endif
45 
46 class SpindleLaser {
47 public:
49 
50  static void init();
51 
52  static inline bool enabled() { return !!power; }
53 
54  static inline void set_power(const cutter_power_t pwr) { power = pwr; }
55 
56  static inline void refresh() { apply_power(power); }
57 
58  static inline void set_enabled(const bool enable) {
59  const bool was = enabled();
60  set_power(enable ? 255 : 0);
61  if (was != enable) power_delay();
62  }
63 
64  static void apply_power(const cutter_power_t inpow);
65 
66  //static bool active() { return READ(SPINDLE_LASER_ENA_PIN) == SPINDLE_LASER_ACTIVE_HIGH; }
67 
68  static void update_output();
69 
70  #if ENABLED(SPINDLE_LASER_PWM)
71  static void set_ocr(const uint8_t ocr);
72  static inline void set_ocr_power(const cutter_power_t pwr) { power = pwr; set_ocr(pwr); }
73  #endif
74 
75  // Wait for spindle to spin up or spin down
76  static inline void power_delay() {
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  }
81 
82  #if ENABLED(SPINDLE_CHANGE_DIR)
83  static void set_direction(const bool reverse);
84  #else
85  static inline void set_direction(const bool) {}
86  #endif
87 
88  static inline void disable() { set_enabled(false); }
89  static inline void enable_forward() { set_direction(false); set_enabled(true); }
90  static inline void enable_reverse() { set_direction(true); set_enabled(true); }
91 
92 };
93 
94 extern SpindleLaser cutter;
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::disable
static void disable()
Definition: spindle_laser.h:88
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
SpindleLaser cutter
Definition: spindle_laser.cpp:33
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::enable_reverse
static void enable_reverse()
Definition: spindle_laser.h:90
SpindleLaser::apply_power
static void apply_power(const cutter_power_t inpow)
Definition: spindle_laser.cpp:64
uint8_t
const uint8_t[]
Definition: 404_html.c:3
SpindleLaser
Definition: spindle_laser.h:46
SpindleLaser::init
static void init()
Definition: spindle_laser.cpp:39
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
SpindleLaser::enable_forward
static void enable_forward()
Definition: spindle_laser.h:89
analogWrite
void analogWrite(uint32_t ulPin, uint32_t ulValue)
Definition: wiring_analog.c:12
READ
#define READ(IO)
Definition: fastio.h:95
spindle_laser.h
cutter
SpindleLaser cutter
Definition: spindle_laser.cpp:33
SpindleLaser::refresh
static void refresh()
Definition: spindle_laser.h:56
SpindleLaser::update_output
static void update_output()