Skip to content

Commit

Permalink
[examples] STM32F3 discovery board comparator example
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Jul 15, 2018
1 parent 921d1ab commit 7f92986
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
67 changes: 67 additions & 0 deletions examples/stm32f3_discovery/comp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013, Kevin Läufer
* Copyright (c) 2013-2014, Sascha Schade
* Copyright (c) 2013, 2015-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/debug/logger.hpp>

#include <modm/platform/comp/comp_1.hpp>
#include <modm/platform/comp/comp_2.hpp>

// Set the log level
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO

// Create an IODeviceWrapper around the Uart Peripheral we want to use
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
modm::log::Logger modm::log::debug(loggerDevice);
modm::log::Logger modm::log::info(loggerDevice);
modm::log::Logger modm::log::warning(loggerDevice);
modm::log::Logger modm::log::error(loggerDevice);

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

// initialize Uart2 for MODM_LOG_
Usart2::connect<GpioOutputA2::Tx>();
Usart2::initialize<Board::systemClock, 115200>();

// 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;

using Comparator = modm::platform::Comp2;

Comparator::initialize(
Comparator::InvertingInput::Vref1Div2,
Comparator::NonInvertingInput::BitUnset, // GpioA7
Comparator::Output::Tim1Or8BkIn2,
Comparator::Hysteresis::NoHysteresis,
Comparator::Mode::HighSpeed,
Comparator::Polarity::NonInverted,
false);

while (1)
{
modm::delayMilliseconds(250);
MODM_LOG_INFO << "Comparator: " << Comparator::getOutput() << modm::endl;
}

return 0;
}
13 changes: 13 additions & 0 deletions examples/stm32f3_discovery/comp/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<library>
<extends>../../../src/modm/board/disco_f303vc/board.xml</extends>
<options>
<option name=":build.scons:build.path">../../../build/stm32f3_discovery/blink</option>
</options>
<modules>
<module>:debug</module>
<module>:platform:uart:2</module>
<module>modm:platform:comp:*</module>
<module>:build.scons</module>
</modules>
</library>

0 comments on commit 7f92986

Please sign in to comment.