Lucas Lim / Mbed 2 deprecated HSP_Temperature_Barometer_CS3237

Dependencies:   mbed

Committer:
lucaslwl
Date:
Mon Aug 26 08:11:41 2019 +0000
Revision:
22:5c07298d3383
add library folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lucaslwl 22:5c07298d3383 1 /*******************************************************************************
lucaslwl 22:5c07298d3383 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
lucaslwl 22:5c07298d3383 3 *
lucaslwl 22:5c07298d3383 4 * Permission is hereby granted, free of charge, to any person obtaining a
lucaslwl 22:5c07298d3383 5 * copy of this software and associated documentation files (the "Software"),
lucaslwl 22:5c07298d3383 6 * to deal in the Software without restriction, including without limitation
lucaslwl 22:5c07298d3383 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
lucaslwl 22:5c07298d3383 8 * and/or sell copies of the Software, and to permit persons to whom the
lucaslwl 22:5c07298d3383 9 * Software is furnished to do so, subject to the following conditions:
lucaslwl 22:5c07298d3383 10 *
lucaslwl 22:5c07298d3383 11 * The above copyright notice and this permission notice shall be included
lucaslwl 22:5c07298d3383 12 * in all copies or substantial portions of the Software.
lucaslwl 22:5c07298d3383 13 *
lucaslwl 22:5c07298d3383 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
lucaslwl 22:5c07298d3383 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
lucaslwl 22:5c07298d3383 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
lucaslwl 22:5c07298d3383 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
lucaslwl 22:5c07298d3383 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
lucaslwl 22:5c07298d3383 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
lucaslwl 22:5c07298d3383 20 * OTHER DEALINGS IN THE SOFTWARE.
lucaslwl 22:5c07298d3383 21 *
lucaslwl 22:5c07298d3383 22 * Except as contained in this notice, the name of Maxim Integrated
lucaslwl 22:5c07298d3383 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
lucaslwl 22:5c07298d3383 24 * Products, Inc. Branding Policy.
lucaslwl 22:5c07298d3383 25 *
lucaslwl 22:5c07298d3383 26 * The mere transfer of this software does not imply any licenses
lucaslwl 22:5c07298d3383 27 * of trade secrets, proprietary technology, copyrights, patents,
lucaslwl 22:5c07298d3383 28 * trademarks, maskwork rights, or any other form of intellectual
lucaslwl 22:5c07298d3383 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
lucaslwl 22:5c07298d3383 30 * ownership rights.
lucaslwl 22:5c07298d3383 31 *******************************************************************************
lucaslwl 22:5c07298d3383 32 */
lucaslwl 22:5c07298d3383 33 #ifndef S25FS512_H_
lucaslwl 22:5c07298d3383 34 #define S25FS512_H_
lucaslwl 22:5c07298d3383 35
lucaslwl 22:5c07298d3383 36 #include "mbed.h"
lucaslwl 22:5c07298d3383 37 #include "QuadSpiInterface.h"
lucaslwl 22:5c07298d3383 38
lucaslwl 22:5c07298d3383 39
lucaslwl 22:5c07298d3383 40 #define ADDRESS_INC_4K 0x1000
lucaslwl 22:5c07298d3383 41 #define ADDRESS_INC_32K 0x8000
lucaslwl 22:5c07298d3383 42 #define ADDRESS_INC_64K 0x10000
lucaslwl 22:5c07298d3383 43
lucaslwl 22:5c07298d3383 44 #define ADDRESS_4K_START 0x0
lucaslwl 22:5c07298d3383 45 #define ADDRESS_4K_END 0x8000
lucaslwl 22:5c07298d3383 46
lucaslwl 22:5c07298d3383 47 #define ADDRESS_32K_START 0x8000
lucaslwl 22:5c07298d3383 48 #define ADDRESS_32k_END 0x10000
lucaslwl 22:5c07298d3383 49
lucaslwl 22:5c07298d3383 50 #define ADDRESS_64K_START 0x10000
lucaslwl 22:5c07298d3383 51 #define ADDRESS_64k_END 0x2000000
lucaslwl 22:5c07298d3383 52
lucaslwl 22:5c07298d3383 53 #define SIZE_OF_EXTERNAL_FLASH 0x2000000 // 33,554,432 Bytes
lucaslwl 22:5c07298d3383 54 #define SIZE_OF_PAGE 0x100
lucaslwl 22:5c07298d3383 55
lucaslwl 22:5c07298d3383 56 #define IOMUX_IO_ENABLE 1
lucaslwl 22:5c07298d3383 57
lucaslwl 22:5c07298d3383 58 #define S25FS512_SPI_PORT 1
lucaslwl 22:5c07298d3383 59 #define S25FS512_CS_PIN 0
lucaslwl 22:5c07298d3383 60 #define S25FS512_CS_POLARITY 0
lucaslwl 22:5c07298d3383 61 #define S25FS512_CS_ACTIVITY_DELAY 0
lucaslwl 22:5c07298d3383 62 #define S25FS512_CS_INACTIVITY_DELAY 0
lucaslwl 22:5c07298d3383 63 #define S25FS512_CLK_HI 4
lucaslwl 22:5c07298d3383 64 #define S25FS512_CLK_LOW 4
lucaslwl 22:5c07298d3383 65 #define S25FS512_ALT_CLK 0
lucaslwl 22:5c07298d3383 66 #define S25FS512_CLK_POLARITY 0
lucaslwl 22:5c07298d3383 67 #define S25FS512_CLK_PHASE 0
lucaslwl 22:5c07298d3383 68 #define S25FS512_WRITE 1
lucaslwl 22:5c07298d3383 69 #define S25FS512_READ 0
lucaslwl 22:5c07298d3383 70
lucaslwl 22:5c07298d3383 71 ///< Byte addresses for flash configuration
lucaslwl 22:5c07298d3383 72 #define Address_CR1NV 0x00000002
lucaslwl 22:5c07298d3383 73 #define Address_CR1V 0x00800002
lucaslwl 22:5c07298d3383 74 #define Address_CR2NV 0x00000003
lucaslwl 22:5c07298d3383 75 #define Address_CR2V 0x00800003
lucaslwl 22:5c07298d3383 76
lucaslwl 22:5c07298d3383 77 #define INT_PORT_B 3
lucaslwl 22:5c07298d3383 78 #define INT_PIN_B 6
lucaslwl 22:5c07298d3383 79
lucaslwl 22:5c07298d3383 80
lucaslwl 22:5c07298d3383 81 class S25FS512 {
lucaslwl 22:5c07298d3383 82 public:
lucaslwl 22:5c07298d3383 83
lucaslwl 22:5c07298d3383 84 ///< @detail S25FS512 Commands
lucaslwl 22:5c07298d3383 85 typedef enum{
lucaslwl 22:5c07298d3383 86 Write_Reg = 0x01,
lucaslwl 22:5c07298d3383 87 Read_Status_Reg1 = 0x05,
lucaslwl 22:5c07298d3383 88 Write_Enable = 0x06,
lucaslwl 22:5c07298d3383 89 Erase_4k = 0x20,
lucaslwl 22:5c07298d3383 90 Bulk_Erase = 0x60,
lucaslwl 22:5c07298d3383 91 Read_Any_Reg = 0x65,
lucaslwl 22:5c07298d3383 92 Software_Reset_Enable = 0x66,
lucaslwl 22:5c07298d3383 93 Write_Any_Reg = 0x71,
lucaslwl 22:5c07298d3383 94 Software_Reset = 0x99,
lucaslwl 22:5c07298d3383 95 Read_Id = 0x9F,
lucaslwl 22:5c07298d3383 96 Erase_64k_256k = 0xD8,
lucaslwl 22:5c07298d3383 97 Quad_IO_Read = 0xEB,
lucaslwl 22:5c07298d3383 98 } S25FS512_Commands_t;
lucaslwl 22:5c07298d3383 99
lucaslwl 22:5c07298d3383 100 S25FS512(QuadSpiInterface *_quadSpiInterface);
lucaslwl 22:5c07298d3383 101 ~S25FS512(void);
lucaslwl 22:5c07298d3383 102
lucaslwl 22:5c07298d3383 103 QuadSpiInterface *quadSpiInterface;
lucaslwl 22:5c07298d3383 104
lucaslwl 22:5c07298d3383 105 /** @brief Initialize the driver
lucaslwl 22:5c07298d3383 106 */
lucaslwl 22:5c07298d3383 107 void init(void);
lucaslwl 22:5c07298d3383 108
lucaslwl 22:5c07298d3383 109 /** @brief Detect the presence of the flash device
lucaslwl 22:5c07298d3383 110 */
lucaslwl 22:5c07298d3383 111 uint8_t detect(void);
lucaslwl 22:5c07298d3383 112
lucaslwl 22:5c07298d3383 113 /** @brief Read the identification of the flash
lucaslwl 22:5c07298d3383 114 */
lucaslwl 22:5c07298d3383 115 int8_t readIdentification(uint8_t *dataArray, uint8_t length);
lucaslwl 22:5c07298d3383 116
lucaslwl 22:5c07298d3383 117 /** @brief Bulk erase the flash device
lucaslwl 22:5c07298d3383 118 */
lucaslwl 22:5c07298d3383 119 int8_t bulkErase_Helper(void);
lucaslwl 22:5c07298d3383 120
lucaslwl 22:5c07298d3383 121 /** @brief Erase Parameter Sectors
lucaslwl 22:5c07298d3383 122 */
lucaslwl 22:5c07298d3383 123 int8_t parameterSectorErase_Helper(uint32_t address);
lucaslwl 22:5c07298d3383 124
lucaslwl 22:5c07298d3383 125 /** @brief Write a Page
lucaslwl 22:5c07298d3383 126 */
lucaslwl 22:5c07298d3383 127 int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer, uint32_t offset);
lucaslwl 22:5c07298d3383 128
lucaslwl 22:5c07298d3383 129 /** @brief Read a Page
lucaslwl 22:5c07298d3383 130 */
lucaslwl 22:5c07298d3383 131 int8_t readPages_Helper(uint32_t startPageNumber,uint32_t endPageNumber, uint8_t *buffer, uint32_t offset);
lucaslwl 22:5c07298d3383 132
lucaslwl 22:5c07298d3383 133 /** @brief Erase a Sector
lucaslwl 22:5c07298d3383 134 @param address Address of sector to erase
lucaslwl 22:5c07298d3383 135 */
lucaslwl 22:5c07298d3383 136 int8_t sectorErase_Helper(uint32_t address);
lucaslwl 22:5c07298d3383 137
lucaslwl 22:5c07298d3383 138 /** @brief Scans through byte pointer for a page worth of data to see if the page is all FFs
lucaslwl 22:5c07298d3383 139 @param ptr Byte pointer to buffer to scan
lucaslwl 22:5c07298d3383 140 @return Returns a 1 if the page is empty, 0 if it is not all FFs
lucaslwl 22:5c07298d3383 141 */
lucaslwl 22:5c07298d3383 142 bool isPageEmpty(uint8_t *ptr);
lucaslwl 22:5c07298d3383 143
lucaslwl 22:5c07298d3383 144 /** @brief Issue a software reset to the flash device
lucaslwl 22:5c07298d3383 145 */
lucaslwl 22:5c07298d3383 146 uint8_t reset(void);
lucaslwl 22:5c07298d3383 147
lucaslwl 22:5c07298d3383 148 /** @brief Enable a hardware reset
lucaslwl 22:5c07298d3383 149 */
lucaslwl 22:5c07298d3383 150 uint8_t enableHWReset(void);
lucaslwl 22:5c07298d3383 151
lucaslwl 22:5c07298d3383 152 /** @brief Read the id byte of this device
lucaslwl 22:5c07298d3383 153 */
lucaslwl 22:5c07298d3383 154 void readID(uint8_t *id);
lucaslwl 22:5c07298d3383 155
lucaslwl 22:5c07298d3383 156 void test_verifyPage0Empty(uint8_t *ptr, int currentPage, int pagesWrittenTo);
lucaslwl 22:5c07298d3383 157
lucaslwl 22:5c07298d3383 158 int8_t readPartialPage_Helper(uint32_t pageNumber, uint8_t *buffer, uint32_t count);
lucaslwl 22:5c07298d3383 159
lucaslwl 22:5c07298d3383 160 private:
lucaslwl 22:5c07298d3383 161 void disableInterrupt(uint8_t state);
lucaslwl 22:5c07298d3383 162 int8_t reg_write_read_multiple_quad_last(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut, uint8_t last);
lucaslwl 22:5c07298d3383 163 int8_t reg_write_read_multiple_quad(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut);
lucaslwl 22:5c07298d3383 164 int8_t reg_write_read_multiple_4Wire(uint8_t *bufferOut, uint8_t numberOut, uint8_t *bufferIn, uint8_t numberIn);
lucaslwl 22:5c07298d3383 165 uint8_t spiWriteRead (uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData);
lucaslwl 22:5c07298d3383 166 uint8_t spiWriteRead4Wire(uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData);
lucaslwl 22:5c07298d3383 167 int8_t writeAnyRegister(uint32_t address, uint8_t data);
lucaslwl 22:5c07298d3383 168 int8_t writeAnyRegister4Wire(uint32_t address, uint8_t data);
lucaslwl 22:5c07298d3383 169 int8_t writeRegisters(void);
lucaslwl 22:5c07298d3383 170 uint8_t wren(void);
lucaslwl 22:5c07298d3383 171 int setQuadMode(void);
lucaslwl 22:5c07298d3383 172 int wren4Wire(void);
lucaslwl 22:5c07298d3383 173 // int8_t setQuadMode();
lucaslwl 22:5c07298d3383 174 int8_t readAnyRegister(uint32_t address, uint8_t *data, uint32_t length);
lucaslwl 22:5c07298d3383 175 int8_t bulkErase(void);
lucaslwl 22:5c07298d3383 176 int8_t pageProgram(uint32_t address, uint8_t *buffer);
lucaslwl 22:5c07298d3383 177 int8_t quadIoRead_Pages(uint32_t address, uint8_t *buffer, uint32_t numberOfPages);
lucaslwl 22:5c07298d3383 178 int8_t checkBusy(void);
lucaslwl 22:5c07298d3383 179 void waitTillNotBusy(void);
lucaslwl 22:5c07298d3383 180 int8_t sectorErase(uint32_t address);
lucaslwl 22:5c07298d3383 181 int8_t parameterSectorErase(uint32_t address);
lucaslwl 22:5c07298d3383 182 int8_t quadIoRead_PartialPage(uint32_t address, uint8_t *buffer, uint32_t numberOfBytesInPage);
lucaslwl 22:5c07298d3383 183
lucaslwl 22:5c07298d3383 184 uint8_t flashBuffer[257 + 10];
lucaslwl 22:5c07298d3383 185 };
lucaslwl 22:5c07298d3383 186 #endif /* S25FS512_H_ */
lucaslwl 22:5c07298d3383 187