Skip to content

Commit

Permalink
[gpio] Change line width to 100 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikssn committed Oct 5, 2020
1 parent e382657 commit b44c26d
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand Down
5 changes: 2 additions & 3 deletions src/modm/platform/extint/sam/extint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ 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:
static std::array<std::function<void()>, 16> handlers_;
Expand Down
4 changes: 2 additions & 2 deletions src/modm/platform/extint/sam/extint_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace modm::platform

template<int instance>
void
ExtInt<instance>::initialize(std::function<void()> handler,
InputTrigger trigger, bool wakeupEnabled)
ExtInt<instance>::initialize(std::function<void()> handler, InputTrigger trigger,
bool wakeupEnabled)
{
handlers_[instance] = handler;
if (wakeupEnabled)
Expand Down
62 changes: 23 additions & 39 deletions src/modm/platform/gpio/sam/pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ using tuple_filter_t = typename tuple_filter<Predicate, Tuple>::type;
template<class Predicate, class X, class... Xs>
struct tuple_filter<Predicate, std::tuple<X, Xs...>>
{
using type = std::conditional_t<
Predicate::template value<X>,
tuple_cat_t<std::tuple<X>,
tuple_filter_t<Predicate, std::tuple<Xs...>>>,
tuple_filter_t<Predicate, std::tuple<Xs...>>>;
using type =
std::conditional_t<Predicate::template value<X>,
tuple_cat_t<std::tuple<X>, tuple_filter_t<Predicate, std::tuple<Xs...>>>,
tuple_filter_t<Predicate, std::tuple<Xs...>>>;
};

// Base case
Expand All @@ -85,8 +84,7 @@ template<class P>
struct EqualsPeripheral
{
template<class Signal>
static constexpr bool value =
std::is_same_v<P, typename Signal::peripheral>;
static constexpr bool value = std::is_same_v<P, typename Signal::peripheral>;
};

template<class S>
Expand All @@ -100,8 +98,7 @@ template<class... Signals>
struct OneOfSignals
{
template<class Signal>
static constexpr bool value =
((std::is_same_v<typename Signal::signal, Signals>) | ...);
static constexpr bool value = ((std::is_same_v<typename Signal::signal, Signals>) | ...);
};

template<class... PinConfigs>
Expand Down Expand Up @@ -134,8 +131,7 @@ class GpioSet : protected PinCfgMixin<PinConfigs...>

static constexpr uint32_t mask(PortName port)
{
return (((PinConfigs::port == port) ? 1u << PinConfigs::pin : 0u) |
...);
return (((PinConfigs::port == port) ? 1u << PinConfigs::pin : 0u) | ...);
}

inline static void setPortReg(size_t offset)
Expand Down Expand Up @@ -186,8 +182,7 @@ class GpioSet : protected PinCfgMixin<PinConfigs...>
static void configure(InputType type)
{
set(type == InputType::PullUp);
PinCfg::set(PORT_PINCFG_INEN | (type != InputType::Floating)
<< PORT_PINCFG_PULLEN_Pos);
PinCfg::set(PORT_PINCFG_INEN | (type != InputType::Floating) << PORT_PINCFG_PULLEN_Pos);
}

static void setAnalogInput() {}
Expand Down Expand Up @@ -226,10 +221,7 @@ class Gpio : public GpioSet<PinConfig>, public ::modm::GpioIO
using Tx = As<PeripheralPin::Tx>;
using ExtInt = As<PeripheralPin::ExtInt>;

inline static bool read()
{
return Base::readPortReg<PinConfig::port>(PORT_IN_OFFSET);
}
inline static bool read() { return Base::readPortReg<PinConfig::port>(PORT_IN_OFFSET); }

inline static void write(bool status) { Base::set(status); }
};
Expand All @@ -245,26 +237,23 @@ struct Gpio<PinConfig>::As : public Gpio<PinConfig>
struct ValidatePeripheral
{
using type = tuple_filter_t<EqualsPeripheral<P>, Signals>;
static_assert(
!std::is_same_v<type, std::tuple<>>,
"Gpio pin does not connect to this peripheral! (see above)");
static_assert(!std::is_same_v<type, std::tuple<>>,
"Gpio pin does not connect to this peripheral! (see above)");
};

