Difference between revisions of "Fitlet GPIO SDK for Windows"

From fit-PC wiki
Jump to: navigation, search
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== fitlet GPIO SDK for Windows ==
 
* [http://fit-pc.com/download/fitlet/sw/ fitlet GPIO SDK for Windows]
 
 
 
== Installation ==
 
== Installation ==
 +
* Download the [http://www.fit-pc2.com/download/fitlet/Win7/drivers/fitlet_Win7_GPIO.zip GPIO driver] to the fitlet.
 +
*Run the fitlet_GPIO_Driver_1.0.exe in Administrator mode and follow the on-screen instructions.
 +
 +
== API ==
 +
*The driver will install the GPIO.dll file to the C:\Windows\System\ folder.
 +
*The GPIO.dll exposes the following functions:
 +
 +
=== GPIO_Config ===
 +
Name:  GPIO_Config
 +
 +
Definition:  BOOL GPIO_Config(UINT8 gpioNum, UINT8 gpioDir, UINT8 gpioPullUp, UINT8 gpioPullDown)
 +
 +
Description:  Confgure the GPIO pin
 +
 +
Arguments:
 +
:gpioNum -      GPIO number (1-9)
 +
:gpioDir -      GPIO direction (0 – input, 1 – output)
 +
:gpioPullUp -  GPIO pull-up (0 – disabled, 1 – enabled)
 +
:gpioPullDown - GPIO pull-down (0 – disabled, 1 – enabled)
 +
 +
Return:  GPIO pin configuration status (FALSE - failure, TRUE - success)
 +
 +
=== GPIO_Set ===
 +
Name:  GPIO_Set
 +
 +
Definition:  BOOL GPIO_Set(UINT8 gpioNum, UINT8 gpioValue)
 +
 +
Description:  Set the value of GPIO output pin
 +
 +
Arguments:
 +
:gpioNum -  GPIO number (1-9)
 +
:gpioValue - GPIO output pin value (0 – low, 1 – high)
 +
 +
Return:  GPIO output pin configuration status (FALSE - failure, TRUE -  success)   
 +
 +
=== GPIO_Get ===
 +
Name:  GPIO_Get
 +
 +
Definition:  UINT8 GPIO_Get(UINT8 gpioNum)
 +
 +
Description:  Get the value of the GPIO input pin
 +
 +
Arguments:
 +
:gpioNum - GPIO number (1-9)
 +
 +
Return:  GPIO input pin value (0 – low, 1 - high)
 +
 +
== Sample Application ==
 +
The following [http://www.fit-pc2.com/download/fitlet/Win7/drivers/fitlet_Win7_GPIO.zip example] demonstrates the simple control of a GPIO pins. The application writes to GPIO1 (Pin1) and reads from GPIO2 (Pin2) (before using this application connect GPIO1 (Pin1) to GPIO2 (Pin2)).
 +
 +
<syntaxhighlight lang="cpp">
 +
#include "stdafx.h"
 +
#include "windows.h"
 +
#include "stdio.h"
 +
 +
int _tmain(int argc, _TCHAR* argv[])
 +
{
 +
typedef BOOL (WINAPI* LPGPIO_CONFIG)(UINT8, UINT8, UINT8, UINT8);
 +
typedef BOOL (WINAPI* LPGPIO_SET)(UINT8, UINT8);
 +
typedef UINT8 (WINAPI* LPGPIO_GET)(UINT8);
 +
 +
HINSTANCE hDLL;
 +
LPGPIO_CONFIG GPIO_Config;
 +
LPGPIO_SET GPIO_Set;
 +
LPGPIO_GET GPIO_Get;
 +
 +
// Load the GPIO DLL
 +
hDLL = LoadLibrary(TEXT("C:\\Windows\\System\\GPIO"));
 +
 +
// Obtain the exported functions of the GPIO DLL
 +
if (hDLL != NULL)
 +
{
 +
GPIO_Config = (LPGPIO_CONFIG)GetProcAddress(hDLL, "GPIO_Config");
 +
if (!GPIO_Config)
 +
{
 +
printf("GetProcAddress GPIO_Config error: %d\n", GetLastError());
 +
FreeLibrary(hDLL);
 +
return -1;
 +
}
 +
 +
GPIO_Set = (LPGPIO_SET)GetProcAddress(hDLL, "GPIO_Set");
 +
if (!GPIO_Set)
 +
{
 +
printf("GetProcAddress GPIO_Set error: %d\n", GetLastError());
 +
FreeLibrary(hDLL);
 +
return -1;
 +
}
 +
 +
GPIO_Get = (LPGPIO_GET)GetProcAddress(hDLL, "GPIO_Get");
 +
if (!GPIO_Get)
 +
{
 +
printf("GetProcAddress GPIO_Get error: %d\n", GetLastError());
 +
FreeLibrary(hDLL);
 +
return -1;
 +
}
 +
 +
}
 +
else
 +
printf("LoadLibrary error: %d\n", GetLastError());
 +
 +
// Configure GPIO1 as output with pull-up enabled and pull-down disabled
 +
if (!(GPIO_Config(1, 1, 1, 0))) {
 +
FreeLibrary(hDLL);
 +
printf("GPIO_Config Error\n");
 +
return 0;
 +
}
 +
 +
// Configure GPIO2 as input with pull-up enabled and pull-down disabled
 +
if (!(GPIO_Config(2, 0, 1, 0))) {
 +
FreeLibrary(hDLL);
 +
printf("GPIO_Config Error\n");
 +
return 0;
 +
}
 +
 +
    // Set GPIO1 output pin to HIGH
 +
printf("Set GPIO1 - 1\n");
 +
if (!(GPIO_Set(1, 1))) {
 +
FreeLibrary(hDLL);
 +
printf("GPIO_Set Error\n");
 +
return 0;
 +
}
 +
Sleep(100);
 +
// read the GPIO2
 +
printf("Get GPIO2 - %d\n\n", GPIO_Get(2));
 +
 +
    // Set GPIO1 output pin to LOW
 +
printf("Set GPIO1 - 0\n");
 +
if (!(GPIO_Set(1, 0))) {
 +
FreeLibrary(hDLL);
 +
printf("GPIO_Set Error\n");
 +
return 0;
 +
}
 +
Sleep(100);
 +
// Read the GPIO2
 +
printf("Get GPIO2 - %d\n\n", GPIO_Get(2));
 +
 +
FreeLibrary(hDLL);
 +
 +
return 0;
 +
}</syntaxhighlight>
 +
 +
 +
 +
 +
 +
 +
 +
[[category:fitlet]]

Latest revision as of 08:52, 4 November 2015

Installation

  • Download the GPIO driver to the fitlet.
  • Run the fitlet_GPIO_Driver_1.0.exe in Administrator mode and follow the on-screen instructions.

API

  • The driver will install the GPIO.dll file to the C:\Windows\System\ folder.
  • The GPIO.dll exposes the following functions:

GPIO_Config

Name: GPIO_Config

Definition: BOOL GPIO_Config(UINT8 gpioNum, UINT8 gpioDir, UINT8 gpioPullUp, UINT8 gpioPullDown)

Description: Confgure the GPIO pin

Arguments:

gpioNum - GPIO number (1-9)
gpioDir - GPIO direction (0 – input, 1 – output)
gpioPullUp - GPIO pull-up (0 – disabled, 1 – enabled)
gpioPullDown - GPIO pull-down (0 – disabled, 1 – enabled)

Return: GPIO pin configuration status (FALSE - failure, TRUE - success)

GPIO_Set

Name: GPIO_Set

Definition: BOOL GPIO_Set(UINT8 gpioNum, UINT8 gpioValue)

Description: Set the value of GPIO output pin

Arguments:

gpioNum - GPIO number (1-9)
gpioValue - GPIO output pin value (0 – low, 1 – high)

Return: GPIO output pin configuration status (FALSE - failure, TRUE - success)

GPIO_Get

Name: GPIO_Get

Definition: UINT8 GPIO_Get(UINT8 gpioNum)

Description: Get the value of the GPIO input pin

Arguments:

gpioNum - GPIO number (1-9)

Return: GPIO input pin value (0 – low, 1 - high)

Sample Application

The following example demonstrates the simple control of a GPIO pins. The application writes to GPIO1 (Pin1) and reads from GPIO2 (Pin2) (before using this application connect GPIO1 (Pin1) to GPIO2 (Pin2)).

#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
 
int _tmain(int argc, _TCHAR* argv[])
{
	typedef BOOL (WINAPI* LPGPIO_CONFIG)(UINT8, UINT8, UINT8, UINT8);
	typedef BOOL (WINAPI* LPGPIO_SET)(UINT8, UINT8);
	typedef UINT8 (WINAPI* LPGPIO_GET)(UINT8);
 
	HINSTANCE			hDLL;
	LPGPIO_CONFIG		GPIO_Config;
	LPGPIO_SET			GPIO_Set;
	LPGPIO_GET			GPIO_Get;
 
	// Load the GPIO DLL
	hDLL = LoadLibrary(TEXT("C:\\Windows\\System\\GPIO"));
 
	// Obtain the exported functions of the GPIO DLL
	if (hDLL != NULL)
	{
		GPIO_Config = (LPGPIO_CONFIG)GetProcAddress(hDLL, "GPIO_Config");
		if (!GPIO_Config)
		{
			printf("GetProcAddress GPIO_Config error: %d\n", GetLastError());
			FreeLibrary(hDLL);
			return -1;
		}
 
		GPIO_Set = (LPGPIO_SET)GetProcAddress(hDLL, "GPIO_Set");
		if (!GPIO_Set)
		{
			printf("GetProcAddress GPIO_Set error: %d\n", GetLastError());
			FreeLibrary(hDLL);
			return -1;
		}
 
		GPIO_Get = (LPGPIO_GET)GetProcAddress(hDLL, "GPIO_Get");
		if (!GPIO_Get)
		{
			printf("GetProcAddress GPIO_Get error: %d\n", GetLastError());
			FreeLibrary(hDLL);
			return -1;
		}
 
	}
	else
		printf("LoadLibrary error: %d\n", GetLastError());
 
	// Configure GPIO1 as output with pull-up enabled and pull-down disabled
	if (!(GPIO_Config(1, 1, 1, 0))) {
		FreeLibrary(hDLL);
		printf("GPIO_Config Error\n");
		return 0;
	}
 
	// Configure GPIO2 as input with pull-up enabled and pull-down disabled
	if (!(GPIO_Config(2, 0, 1, 0))) {
		FreeLibrary(hDLL);
		printf("GPIO_Config Error\n");
		return 0;
	}
 
    // Set GPIO1 output pin to HIGH
	printf("Set GPIO1 - 1\n");
	if (!(GPIO_Set(1, 1))) {
		FreeLibrary(hDLL);
		printf("GPIO_Set Error\n");
		return 0;
	}
	Sleep(100);
	// read the GPIO2
	printf("Get GPIO2 - %d\n\n", GPIO_Get(2));
 
    // Set GPIO1 output pin to LOW
	printf("Set GPIO1 - 0\n");
	if (!(GPIO_Set(1, 0))) {
		FreeLibrary(hDLL);
		printf("GPIO_Set Error\n");
		return 0;
	}
	Sleep(100);
	// Read the GPIO2
	printf("Get GPIO2 - %d\n\n", GPIO_Get(2));
 
	FreeLibrary(hDLL);
 
	return 0;
}