|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright (c) 2023, Raphael Lehmann | 
|  | 3 | + * | 
|  | 4 | + * This file is part of the modm project. | 
|  | 5 | + * | 
|  | 6 | + * This Source Code Form is subject to the terms of the Mozilla Public | 
|  | 7 | + * License, v. 2.0. If a copy of the MPL was not distributed with this | 
|  | 8 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. | 
|  | 9 | + */ | 
|  | 10 | + | 
|  | 11 | +#include <modm/board.hpp> | 
|  | 12 | +#include <modm/driver/display/ssd1306_spi.hpp> | 
|  | 13 | + | 
|  | 14 | +/** | 
|  | 15 | + * SSD1306 display in SPI 4-wire mode | 
|  | 16 | + * | 
|  | 17 | + * SCK		<-> Arduino D3 / GpioB3 | 
|  | 18 | + * MOSI		<-> Arduino D4 / GpioB5 | 
|  | 19 | + * CS		<-> Arduino D5 / GpioB4 | 
|  | 20 | + * D/C#		<-> Arduino D2 / GpioA10 | 
|  | 21 | + * RESET#	<-> Arduino D7 / GpioA8 | 
|  | 22 | + * | 
|  | 23 | + * En7V5	<-> Arduino D6 / GpioB10 | 
|  | 24 | + * | 
|  | 25 | + * TODO: Describe charge pump setup for 7.5V | 
|  | 26 | + */ | 
|  | 27 | + | 
|  | 28 | +using MySpiMaster = modm::platform::SpiMaster1; | 
|  | 29 | +using Sck = Board::D3; | 
|  | 30 | +using Mosi = Board::D4; | 
|  | 31 | +using Cs = Board::D5; | 
|  | 32 | +using Dc = Board::D2; | 
|  | 33 | +using Reset = Board::D7; | 
|  | 34 | +using En7V5 = Board::D6; | 
|  | 35 | +using Display = modm::Ssd1306Spi<MySpiMaster, Cs, Dc, 32>; | 
|  | 36 | +Display display; | 
|  | 37 | + | 
|  | 38 | +int | 
|  | 39 | +main() | 
|  | 40 | +{ | 
|  | 41 | +	Board::initialize(); | 
|  | 42 | + | 
|  | 43 | +	En7V5::reset(); | 
|  | 44 | +	En7V5::setOutput(); | 
|  | 45 | +	Reset::reset(); | 
|  | 46 | +	Reset::setOutput(); | 
|  | 47 | + | 
|  | 48 | +	Cs::setOutput(); | 
|  | 49 | +	Dc::setOutput(); | 
|  | 50 | +	MySpiMaster::connect<Sck::Sck, Mosi::Mosi>(); | 
|  | 51 | +	MySpiMaster::initialize<Board::SystemClock, 660_kHz>(); | 
|  | 52 | + | 
|  | 53 | +	Cs::set(); | 
|  | 54 | +	En7V5::set(); | 
|  | 55 | +	modm::delay(500ms); | 
|  | 56 | + | 
|  | 57 | +	Reset::set(); | 
|  | 58 | +	modm::delay(1ms); | 
|  | 59 | + | 
|  | 60 | +	RF_CALL_BLOCKING(display.initialize()); | 
|  | 61 | +	RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0)); | 
|  | 62 | +	RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted)); | 
|  | 63 | +	RF_CALL_BLOCKING(display.setContrast(80)); | 
|  | 64 | + | 
|  | 65 | +	display.setFont(modm::font::Assertion); | 
|  | 66 | + | 
|  | 67 | +	modm::ShortPeriodicTimer timer(333ms); | 
|  | 68 | +	uint16_t counter(0); | 
|  | 69 | + | 
|  | 70 | +	while (true) | 
|  | 71 | +	{ | 
|  | 72 | +		if (timer.execute()) | 
|  | 73 | +		{ | 
|  | 74 | +			display.clear(); | 
|  | 75 | +			display.setCursor(1, 1); | 
|  | 76 | +			display << "Hello World!"; | 
|  | 77 | +			display.setCursor(1,17); | 
|  | 78 | +			display << counter++; | 
|  | 79 | + | 
|  | 80 | +			display.update(); | 
|  | 81 | +		} | 
|  | 82 | +	} | 
|  | 83 | + | 
|  | 84 | +	return 0; | 
|  | 85 | +} | 
0 commit comments