1*f30521d0Sdyoung /* $NetBSD: iq31244_7seg.c,v 1.5 2011/07/01 20:41:16 dyoung Exp $ */
25b9c2e62Sthorpej
35b9c2e62Sthorpej /*
45b9c2e62Sthorpej * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
55b9c2e62Sthorpej * All rights reserved.
65b9c2e62Sthorpej *
75b9c2e62Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
85b9c2e62Sthorpej *
95b9c2e62Sthorpej * Redistribution and use in source and binary forms, with or without
105b9c2e62Sthorpej * modification, are permitted provided that the following conditions
115b9c2e62Sthorpej * are met:
125b9c2e62Sthorpej * 1. Redistributions of source code must retain the above copyright
135b9c2e62Sthorpej * notice, this list of conditions and the following disclaimer.
145b9c2e62Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
155b9c2e62Sthorpej * notice, this list of conditions and the following disclaimer in the
165b9c2e62Sthorpej * documentation and/or other materials provided with the distribution.
175b9c2e62Sthorpej * 3. All advertising materials mentioning features or use of this software
185b9c2e62Sthorpej * must display the following acknowledgement:
195b9c2e62Sthorpej * This product includes software developed for the NetBSD Project by
205b9c2e62Sthorpej * Wasabi Systems, Inc.
215b9c2e62Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
225b9c2e62Sthorpej * or promote products derived from this software without specific prior
235b9c2e62Sthorpej * written permission.
245b9c2e62Sthorpej *
255b9c2e62Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
265b9c2e62Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
275b9c2e62Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
285b9c2e62Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
295b9c2e62Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
305b9c2e62Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
315b9c2e62Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
325b9c2e62Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
335b9c2e62Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
345b9c2e62Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
355b9c2e62Sthorpej * POSSIBILITY OF SUCH DAMAGE.
365b9c2e62Sthorpej */
375b9c2e62Sthorpej
385b9c2e62Sthorpej /*
395b9c2e62Sthorpej * Support for the 7-segment display on the Intel IQ31244.
405b9c2e62Sthorpej */
415b9c2e62Sthorpej
4208716eaeSlukem #include <sys/cdefs.h>
43*f30521d0Sdyoung __KERNEL_RCSID(0, "$NetBSD: iq31244_7seg.c,v 1.5 2011/07/01 20:41:16 dyoung Exp $");
4408716eaeSlukem
455b9c2e62Sthorpej #include <sys/param.h>
465b9c2e62Sthorpej #include <sys/systm.h>
475b9c2e62Sthorpej
48*f30521d0Sdyoung #include <sys/bus.h>
495b9c2e62Sthorpej
505b9c2e62Sthorpej #include <evbarm/iq80321/iq80321reg.h>
515b9c2e62Sthorpej #include <evbarm/iq80321/iq80321var.h>
525b9c2e62Sthorpej
535f1c88d7Sperry #define WRITE(x, v) *((volatile uint8_t *) (x)) = (v)
545b9c2e62Sthorpej
555b9c2e62Sthorpej static int snakestate;
565b9c2e62Sthorpej
575b9c2e62Sthorpej /*
585b9c2e62Sthorpej * The 7-segment display looks like so:
595b9c2e62Sthorpej *
605b9c2e62Sthorpej * A
615b9c2e62Sthorpej * +-----+
625b9c2e62Sthorpej * | |
635b9c2e62Sthorpej * F | | B
645b9c2e62Sthorpej * | G |
655b9c2e62Sthorpej * +-----+
665b9c2e62Sthorpej * | |
675b9c2e62Sthorpej * E | | C
685b9c2e62Sthorpej * | D |
695b9c2e62Sthorpej * +-----+ o DP
705b9c2e62Sthorpej *
715b9c2e62Sthorpej * Setting a bit clears the corresponding segment on the
725b9c2e62Sthorpej * display.
735b9c2e62Sthorpej */
745b9c2e62Sthorpej #define SEG_A (1 << 0)
755b9c2e62Sthorpej #define SEG_B (1 << 1)
765b9c2e62Sthorpej #define SEG_C (1 << 2)
775b9c2e62Sthorpej #define SEG_D (1 << 3)
785b9c2e62Sthorpej #define SEG_E (1 << 4)
795b9c2e62Sthorpej #define SEG_F (1 << 5)
805b9c2e62Sthorpej #define SEG_G (1 << 6)
815b9c2e62Sthorpej #define SEG_DP (1 << 7)
825b9c2e62Sthorpej
835b9c2e62Sthorpej static const uint8_t digitmap[] = {
845b9c2e62Sthorpej /* +#####+
855b9c2e62Sthorpej * # #
865b9c2e62Sthorpej * # #
875b9c2e62Sthorpej * # #
885b9c2e62Sthorpej * +-----+
895b9c2e62Sthorpej * # #
905b9c2e62Sthorpej * # #
915b9c2e62Sthorpej * # #
925b9c2e62Sthorpej * +#####+
935b9c2e62Sthorpej */
945b9c2e62Sthorpej SEG_G,
955b9c2e62Sthorpej
965b9c2e62Sthorpej /* +-----+
975b9c2e62Sthorpej * | #
985b9c2e62Sthorpej * | #
995b9c2e62Sthorpej * | #
1005b9c2e62Sthorpej * +-----+
1015b9c2e62Sthorpej * | #
1025b9c2e62Sthorpej * | #
1035b9c2e62Sthorpej * | #
1045b9c2e62Sthorpej * +-----+
1055b9c2e62Sthorpej */
1065b9c2e62Sthorpej SEG_A|SEG_D|SEG_E|SEG_F|SEG_G,
1075b9c2e62Sthorpej
1085b9c2e62Sthorpej /* +#####+
1095b9c2e62Sthorpej * | #
1105b9c2e62Sthorpej * | #
1115b9c2e62Sthorpej * | #
1125b9c2e62Sthorpej * +#####+
1135b9c2e62Sthorpej * # |
1145b9c2e62Sthorpej * # |
1155b9c2e62Sthorpej * # |
1165b9c2e62Sthorpej * +#####+
1175b9c2e62Sthorpej */
1185b9c2e62Sthorpej SEG_C|SEG_F,
1195b9c2e62Sthorpej
1205b9c2e62Sthorpej /* +#####+
1215b9c2e62Sthorpej * | #
1225b9c2e62Sthorpej * | #
1235b9c2e62Sthorpej * | #
1245b9c2e62Sthorpej * +#####+
1255b9c2e62Sthorpej * | #
1265b9c2e62Sthorpej * | #
1275b9c2e62Sthorpej * | #
1285b9c2e62Sthorpej * +#####+
1295b9c2e62Sthorpej */
1305b9c2e62Sthorpej SEG_E|SEG_F,
1315b9c2e62Sthorpej
1325b9c2e62Sthorpej /* +-----+
1335b9c2e62Sthorpej * # #
1345b9c2e62Sthorpej * # #
1355b9c2e62Sthorpej * # #
1365b9c2e62Sthorpej * +#####+
1375b9c2e62Sthorpej * | #
1385b9c2e62Sthorpej * | #
1395b9c2e62Sthorpej * | #
1405b9c2e62Sthorpej * +-----+
1415b9c2e62Sthorpej */
1425b9c2e62Sthorpej SEG_A|SEG_D|SEG_E,
1435b9c2e62Sthorpej
1445b9c2e62Sthorpej /* +#####+
1455b9c2e62Sthorpej * # |
1465b9c2e62Sthorpej * # |
1475b9c2e62Sthorpej * # |
1485b9c2e62Sthorpej * +#####+
1495b9c2e62Sthorpej * | #
1505b9c2e62Sthorpej * | #
1515b9c2e62Sthorpej * | #
1525b9c2e62Sthorpej * +#####+
1535b9c2e62Sthorpej */
1545b9c2e62Sthorpej SEG_B|SEG_E,
1555b9c2e62Sthorpej
1565b9c2e62Sthorpej /* +#####+
1575b9c2e62Sthorpej * # |
1585b9c2e62Sthorpej * # |
1595b9c2e62Sthorpej * # |
1605b9c2e62Sthorpej * +#####+
1615b9c2e62Sthorpej * # #
1625b9c2e62Sthorpej * # #
1635b9c2e62Sthorpej * # #
1645b9c2e62Sthorpej * +#####+
1655b9c2e62Sthorpej */
1665b9c2e62Sthorpej SEG_B,
1675b9c2e62Sthorpej
1685b9c2e62Sthorpej /* +#####+
1695b9c2e62Sthorpej * | #
1705b9c2e62Sthorpej * | #
1715b9c2e62Sthorpej * | #
1725b9c2e62Sthorpej * +-----+
1735b9c2e62Sthorpej * | #
1745b9c2e62Sthorpej * | #
1755b9c2e62Sthorpej * | #
1765b9c2e62Sthorpej * +-----+
1775b9c2e62Sthorpej */
1785b9c2e62Sthorpej SEG_D|SEG_E|SEG_F,
1795b9c2e62Sthorpej
1805b9c2e62Sthorpej /* +#####+
1815b9c2e62Sthorpej * # #
1825b9c2e62Sthorpej * # #
1835b9c2e62Sthorpej * # #
1845b9c2e62Sthorpej * +#####+
1855b9c2e62Sthorpej * # #
1865b9c2e62Sthorpej * # #
1875b9c2e62Sthorpej * # #
1885b9c2e62Sthorpej * +#####+
1895b9c2e62Sthorpej */
1905b9c2e62Sthorpej 0,
1915b9c2e62Sthorpej
1925b9c2e62Sthorpej /* +#####+
1935b9c2e62Sthorpej * # #
1945b9c2e62Sthorpej * # #
1955b9c2e62Sthorpej * # #
1965b9c2e62Sthorpej * +#####+
1975b9c2e62Sthorpej * | #
1985b9c2e62Sthorpej * | #
1995b9c2e62Sthorpej * | #
2005b9c2e62Sthorpej * +-----+
2015b9c2e62Sthorpej */
2025b9c2e62Sthorpej SEG_D|SEG_E,
2035b9c2e62Sthorpej };
2045b9c2e62Sthorpej
2055b9c2e62Sthorpej static uint8_t
iq80321_7seg_xlate(char c)2065b9c2e62Sthorpej iq80321_7seg_xlate(char c)
2075b9c2e62Sthorpej {
2085b9c2e62Sthorpej uint8_t rv;
2095b9c2e62Sthorpej
2105b9c2e62Sthorpej if (c >= '0' && c <= '9')
2115b9c2e62Sthorpej rv = digitmap[c - '0'];
2125b9c2e62Sthorpej else if (c == '.')
2135b9c2e62Sthorpej rv = (uint8_t) ~SEG_DP;
2145b9c2e62Sthorpej else
2155b9c2e62Sthorpej rv = 0xff;
2165b9c2e62Sthorpej
2175b9c2e62Sthorpej return (rv);
2185b9c2e62Sthorpej }
2195b9c2e62Sthorpej
2205b9c2e62Sthorpej void
iq80321_7seg(char a,char b)2215b9c2e62Sthorpej iq80321_7seg(char a, char b)
2225b9c2e62Sthorpej {
2235b9c2e62Sthorpej uint8_t msb, lsb;
2245b9c2e62Sthorpej
2255b9c2e62Sthorpej msb = iq80321_7seg_xlate(a);
2265b9c2e62Sthorpej lsb = iq80321_7seg_xlate(b);
2275b9c2e62Sthorpej
2285b9c2e62Sthorpej snakestate = 0;
2295b9c2e62Sthorpej
2305b9c2e62Sthorpej WRITE(IQ80321_7SEG_MSB, msb);
2315b9c2e62Sthorpej WRITE(IQ80321_7SEG_LSB, lsb);
2325b9c2e62Sthorpej }
2335b9c2e62Sthorpej
2345b9c2e62Sthorpej static const uint8_t snakemap[][2] = {
2355b9c2e62Sthorpej
2365b9c2e62Sthorpej /* +#####+ +#####+
2375b9c2e62Sthorpej * | | | |
2385b9c2e62Sthorpej * | | | |
2395b9c2e62Sthorpej * | | | |
2405b9c2e62Sthorpej * +-----+ +-----+
2415b9c2e62Sthorpej * | | | |
2425b9c2e62Sthorpej * | | | |
2435b9c2e62Sthorpej * | | | |
2445b9c2e62Sthorpej * +-----+ +-----+
2455b9c2e62Sthorpej */
2465b9c2e62Sthorpej { ~SEG_A, ~SEG_A },
2475b9c2e62Sthorpej
2485b9c2e62Sthorpej /* +-----+ +-----+
2495b9c2e62Sthorpej * # | | #
2505b9c2e62Sthorpej * # | | #
2515b9c2e62Sthorpej * # | | #
2525b9c2e62Sthorpej * +-----+ +-----+
2535b9c2e62Sthorpej * | | | |
2545b9c2e62Sthorpej * | | | |
2555b9c2e62Sthorpej * | | | |
2565b9c2e62Sthorpej * +-----+ +-----+
2575b9c2e62Sthorpej */
2585b9c2e62Sthorpej { ~SEG_F, ~SEG_B },
2595b9c2e62Sthorpej
2605b9c2e62Sthorpej /* +-----+ +-----+
2615b9c2e62Sthorpej * | | | |
2625b9c2e62Sthorpej * | | | |
2635b9c2e62Sthorpej * | | | |
2645b9c2e62Sthorpej * +#####+ +#####+
2655b9c2e62Sthorpej * | | | |
2665b9c2e62Sthorpej * | | | |
2675b9c2e62Sthorpej * | | | |
2685b9c2e62Sthorpej * +-----+ +-----+
2695b9c2e62Sthorpej */
2705b9c2e62Sthorpej { ~SEG_G, ~SEG_G },
2715b9c2e62Sthorpej
2725b9c2e62Sthorpej /* +-----+ +-----+
2735b9c2e62Sthorpej * | | | |
2745b9c2e62Sthorpej * | | | |
2755b9c2e62Sthorpej * | | | |
2765b9c2e62Sthorpej * +-----+ +-----+
2775b9c2e62Sthorpej * | # # |
2785b9c2e62Sthorpej * | # # |
2795b9c2e62Sthorpej * | # # |
2805b9c2e62Sthorpej * +-----+ +-----+
2815b9c2e62Sthorpej */
2825b9c2e62Sthorpej { ~SEG_C, ~SEG_E },
2835b9c2e62Sthorpej
2845b9c2e62Sthorpej /* +-----+ +-----+
2855b9c2e62Sthorpej * | | | |
2865b9c2e62Sthorpej * | | | |
2875b9c2e62Sthorpej * | | | |
2885b9c2e62Sthorpej * +-----+ +-----+
2895b9c2e62Sthorpej * | | | |
2905b9c2e62Sthorpej * | | | |
2915b9c2e62Sthorpej * | | | |
2925b9c2e62Sthorpej * +#####+ +#####+
2935b9c2e62Sthorpej */
2945b9c2e62Sthorpej { ~SEG_D, ~SEG_D },
2955b9c2e62Sthorpej
2965b9c2e62Sthorpej /* +-----+ +-----+
2975b9c2e62Sthorpej * | | | |
2985b9c2e62Sthorpej * | | | |
2995b9c2e62Sthorpej * | | | |
3005b9c2e62Sthorpej * +-----+ +-----+
3015b9c2e62Sthorpej * # | | #
3025b9c2e62Sthorpej * # | | #
3035b9c2e62Sthorpej * # | | #
3045b9c2e62Sthorpej * +-----+ +-----+
3055b9c2e62Sthorpej */
3065b9c2e62Sthorpej { ~SEG_E, ~SEG_C },
3075b9c2e62Sthorpej
3085b9c2e62Sthorpej /* +-----+ +-----+
3095b9c2e62Sthorpej * | | | |
3105b9c2e62Sthorpej * | | | |
3115b9c2e62Sthorpej * | | | |
3125b9c2e62Sthorpej * +#####+ +#####+
3135b9c2e62Sthorpej * | | | |
3145b9c2e62Sthorpej * | | | |
3155b9c2e62Sthorpej * | | | |
3165b9c2e62Sthorpej * +-----+ +-----+
3175b9c2e62Sthorpej */
3185b9c2e62Sthorpej { ~SEG_G, ~SEG_G },
3195b9c2e62Sthorpej
3205b9c2e62Sthorpej /* +-----+ +-----+
3215b9c2e62Sthorpej * | # # |
3225b9c2e62Sthorpej * | # # |
3235b9c2e62Sthorpej * | # # |
3245b9c2e62Sthorpej * +-----+ +-----+
3255b9c2e62Sthorpej * | | | |
3265b9c2e62Sthorpej * | | | |
3275b9c2e62Sthorpej * | | | |
3285b9c2e62Sthorpej * +-----+ +-----+
3295b9c2e62Sthorpej */
3305b9c2e62Sthorpej { ~SEG_B, ~SEG_F },
3315b9c2e62Sthorpej };
3325b9c2e62Sthorpej
3335b9c2e62Sthorpej void
iq80321_7seg_snake(void)3345b9c2e62Sthorpej iq80321_7seg_snake(void)
3355b9c2e62Sthorpej {
3365b9c2e62Sthorpej int cur = snakestate;
3375b9c2e62Sthorpej
3385b9c2e62Sthorpej WRITE(IQ80321_7SEG_MSB, snakemap[cur][0]);
3395b9c2e62Sthorpej WRITE(IQ80321_7SEG_LSB, snakemap[cur][1]);
3405b9c2e62Sthorpej
3415b9c2e62Sthorpej snakestate = (cur + 1) & 7;
3425b9c2e62Sthorpej }
343