INSAT Mini Project

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
mapellil
Date:
Tue Nov 24 16:04:41 2015 +0000
Revision:
36:f6278b3e7c82
Parent:
34:5bcffb4c5b47
Child:
39:3cce4ba37695
Exposed GPIOs on constructor, code cleanup, doxy comment

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
gallonm 16:0d4776564733 50 #define DP (1<<7)
gallonm 16:0d4776564733 51 #define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP )
gallonm 16:0d4776564733 52 #define S0 (1<<0)
gallonm 16:0d4776564733 53 #define S1 (1<<1)
gallonm 16:0d4776564733 54 #define S2 (1<<2)
gallonm 16:0d4776564733 55 #define S3 (1<<3)
gallonm 16:0d4776564733 56 #define S4 (1<<4)
gallonm 16:0d4776564733 57 #define S5 (1<<5)
gallonm 16:0d4776564733 58 #define S6 (1<<6)
gallonm 16:0d4776564733 59
gallonm 16:0d4776564733 60 /* refer to http://www.twyman.org.uk/Fonts/ */
gallonm 16:0d4776564733 61 static const uint8_t ascii_to_display_lut[256]={
gallonm 16:0d4776564733 62 [' ']= 0,
gallonm 16:0d4776564733 63 ['-']= S6,
gallonm 16:0d4776564733 64 ['_']= S3,
gallonm 16:0d4776564733 65 ['=']= S3+S6,
gallonm 16:0d4776564733 66 ['~']= S0+S3+S6, /* 3 h bar */
gallonm 16:0d4776564733 67 ['^']= S0, /* use as top bar */
gallonm 16:0d4776564733 68
gallonm 16:0d4776564733 69 ['?']= NOT_7_NO_DP(S5+S3+S2),
gallonm 16:0d4776564733 70 ['*']= NOT_7_NO_DP(),
gallonm 16:0d4776564733 71 ['[']= S0+S3+S4+S5,
gallonm 16:0d4776564733 72 [']']= S0+S3+S2+S1,
gallonm 16:0d4776564733 73 ['@']= S0+S3,
gallonm 16:0d4776564733 74
gallonm 16:0d4776564733 75 ['0']= NOT_7_NO_DP(S6),
gallonm 16:0d4776564733 76 ['1']= S1+S2,
gallonm 16:0d4776564733 77 ['2']= S0+S1+S6+S4+S3,
gallonm 16:0d4776564733 78 ['3']= NOT_7_NO_DP(S4+S5),
gallonm 16:0d4776564733 79 ['4']= S5+S1+S6+S2,
gallonm 16:0d4776564733 80 ['5']= NOT_7_NO_DP(S1+S4),
gallonm 16:0d4776564733 81 ['6']= NOT_7_NO_DP(S1),
gallonm 16:0d4776564733 82 ['7']= S0+S1+S2,
gallonm 16:0d4776564733 83 ['8']= NOT_7_NO_DP(0),
gallonm 16:0d4776564733 84 ['9']= NOT_7_NO_DP(S4),
gallonm 16:0d4776564733 85
gallonm 16:0d4776564733 86 ['a']= S2+ S3+ S4+ S6 ,
gallonm 16:0d4776564733 87 ['b']= NOT_7_NO_DP(S0+S1),
gallonm 16:0d4776564733 88 ['c']= S6+S4+S3,
gallonm 16:0d4776564733 89 ['d']= NOT_7_NO_DP(S0+S5),
gallonm 16:0d4776564733 90 ['e']= NOT_7_NO_DP(S2),
gallonm 16:0d4776564733 91 ['f']= S6+S5+S4+S0, /* same as F */
gallonm 16:0d4776564733 92 ['g']= NOT_7_NO_DP(S4), /* same as 9 */
gallonm 16:0d4776564733 93 ['h']= S6+S5+S4+S2,
gallonm 16:0d4776564733 94 ['i']= S4,
gallonm 16:0d4776564733 95 ['j']= S1+S2+S3+S4,
gallonm 16:0d4776564733 96 ['k']= S6+S5+S4+S2, /* a h */
gallonm 16:0d4776564733 97 ['l']= S3+S4,
gallonm 16:0d4776564733 98 ['m']= S0+S4+S2, /* same as */
gallonm 16:0d4776564733 99 ['n']= S2+S4+S6,
gallonm 16:0d4776564733 100 ['o']= S6+S4+S3+S2,
gallonm 16:0d4776564733 101 ['p']= NOT_7_NO_DP(S3+S2), // same as P
gallonm 16:0d4776564733 102 ['q']= S0+S1+S2+S5+S6,
gallonm 16:0d4776564733 103 ['r']= S4+S6,
gallonm 16:0d4776564733 104 ['s']= NOT_7_NO_DP(S1+S4),
gallonm 16:0d4776564733 105 ['t']= NOT_7_NO_DP(S0+S1+S2),
gallonm 16:0d4776564733 106 ['u']= S4+S3+S2+S5+S1, // U
gallonm 16:0d4776564733 107 ['v']= S4+S3+S2, // is u but u use U
gallonm 16:0d4776564733 108 ['w']= S1+S3+S5,
gallonm 16:0d4776564733 109 ['x']= NOT_7_NO_DP(S0+S3), // similar to H
gallonm 16:0d4776564733 110 ['y']= NOT_7_NO_DP(S0+S4),
gallonm 16:0d4776564733 111 ['z']= S0+S1+S6+S4+S3, // same as 2
gallonm 16:0d4776564733 112
gallonm 16:0d4776564733 113 ['A']= NOT_7_NO_DP(S3),
gallonm 16:0d4776564733 114 ['B']= NOT_7_NO_DP(S0+S1), /* as b */
gallonm 16:0d4776564733 115 ['C']= S0+S3+S4+S5, // same as [
gallonm 16:0d4776564733 116 ['E']= NOT_7_NO_DP(S1+S2),
gallonm 16:0d4776564733 117 ['F']= S6+S5+S4+S0,
gallonm 16:0d4776564733 118 ['G']= NOT_7_NO_DP(S4), /* same as 9 */
gallonm 16:0d4776564733 119 ['H']= NOT_7_NO_DP(S0+S3),
gallonm 16:0d4776564733 120 ['I']= S1+S2,
gallonm 16:0d4776564733 121 ['J']= S1+S2+S3+S4,
gallonm 16:0d4776564733 122 ['K']= NOT_7_NO_DP(S0+S3), /* same as H */
gallonm 16:0d4776564733 123 ['L']= S3+S4+S5,
gallonm 16:0d4776564733 124 ['M']= S0+S4+S2, /* same as m*/
gallonm 16:0d4776564733 125 ['N']= S2+S4+S6, /* same as n*/
gallonm 16:0d4776564733 126 ['O']= NOT_7_NO_DP(S6),
gallonm 16:0d4776564733 127 ['P']= S0+S1+S2+S5+S6, // sames as 'q'
gallonm 16:0d4776564733 128 ['Q']= NOT_7_NO_DP(S3+S2),
gallonm 16:0d4776564733 129 ['R']= S4+S6,
gallonm 16:0d4776564733 130 ['S']= NOT_7_NO_DP(S1+S4), /* sasme as 5 */
gallonm 16:0d4776564733 131 ['T']= NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
gallonm 16:0d4776564733 132 ['U']= NOT_7_NO_DP(S6+S0),
gallonm 16:0d4776564733 133 ['V']= S4+S3+S2, // is u but u use U
gallonm 16:0d4776564733 134 ['W']= S1+S3+S5,
gallonm 16:0d4776564733 135 ['X']= NOT_7_NO_DP(S0+S3), // similar to H
gallonm 16:0d4776564733 136 ['Y']= NOT_7_NO_DP(S0+S4),
gallonm 16:0d4776564733 137 ['Z']= S0+S1+S6+S4+S3, // same as 2
gallonm 16:0d4776564733 138 };
gallonm 16:0d4776564733 139
gallonm 16:0d4776564733 140 #undef S0
gallonm 16:0d4776564733 141 #undef S1
gallonm 16:0d4776564733 142 #undef S2
gallonm 16:0d4776564733 143 #undef S3
gallonm 16:0d4776564733 144 #undef S4
gallonm 16:0d4776564733 145 #undef S5
gallonm 16:0d4776564733 146 #undef S6
gallonm 16:0d4776564733 147 #undef DP
gallonm 16:0d4776564733 148
gallonm 16:0d4776564733 149 #define DISPLAY_DELAY 1 // in mSec
gallonm 7:2dc81120c917 150
gallonm 7:2dc81120c917 151 /* Classes -------------------------------------------------------------------*/
gallonm 16:0d4776564733 152 /** Class representing Display
gallonm 16:0d4776564733 153 */
licio.mapelli@st.com 33:1573db91352c 154
gallonm 16:0d4776564733 155 class Display
gallonm 7:2dc81120c917 156 {
gallonm 7:2dc81120c917 157 public:
mapellil 36:f6278b3e7c82 158 /** Constructor
mapellil 36:f6278b3e7c82 159 * @param[in] &stmpe_1600 device handler to be used for display control
mapellil 36:f6278b3e7c82 160 */
mapellil 36:f6278b3e7c82 161 Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
mapellil 36:f6278b3e7c82 162 stmpe1600.setGPIOdir (GPIO_7, OUTPUT); // Digit1
mapellil 36:f6278b3e7c82 163 stmpe1600.setGPIOdir (GPIO_8, OUTPUT); // Digit2
mapellil 36:f6278b3e7c82 164 stmpe1600.setGPIOdir (GPIO_9, OUTPUT); // Digit3
mapellil 36:f6278b3e7c82 165 stmpe1600.setGPIOdir (GPIO_10, OUTPUT); // Digit4
licio.mapelli@st.com 33:1573db91352c 166
mapellil 36:f6278b3e7c82 167 stmpe1600.setGPIOdir (GPIO_0, OUTPUT); // SegmentA
mapellil 36:f6278b3e7c82 168 stmpe1600.setGPIOdir (GPIO_1, OUTPUT); // SegmentB
mapellil 36:f6278b3e7c82 169 stmpe1600.setGPIOdir (GPIO_2, OUTPUT); // SegmentC
mapellil 36:f6278b3e7c82 170 stmpe1600.setGPIOdir (GPIO_3, OUTPUT); // SegmentD
mapellil 36:f6278b3e7c82 171 stmpe1600.setGPIOdir (GPIO_4, OUTPUT); // SegmentE
mapellil 36:f6278b3e7c82 172 stmpe1600.setGPIOdir (GPIO_5, OUTPUT); // SegmentF
mapellil 36:f6278b3e7c82 173 stmpe1600.setGPIOdir (GPIO_6, OUTPUT); // SegmentG
mapellil 36:f6278b3e7c82 174 }
mapellil 36:f6278b3e7c82 175
mapellil 36:f6278b3e7c82 176 /*** Interface Methods ***/
mapellil 36:f6278b3e7c82 177 /**
mapellil 36:f6278b3e7c82 178 * @brief Print the string on display
mapellil 36:f6278b3e7c82 179 * @param[in] String to be printed
mapellil 36:f6278b3e7c82 180 * @param[in] String lenght [min 1, max 4]
mapellil 36:f6278b3e7c82 181 * @return void
mapellil 36:f6278b3e7c82 182 */
licio.mapelli@st.com 33:1573db91352c 183 void DisplayString (char str[4], char strlen)
mapellil 36:f6278b3e7c82 184 {
licio.mapelli@st.com 33:1573db91352c 185 int i, dgt;
licio.mapelli@st.com 33:1573db91352c 186 const char *pc;
licio.mapelli@st.com 33:1573db91352c 187 uint8_t data[2];
licio.mapelli@st.com 33:1573db91352c 188 uint16_t *pdata = (uint16_t*)data;
licio.mapelli@st.com 33:1573db91352c 189
licio.mapelli@st.com 33:1573db91352c 190 for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++)
licio.mapelli@st.com 33:1573db91352c 191 {
licio.mapelli@st.com 33:1573db91352c 192 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
licio.mapelli@st.com 33:1573db91352c 193 if( *(pc+1)== '.')
licio.mapelli@st.com 33:1573db91352c 194 {
licio.mapelli@st.com 33:1573db91352c 195 pc++;
licio.mapelli@st.com 33:1573db91352c 196 }
licio.mapelli@st.com 33:1573db91352c 197 wait_ms(DISPLAY_DELAY);
licio.mapelli@st.com 33:1573db91352c 198 stmpe1600.read16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 199 *pdata = *pdata | (uint16_t)0x0780; // all digits off
licio.mapelli@st.com 33:1573db91352c 200 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 201 }
licio.mapelli@st.com 33:1573db91352c 202
mapellil 36:f6278b3e7c82 203 }
mapellil 36:f6278b3e7c82 204
mapellil 36:f6278b3e7c82 205 /**
mapellil 36:f6278b3e7c82 206 * @brief Print the digit on display
mapellil 36:f6278b3e7c82 207 * @param[in] Digit value to be printed
mapellil 36:f6278b3e7c82 208 * @param[in] Digit to be used [min 0, max 3]
mapellil 36:f6278b3e7c82 209 * @return void
mapellil 36:f6278b3e7c82 210 */
mapellil 36:f6278b3e7c82 211 void DisplayDigit (char *val, char dgt)
mapellil 36:f6278b3e7c82 212 {
licio.mapelli@st.com 34:5bcffb4c5b47 213 uint8_t data[2];
licio.mapelli@st.com 34:5bcffb4c5b47 214 uint16_t *pdata = (uint16_t*)data;
licio.mapelli@st.com 34:5bcffb4c5b47 215
mapellil 36:f6278b3e7c82 216 stmpe1600.read16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 34:5bcffb4c5b47 217 *pdata = *pdata | (uint16_t)0x0780; // all digits off
mapellil 36:f6278b3e7c82 218 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 34:5bcffb4c5b47 219 _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);
mapellil 36:f6278b3e7c82 220 }
licio.mapelli@st.com 34:5bcffb4c5b47 221
mapellil 36:f6278b3e7c82 222 private:
mapellil 36:f6278b3e7c82 223 void _V2_Set7Segment( int Leds, int digit )
mapellil 36:f6278b3e7c82 224 {
licio.mapelli@st.com 33:1573db91352c 225 //Digits_off();
licio.mapelli@st.com 33:1573db91352c 226 uint16_t dgt;
licio.mapelli@st.com 33:1573db91352c 227 dgt = 1<<digit;
licio.mapelli@st.com 33:1573db91352c 228 dgt = ((uint16_t)dgt)<<7;
licio.mapelli@st.com 33:1573db91352c 229 dgt = ~dgt;
licio.mapelli@st.com 33:1573db91352c 230 uint8_t data[2];
licio.mapelli@st.com 33:1573db91352c 231 uint16_t *pdata = (uint16_t*)data;
licio.mapelli@st.com 33:1573db91352c 232
licio.mapelli@st.com 33:1573db91352c 233
licio.mapelli@st.com 33:1573db91352c 234 /* set the exppinname state to lvl */
mapellil 36:f6278b3e7c82 235 stmpe1600.read16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 236 *pdata = *pdata | (uint16_t)0x007F; // 7 segments off
mapellil 36:f6278b3e7c82 237 stmpe1600.write16bitReg(GPSR_0_7, pdata);
licio.mapelli@st.com 33:1573db91352c 238
licio.mapelli@st.com 33:1573db91352c 239 int mask=1;
licio.mapelli@st.com 33:1573db91352c 240 for (int i=0; i<7; i++)
licio.mapelli@st.com 33:1573db91352c 241 {
licio.mapelli@st.com 33:1573db91352c 242 if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;
licio.mapelli@st.com 33:1573db91352c 243 mask = mask<<1;
licio.mapelli@st.com 33:1573db91352c 244 }
licio.mapelli@st.com 33:1573db91352c 245 *pdata = *pdata & dgt;
mapellil 36:f6278b3e7c82 246 stmpe1600.write16bitReg(GPSR_0_7, pdata);
mapellil 36:f6278b3e7c82 247 }
mapellil 36:f6278b3e7c82 248 STMPE1600 &stmpe1600;
licio.mapelli@st.com 33:1573db91352c 249 };
licio.mapelli@st.com 33:1573db91352c 250
gallonm 16:0d4776564733 251 #ifdef __cplusplus
gallonm 16:0d4776564733 252 }
gallonm 16:0d4776564733 253 #endif
gallonm 17:922c88827e4d 254 #endif // __DISPLAY_H