The wait in mci_WaitForEvent will delay all card transactions.

Dependencies:   FATFileSystem

Fork of EALib by EmbeddedArtists AB

Committer:
dreschpe
Date:
Sun Dec 15 21:58:56 2013 +0000
Revision:
9:da373a015d07
Parent:
4:b32cf4ef45c5
the wait in mci_WaitForEvent will delay all card transactions.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:0fdadbc3d852 1
embeddedartists 0:0fdadbc3d852 2 #ifndef EALCDBOARD_H
embeddedartists 0:0fdadbc3d852 3 #define EALCDBOARD_H
embeddedartists 0:0fdadbc3d852 4
embeddedartists 0:0fdadbc3d852 5 #include "LcdController.h"
embeddedartists 0:0fdadbc3d852 6
embeddedartists 0:0fdadbc3d852 7 /** An interface to Embedded Artists LCD Boards
embeddedartists 0:0fdadbc3d852 8 *
embeddedartists 0:0fdadbc3d852 9 */
embeddedartists 0:0fdadbc3d852 10 class EaLcdBoard {
embeddedartists 0:0fdadbc3d852 11 public:
embeddedartists 0:0fdadbc3d852 12
embeddedartists 0:0fdadbc3d852 13 enum Result {
embeddedartists 0:0fdadbc3d852 14 Ok = 0,
embeddedartists 0:0fdadbc3d852 15 InvalidCommandString,
embeddedartists 0:0fdadbc3d852 16 InvalidArgument,
embeddedartists 0:0fdadbc3d852 17 InvalidStorage,
embeddedartists 0:0fdadbc3d852 18 BufferTooSmall,
embeddedartists 0:0fdadbc3d852 19 VersionNotSupported,
embeddedartists 0:0fdadbc3d852 20 LcdAccessError
embeddedartists 0:0fdadbc3d852 21 };
embeddedartists 0:0fdadbc3d852 22
embeddedartists 0:0fdadbc3d852 23 enum Constants {
embeddedartists 0:0fdadbc3d852 24 NameBufferSize = 30
embeddedartists 0:0fdadbc3d852 25 };
embeddedartists 0:0fdadbc3d852 26
embeddedartists 4:b32cf4ef45c5 27 enum TouchPanelId {
embeddedartists 4:b32cf4ef45c5 28 // must be first
embeddedartists 4:b32cf4ef45c5 29 TouchPanelInvalidFirst = 0x80,
embeddedartists 4:b32cf4ef45c5 30
embeddedartists 4:b32cf4ef45c5 31 // Texas Instruments Touch Screen Controller (TSC2046).
embeddedartists 4:b32cf4ef45c5 32 TouchPanel_TSC2046,
embeddedartists 4:b32cf4ef45c5 33 // Microchip Touch Screen Controller (AR1021).
embeddedartists 4:b32cf4ef45c5 34 TouchPanel_AR1021,
embeddedartists 4:b32cf4ef45c5 35
embeddedartists 4:b32cf4ef45c5 36 // Must be after last panel ID
embeddedartists 4:b32cf4ef45c5 37 TouchPanelInvalidLast,
embeddedartists 4:b32cf4ef45c5 38 // unknown touch panel
embeddedartists 4:b32cf4ef45c5 39 TouchPanelUnknown = 0xFF
embeddedartists 4:b32cf4ef45c5 40
embeddedartists 4:b32cf4ef45c5 41 };
embeddedartists 4:b32cf4ef45c5 42
embeddedartists 4:b32cf4ef45c5 43 typedef struct {
embeddedartists 4:b32cf4ef45c5 44 uint8_t swap; // set to 1 if x and y should be swapped
embeddedartists 4:b32cf4ef45c5 45 uint32_t xres; // x resistance
embeddedartists 4:b32cf4ef45c5 46 uint32_t yres; // y resistance
embeddedartists 4:b32cf4ef45c5 47 TouchPanelId panelId; // identifies touch panel
embeddedartists 4:b32cf4ef45c5 48
embeddedartists 4:b32cf4ef45c5 49 } TouchParams_t;
embeddedartists 4:b32cf4ef45c5 50
embeddedartists 0:0fdadbc3d852 51 /** Create an interface to an Embedded Artists LCD Board
embeddedartists 0:0fdadbc3d852 52 *
embeddedartists 0:0fdadbc3d852 53 * @param sda I2C data line pin
embeddedartists 0:0fdadbc3d852 54 * @param scl I2C clock line pin
embeddedartists 0:0fdadbc3d852 55 */
embeddedartists 0:0fdadbc3d852 56 EaLcdBoard(PinName sda, PinName scl);
embeddedartists 0:0fdadbc3d852 57
embeddedartists 0:0fdadbc3d852 58 /** Open the interface and start initialization.
embeddedartists 0:0fdadbc3d852 59 *
embeddedartists 0:0fdadbc3d852 60 * @param cfg initialize with a given LCD configuration. If this argument is
embeddedartists 0:0fdadbc3d852 61 * NULL the LCD configuration will be retrieved from persistent
embeddedartists 0:0fdadbc3d852 62 * storage on the LCD Board.
embeddedartists 0:0fdadbc3d852 63 * @param initSeq the initialization string. If this argument is NULL the
embeddedartists 0:0fdadbc3d852 64 * initialization string will be retrieved from persistent
embeddedartists 0:0fdadbc3d852 65 * storage on the LCD Board.
embeddedartists 0:0fdadbc3d852 66 *
embeddedartists 0:0fdadbc3d852 67 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 68 */
embeddedartists 0:0fdadbc3d852 69 Result open(LcdController::Config* cfg, char* initSeq);
embeddedartists 0:0fdadbc3d852 70
embeddedartists 0:0fdadbc3d852 71 /** Close the interface
embeddedartists 0:0fdadbc3d852 72 *
embeddedartists 0:0fdadbc3d852 73 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 74 */
embeddedartists 0:0fdadbc3d852 75 Result close();
embeddedartists 0:0fdadbc3d852 76
embeddedartists 0:0fdadbc3d852 77 /** Set and activate the address of the frame buffer to use.
embeddedartists 0:0fdadbc3d852 78 *
embeddedartists 0:0fdadbc3d852 79 * It is the content of the frame buffer that is shown on the
embeddedartists 0:0fdadbc3d852 80 * display. All the drawing on the frame buffer can be done
embeddedartists 0:0fdadbc3d852 81 * 'offline' and whenever it should be shown this function
embeddedartists 0:0fdadbc3d852 82 * can be called with the address of the offline frame buffer.
embeddedartists 0:0fdadbc3d852 83 *
embeddedartists 0:0fdadbc3d852 84 * @param address Memory address of the frame buffer
embeddedartists 0:0fdadbc3d852 85 *
embeddedartists 0:0fdadbc3d852 86 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 87 */
embeddedartists 0:0fdadbc3d852 88 Result setFrameBuffer(uint32_t address);
embeddedartists 0:0fdadbc3d852 89
embeddedartists 0:0fdadbc3d852 90 /** Get the LCD configuration stored in persistent storage on the LCD Board
embeddedartists 0:0fdadbc3d852 91 *
embeddedartists 0:0fdadbc3d852 92 * @param cfg pointer to a configuration object. Parameters are copied to
embeddedartists 0:0fdadbc3d852 93 * this object.
embeddedartists 0:0fdadbc3d852 94 *
embeddedartists 0:0fdadbc3d852 95 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 96 */
embeddedartists 0:0fdadbc3d852 97 Result getLcdConfig(LcdController::Config* cfg);
embeddedartists 0:0fdadbc3d852 98
embeddedartists 0:0fdadbc3d852 99 /** Get the display name stored in persistent storage on the LCD Board
embeddedartists 0:0fdadbc3d852 100 *
embeddedartists 0:0fdadbc3d852 101 * @param buf buffer to which the name will be copied
embeddedartists 0:0fdadbc3d852 102 * @param len size of the buffer in bytes
embeddedartists 0:0fdadbc3d852 103 *
embeddedartists 0:0fdadbc3d852 104 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 105 */
embeddedartists 0:0fdadbc3d852 106 Result getDisplayName(char* buf, int len);
embeddedartists 0:0fdadbc3d852 107
embeddedartists 0:0fdadbc3d852 108 /** Get the display manufacturer stored in persistent storage on the
embeddedartists 0:0fdadbc3d852 109 * LCD Board
embeddedartists 0:0fdadbc3d852 110 *
embeddedartists 0:0fdadbc3d852 111 * @param buf buffer to which the name will be copied
embeddedartists 0:0fdadbc3d852 112 * @param len size of the buffer in bytes
embeddedartists 0:0fdadbc3d852 113 *
embeddedartists 0:0fdadbc3d852 114 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 115 */
embeddedartists 0:0fdadbc3d852 116 Result getDisplayMfg(char* buf, int len);
embeddedartists 0:0fdadbc3d852 117
embeddedartists 0:0fdadbc3d852 118 /** Get the initialization sequence stored in persistent storage on the
embeddedartists 0:0fdadbc3d852 119 * LCD Board
embeddedartists 0:0fdadbc3d852 120 *
embeddedartists 0:0fdadbc3d852 121 * @param buf buffer to which the string will be copied
embeddedartists 0:0fdadbc3d852 122 * @param len size of the buffer in bytes
embeddedartists 0:0fdadbc3d852 123 *
embeddedartists 0:0fdadbc3d852 124 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 125 */
embeddedartists 0:0fdadbc3d852 126 Result getInitSeq(char* buf, int len);
embeddedartists 0:0fdadbc3d852 127
embeddedartists 0:0fdadbc3d852 128 /** Get the power down sequence stored in persistent storage on the
embeddedartists 0:0fdadbc3d852 129 * LCD Board
embeddedartists 0:0fdadbc3d852 130 *
embeddedartists 0:0fdadbc3d852 131 * @param buf buffer to which the string will be copied
embeddedartists 0:0fdadbc3d852 132 * @param len size of the buffer in bytes
embeddedartists 0:0fdadbc3d852 133 *
embeddedartists 0:0fdadbc3d852 134 * @returns the result of the operation
embeddedartists 0:0fdadbc3d852 135 */
embeddedartists 0:0fdadbc3d852 136 Result getPowerDownSeq(char* buf, int len);
embeddedartists 0:0fdadbc3d852 137
embeddedartists 4:b32cf4ef45c5 138 /**
embeddedartists 4:b32cf4ef45c5 139 * Get the touch panel parameters stored in persistent storage
embeddedartists 4:b32cf4ef45c5 140 *
embeddedartists 4:b32cf4ef45c5 141 * @param params pointer to a configuration object. Parameters are copied to
embeddedartists 4:b32cf4ef45c5 142 * this object.
embeddedartists 4:b32cf4ef45c5 143 *
embeddedartists 4:b32cf4ef45c5 144 * @returns the result of the operation
embeddedartists 4:b32cf4ef45c5 145 */
embeddedartists 4:b32cf4ef45c5 146 Result getTouchParameters(TouchParams_t* params);
embeddedartists 4:b32cf4ef45c5 147
embeddedartists 4:b32cf4ef45c5 148 /**
embeddedartists 4:b32cf4ef45c5 149 * Write display parameters to the EEPROM. Please use this function with
embeddedartists 4:b32cf4ef45c5 150 * care since original parameters will be overwritten and cannot be restored.
embeddedartists 4:b32cf4ef45c5 151 *
embeddedartists 4:b32cf4ef45c5 152 * @param lcdName the name of the display
embeddedartists 4:b32cf4ef45c5 153 * @param lcdMfg the display manufacturer
embeddedartists 4:b32cf4ef45c5 154 * @param cfg the display configuration parameters
embeddedartists 4:b32cf4ef45c5 155 * @param initSeqStr the initialization sequence string
embeddedartists 4:b32cf4ef45c5 156 * @param pdSeqStr the power down sequence string
embeddedartists 4:b32cf4ef45c5 157 * @param touch touch panel parameters
embeddedartists 4:b32cf4ef45c5 158 */
embeddedartists 4:b32cf4ef45c5 159 Result storeParameters(
embeddedartists 4:b32cf4ef45c5 160 const char* lcdName,
embeddedartists 4:b32cf4ef45c5 161 const char* lcdMfg,
embeddedartists 4:b32cf4ef45c5 162 LcdController::Config* cfg,
embeddedartists 4:b32cf4ef45c5 163 const char* initSeqStr,
embeddedartists 4:b32cf4ef45c5 164 const char* pdSeqStr,
embeddedartists 4:b32cf4ef45c5 165 TouchParams_t* touch,
embeddedartists 4:b32cf4ef45c5 166 bool controlWp = false);
embeddedartists 4:b32cf4ef45c5 167
embeddedartists 0:0fdadbc3d852 168
embeddedartists 0:0fdadbc3d852 169 private:
embeddedartists 0:0fdadbc3d852 170
embeddedartists 0:0fdadbc3d852 171 typedef struct {
embeddedartists 0:0fdadbc3d852 172 uint32_t magic; // magic number
embeddedartists 0:0fdadbc3d852 173 uint8_t lcd_name[NameBufferSize]; // LCD name
embeddedartists 0:0fdadbc3d852 174 uint8_t lcd_mfg[NameBufferSize]; // manufacturer name
embeddedartists 0:0fdadbc3d852 175 uint16_t lcdParamOff; // offset to LCD parameters
embeddedartists 0:0fdadbc3d852 176 uint16_t initOff; // offset to init sequence string
embeddedartists 0:0fdadbc3d852 177 uint16_t pdOff; // offset to power down sequence string
embeddedartists 0:0fdadbc3d852 178 uint16_t tsOff; // offset to touch parameters
embeddedartists 0:0fdadbc3d852 179 uint16_t end; // end offset
embeddedartists 0:0fdadbc3d852 180 } store_t;
embeddedartists 0:0fdadbc3d852 181
embeddedartists 0:0fdadbc3d852 182 Result getStore(store_t* store);
embeddedartists 0:0fdadbc3d852 183
embeddedartists 0:0fdadbc3d852 184 int eepromRead(uint8_t* buf, uint16_t offset, uint16_t len);
embeddedartists 0:0fdadbc3d852 185 int eepromWrite(uint8_t* buf, uint16_t offset, uint16_t len);
embeddedartists 0:0fdadbc3d852 186
embeddedartists 0:0fdadbc3d852 187 Result parseInitString(char* str, LcdController::Config* cfg);
embeddedartists 0:0fdadbc3d852 188 Result checkVersion(char* v, uint32_t len);
embeddedartists 0:0fdadbc3d852 189 Result execDelay(char* del, uint32_t len);
embeddedartists 0:0fdadbc3d852 190 Result execSeqCtrl(char* cmd, uint32_t len);
embeddedartists 4:b32cf4ef45c5 191 Result execPinSet(char* cmd, uint32_t len);
embeddedartists 0:0fdadbc3d852 192
embeddedartists 0:0fdadbc3d852 193 void setLsStates(uint16_t states, uint8_t* ls, uint8_t mode);
embeddedartists 0:0fdadbc3d852 194 void setLeds(void);
embeddedartists 0:0fdadbc3d852 195 void pca9532_setLeds (uint16_t ledOnMask, uint16_t ledOffMask);
embeddedartists 0:0fdadbc3d852 196 void pca9532_setBlink0Period(uint8_t period);
embeddedartists 0:0fdadbc3d852 197 void pca9532_setBlink0Duty(uint8_t duty);
embeddedartists 0:0fdadbc3d852 198 void pca9532_setBlink0Leds(uint16_t ledMask);
embeddedartists 0:0fdadbc3d852 199
embeddedartists 4:b32cf4ef45c5 200 void setWriteProtect(bool enable);
embeddedartists 0:0fdadbc3d852 201 void set3V3Signal(bool enabled);
embeddedartists 0:0fdadbc3d852 202 void set5VSignal(bool enabled);
embeddedartists 0:0fdadbc3d852 203 void setDisplayEnableSignal(bool enabled);
embeddedartists 0:0fdadbc3d852 204 void setBacklightContrast(uint32_t value);
embeddedartists 0:0fdadbc3d852 205
embeddedartists 0:0fdadbc3d852 206 I2C _i2c;
embeddedartists 0:0fdadbc3d852 207 LcdController::Config _cfg;
embeddedartists 0:0fdadbc3d852 208 LcdController lcdCtrl;
embeddedartists 0:0fdadbc3d852 209 uint16_t _blink0Shadow;
embeddedartists 0:0fdadbc3d852 210 uint16_t _blink1Shadow;
embeddedartists 0:0fdadbc3d852 211 uint16_t _ledStateShadow;
embeddedartists 0:0fdadbc3d852 212 bool _lcdPwrOn;
embeddedartists 0:0fdadbc3d852 213 };
embeddedartists 0:0fdadbc3d852 214
embeddedartists 0:0fdadbc3d852 215 #endif