-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rpi] Adds basic support for GPIO on Raspberry Pi boards
- Loading branch information
Erik Henriksson
committed
Aug 14, 2020
1 parent
824f6b5
commit 8f79fca
Showing
11 changed files
with
403 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2020, Erik Henriksson | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <modm/debug/logger.hpp> | ||
#include <modm/board.hpp> | ||
|
||
using namespace Board; | ||
|
||
int main() | ||
{ | ||
Board::initialize(); | ||
GpioPin<0>::setOutput(); | ||
MODM_LOG_INFO << "Blink blink..."; | ||
for (int i = 0; i < 10; ++i) { | ||
GpioPin<0>::toggle(); | ||
modm::delay(500ms); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<library> | ||
<extends>modm:raspberrypi-4</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/rpi/blinky</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2020, Erik Henriksson | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <modm/debug/logger.hpp> | ||
#include <modm/platform.hpp> | ||
|
||
#include <wiringPi.h> | ||
|
||
using namespace modm::platform; | ||
|
||
namespace Board | ||
{ | ||
|
||
struct SystemClock {}; | ||
|
||
inline void | ||
initialize() | ||
{ | ||
wiringPiSetup(); | ||
} | ||
|
||
} // Board namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<library> | ||
<repositories> | ||
<repository> | ||
<path>../../../../repo.lb</path> | ||
</repository> | ||
</repositories> | ||
|
||
<options> | ||
<option name="modm:target">hosted-rpi</option> | ||
</options> | ||
<modules> | ||
<module>modm:board:raspberrypi-4</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2020, Erik Henriksson | ||
# | ||
# This file is part of the modm project. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# ----------------------------------------------------------------------------- | ||
|
||
def init(module): | ||
module.name = ":board:raspberrypi-4" | ||
module.description = """\ | ||
# Raspberry Pi 4 | ||
""" | ||
|
||
def prepare(module, options): | ||
if options[":target"].partname != "hosted-rpi": | ||
return False | ||
|
||
module.depends(":platform:core", ":platform:gpio", ":debug") | ||
return True | ||
|
||
def build(env): | ||
env.outbasepath = "modm/src/modm/board" | ||
env.copy('.') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2020, Erik Henriksson | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <modm/architecture/interface/gpio.hpp> | ||
|
||
namespace modm | ||
{ | ||
|
||
namespace platform | ||
{ | ||
|
||
/// @ingroup modm_platform_gpio | ||
enum class | ||
Peripheral | ||
{ | ||
BitBang, | ||
// ... | ||
}; | ||
|
||
/// @ingroup modm_platform_gpio | ||
struct Gpio | ||
{ | ||
/// Each Input Pin can be configured in one of these states. | ||
enum class | ||
InputType : uint8_t | ||
{ | ||
Floating, ///< The input pin is left floating | ||
}; | ||
|
||
enum class | ||
OutputType : uint8_t | ||
{ | ||
PushPull ///< push-pull on output | ||
}; | ||
|
||
/// Available ports on this device. | ||
enum class | ||
Port | ||
{ | ||
// ... | ||
}; | ||
|
||
enum class | ||
Signal | ||
{ | ||
BitBang, | ||
// ... | ||
}; | ||
|
||
/// @endcond | ||
}; | ||
|
||
/// @} | ||
|
||
} // namespace platform | ||
|
||
} // namespace modm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2020, Erik Henriksson | ||
# | ||
# This file is part of the modm project. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# ----------------------------------------------------------------------------- | ||
|
||
|
||
def init(module): | ||
module.name = ":platform:gpio" | ||
module.description = "Hosted GPIO for Raspberry Pi" | ||
|
||
|
||
def prepare(module, options): | ||
if not options[":target"].has_driver("gpio"): | ||
return False | ||
|
||
module.depends(":architecture:gpio") | ||
return True | ||
|
||
|
||
def build(env): | ||
env.substitutions = {"target": env[":target"].identifier} | ||
env.outbasepath = "modm/src/modm/platform/gpio" | ||
|
||
env.collect(":build:library", "wiringPi") | ||
|
||
env.copy(".") | ||
env.copy("../common/inverted.hpp", "inverted.hpp") | ||
env.copy("../common/connector.hpp", "connector.hpp") | ||
env.template("../common/connector_detail.hpp.in", "connector_detail.hpp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2017, Niklas Hauser | ||
* Copyright (c) 2018, Fabian Greif | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <modm/architecture/interface/gpio.hpp> | ||
#include <wiringPi.h> | ||
|
||
#include "base.hpp" | ||
|
||
|
||
namespace modm | ||
{ | ||
|
||
namespace platform | ||
{ | ||
|
||
template< int Pin > | ||
class GpioPin : public Gpio, public modm::GpioIO | ||
{ | ||
static Gpio::InputType inputType; | ||
public: | ||
using Output = GpioPin<Pin>; | ||
using Input = GpioPin<Pin>; | ||
using IO = GpioPin<Pin>; | ||
using Type = GpioPin<Pin>; | ||
|
||
public: | ||
inline static void configure(Gpio::InputType type) {} | ||
modm_always_inline static void setInput() { | ||
pinMode(Pin, INPUT); | ||
} | ||
inline static void setInput(Gpio::InputType type) { | ||
setInput(); | ||
} | ||
modm_always_inline static void setOutput() { | ||
pinMode(Pin, OUTPUT); | ||
} | ||
modm_always_inline static void setOutput(OutputType) { | ||
setOutput(); | ||
} | ||
modm_always_inline static void setOutput(bool status) { | ||
setOutput(); | ||
set(status); | ||
} | ||
inline static void set() { | ||
digitalWrite(Pin, HIGH); | ||
} | ||
modm_always_inline static void reset() { | ||
digitalWrite(Pin, LOW); | ||
} | ||
inline static void set(bool status) { | ||
digitalWrite(Pin, status); | ||
} | ||
inline static bool isSet() { | ||
return digitalRead(Pin); | ||
} | ||
inline static void toggle() { | ||
if (isSet()) { set(); } | ||
else { reset(); } | ||
} | ||
modm_always_inline static modm::Gpio::Direction getDirection() { | ||
return modm::Gpio::Direction::Out; | ||
} | ||
}; | ||
|
||
/// @} | ||
|
||
} // namespace platform | ||
|
||
} // namespace modm | ||
|
Oops, something went wrong.