Skip to content
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

spi: use const for output buffers #4552

Merged
merged 2 commits into from
Mar 23, 2018
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
14 changes: 7 additions & 7 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void SPIClass::write32(uint32_t data, bool msb) {
* @param data uint8_t *
* @param size uint32_t
*/
void SPIClass::writeBytes(uint8_t * data, uint32_t size) {
void SPIClass::writeBytes(const uint8_t * data, uint32_t size) {
while(size) {
if(size > 64) {
writeBytes_(data, 64);
Expand All @@ -393,13 +393,13 @@ void SPIClass::writeBytes(uint8_t * data, uint32_t size) {
}
}

void SPIClass::writeBytes_(uint8_t * data, uint8_t size) {
void SPIClass::writeBytes_(const uint8_t * data, uint8_t size) {
while(SPI1CMD & SPIBUSY) {}
// Set Bits to transfer
setDataBits(size * 8);

uint32_t * fifoPtr = (uint32_t*)&SPI1W0;
uint32_t * dataPtr = (uint32_t*) data;
const uint32_t * dataPtr = (uint32_t*) data;
uint32_t dataSize = ((size + 3) / 4);

while(dataSize--) {
Expand All @@ -418,14 +418,14 @@ void SPIClass::writeBytes_(uint8_t * data, uint8_t size) {
* @param size uint8_t max for size is 64Byte
* @param repeat uint32_t
*/
void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat) {
void SPIClass::writePattern(const uint8_t * data, uint8_t size, uint32_t repeat) {
if(size > 64) return; //max Hardware FIFO

while(SPI1CMD & SPIBUSY) {}

uint32_t buffer[16];
uint8_t *bufferPtr=(uint8_t *)&buffer;
uint8_t *dataPtr = data;
const uint8_t *dataPtr = data;
volatile uint32_t * fifoPtr = &SPI1W0;
uint8_t r;
uint32_t repeatRem;
Expand Down Expand Up @@ -497,7 +497,7 @@ void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat) {
* @param in uint8_t *
* @param size uint32_t
*/
void SPIClass::transferBytes(uint8_t * out, uint8_t * in, uint32_t size) {
void SPIClass::transferBytes(const uint8_t * out, uint8_t * in, uint32_t size) {
while(size) {
if(size > 64) {
transferBytes_(out, in, 64);
Expand All @@ -511,7 +511,7 @@ void SPIClass::transferBytes(uint8_t * out, uint8_t * in, uint32_t size) {
}
}

void SPIClass::transferBytes_(uint8_t * out, uint8_t * in, uint8_t size) {
void SPIClass::transferBytes_(const uint8_t * out, uint8_t * in, uint8_t size) {
while(SPI1CMD & SPIBUSY) {}
// Set in/out Bits to transfer

Expand Down
10 changes: 5 additions & 5 deletions libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class SPIClass {
void write16(uint16_t data, bool msb);
void write32(uint32_t data);
void write32(uint32_t data, bool msb);
void writeBytes(uint8_t * data, uint32_t size);
void writePattern(uint8_t * data, uint8_t size, uint32_t repeat);
void transferBytes(uint8_t * out, uint8_t * in, uint32_t size);
void writeBytes(const uint8_t * data, uint32_t size);
void writePattern(const uint8_t * data, uint8_t size, uint32_t repeat);
void transferBytes(const uint8_t * out, uint8_t * in, uint32_t size);
void endTransaction(void);
private:
bool useHwCs;
uint8_t pinSet;
void writeBytes_(uint8_t * data, uint8_t size);
void transferBytes_(uint8_t * out, uint8_t * in, uint8_t size);
void writeBytes_(const uint8_t * data, uint8_t size);
void transferBytes_(const uint8_t * out, uint8_t * in, uint8_t size);
inline void setDataBits(uint16_t bits);
};

Expand Down