Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 /*
0003  * Copyright (C) 2021 Glider bv
0004  *
0005  * Based on include/uapi/linux/map_to_7segment.h:
0006 
0007  * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
0008  */
0009 
0010 #ifndef MAP_TO_14SEGMENT_H
0011 #define MAP_TO_14SEGMENT_H
0012 
0013 /* This file provides translation primitives and tables for the conversion
0014  * of (ASCII) characters to a 14-segments notation.
0015  *
0016  * The 14 segment's wikipedia notation below is used as standard.
0017  * See: https://en.wikipedia.org/wiki/Fourteen-segment_display
0018  *
0019  * Notation:    +---a---+
0020  *      |\  |  /|
0021  *      f h i j b
0022  *      |  \|/  |
0023  *      +-g1+-g2+
0024  *      |  /|\  |
0025  *      e k l m c
0026  *      |/  |  \|
0027  *      +---d---+
0028  *
0029  * Usage:
0030  *
0031  *   Register a map variable, and fill it with a character set:
0032  *  static SEG14_DEFAULT_MAP(map_seg14);
0033  *
0034  *
0035  *   Then use for conversion:
0036  *  seg14 = map_to_seg14(&map_seg14, some_char);
0037  *  ...
0038  *
0039  * In device drivers it is recommended, if required, to make the char map
0040  * accessible via the sysfs interface using the following scheme:
0041  *
0042  * static ssize_t map_seg14_show(struct device *dev,
0043  *               struct device_attribute *attr, char *buf)
0044  * {
0045  *  memcpy(buf, &map_seg14, sizeof(map_seg14));
0046  *  return sizeof(map_seg14);
0047  * }
0048  * static ssize_t map_seg14_store(struct device *dev,
0049  *                struct device_attribute *attr,
0050  *                const char *buf, size_t cnt)
0051  * {
0052  *  if (cnt != sizeof(map_seg14))
0053  *      return -EINVAL;
0054  *  memcpy(&map_seg14, buf, cnt);
0055  *  return cnt;
0056  * }
0057  * static DEVICE_ATTR_RW(map_seg14);
0058  */
0059 #include <linux/errno.h>
0060 #include <linux/types.h>
0061 
0062 #include <asm/byteorder.h>
0063 
0064 #define BIT_SEG14_A     0
0065 #define BIT_SEG14_B     1
0066 #define BIT_SEG14_C     2
0067 #define BIT_SEG14_D     3
0068 #define BIT_SEG14_E     4
0069 #define BIT_SEG14_F     5
0070 #define BIT_SEG14_G1        6
0071 #define BIT_SEG14_G2        7
0072 #define BIT_SEG14_H     8
0073 #define BIT_SEG14_I     9
0074 #define BIT_SEG14_J     10
0075 #define BIT_SEG14_K     11
0076 #define BIT_SEG14_L     12
0077 #define BIT_SEG14_M     13
0078 #define BIT_SEG14_RESERVED1 14
0079 #define BIT_SEG14_RESERVED2 15
0080 
0081 struct seg14_conversion_map {
0082     __be16 table[128];
0083 };
0084 
0085 static __inline__ int map_to_seg14(struct seg14_conversion_map *map, int c)
0086 {
0087     if (c < 0 || c >= sizeof(map->table) / sizeof(map->table[0]))
0088         return -EINVAL;
0089 
0090     return __be16_to_cpu(map->table[c]);
0091 }
0092 
0093 #define SEG14_CONVERSION_MAP(_name, _map)   \
0094     struct seg14_conversion_map _name = { .table = { _map } }
0095 
0096 /*
0097  * It is recommended to use a facility that allows user space to redefine
0098  * custom character sets for LCD devices. Please use a sysfs interface
0099  * as described above.
0100  */
0101 #define MAP_TO_SEG14_SYSFS_FILE "map_seg14"
0102 
0103 /*******************************************************************************
0104  * ASCII conversion table
0105  ******************************************************************************/
0106 
0107 #define _SEG14(sym, a, b, c, d, e, f, g1, g2, h, j, k, l, m, n) \
0108     __cpu_to_be16( a << BIT_SEG14_A  |  b << BIT_SEG14_B  | \
0109                c << BIT_SEG14_C  |  d << BIT_SEG14_D  | \
0110                e << BIT_SEG14_E  |  f << BIT_SEG14_F  | \
0111               g1 << BIT_SEG14_G1 | g2 << BIT_SEG14_G2 | \
0112                h << BIT_SEG14_H  |  j << BIT_SEG14_I  | \
0113                k << BIT_SEG14_J  |  l << BIT_SEG14_K  | \
0114                m << BIT_SEG14_L  |  n << BIT_SEG14_M )
0115 
0116 #define _MAP_0_32_ASCII_SEG14_NON_PRINTABLE             \
0117     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0118 
0119 #define _MAP_33_47_ASCII_SEG14_SYMBOL               \
0120     _SEG14('!', 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  \
0121     _SEG14('"', 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),  \
0122     _SEG14('#', 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0),  \
0123     _SEG14('$', 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0),  \
0124     _SEG14('%', 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0),  \
0125     _SEG14('&', 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1),  \
0126     _SEG14('\'',0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),  \
0127     _SEG14('(', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1),  \
0128     _SEG14(')', 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0),  \
0129     _SEG14('*', 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1),  \
0130     _SEG14('+', 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0),  \
0131     _SEG14(',', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),  \
0132     _SEG14('-', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0),  \
0133     _SEG14('.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),  \
0134     _SEG14('/', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0),
0135 
0136 #define _MAP_48_57_ASCII_SEG14_NUMERIC              \
0137     _SEG14('0', 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0),  \
0138     _SEG14('1', 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0),  \
0139     _SEG14('2', 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0),  \
0140     _SEG14('3', 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0),  \
0141     _SEG14('4', 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0142     _SEG14('5', 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1),  \
0143     _SEG14('6', 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0144     _SEG14('7', 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0),  \
0145     _SEG14('8', 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0146     _SEG14('9', 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0),
0147 
0148 #define _MAP_58_64_ASCII_SEG14_SYMBOL               \
0149     _SEG14(':', 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),  \
0150     _SEG14(';', 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0),  \
0151     _SEG14('<', 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1),  \
0152     _SEG14('=', 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0),  \
0153     _SEG14('>', 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0),  \
0154     _SEG14('?', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0),  \
0155     _SEG14('@', 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0),
0156 
0157 #define _MAP_65_90_ASCII_SEG14_ALPHA_UPPER          \
0158     _SEG14('A', 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0159     _SEG14('B', 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0),  \
0160     _SEG14('C', 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),  \
0161     _SEG14('D', 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),  \
0162     _SEG14('E', 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0),  \
0163     _SEG14('F', 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0),  \
0164     _SEG14('G', 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0),  \
0165     _SEG14('H', 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0166     _SEG14('I', 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),  \
0167     _SEG14('J', 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  \
0168     _SEG14('K', 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1),  \
0169     _SEG14('L', 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),  \
0170     _SEG14('M', 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0),  \
0171     _SEG14('N', 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1),  \
0172     _SEG14('O', 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),  \
0173     _SEG14('P', 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0174     _SEG14('Q', 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1),  \
0175     _SEG14('R', 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1),  \
0176     _SEG14('S', 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0),  \
0177     _SEG14('T', 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),  \
0178     _SEG14('U', 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),  \
0179     _SEG14('V', 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0),  \
0180     _SEG14('W', 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1),  \
0181     _SEG14('X', 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1),  \
0182     _SEG14('Y', 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0),  \
0183     _SEG14('Z', 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0),
0184 
0185 #define _MAP_91_96_ASCII_SEG14_SYMBOL               \
0186     _SEG14('[', 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),  \
0187     _SEG14('\\',0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),  \
0188     _SEG14(']', 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  \
0189     _SEG14('^', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1),  \
0190     _SEG14('_', 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  \
0191     _SEG14('`', 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0),
0192 
0193 #define _MAP_97_122_ASCII_SEG14_ALPHA_LOWER         \
0194     _SEG14('a', 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0),  \
0195     _SEG14('b', 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1),  \
0196     _SEG14('c', 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0),  \
0197     _SEG14('d', 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0),  \
0198     _SEG14('e', 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0),  \
0199     _SEG14('f', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0),  \
0200     _SEG14('g', 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0),  \
0201     _SEG14('h', 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0),  \
0202     _SEG14('i', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0),  \
0203     _SEG14('j', 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0),  \
0204     _SEG14('k', 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1),  \
0205     _SEG14('l', 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),  \
0206     _SEG14('m', 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0),  \
0207     _SEG14('n', 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0),  \
0208     _SEG14('o', 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0),  \
0209     _SEG14('p', 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0),  \
0210     _SEG14('q', 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0),  \
0211     _SEG14('r', 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0),  \
0212     _SEG14('s', 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1),  \
0213     _SEG14('t', 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0),  \
0214     _SEG14('u', 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),  \
0215     _SEG14('v', 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0),  \
0216     _SEG14('w', 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1),  \
0217     _SEG14('x', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1),  \
0218     _SEG14('y', 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0),  \
0219     _SEG14('z', 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0),
0220 
0221 #define _MAP_123_126_ASCII_SEG14_SYMBOL             \
0222     _SEG14('{', 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0),  \
0223     _SEG14('|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),  \
0224     _SEG14('}', 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1),  \
0225     _SEG14('~', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0),
0226 
0227 /* Maps */
0228 #define MAP_ASCII14SEG_ALPHANUM         \
0229     _MAP_0_32_ASCII_SEG14_NON_PRINTABLE \
0230     _MAP_33_47_ASCII_SEG14_SYMBOL       \
0231     _MAP_48_57_ASCII_SEG14_NUMERIC      \
0232     _MAP_58_64_ASCII_SEG14_SYMBOL       \
0233     _MAP_65_90_ASCII_SEG14_ALPHA_UPPER  \
0234     _MAP_91_96_ASCII_SEG14_SYMBOL       \
0235     _MAP_97_122_ASCII_SEG14_ALPHA_LOWER \
0236     _MAP_123_126_ASCII_SEG14_SYMBOL
0237 
0238 #define SEG14_DEFAULT_MAP(_name)        \
0239     SEG14_CONVERSION_MAP(_name, MAP_ASCII14SEG_ALPHANUM)
0240 
0241 #endif  /* MAP_TO_14SEGMENT_H */