Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 5bbc3ce4b20f95ab753444dff7c0df93a389652d
Author: ThomasToka <[email protected]>
Date:   Thu Aug 3 01:32:45 2023 +0200

    disable eeprom for volume

commit 45d65ba
Author: ThomasToka <[email protected]>
Date:   Wed Aug 2 22:19:05 2023 +0200

    fixed flow percentage commit

commit fca55cf
Author: ThomasToka <[email protected]>
Date:   Wed Aug 2 19:32:21 2023 +0200

    volume and autoscroll part1

commit e5af607
Author: ThomasToka <[email protected]>
Date:   Mon Jul 31 21:58:06 2023 +0200

    laser cardreader upgrade

commit 723d599
Merge: c68849c 2c80874
Author: ThomasToka <[email protected]>
Date:   Mon Jul 31 21:22:30 2023 +0200

    Merge branch 'MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v005-dev' of https://github.com/ThomasToka/Marlin into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v005-dev

commit c68849c
Author: ThomasToka <[email protected]>
Date:   Mon Jul 31 21:21:52 2023 +0200

    the cardreader upgrade

    activating 40 maxfiles and 8 sites

commit 2c80874
Merge: 4cc3696 5da7143
Author: ThomasToka <[email protected]>
Date:   Mon Jul 31 12:41:54 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v005-dev

commit 0056c71
Author: ThomasToka <[email protected]>
Date:   Sat Jul 29 18:11:33 2023 +0200

    reverse temporary changes to marlin state

commit 4cc3696
Author: ThomasToka <[email protected]>
Date:   Sat Jul 29 17:54:56 2023 +0200

    Fixing powerloss as bugfix-2.1.x is buggy

commit c5199ef
Author: ThomasToka <[email protected]>
Date:   Fri Jul 28 15:12:27 2023 +0200

    v004 screen source update

commit c4c4b28
Author: ThomasToka <[email protected]>
Date:   Fri Jul 28 13:02:03 2023 +0200

    serial silence

commit f3f2881
Author: ThomasToka <[email protected]>
Date:   Fri Jul 28 12:49:04 2023 +0200

    m3 m5 float with disabled laser device

commit 6233ef7
Merge: 1a3f46b 2a82ca8
Author: ThomasToka <[email protected]>
Date:   Fri Jul 28 09:43:21 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v004-dev

commit 1a3f46b
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 22:16:18 2023 +0200

    laser feature updates part6

commit 0ab5906
Merge: 9583124 6ba50aa
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 19:29:18 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v004-dev

commit 9583124
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 19:14:50 2023 +0200

    laser feature updates part5

commit 9c9d6f3
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 18:53:22 2023 +0200

    laser feature updates part4

commit a07abe4
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 17:49:19 2023 +0200

    laser feature cardreader fix

commit 0167db2
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 16:33:58 2023 +0200

    laser feature range update

commit 8d84dc0
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 16:05:43 2023 +0200

    laser feature updates part3

commit 7e6361a
Author: ThomasToka <[email protected]>
Date:   Thu Jul 27 15:26:44 2023 +0200

    laser feature update part2

commit 94b26fb
Author: ThomasToka <[email protected]>
Date:   Tue Jul 25 22:53:06 2023 +0200

    powerloss / pin / runout save

commit 6a92159
Author: ThomasToka <[email protected]>
Date:   Tue Jul 25 11:54:02 2023 +0200

    laser feature power update first try

commit a85d32e
Merge: 9bc1796 79be07f
Author: ThomasToka <[email protected]>
Date:   Tue Jul 25 00:27:27 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v004-dev

commit 9bc1796
Author: ThomasToka <[email protected]>
Date:   Tue Jul 25 00:26:41 2023 +0200

    powercontinue follow up

    feedrates yet to be fixed..

commit 004eb2c
Author: ThomasToka <[email protected]>
Date:   Mon Jul 24 17:34:40 2023 +0200

    the bool update

commit 5884496
Author: ThomasToka <[email protected]>
Date:   Mon Jul 24 17:04:19 2023 +0200

    home offset threshold

commit d489bb8
Author: ThomasToka <[email protected]>
Date:   Mon Jul 24 16:44:40 2023 +0200

    powerrecover updates

commit 1c65875
Merge: 3f64061 e451dec
Author: ThomasToka <[email protected]>
Date:   Sun Jul 23 23:23:33 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v004-dev

