Shows how to use a display, the onboard SD Card and the onboard SPI Flash. Requires a display module with direct Arduino pinning

Dependencies:   DmTftLibrary SDFileSystem mbed

Committer:
displaymodule
Date:
Thu Jan 22 05:54:22 2015 +0000
Revision:
6:0f69891b105e
Parent:
0:3ecd25651727
Add DM_TFT43_108, DM_TFT50_111 based on new lib drv: DmTftRa8875

Who changed what in which revision?

UserRevisionLine numberNew contents of line
displaymodule 0:3ecd25651727 1 // W25Q16BV.h
displaymodule 0:3ecd25651727 2
displaymodule 0:3ecd25651727 3 #ifndef W25Q16BV_H
displaymodule 0:3ecd25651727 4 #define W25Q16BV_H
displaymodule 0:3ecd25651727 5
displaymodule 0:3ecd25651727 6 #include "mbed.h"
displaymodule 0:3ecd25651727 7 //#include "BitBangedSPI.h"
displaymodule 0:3ecd25651727 8
displaymodule 0:3ecd25651727 9 #define SPI_FREQ 1000000
displaymodule 0:3ecd25651727 10 #define SPI_MODE 0
displaymodule 0:3ecd25651727 11 #define SPI_NBIT 8
displaymodule 0:3ecd25651727 12
displaymodule 0:3ecd25651727 13 #define POWERUP_INST 0xAB
displaymodule 0:3ecd25651727 14 #define STATUS1_INST 0x05
displaymodule 0:3ecd25651727 15 #define STATUS2_INST 0x35
displaymodule 0:3ecd25651727 16 #define JDEC_INST 0x9F
displaymodule 0:3ecd25651727 17 #define UNIQUE_INST 0x4B
displaymodule 0:3ecd25651727 18 #define WE_INST 0x06
displaymodule 0:3ecd25651727 19 #define WD_INST 0x04
displaymodule 0:3ecd25651727 20 #define R_INST 0x03
displaymodule 0:3ecd25651727 21 #define W_INST 0x02
displaymodule 0:3ecd25651727 22 #define S_ERASE_INST 0x20 /* 4KB sector erase */
displaymodule 0:3ecd25651727 23 #define B_ERASE_INST 0xD8 /* 64KB block erase */
displaymodule 0:3ecd25651727 24 #define C_ERASE_INST 0x60
displaymodule 0:3ecd25651727 25
displaymodule 0:3ecd25651727 26 #define DUMMY_ADDR 0x00
displaymodule 0:3ecd25651727 27
displaymodule 0:3ecd25651727 28 #define WAIT_US_TRES1 5 /* Power Up: 3us */
displaymodule 0:3ecd25651727 29 //#define WAIT_US_TPUW 10000 /* Power Up Write Time: 1-10ms */
displaymodule 0:3ecd25651727 30 //#define WAIT_US_TBP 50 /* Byte Program Time: 20-50us */
displaymodule 0:3ecd25651727 31 //#define WAIT_US_TPP 3000 /* Page Program Time: 0.7-3ms */
displaymodule 0:3ecd25651727 32 //#define WAIT_US_TSE 400000 /* Sector Erase Time: 30-400ms */
displaymodule 0:3ecd25651727 33 //#define WAIT_US_TBE 1000000 /* 64KB Block Erase Time: 1000ms */
displaymodule 0:3ecd25651727 34 //#define WAIT_US_TCE 10000000 /* Chip Erase Time: 3-10s */
displaymodule 0:3ecd25651727 35
displaymodule 0:3ecd25651727 36 //#define ADDR_BMASK2 0x00ff0000
displaymodule 0:3ecd25651727 37 //#define ADDR_BMASK1 0x0000ff00
displaymodule 0:3ecd25651727 38 //#define ADDR_BMASK0 0x000000ff
displaymodule 0:3ecd25651727 39
displaymodule 0:3ecd25651727 40 //#define ADDR_BSHIFT2 16
displaymodule 0:3ecd25651727 41 //#define ADDR_BSHIFT1 8
displaymodule 0:3ecd25651727 42 //#define ADDR_BSHIFT0 0
displaymodule 0:3ecd25651727 43
displaymodule 0:3ecd25651727 44 #define PAGE_SIZE 256
displaymodule 0:3ecd25651727 45 #define SECTOR_SIZE 4096
displaymodule 0:3ecd25651727 46 #define NUM_SECTORS 512
displaymodule 0:3ecd25651727 47 #define NUM_64KB_BLOCKS 32
displaymodule 0:3ecd25651727 48
displaymodule 0:3ecd25651727 49 #define STATUS_1_BUSY 0x01
displaymodule 0:3ecd25651727 50
displaymodule 0:3ecd25651727 51 class W25Q16BV /*: public BitBangedSPI*/ {
displaymodule 0:3ecd25651727 52 public:
displaymodule 0:3ecd25651727 53 W25Q16BV(PinName mosi, PinName miso, PinName sclk, PinName cs);
displaymodule 0:3ecd25651727 54
displaymodule 0:3ecd25651727 55 int readByte(int addr); // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location
displaymodule 0:3ecd25651727 56 int readByte(int a2, int a1, int a0); // takes the address in 3 separate bytes A[23,16], A[15,8], A[7,0]
displaymodule 0:3ecd25651727 57 void readStream(int addr, char* buf, int count); // takes a 24-bit address, reads count bytes, and stores results in buf
displaymodule 0:3ecd25651727 58
displaymodule 0:3ecd25651727 59 void readJEDEC(uint8_t* manId, uint8_t* memType, uint8_t* cap);
displaymodule 0:3ecd25651727 60 uint8_t readStatus1();
displaymodule 0:3ecd25651727 61 uint8_t readStatus2();
displaymodule 0:3ecd25651727 62
displaymodule 0:3ecd25651727 63 void writeByte(int addr, int data); // takes a 24-bit (3 bytes) address and a byte of data to write at that location
displaymodule 0:3ecd25651727 64 void writeByte(int a2, int a1, int a0, int data); // takes the address in 3 separate bytes A[23,16], A[15,8], A[7,0]
displaymodule 0:3ecd25651727 65 void writeStream(int addr, char* buf, int count); // write count bytes of data from buf to memory, starting at addr
displaymodule 0:3ecd25651727 66
displaymodule 0:3ecd25651727 67 void chipErase(); // erase all data on chip
displaymodule 0:3ecd25651727 68 bool blockErase(int startBlock, int num=1); // erase all data in the specified number of 64KB blocks, return false if block number is invalid
displaymodule 0:3ecd25651727 69 bool sectorErase(int startSector, int num=1); // erase all data in the specified number of 4KB sectors, return false if sector number is invalid
displaymodule 0:3ecd25651727 70
displaymodule 0:3ecd25651727 71 private:
displaymodule 0:3ecd25651727 72
displaymodule 0:3ecd25651727 73 void exitDeepPowerDown();
displaymodule 0:3ecd25651727 74 void waitWhileBusy();
displaymodule 0:3ecd25651727 75
displaymodule 0:3ecd25651727 76 void writeEnable(); // write enable
displaymodule 0:3ecd25651727 77 void writeDisable(); // write disable
displaymodule 0:3ecd25651727 78 void chipEnable(); // chip enable
displaymodule 0:3ecd25651727 79 void chipDisable(); // chip disable
displaymodule 0:3ecd25651727 80
displaymodule 0:3ecd25651727 81 // BitBangedSPI _spi;
displaymodule 0:3ecd25651727 82 SPI _spi;
displaymodule 0:3ecd25651727 83 DigitalOut _cs;
displaymodule 0:3ecd25651727 84 };
displaymodule 0:3ecd25651727 85
displaymodule 0:3ecd25651727 86 #endif
displaymodule 0:3ecd25651727 87