-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stm32] Enable extended I2C on F0/F3/F7/L0 targets
- Loading branch information
Showing
19 changed files
with
813 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) 2014, Sascha Schade | ||
* Copyright (c) 2014-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/processing/timer.hpp> | ||
#include <modm/processing/protothread.hpp> | ||
#include <modm/driver/temperature/tmp102.hpp> | ||
|
||
#include <modm/io/iostream.hpp> | ||
|
||
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > device; | ||
modm::IOStream stream(device); | ||
|
||
typedef I2cMaster1 MyI2cMaster; | ||
|
||
|
||
class ThreadOne : public modm::pt::Protothread | ||
{ | ||
public: | ||
ThreadOne() | ||
: temp(temperatureData, 0x48) | ||
{ | ||
} | ||
|
||
bool | ||
update() | ||
{ | ||
temp.update(); | ||
|
||
PT_BEGIN(); | ||
|
||
// ping the device until it responds | ||
while(true) | ||
{ | ||
// we wait until the task started | ||
if (PT_CALL(temp.ping())) | ||
break; | ||
// otherwise, try again in 100ms | ||
this->timeout.restart(100); | ||
PT_WAIT_UNTIL(this->timeout.isExpired()); | ||
} | ||
|
||
|
||
PT_CALL(temp.setUpdateRate(200)); | ||
PT_CALL(temp.enableExtendedMode()); | ||
|
||
PT_CALL(temp.configureAlertMode( | ||
modm::tmp102::ThermostatMode::Comparator, | ||
modm::tmp102::AlertPolarity::ActiveLow, | ||
modm::tmp102::FaultQueue::Faults6)); | ||
PT_CALL(temp.setLowerLimit(28.f)); | ||
PT_CALL(temp.setUpperLimit(30.f)); | ||
|
||
while (true) | ||
{ | ||
{ | ||
PT_CALL(temp.readComparatorMode(result)); | ||
float temperature = temperatureData.getTemperature(); | ||
uint8_t tI = (int) temperature; | ||
uint16_t tP = (temperature - tI) * 10000; | ||
stream << "T= " << tI << "."; | ||
if (tP == 0) | ||
{ | ||
stream << "0000 C"; | ||
} | ||
else if (tP == 625) | ||
{ | ||
stream << "0" << tP << " C"; | ||
} | ||
else | ||
{ | ||
stream << tP << " C"; | ||
} | ||
stream << modm::endl; | ||
if (result) stream << "Heat me up!" << modm::endl; | ||
} | ||
this->timeout.restart(200); | ||
PT_WAIT_UNTIL(this->timeout.isExpired()); | ||
Board::LedDown::toggle(); | ||
} | ||
|
||
PT_END(); | ||
} | ||
|
||
private: | ||
bool result; | ||
modm::ShortTimeout timeout; | ||
modm::tmp102::Data temperatureData; | ||
modm::Tmp102<MyI2cMaster> temp; | ||
}; | ||
|
||
ThreadOne one; | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
Usart1::connect<GpioA9::Tx>(); | ||
Usart1::initialize<Board::systemClock, 115'200>(); | ||
|
||
MyI2cMaster::connect<GpioB7::Sda, GpioB8::Scl>(); | ||
MyI2cMaster::initialize<Board::systemClock, 400'000>(); | ||
|
||
stream << "\n\nRESTART\n\n"; | ||
|
||
while (1) | ||
{ | ||
one.update(); | ||
Board::LedUp::toggle(); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<library> | ||
<extends>modm:board:disco-f072rb</extends> | ||
<options> | ||
<option name=":build:build.path">../../../build/stm32f072_discovery/tmp102</option> | ||
</options> | ||
<modules> | ||
<module>:driver:tmp102</module> | ||
<module>:io</module> | ||
<module>:platform:gpio</module> | ||
<module>:platform:i2c:1</module> | ||
<module>:platform:uart:1</module> | ||
<module>:processing:protothread</module> | ||
<module>:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2014, Sascha Schade | ||
* Copyright (c) 2014-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/processing/timer.hpp> | ||
#include <modm/processing/protothread.hpp> | ||
#include <modm/driver/temperature/tmp102.hpp> | ||
|
||
typedef I2cMaster1 MyI2cMaster; | ||
|
||
|
||
class ThreadOne : public modm::pt::Protothread | ||
{ | ||
public: | ||
ThreadOne() | ||
: temp(temperatureData, 0x48) | ||
{ | ||
} | ||
|
||
bool | ||
update() | ||
{ | ||
temp.update(); | ||
|
||
PT_BEGIN(); | ||
|
||
// ping the device until it responds | ||
while(true) | ||
{ | ||
// we wait until the task started | ||
if (PT_CALL(temp.ping())) | ||
break; | ||
// otherwise, try again in 100ms | ||
this->timeout.restart(100); | ||
PT_WAIT_UNTIL(this->timeout.isExpired()); | ||
} | ||
|
||
|
||
PT_CALL(temp.setUpdateRate(200)); | ||
PT_CALL(temp.enableExtendedMode()); | ||
|
||
PT_CALL(temp.configureAlertMode( | ||
modm::tmp102::ThermostatMode::Comparator, | ||
modm::tmp102::AlertPolarity::ActiveLow, | ||
modm::tmp102::FaultQueue::Faults6)); | ||
PT_CALL(temp.setLowerLimit(28.f)); | ||
PT_CALL(temp.setUpperLimit(30.f)); | ||
|
||
while (true) | ||
{ | ||
{ | ||
PT_CALL(temp.readComparatorMode(result)); | ||
float temperature = temperatureData.getTemperature(); | ||
uint8_t tI = (int) temperature; | ||
uint16_t tP = (temperature - tI) * 10000; | ||
MODM_LOG_INFO << "T= " << tI << "."; | ||
if (tP == 0) | ||
{ | ||
MODM_LOG_INFO << "0000 C"; | ||
} | ||
else if (tP == 625) | ||
{ | ||
MODM_LOG_INFO << "0" << tP << " C"; | ||
} | ||
else | ||
{ | ||
MODM_LOG_INFO << tP << " C"; | ||
} | ||
if (result) { MODM_LOG_INFO << " Heat me up!"; } | ||
MODM_LOG_INFO << modm::endl; | ||
} | ||
this->timeout.restart(200); | ||
PT_WAIT_UNTIL(this->timeout.isExpired()); | ||
Board::LedD13::toggle(); | ||
} | ||
|
||
PT_END(); | ||
} | ||
|
||
private: | ||
bool result; | ||
modm::ShortTimeout timeout; | ||
modm::tmp102::Data temperatureData; | ||
modm::Tmp102<MyI2cMaster> temp; | ||
}; | ||
|
||
ThreadOne one; | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Board::LedD13::setOutput(modm::Gpio::Low); | ||
|
||
MyI2cMaster::connect<Board::D14::Sda, Board::D15::Scl>(); | ||
MyI2cMaster::initialize<Board::systemClock, 400'000>(); | ||
|
||
MODM_LOG_INFO << "\n\nRESTART\n\n"; | ||
|
||
while (1) | ||
{ | ||
one.update(); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<library> | ||
<extends>modm:board:disco-f746ng</extends> | ||
<options> | ||
<option name=":build:build.path">../../../build/stm32f746g_discovery/tmp102</option> | ||
</options> | ||
<modules> | ||
<module>:driver:tmp102</module> | ||
<module>:io</module> | ||
<module>:platform:i2c:1</module> | ||
<module>:processing:protothread</module> | ||
<module>:build:scons</module> | ||
</modules> | ||
</library> |
Submodule modm-devices
updated
66 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.