Skip to content

Commit

Permalink
[driver] Fix ILI9341 and add SPI example for it
Browse files Browse the repository at this point in the history
Signed-off-by: delphi <cpp.create@gmail.com>
  • Loading branch information
asmfreak committed Sep 27, 2020
1 parent a6f1186 commit 43f32e6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
68 changes: 68 additions & 0 deletions examples/stm32f103c8t6_blue_pill/graphics/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2016, Sascha Schade
* Copyright (c) 2017, Niklas Hauser
*
* 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::GpioA4;
using Sck = modm::platform::GpioA5;
using Miso = modm::platform::GpioA6;
using Mosi = modm::platform::GpioA7;
using DataCommands = modm::platform::GpioB0;
using Reset = modm::platform::GpioB1;
using Backlight = modm::platform::GpioB10;
}

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, 1125_kHz>();
tft.initialize();
LedGreen::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)
{
LedGreen::set();
modm::delay(900ms);

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

return 0;
}
2 changes: 2 additions & 0 deletions examples/stm32f103c8t6_blue_pill/graphics/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Replace this with your custom programmer
source [find interface/stlink-v2.cfg]
12 changes: 12 additions & 0 deletions examples/stm32f103c8t6_blue_pill/graphics/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:blue-pill</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f103c8t6_blue_pill/graphics</option>
<option name="modm:build:openocd.cfg">openocd.cfg</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:ili9341</module>
<module>modm:platform:spi:1</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion src/modm/driver/display/ili9341.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Ili9341 : public Interface, public modm::GraphicDisplay
using Rotation = ili9341::Rotation;
using DisplayMode = ili9341::DisplayMode;

template<bool B= std::is_default_constructible_v<Interface>, std::enable_if_t<B> = 0>
template<bool B=std::is_default_constructible_v<Interface>, std::enable_if_t<B, bool> = 0>
Ili9341(): Interface()
{
Reset::setOutput(modm::Gpio::High);
Expand Down

0 comments on commit 43f32e6

Please sign in to comment.