Librairie adaptée au laboratoire 2

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Display.h Source File

Display.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    Display.h
00004  * @author  AST / EST
00005  * @version V0.0.1
00006  * @date    14-April-2015
00007  * @brief   Header file for display
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *       without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036 */
00037 
00038 
00039 #ifndef __DISPLAY_H
00040 #define __DISPLAY_H
00041 
00042 
00043 /* Includes ------------------------------------------------------------------*/
00044 
00045 #include "mbed.h"
00046 #include "STMPE1600.h"
00047 #include "DevI2C.h"
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 #define DP  (1<<7)
00054 #define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP )
00055 #define S0 (1<<0)
00056 #define S1 (1<<1)
00057 #define S2 (1<<2)
00058 #define S3 (1<<3)
00059 #define S4 (1<<4)
00060 #define S5 (1<<5)
00061 #define S6 (1<<6)
00062 
00063 #ifndef __cpluplus  
00064 /* refer to http://www.twyman.org.uk/Fonts/ */
00065 static const uint8_t ascii_to_display_lut[256]={
00066     0,0,0,0,0,0,0,0,
00067     0,0,0,0,0,0,0,0,
00068     0,0,0,0,0,0,0,0,
00069     0,0,0,0,0,0,0,0,
00070     [32]=           0,
00071     0,0,0,0,0,0,0,0,
00072     0,
00073     [42]=           NOT_7_NO_DP(),
00074     0,0,
00075     [45]=           S6,
00076     0,0,
00077     [48]=           NOT_7_NO_DP(S6),
00078     [49]=           S1+S2,
00079     [50]=           S0+S1+S6+S4+S3,
00080     [51]=           NOT_7_NO_DP(S4+S5),
00081     [52]=           S5+S1+S6+S2,
00082     [53]=           NOT_7_NO_DP(S1+S4),
00083     [54]=           NOT_7_NO_DP(S1),
00084     [55]=           S0+S1+S2,
00085     [56]=           NOT_7_NO_DP(0),
00086     [57]=           NOT_7_NO_DP(S4),
00087     0,0,0,
00088     [61]=           S3+S6,
00089     0,
00090     [63]=           NOT_7_NO_DP(S5+S3+S2),
00091     [64]=           S0+S3,
00092     [65]=           NOT_7_NO_DP(S3),
00093     [66]=           NOT_7_NO_DP(S0+S1), /* as b  */
00094     [67]=           S0+S3+S4+S5, // same as [
00095     [68]=           S0+S3+S4+S5, // same as [ DUMMY
00096     [69]=           NOT_7_NO_DP(S1+S2),
00097     [70]=           S6+S5+S4+S0,
00098     [71]=           NOT_7_NO_DP(S4), /* same as 9 */
00099     [72]=           NOT_7_NO_DP(S0+S3),
00100     [73]=           S1+S2,
00101     [74]=           S1+S2+S3+S4,
00102     [75]=           NOT_7_NO_DP(S0+S3), /* same as H */
00103     [76]=           S3+S4+S5,
00104     [77]=           S0+S4+S2, /* same as  m*/
00105     [78]=           S2+S4+S6, /* same as n*/
00106     [79]=           NOT_7_NO_DP(S6),
00107     [80]=           S0+S1+S2+S5+S6, // sames as 'q'
00108     [81]=           NOT_7_NO_DP(S3+S2),
00109     [82]=           S4+S6,
00110     [83]=           NOT_7_NO_DP(S1+S4), /* sasme as 5 */
00111     [84]=           NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
00112     [85]=           NOT_7_NO_DP(S6+S0),
00113     [86]=           S4+S3+S2, // is u but u use U
00114     [87]=           S1+S3+S5,
00115     [88]=           NOT_7_NO_DP(S0+S3), // similar to H
00116     [89]=           NOT_7_NO_DP(S0+S4),
00117     [90]=           S0+S1+S6+S4+S3, // same as 2
00118     [91]=           S0+S3+S4+S5,
00119     0,
00120     [93]=           S0+S3+S2+S1,
00121     [94]=           S0, /* use as top bar */
00122     [95]=           S3, 
00123     0,
00124     [97]=           S2+ S3+ S4+ S6 ,
00125     [98]=           NOT_7_NO_DP(S0+S1),
00126     [99]=           S6+S4+S3,
00127     [100]=           NOT_7_NO_DP(S0+S5),
00128     [101]=           NOT_7_NO_DP(S2),
00129     [102]=           S6+S5+S4+S0, /* same as F */
00130     [103]=           NOT_7_NO_DP(S4), /* same as 9 */
00131     [104]=           S6+S5+S4+S2,
00132     [105]=           S4,
00133     [106]=           S1+S2+S3+S4,
00134     [107]=           S6+S5+S4+S2, /* a h */
00135     [108]=           S3+S4,
00136     [109]=           S0+S4+S2, /* same as  */
00137     [110]=           S2+S4+S6,
00138     [111]=           S6+S4+S3+S2,
00139     [112]=           NOT_7_NO_DP(S3+S2), // same as P
00140     [113]=           S0+S1+S2+S5+S6,
00141     [114]=           S4+S6,
00142     [115]=           NOT_7_NO_DP(S1+S4),
00143     [116]=           NOT_7_NO_DP(S0+S1+S2),
00144     [117]=           S4+S3+S2+S5+S1, // U
00145     [118]=           S4+S3+S2, // is u but u use U
00146     [119]=           S1+S3+S5,
00147     [120]=           NOT_7_NO_DP(S0+S3), // similar to H
00148     [121]=           NOT_7_NO_DP(S0+S4),
00149     [122]=           S0+S1+S6+S4+S3, // same as 2
00150     0,0,0,
00151     [126]=           S0+S3+S6 /* 3 h bar */
00152 };
00153 #else 
00154 /* refer to http://www.twyman.org.uk/Fonts/ */
00155 static const uint8_t ascii_to_display_lut[256]={
00156       [' ']=           0,
00157       ['-']=           S6,
00158       ['_']=           S3,
00159       ['=']=           S3+S6,
00160       ['~']=           S0+S3+S6, /* 3 h bar */
00161       ['^']=           S0, /* use as top bar */
00162 
00163       ['?']=           NOT_7_NO_DP(S5+S3+S2),
00164       ['*']=           NOT_7_NO_DP(),
00165       ['[']=           S0+S3+S4+S5,
00166       [']']=           S0+S3+S2+S1,
00167       ['@']=           S0+S3,
00168 
00169       ['0']=           NOT_7_NO_DP(S6),
00170       ['1']=           S1+S2,
00171       ['2']=           S0+S1+S6+S4+S3,
00172       ['3']=           NOT_7_NO_DP(S4+S5),
00173       ['4']=           S5+S1+S6+S2,
00174       ['5']=           NOT_7_NO_DP(S1+S4),
00175       ['6']=           NOT_7_NO_DP(S1),
00176       ['7']=           S0+S1+S2,
00177       ['8']=           NOT_7_NO_DP(0),
00178       ['9']=           NOT_7_NO_DP(S4),
00179     
00180       ['a']=           S2+ S3+ S4+ S6 ,
00181       ['b']=           NOT_7_NO_DP(S0+S1),
00182       ['c']=           S6+S4+S3,
00183       ['d']=           NOT_7_NO_DP(S0+S5),
00184       ['e']=           NOT_7_NO_DP(S2),
00185       ['f']=           S6+S5+S4+S0, /* same as F */
00186       ['g']=           NOT_7_NO_DP(S4), /* same as 9 */
00187       ['h']=           S6+S5+S4+S2,
00188       ['i']=           S4,
00189       ['j']=           S1+S2+S3+S4,
00190       ['k']=           S6+S5+S4+S2, /* a h */
00191       ['l']=           S3+S4,
00192       ['m']=           S0+S4+S2, /* same as  */
00193       ['n']=           S2+S4+S6,
00194       ['o']=           S6+S4+S3+S2,
00195       ['p']=           NOT_7_NO_DP(S3+S2), // same as P
00196       ['q']=           S0+S1+S2+S5+S6,
00197       ['r']=           S4+S6,
00198       ['s']=           NOT_7_NO_DP(S1+S4),
00199       ['t']=           NOT_7_NO_DP(S0+S1+S2),
00200       ['u']=           S4+S3+S2+S5+S1, // U
00201       ['v']=           S4+S3+S2, // is u but u use U
00202       ['w']=           S1+S3+S5,
00203       ['x']=           NOT_7_NO_DP(S0+S3), // similar to H
00204       ['y']=           NOT_7_NO_DP(S0+S4),
00205       ['z']=           S0+S1+S6+S4+S3, // same as 2
00206       
00207       ['A']=           NOT_7_NO_DP(S3),
00208       ['B']=           NOT_7_NO_DP(S0+S1), /* as b  */
00209       ['C']=           S0+S3+S4+S5, // same as [
00210       ['E']=           NOT_7_NO_DP(S1+S2),
00211       ['F']=           S6+S5+S4+S0,
00212       ['G']=           NOT_7_NO_DP(S4), /* same as 9 */
00213       ['H']=           NOT_7_NO_DP(S0+S3),
00214       ['I']=           S1+S2,
00215       ['J']=           S1+S2+S3+S4,
00216       ['K']=           NOT_7_NO_DP(S0+S3), /* same as H */
00217       ['L']=           S3+S4+S5,
00218       ['M']=           S0+S4+S2, /* same as  m*/
00219       ['N']=           S2+S4+S6, /* same as n*/
00220       ['O']=           NOT_7_NO_DP(S6),
00221       ['P']=           S0+S1+S2+S5+S6, // sames as 'q'
00222       ['Q']=           NOT_7_NO_DP(S3+S2),
00223       ['R']=           S4+S6,
00224       ['S']=           NOT_7_NO_DP(S1+S4), /* sasme as 5 */
00225       ['T']=           NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
00226       ['U']=           NOT_7_NO_DP(S6+S0),
00227       ['V']=           S4+S3+S2, // is u but u use U
00228       ['W']=           S1+S3+S5,
00229       ['X']=           NOT_7_NO_DP(S0+S3), // similar to H
00230       ['Y']=           NOT_7_NO_DP(S0+S4),
00231       ['Z']=           S0+S1+S6+S4+S3 // same as 2
00232 };
00233 #endif
00234 
00235 #undef S0
00236 #undef S1
00237 #undef S2
00238 #undef S3
00239 #undef S4
00240 #undef S5
00241 #undef S6
00242 #undef DP
00243 
00244 #define DISPLAY_DELAY   1  // in mSec       
00245 
00246 /* Classes -------------------------------------------------------------------*/
00247 /** Class representing Display
00248  */ 
00249 
00250 class Display
00251 {
00252 public:
00253      /** Constructor
00254      * @param[in] &stmpe_1600 device handler to be used for display control
00255      */    
00256     Display(STMPE1600 &stmpe_1600) : stmpe1600(stmpe_1600) {
00257         stmpe1600.set_gpio_dir (GPIO_7,  OUTPUT);  // Digit1     
00258         stmpe1600.set_gpio_dir (GPIO_8,  OUTPUT);  // Digit2     
00259         stmpe1600.set_gpio_dir (GPIO_9,  OUTPUT);  // Digit3     
00260         stmpe1600.set_gpio_dir (GPIO_10, OUTPUT);  // Digit4         
00261      
00262         stmpe1600.set_gpio_dir (GPIO_0,  OUTPUT);  // SegmentA           
00263         stmpe1600.set_gpio_dir (GPIO_1,  OUTPUT);  // SegmentB           
00264         stmpe1600.set_gpio_dir (GPIO_2,  OUTPUT);  // SegmentC       
00265         stmpe1600.set_gpio_dir (GPIO_3,  OUTPUT);  // SegmentD       
00266         stmpe1600.set_gpio_dir (GPIO_4,  OUTPUT);  // SegmentE       
00267         stmpe1600.set_gpio_dir (GPIO_5,  OUTPUT);  // SegmentF       
00268         stmpe1600.set_gpio_dir (GPIO_6,  OUTPUT);  // SegmentG               
00269     }
00270      
00271     /*** Interface Methods ***/
00272     /**
00273      * @brief       Print the string on display
00274      * @param[in]   String to be printed
00275      * @param[in]   String lenght [min 1, max 4]
00276      * @return      void
00277      */             
00278     void display_string (char str[4], char strlen)
00279     {
00280         int i, dgt;
00281         const char *pc;
00282         uint8_t data[2];
00283         uint16_t *pdata = (uint16_t*)data;              
00284             
00285         for (i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++) {
00286             _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
00287             if ( *(pc+1)== '.') {
00288                 pc++;
00289             }
00290             wait_ms(DISPLAY_DELAY);                 
00291             stmpe1600.read_16_bit_reg(GPSR_0_7, pdata);
00292             *pdata = *pdata | (uint16_t)0x0780;             // all digits off
00293             stmpe1600.write_16_bit_reg(GPSR_0_7, pdata);
00294         }
00295     }
00296      
00297     /**
00298      * @brief       Print the digit on display
00299      * @param[in]   Digit value to be printed
00300      * @param[in]   Digit to be used [min 0, max 3]
00301      * @return      void
00302      */              
00303     void DisplayDigit (char *val, char dgt) 
00304     {
00305         uint8_t data[2];
00306         uint16_t *pdata = (uint16_t*)data;      
00307             
00308         stmpe1600.read_16_bit_reg(GPSR_0_7, pdata);
00309         *pdata = *pdata | (uint16_t)0x0780;             // all digits off
00310         stmpe1600.write_16_bit_reg(GPSR_0_7, pdata);
00311         _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);                     
00312     }       
00313         
00314 private:        
00315     void _V2_Set7Segment( int Leds, int digit )
00316     {
00317         //Digits_off();
00318         uint16_t dgt;
00319         dgt = 1<<digit;
00320         dgt = ((uint16_t)dgt)<<7;
00321         dgt = ~dgt; 
00322         uint8_t data[2];
00323         uint16_t *pdata = (uint16_t*)data;           
00324 
00325          
00326         /* set the exppinname state to lvl */
00327         stmpe1600.read_16_bit_reg(GPSR_0_7, pdata);
00328         *pdata = *pdata  | (uint16_t)0x007F;      // 7 segments off
00329         stmpe1600.write_16_bit_reg(GPSR_0_7, pdata);
00330          
00331         int mask=1;
00332         for (int i=0; i<7; i++) { 
00333             if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;  
00334             mask = mask<<1;
00335         }        
00336         *pdata = *pdata & dgt;
00337         stmpe1600.write_16_bit_reg(GPSR_0_7, pdata);
00338     }               
00339     STMPE1600 &stmpe1600;
00340 };
00341 
00342 #ifdef __cplusplus
00343 }
00344 #endif
00345 #endif // __DISPLAY_H