Skip to content

Fix: Use only camel case for class member functions. #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ As a result this interruption by the scheduler will break Wire I/O access for bo
The mechanisms implemented in this library allow any thread to dispatch an I/O request asynchronously and either continue its operation or [yield](https://en.wikipedia.org/wiki/Yield_(multithreading)) control to the next scheduled thread. All I/O requests are stored in a queue and are executed within a high-priority I/O thread after a [context-switch](https://en.wikipedia.org/wiki/Context_switch). An example of this can be seen [here](examples/Threadsafe_IO/Threadsafe_SPI/Threadsafe_SPI.ino).

### :relieved: Convenient API
Although you are free to directly manipulate I/O requests and responses (e.g. [Threadsafe_Wire](examples/Threadsafe_IO/Threadsafe_Wire/Threadsafe_Wire.ino)) there are convenient `read`/`write`/`write_then_read` abstractions inspired by the [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO) library (e.g. [Threadsafe_Wire_BusIO](examples/Threadsafe_IO/Threadsafe_Wire_BusIO/Threadsafe_Wire_BusIO.ino)).
Although you are free to directly manipulate I/O requests and responses (e.g. [Threadsafe_Wire](examples/Threadsafe_IO/Threadsafe_Wire/Threadsafe_Wire.ino)) there are convenient `read`/`write`/`writeThenRead` abstractions inspired by the [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO) library (e.g. [Threadsafe_Wire_BusIO](examples/Threadsafe_IO/Threadsafe_Wire_BusIO/Threadsafe_Wire_BusIO.ino)).

## :zap: Caveats

Expand Down
8 changes: 4 additions & 4 deletions docs/04-threadsafe-wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ byte lsm6dsox_read_reg(byte const reg_addr)
}
```

### Synchronous thread-safe `Wire` access with `transfer_and_wait`
### Synchronous thread-safe `Wire` access with `transferAndWait`
([`examples/Threadsafe_IO/Wire`](../examples/Threadsafe_IO/Wire))

As the use of the `transfer` API might be difficult to grasp there's also a synchronous API call combining the request of the transfer and waiting for its result using `transfer_and_wait`.
As the use of the `transfer` API might be difficult to grasp there's also a synchronous API call combining the request of the transfer and waiting for its result using `transferAndWait`.
```C++
byte lsm6dsox_read_reg(byte const reg_addr)
{
byte write_buffer = reg_addr;
byte read_buffer = 0;

IoRequest request(write_buffer, read_buffer);
IoResponse response = transfer_and_wait(lsm6dsox, request); /* Transmit IO request for execution and wait for completion of request. */
IoResponse response = transferAndWait(lsm6dsox, request); /* Transmit IO request for execution and wait for completion of request. */

return read_buffer;
}
Expand All @@ -78,7 +78,7 @@ For further simplification [Adafruit_BusIO](https://github.com/adafruit/Adafruit
byte lsm6dsox_read_reg(byte reg_addr)
{
byte read_buffer = 0;
lsm6dsox.wire().write_then_read(&reg_addr, 1, &read_buffer, 1);
lsm6dsox.wire().writeThenRead(&reg_addr, 1, &read_buffer, 1);
return read_buffer;
}
```
8 changes: 4 additions & 4 deletions docs/05-threadsafe-spi.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ byte bmp388_read_reg(byte const reg_addr)
}
```

### Synchronous thread-safe `SPI` access with `transfer_and_wait`
### Synchronous thread-safe `SPI` access with `transferAndWait`
([`examples/Threadsafe_IO/SPI`](../examples/Threadsafe_IO/SPI))

As the use of the `transfer` API might be difficult to grasp there's also a synchronous API call combining the request of the transfer and waiting for its result using `transfer_and_wait`.
As the use of the `transfer` API might be difficult to grasp there's also a synchronous API call combining the request of the transfer and waiting for its result using `transferAndWait`.
```C++
byte bmp388_read_reg(byte const reg_addr)
{
/* REG_ADDR | DUMMY_BYTE | REG_VAL is on SDO */
byte read_write_buffer[] = {0x80 | reg_addr, 0, 0};

IoRequest request(read_write_buffer, sizeof(read_write_buffer), nullptr, 0);
IoResponse response = transfer_and_wait(bmp388, request);
IoResponse response = transferAndWait(bmp388, request);

auto value = read_write_buffer[2];
return value;
Expand All @@ -74,7 +74,7 @@ byte bmp388_read_reg(byte const reg_addr)
byte write_buffer[2] = {0x80 | reg_addr, 0};
byte read_buffer = 0;

bmp388.spi().write_then_read(write_buffer, sizeof(write_buffer), &read_buffer, sizeof(read_buffer));
bmp388.spi().writeThenRead(write_buffer, sizeof(write_buffer), &read_buffer, sizeof(read_buffer));
return read_buffer;
}
```
2 changes: 1 addition & 1 deletion examples/Breaks_4/Thread.inot
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS);
byte lsm6dsox_read_reg(byte reg_addr)
{
byte read_buf = 0;
lsm6dsox.wire().write_then_read(&reg_addr, 1, &read_buf, 1);
lsm6dsox.wire().writeThenRead(&reg_addr, 1, &read_buf, 1);
return read_buf;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/Threadsafe_IO/SPI/SPI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ byte bmp388_read_reg(byte const reg_addr)
byte read_write_buf[] = {static_cast<byte>(0x80 | reg_addr), 0, 0};

IoRequest req(read_write_buf, sizeof(read_write_buf), nullptr, 0);
IoResponse rsp = transfer_and_wait(bmp388, req);
IoResponse rsp = transferAndWait(bmp388, req);

return read_write_buf[2];
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* with different client devices on the same SPI bus.
*
* This example uses Adafruit_BusIO style read(), write(),
* write_then_read() APIs.
* writeThenRead() APIs.
*/

/**************************************************************************************
Expand Down Expand Up @@ -70,7 +70,7 @@ byte bmp388_read_reg(byte const reg_addr)
byte write_buf[2] = {static_cast<byte>(0x80 | reg_addr), 0};
byte read_buf = 0;

bmp388.spi().write_then_read(write_buf, sizeof(write_buf), &read_buf, sizeof(read_buf));
bmp388.spi().writeThenRead(write_buf, sizeof(write_buf), &read_buf, sizeof(read_buf));
return read_buf;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void setup()
Serial.begin(9600);
while (!Serial) { }

Serial.global_prefix(serial_log_message_prefix);
Serial.global_suffix(serial_log_message_suffix);
Serial.globalPrefix(serial_log_message_prefix);
Serial.globalSuffix(serial_log_message_suffix);

Thread_1.start();
Thread_2.start();
Expand Down
2 changes: 1 addition & 1 deletion examples/Threadsafe_IO/Wire/Wire.ino
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ byte lsm6dsox_read_reg(byte const reg_addr)
byte read_buf = 0;

IoRequest req(write_buf, read_buf);
IoResponse rsp = transfer_and_wait(lsm6dsox, req);
IoResponse rsp = transferAndWait(lsm6dsox, req);

return read_buf;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* with different client devices on the same Wire bus.
*
* This example uses Adafruit_BusIO style read(), write(),
* write_then_read() APIs.
* writeThenRead() APIs.
*/

/**************************************************************************************
Expand Down Expand Up @@ -64,7 +64,7 @@ void loop()
byte lsm6dsox_read_reg(byte reg_addr)
{
byte read_buf = 0;
lsm6dsox.wire().write_then_read(&reg_addr, 1, &read_buf, 1);
lsm6dsox.wire().writeThenRead(&reg_addr, 1, &read_buf, 1);
return read_buf;
}

Expand Down
7 changes: 4 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ block KEYWORD2
unblock KEYWORD2
prefix KEYWORD2
suffix KEYWORD2
global_prefix KEYWORD2
global_suffix KEYWORD2
globalPrefix KEYWORD2
globalSuffix KEYWORD2
spi KEYWORD2
wire KEYWORD2
read KEYWORD2
write KEYWORD2
write_then_read KEYWORD2
writeThenRead KEYWORD2
transferAndWait KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
4 changes: 2 additions & 2 deletions src/io/serial/SerialDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ void SerialDispatcher::suffix(SuffixInjectorCallbackFunc func)
iter->suffix_func = func;
}

void SerialDispatcher::global_prefix(PrefixInjectorCallbackFunc func)
void SerialDispatcher::globalPrefix(PrefixInjectorCallbackFunc func)
{
mbed::ScopedLock<rtos::Mutex> lock(_mutex);
_global_prefix_callback = func;
}

void SerialDispatcher::global_suffix(SuffixInjectorCallbackFunc func)
void SerialDispatcher::globalSuffix(SuffixInjectorCallbackFunc func)
{
mbed::ScopedLock<rtos::Mutex> lock(_mutex);
_global_suffix_callback = func;
Expand Down
4 changes: 2 additions & 2 deletions src/io/serial/SerialDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class SerialDispatcher : public arduino::HardwareSerial
typedef std::function<String(String const &, String const &)> SuffixInjectorCallbackFunc;
void prefix(PrefixInjectorCallbackFunc func);
void suffix(SuffixInjectorCallbackFunc func);
void global_prefix(PrefixInjectorCallbackFunc func);
void global_suffix(SuffixInjectorCallbackFunc func);
void globalPrefix(PrefixInjectorCallbackFunc func);
void globalSuffix(SuffixInjectorCallbackFunc func);


private:
Expand Down
6 changes: 3 additions & 3 deletions src/io/spi/SpiBusDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IoResponse SpiBusDevice::transfer(IoRequest & req)

bool SpiBusDevice::read(uint8_t * buffer, size_t len, uint8_t sendvalue)
{
SpiBusDeviceConfig config(_config.spi(), _config.settings(), _config.select_func(), _config.deselect_func(), sendvalue);
SpiBusDeviceConfig config(_config.spi(), _config.settings(), _config.selectFunc(), _config.deselectFunc(), sendvalue);
IoRequest req(nullptr, 0, buffer, len);
IoResponse rsp = SpiDispatcher::instance().dispatch(&req, &config);
rsp->wait();
Expand All @@ -60,9 +60,9 @@ bool SpiBusDevice::write(uint8_t * buffer, size_t len)
return true;
}

bool SpiBusDevice::write_then_read(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, uint8_t sendvalue)
bool SpiBusDevice::writeThenRead(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, uint8_t sendvalue)
{
SpiBusDeviceConfig config(_config.spi(), _config.settings(), _config.select_func(), _config.deselect_func(), sendvalue);
SpiBusDeviceConfig config(_config.spi(), _config.settings(), _config.selectFunc(), _config.deselectFunc(), sendvalue);
IoRequest req(write_buffer, write_len, read_buffer, read_len);
IoResponse rsp = SpiDispatcher::instance().dispatch(&req, &config);
rsp->wait();
Expand Down
2 changes: 1 addition & 1 deletion src/io/spi/SpiBusDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SpiBusDevice : public BusDeviceBase

bool read(uint8_t * buffer, size_t len, uint8_t sendvalue = 0xFF);
bool write(uint8_t * buffer, size_t len);
bool write_then_read(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, uint8_t sendvalue = 0xFF);
bool writeThenRead(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, uint8_t sendvalue = 0xFF);


private:
Expand Down
6 changes: 3 additions & 3 deletions src/io/spi/SpiBusDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class SpiBusDeviceConfig
SPISettings settings () const { return _spi_settings; }
void select () const { if (_spi_select) _spi_select(); }
void deselect () const { if (_spi_deselect) _spi_deselect(); }
byte fill_symbol() const { return _fill_symbol; }
byte fillSymbol () const { return _fill_symbol; }

SpiSelectFunc select_func () const { return _spi_select; }
SpiDeselectFunc deselect_func() const { return _spi_deselect; }
SpiSelectFunc selectFunc () const { return _spi_select; }
SpiDeselectFunc deselectFunc() const { return _spi_deselect; }

private:

Expand Down
2 changes: 1 addition & 1 deletion src/io/spi/SpiDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void SpiDispatcher::processSpiIoRequest(SpiIoTransaction * spi_io_transaction)
size_t bytes_received = 0;
for(; bytes_received < io_request->bytes_to_read; bytes_received++)
{
uint8_t const tx_byte = config->fill_symbol();
uint8_t const tx_byte = config->fillSymbol();
uint8_t const rx_byte = config->spi().transfer(tx_byte);

io_request->read_buf[bytes_received] = rx_byte;
Expand Down
2 changes: 1 addition & 1 deletion src/io/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* FUNCTION DEFINITION
**************************************************************************************/

IoResponse transfer_and_wait(BusDevice & dev, IoRequest & req)
IoResponse transferAndWait(BusDevice & dev, IoRequest & req)
{
IoResponse rsp = dev.transfer(req);
rsp->wait();
Expand Down
2 changes: 1 addition & 1 deletion src/io/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
* FUNCTION DECLARATION
**************************************************************************************/

IoResponse transfer_and_wait(BusDevice & dev, IoRequest & req);
IoResponse transferAndWait(BusDevice & dev, IoRequest & req);

#endif /* ARDUINO_THREADS_UTIL_H_ */
8 changes: 4 additions & 4 deletions src/io/wire/WireBusDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IoResponse WireBusDevice::transfer(IoRequest & req)

bool WireBusDevice::read(uint8_t * buffer, size_t len, bool stop)
{
WireBusDeviceConfig config(_config.wire(), _config.slave_addr(), _config.restart(), stop);
WireBusDeviceConfig config(_config.wire(), _config.slaveAddr(), _config.restart(), stop);
IoRequest req(nullptr, 0, buffer, len);
IoResponse rsp = WireDispatcher::instance().dispatch(&req, &config);
rsp->wait();
Expand All @@ -55,20 +55,20 @@ bool WireBusDevice::read(uint8_t * buffer, size_t len, bool stop)
bool WireBusDevice::write(uint8_t * buffer, size_t len, bool stop)
{
bool const restart = !stop;
WireBusDeviceConfig config(_config.wire(), _config.slave_addr(), restart, _config.stop());
WireBusDeviceConfig config(_config.wire(), _config.slaveAddr(), restart, _config.stop());
IoRequest req(buffer, len, nullptr, 0);
IoResponse rsp = WireDispatcher::instance().dispatch(&req, &config);
rsp->wait();
return true;
}

bool WireBusDevice::write_then_read(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop)
bool WireBusDevice::writeThenRead(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop)
{
/* Copy the Wire parameters from the device and modify only those
* which can be modified via the parameters of this function.
*/
bool const restart = !stop;
WireBusDeviceConfig config(_config.wire(), _config.slave_addr(), restart, _config.stop());
WireBusDeviceConfig config(_config.wire(), _config.slaveAddr(), restart, _config.stop());
/* Fire off the IO request and await its response. */
IoRequest req(write_buffer, write_len, read_buffer, read_len);
IoResponse rsp = WireDispatcher::instance().dispatch(&req, &config);
Expand Down
2 changes: 1 addition & 1 deletion src/io/wire/WireBusDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WireBusDevice : public BusDeviceBase

bool read(uint8_t * buffer, size_t len, bool stop = true);
bool write(uint8_t * buffer, size_t len, bool stop = true);
bool write_then_read(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop = false);
bool writeThenRead(uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, bool stop = false);


private:
Expand Down
2 changes: 1 addition & 1 deletion src/io/wire/WireBusDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WireBusDeviceConfig


inline arduino::HardwareI2C & wire() { return _wire; }
inline byte slave_addr() const { return _slave_addr; }
inline byte slaveAddr() const { return _slave_addr; }
inline bool restart() const { return _restart; }
inline bool stop() const { return _stop; }

Expand Down
4 changes: 2 additions & 2 deletions src/io/wire/WireDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void WireDispatcher::processWireIoRequest(WireIoTransaction * wire_io_transactio

if (io_request->bytes_to_write > 0)
{
config->wire().beginTransmission(config->slave_addr());
config->wire().beginTransmission(config->slaveAddr());

size_t bytes_written = 0;
for (; bytes_written < io_request->bytes_to_write; bytes_written++)
Expand All @@ -155,7 +155,7 @@ void WireDispatcher::processWireIoRequest(WireIoTransaction * wire_io_transactio

if (io_request->bytes_to_read > 0)
{
config->wire().requestFrom(config->slave_addr(), io_request->bytes_to_read, config->stop());
config->wire().requestFrom(config->slaveAddr(), io_request->bytes_to_read, config->stop());

while(config->wire().available() != static_cast<int>(io_request->bytes_to_read))
{
Expand Down