SPI Flash AT45DBXXXD

Fork of at45db161d by Suga koubou

Revision:
6:1872f591d604
Parent:
5:ef7247c6f073
Child:
7:2f9d8b47704f
--- a/at45db161d.h	Fri Mar 06 09:18:42 2015 +0800
+++ b/at45db161d.h	Fri Mar 06 09:42:28 2015 +0800
@@ -2,124 +2,12 @@
  * @file at45db161d.h
  * @brief AT45DB161D module
  **/
-#ifndef AT45DB161D_H
-#define AT45DB161D_H
+
+#ifndef AT45DB161D_H_
+#define AT45DB161D_H_
 
 #include "mbed.h"
 
-extern "C" {
-
-//#include <avr/pgmspace.h>
-#include <inttypes.h>
-//#include "WConstants.h"
-
-};
-
-#include "at45db161d_commands.h"
-
-/**
- * @defgroup AT45DB161D AT45DB161D module
- * @{
- **/
-
-/**
- * @defgroup SPI SPI pinout and transfert function
- * @{
- **/
-#ifndef SPI
-/**
- * @defgroup SPI_Pinout SPI pinout
- * @{
- **/
-///** Serial input (SI) **/
-//#define DATAOUT     11
-///** Serial output (SO) **/
-//#define DATAIN      12
-///** Serial clock (SCK) **/
-//#define SPICLOCK    13
-///** Chip select (CS) **/
-//#define SLAVESELECT 10
-///** Reset (Reset) **/
-//#define RESET        8
-///** Write protect (WP) **/
-//#define WP           7
-/**
- * @} 
- **/
-
-/**
- * @fn inline uint8_t spi_transfer(uint8_t data)
- * @brief Transfer a byte via spi
- * @param data Data to transfer via SPI
- * @return The content of the SPI data register (SPDR)
- **/
-/*
-inline uint8_t spi_transfer(uint8_t data)
-{
-    SPDR = data;
-    while(!(SPSR & (1 << SPIF))) ;
-    return SPDR;
-}
-*/
-//#define spi_transfer(data) _spi.write(data)
-
-/** De-assert CS **/
-//#define DF_CS_inactive digitalWrite(SLAVESELECT,HIGH)
-#define DF_CS_inactive _cs = 1
-/** Assert CS **/
-//#define DF_CS_active digitalWrite(SLAVESELECT,LOW)
-#define DF_CS_active _cs = 0
-
-#endif /* SPI */
-/**
- * @}
- **/
-
-/**
- * @defgroup STATUS_REGISTER_FORMAT Status register format
- * @{
- **/
-/**
- * Ready/busy status is indicated using bit 7 of the status register.
- * If bit 7 is a 1, then the device is not busy and is ready to accept
- * the next command. If bit 7 is a 0, then the device is in a busy 
- * state.
- **/
-#define READY_BUSY 0x80
-/**
- * Result of the most recent Memory Page to Buffer Compare operation.
- * If this bit is equal to 0, then the data in the main memory page
- * matches the data in the buffer. If it's 1 then at least 1 byte in 
- * the main memory page does not match the data in the buffer.
- **/
-#define COMPARE 0x40
-/**
- * Bit 1 in the Status Register is used to provide information to the
- * user whether or not the sector protection has been enabled or
- * disabled, either by software-controlled method or 
- * hardware-controlled method. 1 means that the sector protection has
- * been enabled and 0 that it has been disabled.
- **/
-#define PROTECT 0x02
-/**
- * Bit 0 indicates wether the page size of the main memory array is
- * configured for "power of 2" binary page size (512 bytes) (bit=1) or 
- * standard DataFlash page size (528 bytes) (bit=0).
- **/
-//#define PAGE_SIZE 0x01
-/**
- * Bits 5, 4, 3 and 2 indicates the device density. The decimal value
- * of these four binary bits does not equate to the device density; the
- * four bits represent a combinational code relating to differing
- * densities of DataFlash devices. The device density is not the same
- * as the density code indicated in the JEDEC device ID information.
- * The device density is provided only for backward compatibility.
- **/
-#define DEVICE_DENSITY 0x2C 
-/**
- * @}
- **/
-
 /**
  * @brief at45db161d module
  * @todo
@@ -128,19 +16,17 @@
  *     - Auto Page Rewrite through Buffer 1
  *     - Auto Page Rewrite through Buffer 2
  **/
-class ATD45DB161D
-{
+class ATD45DB161D {
     public:
         /** 
          * @brief ID structure 
          * This structure contains various informations about the
          * dataflash chip being used.
          **/
-        struct ID
-        {
-            uint8_t manufacturer;       /**< Manufacturer id                           **/
-            uint8_t device[2];          /**< Device id                                 **/
-            uint8_t extendedInfoLength; /**< Extended device information string length **/
+        struct ID {
+                uint8_t manufacturer; /**< Manufacturer id                           **/
+                uint8_t device[2]; /**< Device id                                 **/
+                uint8_t extendedInfoLength; /**< Extended device information string length **/
         };
 
     public:
@@ -150,9 +36,6 @@
          */
         ATD45DB161D(SPI *spi, PinName cs);
 
-        /** Setup SPI and pinout **/
-        void Init();
-
         /** 
          * Read status register 
          * @return The content of the status register
@@ -167,7 +50,7 @@
          * @param id Pointer to the ID structure to initialize
          **/
         void ReadManufacturerAndDeviceID(struct ATD45DB161D::ID *id);
-        
+
         /** 
          * A main memory page read allows the user to read data directly from
          * any one of the 4096 pages in the main memory, bypassing both of the
@@ -187,10 +70,9 @@
          **/
         void ContinuousArrayRead(uint16_t page, uint16_t offset, uint8_t low);
 
+        void read(uint16_t addr, void *buf, uint16_t len);
 
-        void read(uint16_t addr, void *buf, uint16_t len) ;
-
-        void write(uint16_t addr, void *buf, uint16_t len) ;
+        void write(uint16_t addr, void *buf, uint16_t len);
 
         /** 
          * Read the content of one of the SRAM data buffers (in low or high speed mode).
@@ -210,7 +92,7 @@
          * @param offset Starting byte within the buffer
          **/
         void BufferWrite(uint8_t bufferNum, uint16_t offset);
-        
+
         /**
          * Transfer data from buffer 1 or 2 to main memory page.
          * @param bufferNum Buffer to use (1 or 2)
@@ -218,7 +100,7 @@
          * @param erase If set the page will be first erased before the buffer transfer.
          * @note If erase is equal to zero, the page must have been previously erased using one of the erase command (Page or Block Erase).
          **/
-        void BufferToPage(uint8_t bufferNum, uint16_t page, uint8_t erase);        
+        void BufferToPage(uint8_t bufferNum, uint16_t page, uint8_t erase);
 
         /**
          * Transfer a page of data from main memory to buffer 1 or 2.
@@ -233,7 +115,7 @@
          * @warning UNTESTED
          **/
         void PageErase(uint16_t page);
-        
+
         /**
          * Erase a block of eight pages at one time.
          * @param block Index of the block to erase
@@ -266,7 +148,7 @@
          * @warning UNTESTED
          **/
         void BeginPageWriteThroughBuffer(uint16_t page, uint16_t offset, uint8_t bufferNum);
-        
+
         /**
          * Perform a low-to-high transition on the CS pin and then poll
          * the status register to check if the dataflash is busy.