📄 saa713x.pas
字号:
unit saa713x;
interface
var
RC_LowGpioPin: integer = $08;
RC_HighGpioPin: integer = $0c;
RC_ResetGpioPin: integer = $0f;
RC_StatusGpioPin: integer = $0e;
function Init713x: boolean;
function Poll713x: integer;
procedure Done713x;
implementation
uses windows;
var
_CVampGPIO: procedure;
_DVampGPIO: procedure;
_ReadFromGPIONr: procedure;
_WriteGPIONr: procedure;
var
gpio: array[0..1023] of char; // namiesto heapu
hLib: HMODULE;
function Init713x: boolean;
begin
result:=false;
hLib:=LoadLibrary('34api.dll');
_CVampGPIO:=GetProcAddress(hLib,'??0CVampGPIOStatic@@QAE@K@Z');
_DVampGPIO:=GetProcAddress(hLib,'??1CVampGPIOStatic@@UAE@XZ');
_ReadFromGPIONr:=GetProcAddress(hLib,'?ReadFromGPIONr@CVampGPIOStatic@@QAEJEPAE@Z');
_WriteGPIONr:=GetProcAddress(hLib,'?WriteToGPIONr@CVampGPIOStatic@@QAEJEE@Z');
if assigned(_CVampGPIO) and assigned(_DVampGPIO) and
assigned(_ReadFromGPIONr) and assigned(_WriteGPIONr) then begin
asm
push 0 // cislo zariadenia
mov ecx,offset gpio
call _CVampGPIO
end;
result:=true;
end else FreeLibrary(hLib);
end;
procedure Done713x;
begin
asm
mov ecx,offset gpio
call _DVampGPIO
end;
_CVampGPIO:=nil;
_DVampGPIO:=nil;
_ReadFromGPIONr:=nil;
_WriteGPIONr:=nil;
FreeLibrary(hLib);
end;
function ReadGPIO(pinnum: integer): integer; assembler;
asm
lea ecx,result
xor edx,edx
mov [ecx],edx
push ecx
push pinnum
mov ecx,offset gpio
call _ReadFromGPIONr
end;
procedure WriteGPIO(pinnum,value: integer); assembler;
asm
mov eax,value
mov ecx,pinnum
push eax
push ecx
mov ecx,offset gpio
call _WriteGPIONr
end;
function ReadGpioRange(low,high: integer): integer;
var
i,mask,value: integer;
begin
mask:=0; value:=0;
for i:=low to high do begin
value:=value or ReadGPIO(i) shl mask;
inc(mask);
end;
result:=value;
end;
var
bRepeat: boolean;
iRepDel: cardinal = 200;
iPrevScan: integer = -1;
t: cardinal;
function Poll713x: integer;
var
ScanCode,rd: integer;
begin
if ReadGpio(RC_StatusGpioPin) = 0 then begin
rd:=ReadGpioRange(RC_LowGpioPin,RC_HighGpioPin);
if (rd = iPrevScan) then begin
if bRepeat then begin
ScanCode:=rd;
end
else
if (GetTickCount - t > iRepDel) then begin
t:=GetTickCount;
ScanCode:=rd;
bRepeat:=true;
end
else
ScanCode:=-1;
end
else begin
bRepeat:=false;
t:=GetTickCount;
ScanCode:=rd;
iPrevScan:=rd;
end
end
else begin
WriteGpio(RC_ResetGpioPin,1);
ScanCode:=-1;
bRepeat:=false;
iPrevScan:=-1;
end;
sleep(10);
result:=ScanCode;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -