MAX30001-MAX32630FTHR SYS EvKit

Dependencies:   USBDevice max32630fthr

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers S25FS512.h Source File

S25FS512.h

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 #ifndef S25FS512_H_
00034 #define S25FS512_H_
00035 
00036 #include "mbed.h"
00037 #include "QuadSpiInterface.h"
00038 
00039 class S25FS512 {
00040 public:
00041   S25FS512(QuadSpiInterface *_quadSpiInterface);
00042   ~S25FS512(void);
00043 
00044   QuadSpiInterface *quadSpiInterface;
00045 
00046   /** Initialize the driver
00047   */
00048   int init(void);
00049 
00050   /** Detect the presence of the flash device
00051   */
00052   uint8_t detect(void);
00053 
00054   /** Read the identification of the flash
00055   */
00056   int8_t readIdentification(uint8_t *dataArray, uint8_t length);
00057 
00058   /** Bulk erase the flash device
00059   */
00060   int8_t bulkErase_Helper(void);
00061 
00062   /** Erase Parameter Sectors
00063   */
00064   int8_t parameterSectorErase_Helper(uint32_t address);
00065 
00066   /** Write a Page
00067   */
00068   int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer,
00069                           uint32_t offset);
00070 
00071   /** Read a Page
00072   * @param
00073   */
00074   int8_t readPages_Helper(uint32_t startPageNumber, uint32_t endPageNumber,
00075                           uint8_t *buffer, uint32_t offset);
00076 
00077   /** Erase a Sector
00078   @param address Address of sector to erase
00079   */
00080 
00081   int8_t sectorErase_Helper(uint32_t address);
00082   /** Scans through byte pointer for a page worth of data to see if the page is all FFs
00083   @param ptr Byte pointer to buffer to scan
00084   @return Returns a 1 if the page is empty, 0 if it is not all FFs
00085   */
00086   uint32_t isPageEmpty(uint8_t *ptr);
00087   
00088   /** Issue a software reset to the flash device
00089   */
00090 
00091   uint8_t reset(void);
00092   /** Enable a hardware reset
00093   */
00094 
00095   uint8_t enableHWReset(void);
00096   /** Read the id byte of this device
00097   */
00098 
00099   void readID(uint8_t *id);
00100 
00101 private:
00102   int8_t reg_write_read_multiple_quad_last(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut, uint8_t last);
00103   int8_t reg_write_read_multiple_quad(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut);
00104   int8_t reg_write_read_multiple_4Wire(uint8_t *bufferOut, uint8_t numberOut, uint8_t *bufferIn, uint8_t numberIn);
00105   uint8_t spiWriteRead (uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData);
00106   uint8_t spiWriteRead4Wire(uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData);
00107 
00108   int8_t writeAnyRegister(uint32_t address, uint8_t data);
00109   int8_t writeAnyRegister4Wire(uint32_t address, uint8_t data);
00110   int8_t writeRegisters(void);
00111   uint8_t wren(void);
00112   int setQuadMode(void);
00113   int wren4Wire(void);
00114   // int8_t setQuadMode();
00115   int8_t readAnyRegister(uint32_t address, uint8_t *data, uint32_t length);
00116   int8_t bulkErase(void);
00117   int8_t pageProgram(uint32_t address, uint8_t *buffer);
00118   int8_t quadIoRead_Pages(uint32_t address, uint8_t *buffer, uint32_t numberOfPages);
00119   int8_t checkBusy(void);
00120   void waitTillNotBusy(void);
00121   int8_t sectorErase(uint32_t address);
00122   int8_t parameterSectorErase(uint32_t address);
00123   void wait_1mS(void);
00124   void wait_100uS(void);
00125   void wait_10mS(void);
00126 };
00127 #endif /* S25FS512_H_ */
00128