diff --git a/examples/nucleo_g474re/ssd1306_spi/main.cpp b/examples/nucleo_g474re/ssd1306_spi/main.cpp new file mode 100644 index 0000000000..6e3673ba56 --- /dev/null +++ b/examples/nucleo_g474re/ssd1306_spi/main.cpp @@ -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 +#include + +/** + * 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; +Display display; + +int +main() +{ + Board::initialize(); + + En7V5::reset(); + En7V5::setOutput(); + Reset::reset(); + Reset::setOutput(); + + Cs::setOutput(); + Dc::setOutput(); + MySpiMaster::connect(); + MySpiMaster::initialize(); + + 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; +} diff --git a/examples/nucleo_g474re/ssd1306_spi/project.xml b/examples/nucleo_g474re/ssd1306_spi/project.xml new file mode 100644 index 0000000000..c1c6902d35 --- /dev/null +++ b/examples/nucleo_g474re/ssd1306_spi/project.xml @@ -0,0 +1,12 @@ + + modm:nucleo-g474re + + + + + modm:driver:ssd1306.spi + modm:platform:gpio + modm:platform:spi:1 + modm:build:scons + +