A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.

Dependencies:   FATFileSystem

Fork of EALib by EmbeddedArtists AB

Committer:
msamadani
Date:
Mon May 22 19:58:24 2017 +0000
Revision:
21:5ac242986175
Parent:
16:c22621bd7dea
Working version of the library.

Who changed what in which revision?

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