commit 3f64061
Author: ThomasToka <[email protected]>
Date:   Sun Jul 23 23:22:42 2023 +0200

    v004 updates

commit 782a92d
Author: ThomasToka <[email protected]>
Date:   Sat Jul 22 10:39:28 2023 +0200

    including my Marlin PR MarlinFirmware#26099

    Add M221 to M503/M502
    MarlinFirmware#26099

commit 5a6132d
Author: ThomasToka <[email protected]>
Date:   Fri Jul 21 20:50:11 2023 +0200

    add version to filenames

    - remove -LA- as all builds include LA
    - add version string for better recognization of versions

commit 6f24287
Author: ThomasToka <[email protected]>
Date:   Fri Jul 21 18:35:04 2023 +0200

    Add extruder flowrate to M221 report followup

    Add M211 to the report followup
    reset and default value

commit 4becd4a
Merge: 23e5711 91c6a71
Author: ThomasToka <[email protected]>
Date:   Fri Jul 21 10:26:04 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v004-dev

commit 23e5711
Author: ThomasToka <[email protected]>
Date:   Fri Jul 21 10:09:10 2023 +0200

    trying to read screen version from the stream

commit 5e43853
Author: ThomasToka <[email protected]>
Date:   Thu Jul 20 18:31:03 2023 +0200

    laser feature babystepping fix after upstream change

commit 5db4f00
Merge: a951d3d 6bc4230
Author: ThomasToka <[email protected]>
Date:   Thu Jul 20 15:14:41 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v004-dev

commit a951d3d
Author: ThomasToka <[email protected]>
Date:   Thu Jul 20 12:03:11 2023 +0200

    screen files update

    visual bug on the adjust page for zoffset fixed

commit c9abe8d
Author: ThomasToka <[email protected]>
Date:   Wed Jul 19 17:41:55 2023 +0200

    M221 on M503 fix

    output fix

commit 59239d2
Author: ThomasToka <[email protected]>
Date:   Wed Jul 19 16:29:14 2023 +0200

    auto cr-touch point 1 fix / screen v003 release

    - point 1 was misscalculated on cr-touch autorun. fixed.
    - screen v003 incl source release

commit 0773c09
Author: ThomasToka <[email protected]>
Date:   Wed Jul 19 15:02:29 2023 +0200

    m221 report update

    Implemented M221 report on M503

commit 6c4ef51
Author: ThomasToka <[email protected]>
Date:   Wed Jul 19 12:47:32 2023 +0200

    v003 update fixes

    - flag v003
    - enabled gcode_repeat_markers
    - adjusted abl and meshviewer vor 7x7 and 10x10 versions
    - added flow
    - extended home_offset function
    - disabled sd_finished_releasecommand as we do it in end gcode if needed

commit faac038
Merge: f88f40d 885e9cc
Author: ThomasToka <[email protected]>
Date:   Wed Jul 19 12:44:55 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v003-dev

commit f88f40d
Author: ThomasToka <[email protected]>
Date:   Mon Jul 17 11:51:03 2023 +0200

    format fix runout.cpp

commit 342695e
Merge: 7267d25 244de24
Author: ThomasToka <[email protected]>
Date:   Mon Jul 17 11:49:26 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v003-dev

commit 7267d25
Author: ThomasToka <[email protected]>
Date:   Sun Jul 16 21:30:04 2023 +0200

    fix runout status an all events

    - fix runout disabled status on all events (start,pause, etc)

commit bc2daee
Merge: 59f42f7 810c169
Author: ThomasToka <[email protected]>
Date:   Sun Jul 16 21:28:51 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE-v003-dev

commit 59f42f7
Author: ThomasToka <[email protected]>
Date:   Sun Jul 16 21:28:00 2023 +0200

    v003 updates

    - reintroduce 7x7 and 10x10 build generally
    - add abl7x7 and abl10x10 builds
    - fix runout disabled status on all events (start,pause, etc)

commit 2d02ccd
Author: ThomasToka <[email protected]>
Date:   Sun Jul 16 00:49:41 2023 +0200

    past v002 ubl fix

    tramming points fix for cr-touch and tramming with ubl

commit c6c4d14
Author: ThomasToka <[email protected]>
Date:   Sat Jul 15 18:16:12 2023 +0200

    Updated Screenfiles cause of missing font

