OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [dev/] [kptest.c] - Blame information for rev 53

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    kptest.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     To test and demonstrate that the keypad works.
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14 45 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
15 29 dgisselq
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
#include "board.h"
39
#include "keypad.h"
40 45 dgisselq
#include "txfns.h"
41 29 dgisselq
 
42
void entry(void) {
43 45 dgisselq
        register volatile IOSPACE *const sys = _sys;
44 29 dgisselq
 
45
        sys->io_pic = 0x07fffffff; // Acknowledge and turn off all interrupts
46
        sys->io_spio = 0x0f0;
47 45 dgisselq
        sys->io_timer = 100000 | TM_REPEAT;
48 29 dgisselq
 
49
        txstr("Press any keypad button for test.\r\n");
50
 
51
        while(1) {
52
                int     ch;
53
                while(0 == (sys->io_pic & INT_KEYPAD))
54
                        ;
55 45 dgisselq
                sys->io_pic = INT_KEYPAD | INT_TIMER;
56 29 dgisselq
                // Wait 5 ms
57
                for(int i=0; i<5; i++) {
58 45 dgisselq
                        while(0 == (sys->io_pic & INT_TIMER))
59 29 dgisselq
                                ;
60
                }
61
                sys->io_spio = 0x011;
62
                ch = keypadread();
63 45 dgisselq
                if ((ch < 0)||(ch == -1))
64 29 dgisselq
                        ; // txstr("Unknown key pressed or error\n");
65
                else if (ch < 10)
66
                        txchr(ch+'0');
67
                else if (ch == 15)
68
                        txstr("F\r\n");
69
                else if (ch < 15)
70
                        txchr(ch+'A'-10);
71 45 dgisselq
                else {
72
                        txstr("Unknown key pressed\r\n");
73
                }
74 29 dgisselq
                keypad_wait_for_release();
75
                sys->io_spio = 0x010;
76
        }
77
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.