Skip to content

Commit

Permalink
[gpio] Refactor SAM signals API
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikssn authored and salkinium committed Oct 6, 2020
1 parent 85eec34 commit dc56af2
Show file tree
Hide file tree
Showing 22 changed files with 753 additions and 739 deletions.
38 changes: 21 additions & 17 deletions examples/samd/interrupt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@ using namespace std::chrono_literals;
static volatile bool blink = true;

void
isr() {
blink = !blink;
// Kids, please don't do serial logging in ISRs...
MODM_LOG_DEBUG << "blink: " << (blink ? "true" : "false") << modm::endl;
isr()
{
blink = !blink;
// Kids, please don't do serial logging in ISRs...
MODM_LOG_DEBUG << "blink: " << (blink ? "true" : "false") << modm::endl;
}

int
main()
{
Board::initialize();
ExternalInterrupt::initialize();
ExtInt<3>::initialize(&isr);
ExtInt<3>::connectPin<D12>();
while (1) {
if (blink) {
Led::toggle();
} else {
Led::set(0);
}
modm::delay(100ms);
}
return 0;
Board::initialize();
ExternalInterrupt::initialize();
ExtInt<3>::initialize(&isr);
ExtInt<3>::connect<D12>();
while (1)
{
if (blink)
{
Led::toggle();
} else
{
Led::set(0);
}
modm::delay(100ms);
}
return 0;
}
3 changes: 2 additions & 1 deletion examples/samd/usbserial/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ int main()
TCC0->PER.bit.PER = SystemClock::Frequency / 1000;
TCC0->CC[3].bit.CC = SystemClock::Frequency / 2000;
TCC0->CTRLA.bit.ENABLE = true;
D12::Wo3<Peripheral::Tcc0>::connect();
using Tcc = Peripherals::Tcc<0>;
D12::As<PeripheralPin::Wo>::Connector<Tcc, Tcc::Wo<3>>::connect();
GenericClockController::connect<ClockPeripheral::Tcc0>(ClockGenerator::System);

tusb_init();
Expand Down
2 changes: 1 addition & 1 deletion ext/modm-devices
17 changes: 8 additions & 9 deletions src/modm/board/feather_m0/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@

#pragma once

#include <modm/architecture/interface/clock.hpp>
#include <modm/debug/logger.hpp>
#include <modm/platform.hpp>
#include <modm/architecture/interface/clock.hpp>
#define MODM_BOARD_HAS_LOGGER

using namespace modm::platform;


/// @ingroup modm_board_feather_m0
namespace Board
{
Expand Down Expand Up @@ -54,9 +53,9 @@ using Sda = GpioA23;
using Scl = GpioA22;

// For RFM69 / LoRa boards
using RadioRst = GpioA08;
using RadioIrq = GpioA09;
using RadioCs = GpioA06;
using RadioRst = GpioA08;
using RadioIrq = GpioA09;
using RadioCs = GpioA06;

// This is the red LED by the USB jack.
using Led = D13;
Expand Down Expand Up @@ -101,15 +100,15 @@ struct SystemClock
}
};

using LoggerDevice = modm::IODeviceWrapper< Uart0, modm::IOBuffer::BlockIfFull >;
using Leds = SoftwareGpioPort< Led >;
using LoggerDevice = modm::IODeviceWrapper<Uart0, modm::IOBuffer::BlockIfFull>;
using Leds = Led;

inline void
initialize()
{
SystemClock::enable();
SysTickTimer::initialize<SystemClock>();
Uart0::connect<Rx::Pad3, Tx::Pad2>();
Uart0::connect<Rx::Rx, Tx::Tx>();
Uart0::initialize<SystemClock, 115'200_Bd>();

Led::setOutput(modm::Gpio::Low);
Expand All @@ -122,4 +121,4 @@ initializeUsbFs()
modm::platform::Usb::connect<GpioA24::Dm, GpioA25::Dp>();
}

} // Board namespace
} // namespace Board
46 changes: 30 additions & 16 deletions src/modm/platform/extint/sam/extint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <modm/architecture/interface/interrupt.hpp>
#include <modm/platform/clock/gclk.hpp>
#include <modm/platform/device.hpp>
#include <modm/platform/gpio/base.hpp>
#include <modm/platform/gpio/pin.hpp>

#pragma once

Expand All @@ -25,14 +25,25 @@ namespace platform