commit 5e86301
Author: ThomasToka <[email protected]>
Date:   Sat Jul 15 14:54:29 2023 +0200

    Screen firmware source code upload

    Additionally:
    - z_values output to serial not needed so deactivated
    - home offset serial output only in debug mode

commit 6c62210
Merge: ff8af9b 28f69a0
Author: ThomasToka <[email protected]>
Date:   Sat Jul 15 12:48:51 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-v002-dev

commit ff8af9b
Author: ThomasToka <[email protected]>
Date:   Sat Jul 15 12:47:53 2023 +0200

    v002 update configs and last minute fixes

    -safe tramming points after M84
    -no workspace offsets
    -ubl grid point fixes

commit 1fc9ebc
Author: ThomasToka <[email protected]>
Date:   Tue Jun 20 19:15:59 2023 +0200

    Revert M206 Home Offset behavior MarlinFirmware#25996

    MarlinFirmware#25996

commit 2e437a8
Author: ThomasToka <[email protected]>
Date:   Wed Jul 12 18:40:40 2023 +0200

    point_num_real meshviewer fix

    fixes point_num_real to match the address space of the mashviewer.

commit 0039d17
Author: ThomasToka <[email protected]>
Date:   Wed Jul 12 17:15:31 2023 +0200

    PR compatibilty

    changes only if needed and then in a "enabled" area.

commit 59f98b3
Author: ThomasToka <[email protected]>
Date:   Wed Jul 12 15:08:00 2023 +0200

    The Filament runout icon update

commit 20a88f5
Author: ThomasToka <[email protected]>
Date:   Wed Jul 12 14:12:29 2023 +0200

    The UBL Update - stabilizing

    should work reliably now :)

commit c78c4b0
Author: ThomasToka <[email protected]>
Date:   Tue Jul 11 22:34:00 2023 +0200

    The UBL Update - first try correction

    seems to work :-)

commit 4edfefd
Author: ThomasToka <[email protected]>
Date:   Tue Jul 11 21:43:15 2023 +0200

    The UBL Update - first try..

    loading after reboot still broken.. investigating..

commit 8e8ceb5
Merge: 52c4ae9 bcf61cc
Author: ThomasToka <[email protected]>
Date:   Thu Jul 6 11:15:50 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-v001-JULI-UPDATE

commit 52c4ae9
Merge: 608e4a3 57d26f7
Author: ThomasToka <[email protected]>
Date:   Wed Jul 5 14:06:31 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-v001-JULI-UPDATE

commit 608e4a3
Merge: 66afd46 87b2af2
Author: ThomasToka <[email protected]>
Date:   Tue Jul 4 20:19:22 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-v001-JULI-UPDATE

commit 87b2af2
Author: thinkyhead <[email protected]>
Date:   Tue Jul 4 06:06:45 2023 +0000

    [cron] Bump distribution date (2023-07-04)

commit 9799b57
Author: Scott Lahteine <[email protected]>
Date:   Sat Jul 1 20:38:17 2023 -0500

    🎨 Misc. fixes and formatting

commit 66afd46
Merge: 07cc565 4a734e4
Author: ThomasToka <[email protected]>
Date:   Mon Jun 26 14:03:05 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit 07cc565
Merge: bb79690 60f591f
Author: ThomasToka <[email protected]>
Date:   Mon Jun 26 13:58:01 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit bb79690
Merge: 139fee9 2dc7668
Author: ThomasToka <[email protected]>
Date:   Tue Jun 20 18:27:23 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit 139fee9
Merge: 4b7cd78 733209f
Author: ThomasToka <[email protected]>
Date:   Mon Jun 19 13:22:27 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit 4b7cd78
Merge: 8f4674c dd1792b
Author: ThomasToka <[email protected]>
Date:   Sun Jun 18 10:40:30 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit 8f4674c
Merge: a958692 eca80db
Author: ThomasToka <[email protected]>
Date:   Fri Jun 16 13:00:53 2023 +0200

    Merge branch 'bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit a958692
Author: ThomasToka <[email protected]>
Date:   Tue Jun 13 20:28:00 2023 +0200

    PlatformIO Name output Fix

    Unified the output of the compile files after upstream commit