template<class Signals, class... RequiredSignals>
struct ValidateSignal
{
using type = tuple_filter_t<OneOfSignals<RequiredSignals...>, Signals>;
static_assert(
!std::is_same_v<type, std::tuple<>>,
"Gpio pin does not connect to any of the required signals! "
"(see above)");
static_assert(!std::is_same_v<type, std::tuple<>>,
"Gpio pin does not connect to any of the required signals! "
"(see above)");
};

template<class Signals>
struct GetSingleSignal
{
using crash =
typename Signals::errorPeripheralInstanceMatchedMoreThanOneSignal;
using crash = typename Signals::errorPeripheralInstanceMatchedMoreThanOneSignal;
};

template<class Signal>
Expand All @@ -277,11 +266,9 @@ struct Gpio<PinConfig>::As : public Gpio<PinConfig>
struct Connector
{
using ValidatedPeripheral =
typename ValidatePeripheral<typename PinConfig::Signals,
peripheral>::type;
typename ValidatePeripheral<typename PinConfig::Signals, peripheral>::type;
using ValidatedSignals =
typename ValidateSignal<ValidatedPeripheral,
RequiredSignals...>::type;
typename ValidateSignal<ValidatedPeripheral, RequiredSignals...>::type;
using PinSignal = typename GetSingleSignal<ValidatedSignals>::type;
using Signal = typename PinSignal::signal;

Expand All @@ -290,14 +277,12 @@ struct Gpio<PinConfig>::As : public Gpio<PinConfig>
Base::PinCfg::set(PORT_PINCFG_INEN);
if constexpr (PinConfig::pin >> 1)
{
PORT->Group[uint32_t(PinConfig::port)]
.PMUX[PinConfig::pin >> 1]
.bit.PMUXO = uint32_t(PinSignal::function);
PORT->Group[uint32_t(PinConfig::port)].PMUX[PinConfig::pin >> 1].bit.PMUXO =
uint32_t(PinSignal::function);
} else
{
PORT->Group[uint32_t(PinConfig::port)]
.PMUX[PinConfig::pin >> 1]
.bit.PMUXE = uint32_t(PinSignal::function);
PORT->Group[uint32_t(PinConfig::port)].PMUX[PinConfig::pin >> 1].bit.PMUXE =
uint32_t(PinSignal::function);
}
}
};
Expand All @@ -312,9 +297,8 @@ using GetPin_t = typename GetPin<peripheral_pin, Pins...>::type;
template<PeripheralPin peripheral_pin, class Pin, class... Pins>
struct GetPin<peripheral_pin, Pin, Pins...>
{
using type =
typename std::conditional_t<peripheral_pin == Pin::peripheral_pin, Pin,
GetPin_t<peripheral_pin, Pins...>>;
using type = typename std::conditional_t<peripheral_pin == Pin::peripheral_pin, Pin,
GetPin_t<peripheral_pin, Pins...>>;
};

template<PeripheralPin peripheral_pin>
Expand Down
81 changes: 29 additions & 52 deletions src/modm/platform/i2c/bitbang/bitbang_i2c_master_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,25 @@ uint16_t modm::platform::BitBangI2cMaster<Scl, Sda>::delayTime(3);
template<class Scl, class Sda>
modm::I2c::Operation modm::platform::BitBangI2cMaster<Scl, Sda>::nextOperation;
template<class Scl, class Sda>
modm::I2cTransaction
*modm::platform::BitBangI2cMaster<Scl, Sda>::transactionObject(nullptr);
modm::I2cTransaction *modm::platform::BitBangI2cMaster<Scl, Sda>::transactionObject(nullptr);
template<class Scl, class Sda>
modm::I2cMaster::Error modm::platform::BitBangI2cMaster<Scl, Sda>::errorState(
modm::I2cMaster::Error::NoError);
template<class Scl, class Sda>
modm::I2c::ConfigurationHandler
modm::platform::BitBangI2cMaster<Scl, Sda>::configuration(nullptr);
modm::I2c::ConfigurationHandler modm::platform::BitBangI2cMaster<Scl, Sda>::configuration(nullptr);

