Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
licio.mapelli@st.com
Date:
Tue Nov 17 17:38:38 2015 +0100
Revision:
34:5bcffb4c5b47
Parent:
33:1573db91352c
Child:
36:f6278b3e7c82
Added DisplayDigit function to Display class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gallonm 7:2dc81120c917 1 /**
gallonm 7:2dc81120c917 2 ******************************************************************************
gallonm 7:2dc81120c917 3 * @file Display.h
gallonm 7:2dc81120c917 4 * @author AST / EST
gallonm 7:2dc81120c917 5 * @version V0.0.1
gallonm 7:2dc81120c917 6 * @date 14-April-2015
gallonm 7:2dc81120c917 7 * @brief Header file for display
gallonm 7:2dc81120c917 8 ******************************************************************************
gallonm 7:2dc81120c917 9 * @attention
gallonm 7:2dc81120c917 10 *
gallonm 7:2dc81120c917 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
gallonm 7:2dc81120c917 12 *
gallonm 7:2dc81120c917 13 * Redistribution and use in source and binary forms, with or without modification,
gallonm 7:2dc81120c917 14 * are permitted provided that the following conditions are met:
gallonm 7:2dc81120c917 15 * 1. Redistributions of source code must retain the above copyright notice,
gallonm 7:2dc81120c917 16 * this list of conditions and the following disclaimer.
gallonm 7:2dc81120c917 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
gallonm 7:2dc81120c917 18 * this list of conditions and the following disclaimer in the documentation
gallonm 7:2dc81120c917 19 * and/or other materials provided with the distribution.
gallonm 7:2dc81120c917 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gallonm 7:2dc81120c917 21 * may be used to endorse or promote products derived from this software
gallonm 7:2dc81120c917 22 * without specific prior written permission.
gallonm 7:2dc81120c917 23 *
gallonm 7:2dc81120c917 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gallonm 7:2dc81120c917 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gallonm 7:2dc81120c917 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gallonm 7:2dc81120c917 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gallonm 7:2dc81120c917 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gallonm 7:2dc81120c917 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gallonm 7:2dc81120c917 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gallonm 7:2dc81120c917 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gallonm 7:2dc81120c917 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gallonm 7:2dc81120c917 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gallonm 7:2dc81120c917 34 *
gallonm 7:2dc81120c917 35 ******************************************************************************
gallonm 7:2dc81120c917 36 */
gallonm 7:2dc81120c917 37
gallonm 7:2dc81120c917 38 #ifndef __DISPLAY_H
gallonm 7:2dc81120c917 39 #define __DISPLAY_H
gallonm 7:2dc81120c917 40
gallonm 7:2dc81120c917 41 /* Includes ------------------------------------------------------------------*/
gallonm 7:2dc81120c917 42 #include "mbed.h"
gallonm 16:0d4776564733 43 #include "stmpe1600_class.h"
gallonm 16:0d4776564733 44 #include "DevI2C.h"
gallonm 7:2dc81120c917 45
gallonm 16:0d4776564733 46 #ifdef __cplusplus
gallonm 16:0d4776564733 47 extern "C" {
gallonm 16:0d4776564733 48 #endif
gallonm 16:0d4776564733 49
licio.mapelli@st.com 33:1573db91352c 50 #define DISPLAY_USING_STMPE1600
licio.mapelli@st.com 33:1573db91352c 51
licio.mapelli@st.com 33:1573db91352c 52 #ifndef DISPLAY_USING_STMPE1600
licio.mapelli@st.com 33:1573db91352c 53 #define FAST_DISPLAY // fast quick and dirty display to speed up
licio.mapelli@st.com 33:1573db91352c 54 #endif
gallonm 16:0d4776564733 55
gallonm 16:0d4776564733 56 #define DP (1<<7)
gallonm 16:0d4776564733 57 #define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP )
gallonm 16:0d4776564733 58 #define S0 (1<<0)
gallonm 16:0d4776564733 59 #define S1 (1<<1)
gallonm 16:0d4776564733 60 #define S2 (1<<2)
gallonm 16:0d4776564733 61 #define S3 (1<<3)
gallonm 16:0d4776564733 62 #define S4 (1<<4)
gallonm 16:0d4776564733 63 #define S5 (1<<5)
gallonm 16:0d4776564733 64 #define S6 (1<<6)
gallonm 16:0d4776564733 65
gallonm 16:0d4776564733 66 /* refer to http://www.twyman.org.uk/Fonts/ */
gallonm 16:0d4776564733 67 static const uint8_t ascii_to_display_lut[256]={
gallonm 16:0d4776564733 68 [' ']= 0,
gallonm 16:0d4776564733 69 ['-']= S6,
gallonm 16:0d4776564733 70 ['_']= S3,
gallonm 16:0d4776564733 71 ['=']= S3+S6,
gallonm 16:0d4776564733 72 ['~']= S0+S3+S6, /* 3 h bar */
gallonm 16:0d4776564733 73 ['^']= S0, /* use as top bar */
gallonm 16:0d4776564733 74
gallonm 16:0d4776564733 75 ['?']= NOT_7_NO_DP(S5+S3+S2),
gallonm 16:0d4776564733 76 ['*']= NOT_7_NO_DP(),
gallonm 16:0d4776564733 77 ['[']= S0+S3+S4+S5,
gallonm 16:0d4776564733 78 [']']= S0+S3+S2+S1,
gallonm 16:0d4776564733 79 ['@']= S0+S3,
gallonm 16:0d4776564733 80
gallonm 16:0d4776564733 81 ['0']= NOT_7_NO_DP(S6),
gallonm 16:0d4776564733 82 ['1']= S1+S2,
gallonm 16:0d4776564733 83 ['2']= S0+S1+S6+S4+S3,
gallonm 16:0d4776564733 84 ['3']= NOT_7_NO_DP(S4+S5),
gallonm 16:0d4776564733 85 ['4']= S5+S1+S6+S2,
gallonm 16:0d4776564733 86 ['5']= NOT_7_NO_DP(S1+S4),
gallonm 16:0d4776564733 87 ['6']= NOT_7_NO_DP(S1),
gallonm 16:0d4776564733 88 ['7']= S0+S1+S2,
gallonm 16:0d4776564733 89 ['8']= NOT_7_NO_DP(0),
gallonm 16:0d4776564733 90 ['9']= NOT_7_NO_DP(S4),
gallonm 16:0d4776564733 91
gallonm 16:0d4776564733 92 ['a']= S2+ S3+ S4+ S6 ,
gallonm 16:0d4776564733 93 ['b']= NOT_7_NO_DP(S0+S1),
gallonm 16:0d4776564733 94 ['c']= S6+S4+S3,
gallonm 16:0d4776564733 95 ['d']= NOT_7_NO_DP(S0+S5),
gallonm 16:0d4776564733 96 ['e']= NOT_7_NO_DP(S2),
gallonm 16:0d4776564733 97 ['f']= S6+S5+S4+S0, /* same as F */
gallonm 16:0d4776564733 98 ['g']= NOT_7_NO_DP(S4), /* same as 9 */
gallonm 16:0d4776564733 99 ['h']= S6+S5+S4+S2,
gallonm 16:0d4776564733 100 ['i']= S4,
gallonm 16:0d4776564733 101 ['j']= S1+S2+S3+S4,
gallonm 16:0d4776564733 102 ['k']= S6+S5+S4+S2, /* a h */
gallonm 16:0d4776564733 103 ['l']= S3+S4,
gallonm 16:0d4776564733 104 ['m']= S0+S4+S2, /* same as */
gallonm 16:0d4776564733 105 ['n']= S2+S4+S6,
gallonm 16:0d4776564733 106 ['o']= S6+S4+S3+S2,
gallonm 16:0d4776564733 107 ['p']= NOT_7_NO_DP(S3+S2), // same as P
gallonm 16:0d4776564733 108 ['q']= S0+S1+S2+S5+S6,
gallonm 16:0d4776564733 109 ['r']= S4+S6,
gallonm 16:0d4776564733 110 ['s']= NOT_7_NO_DP(S1+S4),
gallonm 16:0d4776564733 111 ['t']= NOT_7_NO_DP(S0+S1+S2),
gallonm 16:0d4776564733 112 ['u']= S4+S3+S2+S5+S1, // U
gallonm 16:0d4776564733 113 ['v']= S4+S3+S2, // is u but u use U
gallonm 16:0d4776564733 114 ['w']= S1+S3+S5,
gallonm 16:0d4776564733 115 ['x']= NOT_7_NO_DP(S0+S3), // similar to H
gallonm 16:0d4776564733 116 ['y']= NOT_7_NO_DP(S0+S4),
gallonm 16:0d4776564733 117 ['z']= S0+S1+S6+S4+S3, // same as 2
gallonm 16:0d4776564733 118
gallonm 16:0d4776564733 119 ['A']= NOT_7_NO_DP(S3),
gallonm 16:0d4776564733 120 ['B']= NOT_7_NO_DP(S0+S1), /* as b */
gallonm 16:0d4776564733 121 ['C']= S0+S3+S4+S5, // same as [
gallonm 16:0d4776564733 122 ['E']= NOT_7_NO_DP(S1+S2),
gallonm 16:0d4776564733 123 ['F']= S6+S5+S4+S0,
gallonm 16:0d4776564733 124 ['G']= NOT_7_NO_DP(S4), /* same as 9 */
gallonm 16:0d4776564733 125 ['H']= NOT_7_NO_DP(S0+S3),
gallonm 16:0d4776564733 126 ['I']= S1+S2,
gallonm 16:0d4776564733 127 ['J']= S1+S2+S3+S4,
gallonm 16:0d4776564733 128 ['K']= NOT_7_NO_DP(S0+S3), /* same as H */
gallonm 16:0d4776564733 129 ['L']= S3+S4+S5,
gallonm 16:0d4776564733 130 ['M']= S0+S4+S2, /* same as m*/
gallonm 16:0d4776564733 131 ['N']= S2+S4+S6, /* same as n*/
gallonm 16:0d4776564733 132 ['O']= NOT_7_NO_DP(S6),
gallonm 16:0d4776564733 133 ['P']= S0+S1+S2+S5+S6, // sames as 'q'
gallonm 16:0d4776564733 134 ['Q']= NOT_7_NO_DP(S3+S2),
gallonm 16:0d4776564733 135 ['R']= S4+S6,
gallonm 16:0d4776564733 136 ['S']= NOT_7_NO_DP(S1+S4), /* sasme as 5 */
gallonm 16:0d4776564733 137 ['T']= NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
gallonm 16:0d4776564733 138 ['U']= NOT_7_NO_DP(S6+S0),
gallonm 16:0d4776564733 139 ['V']= S4+S3+S2, // is u but u use U
gallonm 16:0d4776564733 140 ['W']= S1+S3+S5,
gallonm 16:0d4776564733 141 ['X']= NOT_7_NO_DP(S0+S3), // similar to H
gallonm 16:0d4776564733 142 ['Y']= NOT_7_NO_DP(S0+S4),
gallonm 16:0d4776564733 143 ['Z']= S0+S1+S6+S4+S3, // same as 2
gallonm 16:0d4776564733 144
gallonm 16:0d4776564733 145
gallonm 16:0d4776564733 146 };
gallonm 16:0d4776564733 147
gallonm 16:0d4776564733 148 #undef S0
gallonm 16:0d4776564733 149 #undef S1
gallonm 16:0d4776564733 150 #undef S2
gallonm 16:0d4776564733 151 #undef S3
gallonm 16:0d4776564733 152 #undef S4
gallonm 16:0d4776564733 153 #undef S5
gallonm 16:0d4776564733 154 #undef S6
gallonm 16:0d4776564733 155 #undef DP
gallonm 16:0d4776564733 156
gallonm 16:0d4776564733 157 #define DISPLAY_DELAY 1 // in mSec
gallonm 7:2dc81120c917 158
gallonm 7:2dc81120c917 159 /* Classes -------------------------------------------------------------------*/
gallonm 16:0d4776564733 160 /** Class representing Display
gallonm 16:0d4776564733 161 */
licio.mapelli@st.com 33:1573db91352c 162 #ifndef DISPLAY_USING_STMPE1600
licio.mapelli@st.com 33:1573db91352c 163
gallonm 16:0d4776564733 164 class Display
gallonm 7:2dc81120c917 165 {
gallonm 7:2dc81120c917 166 public:
gallonm 7:2dc81120c917 167
gallonm 16:0d4776564733 168 #ifndef FAST_DISPLAY
gallonm 16:0d4776564733 169
gallonm 16:0d4776564733 170 Display(DevI2C &i2c, STMPE1600DigiOut &D1, STMPE1600DigiOut &D2, STMPE1600DigiOut &D3, STMPE1600DigiOut &D4,
gallonm 23:dfb5ccc7b780 171 STMPE1600DigiOut &D_A, STMPE1600DigiOut &D_B, STMPE1600DigiOut &D_C, STMPE1600DigiOut &D_D,
gallonm 23:dfb5ccc7b780 172 STMPE1600DigiOut &D_E, STMPE1600DigiOut &D_F, STMPE1600DigiOut &D_G)
gallonm 23:dfb5ccc7b780 173 : Display_D1(D1), Display_D2(D2), Display_D3(D3), Display_D4(D4), Display_A(D_A), Display_B(D_B),
gallonm 23:dfb5ccc7b780 174 Display_C(D_C), Display_D(D_D), Display_E(D_E), Display_F(D_F), Display_G(D_G), dev_i2c(i2c)
gallonm 23:dfb5ccc7b780 175 {
gallonm 23:dfb5ccc7b780 176 pDisplay_DGT[0] = &Display_D1;
gallonm 23:dfb5ccc7b780 177 pDisplay_DGT[1] = &Display_D2;
gallonm 23:dfb5ccc7b780 178 pDisplay_DGT[2] = &Display_D3;
gallonm 23:dfb5ccc7b780 179 pDisplay_DGT[3] = &Display_D4;
gallonm 23:dfb5ccc7b780 180 pDisplay_SEG[0] = &Display_A;
gallonm 23:dfb5ccc7b780 181 pDisplay_SEG[1] = &Display_B;
gallonm 23:dfb5ccc7b780 182 pDisplay_SEG[2] = &Display_C;
gallonm 23:dfb5ccc7b780 183 pDisplay_SEG[3] = &Display_D;
gallonm 23:dfb5ccc7b780 184 pDisplay_SEG[4] = &Display_E;
gallonm 23:dfb5ccc7b780 185 pDisplay_SEG[5] = &Display_F;
gallonm 23:dfb5ccc7b780 186 pDisplay_SEG[6] = &Display_G;
gallonm 16:0d4776564733 187
gallonm 23:dfb5ccc7b780 188 for (int i=0; i<4; i++) { *pDisplay_DGT[i]=1; }
gallonm 23:dfb5ccc7b780 189 for (int i=0; i<7; i++) { *pDisplay_SEG[i]=1; }
gallonm 23:dfb5ccc7b780 190 }
gallonm 16:0d4776564733 191 #else
gallonm 16:0d4776564733 192 Display(DevI2C &i2c) : dev_i2c(i2c) {}
gallonm 16:0d4776564733 193 #endif
gallonm 16:0d4776564733 194
gallonm 16:0d4776564733 195 #ifndef FAST_DISPLAY
gallonm 20:dd8390d615bf 196 void Digits_off (void) // all 4 digits off
gallonm 20:dd8390d615bf 197 {
gallonm 20:dd8390d615bf 198 Display_D1=1;
gallonm 20:dd8390d615bf 199 Display_D2=1;
gallonm 20:dd8390d615bf 200 Display_D3=1;
gallonm 20:dd8390d615bf 201 Display_D4=1;
gallonm 20:dd8390d615bf 202 }
gallonm 16:0d4776564733 203
gallonm 20:dd8390d615bf 204 void Digits_on (void) // all 4 digits on
gallonm 20:dd8390d615bf 205 {
gallonm 20:dd8390d615bf 206 Display_D1=0;
gallonm 20:dd8390d615bf 207 Display_D2=0;
gallonm 20:dd8390d615bf 208 Display_D3=0;
gallonm 20:dd8390d615bf 209 Display_D4=0;
gallonm 20:dd8390d615bf 210 }
gallonm 16:0d4776564733 211
gallonm 20:dd8390d615bf 212 void Digit_on (int digit) // digits on
gallonm 20:dd8390d615bf 213 {
gallonm 20:dd8390d615bf 214 *pDisplay_DGT[digit] = 0;
gallonm 20:dd8390d615bf 215 }
gallonm 16:0d4776564733 216
gallonm 28:7c9031e96c22 217 void Digit_off (int digit) // digits off
gallonm 20:dd8390d615bf 218 {
gallonm 20:dd8390d615bf 219 *pDisplay_DGT[digit] = 1;
gallonm 20:dd8390d615bf 220 }
gallonm 16:0d4776564733 221
gallonm 20:dd8390d615bf 222 void Segments_off () // all 7 segments off
gallonm 20:dd8390d615bf 223 {
gallonm 20:dd8390d615bf 224 Display_A=1;
gallonm 20:dd8390d615bf 225 Display_B=1;
gallonm 20:dd8390d615bf 226 Display_C=1;
gallonm 20:dd8390d615bf 227 Display_D=1;
gallonm 20:dd8390d615bf 228 Display_E=1;
gallonm 20:dd8390d615bf 229 Display_F=1;
gallonm 20:dd8390d615bf 230 Display_G=1;
gallonm 20:dd8390d615bf 231 }
gallonm 16:0d4776564733 232
gallonm 20:dd8390d615bf 233 void Segment_off (int seg) // segment off
gallonm 20:dd8390d615bf 234 {
gallonm 20:dd8390d615bf 235 *pDisplay_SEG[seg] = 1;
gallonm 20:dd8390d615bf 236 }
gallonm 16:0d4776564733 237
gallonm 20:dd8390d615bf 238 void Segment_on (int seg) // segment on
gallonm 20:dd8390d615bf 239 {
gallonm 20:dd8390d615bf 240 *pDisplay_SEG[seg] = 0;
gallonm 20:dd8390d615bf 241 }
gallonm 16:0d4776564733 242
gallonm 16:0d4776564733 243
gallonm 20:dd8390d615bf 244 void DisplayString (char str[4])
gallonm 20:dd8390d615bf 245 {
gallonm 20:dd8390d615bf 246 int i;
gallonm 20:dd8390d615bf 247 const char *pc;
gallonm 16:0d4776564733 248
gallonm 23:dfb5ccc7b780 249 for( i=0, pc=str; i<4 && *pc!=0 ; i++, pc++)
gallonm 23:dfb5ccc7b780 250 {
gallonm 20:dd8390d615bf 251 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], i);
gallonm 23:dfb5ccc7b780 252 if( *(pc+1)== '.')
gallonm 23:dfb5ccc7b780 253 {
gallonm 23:dfb5ccc7b780 254 pc++;
gallonm 20:dd8390d615bf 255 }
gallonm 20:dd8390d615bf 256 wait_ms(DISPLAY_DELAY);
gallonm 20:dd8390d615bf 257 Digits_off();
gallonm 20:dd8390d615bf 258 }
gallonm 20:dd8390d615bf 259 }
gallonm 16:0d4776564733 260
gallonm 16:0d4776564733 261
gallonm 23:dfb5ccc7b780 262 void _V2_Set7Segment( int Leds, int digit )
gallonm 23:dfb5ccc7b780 263 {
gallonm 20:dd8390d615bf 264 //Digits_off();
gallonm 23:dfb5ccc7b780 265 Segments_off(); // 7 seg off */
gallonm 20:dd8390d615bf 266 int mask=1;
gallonm 23:dfb5ccc7b780 267 for (int i=0; i<7; i++)
gallonm 23:dfb5ccc7b780 268 {
gallonm 20:dd8390d615bf 269 if (Leds & mask) Segment_on(i);
gallonm 20:dd8390d615bf 270 mask = mask<<1;
gallonm 20:dd8390d615bf 271 }
gallonm 20:dd8390d615bf 272 Digit_on(digit);
gallonm 20:dd8390d615bf 273 }
gallonm 16:0d4776564733 274
gallonm 16:0d4776564733 275
gallonm 16:0d4776564733 276 #else
gallonm 16:0d4776564733 277
gallonm 20:dd8390d615bf 278 void DisplayDigit (char *val, char dgt)
gallonm 20:dd8390d615bf 279 {
gallonm 20:dd8390d615bf 280 uint8_t data[2];
gallonm 20:dd8390d615bf 281 uint16_t *pdata = (uint16_t*)data;
gallonm 23:dfb5ccc7b780 282 dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 23:dfb5ccc7b780 283 *pdata = *pdata | (uint16_t)0x0780; // all digits off
gallonm 23:dfb5ccc7b780 284 dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 16:0d4776564733 285
gallonm 20:dd8390d615bf 286 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);
gallonm 20:dd8390d615bf 287 }
gallonm 16:0d4776564733 288
gallonm 20:dd8390d615bf 289 void DisplayString (char str[4], char strlen)
gallonm 20:dd8390d615bf 290 {
gallonm 20:dd8390d615bf 291 int i, dgt;
gallonm 20:dd8390d615bf 292 const char *pc;
gallonm 20:dd8390d615bf 293 uint8_t data[2];
gallonm 20:dd8390d615bf 294 uint16_t *pdata = (uint16_t*)data;
gallonm 16:0d4776564733 295
gallonm 23:dfb5ccc7b780 296 //dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 23:dfb5ccc7b780 297 //*pdata = *pdata | (uint16_t)0x0780; // all digits off
gallonm 23:dfb5ccc7b780 298 //dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 16:0d4776564733 299
gallonm 23:dfb5ccc7b780 300 for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++)
gallonm 23:dfb5ccc7b780 301 {
gallonm 23:dfb5ccc7b780 302 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
gallonm 23:dfb5ccc7b780 303 if( *(pc+1)== '.')
gallonm 23:dfb5ccc7b780 304 {
gallonm 23:dfb5ccc7b780 305 pc++;
gallonm 23:dfb5ccc7b780 306 }
gallonm 23:dfb5ccc7b780 307 wait_ms(DISPLAY_DELAY);
gallonm 23:dfb5ccc7b780 308 dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 23:dfb5ccc7b780 309 *pdata = *pdata | (uint16_t)0x0780; // all digits off
gallonm 23:dfb5ccc7b780 310 dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 20:dd8390d615bf 311 }
gallonm 20:dd8390d615bf 312 }
gallonm 16:0d4776564733 313
gallonm 16:0d4776564733 314
gallonm 23:dfb5ccc7b780 315 void _V2_Set7Segment( int Leds, int digit )
gallonm 23:dfb5ccc7b780 316 {
gallonm 20:dd8390d615bf 317 //Digits_off();
gallonm 20:dd8390d615bf 318 uint16_t dgt;
gallonm 20:dd8390d615bf 319 dgt = 1<<digit;
gallonm 20:dd8390d615bf 320 dgt = ((uint16_t)dgt)<<7;
gallonm 20:dd8390d615bf 321 dgt = ~dgt;
gallonm 20:dd8390d615bf 322 uint8_t data[2];
gallonm 20:dd8390d615bf 323 uint16_t *pdata = (uint16_t*)data;
gallonm 16:0d4776564733 324
gallonm 16:0d4776564733 325
gallonm 20:dd8390d615bf 326 /* set the exppinname state to lvl */
gallonm 20:dd8390d615bf 327 dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 20:dd8390d615bf 328 *pdata = *pdata | (uint16_t)0x007F; // 7 segments off
gallonm 20:dd8390d615bf 329 dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 16:0d4776564733 330
gallonm 20:dd8390d615bf 331 int mask=1;
gallonm 23:dfb5ccc7b780 332 for (int i=0; i<7; i++)
gallonm 23:dfb5ccc7b780 333 {
gallonm 20:dd8390d615bf 334 if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;
gallonm 20:dd8390d615bf 335 mask = mask<<1;
gallonm 20:dd8390d615bf 336 }
gallonm 20:dd8390d615bf 337 *pdata = *pdata & dgt;
gallonm 20:dd8390d615bf 338 dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7
gallonm 23:dfb5ccc7b780 339 }
gallonm 16:0d4776564733 340 #endif
gallonm 16:0d4776564733 341
gallonm 16:0d4776564733 342
gallonm 16:0d4776564733 343 private:
gallonm 16:0d4776564733 344
gallonm 16:0d4776564733 345 #ifndef FAST_DISPLAY
gallonm 23:dfb5ccc7b780 346 STMPE1600DigiOut &Display_D1;
gallonm 23:dfb5ccc7b780 347 STMPE1600DigiOut &Display_D2;
gallonm 23:dfb5ccc7b780 348 STMPE1600DigiOut &Display_D3;
gallonm 23:dfb5ccc7b780 349 STMPE1600DigiOut &Display_D4;
gallonm 23:dfb5ccc7b780 350 STMPE1600DigiOut *pDisplay_DGT[4]; // the 4 display digits
gallonm 16:0d4776564733 351
gallonm 23:dfb5ccc7b780 352 STMPE1600DigiOut &Display_A;
gallonm 23:dfb5ccc7b780 353 STMPE1600DigiOut &Display_B;
gallonm 23:dfb5ccc7b780 354 STMPE1600DigiOut &Display_C;
gallonm 23:dfb5ccc7b780 355 STMPE1600DigiOut &Display_D;
gallonm 23:dfb5ccc7b780 356 STMPE1600DigiOut &Display_E;
gallonm 23:dfb5ccc7b780 357 STMPE1600DigiOut &Display_F;
gallonm 23:dfb5ccc7b780 358 STMPE1600DigiOut &Display_G;
gallonm 23:dfb5ccc7b780 359 STMPE1600DigiOut *pDisplay_SEG[7]; // the 7 digit segmments
gallonm 16:0d4776564733 360 #endif
gallonm 23:dfb5ccc7b780 361 DevI2C &dev_i2c;
gallonm 7:2dc81120c917 362 };
gallonm 7:2dc81120c917 363
licio.mapelli@st.com 33:1573db91352c 364 #else // defined DISPLAY_USING_STMPE1600
licio.mapelli@st.com 33:1573db91352c 365
licio.mapelli@st.com 33:1573db91352c 366 class Display
licio.mapelli@st.com 33:1573db91352c 367 {
licio.mapelli@st.com 33:1573db91352c 368 public:
licio.mapelli@st.com 33:1573db91352c 369
licio.mapelli@st.com 33:1573db91352c 370 Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
licio.mapelli@st.com 33:1573db91352c 371 stmpe1600.setGPIOdir (GPIO_7, OUTPUT); // Digit1
licio.mapelli@st.com 33:1573db91352c 372 stmpe1600.setGPIOdir (GPIO_8, OUTPUT); // Digit2
licio.mapelli@st.com 33:1573db91352c 373 stmpe1600.setGPIOdir (GPIO_9, OUTPUT); // Digit3
licio.mapelli@st.com 33:1573db91352c 374 stmpe1600.setGPIOdir (GPIO_10, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 375
licio.mapelli@st.com 33:1573db91352c 376 stmpe1600.setGPIOdir (GPIO_0, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 377 stmpe1600.setGPIOdir (GPIO_1, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 378 stmpe1600.setGPIOdir (GPIO_2, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 379 stmpe1600.setGPIOdir (GPIO_3, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 380 stmpe1600.setGPIOdir (GPIO_4, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 381 stmpe1600.setGPIOdir (GPIO_5, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 382 stmpe1600.setGPIOdir (GPIO_6, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 383
licio.mapelli@st.com 33:1573db91352c 384 }
licio.mapelli@st.com 33:1573db91352c 385
licio.mapelli@st.com 33:1573db91352c 386 void DisplayString (char str[4], char strlen)
licio.mapelli@st.com 33:1573db91352c 387 {
licio.mapelli@st.com 33:1573db91352c 388 int i, dgt;
licio.mapelli@st.com 33:1573db91352c 389 const char *pc;
licio.mapelli@st.com 33:1573db91352c 390 uint8_t data[2];
licio.mapelli@st.com 33:1573db91352c 391 uint16_t *pdata = (uint16_t*)data;
licio.mapelli@st.com 33:1573db91352c 392
licio.mapelli@st.com 33:1573db91352c 393 for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++)
licio.mapelli@st.com 33:1573db91352c 394 {
licio.mapelli@st.com 33:1573db91352c 395 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
licio.mapelli@st.com 33:1573db91352c 396 if( *(pc+1)== '.')
licio.mapelli@st.com 33:1573db91352c 397 {
licio.mapelli@st.com 33:1573db91352c 398 pc++;
licio.mapelli@st.com 33:1573db91352c 399 }
licio.mapelli@st.com 33:1573db91352c 400 wait_ms(DISPLAY_DELAY);
licio.mapelli@st.com 33:1573db91352c 401 stmpe1600.read16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 402 *pdata = *pdata | (uint16_t)0x0780; // all digits off
licio.mapelli@st.com 33:1573db91352c 403 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 404 }
licio.mapelli@st.com 33:1573db91352c 405
licio.mapelli@st.com 33:1573db91352c 406 }
licio.mapelli@st.com 33:1573db91352c 407
licio.mapelli@st.com 34:5bcffb4c5b47 408 void DisplayDigit (char *val, char dgt)
licio.mapelli@st.com 34:5bcffb4c5b47 409 {
licio.mapelli@st.com 34:5bcffb4c5b47 410 uint8_t data[2];
licio.mapelli@st.com 34:5bcffb4c5b47 411 uint16_t *pdata = (uint16_t*)data;
licio.mapelli@st.com 34:5bcffb4c5b47 412
licio.mapelli@st.com 34:5bcffb4c5b47 413 stmpe1600.read16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 34:5bcffb4c5b47 414 *pdata = *pdata | (uint16_t)0x0780; // all digits off
licio.mapelli@st.com 34:5bcffb4c5b47 415 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 34:5bcffb4c5b47 416 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);
licio.mapelli@st.com 34:5bcffb4c5b47 417 }
licio.mapelli@st.com 34:5bcffb4c5b47 418
licio.mapelli@st.com 33:1573db91352c 419 void _V2_Set7Segment( int Leds, int digit )
licio.mapelli@st.com 33:1573db91352c 420 {
licio.mapelli@st.com 33:1573db91352c 421 //Digits_off();
licio.mapelli@st.com 33:1573db91352c 422 uint16_t dgt;
licio.mapelli@st.com 33:1573db91352c 423 dgt = 1<<digit;
licio.mapelli@st.com 33:1573db91352c 424 dgt = ((uint16_t)dgt)<<7;
licio.mapelli@st.com 33:1573db91352c 425 dgt = ~dgt;
licio.mapelli@st.com 33:1573db91352c 426 uint8_t data[2];
licio.mapelli@st.com 33:1573db91352c 427 uint16_t *pdata = (uint16_t*)data;
licio.mapelli@st.com 33:1573db91352c 428
licio.mapelli@st.com 33:1573db91352c 429
licio.mapelli@st.com 33:1573db91352c 430 /* set the exppinname state to lvl */
licio.mapelli@st.com 33:1573db91352c 431 stmpe1600.read16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 432 *pdata = *pdata | (uint16_t)0x007F; // 7 segments off
licio.mapelli@st.com 33:1573db91352c 433 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 434
licio.mapelli@st.com 33:1573db91352c 435 int mask=1;
licio.mapelli@st.com 33:1573db91352c 436 for (int i=0; i<7; i++)
licio.mapelli@st.com 33:1573db91352c 437 {
licio.mapelli@st.com 33:1573db91352c 438 if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;
licio.mapelli@st.com 33:1573db91352c 439 mask = mask<<1;
licio.mapelli@st.com 33:1573db91352c 440 }
licio.mapelli@st.com 33:1573db91352c 441 *pdata = *pdata & dgt;
licio.mapelli@st.com 33:1573db91352c 442 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 443 }
licio.mapelli@st.com 33:1573db91352c 444
licio.mapelli@st.com 33:1573db91352c 445 private:
licio.mapelli@st.com 33:1573db91352c 446 STMPE1600 &stmpe1600;
licio.mapelli@st.com 33:1573db91352c 447
licio.mapelli@st.com 33:1573db91352c 448 };
licio.mapelli@st.com 33:1573db91352c 449 #endif
licio.mapelli@st.com 33:1573db91352c 450
gallonm 16:0d4776564733 451 #ifdef __cplusplus
gallonm 16:0d4776564733 452 }
gallonm 16:0d4776564733 453 #endif
gallonm 17:922c88827e4d 454 #endif // __DISPLAY_H