commit d6c501d
Merge: 361ee45 1726ba5
Author: ThomasToka <[email protected]>
Date:   Tue Jun 13 19:53:50 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit 361ee45
Author: ThomasToka <[email protected]>
Date:   Sun Jun 11 15:08:53 2023 +0200

    build system simplyfied after upstream commit

commit ad3b7c4
Merge: 9e791cc fd632da
Author: ThomasToka <[email protected]>
Date:   Sun Jun 11 14:19:29 2023 +0200

    Merge branch 'MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE' of https://github.com/ThomasToka/Marlin into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit fd632da
Merge: df2e2d8 85067e1
Author: ThomasToka <[email protected]>
Date:   Sun Jun 11 14:19:09 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit 9e791cc
Author: ThomasToka <[email protected]>
Date:   Sun Jun 11 14:12:01 2023 +0200

    laser feature readjusted

    - laser feature enable in build system for ablbuilds
    - laser feature disable globally so ubl is buildable again

commit df2e2d8
Merge: d5edd7b b5d3d01
Author: ThomasToka <[email protected]>
Date:   Sat Jun 10 16:46:27 2023 +0200

    Merge branch 'MarlinFirmware:bugfix-2.1.x' into MARLIN-E3S1PROFORK-BYTT-RELEASE-CODE

commit d5edd7b
Author: ThomasToka <[email protected]>
Date:   Sat Jun 10 16:41:16 2023 +0200

    MARLIN-E3S1PROFORK-BYTT initial commit

    This is MARLIN-E3S1PRO-FORK-BYTT Release Candidate 1.

    This fork was ported from the Original Creality Ender 3 S1 Pro Code from here:
    https://github.com/CrealityOfficial/Ender-3S1/tree/s1_pro

    This port was created by Thomas Toka.

    This code is based on Marlin bugfix-2.1.x taken from:
    Marlin Github
    on the 21st may 2023 after this commit:
    MarlinFirmware@06b1f85

    Other Code was implemented from:
    Creality Github
    Synman Github
    Mriscoc Github
    johncarlson21 Github

    Initial commit code taken from the Creality Ender 3 S1 Github Repo:
    CrealityOfficial/Ender-3S1@f8be17f

    Crosschecked with the initial and following commits of Synman:
    synman@25d641e

    Laser implementation partly taken from Creality´s commit from:
    CrealityOfficial/Ender-3S1@cb5f3c3

    Extended temperature table from mriscoc from:
    https://github.com/mriscoc/Ender3V2S1/blob/Ender3V2S1-Released/Marlin/src/module/thermistor/thermistor_1.h#L27

    Cardreader Update inspiration taken from:
    https://github.com/CrealityOfficial/CR-10-Smart-Pro/blob/main/Marlin/src/lcd/dwin/lcd_rts.cpp

    Autopid implementation taken from here:
    https://github.com/CrealityOfficial/Ender-5S1

    Meshviewer taken from:
    https://github.com/johncarlson21/SV04-Marlin-2.1.x
  • Loading branch information
ThomasToka committed Aug 2, 2023
1 parent 5da7143 commit 7252450
Show file tree
Hide file tree
Showing 90 changed files with 12,398 additions and 390 deletions.
619 changes: 502 additions & 117 deletions Marlin/Configuration.h

Large diffs are not rendered by default.

