Skip to content

Commit

Permalink
[examples] Add SSD1306 SPI display example for Nucleo-G474RE
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Oct 11, 2023
1 parent 275c635 commit 4c0e511
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
85 changes: 85 additions & 0 deletions examples/nucleo_g474re/ssd1306_spi/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2023, 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/ssd1306_spi.hpp>

/**
* SSD1306 display in SPI 4-wire mode
*
* SCK <-> Arduino D3 / GpioB3
* MOSI <-> Arduino D4 / GpioB5
* CS <-> Arduino D5 / GpioB4
* D/C# <-> Arduino D2 / GpioA10
* RESET# <-> Arduino D7 / GpioA8
*
* En7V5 <-> Arduino D6 / GpioB10
*
* TODO: Describe charge pump setup for 7.5V
*/

using MySpiMaster = modm::platform::SpiMaster1;
using Sck = Board::D3;
using Mosi = Board::D4;
using Cs = Board::D5;
using Dc = Board::D2;
using Reset = Board::D7;
using En7V5 = Board::D6;
using Display = modm::Ssd1306Spi<MySpiMaster, Cs, Dc, 32>;
Display display;

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

En7V5::reset();
En7V5::setOutput();
Reset::reset();
Reset::setOutput();

Cs::setOutput();
Dc::setOutput();
MySpiMaster::connect<Sck::Sck, Mosi::Mosi>();
MySpiMaster::initialize<Board::SystemClock, 660_kHz>();

Cs::set();
En7V5::set();
modm::delay(500ms);

Reset::set();
modm::delay(1ms);

RF_CALL_BLOCKING(display.initialize());
RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0));
RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted));
RF_CALL_BLOCKING(display.setContrast(80));

display.setFont(modm::font::Assertion);

modm::ShortPeriodicTimer timer(333ms);
uint16_t counter(0);

while (true)
{
if (timer.execute())
{
display.clear();
display.setCursor(1, 1);
display << "Hello World!";
display.setCursor(1,17);
display << counter++;

display.update();
}
}

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

0 comments on commit 4c0e511

Please sign in to comment.