Statistics
| Revision:

root / trunk / tp_info6 / Emb_App / clavier.c @ 1

History | View | Annotate | Download (4.67 KB)

1
// subroutines for control the matriced keyboard
2

    
3
#ifdef M32C87
4
        #include "sfr32c87.h"
5
#endif
6

    
7
#ifdef M32C83
8
        #include "sfr32c83.h"
9
#endif
10

    
11
#include <itron.h> 
12
#include <kernel.h> 
13
#include <kernel_api.h>
14
#include "kernel_id.h" 
15

    
16
#ifdef M32C87
17
void clavier_init(int int_level)
18
{
19
     pd10= 0x0F;              // bit7 to bit4 input      bit3 to bit0 output   for port 10
20
         p10= 0xF0;
21
     pu31 = 1;                 // pull up enable for pins P10_7 to P10_4
22
     kupic = int_level;        // set key interrupt level
23
}
24

    
25
unsigned char clavier_scan(void)
26
{
27
        unsigned char touche; 
28
        static unsigned char ltouche;
29
        const unsigned char t_scan[4]={~(1<<0),~(1<<1),~(1<<2),~(1<<3)};
30
        static int col=0;
31
                
32
                p10=t_scan[col++];
33
                col&=0x03;
34
                        
35
            touche = p10;                        // lecture code binaire clavier
36
                switch(touche)                                        //determine et affiche numero touche appuyee
37
                {
38
                        case 0xBE: 
39
                                 touche = '1';
40
                             break;
41
                        case 0xDE: 
42
                             touche = '2';
43
                             break;
44
                        case 0x7E: 
45
                             touche = '3';
46
                 break;
47
            case 0xBD: 
48
                 touche = '4';
49
                 break;
50
            case 0xDD: 
51
                 touche = '5';
52
                             break;
53
                        case 0x7D: 
54
                             touche = '6';
55
                 break;
56
            case 0xEB: 
57
                             touche = '7';
58
                 break;
59
                        case 0xDB: 
60
                             touche = '8';
61
                             break;
62
                        case 0x7B: 
63
                             touche = '9';
64
                 break;
65
            case 0xE7: 
66
                 touche = '*';
67
                             break;
68
                        case 0xD7: 
69
                             touche = '0';
70
                             break;
71
                        case 0x77: 
72
                             touche = '#';
73
                 break;
74
            default : touche = 0;
75
                 break;
76
                   }         
77
                return( touche );                 
78
}
79

    
80
int touche_filter(void)
81
{
82
SYSTIM time;
83
static SYSTIM ltime;
84
SYSTIM dtime;
85

    
86
        iget_tim(&time);
87
        
88
        dtime.utime=time.utime-ltime.utime;        
89
        
90
        if (time.ltime<ltime.ltime)
91
                dtime.utime--;
92
                
93
        dtime.ltime=time.ltime-ltime.ltime;
94
        
95
        ltime.utime=time.utime;
96
        ltime.ltime=time.ltime;
97
                
98
        if (dtime.utime>0)
99
                return 1;
100
        else if (dtime.ltime>100)
101
                return 1;
102
                
103
        return 0;
104
}
105

    
106
void itouche(void )
107
{
108
        char t;
109
        
110
        if (t=clavier_scan()){ 
111
                if (touche_filter())
112
                        vipsnd_dtq(QdmTouche,t);
113
        }
114
        p10=0xF0;                        
115
}
116

    
117
#endif
118

    
119
#ifdef M32C83
120

    
121
// Clavier M32C83 Carte Lp
122

    
123
void clavier_init(int level)
124
{
125
    pd4 &= 0x0F;        //p44->P47 inputs   p40 -> p44 outputs
126
    pd5 = 0xFF;         //port 5 outputs
127
    p5 = 0xFD;
128
}
129

    
130

    
131

    
132
unsigned char clavier_scan(void)
133
{
134
    unsigned int code;
135
    unsigned int row;
136
    unsigned int colum;
137
    static unsigned char table[] = {0x7F,0xBF,0xEF,0xF7,0xFB,0xFD};
138
        static int i=0;
139

    
140
    p5 = colum = table[i];    
141
    i++;
142
    if(i==6) i=0;
143

    
144
    row = p4 & 0xF0;
145
    code = (colum << 8) | row;
146

    
147
    switch(code)
148
    {
149
        case(0x7F70) : return('/');
150
                    break;
151
        case(0xBF70) : return('*');
152
                    break;
153
        case(0xEF70) : return('F');
154
                    break;
155
        case(0xF770) : return('E');
156
                    break;
157
        case(0xFB70) : return('D');
158
                    break;
159
        case(0xFD70) : return('C');
160
                    break;
161
        case(0x7FB0) : return('X');
162
                    break;
163
        case(0xBFB0) : return('#');
164
                    break;
165
        case(0xEFB0) : return('B');
166
                    break;
167
        case(0xF7B0) : return('A');
168
                    break;
169
        case(0xFBB0) : return('9');
170
                    break;
171
        case(0xFDB0) : return('8');
172
                    break;
173
        case(0x7FD0) : return('-');
174
                    break;
175
        case(0xBFD0) : return('.');
176
                    break;
177
        case(0xEFD0) : return('7');
178
                    break;
179
        case(0xF7D0) : return('6');
180
                    break;
181
        case(0xFBD0) : return('5');
182
                    break;
183
        case(0xFDD0) : return('4');
184
                    break;
185
        case(0x7FE0) : return('+');
186
                    break;
187
        case(0xBFE0) : return('=');
188
                    break;
189
        case(0xEFE0) : return('3');
190
                    break;
191
        case(0xF7E0) : return('2');
192
                    break;
193
        case(0xFBE0) : return('1');
194
                    break;
195
        case(0xFDE0) : return('0');
196
                    break;
197
        default : return(0);  // Si aucune touche renvoi 0 plus facile a tester
198
                    break;
199
    }
200
}
201

    
202
void itouche(void) // Dummy fonction compatibility with Polytech Card
203
{}
204

    
205
#endif