226 changes: 140 additions & 86 deletions Marlin/Configuration_adv.h

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions Marlin/src/HAL/STM32/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,116 @@ static constexpr bool verify_no_timer_conflicts() {
// when hovering over it, making it easy to identify the conflicting timers.
static_assert(verify_no_timer_conflicts(), "One or more timer conflict detected. Examine \"timers_in_use\" to help identify conflict.");

#if ALL(E3S1PRO_RTS, LASER_FEATURE)

#define LASER_TIMER_NUM 3
#define LASER_TIMER_DEV _TIMER_DEV(LASER_TIMER_NUM)
#define LASER_TIMER_PRESCALE(timer_clk, freq) ((timer_clk) / ((freq) * (LASER_TIMER_PWM_MAX + 1)))
#define LASER_TIMER_IRQ_PRIO 1

typedef enum
{
LASER_PWM_STATE_L = 0,
LASER_PWM_STATE_H
}laser_pwm_state_t;

static HardwareTimer *timer_laser = nullptr;
static uint8_t laser_h = 0, laser_l = 0;
static laser_pwm_state_t laser_pwm_state;

FORCE_INLINE static void laser_timer_set_compare(const hal_timer_t overflow)
{
if (timer_laser)
{
timer_laser->setOverflow(overflow + 1, TICK_FORMAT);
if (overflow < timer_laser->getCount())
timer_laser->refresh();
}
}

static void laser_timer_handler(void)
{
// SERIAL_ECHO_MSG("laser_timer_handler");

switch(laser_pwm_state)
{
case LASER_PWM_STATE_L:
laser_timer_set_compare(laser_h);
WRITE(LASER_SOFT_PWM_PIN, 1);
laser_pwm_state = LASER_PWM_STATE_H;
break;
case LASER_PWM_STATE_H:
laser_timer_set_compare(laser_l);
WRITE(LASER_SOFT_PWM_PIN, 0);
laser_pwm_state = LASER_PWM_STATE_L;
break;
}
}

void laser_timer_soft_pwm_start(uint8_t pwm)
{
// SERIAL_ECHOLNPAIR("laser_timer_soft_pwm_start():", pwm);

if(timer_laser == nullptr) return;

if(pwm > LASER_TIMER_PWM_MAX) pwm = LASER_TIMER_PWM_MAX;

if(pwm == 0x00)
{
laser_timer_soft_pwm_stop();
}
else if(pwm == 0xFF)
{
timer_laser->pause();
OUT_WRITE(LASER_SOFT_PWM_PIN, 1);
}
else
{
timer_laser->pause();
laser_pwm_state = LASER_PWM_STATE_H;
WRITE(LASER_SOFT_PWM_PIN, 1);
laser_l = LASER_TIMER_PWM_MAX - pwm;
laser_h = pwm;
laser_timer_set_compare(laser_h);
timer_laser->resume();
// 立即进入中断 -> 设置为0无法触发中断
// laser_timer_set_compare(0);
}
}


void laser_timer_soft_pwm_stop(void)
{
// SERIAL_ECHO_MSG("laser_timer_soft_pwm_stop()");

laser_timer_soft_pwm_start(1);
}

void laser_timer_soft_pwm_close()
{
// SERIAL_ECHO_MSG("laser_timer_soft_pwm_close()");

if(timer_laser == nullptr) return;

timer_laser->pause();
WRITE(LASER_SOFT_PWM_PIN, 0);
}

void laser_timer_soft_pwm_init()
{
const uint32_t frequency = LASER_TIMER_FREQUENCY;
if(timer_laser == nullptr)
{
timer_laser = new HardwareTimer(LASER_TIMER_DEV);
uint32_t prescale = LASER_TIMER_PRESCALE(timer_laser->getTimerClkFreq(), frequency);
timer_laser->setPrescaleFactor(prescale);
timer_laser->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (timer_laser->getTimerClkFreq()) / (prescale) /* /frequency */), TICK_FORMAT);
timer_laser->setPreloadEnable(false);
if(!timer_laser->hasInterrupt()) timer_laser->attachInterrupt(laser_timer_handler);
timer_laser->pause();
timer_laser->setInterruptPriority(LASER_TIMER_IRQ_PRIO, 0);
}
}
#endif //#if HAS_CUTTER

#endif // HAL_STM32
10 changes: 10 additions & 0 deletions Marlin/src/HAL/STM32/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const ha

#define HAL_timer_isr_prologue(T) NOOP
#define HAL_timer_isr_epilogue(T) NOOP

#if ALL(E3S1PRO_RTS, LASER_FEATURE)
#define LASER_TIMER_FREQUENCY 1000 // PWM freq:1000Hz
#define LASER_TIMER_PWM_MAX 255 // PWM value range: 0~255

void laser_timer_soft_pwm_init();
void laser_timer_soft_pwm_start(uint8_t pwm);
void laser_timer_soft_pwm_stop(void);
void laser_timer_soft_pwm_close();
#endif
75 changes: 75 additions & 0 deletions Marlin/src/HAL/STM32F1/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,79 @@ timer_dev* HAL_get_timer_dev(int number) {
}
}

#if ALL(E3S1PRO_RTS, LASER_FEATURE)
static unsigned int sw=0, laser_h = 0, laser_l = 0;

