Library for use with VL53L0X, cut 1.1, based on mass-market API v1.1.

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   ConcorsoFinal HelloWorld_IHM01A1 m3pi_BT m3pi_LIDAR ... more

Fork of X_NUCLEO_53L0A1 by ST Expansion SW Team

X-NUCLEO-53L0A1 Proximity Sensor Expansion Board Firmware Package

Introduction

This firmware package includes Component Device Drivers and the Board Support Package for STMicroelectronics' X-NUCLEO-53L0A1 Proximity sensor expansion board based on VL53L0X.

Firmware Library

Class X_NUCLEO_53L0A1 is intended to represent the Proximity sensor expansion board with the same name.

The expansion board provides support for the following components:

  1. on-board VL53L0X proximity sensor,
  2. up to two additional VL53L0X Satellites,
  3. on-board 4-digit display

It is intentionally implemented as a singleton because only one X-NUCLEO-VL53L0A1 may be deployed at a time in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:

// Sensors expansion board singleton instance
static X_NUCLEO_53L0A1 *board = X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);

Example Applications

The library and sample application code were tested against mbed revision 143, dated 26th May 2017.

Committer:
mapellil
Date:
Mon Dec 18 09:52:09 2017 +0000
Revision:
21:99c367e8a402
Parent:
17:f8187a3fa36e
Updated 53L0 lib

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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 */
mapellil 21:99c367e8a402 333 //<<<<<<< local
nikapov 17:f8187a3fa36e 334 Display(Stmpe1600 *stmpe_1600_exp0, Stmpe1600 *stmpe_1600_exp1) : stmpe1600_exp0(stmpe_1600_exp0),
johnAlexander 14:8320b5ff96fa 335 stmpe1600_exp1(stmpe_1600_exp1)
mapellil 21:99c367e8a402 336 //=======
mapellil 21:99c367e8a402 337 // Display(Stmpe1600 &stmpe_1600_exp0, Stmpe1600 &stmpe_1600_exp1) : stmpe1600_exp0(&stmpe_1600_exp0),
mapellil 21:99c367e8a402 338 // stmpe1600_exp1(&stmpe_1600_exp1)
mapellil 21:99c367e8a402 339 //>>>>>>> other
johnAlexander 14:8320b5ff96fa 340 {
johnAlexander 14:8320b5ff96fa 341 uint16_t expander_data;
johnAlexander 0:c523920bcc09 342
johnAlexander 0:c523920bcc09 343 // detect the extenders
nikapov 17:f8187a3fa36e 344 stmpe1600_exp0->read_16bit_reg(0x00, &expander_data);
johnAlexander 0:c523920bcc09 345 // if (ExpanderData != 0x1600) {/* log - failed to find expander exp0 */ }
nikapov 17:f8187a3fa36e 346 stmpe1600_exp1->read_16bit_reg(0x00, &expander_data);
johnAlexander 0:c523920bcc09 347 // if (ExpanderData != 0x1600) {/* log - failed to find expander exp1 */ }
johnAlexander 0:c523920bcc09 348
johnAlexander 0:c523920bcc09 349 // configure all necessary GPIO pins as outputs
johnAlexander 14:8320b5ff96fa 350 expander_data = 0xFFFF;
nikapov 17:f8187a3fa36e 351 stmpe1600_exp0->write_16bit_reg(GPDR, &expander_data);
johnAlexander 14:8320b5ff96fa 352 expander_data = 0xBFFF; // leave bit 14 as an input, for the pushbutton, PB1.
nikapov 17:f8187a3fa36e 353 stmpe1600_exp1->write_16bit_reg(GPDR, &expander_data);
johnAlexander 0:c523920bcc09 354
johnAlexander 0:c523920bcc09 355 // shut down all segment and all device
johnAlexander 14:8320b5ff96fa 356 expander_data = 0x7F + (0x7F << 7);
nikapov 17:f8187a3fa36e 357 stmpe1600_exp0->write_16bit_reg(GPSR, &expander_data);
nikapov 17:f8187a3fa36e 358 stmpe1600_exp1->write_16bit_reg(GPSR, &expander_data);
johnAlexander 0:c523920bcc09 359 }
johnAlexander 14:8320b5ff96fa 360
johnAlexander 14:8320b5ff96fa 361 /*** Interface Methods ***/
johnAlexander 14:8320b5ff96fa 362 /**
johnAlexander 14:8320b5ff96fa 363 * @brief Print the string on display
johnAlexander 14:8320b5ff96fa 364 * @param[in] String to be printed
johnAlexander 14:8320b5ff96fa 365 * @param[in] String lenght [min 1, max 4]
johnAlexander 14:8320b5ff96fa 366 * @return void
johnAlexander 14:8320b5ff96fa 367 */
johnAlexander 14:8320b5ff96fa 368 void display_string(const char *str)
johnAlexander 0:c523920bcc09 369 {
johnAlexander 14:8320b5ff96fa 370 uint16_t expander_data;
johnAlexander 14:8320b5ff96fa 371 uint32_t segments;
johnAlexander 14:8320b5ff96fa 372 int bit_posn;
johnAlexander 0:c523920bcc09 373 int i;
johnAlexander 0:c523920bcc09 374
johnAlexander 14:8320b5ff96fa 375 for (i = 0; (i < 4 && str[i] != 0); i++) {
johnAlexander 14:8320b5ff96fa 376 segments = (uint32_t) ascii_to_display_lut[(uint8_t) str[i]];
johnAlexander 14:8320b5ff96fa 377 segments = (~segments) & 0x7F;
johnAlexander 14:8320b5ff96fa 378 bit_posn = display_bit_posn[i];
johnAlexander 14:8320b5ff96fa 379 cur_io_val.u32 &= ~(0x7F << bit_posn);
johnAlexander 14:8320b5ff96fa 380 cur_io_val.u32 |= segments << bit_posn;
johnAlexander 0:c523920bcc09 381 }
johnAlexander 0:c523920bcc09 382 /* clear unused digit */
johnAlexander 14:8320b5ff96fa 383 for (; i < 4; i++) {
johnAlexander 14:8320b5ff96fa 384 bit_posn = display_bit_posn[i];
johnAlexander 14:8320b5ff96fa 385 cur_io_val.u32 |= 0x7F << bit_posn;
johnAlexander 0:c523920bcc09 386 }
johnAlexander 0:c523920bcc09 387
johnAlexander 0:c523920bcc09 388 // stmpe1600_exp0.write16bitReg(GPSR, (uint16_t *)&CurIOVal.bytes[0]);
johnAlexander 0:c523920bcc09 389 // stmpe1600_exp1.write16bitReg(GPSR, (uint16_t *)&CurIOVal.bytes[2]);
johnAlexander 0:c523920bcc09 390
johnAlexander 0:c523920bcc09 391 // ordered low-byte/high-byte!
johnAlexander 14:8320b5ff96fa 392 cur_io_val.bytes[1] |= 0xC0; // ensure highest bits are high, as these are xshutdown pins for left & right sensors!
johnAlexander 14:8320b5ff96fa 393 expander_data = (cur_io_val.bytes[1] << 8) + cur_io_val.bytes[0];
nikapov 17:f8187a3fa36e 394 stmpe1600_exp0->write_16bit_reg(GPSR, &expander_data);
johnAlexander 14:8320b5ff96fa 395 cur_io_val.bytes[3] |= 0x80; // ensure highest bit is high, as this is xshutdown pin on central sensor!
johnAlexander 14:8320b5ff96fa 396 expander_data = (cur_io_val.bytes[3] << 8) + cur_io_val.bytes[2];
nikapov 17:f8187a3fa36e 397 stmpe1600_exp1->write_16bit_reg(GPSR, &expander_data);
johnAlexander 0:c523920bcc09 398
johnAlexander 0:c523920bcc09 399 }
johnAlexander 0:c523920bcc09 400
johnAlexander 14:8320b5ff96fa 401 void clear_display(void)
johnAlexander 0:c523920bcc09 402 {
johnAlexander 14:8320b5ff96fa 403 uint16_t expander_data;
johnAlexander 0:c523920bcc09 404
johnAlexander 14:8320b5ff96fa 405 expander_data = 0x7F + (0x7F << 7);
nikapov 17:f8187a3fa36e 406 stmpe1600_exp0->write_16bit_reg(GPSR, &expander_data);
nikapov 17:f8187a3fa36e 407 stmpe1600_exp1->write_16bit_reg(GPSR, &expander_data);
johnAlexander 0:c523920bcc09 408 }
johnAlexander 0:c523920bcc09 409
johnAlexander 0:c523920bcc09 410 };
johnAlexander 0:c523920bcc09 411
johnAlexander 0:c523920bcc09 412 #ifdef __cplusplus
johnAlexander 0:c523920bcc09 413 }
johnAlexander 0:c523920bcc09 414 #endif
johnAlexander 0:c523920bcc09 415 #endif // __DISPLAY_H