Skip to content

Commit

Permalink
[examples] Add Nucleo-G431RB blink and graphics examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Oct 9, 2020
1 parent b7b9823 commit bc43bfc
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/nucleo_g431rb/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2020, Raphael Lehmann
*
* 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/board.hpp>

using namespace Board;

int
main()
{
Board::initialize();
LedD13::setOutput();

// Use the logging streams to print some messages.
// Change MODM_LOG_LEVEL above to enable or disable these messages
MODM_LOG_DEBUG << "debug" << modm::endl;
MODM_LOG_INFO << "info" << modm::endl;
MODM_LOG_WARNING << "warning" << modm::endl;
MODM_LOG_ERROR << "error" << modm::endl;

uint32_t counter(0);

while (true)
{
LedD13::toggle();
modm::delay(Button::read() ? 100ms : 500ms);

MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
}

return 0;
}
9 changes: 9 additions & 0 deletions examples/nucleo_g431rb/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library>
<extends>modm:nucleo-g431rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g431rb/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
</modules>
</library>
67 changes: 67 additions & 0 deletions examples/nucleo_g431rb/graphics/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2020, Raphael Lehmann
*
* 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/board.hpp>
#include <modm/driver/display/ili9341_spi.hpp>
using namespace Board;

namespace display
{
using Spi = SpiMaster1;
using Cs = modm::platform::GpioA3;
using Sck = modm::platform::GpioA5;
using Miso = modm::platform::GpioA6;
using Mosi = modm::platform::GpioA7;
using DataCommands = modm::platform::GpioA10;
using Reset = modm::platform::GpioA2;
using Backlight = modm::platform::GpioB3;
}

modm::Ili9341Spi<
display::Spi,
display::Cs,
display::DataCommands,
display::Reset,
display::Backlight
> tft;

/*
* Blinks the green user LED with 1 Hz.
* It is on for 90% of the time and off for 10% of the time.
*/

int
main()
{
using namespace modm::literals;
Board::initialize();
display::Spi::connect<
display::Sck::Sck, display::Miso::Miso, display::Mosi::Mosi>();
display::Spi::initialize<SystemClock, 1328_kHz>();
tft.initialize();
LedD13::set();
tft.setColor(modm::glcd::Color::black());
int16_t w = tft.getWidth();
int16_t h = tft.getHeight();
tft.drawLine({0,0}, {w, h});
tft.drawLine({w,0}, {0, h});

while (true)
{
LedD13::set();
modm::delay(900ms);

LedD13::reset();
modm::delay(100ms);
}

return 0;
}
11 changes: 11 additions & 0 deletions examples/nucleo_g431rb/graphics/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-g431rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g431rb/graphics</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:ili9341</module>
<module>modm:platform:spi:1</module>
</modules>
</library>

0 comments on commit bc43bfc

Please sign in to comment.