diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index ed2a042e9e..e0e492bda5 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -67,7 +67,7 @@ jobs:
- name: Hosted Examples
if: always()
run: |
- (cd examples && ../tools/scripts/examples_compile.py linux)
+ (cd examples/linux && ../../tools/scripts/examples_compile.py block_device assert build_info etl fiber git logger printf threads)
- name: Compile STM32 Examples
if: always()
diff --git a/examples/avr/display/hd44780/project.xml b/examples/avr/display/hd44780/project.xml
index 37e48bec39..a926d56242 100644
--- a/examples/avr/display/hd44780/project.xml
+++ b/examples/avr/display/hd44780/project.xml
@@ -8,6 +8,7 @@
modm:driver:hd44780
modm:platform:gpio
modm:platform:core
+ modm:platform:clock
modm:build:scons
diff --git a/examples/avr/qmc5883l/main.cpp b/examples/avr/qmc5883l/main.cpp
index edcee2a985..db58fe0a09 100644
--- a/examples/avr/qmc5883l/main.cpp
+++ b/examples/avr/qmc5883l/main.cpp
@@ -17,7 +17,7 @@
using namespace Board;
using namespace std::chrono_literals;
-using Compass = Qmc5883l;
+using Compass = modm::Qmc5883l;
Compass::Data data;
Compass compass(data);
modm::atomic::Flag dataReady(true);
@@ -54,7 +54,7 @@ main()
<< modm::endl;
} else
{
- MODM_LOG_INFO << "readDataBlocking(): Error: " << uint8_t(I2cMaster::getErrorState())
+ MODM_LOG_INFO << "readData(): Error: " << uint8_t(I2cMaster::getErrorState())
<< modm::endl;
}
}
diff --git a/examples/generic/ros/environment/thread_display.cpp b/examples/generic/ros/environment/thread_display.cpp
index d96d565f9f..4fba8787fc 100644
--- a/examples/generic/ros/environment/thread_display.cpp
+++ b/examples/generic/ros/environment/thread_display.cpp
@@ -32,7 +32,7 @@ DisplayThread::update()
// Wait for 100 msec unitl display powered up.
modm::this_fiber::sleep_for(100ms);
- display.initializeBlocking();
+ display.initialize();
display.setFont(modm::font::Assertion);
display.clear();
display << "Hello World!";
diff --git a/examples/nucleo_f042k6/spi_dma/main.cpp b/examples/nucleo_f042k6/spi_dma/main.cpp
index 611068fe38..a82b7b025f 100644
--- a/examples/nucleo_f042k6/spi_dma/main.cpp
+++ b/examples/nucleo_f042k6/spi_dma/main.cpp
@@ -33,10 +33,10 @@ int main()
uint8_t receiveBuffer[13];
// send out 12 bytes, don't care about response
- Spi::transferBlocking(sendBuffer, nullptr, 12);
+ Spi::transfer(sendBuffer, nullptr, 12);
// send out 12 bytes, read in 12 bytes
- Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
+ Spi::transfer(sendBuffer, receiveBuffer, 12);
}
return 0;
diff --git a/examples/nucleo_f303re/spi_dma/main.cpp b/examples/nucleo_f303re/spi_dma/main.cpp
index 5e60bf438f..6e3f0ac8f7 100644
--- a/examples/nucleo_f303re/spi_dma/main.cpp
+++ b/examples/nucleo_f303re/spi_dma/main.cpp
@@ -33,10 +33,10 @@ int main()
uint8_t receiveBuffer[13];
// send out 12 bytes, don't care about response
- Spi::transferBlocking(sendBuffer, nullptr, 12);
+ Spi::transfer(sendBuffer, nullptr, 12);
// send out 12 bytes, read in 12 bytes
- Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
+ Spi::transfer(sendBuffer, receiveBuffer, 12);
}
return 0;
diff --git a/examples/nucleo_f401re/distance_vl53l0/project.xml b/examples/nucleo_f401re/distance_vl53l0/project.xml
index ebb54c6ac7..47779d3be6 100644
--- a/examples/nucleo_f401re/distance_vl53l0/project.xml
+++ b/examples/nucleo_f401re/distance_vl53l0/project.xml
@@ -7,6 +7,7 @@
modm:driver:vl53l0
modm:platform:i2c:1
modm:processing:fiber
+ modm:processing:timer
modm:build:scons
diff --git a/examples/nucleo_g071rb/amnb/main.cpp b/examples/nucleo_g071rb/amnb/main.cpp
index f51990a325..5cd952c360 100644
--- a/examples/nucleo_g071rb/amnb/main.cpp
+++ b/examples/nucleo_g071rb/amnb/main.cpp
@@ -36,16 +36,14 @@ Listener listeners[] =
};
Action actions[] =
{
- {1, []() -> Response
+ {1, [counter=uint8_t{}]() mutable -> Response
{
- static uint8_t counter{0};
MODM_LOG_INFO << "Node1 or Node3 received Action 1" << modm::endl;
return counter++;
}
},
- {2, [](const uint32_t& data) -> Response
+ {2, [counter=uint8_t{}](const uint32_t& data) mutable -> Response
{
- static uint8_t counter{0};
MODM_LOG_INFO << "Node1 or Node3 received Action 2 with argument: " << data << modm::endl;
return ErrorResponse(counter++);
}
@@ -82,15 +80,17 @@ modm::Fiber fiber_demo([]
node1.broadcast(1, counter++);
node3.broadcast(2);
- auto res1 = node2.request(1, 1);
+ auto res1 = node1.request(1, 1);
MODM_LOG_INFO << "Node1 responded with: " << res1.error();
- if (res1) { MODM_LOG_INFO << " " << *res1 << modm::endl; }
+ if (res1) { MODM_LOG_INFO << " " << *res1; }
+ MODM_LOG_INFO << modm::endl;
auto res2 = node1.request(3, 2, counter);
- MODM_LOG_INFO << "Node3 responded with: " << res2.error();
+ MODM_LOG_INFO << "Node1 responded with: " << res2.error();
if (res2.hasUserError()) {
- MODM_LOG_INFO << " " << *res2.userError() << modm::endl;
+ MODM_LOG_INFO << " " << *res2.userError();
}
+ MODM_LOG_INFO << modm::endl;
if (counter % 10 == 0)
{
diff --git a/examples/nucleo_l432kc/spi_dma/main.cpp b/examples/nucleo_l432kc/spi_dma/main.cpp
index 3c5b45d0f1..af84cd8741 100644
--- a/examples/nucleo_l432kc/spi_dma/main.cpp
+++ b/examples/nucleo_l432kc/spi_dma/main.cpp
@@ -34,10 +34,10 @@ int main()
uint8_t receiveBuffer[13];
// send out 12 bytes, don't care about response
- Spi::transferBlocking(sendBuffer, nullptr, 12);
+ Spi::transfer(sendBuffer, nullptr, 12);
// send out 12 bytes, read in 12 bytes
- Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
+ Spi::transfer(sendBuffer, receiveBuffer, 12);
}
return 0;
diff --git a/examples/nucleo_l432kc/uart_spi/main.cpp b/examples/nucleo_l432kc/uart_spi/main.cpp
index 9c3a98385d..83a09dcf72 100644
--- a/examples/nucleo_l432kc/uart_spi/main.cpp
+++ b/examples/nucleo_l432kc/uart_spi/main.cpp
@@ -25,7 +25,7 @@ main()
while (true)
{
- UartSpiMaster1::transferBlocking(0xF0);
+ UartSpiMaster1::transfer(0xF0);
}
return 0;
diff --git a/examples/rp_pico/spi_dma/main.cpp b/examples/rp_pico/spi_dma/main.cpp
index e019436b3a..f3ba220ec0 100644
--- a/examples/rp_pico/spi_dma/main.cpp
+++ b/examples/rp_pico/spi_dma/main.cpp
@@ -42,12 +42,12 @@ int main()
usb_stream0 << "Spi tx only" << modm::endl;
tud_task();
// send out 12 bytes, don't care about response
- Spi::transferBlocking(sendBuffer, nullptr, 12);
+ Spi::transfer(sendBuffer, nullptr, 12);
usb_stream0 << "Spi send \"" << reinterpret_cast(sendBuffer) << "\"" << modm::endl;
tud_task();
// send out 12 bytes, read in 12 bytes
- Spi::transferBlocking(sendBuffer, receiveBuffer, 12);
+ Spi::transfer(sendBuffer, receiveBuffer, 12);
receiveBuffer[12] = 0;
usb_stream0 << "Spi received \"" << reinterpret_cast(receiveBuffer) << "\"" << modm::endl;
tud_task();
diff --git a/examples/samg55_xplained_pro/spi-loopback/main.cpp b/examples/samg55_xplained_pro/spi-loopback/main.cpp
index 98c20ebf6e..dce76f59ad 100644
--- a/examples/samg55_xplained_pro/spi-loopback/main.cpp
+++ b/examples/samg55_xplained_pro/spi-loopback/main.cpp
@@ -29,7 +29,7 @@ int main()
uint8_t tx[] = {0xa5, 0x21};
uint8_t rx[2];
- SpiMaster0::transferBlocking(tx, rx, 2);
+ SpiMaster0::transfer(tx, rx, 2);
if(rx[0] == 0xa5 && rx[1] == 0x21) {
flash_time_ms = 500;
diff --git a/examples/stm32f4_discovery/display/ssd1306/main.cpp b/examples/stm32f4_discovery/display/ssd1306/main.cpp
index aeea40c8a4..633ffbca41 100644
--- a/examples/stm32f4_discovery/display/ssd1306/main.cpp
+++ b/examples/stm32f4_discovery/display/ssd1306/main.cpp
@@ -35,7 +35,7 @@ main()
MyI2cMaster::connect();
MyI2cMaster::initialize();
- display.initializeBlocking();
+ display.initialize();
display.setFont(modm::font::Assertion);
display << "Hello World!";
display.update();
diff --git a/examples/stm32f4_discovery/spi/main.cpp b/examples/stm32f4_discovery/spi/main.cpp
index c20a834f29..a17412fd97 100644
--- a/examples/stm32f4_discovery/spi/main.cpp
+++ b/examples/stm32f4_discovery/spi/main.cpp
@@ -36,7 +36,7 @@ main()
while (true)
{
// Connect Mosi to Miso to create a loopback
- data = SpiMaster::transferBlocking(data);
+ data = SpiMaster::transfer(data);
data++;
// This will be spamming the bus
}
diff --git a/examples/stm32f4_discovery/uart_spi/main.cpp b/examples/stm32f4_discovery/uart_spi/main.cpp
index 7168244355..ed1a49c668 100644
--- a/examples/stm32f4_discovery/uart_spi/main.cpp
+++ b/examples/stm32f4_discovery/uart_spi/main.cpp
@@ -24,7 +24,7 @@ main()
while (true)
{
- UartSpiMaster2::transferBlocking(0xF0);
+ UartSpiMaster2::transfer(0xF0);
}
return 0;
diff --git a/examples/stm32f746g_discovery/tmp102/main.cpp b/examples/stm32f746g_discovery/tmp102/main.cpp
index 362011ca5b..557f3529c9 100644
--- a/examples/stm32f746g_discovery/tmp102/main.cpp
+++ b/examples/stm32f746g_discovery/tmp102/main.cpp
@@ -13,7 +13,6 @@
#include
#include
-#include
#include
typedef I2cMaster1 MyI2cMaster;
diff --git a/src/modm/architecture/interface/block_device.hpp b/src/modm/architecture/interface/block_device.hpp
index 78b6312ecf..eebe04aae3 100644
--- a/src/modm/architecture/interface/block_device.hpp
+++ b/src/modm/architecture/interface/block_device.hpp
@@ -14,7 +14,6 @@
#define MODM_INTERFACE_BLOCK_DEVICE_HPP
#include
-#include
namespace modm
{
@@ -40,11 +39,11 @@ class BlockDevice
#ifdef __DOXYGEN__
public:
/// Initializes the storage hardware
- modm::ResumableResult
+ bool
initialize();
/// Deinitializes the storage hardware
- modm::ResumableResult
+ bool
deinitialize();
/** Read data from one or more blocks
@@ -54,7 +53,7 @@ class BlockDevice
* @param size Size to read in bytes (multiple of read block size)
* @return True on success
*/
- modm::ResumableResult
+ bool
read(uint8_t *buffer, bd_address_t address, bd_size_t size);
/** Program blocks with data
@@ -66,7 +65,7 @@ class BlockDevice
* @param size Size to write in bytes (multiple of read block size)
* @return True on success
*/
- modm::ResumableResult
+ bool
program(const uint8_t *buffer, bd_address_t address, bd_size_t size);
/** Erase blocks
@@ -77,7 +76,7 @@ class BlockDevice
* @param size Size to erase in bytes (multiple of read block size)
* @return True on success
*/
- modm::ResumableResult
+ bool
erase(bd_address_t address, bd_size_t size);
/** Writes data to one or more blocks after erasing them
@@ -89,7 +88,7 @@ class BlockDevice
* @param size Size to write in bytes (multiple of read block size)
* @return True on success
*/
- modm::ResumableResult
+ bool
write(const uint8_t *buffer, bd_address_t address, bd_size_t size);
public:
diff --git a/src/modm/architecture/interface/gpio_expander.hpp b/src/modm/architecture/interface/gpio_expander.hpp
index cad784cbf7..58fd6013ba 100644
--- a/src/modm/architecture/interface/gpio_expander.hpp
+++ b/src/modm/architecture/interface/gpio_expander.hpp
@@ -14,7 +14,6 @@
#include
#include
-#include
#include
namespace modm
@@ -73,27 +72,27 @@ class GpioExpander
public:
/// Sets one or more pins to output
- modm::ResumableResult
+ bool
setOutput(Pins pins);
/// Sets one or more pins to logic high
/// @warning only modifies pins that have previously been set to output!
- modm::ResumableResult
+ bool
set(Pins pins);
/// Resets one or more pins to logic low
/// @warning only modifies pins that have previously been set to output!
- modm::ResumableResult
+ bool
reset(Pins pins);
/// Toggles one or more pins
/// @warning only modifies pins that have previously been set to output!
- modm::ResumableResult
+ bool
toggle(Pins pins);
/// sets one or more pins to high or low level
/// @warning only modifies pins that have previously been set to output!
- modm::ResumableResult
+ bool
set(Pins pins, bool value);
/// Returns the set logical output state of the pin.
@@ -106,7 +105,7 @@ class GpioExpander
public:
/// Sets one or more pins to input
- modm::ResumableResult
+ bool
setInput(Pins pins);
/// Returns true if **all** pins have a high level
@@ -116,17 +115,17 @@ class GpioExpander
read(Pins pins) const;
/// Reads the inputs and buffers them
- modm::ResumableResult
+ bool
readInput();
public:
/// Writes data to the entire port
/// @warning only modifies pins that have previously been set to output!
- modm::ResumableResult
+ bool
writePort(PortType data);
/// Reads the entire port, buffers them and outputs the result to data.
- modm::ResumableResult
+ bool
readPort(PortType &data);
public:
@@ -208,7 +207,7 @@ class GpioExpanderPin : public modm::GpioIO
static void
setOutput()
{
- RF_CALL_BLOCKING(expander.setOutput(pin));
+ expander.setOutput(pin);
}
static void inline
@@ -220,25 +219,25 @@ class GpioExpanderPin : public modm::GpioIO
static void
set()
{
- RF_CALL_BLOCKING(expander.set(pin));
+ expander.set(pin);
}
static void
set(bool value)
{
- RF_CALL_BLOCKING(expander.set(pin, value));
+ expander.set(pin, value);
}
static void
reset()
{
- RF_CALL_BLOCKING(expander.reset(pin));
+ expander.reset(pin);
}
static void
toggle()
{
- RF_CALL_BLOCKING(expander.toggle(pin));
+ expander.toggle(pin);
}
static bool inline
@@ -250,13 +249,13 @@ class GpioExpanderPin : public modm::GpioIO
static void
setInput()
{
- RF_CALL_BLOCKING(expander.setInput(pin));
+ expander.setInput(pin);
}
static bool
read()
{
- RF_CALL_BLOCKING(expander.readInput());
+ expander.readInput();
return expander.read(pin);
}
@@ -370,19 +369,19 @@ class GpioExpanderPort : public modm::GpioPort
static void
setOutput()
{
- RF_CALL_BLOCKING(expander.setOutput(Pins(portMask)));
+ expander.setOutput(Pins(portMask));
}
static void
setInput()
{
- RF_CALL_BLOCKING(expander.setInput(Pins(portMask)));
+ expander.setInput(Pins(portMask));
}
static PortType
read()
{
- RF_CALL_BLOCKING(expander.readInput());
+ expander.readInput();
return (expander.getInputs().value & portMask) >> StartIndex;
}
@@ -392,13 +391,13 @@ class GpioExpanderPort : public modm::GpioPort
{
data = (data & dataMask) << StartIndex;
data = (expander.getOutputs().value & ~portMask) | data;
- RF_CALL_BLOCKING( expander.writePort(data) );
+ expander.writePort(data);
}
static void
toggle()
{
- RF_CALL_BLOCKING( expander.toggle(Pins(portMask)) );
+ expander.toggle(Pins(portMask));
}
};
@@ -439,19 +438,19 @@ class GpioExpanderPort> StartIndexReversed;
}
@@ -461,13 +460,13 @@ class GpioExpanderPort
#include
-#include
+#include
namespace modm
{
@@ -116,13 +116,13 @@ struct I2c
static void
resetDevices(uint32_t baudrate = 100'000)
{
- const auto delay = 500'000ul / baudrate;
+ const std::chrono::microseconds delay{500'000ul / baudrate};
for (uint_fast8_t ii = 0; ii < 9; ++ii) {
Scl::reset();
- modm::delay_us(delay);
+ modm::this_fiber::sleep_for(delay);
Scl::set();
- modm::delay_us(delay);
+ modm::this_fiber::sleep_for(delay);
}
}
diff --git a/src/modm/architecture/interface/i2c_device.hpp b/src/modm/architecture/interface/i2c_device.hpp
index 8c2a3d3b56..8fe4510342 100644
--- a/src/modm/architecture/interface/i2c_device.hpp
+++ b/src/modm/architecture/interface/i2c_device.hpp
@@ -15,7 +15,7 @@
#include "i2c.hpp"
#include "i2c_master.hpp"
#include "i2c_transaction.hpp"
-#include
+#include
namespace modm
{
@@ -41,7 +41,7 @@ namespace modm
* @ingroup modm_architecture_i2c_device
*/
template < class I2cMaster, uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction >
-class I2cDevice : protected modm::NestedResumable< NestingLevels + 1 >
+class I2cDevice
{
public:
/// @param address the slave address not yet shifted left (address < 128).
@@ -68,82 +68,36 @@ class I2cDevice : protected modm::NestedResumable< NestingLevels + 1 >
/// @retval true device responds to address
/// @retval false no device with address found
- modm::ResumableResult
+ bool
ping()
{
- RF_BEGIN();
-
- RF_WAIT_UNTIL( transaction.configurePing() and startTransaction() );
-
- RF_WAIT_WHILE( isTransactionRunning() );
-
- RF_END_RETURN( wasTransactionSuccessful() );
+ modm::this_fiber::poll([&]{ return transaction.configurePing(); });
+ return runTransaction();
}
/// Starts a write-read transaction and waits until finished.
- modm::ResumableResult
+ bool
writeRead(const uint8_t *writeBuffer, std::size_t writeSize,
uint8_t *readBuffer, std::size_t readSize)
{
- RF_BEGIN();
-
- RF_WAIT_UNTIL( startWriteRead(writeBuffer, writeSize, readBuffer, readSize) );
-
- RF_WAIT_WHILE( isTransactionRunning() );
-
- RF_END_RETURN( wasTransactionSuccessful() );
+ modm::this_fiber::poll([&]{ return transaction.configureWriteRead(writeBuffer, writeSize, readBuffer, readSize); });
+ return runTransaction();
}
/// Starts a write transaction and waits until finished.
- modm::ResumableResult
+ bool
write(const uint8_t *buffer, std::size_t size)
{
- RF_BEGIN();
-
- RF_WAIT_UNTIL( startWrite(buffer, size) );
-
- RF_WAIT_WHILE( isTransactionRunning() );
-
- RF_END_RETURN( wasTransactionSuccessful() );
+ modm::this_fiber::poll([&]{ return transaction.configureWrite(buffer, size); });
+ return runTransaction();
}
/// Starts a write transaction and waits until finished.
- modm::ResumableResult
+ bool
read(uint8_t *buffer, std::size_t size)
{
- RF_BEGIN();
-
- RF_WAIT_UNTIL( startRead(buffer, size) );
-
- RF_WAIT_WHILE( isTransactionRunning() );
-
- RF_END_RETURN( wasTransactionSuccessful() );
- }
-
-protected:
- /// Configures the transaction with a write/read operation and starts it.
- bool inline
- startWriteRead(const uint8_t *writeBuffer, std::size_t writeSize,
- uint8_t *readBuffer, std::size_t readSize)
- {
- return ( transaction.configureWriteRead(writeBuffer, writeSize, readBuffer, readSize) and
- startTransaction() );
- }
-
- /// Configures the transaction with a write operation and starts it.
- bool inline
- startWrite(const uint8_t *buffer, std::size_t size)
- {
- return ( transaction.configureWrite(buffer, size) and
- startTransaction() );
- }
-
- /// Configures the transaction with a read operation and starts it.
- bool inline
- startRead(uint8_t *buffer, std::size_t size)
- {
- return ( transaction.configureRead(buffer, size) and
- startTransaction() );
+ modm::this_fiber::poll([&]{ return transaction.configureRead(buffer, size); });
+ return runTransaction();
}
protected:
@@ -176,16 +130,12 @@ class I2cDevice : protected modm::NestedResumable< NestingLevels + 1 >
}
/// Starts our own transaction and waits until finished.
- modm::ResumableResult
+ bool
runTransaction()
{
- RF_BEGIN();
-
- RF_WAIT_UNTIL( startTransaction() );
-
- RF_WAIT_WHILE( isTransactionRunning() );
-
- RF_END_RETURN( wasTransactionSuccessful() );
+ modm::this_fiber::poll([&]{ return startTransaction(); });
+ modm::this_fiber::poll([&]{ return isTransactionRunning(); });
+ return wasTransactionSuccessful();
}
protected:
diff --git a/src/modm/architecture/interface/i2c_multiplexer.hpp b/src/modm/architecture/interface/i2c_multiplexer.hpp
index 65e6b6171d..31725d7272 100644
--- a/src/modm/architecture/interface/i2c_multiplexer.hpp
+++ b/src/modm/architecture/interface/i2c_multiplexer.hpp
@@ -12,7 +12,8 @@
#ifndef MODM_I2C_MULTIPLEXER_HPP
#define MODM_I2C_MULTIPLEXER_HPP
-#include
+#include
+#include "i2c_transaction.hpp"
namespace modm
{
@@ -99,10 +100,9 @@ bool
modm::I2cMultiplexerChannel::start(modm::I2cTransaction *transaction, ConfigurationHandler handler)
{
// If call to multiplexer failed, return without doing the actual transaction
- if (RF_CALL_BLOCKING(multiplexer.multiplexerDevice.setActiveChannel(static_cast(channel))) == false) {
+ if (not multiplexer.multiplexerDevice.setActiveChannel(uint8_t(channel))) {
return false;
}
-
return multiplexer.start(transaction, handler);
}
diff --git a/src/modm/architecture/interface/spi_master.hpp b/src/modm/architecture/interface/spi_master.hpp
index cbf571483a..9e32b121cb 100644
--- a/src/modm/architecture/interface/spi_master.hpp
+++ b/src/modm/architecture/interface/spi_master.hpp
@@ -15,7 +15,6 @@
#ifndef MODM_INTERFACE_SPI_MASTER_HPP
#define MODM_INTERFACE_SPI_MASTER_HPP
-#include
#include "spi.hpp"
namespace modm
@@ -105,7 +104,7 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* data to be sent
* @return received data
*/
- static modm::ResumableResult
+ static uint8_t
transfer(uint8_t data);
/**
@@ -123,7 +122,7 @@ class SpiMaster : public ::modm::PeripheralDriver, public Spi
* @param length
* number of bytes to be shifted out
*/
- static modm::ResumableResult
+ static void
transfer(const uint8_t *tx, uint8_t *rx, std::size_t length);
#endif
};
diff --git a/src/modm/architecture/interface/uart_device.hpp b/src/modm/architecture/interface/uart_device.hpp
index 1be7ff47b6..5410e9fb5e 100644
--- a/src/modm/architecture/interface/uart_device.hpp
+++ b/src/modm/architecture/interface/uart_device.hpp
@@ -26,8 +26,8 @@ namespace modm
* @author Rasmus Kleist Hørlyck Sørensen
* @ingroup modm_architecture_uart_device
*/
-template < class Uart, uint8_t NestingLevels = 10 >
-class UartDevice : protected modm::NestedResumable< NestingLevels + 1 >
+template < class Uart >
+class UartDevice
{
public:
UartDevice() :
@@ -55,28 +55,24 @@ class UartDevice : protected modm::NestedResumable< NestingLevels + 1 >
}
protected:
- modm::ResumableResult
+ bool
write(uint8_t data)
{
- RF_BEGIN(0);
-
timeout.restart(txTimeout);
- RF_WAIT_UNTIL(Uart::write(data) or timeout.isExpired() or Uart::hasError());
+ modm::this_fiber::poll([&]{ return Uart::write(data) or timeout.isExpired() or Uart::hasError(); });
if (timeout.isExpired() or Uart::hasError())
{
Uart::discardTransmitBuffer();
Uart::discardReceiveBuffer();
Uart::clearError();
- RF_RETURN(false);
+ return false;
}
- RF_END_RETURN(true);
+ return true;
}
- modm::ResumableResult
+ bool
write(const uint8_t *data, std::size_t length)
{
- RF_BEGIN(0);
-
writeIndex = 0;
timeout.restart(txTimeout);
while (writeIndex < length)
@@ -91,35 +87,31 @@ class UartDevice : protected modm::NestedResumable< NestingLevels + 1 >
{
Uart::discardReceiveBuffer();
Uart::clearError();
- RF_RETURN(false);
+ return false;
}
- RF_YIELD();
+ modm::this_fiber::yield();
}
- RF_END_RETURN(true);
+ return true;
}
- modm::ResumableResult
+ bool
read(uint8_t &data)
{
- RF_BEGIN(1);
-
timeout.restart(rxTimeout);
- RF_WAIT_UNTIL(Uart::read(data) or timeout.isExpired() or Uart::hasError());
+ modm::this_fiber::poll([&]{ return Uart::read(data) or timeout.isExpired() or Uart::hasError(); });
if (timeout.isExpired() or Uart::hasError())
{
Uart::discardReceiveBuffer();
Uart::clearError();
- RF_RETURN(false);
+ return false;
}
- RF_END_RETURN(true);
+ return true;
}
- modm::ResumableResult
+ bool
read(uint8_t *buffer, std::size_t length)
{
- RF_BEGIN(1);
-
readIndex = 0;
timeout.restart(rxTimeout);
while (readIndex < length)
@@ -134,12 +126,12 @@ class UartDevice : protected modm::NestedResumable< NestingLevels + 1 >
{
Uart::discardReceiveBuffer();
Uart::clearError();
- RF_RETURN(false);
+ return false;
}
- RF_YIELD();
+ modm::this_fiber::yield();
}
- RF_END_RETURN(true);
+ return true;
}
private:
diff --git a/src/modm/architecture/module.lb b/src/modm/architecture/module.lb
index f6bd40ac13..f4eda182fd 100644
--- a/src/modm/architecture/module.lb
+++ b/src/modm/architecture/module.lb
@@ -94,7 +94,6 @@ class BlockDevice(Module):
module.description = "Block Devices"
def prepare(self, module, options):
- module.depends(":processing:resumable")
return True
def build(self, env):
@@ -203,8 +202,7 @@ class GpioExpander(Module):
module.description = "GPIO Expanders"
def prepare(self, module, options):
- module.depends(":architecture:gpio", ":architecture:register",
- ":processing:resumable", ":math:utils")
+ module.depends(":architecture:gpio", ":architecture:register", ":math:utils")
return True
def build(self, env):
@@ -218,7 +216,7 @@ class I2c(Module):
module.description = "Inter-Integrated Circuit (I²C)"
def prepare(self, module, options):
- module.depends(":architecture:gpio", ":architecture:delay")
+ module.depends(":architecture:gpio", ":architecture:fiber")
return True
def build(self, env):
@@ -234,7 +232,7 @@ class I2cDevice(Module):
module.description = "I²C Devices"
def prepare(self, module, options):
- module.depends(":architecture:i2c", ":processing:resumable")
+ module.depends(":architecture:i2c", ":architecture:fiber")
return True
def build(self, env):
@@ -248,8 +246,7 @@ class I2cMultiplexer(Module):
module.description = "I²C Multiplexer"
def prepare(self, module, options):
- module.depends(":architecture:i2c", ":architecture:register",
- ":processing:resumable", ":math:utils")
+ module.depends(":architecture:i2c")
return True
def build(self, env):
@@ -317,7 +314,6 @@ class Spi(Module):
module.description = "Serial Peripheral Interface (SPI)"
def prepare(self, module, options):
- module.depends(":processing:resumable")
return True
def build(self, env):
@@ -360,7 +356,7 @@ class UartDevice(Module):
module.description = "UART Devices"
def prepare(self, module, options):
- module.depends(":architecture:uart")
+ module.depends(":architecture:uart", ":processing:timer")
return True
def build(self, env):
diff --git a/src/modm/communication/amnb/interface.hpp b/src/modm/communication/amnb/interface.hpp
index cf9c3f84bc..41c781d6ff 100644
--- a/src/modm/communication/amnb/interface.hpp
+++ b/src/modm/communication/amnb/interface.hpp
@@ -14,7 +14,6 @@
#include "message.hpp"
#include
#include
-#include
namespace modm::amnb
{
@@ -47,15 +46,15 @@ class Device
virtual bool
hasReceived() = 0;
- virtual modm::ResumableResult
+ virtual bool
write(uint8_t data) = 0;
- virtual modm::ResumableResult
+ virtual bool
read(uint8_t *data) = 0;
};
template< class Uart, uint16_t TimeoutUsTx = 1000, uint16_t TimeoutUsRx = 10'000 >
-class DeviceWrapper : public Device, modm::Resumable<2>
+class DeviceWrapper : public Device
{
public:
bool
@@ -64,37 +63,35 @@ class DeviceWrapper : public Device, modm::Resumable<2>
return Uart::receiveBufferSize() > 0;
}
- modm::ResumableResult
+ bool
write(uint8_t data) final
{
- RF_BEGIN(0);
- RF_WAIT_UNTIL(Uart::write(data));
+ modm::this_fiber::poll([&]{ return Uart::write(data); });
timeout.restart(std::chrono::microseconds(TimeoutUsTx));
- RF_WAIT_UNTIL(Uart::read(rx_data) or Uart::hasError() or timeout.isExpired());
+ modm::this_fiber::poll([&]{ return Uart::read(rx_data) or Uart::hasError() or timeout.isExpired(); });
if (timeout.isExpired() or Uart::hasError() or rx_data != data)
{
Uart::discardTransmitBuffer();
Uart::discardReceiveBuffer();
Uart::clearError();
- RF_RETURN(false);
+ return false;
}
- RF_END_RETURN(true);
+ return true;
}
- modm::ResumableResult
+ bool
read(uint8_t *data) final
{
- RF_BEGIN(1);
timeout.restart(std::chrono::microseconds(TimeoutUsRx));
- RF_WAIT_UNTIL(Uart::read(*data) or Uart::hasError() or timeout.isExpired());
+ modm::this_fiber::poll([&]{ return Uart::read(*data) or Uart::hasError() or timeout.isExpired(); });
if (timeout.isExpired() or Uart::hasError())
{
Uart::discardReceiveBuffer();
Uart::clearError();
- RF_RETURN(false);
+ return false;
}
- RF_END_RETURN(true);
+ return true;
}
protected:
@@ -103,7 +100,7 @@ class DeviceWrapper : public Device, modm::Resumable<2>
};
template< size_t MaxHeapAllocation = 0 >
-class Interface : modm::Resumable<6>
+class Interface
{
public:
Interface(Device &device)
@@ -113,140 +110,130 @@ class Interface : modm::Resumable<6>
isMediumBusy() const
{ return isReceiving or device.hasReceived(); }
- modm::ResumableResult
+ InterfaceStatus
transmit(const Message *message)
{
- RF_BEGIN(0);
-
if (isMediumBusy())
- RF_RETURN(InterfaceStatus::MediumBusy);
+ return InterfaceStatus::MediumBusy;
isTransmitting = true;
tx_data = STX;
- if (not RF_CALL(write())) RF_RETURN(InterfaceStatus::SyncWriteFailed);
- if (not RF_CALL(write())) RF_RETURN(InterfaceStatus::SyncWriteFailed);
+ if (not write()) return InterfaceStatus::SyncWriteFailed;
+ if (not write()) return InterfaceStatus::SyncWriteFailed;
for (tx_index = 0; tx_index < message->headerLength(); tx_index++)
- if (not RF_CALL(write_escaped(message->self()[tx_index])))
- RF_RETURN(InterfaceStatus::HeaderWriteFailed);
+ if (not write_escaped(message->self()[tx_index]))
+ return InterfaceStatus::HeaderWriteFailed;
for (tx_index = 0; tx_index < message->dataLength(); tx_index++)
- if (not RF_CALL(write_escaped(message->get()[tx_index])))
- RF_RETURN(InterfaceStatus::DataWriteFailed);
+ if (not write_escaped(message->get()[tx_index]))
+ return InterfaceStatus::DataWriteFailed;
isTransmitting = false;
- RF_END_RETURN(InterfaceStatus::Ok);
+ return InterfaceStatus::Ok;
}
- modm::ResumableResult
+ InterfaceStatus
receiveHeader(Message *message)
{
- RF_BEGIN(1);
-
if (isTransmitting)
- RF_RETURN(InterfaceStatus::MediumBusy);
+ return InterfaceStatus::MediumBusy;
if (not device.hasReceived())
- RF_RETURN(InterfaceStatus::MediumEmpty);
+ return InterfaceStatus::MediumEmpty;
- if (not RF_CALL(read())) RF_RETURN(InterfaceStatus::SyncReadFailed);
- if (rx_data != STX) RF_RETURN(InterfaceStatus::SyncReadFailed);
+ if (not read()) return InterfaceStatus::SyncReadFailed;
+ if (rx_data != STX) return InterfaceStatus::SyncReadFailed;
isReceiving = true;
- if (not RF_CALL(read())) {
+ if (not read()) {
isReceiving = false;
- RF_RETURN(InterfaceStatus::SyncReadFailed);
+ return InterfaceStatus::SyncReadFailed;
}
if (rx_data != STX) {
isReceiving = false;
- RF_RETURN(InterfaceStatus::SyncReadFailed);
+ return InterfaceStatus::SyncReadFailed;
}
for(rx_index = 0; rx_index < message->SMALL_HEADER_SIZE; rx_index++)
{
- if (not RF_CALL(read_escaped())) RF_RETURN(InterfaceStatus::HeaderReadFailed);
+ if (not read_escaped()) return InterfaceStatus::HeaderReadFailed;
message->self()[rx_index] = rx_data;
}
for(; rx_index < message->headerLength(); rx_index++)
{
- if (not RF_CALL(read_escaped())) RF_RETURN(InterfaceStatus::HeaderReadFailed);
+ if (not read_escaped()) return InterfaceStatus::HeaderReadFailed;
message->self()[rx_index] = rx_data;
}
if (not message->isHeaderValid()) {
isReceiving = false;
- RF_RETURN(InterfaceStatus::HeaderInvalid);
+ return InterfaceStatus::HeaderInvalid;
}
if (not message->isLarge()) isReceiving = false;
- RF_END_RETURN(InterfaceStatus::Ok);
+ return InterfaceStatus::Ok;
}
- modm::ResumableResult
+ InterfaceStatus
receiveData(Message *message, bool allocate=true)
{
- RF_BEGIN(1); // same index as receiveHeader!!!
-
- if (not message->isLarge()) RF_RETURN(InterfaceStatus::Ok);
+ if (not message->isLarge()) return InterfaceStatus::Ok;
if ( (rx_allocated = allocate and (message->dataLength() <= MaxHeapAllocation)) )
rx_allocated = message->allocate();
for(rx_index = 0; rx_index < message->dataLength(); rx_index++)
{
- if (not RF_CALL(read_escaped())) RF_RETURN(InterfaceStatus::DataReadFailed);
+ if (not read_escaped()) return InterfaceStatus::DataReadFailed;
if (rx_allocated) message->get()[rx_index] = rx_data;
}
isReceiving = false;
- if (allocate and not rx_allocated) RF_RETURN(InterfaceStatus::AllocationFailed);
+ if (allocate and not rx_allocated) return InterfaceStatus::AllocationFailed;
- RF_END_RETURN(message->isDataValid() ? InterfaceStatus::Ok : InterfaceStatus::DataInvalid);
+ return message->isDataValid() ? InterfaceStatus::Ok : InterfaceStatus::DataInvalid;
}
protected:
- modm::ResumableResult
+ bool
write_escaped(uint8_t data)
{
- RF_BEGIN(2);
if (data == STX or data == DLE) {
tx_data = DLE;
- if (not RF_CALL(write())) RF_RETURN(false);
+ if (not write()) return false;
tx_data = data ^ 0x20;
}
else {
tx_data = data;
}
- RF_END_RETURN_CALL(write());
+ return write();
}
- modm::ResumableResult
+ bool
read_escaped()
{
- RF_BEGIN(3);
- if (not RF_CALL(read())) RF_RETURN(false);
+ if (not read()) return false;
if (rx_data == DLE) {
- if (not RF_CALL(read())) RF_RETURN(false);
+ if (not read()) return false;
rx_data ^= 0x20;
}
- RF_END_RETURN(true);
+ return true;
}
- modm::ResumableResult
+ bool
write()
{
- RF_BEGIN(4);
- if (RF_CALL(device.write(tx_data)))
- RF_RETURN(true);
+ if (device.write(tx_data))
+ return true;
isTransmitting = false;
- RF_END_RETURN(false);
+ return false;
}
- modm::ResumableResult
+ bool
read()
{
- RF_BEGIN(5);
- if (RF_CALL(device.read(&rx_data)))
- RF_RETURN(true);
+ if (device.read(&rx_data))
+ return true;
isReceiving = false;
- RF_END_RETURN(false);
+ return false;
}
protected:
diff --git a/src/modm/communication/amnb/module.lb b/src/modm/communication/amnb/module.lb
index 520c1f64b4..48120274ce 100644
--- a/src/modm/communication/amnb/module.lb
+++ b/src/modm/communication/amnb/module.lb
@@ -17,7 +17,7 @@ def init(module):
def prepare(module, options):
module.depends(
":math:utils",
- ":processing:resumable",
+ ":architecture:fiber",
":processing:timer",
":container",
":utils")
diff --git a/src/modm/communication/amnb/node.hpp b/src/modm/communication/amnb/node.hpp
index 893348b4db..63847caae2 100644
--- a/src/modm/communication/amnb/node.hpp
+++ b/src/modm/communication/amnb/node.hpp
@@ -22,7 +22,7 @@ namespace modm::amnb
/// @author Niklas Hauser
/// @ingroup modm_communication_amnb
template < size_t TxBufferSize = 2, size_t MaxHeapAllocation = 0 >
-class Node : public modm::Resumable<6>
+class Node
{
static_assert(2 <= TxBufferSize, "TxBuffer must have at least two messages!");
public:
@@ -90,122 +90,113 @@ class Node : public modm::Resumable<6>
}
template< class ReturnType = void, class ErrorType = void >
- modm::ResumableResult< Result >
+ Result
request(uint8_t from, uint8_t command)
{
- RF_BEGIN(0);
request_msg = Message(from, command, Type::Request);
- RF_CALL(request());
- RF_END_RETURN(request_msg);
+ request();
+ return request_msg;
}
template< class ReturnType = void, class ErrorType = void >
- modm::ResumableResult< Result >
+ Result
request(uint8_t from, uint8_t command, const uint8_t *data, size_t length)
{
- RF_BEGIN(1);
{
request_msg = Message(from, command, length, Type::Request);
uint8_t* arg = request_msg.get();
if (arg == nullptr) {
request_msg = Response(Error::RequestAllocationFailed).msg;
- RF_RETURN(request_msg);
+ return request_msg;
}
std::memcpy(arg, data, length);
}
- RF_CALL(request());
- RF_END_RETURN(request_msg);
+ request();
+ return request_msg;
}
template< class ReturnType = void, class ErrorType = void, class T >
- modm::ResumableResult< Result >
+ Result
request(uint8_t from, uint8_t command, const T &argument)
{
return request(from, command, (uint8_t*)&argument, sizeof(T));
}
public:
- modm::ResumableResult
+ void
update_transmit()
{
- RF_BEGIN(2);
while(1)
{
if (not tx_queue.isEmpty())
{
- RF_WAIT_WHILE(isResumableRunning(3));
- RF_CALL(send(tx_queue.get()));
+ modm::this_fiber::poll([&]{ return not is_sending; });
+ send(tx_queue.get());
tx_queue.pop();
}
- RF_YIELD();
+ modm::this_fiber::yield();
}
- RF_END();
}
- modm::ResumableResult
+ void
update_receive()
{
- RF_BEGIN(5);
while(1)
{
rx_msg.deallocate(); // deallocates previous message
- if (RF_CALL(interface.receiveHeader(&rx_msg)) == InterfaceStatus::Ok)
+ if (interface.receiveHeader(&rx_msg) == InterfaceStatus::Ok)
{
// Check lists if we are interested in this message
is_rx_msg_for_us = handleRxMessage(false);
// Receive the message data, only allocate if it's for us
- if (RF_CALL(interface.receiveData(&rx_msg, is_rx_msg_for_us)) == InterfaceStatus::Ok)
+ if (interface.receiveData(&rx_msg, is_rx_msg_for_us) == InterfaceStatus::Ok)
{
// Only handle message *with* data if it's for us
if (is_rx_msg_for_us) handleRxMessage(true);
}
}
- RF_YIELD();
+ modm::this_fiber::yield();
}
- RF_END();
}
protected:
- modm::ResumableResult
+ void
send(Message &msg)
{
- RF_BEGIN(3);
-
+ is_sending = true;
msg.setValid();
tx_counter = std::min(MIN_TX_TRIES, uint8_t(msg.command() >> (8 - PRIORITY_BITS)));
while(1)
{
while (interface.isMediumBusy())
{
- RF_WAIT_WHILE(interface.isMediumBusy());
+ modm::this_fiber::poll([&]{ return not interface.isMediumBusy(); });
reschedule(RESCHEDULE_MASK_SHORT);
- RF_WAIT_UNTIL(tx_timer.isExpired());
+ modm::this_fiber::poll([&]{ return tx_timer.isExpired(); });
}
- if (RF_CALL(interface.transmit(&msg)) == InterfaceStatus::Ok)
+ if (interface.transmit(&msg) == InterfaceStatus::Ok)
break;
if (--tx_counter == 0) break;
// a collision or other write issue occurred
- RF_WAIT_WHILE(interface.isMediumBusy());
+ modm::this_fiber::poll([&]{ return not interface.isMediumBusy(); });
reschedule(RESCHEDULE_MASK_LONG);
- RF_WAIT_UNTIL(tx_timer.isExpired());
+ modm::this_fiber::poll([&]{ return tx_timer.isExpired(); });
}
- RF_END();
+ is_sending = false;
}
- modm::ResumableResult
+ void
request()
{
- RF_BEGIN(4);
-
- RF_WAIT_WHILE(isResumableRunning(3));
+ modm::this_fiber::poll([&]{ return not is_sending; });
response_status = ResponseStatus::Waiting;
- RF_CALL(send(request_msg));
+ send(request_msg);
response_timer.restart(1s);
- RF_WAIT_UNTIL((response_status == ResponseStatus::Received) or response_timer.isExpired());
+ modm::this_fiber::poll([&]{ return (response_status == ResponseStatus::Received) or response_timer.isExpired(); });
response_status = ResponseStatus::NotWaiting;
if (response_timer.isExpired()) {
@@ -213,7 +204,6 @@ class Node : public modm::Resumable<6>
*request_msg.get() = Error::RequestTimeout;
}
- RF_END();
}
protected:
@@ -306,6 +296,7 @@ class Node : public modm::Resumable<6>
const uint8_t actionCount{0};
const uint8_t listenerCount{0};
uint8_t address;
+ bool is_sending{false};
uint8_t tx_counter;
bool is_rx_msg_for_us;
diff --git a/src/modm/driver/adc/ad7280a.hpp b/src/modm/driver/adc/ad7280a.hpp
index f0bee5e4e9..a5b7370eb5 100644
--- a/src/modm/driver/adc/ad7280a.hpp
+++ b/src/modm/driver/adc/ad7280a.hpp
@@ -15,8 +15,9 @@
#include
+#include
#include
-#include
+#include
#include
@@ -145,38 +146,38 @@ namespace modm
*
* @ingroup modm_driver_ad7280a
*/
- template
- class Ad7280a
+ template
+ class Ad7280a: public modm::SpiDevice
{
// used for Unittests
friend class ::Ad7280aTest;
public:
- static void
+ void
initialize(ad7280a::Average average = ad7280a::NO_AVERAGE);
/*
* Initialize daisy chain.
*/
- static bool
+ bool
chainSetup();
/**
* Enable/Disable the six cell balance outputs.
*/
- static void
+ void
enableBalancer(uint8_t device, uint8_t cells);
- static bool
+ bool
performSelftest();
- static void
+ void
softwareReset();
/**
* Read a single channel
*/
- static bool
+ bool
readChannel(uint8_t device, ad7280a::Channel channel, uint16_t *value);
/**
@@ -184,14 +185,14 @@ namespace modm
*
* \param[out] values Array containing the results
*/
- static bool
+ bool
readAllChannels(uint16_t *values);
private:
/**
* Calculate the CRC for one byte
*/
- static uint8_t
+ uint8_t
updateCrc(uint8_t data);
/**
@@ -206,30 +207,30 @@ namespace modm
* uint8_t crc = calculateCrc(reg >> 10);
* \endcode
*/
- static uint8_t
+ uint8_t
calculateCrc(uint32_t data);
- static bool
+ bool
write(uint8_t device, ad7280a::Register reg, bool addressAll, uint8_t value);
- static bool
+ bool
read(uint32_t *value);
- static bool
+ bool
readRegister(ad7280a::RegisterValue* result);
- static bool
+ bool
readConversionResult(ad7280a::ConversionValue* result);
/*static void
dumpRegisterRead(uint32_t value);
- static void
+ void
dumpConversion(uint32_t value);*/
- static uint8_t controlHighByte;
+ uint8_t controlHighByte{};
};
#if __has_include()
diff --git a/src/modm/driver/adc/ad7280a.lb b/src/modm/driver/adc/ad7280a.lb
index 1c1164de6b..488c6c164c 100644
--- a/src/modm/driver/adc/ad7280a.lb
+++ b/src/modm/driver/adc/ad7280a.lb
@@ -36,7 +36,7 @@ be lower than 1 MHz because delays introduced in each stage of the chain.
def prepare(module, options):
module.depends(
- ":architecture:delay",
+ ":architecture:fiber",
":architecture:gpio",
":architecture:spi",
":math:utils")
diff --git a/src/modm/driver/adc/ad7280a_impl.hpp b/src/modm/driver/adc/ad7280a_impl.hpp
index b5ddc0f834..18bb97d80c 100644
--- a/src/modm/driver/adc/ad7280a_impl.hpp
+++ b/src/modm/driver/adc/ad7280a_impl.hpp
@@ -131,13 +131,9 @@
#define AD7280A_READ_TXVAL 0xF800030A
// ----------------------------------------------------------------------------
-template
-uint8_t modm::Ad7280a::controlHighByte = 0;
-
-// ----------------------------------------------------------------------------
-template
+template
void
-modm::Ad7280a::initialize(ad7280a::Average average)
+modm::Ad7280a::initialize(ad7280a::Average average)
{
static_assert(N == 1, "Daisy chain length is currently limited to 1!");
@@ -148,9 +144,9 @@ modm::Ad7280a::initialize(ad7280a::Average average)
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::chainSetup()
+modm::Ad7280a::chainSetup()
{
// Set reset bit for all devices
write(ad7280a::MASTER, ad7280a::CTRL_LB, true,
@@ -200,17 +196,17 @@ modm::Ad7280a::chainSetup()
}
// ----------------------------------------------------------------------------
-template
+template
void
-modm::Ad7280a::enableBalancer(uint8_t device, uint8_t cells)
+modm::Ad7280a::enableBalancer(uint8_t device, uint8_t cells)
{
write(device, ad7280a::CELL_BALANCE, false, cells);
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::performSelftest()
+modm::Ad7280a::performSelftest()
{
// Set Bit D0 of the control register to 1 on all parts. This
// setting enables the daisy-chain register read operation on
@@ -229,7 +225,7 @@ modm::Ad7280a::performSelftest()
// Allow sufficient time for the self-test conversions to be
// completed plus tWAIT.
- modm::delay_ms(50); // TODO
+ modm::this_fiber::sleep_for(50ms); // TODO
// The register address corresponding to the self-test
// conversion should be written to the read register of all
@@ -256,9 +252,9 @@ modm::Ad7280a::performSelftest()
}
// ----------------------------------------------------------------------------
-template
+template
void
-modm::Ad7280a::softwareReset()
+modm::Ad7280a::softwareReset()
{
// Set reset bit for all devices
write(ad7280a::MASTER, ad7280a::CTRL_LB, true,
@@ -275,9 +271,9 @@ modm::Ad7280a::softwareReset()
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::readChannel(uint8_t device,
+modm::Ad7280a::readChannel(uint8_t device,
ad7280a::Channel channel, uint16_t *value)
{
write(ad7280a::MASTER, ad7280a::CTRL_HB, true,
@@ -290,7 +286,7 @@ modm::Ad7280a::readChannel(uint8_t device,
AD7280A_CTRL_HB_CONV_START_CS);
// Wait for the conversion to finish
- modm::delay_ms(5);
+ modm::this_fiber::sleep_for(5ms);
// Read one channel
write(device, ad7280a::READ, false, channel);
@@ -308,9 +304,9 @@ modm::Ad7280a::readChannel(uint8_t device,
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::readAllChannels(uint16_t *values)
+modm::Ad7280a::readAllChannels(uint16_t *values)
{
// Write Register Address 0x00 to the read register on all
// parts. A device address of 0x00 is used when computing
@@ -323,7 +319,7 @@ modm::Ad7280a::readAllChannels(uint16_t *values)
AD7280A_CTRL_HB_CONV_START_CS);
// Allow sufficient time for all conversions to be completed plus tWAIT.
- modm::delay_ms(5);
+ modm::this_fiber::sleep_for(5ms);
// Apply a CS low pulse that frames 32 SCLKs to read back
// the desired voltage. This frame should simultaneously
@@ -350,9 +346,9 @@ modm::Ad7280a::readAllChannels(uint16_t *values)
/*
* P(x) = x^8 + x^5 + x^3 + x^2 + x^1 + x^0 = 0b100101111 => 0x2F
*/
-template
+template
uint8_t
-modm::Ad7280a::updateCrc(uint8_t data)
+modm::Ad7280a::updateCrc(uint8_t data)
{
for (uint_fast8_t i = 0; i < 8; i++) {
uint8_t bit = data & 0x80;
@@ -366,9 +362,9 @@ modm::Ad7280a::updateCrc(uint8_t data)
}
// ----------------------------------------------------------------------------
-template
+template
uint8_t
-modm::Ad7280a::calculateCrc(uint32_t data)
+modm::Ad7280a::calculateCrc(uint32_t data)
{
uint8_t crc;
@@ -379,9 +375,9 @@ modm::Ad7280a::calculateCrc(uint32_t data)
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::write(uint8_t device, ad7280a::Register reg,
+modm::Ad7280a::write(uint8_t device, ad7280a::Register reg,
bool addressAll, uint8_t value)
{
// The device address is send with LSB first
@@ -393,29 +389,34 @@ modm::Ad7280a::write(uint8_t device, ad7280a::Register reg,
t |= calculateCrc(t >> 11) << 3 | 0x2;
+ modm::this_fiber::poll([&]{ return this->acquireMaster(); });
Cs::reset();
- Spi::write((t >> 24) & 0xff);
- Spi::write((t >> 16) & 0xff);
- Spi::write((t >> 8) & 0xff);
- Spi::write((t >> 0) & 0xff);
- Cs::set();
+ SpiMaster::transfer((t >> 24) & 0xff);
+ SpiMaster::transfer((t >> 16) & 0xff);
+ SpiMaster::transfer((t >> 8) & 0xff);
+ SpiMaster::transfer((t >> 0) & 0xff);
+
+ if (this->releaseMaster()) Cs::set();
// TODO remove this
- modm::delay_us(1);
+ modm::this_fiber::sleep_for(1us);
return true;
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::read(uint32_t *value)
+modm::Ad7280a::read(uint32_t *value)
{
+ modm::this_fiber::poll([&]{ return this->acquireMaster(); });
Cs::reset();
- *value = static_cast(Spi::write(0xF8)) << 24;
- *value |= static_cast(Spi::write(0x00)) << 16;
- *value |= static_cast(Spi::write(0x03)) << 8;
- *value |= static_cast(Spi::write(0x0A));
- Cs::set();
+
+ *value = static_cast(SpiMaster::transfer(0xF8)) << 24;
+ *value |= static_cast(SpiMaster::transfer(0x00)) << 16;
+ *value |= static_cast(SpiMaster::transfer(0x03)) << 8;
+ *value |= static_cast(SpiMaster::transfer(0x0A));
+
+ if (this->releaseMaster()) Cs::set();
//MODM_LOG_DEBUG << "read = " << modm::hex << *value << modm::ascii << modm::endl;
@@ -430,9 +431,9 @@ modm::Ad7280a::read(uint32_t *value)
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::readRegister(ad7280a::RegisterValue* result)
+modm::Ad7280a::readRegister(ad7280a::RegisterValue* result)
{
uint32_t value;
if (read(&value))
@@ -449,9 +450,9 @@ modm::Ad7280a::readRegister(ad7280a::RegisterValue* result)
}
// ----------------------------------------------------------------------------
-template
+template
bool
-modm::Ad7280a::readConversionResult(ad7280a::ConversionValue* result)
+modm::Ad7280a::readConversionResult(ad7280a::ConversionValue* result)
{
uint32_t value;
if (read(&value))
diff --git a/src/modm/driver/adc/ad7928.hpp b/src/modm/driver/adc/ad7928.hpp
index 0cb440e4e0..0ada4ee813 100644
--- a/src/modm/driver/adc/ad7928.hpp
+++ b/src/modm/driver/adc/ad7928.hpp
@@ -18,8 +18,7 @@
#include
#include
#include
-#include
-#include
+#include
namespace modm
{
@@ -153,30 +152,30 @@ struct ad7928
* @ingroup modm_driver_ad7928
*/
template
-class Ad7928 : public ad7928, public modm::SpiDevice, protected modm::NestedResumable<3>
+class Ad7928 : public ad7928, public modm::SpiDevice
{
public:
Ad7928();
/// Call this function once before using the device
- modm::ResumableResult
+ void
initialize();
/// Initiate a single conversion and return the result of the previous conversion
/// A running sequence will be aborted.
/// If the device is in full shutdown, it will be woken up.
- modm::ResumableResult
+ Data
singleConversion(InputChannel channel);
/// Start a conversion sequence.
/// The device will automatically cycle through the specified channels, starting
/// with the lowest channel index in sequence1, when nextSequenceConversion() is called.
- modm::ResumableResult
+ void
startSequence(SequenceChannels_t channels1, SequenceChannels_t channels2 = SequenceChannels_t(0));
/// Perform the next sequence conversion
/// The result is undefined if the device is not in sequence mode or not in normal power mode.
- modm::ResumableResult
+ Data
nextSequenceConversion();
/// Enable extended range mode (0V < input < 2*Vref)
@@ -199,15 +198,15 @@ class Ad7928 : public ad7928, public modm::SpiDevice, protected modm:
/// Shutdown device
/// Calling wakeup() or initiating a conversion will wake up the device
- modm::ResumableResult
+ void
fullShutdown();
/// Wake up the device from full shutdown mode
- modm::ResumableResult
+ void
wakeup();
private:
- modm::ResumableResult
+ void
transfer(Register_t reg);
ControlRegister_t config;
diff --git a/src/modm/driver/adc/ad7928.lb b/src/modm/driver/adc/ad7928.lb
index 783694b6ee..f5e8921f48 100644
--- a/src/modm/driver/adc/ad7928.lb
+++ b/src/modm/driver/adc/ad7928.lb
@@ -24,11 +24,10 @@ of 20 Mhz is supported.
def prepare(module, options):
module.depends(
- ":architecture:delay",
+ ":architecture:fiber",
":architecture:gpio",
":architecture:register",
- ":architecture:spi.device",
- ":processing:resumable")
+ ":architecture:spi.device")
return True
def build(env):
diff --git a/src/modm/driver/adc/ad7928_impl.hpp b/src/modm/driver/adc/ad7928_impl.hpp
index d4fe3651d2..f68cfe5680 100644
--- a/src/modm/driver/adc/ad7928_impl.hpp
+++ b/src/modm/driver/adc/ad7928_impl.hpp
@@ -31,17 +31,15 @@ Ad7928::Ad7928() : currentPowerMode{PowerMode::Normal}
// ----------------------------------------------------------------------------
template
-ResumableResult
+void
Ad7928::initialize()
{
- RF_BEGIN();
-
Cs::setOutput(modm::Gpio::High);
- modm::delay_us(1);
+ modm::this_fiber::sleep_for(1us);
// reset device
- RF_CALL(transfer(Register_t(0xFF)));
- RF_CALL(transfer(Register_t(0xFF)));
+ transfer(Register_t(0xFF));
+ transfer(Register_t(0xFF));
config |= ControlRegister::WriteControlReg;
config |= ControlRegister::UnsignedOutput;
@@ -51,87 +49,77 @@ Ad7928::initialize()
InputChannel_t::reset(config);
// write configuration
- RF_CALL(transfer(config));
+ transfer(config);
currentPowerMode = PowerMode::Normal;
-
- RF_END();
}
// ----------------------------------------------------------------------------
template
-ResumableResult
+ad7928::Data
Ad7928::singleConversion(ad7928::InputChannel channel)
{
- RF_BEGIN();
-
SequenceMode_t::set(config, SequenceMode::NoSequence);
if(currentPowerMode == PowerMode::FullShutdown) {
// power up device, will be in normal mode afterwards
- RF_CALL(wakeup());
+ wakeup();
} else if(currentPowerMode == PowerMode::AutoShutdown) {
// dummy conversion to power up device
// does not alter control register (write bit = 0)
- RF_CALL(transfer(ControlRegister(0)));
+ transfer(ControlRegister(0));
}
InputChannel_t::set(config, channel);
- RF_CALL(transfer(config));
+ transfer(config);
InputChannel_t::reset(config);
currentPowerMode = PowerMode_t::get(config);
- RF_END_RETURN(data);
+ return data;
}
// ----------------------------------------------------------------------------
template
-ResumableResult
+void
Ad7928::startSequence(ad7928::SequenceChannels_t channels1,
ad7928::SequenceChannels_t channels2)
{
- RF_BEGIN();
-
if(currentPowerMode == PowerMode::FullShutdown) {
// power up device, will be in normal mode afterwards
- RF_CALL(wakeup());
+ wakeup();
} else if(currentPowerMode == PowerMode::AutoShutdown) {
// dummy conversion to power up device
// does not alter control register (write bit = 0)
- RF_CALL(transfer(ControlRegister_t(0)));
+ transfer(ControlRegister_t(0));
}
PowerMode_t::set(config, PowerMode::Normal);
SequenceMode_t::set(config, SequenceMode::ProgramShadowRegister);
- RF_CALL(transfer(config));
+ transfer(config);
currentPowerMode = PowerMode::Normal;
// The next transfer writes to the shadow register
Sequence1Channels_t::set(sequenceChannels, static_cast(channels1.value));
Sequence2Channels_t::set(sequenceChannels, static_cast(channels2.value));
- RF_CALL(transfer(sequenceChannels));
-
- RF_END();
+ transfer(sequenceChannels);
}
// ----------------------------------------------------------------------------
template
-ResumableResult
+ad7928::Data
Ad7928::nextSequenceConversion()
{
- RF_BEGIN();
-
SequenceMode_t::set(config, SequenceMode::ContinueSequence);
// invalid if device is not in normal mode
if(currentPowerMode != PowerMode::Normal) {
- RF_RETURN(data);
+ return data;
}
- RF_CALL(transfer(config));
+ transfer(config);
currentPowerMode = PowerMode_t::get(config);
- RF_END_RETURN(data);
+ return data;
}
// ----------------------------------------------------------------------------
@@ -176,7 +164,7 @@ Ad7928::isAutoShutdownEnabled()
// ----------------------------------------------------------------------------
template
-ResumableResult
+void
Ad7928::fullShutdown()
{
SequenceMode_t::set(config, SequenceMode::NoSequence);
@@ -191,31 +179,26 @@ Ad7928::fullShutdown()
// ----------------------------------------------------------------------------
template
-ResumableResult
+void
Ad7928::wakeup()
{
- RF_BEGIN();
SequenceMode_t::set(config, SequenceMode::NoSequence);
PowerMode_t::set(config, PowerMode::Normal);
- RF_CALL(transfer(config));
+ transfer(config);
// Wait for the device to power up
- modm::delay_us(1);
+ modm::this_fiber::sleep_for(1us);
currentPowerMode = PowerMode::Normal;
-
- RF_END();
}
// ----------------------------------------------------------------------------
template
-ResumableResult
+void
Ad7928::transfer(Register_t reg)
{
- RF_BEGIN();
-
- RF_WAIT_UNTIL(this->acquireMaster());
+ modm::this_fiber::poll([&]{ return this->acquireMaster(); });
SpiMaster::setDataMode(SpiMaster::DataMode::Mode1);
@@ -224,12 +207,10 @@ Ad7928::transfer(Register_t reg)
outBuffer[0] = (reg.value & 0xFF00) >> 8;
outBuffer[1] = reg.value & 0xFF;
- RF_CALL(SpiMaster::transfer(outBuffer, data.data, 2));
+ SpiMaster::transfer(outBuffer, data.data, 2);
if (this->releaseMaster())
Cs::set();
-
- RF_END();
}
} // namespace modm
diff --git a/src/modm/driver/adc/ads101x.hpp b/src/modm/driver/adc/ads101x.hpp
index 741d1bbc58..a249e60854 100644
--- a/src/modm/driver/adc/ads101x.hpp
+++ b/src/modm/driver/adc/ads101x.hpp
@@ -187,7 +187,7 @@ struct ads101x
* @ingroup modm_driver_ads101x
*/
template
-class Ads101x : public ads101x, public modm::I2cDevice
+class Ads101x : public ads101x, public modm::I2cDevice
{
public:
/**
@@ -197,52 +197,52 @@ class Ads101x : public ads101x, public modm::I2cDevice
Ads101x(Data &data, uint8_t address = 0x49);
/// Call this function before using the device
- modm::ResumableResult
+ bool
initialize();
/// Determine if the device is currently performing a conversion
- modm::ResumableResult
+ bool
isBusy();
/// Start a single conversion with the specified input
- modm::ResumableResult
+ bool
startSingleShotConversion();
/// Start continuous conversions with the specified datarate and input
- modm::ResumableResult
+ bool
startContinuousConversion(DataRate dataRate = DataRate::Sps1600);
/// Start a single conversion with the specified input
/// @warning ADS1015 only
- modm::ResumableResult
+ bool
startSingleShotConversion(InputMultiplexer input = InputMultiplexer::Input0);
/// Start continuous conversions with the specified datarate and input
/// @warning ADS1015 only
- modm::ResumableResult
+ bool
startContinuousConversion(InputMultiplexer input = InputMultiplexer::Input0, DataRate dataRate = DataRate::Sps1600);
/// Read the last conversion result
/// @attention Following power-up, the conversion result remains zero until the first conversion is completed
- modm::ResumableResult
+ bool
readConversionResult();
/// Enable the conversion-ready function of the ALERT/RDY pin
/// @attention enabling the conversion-ready function disables the comparator and sets the ComparatorQue value to one conversion
- modm::ResumableResult
+ bool
enableConversionReadyFunction();
/// Enable the comparator
/// @warning ADS1014 and ADS1015 only
/// @warning To use the comparator-function the high threshold must be greater than the low threshold
- modm::ResumableResult
+ bool
enableComparator(ComparatorMode mode, ComparatorPolarity polarity, ComparatorLatch latch, ComparatorQueue queue);
/// Set the low threshold used by the comparator queue
/// @warning ADS1014 and ADS1015 only
/// @warning The low threshold value must be smaller than the high threshold value
/// @attention The high threshold value must be updated whenever the PGA settings are changed
- modm::ResumableResult
+ bool
setLowThreshold(uint16_t threshold)
{
return writeRegister(Register::LowThreshold, (threshold << 4) & 0xFFF0);
@@ -252,18 +252,18 @@ class Ads101x : public ads101x, public modm::I2cDevice
/// @warning ADS1014 and ADS1015 only
/// @warning The high threshold value must be greater than the low threshold value
/// @attention The high threshold value must be updated whenever the PGA settings are changed
- modm::ResumableResult
+ bool
setHighThreshold(uint16_t threshold)
{
return writeRegister(Register::HighThreshold, (threshold << 4) | 0x0F);
}
/// Set the full scale range by programming the PGA and corresponding LSB size
- modm::ResumableResult
+ bool
setFullScaleRange(FullScaleRange fullScaleRange);
private:
- modm::ResumableResult
+ bool
writeRegister(Register reg, uint16_t data);
Data &data;
diff --git a/src/modm/driver/adc/ads101x_impl.hpp b/src/modm/driver/adc/ads101x_impl.hpp
index 9ed84f2364..49c6d16f8b 100644
--- a/src/modm/driver/adc/ads101x_impl.hpp
+++ b/src/modm/driver/adc/ads101x_impl.hpp
@@ -18,18 +18,16 @@ namespace modm
{
template
-Ads101x::Ads101x(Data &data, uint8_t address) : I2cDevice(address), data(data)
+Ads101x::Ads101x(Data &data, uint8_t address) : I2cDevice(address), data(data)
{
}
// ----------------------------------------------------------------------------
template
-modm::ResumableResult
+bool
Ads101x::initialize()
{
- RF_BEGIN();
-
InputMultiplexer_t::set(config, InputMultiplexer::Input0);
FullScaleRange_t::set(config, FullScaleRange::V2_048);
DeviceOperatingMode_t::set(config, DeviceOperatingMode::SingleShot);
@@ -37,168 +35,141 @@ Ads101x::initialize()
ComparatorQueue_t::set(config, ComparatorQueue::Disable);
data.lsbSizeIndex = i(FullScaleRange::V2_048) >> 9;
- RF_END_RETURN_CALL(writeRegister(Register::Config, config.value));
+ return writeRegister(Register::Config, config.value);
}
// ----------------------------------------------------------------------------
template
-modm::ResumableResult
+bool
Ads101x::isBusy()
{
- RF_BEGIN();
-
buffer[0] = i(Register::Config);
- this->transaction.configureWriteRead(buffer, 1, buffer, 2);
-
- if (RF_CALL(this->runTransaction()))
+ if (I2cDevice::writeRead(buffer, 1, buffer, 2))
{
- RF_RETURN((static_cast(buffer[0] << 8) & i(ConfigRegister::OS)) == 0);
+ return (static_cast(buffer[0] << 8) & i(ConfigRegister::OS)) == 0;
}
- RF_END_RETURN(false);
+ return false;
}
// ----------------------------------------------------------------------------
template
-modm::ResumableResult
+bool
Ads101x::startSingleShotConversion()
{
- RF_BEGIN();
-
DeviceOperatingMode_t::set(config, DeviceOperatingMode::SingleShot);
- RF_END_RETURN_CALL(writeRegister(Register::Config, i(ConfigRegister::OS) | config.value));
+ return writeRegister(Register::Config, i(ConfigRegister::OS) | config.value);
}
// ----------------------------------------------------------------------------
template
-modm::ResumableResult
+bool
Ads101x::startContinuousConversion(DataRate dataRate)
{
- RF_BEGIN();
-
DataRate_t::set(config, dataRate);
DeviceOperatingMode_t::set(config, DeviceOperatingMode::Continuous);
- RF_END_RETURN_CALL(writeRegister(Register::Config, config.value));
+ return writeRegister(Register::Config, config.value);
}
// ----------------------------------------------------------------------------
template