Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 98bb122

Browse files
committedSep 28, 2021
Implement Adafruit_BusIO-style write/read method for SPI.
1 parent 58b6fb9 commit 98bb122

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎src/spi/SpiBusDevice.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ IoResponse SpiBusDevice::transfer(IoRequest & req)
4343
return SpiDispatcher::instance().dispatch(&req, &_config);
4444
}
4545

46+
bool SpiBusDevice::read(uint8_t * buffer, size_t len, uint8_t sendvalue)
47+
{
48+
SpiBusDeviceConfig config(_config.spi(), _config.settings(), _config.select_func(), _config.deselect_func(), sendvalue);
49+
IoRequest req(nullptr, 0, buffer, len);
50+
IoResponse rsp = SpiDispatcher::instance().dispatch(&req, &config);
51+
rsp->wait();
52+
return true;
53+
}
54+
55+
bool SpiBusDevice::write(const uint8_t * buffer, size_t len)
56+
{
57+
IoRequest req(buffer, len, nullptr, 0);
58+
IoResponse rsp = SpiDispatcher::instance().dispatch(&req, &_config);
59+
rsp->wait();
60+
return true;
61+
}
62+
4663
bool SpiBusDevice::write_then_read(const uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, uint8_t sendvalue)
4764
{
4865
SpiBusDeviceConfig config(_config.spi(), _config.settings(), _config.select_func(), _config.deselect_func(), sendvalue);

‎src/spi/SpiBusDevice.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class SpiBusDevice : public BusDeviceBase
4242
virtual IoResponse transfer(IoRequest & req) override;
4343

4444

45+
bool read(uint8_t * buffer, size_t len, uint8_t sendvalue = 0xFF);
46+
bool write(const uint8_t * buffer, size_t len);
4547
bool write_then_read(const uint8_t * write_buffer, size_t write_len, uint8_t * read_buffer, size_t read_len, uint8_t sendvalue = 0xFF);
4648

4749

0 commit comments

Comments
 (0)
Please sign in to comment.