From dea0868b9a144118ee2bff96abd2f1104f6e7ad7 Mon Sep 17 00:00:00 2001 From: alba-ado Date: Wed, 1 Nov 2023 15:40:29 +0300 Subject: [PATCH 1/5] Changed return types of functions that call Adafruit_SPI device --- .vscode/settings.json | 5 +++++ Adafruit_FRAM_SPI.cpp | 28 ++++++++++++++++------------ Adafruit_FRAM_SPI.h | 12 ++++++------ 3 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..930ff05 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.tcc": "cpp" + } +} \ No newline at end of file diff --git a/Adafruit_FRAM_SPI.cpp b/Adafruit_FRAM_SPI.cpp index e09f112..cfee60a 100644 --- a/Adafruit_FRAM_SPI.cpp +++ b/Adafruit_FRAM_SPI.cpp @@ -162,7 +162,7 @@ bool Adafruit_FRAM_SPI::begin(uint8_t nAddressSizeBytes) { @param enable True enables writes, false disables writes */ -void Adafruit_FRAM_SPI::writeEnable(bool enable) { +bool Adafruit_FRAM_SPI::writeEnable(bool enable) { uint8_t cmd; if (enable) { @@ -170,7 +170,7 @@ void Adafruit_FRAM_SPI::writeEnable(bool enable) { } else { cmd = OPCODE_WRDI; } - spi_dev->write(&cmd, 1); + return spi_dev->write(&cmd, 1); } /*! @@ -180,7 +180,7 @@ void Adafruit_FRAM_SPI::writeEnable(bool enable) { * @param value * The 8-bit value to write at framAddr */ -void Adafruit_FRAM_SPI::write8(uint32_t addr, uint8_t value) { +bool Adafruit_FRAM_SPI::write8(uint32_t addr, uint8_t value) { uint8_t buffer[10]; uint8_t i = 0; @@ -193,7 +193,7 @@ void Adafruit_FRAM_SPI::write8(uint32_t addr, uint8_t value) { buffer[i++] = (uint8_t)(addr & 0xFF); buffer[i++] = value; - spi_dev->write(buffer, i); + return spi_dev->write(buffer, i); } /*! @@ -205,7 +205,7 @@ void Adafruit_FRAM_SPI::write8(uint32_t addr, uint8_t value) { * @param count * The number of bytes to write */ -void Adafruit_FRAM_SPI::write(uint32_t addr, const uint8_t *values, +bool Adafruit_FRAM_SPI::write(uint32_t addr, const uint8_t *values, size_t count) { uint8_t prebuf[10]; uint8_t i = 0; @@ -218,7 +218,7 @@ void Adafruit_FRAM_SPI::write(uint32_t addr, const uint8_t *values, prebuf[i++] = (uint8_t)(addr >> 8); prebuf[i++] = (uint8_t)(addr & 0xFF); - spi_dev->write(values, count, prebuf, i); + return spi_dev->write(values, count, prebuf, i); } /*! @@ -253,7 +253,7 @@ uint8_t Adafruit_FRAM_SPI::read8(uint32_t addr) { * @param count * The number of bytes to read */ -void Adafruit_FRAM_SPI::read(uint32_t addr, uint8_t *values, size_t count) { +bool Adafruit_FRAM_SPI::read(uint32_t addr, uint8_t *values, size_t count) { uint8_t buffer[10]; uint8_t i = 0; @@ -265,7 +265,7 @@ void Adafruit_FRAM_SPI::read(uint32_t addr, uint8_t *values, size_t count) { buffer[i++] = (uint8_t)(addr >> 8); buffer[i++] = (uint8_t)(addr & 0xFF); - spi_dev->write_then_read(buffer, i, values, count); + return spi_dev->write_then_read(buffer, i, values, count); } /*! @@ -277,12 +277,14 @@ void Adafruit_FRAM_SPI::read(uint32_t addr, uint8_t *values, size_t count) { * Product ID fields (bytes 7..0). Should be 0x0302 for * the MB85RS64VPNF-G-JNERE1. */ -void Adafruit_FRAM_SPI::getDeviceID(uint8_t *manufacturerID, +bool Adafruit_FRAM_SPI::getDeviceID(uint8_t *manufacturerID, uint16_t *productID) { uint8_t cmd = OPCODE_RDID; uint8_t a[4] = {0, 0, 0, 0}; - spi_dev->write_then_read(&cmd, 1, a, 4); + if( !spi_dev->write_then_read(&cmd, 1, a, 4) ) { + return false; + } if (a[1] == 0x7f) { // Device with continuation code (0x7F) in their second byte @@ -295,6 +297,8 @@ void Adafruit_FRAM_SPI::getDeviceID(uint8_t *manufacturerID, *manufacturerID = (a[0]); *productID = (a[1] << 8) + a[2]; } + + return true; } /*! @@ -316,13 +320,13 @@ uint8_t Adafruit_FRAM_SPI::getStatusRegister() { * @param value * value that will be set */ -void Adafruit_FRAM_SPI::setStatusRegister(uint8_t value) { +bool Adafruit_FRAM_SPI::setStatusRegister(uint8_t value) { uint8_t cmd[2]; cmd[0] = OPCODE_WRSR; cmd[1] = value; - spi_dev->write(cmd, 2); + return spi_dev->write(cmd, 2); } /*! diff --git a/Adafruit_FRAM_SPI.h b/Adafruit_FRAM_SPI.h index 073d664..3baf249 100644 --- a/Adafruit_FRAM_SPI.h +++ b/Adafruit_FRAM_SPI.h @@ -47,14 +47,14 @@ class Adafruit_FRAM_SPI { Adafruit_FRAM_SPI(int8_t clk, int8_t miso, int8_t mosi, int8_t cs); bool begin(uint8_t nAddressSizeBytes = 2); - void writeEnable(bool enable); - void write8(uint32_t addr, uint8_t value); - void write(uint32_t addr, const uint8_t *values, size_t count); + bool writeEnable(bool enable); + bool write8(uint32_t addr, uint8_t value); + bool write(uint32_t addr, const uint8_t *values, size_t count); uint8_t read8(uint32_t addr); - void read(uint32_t addr, uint8_t *values, size_t count); - void getDeviceID(uint8_t *manufacturerID, uint16_t *productID); + bool read(uint32_t addr, uint8_t *values, size_t count); + bool getDeviceID(uint8_t *manufacturerID, uint16_t *productID); uint8_t getStatusRegister(void); - void setStatusRegister(uint8_t value); + bool setStatusRegister(uint8_t value); void setAddressSize(uint8_t nAddressSize); private: From 4f1a906974da11cabec6f86cfa90274c06b63bb4 Mon Sep 17 00:00:00 2001 From: alba-ado Date: Wed, 1 Nov 2023 16:53:34 +0300 Subject: [PATCH 2/5] Removed .vscode file --- .gitignore | 1 + .vscode/settings.json | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 542d266..bd98806 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ Doxyfile* doxygen_sqlite3.db html *.tmp +.vscode/* diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 930ff05..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "*.tcc": "cpp" - } -} \ No newline at end of file From 46a263c12dd83b776285c21247184fb7845d246d Mon Sep 17 00:00:00 2001 From: alba-ado Date: Thu, 2 Nov 2023 11:30:27 +0300 Subject: [PATCH 3/5] Clang formatting mistake fix --- Adafruit_FRAM_SPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_FRAM_SPI.cpp b/Adafruit_FRAM_SPI.cpp index cfee60a..917e34a 100644 --- a/Adafruit_FRAM_SPI.cpp +++ b/Adafruit_FRAM_SPI.cpp @@ -282,7 +282,7 @@ bool Adafruit_FRAM_SPI::getDeviceID(uint8_t *manufacturerID, uint8_t cmd = OPCODE_RDID; uint8_t a[4] = {0, 0, 0, 0}; - if( !spi_dev->write_then_read(&cmd, 1, a, 4) ) { + if(!spi_dev->write_then_read(&cmd, 1, a, 4)) { return false; } From 6b8f9d52f0a8fa33be4383c503959d10893832d6 Mon Sep 17 00:00:00 2001 From: alba-ado Date: Thu, 2 Nov 2023 11:32:14 +0300 Subject: [PATCH 4/5] Clang formatting mistake fix 2 --- Adafruit_FRAM_SPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_FRAM_SPI.cpp b/Adafruit_FRAM_SPI.cpp index 917e34a..d900b5e 100644 --- a/Adafruit_FRAM_SPI.cpp +++ b/Adafruit_FRAM_SPI.cpp @@ -282,7 +282,7 @@ bool Adafruit_FRAM_SPI::getDeviceID(uint8_t *manufacturerID, uint8_t cmd = OPCODE_RDID; uint8_t a[4] = {0, 0, 0, 0}; - if(!spi_dev->write_then_read(&cmd, 1, a, 4)) { + if (!spi_dev->write_then_read(&cmd, 1, a, 4)) { return false; } From ed0aed4b8cb91563ab2eefa5cd0ddd063cc2ea77 Mon Sep 17 00:00:00 2001 From: alba-ado Date: Thu, 2 Nov 2023 11:49:11 +0300 Subject: [PATCH 5/5] Added doxygen return types --- Adafruit_FRAM_SPI.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Adafruit_FRAM_SPI.cpp b/Adafruit_FRAM_SPI.cpp index d900b5e..9284998 100644 --- a/Adafruit_FRAM_SPI.cpp +++ b/Adafruit_FRAM_SPI.cpp @@ -158,10 +158,11 @@ bool Adafruit_FRAM_SPI::begin(uint8_t nAddressSizeBytes) { } /*! - @brief Enables or disables writing to the SPI flash - @param enable - True enables writes, false disables writes -*/ + * @brief Enables or disables writing to the SPI flash + * @param enable + * True enables writes, false disables writes + * @return true if successful + */ bool Adafruit_FRAM_SPI::writeEnable(bool enable) { uint8_t cmd; @@ -179,6 +180,7 @@ bool Adafruit_FRAM_SPI::writeEnable(bool enable) { * The 32-bit address to write to in FRAM memory * @param value * The 8-bit value to write at framAddr + * @return true if successful */ bool Adafruit_FRAM_SPI::write8(uint32_t addr, uint8_t value) { uint8_t buffer[10]; @@ -204,6 +206,7 @@ bool Adafruit_FRAM_SPI::write8(uint32_t addr, uint8_t value) { * The pointer to an array of 8-bit values to write starting at addr * @param count * The number of bytes to write + * @return true if successful */ bool Adafruit_FRAM_SPI::write(uint32_t addr, const uint8_t *values, size_t count) { @@ -252,6 +255,7 @@ uint8_t Adafruit_FRAM_SPI::read8(uint32_t addr) { * The pointer to an array of 8-bit values to read starting at addr * @param count * The number of bytes to read + * @return true if successful */ bool Adafruit_FRAM_SPI::read(uint32_t addr, uint8_t *values, size_t count) { uint8_t buffer[10]; @@ -276,6 +280,7 @@ bool Adafruit_FRAM_SPI::read(uint32_t addr, uint8_t *values, size_t count) { * The memory density (bytes 15..8) and proprietary * Product ID fields (bytes 7..0). Should be 0x0302 for * the MB85RS64VPNF-G-JNERE1. + * @return true if successful */ bool Adafruit_FRAM_SPI::getDeviceID(uint8_t *manufacturerID, uint16_t *productID) { @@ -319,6 +324,7 @@ uint8_t Adafruit_FRAM_SPI::getStatusRegister() { * @brief Sets the status register * @param value * value that will be set + * @return true if successful */ bool Adafruit_FRAM_SPI::setStatusRegister(uint8_t value) { uint8_t cmd[2];