Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
1020 commits
Select commit Hold shift + click to select a range
7a60a36
I2C slave support for Pyportal Titano M4
JordanMajd Oct 31, 2019
04a2dd8
Preserve original formatting on base sercom handler
JordanMajd Oct 31, 2019
2b052e1
Reenable Serial1 sercom int handlers, disable Wire i2c slave int hand…
JordanMajd Oct 31, 2019
feb846a
add monster m4sk too
ladyada Nov 3, 2019
6be0d1f
Merge branch 'JordanMajd-patch_samd51_i2c_slave'
ladyada Nov 3, 2019
9df0b07
fix i2c for peripheral use thanks to https://github.com/adafruit/Ardu…
ladyada Nov 3, 2019
a2c0a5b
SAMD21: Fix freq clipping in SPI.h, allow 24 MHz SPI
PaintYourDragon Nov 4, 2019
361481d
Merge pull request #186 from adafruit/baud-fix
ladyada Nov 4, 2019
7f3211f
tinyusb: Correct descriptor string length calculation
kaysievers Nov 19, 2019
5f68c65
Merge pull request #182 from kaysievers/tinyusb-descriptor-len
hathach Nov 19, 2019
6630fe7
@hathach Arduino core now wants size_t returned
ladyada Dec 11, 2019
516cec5
Merge branch 'master' of github.com:adafruit/ArduinoCore-samd
ladyada Dec 11, 2019
4cca5de
Merge remote-tracking branch 'adafruit/master'
hathach Dec 18, 2019
dfac9e8
move tinyusb core & cdc to submodule
hathach Dec 19, 2019
2bb0a7a
tinyusb submodule work well
hathach Dec 19, 2019
a346cf7
implement detach/attach
hathach Dec 19, 2019
b92b61b
refactor load_serial_number() to Adafruit_USBD_Device::getSerialDescr…
hathach Dec 19, 2019
4f8ccb1
move yield() to main.cpp
hathach Dec 19, 2019
dd19013
rename Adafruit_TinyUSB_Core.cpp to Adafruit_TinyUSB_SAMD.cpp
hathach Dec 19, 2019
bffd304
clean up
hathach Dec 19, 2019
21b3e13
update tinyusb core
hathach Dec 20, 2019
f996c94
clean up
hathach Dec 20, 2019
1941e17
Merge pull request #190 from hathach/develop
ladyada Dec 20, 2019
31fc54d
added option to debug tinyusb with Serial1
hathach Dec 24, 2019
861fec5
update tinyusb core
hathach Dec 24, 2019
b1a7975
Merge pull request #192 from hathach/develop
hathach Dec 24, 2019
2179f63
tinyusb core: improve setup handling
hathach Dec 25, 2019
1dcf3c5
Merge pull request #193 from hathach/develop
hathach Dec 25, 2019
8e3c4bc
improve tinyusb samd driver
hathach Dec 26, 2019
2ca9dfd
update tinyusb core
hathach Dec 27, 2019
2bf2a37
Merge pull request #194 from hathach/develop
hathach Dec 27, 2019
99f1fa3
Removing _dacResolution for no-__SAMD51__ (variable not used)
Dec 29, 2019
32e5394
Increase version for release
hathach Dec 30, 2019
fc737be
revert 6630fe7cc0b5a393a54e6c6df20682685a91fb4c availableForWrite() r…
hathach Dec 31, 2019
18b64d4
Merge pull request #199 from hathach/develop
hathach Dec 31, 2019
137c0bd
increase version to 1.5.9 for release
hathach Dec 31, 2019
411cfa6
test metro_m0 build
hathach Jan 2, 2020
90c0b48
add build all script
hathach Jan 2, 2020
1595e2f
update lib deps
hathach Jan 2, 2020
9d9b509
add metro_m4 test
hathach Jan 2, 2020
c53c443
build most of adafruit samd boards
hathach Jan 2, 2020
bab8b92
add skip file
hathach Jan 2, 2020
2cc7f72
drop monster_m4sk
hathach Jan 2, 2020
f2a2126
add action badge to readme
hathach Jan 2, 2020
c14e078
Merge pull request #200 from hathach/action-ci
ladyada Jan 2, 2020
ed2dded
fix https://github.com/adafruit/ArduinoCore-samd/issues/187
ladyada Jan 7, 2020
4cc3251
Merge branch 'master' of github.com:adafruit/ArduinoCore-samd
ladyada Jan 7, 2020
460b1c2
Force linker to use newer Arduino-provided versions of libarm_cortexM…
rlcamp Jan 7, 2020
1df7e52
add math linker test!
ladyada Jan 7, 2020
34013bf
Update boards.txt
rlcamp Jan 7, 2020
330cb4e
Merge pull request #202 from rlcamp/master
ladyada Jan 7, 2020
70d3c1d
Fix warnings about redefinition of `LITTLE_ENDIAN`
henrygab Jan 17, 2020
52c988f
Mark unused parameters as such.
henrygab Jan 17, 2020
8afd052
Fix unintended fall-through
henrygab Jan 17, 2020
bee96c4
Merge pull request #206 from henrygab/fix_compile_warnings
ladyada Jan 17, 2020
cb97944
Can we mark jobs as allowed to fail?
henrygab Jan 17, 2020
622d9f6
re-enable builds with all warnings
henrygab Jan 17, 2020
155cbc5
Friendlier name for -Wall build
henrygab Jan 17, 2020
9ab68e1
avoid warnings on unused parameter
henrygab Jan 17, 2020
4f80972
cast to uint32_t to avoid compiler warning
henrygab Jan 17, 2020
d5935a8
remove 'unused parameter' compiler warning
henrygab Jan 17, 2020
3253d46
Avoid unused parameter compiler warnings
henrygab Jan 17, 2020
a2dd861
Avoid signed/unsigned comparison warning.
henrygab Jan 17, 2020
4276526
Avoid compiler warning for unused parameter
henrygab Jan 17, 2020
e1e7b37
Disable `-Wimplicit-fallthrough` for these two files.
henrygab Jan 17, 2020
1a89b14
Enhance warning output.
henrygab Jan 17, 2020
5cbfd74
TEST: Is `LITTLE_ENDIAN` already properly defined?
henrygab Jan 17, 2020
c68c0b1
Disable `-Wimplicit-fallthrough` in sections
henrygab Jan 17, 2020
12c4506
Improve variant compliance
henrygab Jan 17, 2020
6be9163
add flash definitions
ladyada Feb 2, 2020
b09a926
& circuitplay too!
ladyada Feb 2, 2020
f55ecad
Merge pull request #210 from adafruit/flashdefines
hathach Feb 3, 2020
b13e6c6
Update platform.txt
hathach Feb 3, 2020
a5271b3
Update total pins
GMagician Feb 8, 2020
5b24029
Merge pull request #211 from GMagician/Fix-AGCM4-total-pins
ladyada Feb 9, 2020
bfba981
add fake CI_Tests.h header to make Arduino happy
hathach Feb 11, 2020
18e455f
Merge pull request #214 from hathach/fix-CI_Tests-warning
ladyada Feb 11, 2020
aa21fb1
increase version 1.5.11 for release
hathach Feb 26, 2020
1112d77
less warnings on featherM0
d-a-v Mar 5, 2020
bf24e95
Merge pull request #217 from d-a-v/wless
ladyada Mar 5, 2020
f564235
update tinyusb core and samd port
hathach Apr 21, 2020
72ebc1a
sync with tinyusb commit 1d33aa9
hathach Apr 21, 2020
aa97921
tinyusb: MIDI - Increase buffer size
kaysievers Apr 21, 2020
6c2a982
Merge pull request #222 from versioduo/midi-buffer-size
hathach Apr 22, 2020
a45b5c5
Merge pull request #221 from hathach/update-tinyusb
hathach Apr 22, 2020
d56901d
increase version to release 1.5.12
hathach Apr 22, 2020
159ae8e
Update TinyUSB to commit c59fa77 due to a bug in the stack
hathach Apr 23, 2020
d60ec0f
Merge pull request #224 from hathach/release-.1.5.13
hathach Apr 23, 2020
6d6e5b1
fix incorrect USB IRQ typo for samd
hathach May 4, 2020
e607c3d
Merge pull request #226 from hathach/fix-samd21-usb
hathach May 4, 2020
52d793e
release 1.5.14
hathach May 4, 2020
dad77cd
add SERCOM patch from arduino SAMD core
prototypicalpro May 29, 2020
bdf0c84
Merge pull request #227 from OPEnSLab-OSU/master
ladyada May 29, 2020
fdddb19
add BLE uart test support
ladyada Jun 23, 2020
ff82b73
remove gcc 7-2017q4 specific
hathach Jul 5, 2020
00a863c
update tinyusb to 0749077
hathach Jul 5, 2020
246c75a
bump up version for 1.5.15
hathach Jul 5, 2020
290f3d6
update cmsis from 4.5.0 to 5.4.0
hathach Jul 6, 2020
53c92d4
Increase version to 1.6.0 per review
hathach Jul 7, 2020
196a29f
Merge pull request #232 from hathach/update-toolchain-cmsis
hathach Jul 7, 2020
2569103
move test_cmsis_fast_rfft example to its own folder to fix ci build
hathach Jul 13, 2020
4b669ea
Merge pull request #235 from hathach/fix-ci-build
ladyada Jul 13, 2020
50f9be1
increase 1.6.1 for release
hathach Jul 21, 2020
57db4d7
Fix external pin interrupt definitions for Feather M4
NanoCodeBug Jul 22, 2020
2555c2d
sync with Adafruit_TinyUSB_ArduinoCore commit 238a5c0b95fcd402d24524c…
hathach Jul 23, 2020
4141fce
Merge pull request #241 from adafruit/sync-tinyusb-238a5c0b95fcd402d2…
hathach Jul 23, 2020
3f0f35f
Merge pull request #239 from NanoCodeBug/patch-1
hathach Jul 24, 2020
860bc6c
fix EXTINT for PA4 and PA6
hathach Jul 24, 2020
76f0206
fix all other incorrect EXTINT
hathach Jul 24, 2020
d9e9508
Merge pull request #242 from adafruit/fix-extint-m4
hathach Jul 24, 2020
0947169
add blm badge
ladyada Jul 25, 2020
b1572ce
Enable Interrupt #8 on Pin PORTA28 (GPIO2)
nekuneko Jul 27, 2020
ea9f1a5
Merge pull request #243 from nekuneko/patch-1
ladyada Jul 27, 2020
00dd2e0
Per @hathach request
henrygab Aug 4, 2020
25a5789
Merge branch 'master' into fix_compile_warnings3
henrygab Aug 4, 2020
a2801a1
fix tab/space mixtures -- whitespace only change
henrygab Aug 4, 2020
77321a6
Merge branch 'fix_compile_warnings3' of https://github.com/henrygab/A…
henrygab Aug 4, 2020
eb3c114
Revert "TEST: Is `LITTLE_ENDIAN` already properly defined?"
henrygab Aug 5, 2020
adc0866
Hathach doesn't like attributes on parameters
henrygab Aug 5, 2020
528a25e
@hathach is uncomfortable with attributes on function parameters
henrygab Aug 6, 2020
134ebe7
typo - missing semicolon
henrygab Aug 6, 2020
55a9930
reduce affected area of diagnostic push/pop
henrygab Aug 7, 2020
66b0a74
Use FIXME instead of BUGBUG
henrygab Aug 10, 2020
fd40287
Merge pull request #207 from henrygab/fix_compile_warnings3
hathach Aug 10, 2020
420b9a8
Small SPI lib fix, add SWO pin to variant header
PaintYourDragon Aug 19, 2020
94e908c
Merge branch 'master' into unusedvariable
hathach Aug 20, 2020
37a6ab9
Merge pull request #196 from ulysse314/unusedvariable
hathach Aug 20, 2020
1e92424
Obscure SPI DMA bug fixed. Also, big non-blocking transfers supported.
PaintYourDragon Aug 21, 2020
aa5fa81
use TC1 for servo, TC0 for tone for samd51
hathach Aug 28, 2020
83b63b1
Merge pull request #257 from adafruit/fix-tone
hathach Aug 28, 2020
1264ec6
Merge branch 'master' into matrixportal
ladyada Aug 29, 2020
731adc7
add variant
ladyada Aug 29, 2020
66097a8
add fake LED
ladyada Aug 30, 2020
1ba7379
add blm badge
ladyada Jul 25, 2020
d1c52f2
Merge pull request #258 from adafruit/blmbadge
ladyada Aug 30, 2020
287d079
Merge remote-tracking branch 'origin/master' into matrixportal
ladyada Aug 30, 2020
9827155
oof bad merge
ladyada Aug 30, 2020
c044ba3
add bootloader
ladyada Aug 31, 2020
8d3b49b
Merge pull request #259 from adafruit/matrixportal
ladyada Sep 4, 2020
9ba4e98
Increase version for release 1.6.2
hathach Sep 8, 2020
028ca90
rev A variant
ladyada Sep 12, 2020
28cbc71
test external SPI flash + I2S
ladyada Sep 13, 2020
bdf5ac8
fix some pin numbers so that there's an LED on pin 13
ladyada Sep 13, 2020
a0d7cfd
update tinyusb core to commit 0328bd4c134d05b4bb0472e0db918153f4dd15dd
hathach Sep 15, 2020
4888cdc
update tinyusb core to commit e7b892095f2bb5d8bef6a748238369bdd268ed5e
hathach Sep 15, 2020
814a352
Avoiding unused parameter warning for dmaDoNothingCallback()
Sep 15, 2020
e6c07cc
Merge pull request #263 from ulysse314/adafruit-master
ladyada Sep 15, 2020
6a59e83
Merge pull request #262 from adafruit/update-tinyusb
hathach Sep 15, 2020
fad2d91
increase serial buffer (helps with bno08x uart!)
ladyada Sep 19, 2020
a029d61
Merge branch 'master' of github.com:adafruit/ArduinoCore-samd
ladyada Sep 19, 2020
bdd8ee9
rev C complete!
ladyada Sep 23, 2020
4a5f9f7
add custom init code for neopixel power pin to default on
ladyada Sep 23, 2020
0d46fb5
fix name of chip
ladyada Sep 23, 2020
a2151f3
fix matrixportal_m4 warning define
hathach Sep 23, 2020
e99eb50
Merge pull request #264 from adafruit/qtpy
hathach Sep 23, 2020
9c667a4
Merge pull request #265 from adafruit/fix-warning
ladyada Sep 23, 2020
9d4bdb8
increase for 1.6.3 release
hathach Sep 23, 2020
fa095b3
Merge branch 'master' of github.com:adafruit/ArduinoCore-samd
ladyada Sep 29, 2020
4c6d754
fix https://github.com/adafruit/ArduinoCore-samd/issues/266
ladyada Oct 1, 2020
0c8e1ed
boards.txt: add Feather CAN
jepler Oct 6, 2020
1ffdc7d
Files from Atmel.SAME51_DFP.1.1.139.atpack
jepler Oct 6, 2020
7ae96b4
Adapt feather_m4 variant files to can
jepler Oct 6, 2020
ad022b4
Add special linker script stanza for CAN message RAM
jepler Oct 6, 2020
308e949
feather_m4_can: Add CAN-related pins to variant files
jepler Oct 7, 2020
3ab4dfe
feather_can_m4: define PIN_CAN_abc macros
jepler Oct 7, 2020
f077606
correct board name string
jepler Oct 7, 2020
3471cdf
update feather can board property
jepler Oct 9, 2020
da80034
Add CAN handlers for SAM E51
jepler Oct 20, 2020
b94b432
Merge pull request #267 from jepler/feather-can-bsp
ladyada Oct 20, 2020
54beccb
added optimization menu option for M0
hathach Oct 31, 2020
d0396b0
Merge pull request #269 from adafruit/m0-optimization-option
ladyada Oct 31, 2020
b823585
update LED_BUILTIN for matrixportal_m4
mdonoughe Oct 31, 2020
0b16016
Merge pull request #270 from mdonoughe/matrixportal-led
ladyada Oct 31, 2020
1fa45ad
update version to 1.6.4 for release
hathach Nov 5, 2020
ec69488
add boost enable pin for CAN feather
ladyada Dec 2, 2020
f2a72d1
Fix addpath (#275)
ladyada Dec 10, 2020
dcc531f
Typo fix in PID for BLM Badge (#274)
valeros Dec 10, 2020
3c7a2d5
Added a isBusy() method to SPI calls to allow non-blocking polling of…
RudolphRiedel Dec 28, 2020
12e0a79
Merge pull request #279 from RudolphRiedel/master
PaintYourDragon Dec 28, 2020
9ddc306
CAN variant updates, fix for PDM on badge
ladyada Jan 10, 2021
812399f
Merge branch 'master' of github.com:adafruit/ArduinoCore-samd
ladyada Jan 10, 2021
aa706d7
Fix EINT listing for pin 4
Jan 25, 2021
8c6f2dd
Fix remaining EINT values
Jan 25, 2021
7716ebb
update BLM badge for uart (used in testing)
ladyada Jan 25, 2021
8dcab42
bump to add fixes for CAN Feather and BLM Badge
ladyada Jan 26, 2021
e16a55b
Merge pull request #281 from matt-chan/patch-1
hathach Jan 26, 2021
aebf3cb
Port some AVR Serial_ (SerialUSB) API's over (#285)
myelin Mar 6, 2021
3adf881
add new variant
ladyada Mar 14, 2021
af4f2cb
typo fixes!
ladyada Mar 15, 2021
9e15226
Merge pull request #286 from adafruit/neotrinkey
hathach Mar 15, 2021
243c208
bump version for 1.6.6 release
hathach Mar 15, 2021
d542a60
Cast to integral type ignores qualifier `volatile`
henrygab Mar 25, 2021
76f999b
Fix [-Wrestrict] bug
henrygab Mar 25, 2021
e340701
Merge pull request #288 from henrygab/patch-1
hathach Mar 29, 2021
a7a9d2d
Fix loop iterations
henrygab Apr 9, 2021
1870cef
use same51 header from cmsis-atmel package
hathach Apr 9, 2021
c477272
increase version to 1.6.7
hathach Apr 9, 2021
dffa5b8
Merge pull request #291 from adafruit/use-same51-from-cmsis-atmel-tool
hathach Apr 9, 2021
ea208a4
use correct CMSIS-Atmel-1.2.1.path
hathach Apr 9, 2021
ade7caf
Merge pull request #289 from henrygab/patch-2
hathach Apr 13, 2021
439c6b5
Narrowly silence new (GCC 8.1+) warning (#290)
henrygab Apr 30, 2021
fc358ea
remove tinyusb core submodule, move tinyusb src to its own library to…
hathach May 6, 2021
d3091df
change porting API
hathach May 6, 2021
6fd7609
add feather m4 can to ci
hathach May 6, 2021
1f029ec
fix typo
hathach May 6, 2021
88520ba
update tinyusb header
hathach May 7, 2021
15fd604
clean up
hathach May 7, 2021
704450c
add libraries/Adafruit_TinyUSB_Arduino as submodule
hathach May 7, 2021
c26a837
Trinkeys (#296)
ladyada May 8, 2021
30d0738
sync with tinyusb lib latest change
hathach May 10, 2021
3c173d5
update with TinyUSB_Device_FlushCDC()
hathach May 10, 2021
7234390
sync tinyusb lib
hathach May 10, 2021
48956dd
increase version for release 1.6.8
hathach May 10, 2021
c262dc2
clean up and add note for "-Wclass-memaccess"
hathach May 10, 2021
a9d41b6
fix typo in tinyusb lib
hathach May 10, 2021
322f2ff
add definition for touchpad
ladyada May 13, 2021
93b1ba1
A11 isnt an analog in!
ladyada May 14, 2021
a7bab5b
update tinyusb lib to 1.0.0
hathach May 18, 2021
461f855
ci skip tinyusb lib examples for now
hathach May 18, 2021
32b62c8
add AREF pin as A12
ladyada May 18, 2021
7585cb7
Merge pull request #298 from adafruit/rework-tinyusb
hathach May 19, 2021
fa24f50
increase version to 1.7.0 for release
hathach May 19, 2021
a7a8b02
use CMSIS-Atmel-1.2.2 to fix LITTLE_ENDIAN warning
hathach May 24, 2021
51bd7a7
better fix warning with "-Wclass-memaccess" in SPI
hathach May 24, 2021
e49dab6
also bump tinyusb
hathach May 24, 2021
33a1e15
increase version to 1.7.1
hathach May 24, 2021
cca8448
Merge pull request #300 from adafruit/fix-warnings
hathach May 24, 2021
14a6b40
remove local copy of Adafruit_ZeroDMA
hathach May 25, 2021
69a2211
add Adafruit_ZeroDMA as submodules
hathach May 25, 2021
9c2bdbc
include TinyUSB header for builtin libraries if selected
hathach May 25, 2021
8c2dd0b
bump zeroDMA
hathach May 25, 2021
481e492
always build with all warnings, but not fatal error
hathach May 25, 2021
3c601b6
bump builtin TinyUSB to 1.0.3
hathach May 26, 2021
aff98b3
increase version 1.7.2 for release
hathach May 26, 2021
4e51791
Merge pull request #301 from adafruit/more-ci-work
hathach May 26, 2021
2037467
Update tinyusb library to compatible with 1.2.0 (#303)
hathach Jun 25, 2021
2163aa8
bump tinyusb
hathach Jun 25, 2021
f5564f8
bump TinyUSB to 1.3.0
hathach Jun 29, 2021
a02b851
add -DADAFRUIT_ARCH_SAMD to all board's build.extra_flags
2bndy5 Jul 15, 2021
42d3ad1
requested changes
2bndy5 Jul 15, 2021
de975d9
Merge pull request #306 from 2bndy5/global-define-for-any-adafruit-bo…
hathach Jul 15, 2021
46e2271
fix m4 can pin typo (#307)
hathach Aug 16, 2021
1b17683
increase version for 1.7.4 release
hathach Aug 17, 2021
e24e4af
fix m4 can typo
hathach Aug 31, 2021
11b223a
Merge pull request #308 from adafruit/more-m4-can-typo
hathach Aug 31, 2021
bafcb36
bump up version for release 1.7.5
hathach Sep 1, 2021
6ddfddf
Bugfix - waiting for first ADC read to complete after ADC enable.
zuyan9 Sep 15, 2021
8b70e4c
Merge pull request #309 from zuyan9/master
hathach Sep 17, 2021
6907751
Update Print.h
Sep 30, 2021
3b2df62
Update Print.cpp
Sep 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use TC1 for servo, TC0 for tone for samd51
- make Tone_Handler() a strong symbol
  • Loading branch information
hathach committed Aug 28, 2020
commit aa5fa81bb75c7ee08cb79ea78ee965b812b8c511
59 changes: 35 additions & 24 deletions cores/arduino/Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#include "Tone.h"
#include "variant.h"

#if defined(__SAMD51__)
#define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.SYNCBUSY.bit.ENABLE);
#else
#define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.STATUS.bit.SYNCBUSY);
#endif

uint32_t toneMaxFrequency = F_CPU / 2;
uint32_t lastOutputPin = 0xFFFFFFFF;

Expand All @@ -37,22 +31,24 @@ volatile bool toneIsActive = false;
volatile bool firstTimeRunning = false;

#if defined(__SAMD51__)
#define TONE_TC TC0
#define TONE_TC_IRQn TC0_IRQn
#define TONE_TC_GCLK_ID TC0_GCLK_ID
#define TONE_TC TC0
#define TONE_TC_IRQn TC0_IRQn
#define TONE_TC_GCLK_ID TC0_GCLK_ID
#define Tone_Handler TC0_Handler

#define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.SYNCBUSY.bit.ENABLE);

#else
#define TONE_TC TC5
#define TONE_TC_IRQn TC5_IRQn
#define TONE_TC TC5
#define TONE_TC_IRQn TC5_IRQn
#define Tone_Handler TC5_Handler

#define WAIT_TC16_REGS_SYNC(x) while(x->COUNT16.STATUS.bit.SYNCBUSY);
#endif

#define TONE_TC_TOP 0xFFFF
#define TONE_TC_CHANNEL 0

#if defined(__SAMD51__)
void TC0_Handler (void) __attribute__ ((weak, alias("Tone_Handler")));
#else
void TC5_Handler (void) __attribute__ ((weak, alias("Tone_Handler")));
#endif

static inline void resetTC (Tc* TCx)
{
// Disable TCx
Expand All @@ -72,6 +68,14 @@ void toneAccurateClock (uint32_t accurateSystemCoreClockFrequency)

void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration)
{

// Avoid divide by zero error by calling 'noTone' instead
if (frequency == 0)
{
noTone(outputPin);
return;
}

// Configure interrupt request
NVIC_DisableIRQ(TONE_TC_IRQn);
NVIC_ClearPendingIRQ(TONE_TC_IRQn);
Expand All @@ -90,9 +94,6 @@ void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration)
while (GCLK->STATUS.bit.SYNCBUSY);
#endif
}

//if it's a rest, set to 1Hz (below audio range)
frequency = (frequency > 0 ? frequency : 1);

if (toneIsActive && (outputPin != lastOutputPin))
noTone(lastOutputPin);
Expand Down Expand Up @@ -167,8 +168,8 @@ void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration)
lastOutputPin = outputPin;
digitalWrite(outputPin, LOW);
pinMode(outputPin, OUTPUT);
toneIsActive = true;
}
toneIsActive = true;

// Enable TONE_TC
TONE_TC->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE;
Expand All @@ -179,9 +180,19 @@ void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration)

void noTone (uint32_t outputPin)
{
resetTC(TONE_TC);
digitalWrite(outputPin, LOW);
toneIsActive = false;
/* 'tone' need to run at least once in order to enable GCLK for
* the timers used for the tone-functionality. If 'noTone' is called
* without ever calling 'tone' before then 'WAIT_TC16_REGS_SYNC(TCx)'
* will wait infinitely. The variable 'firstTimeRunning' is set the
* 1st time 'tone' is set so it can be used to detect wether or not
* 'tone' has been called before.
*/
if(firstTimeRunning)
{
resetTC(TONE_TC);
digitalWrite(outputPin, LOW);
toneIsActive = false;
}
}

#ifdef __cplusplus
Expand Down
88 changes: 45 additions & 43 deletions libraries/Servo/src/samd/ServoTimers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,52 @@
// to manage more than one channel per timer on the SAMD architecture

#if defined(__SAMD51__)
#if defined (_useTimer1)
#define TC_FOR_TIMER1 TC0
#define CHANNEL_FOR_TIMER1 0
#define INTENSET_BIT_FOR_TIMER_1 TC_INTENSET_MC0
#define INTENCLR_BIT_FOR_TIMER_1 TC_INTENCLR_MC0
#define INTFLAG_BIT_FOR_TIMER_1 TC_INTFLAG_MC0
#define ID_TC_FOR_TIMER1 ID_TC0
#define IRQn_FOR_TIMER1 TC0_IRQn
#define HANDLER_FOR_TIMER1 TC0_Handler
#define GCM_FOR_TIMER_1 9 // GCLK_TC0
#endif
#if defined (_useTimer2)
#define TC_FOR_TIMER2 TC0
#define CHANNEL_FOR_TIMER2 1
#define INTENSET_BIT_FOR_TIMER_2 TC_INTENSET_MC1
#define INTENCLR_BIT_FOR_TIMER_2 TC_INTENCLR_MC1
#define INTFLAG_BIT_FOR_TIMER_2 TC_INTFLAG_MC1
#define ID_TC_FOR_TIMER2 ID_TC0
#define IRQn_FOR_TIMER2 TC0_IRQn
#define HANDLER_FOR_TIMER2 TC0_Handler
#define GCM_FOR_TIMER_2 9 // GCLK_TC0
#endif
#if defined (_useTimer1)
#define TC_FOR_TIMER1 TC1
#define CHANNEL_FOR_TIMER1 0
#define INTENSET_BIT_FOR_TIMER_1 TC_INTENSET_MC0
#define INTENCLR_BIT_FOR_TIMER_1 TC_INTENCLR_MC0
#define INTFLAG_BIT_FOR_TIMER_1 TC_INTFLAG_MC0
#define ID_TC_FOR_TIMER1 ID_TC1
#define IRQn_FOR_TIMER1 TC1_IRQn
#define HANDLER_FOR_TIMER1 TC1_Handler
#define GCM_FOR_TIMER_1 TC1_GCLK_ID
#endif

#if defined (_useTimer2)
#define TC_FOR_TIMER2 TC1
#define CHANNEL_FOR_TIMER2 1
#define INTENSET_BIT_FOR_TIMER_2 TC_INTENSET_MC1
#define INTENCLR_BIT_FOR_TIMER_2 TC_INTENCLR_MC1
#define INTFLAG_BIT_FOR_TIMER_2 TC_INTFLAG_MC1
#define ID_TC_FOR_TIMER2 ID_TC1
#define IRQn_FOR_TIMER2 TC1_IRQn
#define HANDLER_FOR_TIMER2 TC1_Handler
#define GCM_FOR_TIMER_2 TC1_GCLK_ID
#endif
#else
#if defined (_useTimer1)
#define TC_FOR_TIMER1 TC4
#define CHANNEL_FOR_TIMER1 0
#define INTENSET_BIT_FOR_TIMER_1 TC_INTENSET_MC0
#define INTENCLR_BIT_FOR_TIMER_1 TC_INTENCLR_MC0
#define INTFLAG_BIT_FOR_TIMER_1 TC_INTFLAG_MC0
#define ID_TC_FOR_TIMER1 ID_TC4
#define IRQn_FOR_TIMER1 TC4_IRQn
#define HANDLER_FOR_TIMER1 TC4_Handler
#define GCM_FOR_TIMER_1 GCM_TC4_TC5
#endif
#if defined (_useTimer2)
#define TC_FOR_TIMER2 TC4
#define CHANNEL_FOR_TIMER2 1
#define INTENSET_BIT_FOR_TIMER_2 TC_INTENSET_MC1
#define INTENCLR_BIT_FOR_TIMER_2 TC_INTENCLR_MC1
#define ID_TC_FOR_TIMER2 ID_TC4
#define IRQn_FOR_TIMER2 TC4_IRQn
#define HANDLER_FOR_TIMER2 TC4_Handler
#define GCM_FOR_TIMER_2 GCM_TC4_TC5
#endif
#if defined (_useTimer1)
#define TC_FOR_TIMER1 TC4
#define CHANNEL_FOR_TIMER1 0
#define INTENSET_BIT_FOR_TIMER_1 TC_INTENSET_MC0
#define INTENCLR_BIT_FOR_TIMER_1 TC_INTENCLR_MC0
#define INTFLAG_BIT_FOR_TIMER_1 TC_INTFLAG_MC0
#define ID_TC_FOR_TIMER1 ID_TC4
#define IRQn_FOR_TIMER1 TC4_IRQn
#define HANDLER_FOR_TIMER1 TC4_Handler
#define GCM_FOR_TIMER_1 GCM_TC4_TC5
#endif

#if defined (_useTimer2)
#define TC_FOR_TIMER2 TC4
#define CHANNEL_FOR_TIMER2 1
#define INTENSET_BIT_FOR_TIMER_2 TC_INTENSET_MC1
#define INTENCLR_BIT_FOR_TIMER_2 TC_INTENCLR_MC1
#define ID_TC_FOR_TIMER2 ID_TC4
#define IRQn_FOR_TIMER2 TC4_IRQn
#define HANDLER_FOR_TIMER2 TC4_Handler
#define GCM_FOR_TIMER_2 GCM_TC4_TC5
#endif
#endif

typedef enum {
Expand Down