forked from 1658988725/hisi_rtsp_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.c
executable file
·214 lines (179 loc) · 3.49 KB
/
key.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include "hi_common.h"
#include "hi_comm_video.h"
#include "hi_comm_sys.h"
#include "mpi_sys.h"
#include "hi_comm_vb.h"
#include "mpi_vb.h"
#include "hi_comm_vpss.h"
#include "mpi_vpss.h"
#include "mpi_vgs.h"
void CS(unsigned char flag)
{
if(flag == 0)
//system("himm 0x2016040 0xFF");
HI_MPI_SYS_SetReg(0x20160040,0x00);
else
// system("himm 0x2016040 0x00");
HI_MPI_SYS_SetReg(0x20160040,0xFF);
}
void DATA(unsigned char flag)
{
//printf("%d \n",flag);
if(flag == 0)
//system("himm 0x2016080 0xFF");
HI_MPI_SYS_SetReg(0x20160080,0x00);
else
//system("himm 0x2016080 0x00");
HI_MPI_SYS_SetReg(0x20160080,0xFF);
}
int set_gpio_mode(unsigned int reg,int nIndex,int mode)
{
//Ö»ÄÜÉ趨GPIO_DIRÖµ.
if((reg & 0x0400) != 0x0400)
return -1;
unsigned int nValue;
if(HI_SUCCESS == HI_MPI_SYS_GetReg(reg,&nValue))
{
if(mode == 1)
{
nValue |= (0x01<<nIndex);
}
else
{
nValue &= ~(0x01<< nIndex);
}
HI_MPI_SYS_SetReg(reg,nValue);
}
return -1;
}
//RST H2 GPIO0_2 muxctrl_reg30
static void key_Cfg(void)
{
system("himm 0x200F0024 0x00");//set gpio mode
system("himm 0x20140400 0x00");//set out mode
usleep(100);
}
static unsigned int read_key_value()
{
unsigned int uiRegValue = 0;
//HI_MPI_SYS_GetReg(0x20140100, &uiRegValue);
HI_MPI_SYS_GetReg(0x201403FC, &uiRegValue);
//printf("%s --- %d \n",__FUNCTION__,uiRegValue);
return uiRegValue;
}
void sendcmd(unsigned char uCmd)
{
printf("%s %d \n",__FUNCTION__,uCmd);
int i=0;
CS(0);
for(i = 0 ;i< 8;i++)
{
DATA(uCmd & 0x80);
usleep(12000);
uCmd = uCmd << 1;
}
CS(1);
sleep(1);
}
static void key_check_handle_thread()
{
unsigned int uiRegValue = 0,uiRegValue1 = 0;
static int flag = 0;
while(1)
{
CS(1);
DATA(1);
uiRegValue = read_key_value();
usleep(10000);
if(uiRegValue == 4)continue;
uiRegValue1 = read_key_value(); //Ïû¶¶
if(uiRegValue == uiRegValue1)
{
sendcmd(flag%3 + 1);
flag ++;
}
}
}
static void key_check_thread(void)
{
pthread_t tfid;
int ret = 0;
ret = pthread_create(&tfid, NULL, (void*)key_check_handle_thread, NULL);
if (ret != 0)
{
//printf("pthread_create failed, %d, %s\n", errno, strerror(errno));
return ;
}
pthread_detach(tfid);
}
/*
CS SINGAL_IN4 B14 muxctrl_reg8 GPIO2_4
//GPIO
himm 0x200F0020 0x00
himm 0x20160400 0x10
himm 0x201603FC 0xFF
*/
/*
DATA SINGAL_IN3 A13 muxctrl_reg9 GPIO2_5
himm 0x200F0024 0x00
himm 0x20160400 0x20
himm 0x201603FC 0xFF
himm 0x201603FC 0x00
*/
//GPIO2_4
static void serio(void)
{
//CS
system("himm 0x200F0020 0x00");
set_gpio_mode(0x20160400,4,1);
//system("himm 0x20160400 0x10");
system("himm 0x201603FC 0xFF");
//Data
system("himm 0x200F0024 0x00");
//system("himm 0x20160400 0x20");
set_gpio_mode(0x20160400,5,1);
system("himm 0x201603FC 0xFF");
usleep(100);
}
static void read_serial()
{
while(1)
{
CS(1);
DATA(1);
switch(getchar())
{
case 0x31:
sendcmd(0x01);
printf("0x01 start rec\n");
break;
case 0x32:
sendcmd(0x02);
printf("0x02 stop rec\n");
break;
case 0x33:
sendcmd(0x03);
printf("0x03 capture\n");
break;
}
}
}
int main()
{
key_Cfg();
serio();
CS(1);
DATA(1);
//key_check_thread();
//key_check_handle_thread();
read_serial();
return 0;
}