Winbond W25Q32 SPI library. Tested on Winbond W74M32 embedded on Hani-IoT. Based on https://os.mbed.com/users/perezalvarezhi/code/W25Q80BV/
Revision 1:d3928deefb53, committed 2020-01-08
- Comitter:
- Pawel Zarembski
- Date:
- Wed Jan 08 11:17:24 2020 +0100
- Parent:
- 0:cc8118fdcc22
- Commit message:
- fix methods names
Changed in this revision
W25Q32.cpp | Show annotated file Show diff for this revision Revisions of this file |
W25Q32.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/W25Q32.cpp Wed Jan 08 11:13:52 2020 +0100 +++ b/W25Q32.cpp Wed Jan 08 11:17:24 2020 +0100 @@ -4,7 +4,7 @@ } -int W25Q80BV::getMID() +int W25Q32::getMID() { int ID = 0; chipEnable(); @@ -18,7 +18,7 @@ return ID; } -int W25Q80BV::readByte(int addr) +int W25Q32::readByte(int addr) { chipEnable(); this->writeSPI(READ_DATA); @@ -30,7 +30,7 @@ return response; } -int W25Q80BV::readByte(int a2, int a1, int a0) +int W25Q32::readByte(int a2, int a1, int a0) { chipEnable(); this->writeSPI(READ_DATA); @@ -41,7 +41,7 @@ chipDisable(); return response; } -void W25Q80BV::readStream(int addr, char* buf, int count) +void W25Q32::readStream(int addr, char* buf, int count) { if (count < 1) { return; @@ -60,7 +60,7 @@ chipDisable(); } -void W25Q80BV::writeByte(int addr, int data) +void W25Q32::writeByte(int addr, int data) { writeEnable(); chipEnable(); @@ -74,7 +74,7 @@ thread_sleep_for(WAIT_TIME); } -void W25Q80BV::writeByte(int a2, int a1, int a0, int data) +void W25Q32::writeByte(int a2, int a1, int a0, int data) { writeEnable(); chipEnable(); @@ -88,7 +88,7 @@ thread_sleep_for(WAIT_TIME); } -void W25Q80BV::writeStream(int addr, char* buf, int count) { +void W25Q32::writeStream(int addr, char* buf, int count) { if (count < 1) { return; } @@ -109,7 +109,7 @@ thread_sleep_for(WAIT_TIME); } -void W25Q80BV::chipErase() +void W25Q32::chipErase() { writeEnable(); chipEnable(); @@ -119,32 +119,32 @@ thread_sleep_for(WAIT_TIME); } -void W25Q80BV::writeEnable() +void W25Q32::writeEnable() { chipEnable(); this->writeSPI(WRITE_ENABLE); chipDisable(); } -void W25Q80BV::writeDisable() +void W25Q32::writeDisable() { chipEnable(); this->writeSPI(WRITE_DISABLE); chipDisable(); } -void W25Q80BV::chipEnable() +void W25Q32::chipEnable() { _cs = 0; } -void W25Q80BV::chipDisable() +void W25Q32::chipDisable() { _cs = 1; } // Sends and receives 1 byte of SPI data MSB endianness -int W25Q80BV::writeSPI(int data){ +int W25Q32::writeSPI(int data){ int i; int aux = 0; int aux2 = 0;
--- a/W25Q32.h Wed Jan 08 11:13:52 2020 +0100 +++ b/W25Q32.h Wed Jan 08 11:17:24 2020 +0100 @@ -25,9 +25,9 @@ #define ADDR_BSHIFT1 8 #define ADDR_BSHIFT0 0 -class W25Q80BV { +class W25Q32 { public: - W25Q80BV(PinName mosi, PinName miso, PinName sclk, PinName cs); + W25Q32(PinName mosi, PinName miso, PinName sclk, PinName cs); int readByte(int addr); // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location int readByte(int a2, int a1, int a0); // takes the address in 3 separate bytes A[23,16], A[15,8], A[7,0] @@ -38,7 +38,7 @@ void writeStream(int addr, char* buf, int count); // write count bytes of data from buf to memory, starting at addr void chipErase(); // erase all data on chip - int getMID( ) ; // get the manufacturer ID + int getMID(); // get the manufacturer ID private: void writeEnable(); // write enable