void outport(unsigned int portid, unsigned int value) { __asm mov edx, portid; __asm mov eax, value; __asm out dx, ax; } void outportb(unsigned int portid, unsigned char value) { __asm mov edx, portid __asm mov al, value __asm out dx, al } unsigned char inportb(unsigned int portid) { unsigned char value; __asm mov edx, portid __asm in al, dx __asm mov value, al return value; } unsigned int inport(unsigned int portid) { auto value = 0; __asm mov edx, portid __asm in ax, dx __asm mov value, eax return value; }
// dllmain.cpp: DLL. #include "stdafx.h" BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; }
#pragma once #include <jni.h> /* Header for class NativeGPIO */ #include "stdafx.h" /** * », ¤ ¤ ¤ (.dll) */ extern "C" { #define GPIO1 0x538 #define GPIO2 0x548 /**„ gpio1 1 integer*/ extern __declspec(dllexport) unsigned int readGPIO1(); /**„ gpio2 1 integer*/ extern __declspec(dllexport) unsigned int readGPIO2(); /**¤ */ extern __declspec(dllexport) unsigned char inportb(unsigned int portid); /**¤ int */ extern __declspec(dllexport) unsigned int inport(unsigned int portid); /**¤ int */ extern __declspec(dllexport) void outport(unsigned int portid, unsigned int value); /**¤ */ extern __declspec(dllexport) void outportb(unsigned int portid, unsigned char value); }
// dllmain.cpp: DLL. // NativeGPIO.cpp: DLL. // #include "stdafx.h" #include "NativeGPIO.h" #include <windows.h> void outport(unsigned int portid, unsigned int value) { __asm mov edx, portid; __asm mov eax, value; __asm out dx, ax; } void outportb(unsigned int portid, unsigned char value) { __asm mov edx, portid __asm mov al, value __asm out dx, al } unsigned char inportb(unsigned int portid) { unsigned char value; __asm mov edx, portid __asm in al, dx __asm mov value, al return value; } unsigned int inport(unsigned int portid) { auto value = 0; __asm mov edx, portid __asm in ax, dx __asm mov value, eax return value; } unsigned readGPIO2() { jint value = inportb(GPIO2); return value; } unsigned readGPIO1() { jint value = inportb(GPIO1); return value; }
import org.bridj.BridJ; import org.bridj.CRuntime; import org.bridj.ann.Library; /** * Created by Koksharov on 04.09.2015. * package = com.astra.app.neptun.applicationmanager * project = ApplicationManager */ @Library( "NativeGPIO" ) @org.bridj.ann.Runtime( CRuntime.class ) class NativeGPIOLibrary { { BridJ.register(); } public final int GPIO2 = ( int ) 1352; public final int GPIO1 = ( int ) 1336; /** * Original signature : <code>int readGPIO1()</code> * <i>native declaration : line 8</i> * GPIO 1, 0x538 * * @return , 1-4 */ native public int readGPIO1 (); /** * Original signature : <code>int readGPIO2()</code> * <i>native declaration : line 9</i> * GPIO 2, 0x548 * * @return , 5-8 */ native public int readGPIO2 (); /** * Original signature : <code>char inportb(unsigned int)</code> * <i>native declaration : line 10</i> * , ( , * ) * * @return , (-) */ native public byte inportb ( int portid ); /** * Original signature : <code>int inport(unsigned int)</code> * <i>native declaration : line 11</i> * , ( , * ) * * @return , (-) */ native public int inport ( int portid ); /** * Original signature : <code>void outport(unsigned int, unsigned int)</code> * <i>native declaration : line 12</i> * , ( , * , * ) */ native public void outport ( int portid, int value ); /** * Original signature : <code>void outportb(unsigned int, unsigned char)</code> * <i>native declaration : line 13</i> * , ( , * , * ) */ native public void outportb ( int portid, byte value ); }
for (;;){ System.out.println(NativeGPIOLibrary.readGPIO1()); System.out.println(NativeGPIOLibrary.readGPIO2()); int GPIOValue1 = (NativeGPIOLibrary.inport(NativeGPIOLibrary.GPIO1)); int GPIOValue2 = (NativeGPIOLibrary.inport(NativeGPIOLibrary.GPIO2)); int GPIOValue_34 = (NativeGPIOLibrary.inport(NativeGPIOLibrary.GPIO_34)); int GPIOValue_44 = (NativeGPIOLibrary.inport(NativeGPIOLibrary.GPIO_44)); System.out.println(GPIOValue1 + " " + GPIOValue2 + " " + GPIOValue_34 + " " + GPIOValue_44); int gp1 = GPIOValue1;// & 0b1111110; int gp2 = GPIOValue2;// & 0b1111111; if ( (gp1 & 0b00001000) == 0 ){ System.out.println("button 1 1 pressed"); } if ( (gp1 & 0b00010000) == 0 ){ System.out.println("button 1 2 pressed"); } if ( (gp1 & 0b00100000) == 0 ){ System.out.println("button 1 3 pressed"); } if ( (gp2 & 0b00100000) == 0 ){ System.out.println("button 2 1 pressed"); } if ( (gp2 & 0b00010000) == 0 ){ System.out.println("button 2 2 pressed"); } if ( (gp2 & 0b01000000) == 0 ){ System.out.println("button 2 3 pressed"); } if ( (gp2 & 0b10000000) != 0 ){ System.out.println("button OFF pressed"); } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } }
Source: https://habr.com/ru/post/268523/
All Articles