Seiji Ainoguchi / SerialFlash

Dependents:   SerialFlashTest

Fork of SerialFlash by Seiji Ainoguchi

M25PDeviceImpl.h

Committer:
s_ain
Date:
2011-03-01
Revision:
0:d0117f54a7ee
Child:
2:6f8ab876b516

File content as of revision 0:d0117f54a7ee:

#pragma once

#include <string>

class ISPI;

class M25PDeviceImpl
{
public:
    static bool IsSupported(ISPI* pSPI);
    static M25PDeviceImpl* Create(ISPI* pSPI);
    ~M25PDeviceImpl(void);
    
    std::string GetDeviceName() const;
    int GetCapacity() const;
    int Read(int address, void* buffer, int length);
    int Write(int address, const void* buffer, int length);
    void BulkErase(void);

private:
    ISPI* _pSPI;
    int _operationFrequency;
    struct DeviceProperty
    {
        std::string deviceName;
        int  capacity;
        int  blockProtectionMask;
    } const& _property;
    static const DeviceProperty* findMatchDevice(ISPI* pSPI);

    M25PDeviceImpl(ISPI* pSPI, const DeviceProperty& property);
    void writeAddress(int address);
    static void readId(ISPI* pSPI, int& manufacturerId, int& memoryType, int& memoryCapacity);

    int readStatusRegister(void);
    void clearBlockProtection(void);
    void writeStatusRegister(int value);
    void writeEnable(void);
    void writeDisable(void);
    void pageProgram(int address, const void* buffer);
};