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 committed Oct 5, 2020
1 parent ceef55d commit 6382b44
Show file tree
Hide file tree
Showing 24 changed files with 884 additions and 743 deletions.
163 changes: 163 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: TopLevel
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
- Regex: '^<.*'
Priority: 2
SortPriority: 0
- Regex: '.*'
Priority: 3
SortPriority: 0
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: ForContinuationAndIndentation
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{lb,py}]
indent_style = space
indent_size = 4
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;
}
2 changes: 1 addition & 1 deletion ext/modm-devices
24 changes: 11 additions & 13 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 All @@ -39,8 +38,8 @@ using Sck = GpioB11;
using Mosi = GpioB10;
using Miso = GpioA12;

using Rx = GpioA11;
using Tx = GpioA10;
using Rx = GpioA11::Rx;
using Tx = GpioA10::Tx;

using D13 = GpioA17;
using D12 = GpioA19;
Expand All @@ -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 @@ -88,8 +87,7 @@ struct SystemClock
// static constexpr uint32_t Timer3 = Apb1Timer;
// static constexpr uint32_t Timer4 = Apb1Timer;

static bool inline
enable()
static bool inline enable()
{
GenericClockController::setFlashLatency<Frequency>();
GenericClockController::initExternalCrystal();
Expand All @@ -101,15 +99,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, Tx>();
Uart0::initialize<SystemClock, 115'200_Bd>();

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

} // Board namespace
} // namespace Board
46 changes: 29 additions & 17 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,10 @@ 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 +66,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 +81,27 @@ 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>
static void
connectPin() {
Pin::template connectInterrupt<instance>();
template<class GpioPin>
static void 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"
Loading

0 comments on commit 6382b44

Please sign in to comment.