Difference between revisions of "CM-T3530: WinCE: GPIOs Programming"
Line 12: | Line 12: | ||
The GPIO_Sample application manipulates the following GPIOs: | The GPIO_Sample application manipulates the following GPIOs: | ||
* GPIO140 - set as output (Pin 14 of connector P9 on SB-T35). | * GPIO140 - set as output (Pin 14 of connector P9 on SB-T35). | ||
− | * | + | * GPIO170 - set as input (Pin 1 of connector P11 on SB-T35). |
− | GPIO140 voltage level can be monitored with a DVM or an oscilloscope. | + | GPIO140 voltage level can be monitored with a DVM or an oscilloscope. GPIO170 can be controlled by an external switch or button. |
The GPIO_Sample performs the following actions: | The GPIO_Sample performs the following actions: | ||
* 1Hz clock simulation on GPIO140 for 10 seconds. | * 1Hz clock simulation on GPIO140 for 10 seconds. | ||
− | * Input voltage level monitoring on | + | * Input voltage level monitoring on GPIO170. |
− | * Edge detection on | + | * Edge detection on GPIO170. Event handler is registered with [[#DWORD GPIOInterruptInitialize(HANDLE hContext,DWORD id,HANDLE hEvent)|GPIOInterruptInitialize]]. The handler calls [[#DWORD GPIOInterruptDone(HANDLE hContext, DWORD id,DWORD intrID)|GPIOInterruptDone]] to indicate interrupt completion. |
Line 91: | Line 91: | ||
Param4 = | | Param4 = | | ||
Remarks = }} | Remarks = }} | ||
− | {{API | Signature = DWORD GPIOInterruptInitialize(HANDLE hContext,DWORD id | + | {{API | Signature = DWORD GPIOInterruptInitialize(HANDLE hContext,DWORD id,HANDLE hEvent) | |
Description = Sets an interrupt on a GPIO.| | Description = Sets an interrupt on a GPIO.| | ||
Return = Nonzero indicates success. | | Return = Nonzero indicates success. | | ||
Param1 = *hContext - Handle to an open driver instance.| | Param1 = *hContext - Handle to an open driver instance.| | ||
Param2 = *id - GPIO number.| | Param2 = *id - GPIO number.| | ||
− | Param3 | + | Param3 = *hEvent - Event to be signaled when the interrupt is triggered | |
− | + | Param4 = | | |
Remarks = * This function must be called before using the hEvent parameter. | Remarks = * This function must be called before using the hEvent parameter. | ||
:* The hEvent parameter can only be used in a WaitForSingleObject call. A WaitForMultipleObjects call with hEvent will fail. | :* The hEvent parameter can only be used in a WaitForSingleObject call. A WaitForMultipleObjects call with hEvent will fail. | ||
:* If you use hEvent in a call to WaitForSingleObject before you call GPIOInterruptInitialize, GPIOInterruptInitialize will fail. | :* If you use hEvent in a call to WaitForSingleObject before you call GPIOInterruptInitialize, GPIOInterruptInitialize will fail. | ||
}} | }} | ||
− | + | {{API | Signature = DWORD GPIOInterruptDone(HANDLE hContext, DWORD id) | | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | {{API | Signature = DWORD GPIOInterruptDone(HANDLE hContext, DWORD id | ||
Description = Signals to the kernel that GPIO interrupt processing is complete.| | Description = Signals to the kernel that GPIO interrupt processing is complete.| | ||
Return = Nonzero indicates success. | | Return = Nonzero indicates success. | | ||
Param1 = *hContext - Handle to an open driver instance.| | Param1 = *hContext - Handle to an open driver instance.| | ||
Param2 = *id - GPIO number.| | Param2 = *id - GPIO number.| | ||
− | Param3 = | + | Param3 = | |
Param4 = | | Param4 = | | ||
Remarks = A program calls GPIOInterruptDone when it has completed the interrupt processing and is ready for another interrupt. GPIOInterruptDone must be called to unmask the interrupt before the registered event can be signaled again.}} | Remarks = A program calls GPIOInterruptDone when it has completed the interrupt processing and is ready for another interrupt. GPIOInterruptDone must be called to unmask the interrupt before the registered event can be signaled again.}} | ||
− | {{API | Signature = DWORD GPIOInterruptDisable(HANDLE hContext, DWORD id | + | {{API | Signature = DWORD GPIOInterruptDisable(HANDLE hContext, DWORD id) | |
Description = Disables the GPIO hardware interrupt specified by interrupt identifier.| | Description = Disables the GPIO hardware interrupt specified by interrupt identifier.| | ||
Return = Nonzero indicates success. | | Return = Nonzero indicates success. | | ||
Param1 = *hContext - Handle to an open driver instance.| | Param1 = *hContext - Handle to an open driver instance.| | ||
Param2 = *id - GPIO number.| | Param2 = *id - GPIO number.| | ||
− | Param3 = | + | Param3 = | |
Param4 = | | Param4 = | | ||
Remarks = A program calls GPIOInterruptDisable to disable the hardware interrupt and to unregister the event registered by GPIOInterruptInitialize. The program must call GPIOInterruptDisable before closing the event handle.}} | Remarks = A program calls GPIOInterruptDisable to disable the hardware interrupt and to unregister the event registered by GPIOInterruptInitialize. The program must call GPIOInterruptDisable before closing the event handle.}} |
Latest revision as of 11:39, 21 June 2010
The WinCE demo image includes a GPIO driver that allows direct GPIO control. The GPIO driver is a stream driver that can be accessed using the "GIO" prefix.
Contents
- 1 GPIO Sample Application
- 2 GPIO Driver API
- 2.1 HANDLE GPIOOpen()
- 2.2 void GPIOClose(HANDLE hContext)
- 2.3 void GPIOSetBit(HANDLE hContext,DWORD id)
- 2.4 void GPIOClrBit(HANDLE hContext,DWORD id)
- 2.5 DWORD GPIOGetBit(HANDLE hContext,DWORD id)
- 2.6 void GPIOSetMode(HANDLE hContext, DWORD id, DWORD mode)
- 2.7 DWORD GPIOGetMode(HANDLE hContext,DWORD id)
- 2.8 DWORD GPIOInterruptInitialize(HANDLE hContext,DWORD id,HANDLE hEvent)
- 2.9 DWORD GPIOInterruptDone(HANDLE hContext, DWORD id)
- 2.10 DWORD GPIOInterruptDisable(HANDLE hContext, DWORD id)
GPIO Sample Application
This GPIO_Sample application illustrates basic functionality of CM-T3530 GPIOs in Windows CE:
- How to configure a GPIO pin as output and manipulate it.
- How to configure a GPIO pin as input and respond to changes in signal level.
- How to setup an edge triggered event.
The GPIO_Sample application manipulates the following GPIOs:
- GPIO140 - set as output (Pin 14 of connector P9 on SB-T35).
- GPIO170 - set as input (Pin 1 of connector P11 on SB-T35).
GPIO140 voltage level can be monitored with a DVM or an oscilloscope. GPIO170 can be controlled by an external switch or button.
The GPIO_Sample performs the following actions:
- 1Hz clock simulation on GPIO140 for 10 seconds.
- Input voltage level monitoring on GPIO170.
- Edge detection on GPIO170. Event handler is registered with GPIOInterruptInitialize. The handler calls GPIOInterruptDone to indicate interrupt completion.
GPIO Driver API
HANDLE GPIOOpen()
Opens an instance of the GPIO Driver. Returns a handle that should be used to access the driver
Return Values
- Nonzero indicates success.
void GPIOClose(HANDLE hContext)
Closes the driver handle
Parameters
- hContext - Handle to an open driver instance
void GPIOSetBit(HANDLE hContext,DWORD id)
Sets the GPIO output high (logical 1).
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
Remarks
- Make sure the GPIO direction is setup as output.
void GPIOClrBit(HANDLE hContext,DWORD id)
Sets the GPIO output low (logical 0).
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
Remarks
- Make sure the GPIO's direction is setup as output.
DWORD GPIOGetBit(HANDLE hContext,DWORD id)
Measures the GPIO voltage level.
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
Return Values
- 1 - Indicates high (logical 1).
- 0 - Indicates low (logical 0).
Remarks
- Make sure the GPIO direction is setup as input.
void GPIOSetMode(HANDLE hContext, DWORD id, DWORD mode)
Sets the GPIO operation mode.
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
- DWORD mode - GPIO operation mode. Possible modes:
#define GPIO_DIR_OUTPUT (0 << 0) //GPIO is set to output mode #define GPIO_DIR_INPUT (1 << 0) //GPIO is set to input mode #define GPIO_INT_LOW_HIGH (1 << 1) //Enable IRQ/Wakeup on rising edge detect #define GPIO_INT_HIGH_LOW (1 << 2) //Enable IRQ/Wakeup on falling edge detect #define GPIO_INT_LOW (1 << 3) //Enable the IRQ assertion on low level detect #define GPIO_INT_HIGH (1 << 4) //Enable the IRQ assertion on high level detect #define GPIO_DEBOUNCE_ENABLE (1 << 5) //Enable debouncing feature on the corresponding input port
Remarks
- After GPIO operation mode is set as output, use GPIOSetBit and GPIOClrBit to set the GPIO output level.
- If a GPIO is setup as output, it will not generate interrupts, regardless of GPIO_INT_xxx flags.
DWORD GPIOGetMode(HANDLE hContext,DWORD id)
Returns the GPIO operating mode.
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
Return Values
- GPIO operating mode as described in GPIOSetMode.
DWORD GPIOInterruptInitialize(HANDLE hContext,DWORD id,HANDLE hEvent)
Sets an interrupt on a GPIO.
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
- hEvent - Event to be signaled when the interrupt is triggered
Return Values
- Nonzero indicates success.
Remarks
- This function must be called before using the hEvent parameter.
- The hEvent parameter can only be used in a WaitForSingleObject call. A WaitForMultipleObjects call with hEvent will fail.
- If you use hEvent in a call to WaitForSingleObject before you call GPIOInterruptInitialize, GPIOInterruptInitialize will fail.
DWORD GPIOInterruptDone(HANDLE hContext, DWORD id)
Signals to the kernel that GPIO interrupt processing is complete.
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
Return Values
- Nonzero indicates success.
Remarks
- A program calls GPIOInterruptDone when it has completed the interrupt processing and is ready for another interrupt. GPIOInterruptDone must be called to unmask the interrupt before the registered event can be signaled again.
DWORD GPIOInterruptDisable(HANDLE hContext, DWORD id)
Disables the GPIO hardware interrupt specified by interrupt identifier.
Parameters
- hContext - Handle to an open driver instance.
- id - GPIO number.
Return Values
- Nonzero indicates success.
Remarks
- A program calls GPIOInterruptDisable to disable the hardware interrupt and to unregister the event registered by GPIOInterruptInitialize. The program must call GPIOInterruptDisable before closing the event handle.