Shows how to use a display and the onboard SD Card. Requires a display module with an adapter

Dependencies:   DmTftLibrary SDFileSystem mbed

Committer:
displaymodule
Date:
Mon Sep 01 11:06:18 2014 +0000
Revision:
6:592bba211e38
Parent:
0:ee27d4c12433
Removed dependency on mbed-src for LPC1549

Who changed what in which revision?

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