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

[gpio] Refactor GPIO and Signal implementation #686

Merged
merged 4 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
142 changes: 71 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Here is a table with all device families and the peripheral drivers they support

- ✅ Implemented as a software driver in modm.
- ○ Available in hardware but missing a software driver in modm.
- Unavailable in hardware or device with that peripheral not supported by modm.
- Unavailable in hardware or device with that peripheral not supported by modm.

Note that this is a summary overview and your specific device may not have all
the peripherals in this table.
Expand Down Expand Up @@ -146,34 +146,34 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">Comparator</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center">○</td>
Expand All @@ -193,11 +193,11 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">DMA</td>
<td align="center">✅</td>
Expand All @@ -213,31 +213,31 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">Ethernet</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">External Interrupt</td>
<td align="center">✅</td>
Expand All @@ -253,31 +253,31 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr><tr>
<td align="left">External Memory</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">GPIO</td>
<td align="center">✅</td>
Expand Down Expand Up @@ -335,29 +335,29 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">○</td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">Random Generator</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">SPI</td>
<td align="center">✅</td>
Expand Down Expand Up @@ -393,11 +393,11 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">Timer</td>
<td align="center">✅</td>
Expand Down Expand Up @@ -452,12 +452,12 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr><tr>
<td align="left">USB</td>
<td align="center">✅</td>
Expand All @@ -466,7 +466,7 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
Expand All @@ -475,9 +475,9 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
</tr>
</table>
<!--/alltable-->
Expand Down
3 changes: 0 additions & 3 deletions docs/src/how-modm-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ bool state = Button::read();
// Depending on your targets, additional functions are available
Led::setOutput(Gpio::OutputType::OpenDrain);
Button::setInput(Gpio::InputType::PullUp);
Button::setInputTrigger(Gpio::InputTrigger::RisingEdge);
Button::enableExternalInterrupt();
Button::acknowledgeExternalInterruptFlag();
```

You can use these GPIOs as building blocks for more complex drivers and
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f411re/radio/lbuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<extends>modm:nucleo-f411re</extends>
<modules>
<module>modm:driver:nrf24</module>
<module>modm:platform:exti</module>
<module>modm:platform:spi:2</module>
<module>modm:platform:spi:3</module>
<module>modm:platform:timer:2</module>
Expand Down
32 changes: 10 additions & 22 deletions examples/nucleo_f411re/radio/radio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ using Nrf1Phy = modm::Nrf24Phy<Nrf1Spi, Nrf1Csn, Nrf1Ce>;
using Nrf1Config = modm::Nrf24Config<Nrf1Phy>;
using Nrf1Data = modm::Nrf24Data<Nrf1Phy, ClockUs>;


// This must normally be declared in a .cpp file, NOT a header file
MODM_ISR(EXTI9_5) // From PA9
{
Nrf1Irq::acknowledgeExternalInterruptFlag();
Board::LedD13::toggle();
Nrf1Data::interruptHandler();
}

using Nrf2Spi = SpiMaster2;
using Nrf2Sck = GpioB13;
using Nrf2Mosi = GpioB15;
Expand All @@ -81,13 +72,6 @@ using Nrf2Phy = modm::Nrf24Phy<Nrf2Spi, Nrf2Csn, Nrf2Ce>;
using Nrf2Config = modm::Nrf24Config<Nrf2Phy>;
using Nrf2Data = modm::Nrf24Data<Nrf2Phy, ClockUs>;

MODM_ISR(EXTI15_10) // From PB12
{
Nrf2Irq::acknowledgeExternalInterruptFlag();
Board::LedD13::toggle();
Nrf2Data::interruptHandler();
}

void inline
initializeSpi(uint8_t instances=0b11)
{
Expand Down Expand Up @@ -138,9 +122,11 @@ initializeNrf(uint8_t instances=0b11, uint8_t address1=nrf_address1, uint8_t add
Nrf1Config::setCrc(Nrf1Config::Crc::Crc2Byte);

Nrf1Irq::setInput(Nrf1Irq::InputType::PullUp);
Nrf1Irq::setInputTrigger(Nrf1Irq::InputTrigger::FallingEdge);
Nrf1Irq::enableExternalInterrupt();
Nrf1Irq::enableExternalInterruptVector(4);
Exti::connect<Nrf1Irq>(Exti::Trigger::FallingEdge, [](uint8_t)
{
Board::LedD13::toggle();
Nrf1Data::interruptHandler();
});
}
if (instances & 0b10)
{
Expand All @@ -155,8 +141,10 @@ initializeNrf(uint8_t instances=0b11, uint8_t address1=nrf_address1, uint8_t add
Nrf2Config::setCrc(Nrf2Config::Crc::Crc2Byte);

Nrf2Irq::setInput(Nrf2Irq::InputType::PullUp);
Nrf2Irq::setInputTrigger(Nrf2Irq::InputTrigger::FallingEdge);
Nrf2Irq::enableExternalInterrupt();
Nrf2Irq::enableExternalInterruptVector(5);
Exti::connect<Nrf2Irq>(Exti::Trigger::FallingEdge, [](uint8_t)
{
Board::LedD13::toggle();
Nrf2Data::interruptHandler();
});
}
}
6 changes: 6 additions & 0 deletions examples/stm32f469_discovery/blink/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ main()
uint32_t ms_counter{0};
uint32_t us_counter{0};

Exti::connect<Board::Button>(Exti::Trigger::FallingEdge, [count = uint32_t(0)](uint8_t line) mutable
{
count++;
MODM_LOG_INFO << "Button called " << count << " times on line " << line << modm::endl;
});

while (true)
{
{
Expand Down
5 changes: 4 additions & 1 deletion examples/stm32f469_discovery/blink/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
<option name="modm:build:build.path">../../../build/stm32f469_discovery/blink</option>
</options>
<modules>
<module>modm:platform:gpio</module>
<module>modm:platform:exti</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
</modules>
<collectors>
<collect name="modm:build:cppdefines">MODM_EXTI_HANDLER_STORAGE=12</collect>
</collectors>
</library>
5 changes: 2 additions & 3 deletions examples/stm32f469_discovery/touchscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ class LineDrawer : public modm::pt::Protothread
{
do {
// Wait for either touchscreen interrupt or clear screen button
PT_WAIT_UNTIL(Int::getExternalInterruptFlag() or Button::read());
PT_WAIT_UNTIL(Int::read() or Button::read());
if (Button::read()) display.clear();
} while (not Int::getExternalInterruptFlag());
} while (not Int::read());

Int::acknowledgeExternalInterruptFlag();
LedRed::set();

PT_CALL(touch.readTouches());
Expand Down
Loading