Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RH_ASK support for SAMD51 processor #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Next Next commit
Added RH_ASK SAMD51 support
IoTPanic committed Oct 4, 2020
commit 8f215e3c28235b80b26cd1e7b0f27149f3ca7de9
41 changes: 40 additions & 1 deletion RH_ASK.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@

#include <RH_ASK.h>
#include <RHCRC.h>

#if (RH_PLATFORM == RH_PLATFORM_STM32)
// Maple etc
HardwareTimer timer(MAPLE_TIMER);
@@ -234,6 +233,38 @@ void RH_ASK::timerSetup()
IntervalTimer *t = new IntervalTimer();
void TIMER1_COMPA_vect(void);
t->begin(TIMER1_COMPA_vect, 125000 / _speed);
#elif defined (__arm__) && defined(__SAMD51__)
// Arduino SAMD51
#define RH_ASK_M4_TIMER TC3
// Clock speed is 120MHz, prescaler of 256 is close to the 64 example below for samd21
#define RH_ASK_M4_PRESCALER 256
#define RH_ASK_M4_TIMER_IRQ TC3_IRQn

GCLK->PCHCTRL[TC3_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK1_Val |
(1 << GCLK_PCHCTRL_CHEN_Pos);

while (GCLK->SYNCBUSY.reg > 0);

TC3->COUNT16.CTRLA.bit.ENABLE = 0;
TC3->COUNT16.WAVE.bit.WAVEGEN = TC_WAVE_WAVEGEN_MFRQ;
while (TC3->COUNT16.SYNCBUSY.reg != 0) {}

TC3->COUNT16.INTENSET.reg = 0;
TC3->COUNT16.INTENSET.bit.MC0 = 1;

// Enable IRQ
NVIC_EnableIRQ(TC3_IRQn);

TC3->COUNT16.CTRLA.reg &= ~0b011100000000;
while (TC3->COUNT16.SYNCBUSY.reg != 0) {}

TC3->COUNT16.CTRLA.reg |= (uint32_t)TC_CTRLA_PRESCALER_DIV256;
while (TC3->COUNT16.SYNCBUSY.reg != 0) {}
uint32_t rc = (VARIANT_MCK / _speed) / RH_ASK_M4_PRESCALER / 8;
TC3->COUNT16.CC[0].reg = rc;
while (TC3->COUNT16.SYNCBUSY.reg != 0) {}
TC3->COUNT16.CTRLA.bit.ENABLE = 1;
while (TC3->COUNT16.SYNCBUSY.reg != 0) {}

#elif defined (__arm__) && defined(ARDUINO_ARCH_SAMD)
// Arduino Zero
@@ -604,6 +635,14 @@ void TIMER1_COMPA_vect(void)
{
thisASKDriver->handleTimerInterrupt();
}
#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && defined(__SAMD51__)

void TC3_Handler() {
if (TC3->COUNT16.INTFLAG.bit.MC0 == 1) {
TC3->COUNT16.INTFLAG.bit.MC0 = 1;
thisASKDriver->handleTimerInterrupt();
}
}

#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && defined(ARDUINO_ARCH_SAMD)
// Arduino Zero