void laser_timer_soft_pwm_start(uint8_t pwm)
{
//SERIAL_ECHOLNPAIR("laser_timer_soft_pwm_start():", pwm);

if(pwm>255) pwm =255;
if(pwm<=0) pwm = 1;

if(pwm <= 0X00){//
timer_pause(LASER_TIMER_DEV);
WRITE(LASER_SOFT_PWM_PIN, 0); //WRITE(PC0, 0);
}else if(pwm>=0xFE){
timer_pause(LASER_TIMER_DEV);

WRITE(LASER_SOFT_PWM_PIN, 1); //WRITE(PC0, 0);
}else{
timer_pause(LASER_TIMER_DEV);
sw = 0;
laser_l = 256 - pwm;
laser_h = pwm;
timer_resume(LASER_TIMER_DEV);
}
}

void laser_timer_soft_pwm_stop(void)
{
// SERIAL_ECHO_MSG("laser_timer_soft_pwm_stop()");
// SERIAL_ECHOLNPAIR(str, val)

laser_timer_soft_pwm_start(1);
}

void laser_timer_soft_pwm_close()
{
timer_pause(LASER_TIMER_DEV);
WRITE(LASER_SOFT_PWM_PIN, 0);//WRITE(PC0, 0);
}

void laser_timer_handler(void)
{
// SERIAL_ECHO_MSG("laser_timer_handler");

switch(sw)
{
case 0:
timer_set_reload(LASER_TIMER_DEV, laser_l);//0xFFFF);
WRITE(LASER_SOFT_PWM_PIN, 1);//WRITE(PC0, 1);
sw = 1;
break;
case 1:
timer_set_reload(LASER_TIMER_DEV, laser_h);//0xFFFF);
WRITE(LASER_SOFT_PWM_PIN, 0);//WRITE(PC0, 0);
sw=0;
break;
}
}

void laser_timer_soft_pwm_init()
{
const uint32_t frequency = LASER_TIMER_FREQUENCY;
timer_pause(LASER_TIMER_DEV);
//timer_set_mode(LASER_TIMER_DEV, TEMP_TIMER_CHAN, TIMER_OUTPUT_COMPARE);
timer_set_count(LASER_TIMER_DEV, 0);
timer_set_prescaler(LASER_TIMER_DEV, (uint16_t)(LASER_TIMER_PRESCALE(frequency) - 1));
timer_set_reload(LASER_TIMER_DEV, LASER_TIMER_PWM_MAX);//0xFFFF);
//timer_set_compare(LASER_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (F_CPU) / (LASER_TIMER_PRESCALE) / frequency));
timer_attach_interrupt(LASER_TIMER_DEV, TEMP_TIMER_CHAN, laser_timer_handler);
timer_set_interrupt_priority(LASER_TIMER_NUM, LASER_TIMER_IRQ_PRIO);
timer_generate_update(LASER_TIMER_DEV);
// timer_resume(LASER_TIMER_DEV);
}
#endif //#if LASER_FEATURE

#endif // __STM32F1__
15 changes: 15 additions & 0 deletions Marlin/src/HAL/STM32F1/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,18 @@ FORCE_INLINE static void timer_no_ARR_preload_ARPE(timer_dev *dev) {
void HAL_timer_set_interrupt_priority(uint_fast8_t timer_num, uint_fast8_t priority);

#define TIMER_OC_NO_PRELOAD 0 // Need to disable preload also on compare registers.

#if ALL(E3S1PRO_RTS, LASER_FEATURE)
#define LASER_TIMER_NUM 3
#define LASER_TIMER_DEV TIMER_DEV(LASER_TIMER_NUM)
#define LASER_TIMER_FREQUENCY 1000 // PWM freq:1000Hz
#define LASER_TIMER_PWM_MAX 255 // PWM value range: 0~255
#define LASER_TIMER_PRESCALE(freq) (HAL_TIMER_RATE / (freq * (LASER_TIMER_PWM_MAX + 1))) // (72M/1000*256)=281
#define LASER_TIMER_CHAN 1
#define LASER_TIMER_IRQ_PRIO 1

void laser_timer_soft_pwm_init();
void laser_timer_soft_pwm_start(uint8_t pwm);
void laser_timer_soft_pwm_stop(void);
void laser_timer_soft_pwm_close();
#endif
Loading

0 comments on commit 7252450

Please sign in to comment.