template<class Scl, class Sda>
modm::I2cTransaction::Starting
modm::platform::BitBangI2cMaster<Scl, Sda>::starting(
0, modm::I2c::OperationAfterStart::Stop);
modm::I2cTransaction::Starting modm::platform::BitBangI2cMaster<Scl, Sda>::starting(
0, modm::I2c::OperationAfterStart::Stop);
template<class Scl, class Sda>
modm::I2cTransaction::Writing
modm::platform::BitBangI2cMaster<Scl, Sda>::writing(
nullptr, 0, modm::I2c::OperationAfterWrite::Stop);
modm::I2cTransaction::Writing modm::platform::BitBangI2cMaster<Scl, Sda>::writing(
nullptr, 0, modm::I2c::OperationAfterWrite::Stop);
template<class Scl, class Sda>
modm::I2cTransaction::Reading
modm::platform::BitBangI2cMaster<Scl, Sda>::reading(
nullptr, 0, modm::I2c::OperationAfterRead::Stop);
modm::I2cTransaction::Reading modm::platform::BitBangI2cMaster<Scl, Sda>::reading(
nullptr, 0, modm::I2c::OperationAfterRead::Stop);

template<class Scl, class Sda>
template<class SystemClock, modm::baudrate_t baudrate,
modm::percent_t tolerance>
template<class SystemClock, modm::baudrate_t baudrate, modm::percent_t tolerance>
void
modm::platform::BitBangI2cMaster<Scl, Sda>::initialize()
{
Expand All @@ -78,13 +72,11 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::connect(PullUps pullups)
static_assert(sizeof...(Signals) == 2,
"BitBangI2cMaster<Scl, Sda>::connect() requires one Scl and "
"one Sda signal!");
static_assert(
Connector::template Contains<SCL> and Connector::template Contains<SDA>,
"BitBangI2cMaster<Scl, Sda> can only connect to the same Scl and Sda "
"signals of the declaration!");
const typename SCL::InputType input = (pullups == PullUps::Internal)
? SCL::InputType::PullUp
: SCL::InputType::Floating;
static_assert(Connector::template Contains<SCL> and Connector::template Contains<SDA>,
"BitBangI2cMaster<Scl, Sda> can only connect to the same Scl and Sda "
"signals of the declaration!");
const typename SCL::InputType input =
(pullups == PullUps::Internal) ? SCL::InputType::PullUp : SCL::InputType::Floating;

Connector::disconnect();
SCL::configure(input);
Expand All @@ -97,8 +89,8 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::connect(PullUps pullups)

template<class Scl, class Sda>
bool
modm::platform::BitBangI2cMaster<Scl, Sda>::start(
modm::I2cTransaction *transaction, ConfigurationHandler handler)
modm::platform::BitBangI2cMaster<Scl, Sda>::start(modm::I2cTransaction *transaction,
ConfigurationHandler handler)
{
if ((not transactionObject) and transaction)
{
Expand Down Expand Up @@ -129,10 +121,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::start(
uint8_t address = (starting.address & 0xfe);

// set the correct addressing bit
DEBUG_SW_I2C(
(starting.next == modm::I2c::OperationAfterStart::Read)
? 'r'
: 'w');
DEBUG_SW_I2C((starting.next == modm::I2c::OperationAfterStart::Read) ? 'r' : 'w');
if (starting.next == modm::I2c::OperationAfterStart::Read)
address |= modm::I2c::Read;

Expand All @@ -143,11 +132,9 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::start(
starting.address = 0;

// if the inner loop required a restart, we arrive here again
if (nextOperation == modm::I2c::Operation::Restart)
{ DEBUG_SW_I2C('R'); }
if (nextOperation == modm::I2c::Operation::Restart) { DEBUG_SW_I2C('R'); }
// what is the first operation after (re-)start?
nextOperation =
static_cast<modm::I2c::Operation>(starting.next);
nextOperation = static_cast<modm::I2c::Operation>(starting.next);

do
{
Expand All @@ -159,15 +146,13 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::start(
while (reading.length > 1)
{
// continue reading, by sending ACKs
if (not read(*reading.buffer++, ACK))
return true;
if (not read(*reading.buffer++, ACK)) return true;
reading.length--;
}
// read last byte, conclude with NACK
if (not read(*reading.buffer, NACK)) return true;
// what next?
nextOperation =
static_cast<modm::I2c::Operation>(reading.next);
nextOperation = static_cast<modm::I2c::Operation>(reading.next);
break;

case modm::I2c::Operation::Write:
Expand All @@ -180,14 +165,12 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::start(
writing.length--;
}
// what next?
nextOperation =
static_cast<modm::I2c::Operation>(writing.next);
nextOperation = static_cast<modm::I2c::Operation>(writing.next);
break;

default:
case modm::I2c::Operation::Stop:
transactionObject->detaching(
modm::I2c::DetachCause::NormalStop);
transactionObject->detaching(modm::I2c::DetachCause::NormalStop);
transactionObject = nullptr;
stopCondition();
return true;
Expand All @@ -209,8 +192,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::reset()
DEBUG_SW_I2C('E');
DEBUG_SW_I2C('0' + static_cast<uint8_t>(Error::SoftwareReset));
errorState = Error::SoftwareReset;
if (transactionObject)
transactionObject->detaching(DetachCause::ErrorCondition);
if (transactionObject) transactionObject->detaching(DetachCause::ErrorCondition);
transactionObject = nullptr;
}

Expand Down Expand Up @@ -239,8 +221,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::error(Error error)
// save error state
errorState = error;

if (transactionObject)
transactionObject->detaching(DetachCause::ErrorCondition);
if (transactionObject) transactionObject->detaching(DetachCause::ErrorCondition);
transactionObject = nullptr;
}

Expand All @@ -259,8 +240,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::startCondition()
{
// could not release data line
errorState = Error::BusBusy;
if (transactionObject)
transactionObject->detaching(DetachCause::ErrorCondition);
if (transactionObject) transactionObject->detaching(DetachCause::ErrorCondition);
transactionObject = nullptr;
return false;
}
Expand All @@ -269,8 +249,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::startCondition()
{
// could not release clock line
errorState = Error::BusBusy;
if (transactionObject)
transactionObject->detaching(DetachCause::ErrorCondition);
if (transactionObject) transactionObject->detaching(DetachCause::ErrorCondition);
transactionObject = nullptr;
return false;
}
Expand Down Expand Up @@ -301,8 +280,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::stopCondition()
{
// could not release clock line
errorState = Error::BusCondition;
if (transactionObject)
transactionObject->detaching(DetachCause::ErrorCondition);
if (transactionObject) transactionObject->detaching(DetachCause::ErrorCondition);
transactionObject = nullptr;
return false;
}
Expand All @@ -315,8 +293,7 @@ modm::platform::BitBangI2cMaster<Scl, Sda>::stopCondition()
{
// could not release data line
errorState = Error::BusCondition;
if (transactionObject)
transactionObject->detaching(DetachCause::ErrorCondition);
if (transactionObject) transactionObject->detaching(DetachCause::ErrorCondition);
transactionObject = nullptr;
return false;
}
Expand Down
Loading

0 comments on commit b44c26d

Please sign in to comment.