initial release
Components/Display/Display.h@17:f8187a3fa36e, 2017-10-10 (annotated)
- Committer:
- nikapov
- Date:
- Tue Oct 10 08:48:41 2017 +0000
- Revision:
- 17:f8187a3fa36e
- Parent:
- 16:27d3d95c8593
- Child:
- 21:99c367e8a402
Support external component.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnAlexander | 0:c523920bcc09 | 1 | /** |
johnAlexander | 0:c523920bcc09 | 2 | ****************************************************************************** |
johnAlexander | 0:c523920bcc09 | 3 | * @file Display.h |
johnAlexander | 0:c523920bcc09 | 4 | * @author AST / EST |
johnAlexander | 0:c523920bcc09 | 5 | * @version V0.0.1 |
johnAlexander | 0:c523920bcc09 | 6 | * @date 14-April-2015 |
johnAlexander | 0:c523920bcc09 | 7 | * @brief Header file for display |
johnAlexander | 0:c523920bcc09 | 8 | ****************************************************************************** |
johnAlexander | 0:c523920bcc09 | 9 | * @attention |
johnAlexander | 0:c523920bcc09 | 10 | * |
johnAlexander | 0:c523920bcc09 | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
johnAlexander | 0:c523920bcc09 | 12 | * |
johnAlexander | 0:c523920bcc09 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
johnAlexander | 0:c523920bcc09 | 14 | * are permitted provided that the following conditions are met: |
johnAlexander | 0:c523920bcc09 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
johnAlexander | 0:c523920bcc09 | 16 | * this list of conditions and the following disclaimer. |
johnAlexander | 0:c523920bcc09 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
johnAlexander | 0:c523920bcc09 | 18 | * this list of conditions and the following disclaimer in the documentation |
johnAlexander | 0:c523920bcc09 | 19 | * and/or other materials provided with the distribution. |
johnAlexander | 0:c523920bcc09 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
johnAlexander | 0:c523920bcc09 | 21 | * may be used to endorse or promote products derived from this software |
johnAlexander | 0:c523920bcc09 | 22 | * without specific prior written permission. |
johnAlexander | 0:c523920bcc09 | 23 | * |
johnAlexander | 0:c523920bcc09 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
johnAlexander | 0:c523920bcc09 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
johnAlexander | 0:c523920bcc09 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
johnAlexander | 0:c523920bcc09 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
johnAlexander | 0:c523920bcc09 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
johnAlexander | 0:c523920bcc09 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
johnAlexander | 0:c523920bcc09 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
johnAlexander | 0:c523920bcc09 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
johnAlexander | 0:c523920bcc09 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
johnAlexander | 0:c523920bcc09 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
johnAlexander | 0:c523920bcc09 | 34 | * |
johnAlexander | 0:c523920bcc09 | 35 | ****************************************************************************** |
johnAlexander | 0:c523920bcc09 | 36 | */ |
johnAlexander | 0:c523920bcc09 | 37 | |
johnAlexander | 0:c523920bcc09 | 38 | #ifndef __DISPLAY_H |
johnAlexander | 0:c523920bcc09 | 39 | #define __DISPLAY_H |
johnAlexander | 0:c523920bcc09 | 40 | |
johnAlexander | 0:c523920bcc09 | 41 | /* Includes ------------------------------------------------------------------*/ |
johnAlexander | 0:c523920bcc09 | 42 | #include "mbed.h" |
Davidroid | 16:27d3d95c8593 | 43 | #include "Stmpe1600.h" |
johnAlexander | 0:c523920bcc09 | 44 | #include "DevI2C.h" |
johnAlexander | 0:c523920bcc09 | 45 | |
johnAlexander | 0:c523920bcc09 | 46 | #ifdef __cplusplus |
johnAlexander | 0:c523920bcc09 | 47 | extern "C" { |
johnAlexander | 0:c523920bcc09 | 48 | #endif |
johnAlexander | 0:c523920bcc09 | 49 | |
johnAlexander | 0:c523920bcc09 | 50 | /** |
johnAlexander | 0:c523920bcc09 | 51 | * GPIO monitor pin state register |
johnAlexander | 0:c523920bcc09 | 52 | * 16 bit register LSB at lowest offset (little endian) |
johnAlexander | 0:c523920bcc09 | 53 | */ |
johnAlexander | 0:c523920bcc09 | 54 | #define GPMR 0x10 |
johnAlexander | 0:c523920bcc09 | 55 | /** |
johnAlexander | 0:c523920bcc09 | 56 | * STMPE1600 GPIO set pin state register |
johnAlexander | 0:c523920bcc09 | 57 | * 16 bit register LSB at lowest offset (little endian) |
johnAlexander | 0:c523920bcc09 | 58 | */ |
johnAlexander | 0:c523920bcc09 | 59 | #define GPSR 0x12 |
johnAlexander | 0:c523920bcc09 | 60 | /** |
johnAlexander | 0:c523920bcc09 | 61 | * STMPE1600 GPIO set pin direction register |
johnAlexander | 0:c523920bcc09 | 62 | * 16 bit register LSB at lowest offset |
johnAlexander | 0:c523920bcc09 | 63 | */ |
johnAlexander | 0:c523920bcc09 | 64 | #define GPDR 0x14 |
johnAlexander | 0:c523920bcc09 | 65 | |
johnAlexander | 0:c523920bcc09 | 66 | |
johnAlexander | 0:c523920bcc09 | 67 | /** |
johnAlexander | 0:c523920bcc09 | 68 | * cache the full set of expanded GPIO values to avoid i2c reading |
johnAlexander | 0:c523920bcc09 | 69 | */ |
johnAlexander | 0:c523920bcc09 | 70 | static union CurIOVal_u { |
johnAlexander | 0:c523920bcc09 | 71 | uint8_t bytes[4]; /*!< 4 bytes array i/o view */ |
johnAlexander | 0:c523920bcc09 | 72 | uint32_t u32; /*!< single dword i/o view */ |
johnAlexander | 0:c523920bcc09 | 73 | } |
johnAlexander | 0:c523920bcc09 | 74 | /** cache the extended IO values */ |
johnAlexander | 14:8320b5ff96fa | 75 | cur_io_val; |
johnAlexander | 0:c523920bcc09 | 76 | |
johnAlexander | 0:c523920bcc09 | 77 | /** |
johnAlexander | 0:c523920bcc09 | 78 | * lookup table for digit to bit position |
johnAlexander | 0:c523920bcc09 | 79 | */ |
johnAlexander | 14:8320b5ff96fa | 80 | static int display_bit_posn[4] = {0, 7, 16, 16 + 7}; |
johnAlexander | 0:c523920bcc09 | 81 | |
johnAlexander | 0:c523920bcc09 | 82 | /** |
johnAlexander | 0:c523920bcc09 | 83 | * @defgroup XNUCLEO53L0A1_7Segment 7 segment display |
johnAlexander | 0:c523920bcc09 | 84 | * |
johnAlexander | 0:c523920bcc09 | 85 | * macro use for human readable segment building |
johnAlexander | 0:c523920bcc09 | 86 | * @code |
johnAlexander | 0:c523920bcc09 | 87 | * --s0-- |
johnAlexander | 0:c523920bcc09 | 88 | * s s |
johnAlexander | 0:c523920bcc09 | 89 | * 5 1 |
johnAlexander | 0:c523920bcc09 | 90 | * --s6-- |
johnAlexander | 0:c523920bcc09 | 91 | * s s |
johnAlexander | 0:c523920bcc09 | 92 | * 4 2 |
johnAlexander | 0:c523920bcc09 | 93 | * --s3-- . s7 (dp) |
johnAlexander | 0:c523920bcc09 | 94 | * @endcode |
johnAlexander | 0:c523920bcc09 | 95 | * |
johnAlexander | 0:c523920bcc09 | 96 | * @{ |
johnAlexander | 0:c523920bcc09 | 97 | */ |
johnAlexander | 0:c523920bcc09 | 98 | /** decimal point bit mapping* */ |
johnAlexander | 14:8320b5ff96fa | 99 | #define DP (1 << 7) |
johnAlexander | 0:c523920bcc09 | 100 | |
johnAlexander | 0:c523920bcc09 | 101 | /** sgement s0 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 102 | #define S0 (1 << 3) |
johnAlexander | 0:c523920bcc09 | 103 | /** sgement s1 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 104 | #define S1 (1 << 5) |
johnAlexander | 0:c523920bcc09 | 105 | /** sgement s2 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 106 | #define S2 (1 << 6) |
johnAlexander | 0:c523920bcc09 | 107 | /** sgement s3 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 108 | #define S3 (1 << 4) |
johnAlexander | 0:c523920bcc09 | 109 | /** sgement s4 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 110 | #define S4 (1 << 0) |
johnAlexander | 0:c523920bcc09 | 111 | /** sgement s5 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 112 | #define S5 (1 << 1) |
johnAlexander | 0:c523920bcc09 | 113 | /** sgement s6 bit mapping*/ |
johnAlexander | 14:8320b5ff96fa | 114 | #define S6 (1 << 2) |
johnAlexander | 0:c523920bcc09 | 115 | |
johnAlexander | 0:c523920bcc09 | 116 | /** |
johnAlexander | 0:c523920bcc09 | 117 | * build a character by defining the non lighted segment (not one and no DP) |
johnAlexander | 0:c523920bcc09 | 118 | * |
johnAlexander | 0:c523920bcc09 | 119 | * @param ... literal sum and or combine of any macro to define any segment #S0 .. #S6 |
johnAlexander | 0:c523920bcc09 | 120 | * |
johnAlexander | 0:c523920bcc09 | 121 | * example '9' is all segment on but S4 |
johnAlexander | 0:c523920bcc09 | 122 | * @code |
johnAlexander | 0:c523920bcc09 | 123 | * ['9']= NOT_7_NO_DP(S4), |
johnAlexander | 0:c523920bcc09 | 124 | * @endcode |
johnAlexander | 0:c523920bcc09 | 125 | */ |
johnAlexander | 0:c523920bcc09 | 126 | #define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP ) |
johnAlexander | 0:c523920bcc09 | 127 | |
johnAlexander | 0:c523920bcc09 | 128 | /** |
johnAlexander | 0:c523920bcc09 | 129 | * Ascii to 7 segment lookup table |
johnAlexander | 0:c523920bcc09 | 130 | * |
johnAlexander | 0:c523920bcc09 | 131 | * Most common character are supported and follow http://www.twyman.org.uk/Fonts/ |
johnAlexander | 0:c523920bcc09 | 132 | * few extra special \@ ^~ ... etc are present for specific demo purpose |
johnAlexander | 0:c523920bcc09 | 133 | */ |
johnAlexander | 0:c523920bcc09 | 134 | #ifndef __cpluplus |
johnAlexander | 0:c523920bcc09 | 135 | /* refer to http://www.twyman.org.uk/Fonts/ */ |
johnAlexander | 14:8320b5ff96fa | 136 | static const uint8_t ascii_to_display_lut[256] = { |
johnAlexander | 14:8320b5ff96fa | 137 | 0, 0, 0, 0, 0, 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 138 | 0, 0, 0, 0, 0, 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 139 | 0, 0, 0, 0, 0, 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 140 | 0, 0, 0, 0, 0, 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 141 | [32] = 0, |
johnAlexander | 14:8320b5ff96fa | 142 | 0, 0, 0, 0, 0, 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 143 | 0, |
johnAlexander | 14:8320b5ff96fa | 144 | [42] = NOT_7_NO_DP(), |
johnAlexander | 14:8320b5ff96fa | 145 | 0, 0, |
johnAlexander | 14:8320b5ff96fa | 146 | [45] = S6, |
johnAlexander | 14:8320b5ff96fa | 147 | 0, 0, |
johnAlexander | 14:8320b5ff96fa | 148 | [48] = NOT_7_NO_DP(S6), |
johnAlexander | 14:8320b5ff96fa | 149 | [49] = S1 + S2, |
johnAlexander | 14:8320b5ff96fa | 150 | [50] = S0 + S1 + S6 + S4 + S3, |
johnAlexander | 14:8320b5ff96fa | 151 | [51] = NOT_7_NO_DP(S4 + S5), |
johnAlexander | 14:8320b5ff96fa | 152 | [52] = S5 + S1 + S6 + S2, |
johnAlexander | 14:8320b5ff96fa | 153 | [53] = NOT_7_NO_DP(S1 + S4), |
johnAlexander | 14:8320b5ff96fa | 154 | [54] = NOT_7_NO_DP(S1), |
johnAlexander | 14:8320b5ff96fa | 155 | [55] = S0 + S1 + S2, |
johnAlexander | 14:8320b5ff96fa | 156 | [56] = NOT_7_NO_DP(0), |
johnAlexander | 14:8320b5ff96fa | 157 | [57] = NOT_7_NO_DP(S4), |
johnAlexander | 14:8320b5ff96fa | 158 | 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 159 | [61] = S3 + S6, |
johnAlexander | 14:8320b5ff96fa | 160 | 0, |
johnAlexander | 14:8320b5ff96fa | 161 | [63] = NOT_7_NO_DP(S5 + S3 + S2), |
johnAlexander | 14:8320b5ff96fa | 162 | [64] = S0 + S3, |
johnAlexander | 14:8320b5ff96fa | 163 | [65] = NOT_7_NO_DP(S3), |
johnAlexander | 14:8320b5ff96fa | 164 | [66] = NOT_7_NO_DP(S0 + S1), /* as b */ |
johnAlexander | 14:8320b5ff96fa | 165 | [67] = S0 + S3 + S4 + S5, // same as [ |
johnAlexander | 14:8320b5ff96fa | 166 | [68] = S0 + S3 + S4 + S5, // same as [ DUMMY |
johnAlexander | 14:8320b5ff96fa | 167 | [69] = NOT_7_NO_DP(S1 + S2), |
johnAlexander | 14:8320b5ff96fa | 168 | [70] = S6 + S5 + S4 + S0, |
johnAlexander | 14:8320b5ff96fa | 169 | [71] = NOT_7_NO_DP(S4), /* same as 9 */ |
johnAlexander | 14:8320b5ff96fa | 170 | [72] = NOT_7_NO_DP(S0 + S3), |
johnAlexander | 14:8320b5ff96fa | 171 | [73] = S1 + S2, |
johnAlexander | 14:8320b5ff96fa | 172 | [74] = S1 + S2 + S3 + S4, |
johnAlexander | 14:8320b5ff96fa | 173 | [75] = NOT_7_NO_DP(S0 + S3), /* same as H */ |
johnAlexander | 14:8320b5ff96fa | 174 | [76] = S3 + S4 + S5, |
johnAlexander | 14:8320b5ff96fa | 175 | [77] = S0 + S4 + S2, /* same as m*/ |
johnAlexander | 14:8320b5ff96fa | 176 | [78] = S2 + S4 + S6, /* same as n*/ |
johnAlexander | 14:8320b5ff96fa | 177 | [79] = NOT_7_NO_DP(S6), |
johnAlexander | 14:8320b5ff96fa | 178 | [80] = S0 + S1 + S2 + S5 + S6, // sames as 'q' |
johnAlexander | 14:8320b5ff96fa | 179 | [81] = NOT_7_NO_DP(S3 + S2), |
johnAlexander | 14:8320b5ff96fa | 180 | [82] = S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 181 | [83] = NOT_7_NO_DP(S1 + S4), /* sasme as 5 */ |
johnAlexander | 14:8320b5ff96fa | 182 | [84] = NOT_7_NO_DP(S0 + S1 + S2), /* sasme as t */ |
johnAlexander | 14:8320b5ff96fa | 183 | [85] = NOT_7_NO_DP(S6 + S0), |
johnAlexander | 14:8320b5ff96fa | 184 | [86] = S4 + S3 + S2, // is u but u use U |
johnAlexander | 14:8320b5ff96fa | 185 | [87] = S1 + S3 + S5, |
johnAlexander | 14:8320b5ff96fa | 186 | [88] = NOT_7_NO_DP(S0 + S3), // similar to H |
johnAlexander | 14:8320b5ff96fa | 187 | [89] = NOT_7_NO_DP(S0 + S4), |
johnAlexander | 14:8320b5ff96fa | 188 | [90] = S0 + S1 + S6 + S4 + S3, // same as 2 |
johnAlexander | 14:8320b5ff96fa | 189 | [91] = S0 + S3 + S4 + S5, |
johnAlexander | 14:8320b5ff96fa | 190 | 0, |
johnAlexander | 14:8320b5ff96fa | 191 | [93] = S0 + S3 + S2 + S1, |
johnAlexander | 14:8320b5ff96fa | 192 | [94] = S0, /* use as top bar */ |
johnAlexander | 14:8320b5ff96fa | 193 | [95] = S3, |
johnAlexander | 14:8320b5ff96fa | 194 | 0, |
johnAlexander | 14:8320b5ff96fa | 195 | [97] = S2 + S3 + S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 196 | [98] = NOT_7_NO_DP(S0 + S1), |
johnAlexander | 14:8320b5ff96fa | 197 | [99] = S6 + S4 + S3, |
johnAlexander | 14:8320b5ff96fa | 198 | [100] = NOT_7_NO_DP(S0 + S5), |
johnAlexander | 14:8320b5ff96fa | 199 | [101] = NOT_7_NO_DP(S2), |
johnAlexander | 14:8320b5ff96fa | 200 | [102] = S6 + S5 + S4 + S0, /* same as F */ |
johnAlexander | 14:8320b5ff96fa | 201 | [103] = NOT_7_NO_DP(S4), /* same as 9 */ |
johnAlexander | 14:8320b5ff96fa | 202 | [104] = S6 + S5 + S4 + S2, |
johnAlexander | 14:8320b5ff96fa | 203 | [105] = S4, |
johnAlexander | 14:8320b5ff96fa | 204 | [106] = S1 + S2 + S3 + S4, |
johnAlexander | 14:8320b5ff96fa | 205 | [107] = S6 + S5 + S4 + S2, /* a h */ |
johnAlexander | 14:8320b5ff96fa | 206 | [108] = S3 + S4, |
johnAlexander | 14:8320b5ff96fa | 207 | [109] = S0 + S4 + S2, /* same as */ |
johnAlexander | 14:8320b5ff96fa | 208 | [110] = S2 + S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 209 | [111] = S6 + S4 + S3 + S2, |
johnAlexander | 14:8320b5ff96fa | 210 | [112] = NOT_7_NO_DP(S3 + S2), // same as P |
johnAlexander | 14:8320b5ff96fa | 211 | [113] = S0 + S1 + S2 + S5 + S6, |
johnAlexander | 14:8320b5ff96fa | 212 | [114] = S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 213 | [115] = NOT_7_NO_DP(S1 + S4), |
johnAlexander | 14:8320b5ff96fa | 214 | [116] = NOT_7_NO_DP(S0 + S1 + S2), |
johnAlexander | 14:8320b5ff96fa | 215 | [117] = S4 + S3 + S2 + S5 + S1, // U |
johnAlexander | 14:8320b5ff96fa | 216 | [118] = S4 + S3 + S2, // is u but u use U |
johnAlexander | 14:8320b5ff96fa | 217 | [119] = S1 + S3 + S5, |
johnAlexander | 14:8320b5ff96fa | 218 | [120] = NOT_7_NO_DP(S0 + S3), // similar to H |
johnAlexander | 14:8320b5ff96fa | 219 | [121] = NOT_7_NO_DP(S0 + S4), |
johnAlexander | 14:8320b5ff96fa | 220 | [122] = S0 + S1 + S6 + S4 + S3, // same as 2 |
johnAlexander | 14:8320b5ff96fa | 221 | 0, 0, 0, |
johnAlexander | 14:8320b5ff96fa | 222 | [126] = S0 + S3 + S6 /* 3 h bar */ |
johnAlexander | 0:c523920bcc09 | 223 | }; |
johnAlexander | 0:c523920bcc09 | 224 | #else |
johnAlexander | 0:c523920bcc09 | 225 | /* refer to http://www.twyman.org.uk/Fonts/ */ |
johnAlexander | 14:8320b5ff96fa | 226 | static const uint8_t ascii_to_display_lut[256] = { |
johnAlexander | 14:8320b5ff96fa | 227 | [' '] = 0, |
johnAlexander | 14:8320b5ff96fa | 228 | ['-'] = S6, |
johnAlexander | 14:8320b5ff96fa | 229 | ['_'] = S3, |
johnAlexander | 14:8320b5ff96fa | 230 | ['='] = S3 + S6, |
johnAlexander | 14:8320b5ff96fa | 231 | ['~'] = S0 + S3 + S6, /* 3 h bar */ |
johnAlexander | 14:8320b5ff96fa | 232 | ['^'] = S0, /* use as top bar */ |
johnAlexander | 0:c523920bcc09 | 233 | |
johnAlexander | 14:8320b5ff96fa | 234 | ['?'] = NOT_7_NO_DP(S5 + S3 + S2), |
johnAlexander | 14:8320b5ff96fa | 235 | ['*'] = NOT_7_NO_DP(), |
johnAlexander | 14:8320b5ff96fa | 236 | ['['] = S0 + S3 + S4 + S5, |
johnAlexander | 14:8320b5ff96fa | 237 | [']'] = S0 + S3 + S2 + S1, |
johnAlexander | 14:8320b5ff96fa | 238 | ['@'] = S0 + S3, |
johnAlexander | 0:c523920bcc09 | 239 | |
johnAlexander | 14:8320b5ff96fa | 240 | ['0'] = NOT_7_NO_DP(S6), |
johnAlexander | 14:8320b5ff96fa | 241 | ['1'] = S1 + S2, |
johnAlexander | 14:8320b5ff96fa | 242 | ['2'] = S0 + S1 + S6 + S4 + S3, |
johnAlexander | 14:8320b5ff96fa | 243 | ['3'] = NOT_7_NO_DP(S4 + S5), |
johnAlexander | 14:8320b5ff96fa | 244 | ['4'] = S5 + S1 + S6 + S2, |
johnAlexander | 14:8320b5ff96fa | 245 | ['5'] = NOT_7_NO_DP(S1 + S4), |
johnAlexander | 14:8320b5ff96fa | 246 | ['6'] = NOT_7_NO_DP(S1), |
johnAlexander | 14:8320b5ff96fa | 247 | ['7'] = S0 + S1 + S2, |
johnAlexander | 14:8320b5ff96fa | 248 | ['8'] = NOT_7_NO_DP(0), |
johnAlexander | 14:8320b5ff96fa | 249 | ['9'] = NOT_7_NO_DP(S4), |
johnAlexander | 0:c523920bcc09 | 250 | |
johnAlexander | 14:8320b5ff96fa | 251 | ['a'] = S2 + S3 + S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 252 | ['b'] = NOT_7_NO_DP(S0 + S1), |
johnAlexander | 14:8320b5ff96fa | 253 | ['c'] = S6 + S4 + S3, |
johnAlexander | 14:8320b5ff96fa | 254 | ['d'] = NOT_7_NO_DP(S0 + S5), |
johnAlexander | 14:8320b5ff96fa | 255 | ['e'] = NOT_7_NO_DP(S2), |
johnAlexander | 14:8320b5ff96fa | 256 | ['f'] = S6 + S5 + S4 + S0, /* same as F */ |
johnAlexander | 14:8320b5ff96fa | 257 | ['g'] = NOT_7_NO_DP(S4), /* same as 9 */ |
johnAlexander | 14:8320b5ff96fa | 258 | ['h'] = S6 + S5 + S4 + S2, |
johnAlexander | 14:8320b5ff96fa | 259 | ['i'] = S4, |
johnAlexander | 14:8320b5ff96fa | 260 | ['j'] = S1 + S2 + S3 + S4, |
johnAlexander | 14:8320b5ff96fa | 261 | ['k'] = S6 + S5 + S4 + S2, /* a h */ |
johnAlexander | 14:8320b5ff96fa | 262 | ['l'] = S3 + S4, |
johnAlexander | 14:8320b5ff96fa | 263 | ['m'] = S0 + S4 + S2, /* same as */ |
johnAlexander | 14:8320b5ff96fa | 264 | ['n'] = S2 + S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 265 | ['o'] = S6 + S4 + S3 + S2, |
johnAlexander | 14:8320b5ff96fa | 266 | ['p'] = NOT_7_NO_DP(S3 + S2), // same as P |
johnAlexander | 14:8320b5ff96fa | 267 | ['q'] = S0 + S1 + S2 + S5 + S6, |
johnAlexander | 14:8320b5ff96fa | 268 | ['r'] = S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 269 | ['s'] = NOT_7_NO_DP(S1 + S4), |
johnAlexander | 14:8320b5ff96fa | 270 | ['t'] = NOT_7_NO_DP(S0 + S1 + S2), |
johnAlexander | 14:8320b5ff96fa | 271 | ['u'] = S4 + S3 + S2 + S5 + S1, // U |
johnAlexander | 14:8320b5ff96fa | 272 | ['v'] = S4 + S3 + S2, // is u but u use U |
johnAlexander | 14:8320b5ff96fa | 273 | ['w'] = S1 + S3 + S5, |
johnAlexander | 14:8320b5ff96fa | 274 | ['x'] = NOT_7_NO_DP(S0 + S3), // similar to H |
johnAlexander | 14:8320b5ff96fa | 275 | ['y'] = NOT_7_NO_DP(S0 + S4), |
johnAlexander | 14:8320b5ff96fa | 276 | ['z'] = S0 + S1 + S6 + S4 + S3, // same as 2 |
johnAlexander | 0:c523920bcc09 | 277 | |
johnAlexander | 14:8320b5ff96fa | 278 | ['A'] = NOT_7_NO_DP(S3), |
johnAlexander | 14:8320b5ff96fa | 279 | ['B'] = NOT_7_NO_DP(S0 + S1), /* as b */ |
johnAlexander | 14:8320b5ff96fa | 280 | ['C'] = S0 + S3 + S4 + S5, // same as [ |
johnAlexander | 14:8320b5ff96fa | 281 | ['E'] = NOT_7_NO_DP(S1 + S2), |
johnAlexander | 14:8320b5ff96fa | 282 | ['F'] = S6 + S5 + S4 + S0, |
johnAlexander | 14:8320b5ff96fa | 283 | ['G'] = NOT_7_NO_DP(S4), /* same as 9 */ |
johnAlexander | 14:8320b5ff96fa | 284 | ['H'] = NOT_7_NO_DP(S0 + S3), |
johnAlexander | 14:8320b5ff96fa | 285 | ['I'] = S1 + S2, |
johnAlexander | 14:8320b5ff96fa | 286 | ['J'] = S1 + S2 + S3 + S4, |
johnAlexander | 14:8320b5ff96fa | 287 | ['K'] = NOT_7_NO_DP(S0 + S3), /* same as H */ |
johnAlexander | 14:8320b5ff96fa | 288 | ['L'] = S3 + S4 + S5, |
johnAlexander | 14:8320b5ff96fa | 289 | ['M'] = S0 + S4 + S2, /* same as m*/ |
johnAlexander | 14:8320b5ff96fa | 290 | ['N'] = S2 + S4 + S6, /* same as n*/ |
johnAlexander | 14:8320b5ff96fa | 291 | ['O'] = NOT_7_NO_DP(S6), |
johnAlexander | 14:8320b5ff96fa | 292 | ['P'] = S0 + S1 + S2 + S5 + S6, // sames as 'q' |
johnAlexander | 14:8320b5ff96fa | 293 | ['Q'] = NOT_7_NO_DP(S3 + S2), |
johnAlexander | 14:8320b5ff96fa | 294 | ['R'] = S4 + S6, |
johnAlexander | 14:8320b5ff96fa | 295 | ['S'] = NOT_7_NO_DP(S1 + S4), /* sasme as 5 */ |
johnAlexander | 14:8320b5ff96fa | 296 | ['T'] = NOT_7_NO_DP(S0 + S1 + S2), /* sasme as t */ |
johnAlexander | 14:8320b5ff96fa | 297 | ['U'] = NOT_7_NO_DP(S6 + S0), |
johnAlexander | 14:8320b5ff96fa | 298 | ['V'] = S4 + S3 + S2, // is u but u use U |
johnAlexander | 14:8320b5ff96fa | 299 | ['W'] = S1 + S3 + S5, |
johnAlexander | 14:8320b5ff96fa | 300 | ['X'] = NOT_7_NO_DP(S0 + S3), // similar to H |
johnAlexander | 14:8320b5ff96fa | 301 | ['Y'] = NOT_7_NO_DP(S0 + S4), |
johnAlexander | 14:8320b5ff96fa | 302 | ['Z'] = S0 + S1 + S6 + S4 + S3 // same as 2 |
johnAlexander | 0:c523920bcc09 | 303 | }; |
johnAlexander | 0:c523920bcc09 | 304 | #endif |
johnAlexander | 0:c523920bcc09 | 305 | |
johnAlexander | 0:c523920bcc09 | 306 | |
johnAlexander | 0:c523920bcc09 | 307 | #undef S0 |
johnAlexander | 0:c523920bcc09 | 308 | #undef S1 |
johnAlexander | 0:c523920bcc09 | 309 | #undef S2 |
johnAlexander | 0:c523920bcc09 | 310 | #undef S3 |
johnAlexander | 0:c523920bcc09 | 311 | #undef S4 |
johnAlexander | 0:c523920bcc09 | 312 | #undef S5 |
johnAlexander | 0:c523920bcc09 | 313 | #undef S6 |
johnAlexander | 0:c523920bcc09 | 314 | #undef DP |
johnAlexander | 0:c523920bcc09 | 315 | |
johnAlexander | 0:c523920bcc09 | 316 | /** @} */ |
johnAlexander | 0:c523920bcc09 | 317 | |
johnAlexander | 14:8320b5ff96fa | 318 | //#define DISPLAY_DELAY 1 // in mSec |
johnAlexander | 0:c523920bcc09 | 319 | |
johnAlexander | 0:c523920bcc09 | 320 | /* Classes -------------------------------------------------------------------*/ |
johnAlexander | 0:c523920bcc09 | 321 | /** Class representing Display |
johnAlexander | 14:8320b5ff96fa | 322 | */ |
johnAlexander | 0:c523920bcc09 | 323 | |
johnAlexander | 0:c523920bcc09 | 324 | class Display |
johnAlexander | 0:c523920bcc09 | 325 | { |
johnAlexander | 0:c523920bcc09 | 326 | private: |
nikapov | 17:f8187a3fa36e | 327 | Stmpe1600 *stmpe1600_exp0; |
nikapov | 17:f8187a3fa36e | 328 | Stmpe1600 *stmpe1600_exp1; |
johnAlexander | 0:c523920bcc09 | 329 | public: |
johnAlexander | 14:8320b5ff96fa | 330 | /** Constructor |
johnAlexander | 14:8320b5ff96fa | 331 | * @param[in] &stmpe_1600 device handler to be used for display control |
johnAlexander | 14:8320b5ff96fa | 332 | */ |
nikapov | 17:f8187a3fa36e | 333 | Display(Stmpe1600 *stmpe_1600_exp0, Stmpe1600 *stmpe_1600_exp1) : stmpe1600_exp0(stmpe_1600_exp0), |
johnAlexander | 14:8320b5ff96fa | 334 | stmpe1600_exp1(stmpe_1600_exp1) |
johnAlexander | 14:8320b5ff96fa | 335 | { |
johnAlexander | 14:8320b5ff96fa | 336 | uint16_t expander_data; |
johnAlexander | 0:c523920bcc09 | 337 | |
johnAlexander | 0:c523920bcc09 | 338 | // detect the extenders |
nikapov | 17:f8187a3fa36e | 339 | stmpe1600_exp0->read_16bit_reg(0x00, &expander_data); |
johnAlexander | 0:c523920bcc09 | 340 | // if (ExpanderData != 0x1600) {/* log - failed to find expander exp0 */ } |
nikapov | 17:f8187a3fa36e | 341 | stmpe1600_exp1->read_16bit_reg(0x00, &expander_data); |
johnAlexander | 0:c523920bcc09 | 342 | // if (ExpanderData != 0x1600) {/* log - failed to find expander exp1 */ } |
johnAlexander | 0:c523920bcc09 | 343 | |
johnAlexander | 0:c523920bcc09 | 344 | // configure all necessary GPIO pins as outputs |
johnAlexander | 14:8320b5ff96fa | 345 | expander_data = 0xFFFF; |
nikapov | 17:f8187a3fa36e | 346 | stmpe1600_exp0->write_16bit_reg(GPDR, &expander_data); |
johnAlexander | 14:8320b5ff96fa | 347 | expander_data = 0xBFFF; // leave bit 14 as an input, for the pushbutton, PB1. |
nikapov | 17:f8187a3fa36e | 348 | stmpe1600_exp1->write_16bit_reg(GPDR, &expander_data); |
johnAlexander | 0:c523920bcc09 | 349 | |
johnAlexander | 0:c523920bcc09 | 350 | // shut down all segment and all device |
johnAlexander | 14:8320b5ff96fa | 351 | expander_data = 0x7F + (0x7F << 7); |
nikapov | 17:f8187a3fa36e | 352 | stmpe1600_exp0->write_16bit_reg(GPSR, &expander_data); |
nikapov | 17:f8187a3fa36e | 353 | stmpe1600_exp1->write_16bit_reg(GPSR, &expander_data); |
johnAlexander | 0:c523920bcc09 | 354 | } |
johnAlexander | 14:8320b5ff96fa | 355 | |
johnAlexander | 14:8320b5ff96fa | 356 | /*** Interface Methods ***/ |
johnAlexander | 14:8320b5ff96fa | 357 | /** |
johnAlexander | 14:8320b5ff96fa | 358 | * @brief Print the string on display |
johnAlexander | 14:8320b5ff96fa | 359 | * @param[in] String to be printed |
johnAlexander | 14:8320b5ff96fa | 360 | * @param[in] String lenght [min 1, max 4] |
johnAlexander | 14:8320b5ff96fa | 361 | * @return void |
johnAlexander | 14:8320b5ff96fa | 362 | */ |
johnAlexander | 14:8320b5ff96fa | 363 | void display_string(const char *str) |
johnAlexander | 0:c523920bcc09 | 364 | { |
johnAlexander | 14:8320b5ff96fa | 365 | uint16_t expander_data; |
johnAlexander | 14:8320b5ff96fa | 366 | uint32_t segments; |
johnAlexander | 14:8320b5ff96fa | 367 | int bit_posn; |
johnAlexander | 0:c523920bcc09 | 368 | int i; |
johnAlexander | 0:c523920bcc09 | 369 | |
johnAlexander | 14:8320b5ff96fa | 370 | for (i = 0; (i < 4 && str[i] != 0); i++) { |
johnAlexander | 14:8320b5ff96fa | 371 | segments = (uint32_t) ascii_to_display_lut[(uint8_t) str[i]]; |
johnAlexander | 14:8320b5ff96fa | 372 | segments = (~segments) & 0x7F; |
johnAlexander | 14:8320b5ff96fa | 373 | bit_posn = display_bit_posn[i]; |
johnAlexander | 14:8320b5ff96fa | 374 | cur_io_val.u32 &= ~(0x7F << bit_posn); |
johnAlexander | 14:8320b5ff96fa | 375 | cur_io_val.u32 |= segments << bit_posn; |
johnAlexander | 0:c523920bcc09 | 376 | } |
johnAlexander | 0:c523920bcc09 | 377 | /* clear unused digit */ |
johnAlexander | 14:8320b5ff96fa | 378 | for (; i < 4; i++) { |
johnAlexander | 14:8320b5ff96fa | 379 | bit_posn = display_bit_posn[i]; |
johnAlexander | 14:8320b5ff96fa | 380 | cur_io_val.u32 |= 0x7F << bit_posn; |
johnAlexander | 0:c523920bcc09 | 381 | } |
johnAlexander | 0:c523920bcc09 | 382 | |
johnAlexander | 0:c523920bcc09 | 383 | // stmpe1600_exp0.write16bitReg(GPSR, (uint16_t *)&CurIOVal.bytes[0]); |
johnAlexander | 0:c523920bcc09 | 384 | // stmpe1600_exp1.write16bitReg(GPSR, (uint16_t *)&CurIOVal.bytes[2]); |
johnAlexander | 0:c523920bcc09 | 385 | |
johnAlexander | 0:c523920bcc09 | 386 | // ordered low-byte/high-byte! |
johnAlexander | 14:8320b5ff96fa | 387 | cur_io_val.bytes[1] |= 0xC0; // ensure highest bits are high, as these are xshutdown pins for left & right sensors! |
johnAlexander | 14:8320b5ff96fa | 388 | expander_data = (cur_io_val.bytes[1] << 8) + cur_io_val.bytes[0]; |
nikapov | 17:f8187a3fa36e | 389 | stmpe1600_exp0->write_16bit_reg(GPSR, &expander_data); |
johnAlexander | 14:8320b5ff96fa | 390 | cur_io_val.bytes[3] |= 0x80; // ensure highest bit is high, as this is xshutdown pin on central sensor! |
johnAlexander | 14:8320b5ff96fa | 391 | expander_data = (cur_io_val.bytes[3] << 8) + cur_io_val.bytes[2]; |
nikapov | 17:f8187a3fa36e | 392 | stmpe1600_exp1->write_16bit_reg(GPSR, &expander_data); |
johnAlexander | 0:c523920bcc09 | 393 | |
johnAlexander | 0:c523920bcc09 | 394 | } |
johnAlexander | 0:c523920bcc09 | 395 | |
johnAlexander | 14:8320b5ff96fa | 396 | void clear_display(void) |
johnAlexander | 0:c523920bcc09 | 397 | { |
johnAlexander | 14:8320b5ff96fa | 398 | uint16_t expander_data; |
johnAlexander | 0:c523920bcc09 | 399 | |
johnAlexander | 14:8320b5ff96fa | 400 | expander_data = 0x7F + (0x7F << 7); |
nikapov | 17:f8187a3fa36e | 401 | stmpe1600_exp0->write_16bit_reg(GPSR, &expander_data); |
nikapov | 17:f8187a3fa36e | 402 | stmpe1600_exp1->write_16bit_reg(GPSR, &expander_data); |
johnAlexander | 0:c523920bcc09 | 403 | } |
johnAlexander | 0:c523920bcc09 | 404 | |
johnAlexander | 0:c523920bcc09 | 405 | }; |
johnAlexander | 0:c523920bcc09 | 406 | |
johnAlexander | 0:c523920bcc09 | 407 | #ifdef __cplusplus |
johnAlexander | 0:c523920bcc09 | 408 | } |
johnAlexander | 0:c523920bcc09 | 409 | #endif |
johnAlexander | 0:c523920bcc09 | 410 | #endif // __DISPLAY_H |