MODM_ISR_DECL(EIC);

enum class InputTrigger
{
RisingEdge = EIC_CONFIG_SENSE0_RISE_Val,
FallingEdge = EIC_CONFIG_SENSE0_FALL_Val,
BothEdges = EIC_CONFIG_SENSE0_BOTH_Val,
High = EIC_CONFIG_SENSE0_HIGH_Val,
Low = EIC_CONFIG_SENSE0_LOW_Val,
};

/**
* External Interrupt handler for SAMD devices.
*
* @author Erik Henriksson
* @ingroup modm_platform_extint
*/
class ExternalInterrupt {
class ExternalInterrupt
{
friend void EIC_IRQHandler(void);

public:
/**
* Initializes the External Interrupt handler.
Expand All @@ -42,11 +53,11 @@ class ExternalInterrupt {
* be used to akeup the CPU from standby mode, make sure this clock is
* actually running in standby. Defaults to external 32.768kHz crystal osc.
*/
static void initialize(
ClockGenerator clockGen = ClockGenerator::ExternalCrystal32K,
int priority = (1ul << __NVIC_PRIO_BITS) - 1ul);
static void
initialize(ClockGenerator clockGen = ClockGenerator::ExternalCrystal32K,
int priority = (1ul << __NVIC_PRIO_BITS) - 1ul);

protected:
protected:
static std::array<std::function<void()>, 16> handlers_;
};

Expand All @@ -56,7 +67,8 @@ class ExternalInterrupt {
* @author Erik Henriksson
* @ingroup modm_platform_extint
*/
template<int instance> class ExtInt : private ExternalInterrupt
template<int instance>
class ExtInt : private ExternalInterrupt
{
public:
/**
Expand All @@ -70,26 +82,28 @@ template<int instance> class ExtInt : private ExternalInterrupt
* If true (default), allows the CPU to wakeup from interrupt
* from this instance.
*/
static void initialize(
std::function<void()> handler,
Gpio::InputTrigger trigger = Gpio::InputTrigger::RisingEdge,
bool wakeupEnabled = true);
static void
initialize(std::function<void()> handler, InputTrigger trigger = InputTrigger::RisingEdge,
bool wakeupEnabled = true);

/**
* Connects a GPIO pin to this External Interrupt instance.
*
* @tparam Pin
* The GPIO pin to connect this instance to.
*/
template<class Pin>
template<class GpioPin>
static void
connectPin() {
Pin::template connectInterrupt<instance>();
connect()
{
using Eic = Peripherals::Eic;
using Pin = typename GpioPin::template As<PeripheralPin::ExtInt>;
Pin::template Connector<Eic, Eic::Extint<instance>>::connect();
}
};

} // namespace platform
} // namespace platform

} // namespace modm
} // namespace modm

#include "extint_impl.hpp"
23 changes: 10 additions & 13 deletions src/modm/platform/extint/sam/extint_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,26 @@

#pragma once

namespace modm
{
namespace platform
namespace modm::platform
{

template<int instance>
void
ExtInt<instance>::initialize(
std::function<void()> handler,
Gpio::InputTrigger trigger,
bool wakeupEnabled) {
ExtInt<instance>::initialize(std::function<void()> handler, InputTrigger trigger,
bool wakeupEnabled)
{
handlers_[instance] = handler;
if (wakeupEnabled) {
if (wakeupEnabled)
{
EIC->WAKEUP.reg |= EIC_WAKEUP_WAKEUPEN(1u << instance);
} else {
} else
{
EIC->WAKEUP.reg &= ~EIC_WAKEUP_WAKEUPEN(1u << instance);
}
constexpr int sensePos = instance*EIC_CONFIG_SENSE1_Pos;
constexpr int sensePos = instance * EIC_CONFIG_SENSE1_Pos;
EIC->CONFIG[instance & 0x8].reg &= EIC_CONFIG_SENSE0_Msk << sensePos;
EIC->CONFIG[instance & 0x8].reg |= uint32_t(trigger) << sensePos;
EIC->INTENSET.vec.EXTINT |= 1u << instance;
}


} // namespace platform
} // namespace modm
} // namespace modm::platform
125 changes: 0 additions & 125 deletions src/modm/platform/gpio/sam/base.hpp.in

This file was deleted.

Loading

0 comments on commit dc56af2

Please sign in to comment.