Skip to content

Commit 694c2ed

Browse files
committed
Add polarity to PinConf
1 parent 3b2378a commit 694c2ed

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/drivers/pinconf.hh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,15 @@ enum class PinPolarity {
9191
// Pin class
9292
// Can be used as a convenient container for passing pin defintions
9393
// to a peripheral which performs the register initialization later
94+
// polarity controls read() polarity only (does not affect setting the pin)
9495
struct PinConf {
9596
GPIO gpio{GPIO::Unused};
9697
PinNum pin{PinNum::Unused};
9798
PinAF af{PinAF::AFNone};
98-
99-
// FIXME: Polarity is not used
99+
PinPolarity polarity{PinPolarity::Normal};
100100

101101
void init(PinMode mode,
102102
PinPull pull = PinPull::None,
103-
PinPolarity polarity = PinPolarity::Normal,
104103
PinSpeed speed = PinSpeed::High,
105104
PinOType otype = PinOType::PushPull) const
106105
{
@@ -128,13 +127,9 @@ struct PinConf {
128127

129128
// Same as init(), just args in a different order
130129
// Makes it a little cleaner when init'ing AF OpenDrain pins such as I2C
131-
void init(PinMode mode,
132-
PinOType otype,
133-
PinPull pull = PinPull::None,
134-
PinPolarity polarity = PinPolarity::Normal,
135-
PinSpeed speed = PinSpeed::High) const
130+
void init(PinMode mode, PinOType otype, PinPull pull = PinPull::None, PinSpeed speed = PinSpeed::High) const
136131
{
137-
init(mode, pull, polarity, speed, otype);
132+
init(mode, pull, speed, otype);
138133
}
139134

140135
void low() const
@@ -155,7 +150,8 @@ struct PinConf {
155150
{
156151
auto port_ = reinterpret_cast<GPIO_TypeDef *>(gpio);
157152
auto pin_ = static_cast<uint16_t>(pin);
158-
return LL_GPIO_IsInputPinSet(port_, pin_);
153+
bool is_set = LL_GPIO_IsInputPinSet(port_, pin_);
154+
return polarity == PinPolarity::Normal ? is_set : !is_set;
159155
}
160156

161157
static constexpr uint32_t bit_to_num(PinNum PINx)

0 commit comments

Comments
 (0)