A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Fork of EALib by
EaLcdBoard.cpp@0:0fdadbc3d852, 2013-09-26 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Sep 26 06:37:02 2013 +0000
- Revision:
- 0:0fdadbc3d852
- Child:
- 4:b32cf4ef45c5
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:0fdadbc3d852 | 1 | |
embeddedartists | 0:0fdadbc3d852 | 2 | #include "mbed.h" |
embeddedartists | 0:0fdadbc3d852 | 3 | #include "EaLcdBoard.h" |
embeddedartists | 0:0fdadbc3d852 | 4 | |
embeddedartists | 0:0fdadbc3d852 | 5 | #define LCDB_MAGIC 0xEA01CDAE |
embeddedartists | 0:0fdadbc3d852 | 6 | |
embeddedartists | 0:0fdadbc3d852 | 7 | |
embeddedartists | 0:0fdadbc3d852 | 8 | #define LCDB_PCA9532_I2C_ADDR (0x64 << 1) |
embeddedartists | 0:0fdadbc3d852 | 9 | |
embeddedartists | 0:0fdadbc3d852 | 10 | /* PCA9532 registers*/ |
embeddedartists | 0:0fdadbc3d852 | 11 | #define LCDB_PCA9532_INPUT0 0x00 |
embeddedartists | 0:0fdadbc3d852 | 12 | #define LCDB_PCA9532_INPUT1 0x01 |
embeddedartists | 0:0fdadbc3d852 | 13 | #define LCDB_PCA9532_PSC0 0x02 |
embeddedartists | 0:0fdadbc3d852 | 14 | #define LCDB_PCA9532_PWM0 0x03 |
embeddedartists | 0:0fdadbc3d852 | 15 | #define LCDB_PCA9532_PSC1 0x04 |
embeddedartists | 0:0fdadbc3d852 | 16 | #define LCDB_PCA9532_PWM1 0x05 |
embeddedartists | 0:0fdadbc3d852 | 17 | #define LCDB_PCA9532_LS0 0x06 |
embeddedartists | 0:0fdadbc3d852 | 18 | #define LCDB_PCA9532_LS1 0x07 |
embeddedartists | 0:0fdadbc3d852 | 19 | #define LCDB_PCA9532_LS2 0x08 |
embeddedartists | 0:0fdadbc3d852 | 20 | #define LCDB_PCA9532_LS3 0x09 |
embeddedartists | 0:0fdadbc3d852 | 21 | #define LCDB_PCA9532_AUTO_INC 0x10 |
embeddedartists | 0:0fdadbc3d852 | 22 | |
embeddedartists | 0:0fdadbc3d852 | 23 | #define LCDB_LS_MODE_ON 0x01 |
embeddedartists | 0:0fdadbc3d852 | 24 | #define LCDB_LS_MODE_BLINK0 0x02 |
embeddedartists | 0:0fdadbc3d852 | 25 | #define LCDB_LS_MODE_BLINK1 0x03 |
embeddedartists | 0:0fdadbc3d852 | 26 | |
embeddedartists | 0:0fdadbc3d852 | 27 | #define LCDB_CTRL_3V3 0x0001 |
embeddedartists | 0:0fdadbc3d852 | 28 | #define LCDB_CTRL_5V 0x0002 |
embeddedartists | 0:0fdadbc3d852 | 29 | #define LCDB_CTRL_DISP_EN 0x0010 |
embeddedartists | 0:0fdadbc3d852 | 30 | #define LCDB_CTRL_BL_EN 0x0080 |
embeddedartists | 0:0fdadbc3d852 | 31 | #define LCDB_CTRL_BL_C 0x0100 |
embeddedartists | 0:0fdadbc3d852 | 32 | #define LCDB_EEPROM_WP 0x8000 |
embeddedartists | 0:0fdadbc3d852 | 33 | |
embeddedartists | 0:0fdadbc3d852 | 34 | #define LCDB_EEPROM_I2C_ADDR (0x56 << 1) |
embeddedartists | 0:0fdadbc3d852 | 35 | #define LCDB_EEPROM_PAGE_SIZE 32 |
embeddedartists | 0:0fdadbc3d852 | 36 | #define LCDB_EEPROM_TOTAL_SIZE 8192 |
embeddedartists | 0:0fdadbc3d852 | 37 | |
embeddedartists | 0:0fdadbc3d852 | 38 | /* |
embeddedartists | 0:0fdadbc3d852 | 39 | * Set which sequence string version that is supported |
embeddedartists | 0:0fdadbc3d852 | 40 | */ |
embeddedartists | 0:0fdadbc3d852 | 41 | #define LCDB_SEQ_VER 1 |
embeddedartists | 0:0fdadbc3d852 | 42 | |
embeddedartists | 0:0fdadbc3d852 | 43 | #ifndef MIN |
embeddedartists | 0:0fdadbc3d852 | 44 | #define MIN(x, y) (((x)<(y))?(x):(y)) |
embeddedartists | 0:0fdadbc3d852 | 45 | #endif |
embeddedartists | 0:0fdadbc3d852 | 46 | |
embeddedartists | 0:0fdadbc3d852 | 47 | #define EA_LCD_TMP_BUFFER_SZ 256 |
embeddedartists | 0:0fdadbc3d852 | 48 | static char* eaLcdTmpBuffer[EA_LCD_TMP_BUFFER_SZ]; |
embeddedartists | 0:0fdadbc3d852 | 49 | |
embeddedartists | 0:0fdadbc3d852 | 50 | |
embeddedartists | 0:0fdadbc3d852 | 51 | /* Structure containing the parameters for the LCD panel as stored on LCD Board */ |
embeddedartists | 0:0fdadbc3d852 | 52 | |
embeddedartists | 0:0fdadbc3d852 | 53 | /* LCD display types */ |
embeddedartists | 0:0fdadbc3d852 | 54 | typedef enum { |
embeddedartists | 0:0fdadbc3d852 | 55 | TFT = 0, /* standard TFT */ |
embeddedartists | 0:0fdadbc3d852 | 56 | ADTFT, /* advanced TFT */ |
embeddedartists | 0:0fdadbc3d852 | 57 | HRTFT, /* highly reflective TFT */ |
embeddedartists | 0:0fdadbc3d852 | 58 | MONO_4BIT, /* 4-bit mono */ |
embeddedartists | 0:0fdadbc3d852 | 59 | MONO_8BIT, /* 8-bit mono */ |
embeddedartists | 0:0fdadbc3d852 | 60 | CSTN /* color STN */ |
embeddedartists | 0:0fdadbc3d852 | 61 | } nxp_lcd_panel_t; |
embeddedartists | 0:0fdadbc3d852 | 62 | |
embeddedartists | 0:0fdadbc3d852 | 63 | typedef struct { |
embeddedartists | 0:0fdadbc3d852 | 64 | uint8_t h_back_porch; /* Horizontal back porch in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 65 | uint8_t h_front_porch; /* Horizontal front porch in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 66 | uint8_t h_sync_pulse_width; /* HSYNC pulse width in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 67 | uint16_t pixels_per_line; /* Pixels per line (horizontal resolution) */ |
embeddedartists | 0:0fdadbc3d852 | 68 | uint8_t v_back_porch; /* Vertical back porch in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 69 | uint8_t v_front_porch; /* Vertical front porch in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 70 | uint8_t v_sync_pulse_width; /* VSYNC pulse width in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 71 | uint16_t lines_per_panel; /* Lines per panel (vertical resolution) */ |
embeddedartists | 0:0fdadbc3d852 | 72 | uint8_t invert_output_enable; /* Invert output enable, 1 = invert*/ |
embeddedartists | 0:0fdadbc3d852 | 73 | uint8_t invert_panel_clock; /* Invert panel clock, 1 = invert*/ |
embeddedartists | 0:0fdadbc3d852 | 74 | uint8_t invert_hsync; /* Invert HSYNC, 1 = invert */ |
embeddedartists | 0:0fdadbc3d852 | 75 | uint8_t invert_vsync; /* Invert VSYNC, 1 = invert */ |
embeddedartists | 0:0fdadbc3d852 | 76 | uint8_t ac_bias_frequency; /* AC bias frequency in clocks */ |
embeddedartists | 0:0fdadbc3d852 | 77 | uint8_t bits_per_pixel; /* Maximum bits per pixel the display supports */ |
embeddedartists | 0:0fdadbc3d852 | 78 | uint32_t optimal_clock; /* Optimal clock rate (Hz) */ |
embeddedartists | 0:0fdadbc3d852 | 79 | nxp_lcd_panel_t lcd_panel_type; /* LCD panel type */ |
embeddedartists | 0:0fdadbc3d852 | 80 | uint8_t dual_panel; /* Dual panel, 1 = dual panel display */ |
embeddedartists | 0:0fdadbc3d852 | 81 | } nxp_lcd_param_t; |
embeddedartists | 0:0fdadbc3d852 | 82 | |
embeddedartists | 0:0fdadbc3d852 | 83 | static uint32_t str_to_uint(char* str, uint32_t len); |
embeddedartists | 0:0fdadbc3d852 | 84 | |
embeddedartists | 0:0fdadbc3d852 | 85 | EaLcdBoard::EaLcdBoard(PinName sda, PinName scl) : _i2c(sda, scl) { |
embeddedartists | 0:0fdadbc3d852 | 86 | _blink0Shadow = 0; |
embeddedartists | 0:0fdadbc3d852 | 87 | _blink1Shadow = 0; |
embeddedartists | 0:0fdadbc3d852 | 88 | _ledStateShadow = 0; |
embeddedartists | 0:0fdadbc3d852 | 89 | _lcdPwrOn = false; |
embeddedartists | 0:0fdadbc3d852 | 90 | } |
embeddedartists | 0:0fdadbc3d852 | 91 | |
embeddedartists | 0:0fdadbc3d852 | 92 | EaLcdBoard::Result EaLcdBoard::open(LcdController::Config* cfg, char* initSeq) { |
embeddedartists | 0:0fdadbc3d852 | 93 | |
embeddedartists | 0:0fdadbc3d852 | 94 | EaLcdBoard::Result result = Ok; |
embeddedartists | 0:0fdadbc3d852 | 95 | |
embeddedartists | 0:0fdadbc3d852 | 96 | // load LCD configuration from storage |
embeddedartists | 0:0fdadbc3d852 | 97 | if (cfg == NULL) { |
embeddedartists | 0:0fdadbc3d852 | 98 | result = getLcdConfig(&_cfg); |
embeddedartists | 0:0fdadbc3d852 | 99 | cfg = &_cfg; |
embeddedartists | 0:0fdadbc3d852 | 100 | } |
embeddedartists | 0:0fdadbc3d852 | 101 | |
embeddedartists | 0:0fdadbc3d852 | 102 | // load init sequence from storage |
embeddedartists | 0:0fdadbc3d852 | 103 | if (result == Ok && initSeq == NULL) { |
embeddedartists | 0:0fdadbc3d852 | 104 | result = getInitSeq((char*)eaLcdTmpBuffer, EA_LCD_TMP_BUFFER_SZ); |
embeddedartists | 0:0fdadbc3d852 | 105 | initSeq = (char*)eaLcdTmpBuffer; |
embeddedartists | 0:0fdadbc3d852 | 106 | } |
embeddedartists | 0:0fdadbc3d852 | 107 | |
embeddedartists | 0:0fdadbc3d852 | 108 | if (result != Ok) { |
embeddedartists | 0:0fdadbc3d852 | 109 | return result; |
embeddedartists | 0:0fdadbc3d852 | 110 | } |
embeddedartists | 0:0fdadbc3d852 | 111 | |
embeddedartists | 0:0fdadbc3d852 | 112 | return parseInitString(initSeq, cfg); |
embeddedartists | 0:0fdadbc3d852 | 113 | } |
embeddedartists | 0:0fdadbc3d852 | 114 | |
embeddedartists | 0:0fdadbc3d852 | 115 | EaLcdBoard::Result EaLcdBoard::close() { |
embeddedartists | 0:0fdadbc3d852 | 116 | int r = 0; |
embeddedartists | 0:0fdadbc3d852 | 117 | |
embeddedartists | 0:0fdadbc3d852 | 118 | do { |
embeddedartists | 0:0fdadbc3d852 | 119 | r = lcdCtrl.setPower(false); |
embeddedartists | 0:0fdadbc3d852 | 120 | if (r != 0) break; |
embeddedartists | 0:0fdadbc3d852 | 121 | |
embeddedartists | 0:0fdadbc3d852 | 122 | _lcdPwrOn = false; |
embeddedartists | 0:0fdadbc3d852 | 123 | |
embeddedartists | 0:0fdadbc3d852 | 124 | r = lcdCtrl.close(); |
embeddedartists | 0:0fdadbc3d852 | 125 | } while(0); |
embeddedartists | 0:0fdadbc3d852 | 126 | |
embeddedartists | 0:0fdadbc3d852 | 127 | if (r != 0) { |
embeddedartists | 0:0fdadbc3d852 | 128 | return LcdAccessError; |
embeddedartists | 0:0fdadbc3d852 | 129 | } |
embeddedartists | 0:0fdadbc3d852 | 130 | |
embeddedartists | 0:0fdadbc3d852 | 131 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 132 | } |
embeddedartists | 0:0fdadbc3d852 | 133 | |
embeddedartists | 0:0fdadbc3d852 | 134 | EaLcdBoard::Result EaLcdBoard::setFrameBuffer(uint32_t address) { |
embeddedartists | 0:0fdadbc3d852 | 135 | int r = 0; |
embeddedartists | 0:0fdadbc3d852 | 136 | |
embeddedartists | 0:0fdadbc3d852 | 137 | do { |
embeddedartists | 0:0fdadbc3d852 | 138 | |
embeddedartists | 0:0fdadbc3d852 | 139 | // begin by powering on the display |
embeddedartists | 0:0fdadbc3d852 | 140 | if (!_lcdPwrOn) { |
embeddedartists | 0:0fdadbc3d852 | 141 | r = lcdCtrl.setPower(true); |
embeddedartists | 0:0fdadbc3d852 | 142 | if (r != 0) break; |
embeddedartists | 0:0fdadbc3d852 | 143 | |
embeddedartists | 0:0fdadbc3d852 | 144 | _lcdPwrOn = true; |
embeddedartists | 0:0fdadbc3d852 | 145 | } |
embeddedartists | 0:0fdadbc3d852 | 146 | |
embeddedartists | 0:0fdadbc3d852 | 147 | // activate specified frame buffer |
embeddedartists | 0:0fdadbc3d852 | 148 | r = lcdCtrl.setFrameBuffer(address); |
embeddedartists | 0:0fdadbc3d852 | 149 | if (r != 0) break; |
embeddedartists | 0:0fdadbc3d852 | 150 | |
embeddedartists | 0:0fdadbc3d852 | 151 | } while(0); |
embeddedartists | 0:0fdadbc3d852 | 152 | |
embeddedartists | 0:0fdadbc3d852 | 153 | if (r != 0) { |
embeddedartists | 0:0fdadbc3d852 | 154 | return LcdAccessError; |
embeddedartists | 0:0fdadbc3d852 | 155 | } |
embeddedartists | 0:0fdadbc3d852 | 156 | |
embeddedartists | 0:0fdadbc3d852 | 157 | |
embeddedartists | 0:0fdadbc3d852 | 158 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 159 | } |
embeddedartists | 0:0fdadbc3d852 | 160 | |
embeddedartists | 0:0fdadbc3d852 | 161 | EaLcdBoard::Result EaLcdBoard::getLcdConfig(LcdController::Config* cfg) { |
embeddedartists | 0:0fdadbc3d852 | 162 | store_t h; |
embeddedartists | 0:0fdadbc3d852 | 163 | |
embeddedartists | 0:0fdadbc3d852 | 164 | nxp_lcd_param_t lcdParam; |
embeddedartists | 0:0fdadbc3d852 | 165 | |
embeddedartists | 0:0fdadbc3d852 | 166 | getStore(&h); |
embeddedartists | 0:0fdadbc3d852 | 167 | |
embeddedartists | 0:0fdadbc3d852 | 168 | if (h.magic != LCDB_MAGIC) { |
embeddedartists | 0:0fdadbc3d852 | 169 | return InvalidStorage; |
embeddedartists | 0:0fdadbc3d852 | 170 | } |
embeddedartists | 0:0fdadbc3d852 | 171 | |
embeddedartists | 0:0fdadbc3d852 | 172 | eepromRead((uint8_t*)&lcdParam, h.lcdParamOff, |
embeddedartists | 0:0fdadbc3d852 | 173 | (h.initOff-h.lcdParamOff)); |
embeddedartists | 0:0fdadbc3d852 | 174 | |
embeddedartists | 0:0fdadbc3d852 | 175 | cfg->horizontalBackPorch = lcdParam.h_back_porch; |
embeddedartists | 0:0fdadbc3d852 | 176 | cfg->horizontalFrontPorch = lcdParam.h_front_porch; |
embeddedartists | 0:0fdadbc3d852 | 177 | cfg->hsync = lcdParam.h_sync_pulse_width; |
embeddedartists | 0:0fdadbc3d852 | 178 | cfg->width = lcdParam.pixels_per_line; |
embeddedartists | 0:0fdadbc3d852 | 179 | cfg->verticalBackPorch = lcdParam.v_back_porch; |
embeddedartists | 0:0fdadbc3d852 | 180 | cfg->verticalFrontPorch = lcdParam.v_front_porch; |
embeddedartists | 0:0fdadbc3d852 | 181 | cfg->vsync = lcdParam.v_sync_pulse_width; |
embeddedartists | 0:0fdadbc3d852 | 182 | cfg->height = lcdParam.lines_per_panel; |
embeddedartists | 0:0fdadbc3d852 | 183 | cfg->invertOutputEnable = (lcdParam.invert_output_enable == 1); |
embeddedartists | 0:0fdadbc3d852 | 184 | cfg->invertPanelClock = (lcdParam.invert_panel_clock == 1); |
embeddedartists | 0:0fdadbc3d852 | 185 | cfg->invertHsync = (lcdParam.invert_hsync == 1); |
embeddedartists | 0:0fdadbc3d852 | 186 | cfg->invertVsync = (lcdParam.invert_vsync == 1); |
embeddedartists | 0:0fdadbc3d852 | 187 | cfg->acBias = lcdParam.ac_bias_frequency; |
embeddedartists | 0:0fdadbc3d852 | 188 | cfg->bpp = LcdController::Bpp_16_565; |
embeddedartists | 0:0fdadbc3d852 | 189 | cfg->optimalClock = lcdParam.optimal_clock; |
embeddedartists | 0:0fdadbc3d852 | 190 | cfg->panelType = (LcdController::LcdPanel)lcdParam.lcd_panel_type; |
embeddedartists | 0:0fdadbc3d852 | 191 | cfg->dualPanel = (lcdParam.dual_panel == 1); |
embeddedartists | 0:0fdadbc3d852 | 192 | |
embeddedartists | 0:0fdadbc3d852 | 193 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 194 | } |
embeddedartists | 0:0fdadbc3d852 | 195 | |
embeddedartists | 0:0fdadbc3d852 | 196 | EaLcdBoard::Result EaLcdBoard::getDisplayName(char* buf, int len) { |
embeddedartists | 0:0fdadbc3d852 | 197 | store_t h; |
embeddedartists | 0:0fdadbc3d852 | 198 | |
embeddedartists | 0:0fdadbc3d852 | 199 | getStore(&h); |
embeddedartists | 0:0fdadbc3d852 | 200 | |
embeddedartists | 0:0fdadbc3d852 | 201 | if (h.magic != LCDB_MAGIC) { |
embeddedartists | 0:0fdadbc3d852 | 202 | return InvalidStorage; |
embeddedartists | 0:0fdadbc3d852 | 203 | } |
embeddedartists | 0:0fdadbc3d852 | 204 | |
embeddedartists | 0:0fdadbc3d852 | 205 | if (len < NameBufferSize) { |
embeddedartists | 0:0fdadbc3d852 | 206 | return BufferTooSmall; |
embeddedartists | 0:0fdadbc3d852 | 207 | } |
embeddedartists | 0:0fdadbc3d852 | 208 | |
embeddedartists | 0:0fdadbc3d852 | 209 | strncpy(buf, (char*)h.lcd_name, NameBufferSize); |
embeddedartists | 0:0fdadbc3d852 | 210 | |
embeddedartists | 0:0fdadbc3d852 | 211 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 212 | } |
embeddedartists | 0:0fdadbc3d852 | 213 | |
embeddedartists | 0:0fdadbc3d852 | 214 | EaLcdBoard::Result EaLcdBoard::getDisplayMfg(char* buf, int len) { |
embeddedartists | 0:0fdadbc3d852 | 215 | store_t h; |
embeddedartists | 0:0fdadbc3d852 | 216 | |
embeddedartists | 0:0fdadbc3d852 | 217 | getStore(&h); |
embeddedartists | 0:0fdadbc3d852 | 218 | |
embeddedartists | 0:0fdadbc3d852 | 219 | if (h.magic != LCDB_MAGIC) { |
embeddedartists | 0:0fdadbc3d852 | 220 | return InvalidStorage; |
embeddedartists | 0:0fdadbc3d852 | 221 | } |
embeddedartists | 0:0fdadbc3d852 | 222 | |
embeddedartists | 0:0fdadbc3d852 | 223 | if (len < NameBufferSize) { |
embeddedartists | 0:0fdadbc3d852 | 224 | return BufferTooSmall; |
embeddedartists | 0:0fdadbc3d852 | 225 | } |
embeddedartists | 0:0fdadbc3d852 | 226 | |
embeddedartists | 0:0fdadbc3d852 | 227 | strncpy(buf, (char*)h.lcd_mfg, NameBufferSize); |
embeddedartists | 0:0fdadbc3d852 | 228 | |
embeddedartists | 0:0fdadbc3d852 | 229 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 230 | } |
embeddedartists | 0:0fdadbc3d852 | 231 | |
embeddedartists | 0:0fdadbc3d852 | 232 | EaLcdBoard::Result EaLcdBoard::getInitSeq(char* buf, int len) { |
embeddedartists | 0:0fdadbc3d852 | 233 | store_t h; |
embeddedartists | 0:0fdadbc3d852 | 234 | |
embeddedartists | 0:0fdadbc3d852 | 235 | getStore(&h); |
embeddedartists | 0:0fdadbc3d852 | 236 | |
embeddedartists | 0:0fdadbc3d852 | 237 | if (h.magic != LCDB_MAGIC) { |
embeddedartists | 0:0fdadbc3d852 | 238 | return InvalidStorage; |
embeddedartists | 0:0fdadbc3d852 | 239 | } |
embeddedartists | 0:0fdadbc3d852 | 240 | |
embeddedartists | 0:0fdadbc3d852 | 241 | if ((h.pdOff-h.initOff) > len) { |
embeddedartists | 0:0fdadbc3d852 | 242 | return BufferTooSmall; |
embeddedartists | 0:0fdadbc3d852 | 243 | } |
embeddedartists | 0:0fdadbc3d852 | 244 | |
embeddedartists | 0:0fdadbc3d852 | 245 | eepromRead((uint8_t*)buf, h.initOff, |
embeddedartists | 0:0fdadbc3d852 | 246 | (h.pdOff-h.initOff)); |
embeddedartists | 0:0fdadbc3d852 | 247 | |
embeddedartists | 0:0fdadbc3d852 | 248 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 249 | } |
embeddedartists | 0:0fdadbc3d852 | 250 | |
embeddedartists | 0:0fdadbc3d852 | 251 | EaLcdBoard::Result EaLcdBoard::getPowerDownSeq(char* buf, int len) { |
embeddedartists | 0:0fdadbc3d852 | 252 | store_t h; |
embeddedartists | 0:0fdadbc3d852 | 253 | |
embeddedartists | 0:0fdadbc3d852 | 254 | getStore(&h); |
embeddedartists | 0:0fdadbc3d852 | 255 | |
embeddedartists | 0:0fdadbc3d852 | 256 | if (h.magic != LCDB_MAGIC) { |
embeddedartists | 0:0fdadbc3d852 | 257 | return InvalidStorage; |
embeddedartists | 0:0fdadbc3d852 | 258 | } |
embeddedartists | 0:0fdadbc3d852 | 259 | |
embeddedartists | 0:0fdadbc3d852 | 260 | if ((h.tsOff-h.pdOff) > len) { |
embeddedartists | 0:0fdadbc3d852 | 261 | return BufferTooSmall; |
embeddedartists | 0:0fdadbc3d852 | 262 | } |
embeddedartists | 0:0fdadbc3d852 | 263 | |
embeddedartists | 0:0fdadbc3d852 | 264 | eepromRead((uint8_t*)buf, h.pdOff, |
embeddedartists | 0:0fdadbc3d852 | 265 | (h.tsOff-h.pdOff)); |
embeddedartists | 0:0fdadbc3d852 | 266 | |
embeddedartists | 0:0fdadbc3d852 | 267 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 268 | } |
embeddedartists | 0:0fdadbc3d852 | 269 | |
embeddedartists | 0:0fdadbc3d852 | 270 | EaLcdBoard::Result EaLcdBoard::getStore(store_t* store) { |
embeddedartists | 0:0fdadbc3d852 | 271 | int num = 0; |
embeddedartists | 0:0fdadbc3d852 | 272 | |
embeddedartists | 0:0fdadbc3d852 | 273 | if (store == NULL) return InvalidArgument; |
embeddedartists | 0:0fdadbc3d852 | 274 | |
embeddedartists | 0:0fdadbc3d852 | 275 | num = eepromRead((uint8_t*)store, 0, sizeof(store_t)); |
embeddedartists | 0:0fdadbc3d852 | 276 | if (num < (int)sizeof(store_t)) { |
embeddedartists | 0:0fdadbc3d852 | 277 | return InvalidStorage; |
embeddedartists | 0:0fdadbc3d852 | 278 | } |
embeddedartists | 0:0fdadbc3d852 | 279 | |
embeddedartists | 0:0fdadbc3d852 | 280 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 281 | } |
embeddedartists | 0:0fdadbc3d852 | 282 | |
embeddedartists | 0:0fdadbc3d852 | 283 | // ########################### |
embeddedartists | 0:0fdadbc3d852 | 284 | // An EEPROM is used for persistent storage |
embeddedartists | 0:0fdadbc3d852 | 285 | // ########################### |
embeddedartists | 0:0fdadbc3d852 | 286 | |
embeddedartists | 0:0fdadbc3d852 | 287 | int EaLcdBoard::eepromRead(uint8_t* buf, uint16_t offset, uint16_t len) { |
embeddedartists | 0:0fdadbc3d852 | 288 | int i = 0; |
embeddedartists | 0:0fdadbc3d852 | 289 | char off[2]; |
embeddedartists | 0:0fdadbc3d852 | 290 | |
embeddedartists | 0:0fdadbc3d852 | 291 | if (len > LCDB_EEPROM_TOTAL_SIZE || offset+len > LCDB_EEPROM_TOTAL_SIZE) { |
embeddedartists | 0:0fdadbc3d852 | 292 | return -1; |
embeddedartists | 0:0fdadbc3d852 | 293 | } |
embeddedartists | 0:0fdadbc3d852 | 294 | |
embeddedartists | 0:0fdadbc3d852 | 295 | off[0] = ((offset >> 8) & 0xff); |
embeddedartists | 0:0fdadbc3d852 | 296 | off[1] = (offset & 0xff); |
embeddedartists | 0:0fdadbc3d852 | 297 | |
embeddedartists | 0:0fdadbc3d852 | 298 | _i2c.write(LCDB_EEPROM_I2C_ADDR, (char*)off, 2); |
embeddedartists | 0:0fdadbc3d852 | 299 | for ( i = 0; i < 0x2000; i++); |
embeddedartists | 0:0fdadbc3d852 | 300 | _i2c.read(LCDB_EEPROM_I2C_ADDR, (char*)buf, len); |
embeddedartists | 0:0fdadbc3d852 | 301 | |
embeddedartists | 0:0fdadbc3d852 | 302 | return len; |
embeddedartists | 0:0fdadbc3d852 | 303 | } |
embeddedartists | 0:0fdadbc3d852 | 304 | |
embeddedartists | 0:0fdadbc3d852 | 305 | int EaLcdBoard::eepromWrite(uint8_t* buf, uint16_t offset, uint16_t len) { |
embeddedartists | 0:0fdadbc3d852 | 306 | int16_t written = 0; |
embeddedartists | 0:0fdadbc3d852 | 307 | uint16_t wLen = 0; |
embeddedartists | 0:0fdadbc3d852 | 308 | uint16_t off = offset; |
embeddedartists | 0:0fdadbc3d852 | 309 | uint8_t tmp[LCDB_EEPROM_PAGE_SIZE+2]; |
embeddedartists | 0:0fdadbc3d852 | 310 | |
embeddedartists | 0:0fdadbc3d852 | 311 | if (len > LCDB_EEPROM_TOTAL_SIZE || offset+len > LCDB_EEPROM_TOTAL_SIZE) { |
embeddedartists | 0:0fdadbc3d852 | 312 | return -1; |
embeddedartists | 0:0fdadbc3d852 | 313 | } |
embeddedartists | 0:0fdadbc3d852 | 314 | |
embeddedartists | 0:0fdadbc3d852 | 315 | wLen = LCDB_EEPROM_PAGE_SIZE - (off % LCDB_EEPROM_PAGE_SIZE); |
embeddedartists | 0:0fdadbc3d852 | 316 | wLen = MIN(wLen, len); |
embeddedartists | 0:0fdadbc3d852 | 317 | |
embeddedartists | 0:0fdadbc3d852 | 318 | while (len) { |
embeddedartists | 0:0fdadbc3d852 | 319 | tmp[0] = ((off >> 8) & 0xff); |
embeddedartists | 0:0fdadbc3d852 | 320 | tmp[1] = (off & 0xff); |
embeddedartists | 0:0fdadbc3d852 | 321 | memcpy(&tmp[2], (void*)&buf[written], wLen); |
embeddedartists | 0:0fdadbc3d852 | 322 | _i2c.write(LCDB_EEPROM_I2C_ADDR, (char*)tmp, wLen+2); |
embeddedartists | 0:0fdadbc3d852 | 323 | |
embeddedartists | 0:0fdadbc3d852 | 324 | // delay to wait for a write cycle |
embeddedartists | 0:0fdadbc3d852 | 325 | //eepromDelay(); |
embeddedartists | 0:0fdadbc3d852 | 326 | wait_ms(1); |
embeddedartists | 0:0fdadbc3d852 | 327 | |
embeddedartists | 0:0fdadbc3d852 | 328 | len -= wLen; |
embeddedartists | 0:0fdadbc3d852 | 329 | written += wLen; |
embeddedartists | 0:0fdadbc3d852 | 330 | off += wLen; |
embeddedartists | 0:0fdadbc3d852 | 331 | |
embeddedartists | 0:0fdadbc3d852 | 332 | wLen = MIN(LCDB_EEPROM_PAGE_SIZE, len); |
embeddedartists | 0:0fdadbc3d852 | 333 | } |
embeddedartists | 0:0fdadbc3d852 | 334 | |
embeddedartists | 0:0fdadbc3d852 | 335 | return written; |
embeddedartists | 0:0fdadbc3d852 | 336 | } |
embeddedartists | 0:0fdadbc3d852 | 337 | |
embeddedartists | 0:0fdadbc3d852 | 338 | // ########################### |
embeddedartists | 0:0fdadbc3d852 | 339 | // string parsing (initialization and power down strings) |
embeddedartists | 0:0fdadbc3d852 | 340 | // ########################### |
embeddedartists | 0:0fdadbc3d852 | 341 | |
embeddedartists | 0:0fdadbc3d852 | 342 | EaLcdBoard::Result EaLcdBoard::parseInitString(char* str, LcdController::Config* cfg) { |
embeddedartists | 0:0fdadbc3d852 | 343 | char* c = NULL; |
embeddedartists | 0:0fdadbc3d852 | 344 | uint32_t len = 0; |
embeddedartists | 0:0fdadbc3d852 | 345 | Result result = Ok; |
embeddedartists | 0:0fdadbc3d852 | 346 | |
embeddedartists | 0:0fdadbc3d852 | 347 | if (str == NULL) { |
embeddedartists | 0:0fdadbc3d852 | 348 | return InvalidCommandString; |
embeddedartists | 0:0fdadbc3d852 | 349 | } |
embeddedartists | 0:0fdadbc3d852 | 350 | |
embeddedartists | 0:0fdadbc3d852 | 351 | while(*str != '\0') { |
embeddedartists | 0:0fdadbc3d852 | 352 | |
embeddedartists | 0:0fdadbc3d852 | 353 | // skip whitespaces |
embeddedartists | 0:0fdadbc3d852 | 354 | while(*str == ' ') { |
embeddedartists | 0:0fdadbc3d852 | 355 | str++; |
embeddedartists | 0:0fdadbc3d852 | 356 | } |
embeddedartists | 0:0fdadbc3d852 | 357 | |
embeddedartists | 0:0fdadbc3d852 | 358 | c = str; |
embeddedartists | 0:0fdadbc3d852 | 359 | |
embeddedartists | 0:0fdadbc3d852 | 360 | // find end of command |
embeddedartists | 0:0fdadbc3d852 | 361 | while(*str != ',' && *str != '\0') { |
embeddedartists | 0:0fdadbc3d852 | 362 | str++; |
embeddedartists | 0:0fdadbc3d852 | 363 | } |
embeddedartists | 0:0fdadbc3d852 | 364 | |
embeddedartists | 0:0fdadbc3d852 | 365 | len = (str-c); |
embeddedartists | 0:0fdadbc3d852 | 366 | |
embeddedartists | 0:0fdadbc3d852 | 367 | if (*str == ',') { |
embeddedartists | 0:0fdadbc3d852 | 368 | str++; |
embeddedartists | 0:0fdadbc3d852 | 369 | } |
embeddedartists | 0:0fdadbc3d852 | 370 | |
embeddedartists | 0:0fdadbc3d852 | 371 | switch (*c++) { |
embeddedartists | 0:0fdadbc3d852 | 372 | |
embeddedartists | 0:0fdadbc3d852 | 373 | case 'v': |
embeddedartists | 0:0fdadbc3d852 | 374 | result = checkVersion(c, len-1); |
embeddedartists | 0:0fdadbc3d852 | 375 | break; |
embeddedartists | 0:0fdadbc3d852 | 376 | |
embeddedartists | 0:0fdadbc3d852 | 377 | // sequence control command (pca9532) |
embeddedartists | 0:0fdadbc3d852 | 378 | case 'c': |
embeddedartists | 0:0fdadbc3d852 | 379 | execSeqCtrl(c, len-1); |
embeddedartists | 0:0fdadbc3d852 | 380 | break; |
embeddedartists | 0:0fdadbc3d852 | 381 | |
embeddedartists | 0:0fdadbc3d852 | 382 | // delay |
embeddedartists | 0:0fdadbc3d852 | 383 | case 'd': |
embeddedartists | 0:0fdadbc3d852 | 384 | execDelay(c, len-1); |
embeddedartists | 0:0fdadbc3d852 | 385 | break; |
embeddedartists | 0:0fdadbc3d852 | 386 | |
embeddedartists | 0:0fdadbc3d852 | 387 | // open lcd (init LCD controller) |
embeddedartists | 0:0fdadbc3d852 | 388 | case 'o': |
embeddedartists | 0:0fdadbc3d852 | 389 | |
embeddedartists | 0:0fdadbc3d852 | 390 | if (cfg != NULL) { |
embeddedartists | 0:0fdadbc3d852 | 391 | |
embeddedartists | 0:0fdadbc3d852 | 392 | if (lcdCtrl.open(cfg) != 0) { |
embeddedartists | 0:0fdadbc3d852 | 393 | result = LcdAccessError; |
embeddedartists | 0:0fdadbc3d852 | 394 | } |
embeddedartists | 0:0fdadbc3d852 | 395 | } |
embeddedartists | 0:0fdadbc3d852 | 396 | |
embeddedartists | 0:0fdadbc3d852 | 397 | else { |
embeddedartists | 0:0fdadbc3d852 | 398 | result = InvalidArgument; |
embeddedartists | 0:0fdadbc3d852 | 399 | } |
embeddedartists | 0:0fdadbc3d852 | 400 | |
embeddedartists | 0:0fdadbc3d852 | 401 | break; |
embeddedartists | 0:0fdadbc3d852 | 402 | |
embeddedartists | 0:0fdadbc3d852 | 403 | } |
embeddedartists | 0:0fdadbc3d852 | 404 | |
embeddedartists | 0:0fdadbc3d852 | 405 | if (result != Ok) { |
embeddedartists | 0:0fdadbc3d852 | 406 | break; |
embeddedartists | 0:0fdadbc3d852 | 407 | } |
embeddedartists | 0:0fdadbc3d852 | 408 | |
embeddedartists | 0:0fdadbc3d852 | 409 | |
embeddedartists | 0:0fdadbc3d852 | 410 | } |
embeddedartists | 0:0fdadbc3d852 | 411 | |
embeddedartists | 0:0fdadbc3d852 | 412 | |
embeddedartists | 0:0fdadbc3d852 | 413 | return result; |
embeddedartists | 0:0fdadbc3d852 | 414 | } |
embeddedartists | 0:0fdadbc3d852 | 415 | |
embeddedartists | 0:0fdadbc3d852 | 416 | EaLcdBoard::Result EaLcdBoard::checkVersion(char* v, uint32_t len) { |
embeddedartists | 0:0fdadbc3d852 | 417 | uint32_t ver = str_to_uint(v, len); |
embeddedartists | 0:0fdadbc3d852 | 418 | |
embeddedartists | 0:0fdadbc3d852 | 419 | if (ver > LCDB_SEQ_VER) { |
embeddedartists | 0:0fdadbc3d852 | 420 | return VersionNotSupported; |
embeddedartists | 0:0fdadbc3d852 | 421 | } |
embeddedartists | 0:0fdadbc3d852 | 422 | |
embeddedartists | 0:0fdadbc3d852 | 423 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 424 | } |
embeddedartists | 0:0fdadbc3d852 | 425 | |
embeddedartists | 0:0fdadbc3d852 | 426 | EaLcdBoard::Result EaLcdBoard::execDelay(char* del, uint32_t len) { |
embeddedartists | 0:0fdadbc3d852 | 427 | wait_ms(str_to_uint(del, len)); |
embeddedartists | 0:0fdadbc3d852 | 428 | |
embeddedartists | 0:0fdadbc3d852 | 429 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 430 | } |
embeddedartists | 0:0fdadbc3d852 | 431 | |
embeddedartists | 0:0fdadbc3d852 | 432 | EaLcdBoard::Result EaLcdBoard::execSeqCtrl(char* cmd, uint32_t len) { |
embeddedartists | 0:0fdadbc3d852 | 433 | |
embeddedartists | 0:0fdadbc3d852 | 434 | switch (*cmd++) { |
embeddedartists | 0:0fdadbc3d852 | 435 | |
embeddedartists | 0:0fdadbc3d852 | 436 | // display enable |
embeddedartists | 0:0fdadbc3d852 | 437 | case 'd': |
embeddedartists | 0:0fdadbc3d852 | 438 | setDisplayEnableSignal(*cmd == '1'); |
embeddedartists | 0:0fdadbc3d852 | 439 | break; |
embeddedartists | 0:0fdadbc3d852 | 440 | |
embeddedartists | 0:0fdadbc3d852 | 441 | // backlight contrast |
embeddedartists | 0:0fdadbc3d852 | 442 | case 'c': |
embeddedartists | 0:0fdadbc3d852 | 443 | setBacklightContrast(str_to_uint(cmd, len)); |
embeddedartists | 0:0fdadbc3d852 | 444 | break; |
embeddedartists | 0:0fdadbc3d852 | 445 | |
embeddedartists | 0:0fdadbc3d852 | 446 | // 3v3 enable |
embeddedartists | 0:0fdadbc3d852 | 447 | case '3': |
embeddedartists | 0:0fdadbc3d852 | 448 | set3V3Signal(*cmd == '1'); |
embeddedartists | 0:0fdadbc3d852 | 449 | break; |
embeddedartists | 0:0fdadbc3d852 | 450 | |
embeddedartists | 0:0fdadbc3d852 | 451 | // 5v enable |
embeddedartists | 0:0fdadbc3d852 | 452 | case '5': |
embeddedartists | 0:0fdadbc3d852 | 453 | set5VSignal(*cmd == '1'); |
embeddedartists | 0:0fdadbc3d852 | 454 | break; |
embeddedartists | 0:0fdadbc3d852 | 455 | } |
embeddedartists | 0:0fdadbc3d852 | 456 | |
embeddedartists | 0:0fdadbc3d852 | 457 | return Ok; |
embeddedartists | 0:0fdadbc3d852 | 458 | } |
embeddedartists | 0:0fdadbc3d852 | 459 | |
embeddedartists | 0:0fdadbc3d852 | 460 | // ########################### |
embeddedartists | 0:0fdadbc3d852 | 461 | // PCA9532 is used as a control inteface to the display. |
embeddedartists | 0:0fdadbc3d852 | 462 | // voltages can be turned on/off and backlight can be controlled. |
embeddedartists | 0:0fdadbc3d852 | 463 | // ########################### |
embeddedartists | 0:0fdadbc3d852 | 464 | |
embeddedartists | 0:0fdadbc3d852 | 465 | // Helper function to set LED states |
embeddedartists | 0:0fdadbc3d852 | 466 | void EaLcdBoard::setLsStates(uint16_t states, uint8_t* ls, uint8_t mode) |
embeddedartists | 0:0fdadbc3d852 | 467 | { |
embeddedartists | 0:0fdadbc3d852 | 468 | #define IS_LED_SET(bit, x) ( ( ((x) & (bit)) != 0 ) ? 1 : 0 ) |
embeddedartists | 0:0fdadbc3d852 | 469 | |
embeddedartists | 0:0fdadbc3d852 | 470 | int i = 0; |
embeddedartists | 0:0fdadbc3d852 | 471 | |
embeddedartists | 0:0fdadbc3d852 | 472 | for (i = 0; i < 4; i++) { |
embeddedartists | 0:0fdadbc3d852 | 473 | |
embeddedartists | 0:0fdadbc3d852 | 474 | ls[i] |= ( (IS_LED_SET(0x0001, states)*mode << 0) |
embeddedartists | 0:0fdadbc3d852 | 475 | | (IS_LED_SET(0x0002, states)*mode << 2) |
embeddedartists | 0:0fdadbc3d852 | 476 | | (IS_LED_SET(0x0004, states)*mode << 4) |
embeddedartists | 0:0fdadbc3d852 | 477 | | (IS_LED_SET(0x0008, states)*mode << 6) ); |
embeddedartists | 0:0fdadbc3d852 | 478 | |
embeddedartists | 0:0fdadbc3d852 | 479 | states >>= 4; |
embeddedartists | 0:0fdadbc3d852 | 480 | } |
embeddedartists | 0:0fdadbc3d852 | 481 | } |
embeddedartists | 0:0fdadbc3d852 | 482 | |
embeddedartists | 0:0fdadbc3d852 | 483 | void EaLcdBoard::setLeds(void) |
embeddedartists | 0:0fdadbc3d852 | 484 | { |
embeddedartists | 0:0fdadbc3d852 | 485 | uint8_t buf[5]; |
embeddedartists | 0:0fdadbc3d852 | 486 | uint8_t ls[4] = {0,0,0,0}; |
embeddedartists | 0:0fdadbc3d852 | 487 | uint16_t states = _ledStateShadow; |
embeddedartists | 0:0fdadbc3d852 | 488 | |
embeddedartists | 0:0fdadbc3d852 | 489 | // LEDs in On/Off state |
embeddedartists | 0:0fdadbc3d852 | 490 | setLsStates(states, ls, LCDB_LS_MODE_ON); |
embeddedartists | 0:0fdadbc3d852 | 491 | |
embeddedartists | 0:0fdadbc3d852 | 492 | // set the LEDs that should blink |
embeddedartists | 0:0fdadbc3d852 | 493 | setLsStates(_blink0Shadow, ls, LCDB_LS_MODE_BLINK0); |
embeddedartists | 0:0fdadbc3d852 | 494 | setLsStates(_blink1Shadow, ls, LCDB_LS_MODE_BLINK1); |
embeddedartists | 0:0fdadbc3d852 | 495 | |
embeddedartists | 0:0fdadbc3d852 | 496 | buf[0] = LCDB_PCA9532_LS0 | LCDB_PCA9532_AUTO_INC; |
embeddedartists | 0:0fdadbc3d852 | 497 | buf[1] = ls[0]; |
embeddedartists | 0:0fdadbc3d852 | 498 | buf[2] = ls[1]; |
embeddedartists | 0:0fdadbc3d852 | 499 | buf[3] = ls[2]; |
embeddedartists | 0:0fdadbc3d852 | 500 | buf[4] = ls[3]; |
embeddedartists | 0:0fdadbc3d852 | 501 | |
embeddedartists | 0:0fdadbc3d852 | 502 | _i2c.write(LCDB_PCA9532_I2C_ADDR, (char*)buf, 5); |
embeddedartists | 0:0fdadbc3d852 | 503 | } |
embeddedartists | 0:0fdadbc3d852 | 504 | |
embeddedartists | 0:0fdadbc3d852 | 505 | void EaLcdBoard::pca9532_setLeds (uint16_t ledOnMask, uint16_t ledOffMask) |
embeddedartists | 0:0fdadbc3d852 | 506 | { |
embeddedartists | 0:0fdadbc3d852 | 507 | // turn off leds |
embeddedartists | 0:0fdadbc3d852 | 508 | _ledStateShadow &= (~(ledOffMask) & 0xffff); |
embeddedartists | 0:0fdadbc3d852 | 509 | |
embeddedartists | 0:0fdadbc3d852 | 510 | // ledOnMask has priority over ledOffMask |
embeddedartists | 0:0fdadbc3d852 | 511 | _ledStateShadow |= ledOnMask; |
embeddedartists | 0:0fdadbc3d852 | 512 | |
embeddedartists | 0:0fdadbc3d852 | 513 | // turn off blinking |
embeddedartists | 0:0fdadbc3d852 | 514 | _blink0Shadow &= (~(ledOffMask) & 0xffff); |
embeddedartists | 0:0fdadbc3d852 | 515 | _blink1Shadow &= (~(ledOffMask) & 0xffff); |
embeddedartists | 0:0fdadbc3d852 | 516 | |
embeddedartists | 0:0fdadbc3d852 | 517 | setLeds(); |
embeddedartists | 0:0fdadbc3d852 | 518 | } |
embeddedartists | 0:0fdadbc3d852 | 519 | |
embeddedartists | 0:0fdadbc3d852 | 520 | void EaLcdBoard::pca9532_setBlink0Period(uint8_t period) |
embeddedartists | 0:0fdadbc3d852 | 521 | { |
embeddedartists | 0:0fdadbc3d852 | 522 | uint8_t buf[2]; |
embeddedartists | 0:0fdadbc3d852 | 523 | |
embeddedartists | 0:0fdadbc3d852 | 524 | buf[0] = LCDB_PCA9532_PSC0; |
embeddedartists | 0:0fdadbc3d852 | 525 | buf[1] = period; |
embeddedartists | 0:0fdadbc3d852 | 526 | |
embeddedartists | 0:0fdadbc3d852 | 527 | _i2c.write(LCDB_PCA9532_I2C_ADDR, (char*)buf, 2); |
embeddedartists | 0:0fdadbc3d852 | 528 | } |
embeddedartists | 0:0fdadbc3d852 | 529 | |
embeddedartists | 0:0fdadbc3d852 | 530 | void EaLcdBoard::pca9532_setBlink0Duty(uint8_t duty) |
embeddedartists | 0:0fdadbc3d852 | 531 | { |
embeddedartists | 0:0fdadbc3d852 | 532 | uint8_t buf[2]; |
embeddedartists | 0:0fdadbc3d852 | 533 | uint32_t tmp = duty; |
embeddedartists | 0:0fdadbc3d852 | 534 | if (tmp > 100) { |
embeddedartists | 0:0fdadbc3d852 | 535 | tmp = 100; |
embeddedartists | 0:0fdadbc3d852 | 536 | } |
embeddedartists | 0:0fdadbc3d852 | 537 | |
embeddedartists | 0:0fdadbc3d852 | 538 | tmp = (255 * tmp)/100; |
embeddedartists | 0:0fdadbc3d852 | 539 | |
embeddedartists | 0:0fdadbc3d852 | 540 | buf[0] = LCDB_PCA9532_PWM0; |
embeddedartists | 0:0fdadbc3d852 | 541 | buf[1] = tmp; |
embeddedartists | 0:0fdadbc3d852 | 542 | |
embeddedartists | 0:0fdadbc3d852 | 543 | _i2c.write(LCDB_PCA9532_I2C_ADDR, (char*)buf, 2); |
embeddedartists | 0:0fdadbc3d852 | 544 | } |
embeddedartists | 0:0fdadbc3d852 | 545 | |
embeddedartists | 0:0fdadbc3d852 | 546 | void EaLcdBoard::pca9532_setBlink0Leds(uint16_t ledMask) |
embeddedartists | 0:0fdadbc3d852 | 547 | { |
embeddedartists | 0:0fdadbc3d852 | 548 | _blink0Shadow |= ledMask; |
embeddedartists | 0:0fdadbc3d852 | 549 | setLeds(); |
embeddedartists | 0:0fdadbc3d852 | 550 | } |
embeddedartists | 0:0fdadbc3d852 | 551 | |
embeddedartists | 0:0fdadbc3d852 | 552 | void EaLcdBoard::set3V3Signal(bool enabled) { |
embeddedartists | 0:0fdadbc3d852 | 553 | if (enabled) { |
embeddedartists | 0:0fdadbc3d852 | 554 | pca9532_setLeds(LCDB_CTRL_3V3, 0); |
embeddedartists | 0:0fdadbc3d852 | 555 | } else { |
embeddedartists | 0:0fdadbc3d852 | 556 | pca9532_setLeds(0, LCDB_CTRL_3V3); |
embeddedartists | 0:0fdadbc3d852 | 557 | } |
embeddedartists | 0:0fdadbc3d852 | 558 | } |
embeddedartists | 0:0fdadbc3d852 | 559 | |
embeddedartists | 0:0fdadbc3d852 | 560 | void EaLcdBoard::set5VSignal(bool enabled) { |
embeddedartists | 0:0fdadbc3d852 | 561 | if (enabled) { |
embeddedartists | 0:0fdadbc3d852 | 562 | pca9532_setLeds(LCDB_CTRL_5V, 0); |
embeddedartists | 0:0fdadbc3d852 | 563 | } else { |
embeddedartists | 0:0fdadbc3d852 | 564 | pca9532_setLeds(0, LCDB_CTRL_5V); |
embeddedartists | 0:0fdadbc3d852 | 565 | } |
embeddedartists | 0:0fdadbc3d852 | 566 | } |
embeddedartists | 0:0fdadbc3d852 | 567 | |
embeddedartists | 0:0fdadbc3d852 | 568 | void EaLcdBoard::setDisplayEnableSignal(bool enabled) { |
embeddedartists | 0:0fdadbc3d852 | 569 | if (!enabled) { |
embeddedartists | 0:0fdadbc3d852 | 570 | pca9532_setLeds(LCDB_CTRL_DISP_EN, 0); |
embeddedartists | 0:0fdadbc3d852 | 571 | } else { |
embeddedartists | 0:0fdadbc3d852 | 572 | pca9532_setLeds(0, LCDB_CTRL_DISP_EN); |
embeddedartists | 0:0fdadbc3d852 | 573 | } |
embeddedartists | 0:0fdadbc3d852 | 574 | } |
embeddedartists | 0:0fdadbc3d852 | 575 | |
embeddedartists | 0:0fdadbc3d852 | 576 | void EaLcdBoard::setBacklightContrast(uint32_t value) { |
embeddedartists | 0:0fdadbc3d852 | 577 | |
embeddedartists | 0:0fdadbc3d852 | 578 | if (value > 100) return; |
embeddedartists | 0:0fdadbc3d852 | 579 | |
embeddedartists | 0:0fdadbc3d852 | 580 | pca9532_setBlink0Duty(100-value); |
embeddedartists | 0:0fdadbc3d852 | 581 | pca9532_setBlink0Period(0); |
embeddedartists | 0:0fdadbc3d852 | 582 | pca9532_setBlink0Leds(LCDB_CTRL_BL_C); |
embeddedartists | 0:0fdadbc3d852 | 583 | } |
embeddedartists | 0:0fdadbc3d852 | 584 | |
embeddedartists | 0:0fdadbc3d852 | 585 | |
embeddedartists | 0:0fdadbc3d852 | 586 | // convert string to integer |
embeddedartists | 0:0fdadbc3d852 | 587 | static uint32_t str_to_uint(char* str, uint32_t len) |
embeddedartists | 0:0fdadbc3d852 | 588 | { |
embeddedartists | 0:0fdadbc3d852 | 589 | uint32_t val = 0; |
embeddedartists | 0:0fdadbc3d852 | 590 | |
embeddedartists | 0:0fdadbc3d852 | 591 | while(len > 0 && *str <= '9' && *str >= '0') { |
embeddedartists | 0:0fdadbc3d852 | 592 | val = (val * 10) + (*str - '0'); |
embeddedartists | 0:0fdadbc3d852 | 593 | str++; |
embeddedartists | 0:0fdadbc3d852 | 594 | len--; |
embeddedartists | 0:0fdadbc3d852 | 595 | } |
embeddedartists | 0:0fdadbc3d852 | 596 | |
embeddedartists | 0:0fdadbc3d852 | 597 | return val; |
embeddedartists | 0:0fdadbc3d852 | 598 | } |
embeddedartists | 0:0fdadbc3d852 | 599 | |
embeddedartists | 0:0fdadbc3d852 | 600 | |
embeddedartists | 0:0fdadbc3d852 | 601 | |
embeddedartists | 0:0fdadbc3d852 | 602 |