GPIO Interface

DLN series interface adapters contain a large number of pins that you can use as general-purpose inputs and outputs. Some of these pins are shared between GPIO (general-purpose input/output) and other modules (I2C, SPI). If you do not the corresponding pins to other modules, you can configure them as digital inputs or digital outputs and control them.

If you configure pins as inputs, your application reads the digital value set by the external device. If you define pins as outputs, your application can control the digital value on these pins.

To use a pin as a digital input or a digital output, the pin must be assigned to the GPIO module by using the DlnGpioPinEnable() function. You can use the DlnGpioPinIsEnabled() function, to check whether a pin is already assigned to the GPIO module.

You cannot assign a pin to the GPIO module if another module uses it. Call the DlnGetPinCfg() function to check which module uses a pin.

Most of the DLN-series adapters provide additional functionality for GPIO pins. You can configure the following features for any input and/or output pin individually:

  • Event-driven interface. You can configure a digital input pin to raise events when the value on this pin changes. There are several configuration options - what kind of events and when should be generated. For more details, read Digital Input Events.

  • Debounce filter. If you do not want to treat casual pulses as value changes, you can enable the debounce filter, which rejects pulses less that the predefined debounce period. For details, read Debounce Filter.

  • Open drain mode. If you interconnect several outputs on a single I/O line, they may settle different values simultaneously and cause hardware damage. The open drain mode helps you to avoid this. For details, read Open Drain Mode.

  • Pull-up and pull-down resistors. When no external hardware is connected to an input line, the logic level on this line is undefined. Use pull-up or pull-down resistors to ensure that inputs to I/O lines are settled at expected levels. For details, read Pull-up/Pull-down Resistors.

Rating: 
Средняя: 2 (1 оценка)

Digital Outputs

You can configure most of the DLN-series adapter pins as general-purpose digital outputs. Call the DlnGpioPinSetDirection() function and pass 1 for the direction parameter to configure the GPIO pin as a digital output. You can call this function either before or after the pin is assigned to the GPIO module by using the DlnGpioPinEnable() function.

To set the value on the pin, use the DlnGpioPinSetOutVal() function. Call the DlnGpioPinGetOutVal()function to retrieve the output value configured for this pin. The actual value of the pin may differ from the configured one (for example, when the pin is in the open drain mode or it is not assigned to the GPIO module). The DlnGpioPinGetVal()function retrieves the actual value present on the pin.

For digital outputs, you can use the Open Drain Mode.

Use the following GPIO Interface functions to control and monitor output pins:

DlnGpioPinSetDirection()

Configures a pin as a digital output. Pass 1 for the direction parameter.

DlnGpioPinSetOutVal()

Sets the output value for the pin.

DlnGpioPinGetOutVal()

Retrieves the output value configured for the pin.

DlnGpioPinGetVal()

Retrieves the actual value on the I/O line.

Rating: 
Средняя: 1 (1 оценка)

Digital Inputs

You can configure most of the DLN-series adapter pins as general-purpose digital inputs. Call the DlnGpioPinSetDirection() function and pass 0 for the direction parameter to configure the GPIO pin as a digital input. You can call this function either before or after the pin is assigned to the GPIO module by using the DlnGpioPinEnable() function.

You can check a pin direction by using the DlnGpioPinGetDirection() function.

The default pin direction is set to input (value 0).

To check the value on the pin, use the DlnGpioPinGetVal() function.

For digital inputs, you can use the following features:

Use the following GPIO Interface functions to control and monitor input pins:

DlnGpioPinSetDirection()

Configures a pin as a digital input. Pass 0 for the direction parameter.

DlnGpioPinGetVal()

Retrieves the value on the I/O line.

Rating: 
Средняя: 2 (1 оценка)

Digital Input Events

There are two ways of monitoring changes on the digital input line:

  • To poll the input pin periodically. In this case, you can potentially miss an input if your application reads the value at the wrong time.

  • To receive events when the input value changes. You can configure event generation for specific changes, for example, when the level on a pin rises. You can also configure the adapter to generate events periodically.

To configure events, use the DlnGpioPinSetEventCfg() function. You need to specify the eventType and the eventPeriod parameters. The DlnGpioPinGetSupportedEventTypes() function returns the list of event types available for a pin.

The eventType parameter can have one of the following values:

Event TypeDescription

DLN_GPIO_EVENT_NONE

A DLN adapter does not generate any events.

DLN_GPIO_EVENT_CHANGE

A DLN adapter generates events when the level on the digital input line changes. For details, read DLN_GPIO_EVENT_CHANGE Events

DLN_GPIO_EVENT_LEVEL_HIGH

A DLN adapter generates events when the high level is present on the digital input line or after transition from low to high level. For details, read DLN_GPIO_EVENT_LEVEL_HIGH Events

DLN_GPIO_EVENT_LEVEL_LOW

A DLN adapter generates events when the low level is present on the digital input line or after transition from high to low level. For details, read DLN_GPIO_EVENT_LEVEL_LOW Events

DLN_GPIO_EVENT_ALWAYS

A DLN adapter generates events continuously, regardless of the level. For details, read DLN_GPIO_EVENT_ALWAYS Events

The eventPeriod parameter defines the interval between repeated events in milliseconds (ms). This parameter must be non-zero for the DLN_GPIO_EVENT_ALWAYS events. For other events, this parameter is optional.

If the Debounce Filter in enabled on a pin, the level change event is generated after the debounce filter accepts a new value.

You can configure events for each input pin individually. If the pin is configured as a digital input, the new settings are applied immediately. If you configure events when a pin is defined as an output or is not assigned to the GPIO module at all, this configuration is saved in the internal memory and is applied when the pin becomes a GPIO input.

When an event occurs, your application is notified (see the Notifications section). Call the DlnGetMessage() function to obtain the event details. The DLN_GPIO_CONDITION_MET_EV structure describes this information.

By default, event generation is disabled for all pins (the eventType parameter is set to DLN_GPIO_EVENT_NONE).

The DLN-1 adapters do not support events.

The following GPIO Interface functions can be used to control and monitor events:

DlnGpioPinSetEventCfg()

Configures event generation for a pin.

DlnGpioPinGetEventCfg()

Retrieves event generation configuration for a pin.

DlnGpioPinGetSupportedEventTypes()

Returns the list of the event types available for a pin.

Rating: 
Голосов пока нет

DLN_GPIO_EVENT_CHANGE Events

A DLN adapter generates the DLN_GPIO_EVENT_CHANGE events each time the level on the input pin changes.

DLN_GPIO_EVENT_CHANGE event

Use the DlnGpioPinSetEventCfg()function to configure events. Pass DLN_GPIO_EVENT_CHANGE for the eventType parameter.

If the eventPeriod parameter is zero, the DLN adapter generates single events when the level on the input pin changes.

If the eventPeriod is non-zero, the DLN adapter resents the events periodically with the eventPeriod interval while the level on the pin remains unchanged (a series of events).

DLN_GPIO_EVENT_CHANGE events with period

A series of e vents begins when the level on the GPIO line changes. At this moment, the DLN adapter sends the first event in the series. The eventCount field of the first event is set to zero and the value field contains the actual value on the GPIO line. Then, while the level on the GPIO line remains unchanged, the DLN adapter repeatedly sends events with the same value in the value field. The interval between recurring events is equal to eventPeriod milliseconds. The eventCount field increments for each event in the series. You can use this field to calculate the time passed from the last level change (time = eventCount * eventPeriod).When the level on the GPIO line changes, a new series of events begins. The eventCount field is reset to zero and the value field is set to the actual value present on the line after the change.

Rating: 
Голосов пока нет

DLN_GPIO_EVENT_LEVEL_HIGH Events

A DLN adapter generates the DLN_GPIO_EVENT_LEVEL_HIGH events each time the level on the input pin rises.

DLN_GPIO_EVENT_LEVEL_HIGH  event

Use the DlnGpioPinSetEventCfg()function to configure events. Pass DLN_GPIO_EVENT_LEVEL_HIGH for the eventType parameter.

If the eventPeriod is zero, the DLN adapter generates single events when the level on the input pin rises (after transition from low to high level).

If the eventPeriod is non-zero , the DLN adapter resents events periodically with the eventPeriod interval while the level is high:

DLN_GPIO_EVENT_LEVEL_HIGH events with period

A series of events begins when the level on the GPIO line rises. At this moment, the DLN adapter sends the first event in the series. The eventCount field of the first event is set to zero and the value field is set to 1 to reflect the actual value on the GPIO line. Then, while the level on the GPIO line remains high, the DLN adapter repeatedly sends events. The same value in the value field stays the same. The eventCount field increments for every new event. The interval between recurring events is equal to eventPeriod milliseconds. You can calculate the time passed from the last level rise (time = eventCount * eventPeriod).

When the level on the GPIO line drops, the series of events ends. When the level on the line rises again, a new series of events begins. The eventCount field is reset to zero.

Rating: 
Голосов пока нет

DLN_GPIO_EVENT_LEVEL_LOW Events

A DLN adapter generates the DLN_GPIO_EVENT_LEVEL_LOW events each time the level on the input pin drops.

DLN_GPIO_EVENT_LEVEL_LOW events

Use the DlnGpioPinSetEventCfg()function to configure events. Pass DLN_GPIO_EVENT_LEVEL_LOW for the eventType parameter.

If the eventPeriod is zero, the DLN adapter generates single events when the level on the input pin drops (after transition from high to low level).

If the eventPeriod is non-zero, the DLN adapter resents events periodically with the eventPeriod interval while the level is low.

DLN_GPIO_EVENT_LEVEL_LOW events with period

A series of events begins when the level on the GPIO line drops. At this moment, the DLN adapter sends the first event in the series. The eventCount field of the first event is set to zero and the value field contains 0 to reflect the actual value on the GPIO line. Then, while the level on the GPIO line remains low, the DLN adapter repeatedly sends events. The value in the value field stays the same. The eventCount field increments for every new event. The interval between recurring events is equal to eventPeriod milliseconds. You can calculate the time passed from the last level lowering (time = eventCount * eventPeriod).

When the level on the GPIO line rises, the series of events ends. When the level on the line drops again, a new series of events begins. The eventCount field is reset to zero.

Rating: 
Голосов пока нет

DLN_GPIO_EVENT_ALWAYS Events

A DLN adapter generates the DLN_GPIO_EVENT_ALWAYS events periodically with the eventPeriod interval regardless of the level on the pin and its changes. This event notifies the current signal level on a pin.

DLN_GPIO_EVENT_ALWAYS events

Call the DlnGpioPinSetEventCfg()function to configure events. Specify DLN_GPIO_EVENT_ALWAYS as the eventType parameter.

For the DLN_GPIO_EVENT_ALWAYS events, the eventPeriod parameter is required to be non-zero.

Immediately after you configure the DLN_GPIO_EVENT_ALWAYS event, the DLN adapter sends the first event. The eventCount field is set to zero and the value field contains the actual value on the GPIO line. Then, the DLN adapter repeatedly sends events with the actual value on the line in the value field. The interval between recurring events is equal to eventPeriod milliseconds. The eventCount field increments for each event in the series.

The changes of the level on the pin do not affect the eventCount field. You can only reset it if you change the event configuration.

Rating: 
Голосов пока нет

Debounce Filter

Contact bounce may cause faulty level changes and sending numerous events. To avoid it, the DLN-series adapters support a debounce filter. The debounce filter accepts a new signal level only if it is stable for a predefined period of time (Debounce interval).

A pulse shorter than the specified debounce interval is automatically rejected:

Debounce is ignored

A pulse longer than the debounce interval is accepted:

Debounce is accepted

If events are configured for the corresponding input pin, they will only be generated after the debounce filter accepts the level change.

The Debounce interval is the same for all pins.You can change it by using the DlnGpioSetDebounce() function. The Debounce interval is specified in microseconds (µs). If a DLN-series adapter does not support the specified value, it rounds it up to the nearest supported value.

You can switch the debounce filter on/off for each pin individually. To switch it on, use the DlnGpioPinDebounceEnable() function. To switch it off, use the DlnGpioPinDebounceDisable() function. If a pin is not assigned to the GPIO module, your settings are saved in the internal memory and will be applied when you assign the pin to the GPIO module.

By default, the debounce filters are disabled on all pins.

The debounce Filter feature is not available for the DLN-1, DLN-2 adapters.

Use the following GPIO Interface functions to control and monitor the debounce filter:

DlnGpioPinDebounceEnable()

Enables the Debounce Filter on a pin.

DlnGpioPinDebounceDisable()

Disables the Debounce Filter on a pin

DlnGpioPinDebounceIsEnabled()

Determines whether the Debounce Filter is enabled on a pin.

DlnGpioSetDebounce()

Configures the debounce interval (the minimum duration of pulses to be accepted).

DlnGpioGetDebounce()

Retrieves the debounce interval value.

Rating: 
Средняя: 3 (2 оценок)

Open Drain Mode

Your application may require connecting several outputs together on a single I/O line. In this case, you should use the Open Drain feature to avoid the situation when different outputs set different signal levels on the line. To avoid hardware damage all interconnected outputs should be in open drain mode.

In open drain mode, pin cannot output high level (logical 1) on the line. It can either output low level (logical 0) or be in high-impedance state (logically disconnected). In high-impedance, pin does not affect the signal level on the line. A pull-up resistor pulls the line to high voltage level when all outputs are in high-impedance.

The Open Drain Mode can be enabled/disabled on each output pin individually. To activate this feature, use the DlnGpioPinOpendrainEnable() function. To disable it, use the DlnGpioPinOpendrainDisable() function. If a pin is not assigned to the GPIO module, your settings are saved in the internal memory and will be applied when you assign the pin to the GPIO module.

By default, the Open Drain Mode is disabled on all pins.

The DLN-1, DLN-2 adapters do not support the Open Drain mode.

Use the following GPIO Interface functions to control and monitor the Open Drain Mode:

DlnGpioPinOpendrainEnable()

Enables the Open Drain mode on a pin.

DlnGpioPinOpendrainDisable()

Disables the Open Drain mode on a pin.

DlnGpioPinOpendrainIsEnabled()

Determines whether the Open Drain mode in enabled on a pin.

Rating: 
Средняя: 1 (1 оценка)

Pull-up/Pull-down Resistors

Most I/O lines are equipped with an embedded pull-up resistor. A pull-up resistor has one end connected to the positive voltage and the other end connected to an input. The pull-up resistor ensures that the level on the input is high (logic 1) when no external device is connected. If an external device is connected and outputs 0, the input detects logic 0.

A pull-down resistor works the similar way, but it is connected to ground and the logic 0 is present on the line when no external device is connected.

Pull-up and pull-down resistors can be enabled/disabled on each input pin individually.

Call the DlnGpioPinPullupEnable() function to enable the pull-up resistor. It can be disabled by using the DlnGpioPinPullupDisable() function.

To enable a pull-down resistor, use the DlnGpioPinPulldownEnable() function. To disable it, use the DlnGpioPinPulldownDisable() function.

You cannot simultaneously enable pull-up and pull-down resistors for the same pin.

If a pin is not assigned to the GPIO module, your settings are saved in the internal memory and will be applied when you assign the pin to the GPIO module.

By default, pull-up resistors are enabled for all pins. The pull-down resisters are disabled by default.

DLN-4 adapters do not support pull-down resistors.

Use the following GPIO Interface functions to control and monitor pull-up resistors:

DlnGpioPinPullupEnable()

Enables the pull-up resistor on a pin.

DlnGpioPinPullupDisable()

Disables the pull-up resistor on a pin.

DlnGpioPinPullupIsEnabled()

Determines whether the pull-up resistor is enabled on a pin.

Use the following GPIO Interface functions to control and monitor pull-down resistors:

DlnGpioPinPulldownEnable()

Enables the pull-down resistor on a pin.

DlnGpioPinPulldownDisable()

Disables the pull-down resistor on a pin.

DlnGpioPinPulldownIsEnabled()

Determines whether the pull-down resistor is enabled on a pin.

Rating: 
Средняя: 1 (1 оценка)

Default Configuration

When you assign a pin to the GPIO module, it has the following default configuration:

  • The pin is configured as an input.

  • Events are disabled for the pin.

  • Debounce filtering is turned off.

  • An Open Drain mode is not active.

  • An embedded pull-up resistor is active.

  • An embedded pull-down resistor is not active.

You can change the configuration before or after you assign a pin to the GPIO module. If a pin is not currently assigned to the GPIO module, your settings are saved in the internal memory and will be applied when you assign the pin to the GPIO module.

Rating: 
Голосов пока нет

Simple GPIO Module Example

The following example shows how to enable/disable and set GPIO pin parameters, such as direction, output value and read GPIO pin value, when its direction set to input. You can find the complete example in the “..\Program Files\Diolan\DLN\examples\c_cpp\examples\simple” folder after DLN setup package installation.

C/C++
#include "..\..\..\common\dln_generic.h"
#include "..\..\..\common\dln_gpio.h"
#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")


int _tmain(int argc, _TCHAR* argv[])
{
	// Open device
	HDLN device;
	DlnOpenUsbDevice(&device);
	
	// Configure pin 0 to input with pullup
	DlnGpioPinPullupEnable(device, 0);
	DlnGpioPinSetDirection(device, 0, 0);
	DlnGpioPinEnable(device, 0);

	// Configure pin 1 to output
	DlnGpioPinSetDirection(device, 1, 1);
	DlnGpioPinEnable(device, 1);

	// Read pin 0 and set its iverted value on pin 1
	uint8_t value;
	DlnGpioPinGetVal(device, 0, &value);
	DlnGpioPinSetOutVal(device, 1, value ^ 1);

	// Disable buttons
	DlnGpioPinDisable(device, 0);
	DlnGpioPinDisable(device, 0);
	// Close device
	DlnCloseHandle(device);
	return 0;
}

  • Line 1:#include "..\..\..\common\dln_generic.h"

    The dln_generic..h header file declares functions and data structures for the generic interface

  • Line 2:#include "..\..\..\common\dln_gpio.h"

    The dln_gpio.h header file declares functions and data structures for GPIO interface.

  • Line 3:#pragma comment(lib, "..\\..\\..\\bin\\dln.lib")

    Use dln.lib library while project linking.

  • Line 10:DlnOpenUsbDevice(&device);

    The function establishes the connection with the DLN adapter. This application uses the USB connectivity of the adapter. For additional options, refer to the Device Opening & Identification section.

  • Line 13:DlnGpioPinPullupEnable(device, 0);

    Enable pullup for GPIO pin 0. You can read more about pullups at Pull-up/Pull-down Resistors section.

  • Line 14:DlnGpioPinSetDirection(device, 0, 0);

    Set GPIO pin 0 to input. For more information read Digital Inputs section.

  • Line 15:DlnGpioPinEnable(device, 0);

    Enable GPIO pin 0.

  • Line 18:DlnGpioPinSetDirection(device, 1, 1);

    Set GPIO pin 1 direction to output. For more information read Digital Outputs section.

  • Line 19:DlnGpioPinEnable(device, 1);

    Enable GPIO pin 1.

  • Line 23:DlnGpioPinGetVal(device, 0, &value);

    Get value on GPIO pin 0.

  • Line 24:DlnGpioPinSetOutVal(device, 1, value ^ 1);

    Set output value on the GPIO pin 1, which is opposite to the value variable.

  • Line 27:DlnGpioPinDisable(device, 0);

    Disable GPIO pin 0.

  • Line 28:DlnGpioPinDisable(device, 1);

    Disable GPIO pin 1.

  • Line 30:DlnCloseHandle(device);

    The application closes the handle to the connected DLN-series adapter.

Rating: 
Голосов пока нет

GPIO Interface Functions

Use the GPIO Interface functions to control and monitor the GPIO module of a DLN-series adapter.

General pin information:

DlnGpioGetPinCount()

Retrieves the number of pins that can be assigned to the GPIO module.

DlnGpioPinEnable()

Assigns a pin to the GPIO module.

DlnGpioPinDisable()

Unassigns a pin from the GPIO module.

DlnGpioPinIsEnabled()

Retrieves whether a pin is connected to the GPIO module.

DlnGpioPinSetDirection()

Configures a pin as a digital input or output.

DlnGpioPinGetDirection()

Retrieves whether a pin is configured as a digital input or output.

DlnGpioPinSetOutVal()

Defines a value on the output pin.

DlnGpioPinGetOutVal()

Retrieves the output value configured to the pin.

DlnGpioPinGetVal()

Retrieves the actual value on the I/O line.

Event functions:

DlnGpioPinSetEventCfg()

Configures event generation for a pin.

DlnGpioPinGetEventCfg()

Retrieves event generation configuration for a pin.

DlnGpioPinGetSupportedEventTypes()

Returns the list of the event types available for a pin.

Debounce filter functions:

DlnGpioPinDebounceEnable()

Enables the Debounce Filter on a pin.

DlnGpioPinDebounceDisable()

Disables the Debounce Filter on a pin

DlnGpioPinDebounceIsEnabled()

Determines whether the Debounce Filter is enabled on a pin.

DlnGpioSetDebounce()

Configures the debounce interval (the minimum duration of pulses to be registered).

DlnGpioGetDebounce()

Retrieves the debounce interval value.

Open Drain mode functions:

DlnGpioPinOpendrainEnable()

Enables the Open Drain mode on a pin.

DlnGpioPinOpendrainDisable()

Disables the Open Drain mode on a pin.

DlnGpioPinOpendrainIsEnabled()

Determines whether the Open Drain mode in enabled on a pin.

Pull-up/Pull-down resistors functions:

DlnGpioPinPullupEnable()

Enables the pull-up resistor on a pin.

DlnGpioPinPulldownEnable()

Enables the pull-down resistor on a pin.

DlnGpioPinPullupDisable()

Disables the pull-up resistor on a pin.

DlnGpioPinPulldownDisable()

Disables the pull-down resistor on a pin.

DlnGpioPinPullupIsEnabled()

Determines whether the pull-up resistor is enabled on a pin.

DlnGpioPinPulldownIsEnabled()

Determines whether the pull-down resistor is enabled on a pin.

The dln_gpio.h file declares the GPIO Interface functions.

Rating: 
Голосов пока нет

DlnGpioGetPinCount() Function

The DlnGpioGetPinCount() function retrieves the total number of GPIO pins available in the DLN-series adapter.

Syntax
C/C++
DLN_RESULT DlnGpioGetPinCount(
    HDLN handle,
    uint16_t* count
 );
Parameters
handle

A handle to a DLN-series adapter.

count

A pointer to an unsigned 16-bit integer that receives the number of available GPIO pins.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the GPIO pin count.

Remarks

The DlnGpioGetPinCount() function retrieves the number of pins that can be configured as GPIO. Even the pins that are assigned for other modules (but can be configured as GPIO) will be counted. To check whether a pin is connected to the GPIO module, use the DlnGpioPinIsEnabled() function.

The GPIO functions that accept a pin number as a parameter will return the DLN_RES_INVALID_PIN_NUMBER error code if the specified pin number exceeds the value returned by the DlnGpioGetPinCount() function.

The DlnGpioGetPinCount() function is declared in the dln_gpio.h file.

DlnGpioPinEnable() Function

The DlnGpioPinEnable() function connects a pin to the GPIO module.

Syntax
C/C++
DLN_RESULT DlnGpioPinEnable(
    HDLN handle,
    uint8_t pin
);
Parameters
handle

A handle to a DLN-series adapter.

pin

A number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully connected the pin to the GPIO module.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_PIN_IN_USE (0xA5)

Another module uses the pin and the GPIO module cannot use it. Use the DlnGetPinCfg()function to get the name of module using the pin.

Remarks

If you have not changed the configuration settings for the pin which you want to configure as a GPIO, it will have the default configuration. See Digital Input Events for details.

The DlnGpioPinEnable() function is declared in the dln_gpio.h file.

DlnGpioPinDisable() Function

The DlnGpioPinDisable() function disconnects a pin from the GPIO module. Then, another module can use the pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinDisable(
   HDLN handle, 
   uint8_t pin
);
Parameters
handle

A handle to a DLN-series adapter.

pin

A number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully disconnected the pin from the GPIO module.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_PIN_NOT_CONNECTED_TO_MODULE (0xAA)

The GPIO module does not use the pin, so the pin cannot be disconnected from the module.

Remarks

When you use the DlnGpioPinDisable() function, the pin configuration settings are not lost. They are saved in the internal memory. Later, if you reassign this pin to the GPIO module by using the DlnGpioPinEnable() function, the pin configuration is restored.

The DlnGpioPinDisable() function is declared in the dln_gpio.h file.

DlnGpioPinIsEnabled() Function

The DlnGpioPinIsEnabled() function informs whether the GPIO module currently uses the pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinIsEnabled(
   HDLN handle,
   uint8_t pin, 
   uint8_t* enabled
);
Parameters
handle

A handle to a DLN-series adapter.

pin

A number of the pin that you want to check.

enabled

A pointer to an unsigned 8-bit integer. After the function execution, this integer is set to one of the following values:

ValueDescription

1

The pin is configured as GPIO.

0

The pin is NOT configured as GPIO.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the pin information.

DLN_RES_INVALID_PIN_NUMBER ( 0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

To connect the pin with the GPIO module, use the DlnGpioPinEnable() function. To disconnect the pin assigned to the GPIO module, call the DlnGpioPinDisable() function.

To check which module uses the pin, use the DlnGetPinCfg()function.

The DlnGpioPinIsEnabled() function is declared in the dln_gpio.h file.

DlnGpioPinSetDirection() Function

The DlnGpioPinSetDirection() function configures a pin as an input or as an output.

Syntax
C/C++
DLN_RESULT DlnGpioPinSetDirection(
    HDLN handle,
    uint8_t pin,
    uint8_t direction
 );
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the GPIO pin that you want to configure.

direction

Direction of a pin. Set to 0 for input or 1 for output.

Return Value
DLN_RES_SUCCESS (0x00)

The pin direction has been successfully retrieved.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

By default, The GPIO pin is defined as an input. You can check the current pin direction by using the DlnGpioPinGetDirection() function.

If the pin is not currently assigned to the GPIO module, the pin direction setting is not lost. It is saved in internal memory. Later, when you assign this pin to the GPIO module by using the DlnGpioPinEnable() function, the pin direction will be applied.

The DlnGpioPinSetDirection() function is declared in dln_gpio.h file.

DlnGpioPinGetDirection() Function

The DlnGpioPinGetDirection() function retrieves current direction of a GPIO pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinGetDirection(
   HDLN handle,
   uint8_t pin,
   uint8_t* direction
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the GPIO pin that you want to check.

direction

A pointer to an unsigned 8-bit integer. After the function execution, the integer will be filled with the pin current direction. Possible values:

ValueDescription

1

The pin is an output.

0

The pin is an input.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the pin direction.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

If the pin is not currently assigned to the GPIO module, the pin direction setting is got from internal memory where it is saved when you define it. To change the current pin direction, use the DlnGpioPinSetDirection() function.

The DlnGpioPinGetDirection() function is declared in the dln_gpio.h file.

DlnGpioPinGetVal() Function

The DlnGpioPinGetVal() function retrieves the current value on the specified GPIO pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinGetVal(
   HDLN handle, 
   uint8_t pin,
   uint8_t* value
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin which value you want to know.

value

A pointer to an unsigned 8-bit integer. After the function execution, this integer will be set to the pin value.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieved the current pin value successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

The DlnGpioPinGetVal() function retrieves the value on the pin regardless of its direction. To check the GPIO pin direction, use the DlnGpioPinGetDirection() function. You can change the pin output value by using the DlnGpioPinSetOutVal() function.

The DlnGpioPinGetVal() function is declared in the dln_gpio.h file.

DlnGpioPinSetOutVal() Function

The DlnGpioPinSetOutVal() function sets the output value for the specified GPIO pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinSetOutVal(
   HDLN handle,
   uint8_t pin, 
   uint8_t value
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to configure.

value

A pin output value to be set.

Return Value
DLN_RES_SUCCESS (0x00)

The pin output value was successfully applied.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

If the specified pin is an output, the value is applied immediately. If the pins is an input or is not assigned to the GPIO module, the value is stored in the internal memory. The stored value will be applied when the pin becomes output.The DlnGpioPinSetOutVal() function is declared in the dln_gpio.h file.

DlnGpioPinGetOutVal() Function

The DlnGpioPinGetOutVal() function retrieves the pin output value.

Syntax
C/C++
DLN_RESULT DlnGpioPinGetOutVal(
    HDLN handle,
    uint8_t pin, 
    uint8_t* value
 );
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin which output value you want to know.

value

A pointer to an unsigned 8-bit integer. After the function execution, this integer is filled with the pin output value.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieved the pin output value successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

The default pin output value is 0. By using the DlnGpioPinSetOutVal() function you can change the output value. If the specified pin is not assigned to the GPIO module or is not an output, the DlnGpioPinGetOutVal() function takes the output value from the internal memory, where it is saved.

The DlnGpioPinGetOutVal() function is declared in the dln_gpio.h file.

DlnGpioPinSetEventCfg() Function

The DlnGpioPinSetEventCfg() function configures when and which events should be generated for the specified pin. For more information, read Digital Input Events.

Syntax
C/C++
DLN_RESULT DlnGpioPinSetEventCfg(
   HDLN handle,
   uint8_t pin,
   uint8_t eventType,
   uint16_t eventPeriod
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin for which you want to configure the event generation.

eventType

Defines when the DLN adapter should generate pin events. The following values are available:

ValueDescription

0 or DLN_GPIO_EVENT_NONE

The DLN adapter does not generate any events.

1 or DLN_GPIO_EVENT_CHANGE

The DLN adapter generates events when the level on the digital input line changes. For details, read DLN_GPIO_EVENT_CHANGE Events

2 or DLN_GPIO_EVENT_LEVEL_HIGH

The DLN adapter generates events when the high level is present on the digital input line or after transition from low to high level. For details, read DLN_GPIO_EVENT_LEVEL_HIGH Events

3 or DLN_GPIO_EVENT_LEVEL_LOW

The DLN adapter generates events when the low level is present on the digital input line or after transition from high to low level. For details, read DLN_GPIO_EVENT_LEVEL_LOW Events

4 or DLN_GPIO_EVENT_ALWAYS

The DLN adapter generates events continuously, regardless of the level. For details, read DLN_GPIO_EVENT_ALWAYS Events

eventPeriod

Defines the interval in milliseconds (ms) at which the events occur.

Return Value
DLN_RES_SUCCESS (0x00)

The function configured event settings successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_INVALID_EVENT_TYPE (0xA9)

The specified event type is not valid. Use the DlnGpioPinGetSupportedEventTypes() function to check the event types supported for the pin.

DLN_RES_INVALID_EVENT_PERIOD (0xAC)

The specified event period is not valid.

Remarks
The DLN-1 adapters do not support GPIO events.

The DlnGpioPinSetEventCfg() function is declared in the dln_gpio.h file.

DlnGpioPinGetEventCfg() Function

The DlnGpioPinGetEventCfg() function retrieves the current event configuration for the specified pin. For more information, read Digital Input Events.

Syntax
C/C++
DLN_RESULT DlnGpioPinGetEventCfg(
   HDLN handle, 
   uint8_t pin, 
   uint8_t* eventType,
   uint16_t* eventPeriod
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to check.

eventType

A pointer to an unsigned 8-bit integer. After the function execution, this integer is set to the current event configuration of the pin.

eventPeriod

A pointer to an unsigned 16-bit integer. After the function execution, this integer is set to the interval at which the specified events occur.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieved the event configuration successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks
GPIO events are by the DLN-1 adapters.

The DlnGpioPinGetEventCfg() function is declared in the dln_gpio.h file.

DlnGpioPinGetSupportedEventTypes() Function

The DlnGpioPinGetSupportedEventTypes() function returns all event types supported for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinGetSupportedEventTypes(
    HDLN handle, 
    uint16_t pin, 
    DLN_GPIO_PIN_EVENT_TYPES* supportedEventTypes
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin for which you want to get the information.

supportedEventTypes

The pointer to the DLN_GPIO_PIN_EVENT_TYPES structure that is filled by the supported event types. After the function execution, the structure fields include the following information:

FieldDescription

count

The number of available event types.

eventTypes[8]

An 8-element array. Each element corresponds to one of the supported event types.

Return Value
DLN_RES_SUCCESS (0x00)

The function was successful.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks
The DLN-1 adapters do not support GPIO events.

The DlnGpioPinGetSupportedEventTypes() function is declared in the dln_gpio.h file.

DlnGpioPinDebounceEnable() Function

The DlnGpioPinDebounceEnable() function enables Debounce Filter for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinDebounceEnable(
   HDLN handle,
   uint8_t pin
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS ( 0x00)

The function activated the debounce filter successfully.

DLN_RES_INVALID_PIN_NUMBER ( 0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_COMMAND_NOT_SUPPORTED (0x91)

The adapter does not support debounce filtering.

Remarks

You can use the DlnGpioPinDebounceEnable() function regardless of whether or not the specified pin is connected to the GPIO module. For a disconnected pin, the debounce filter configuration is saved in the internal memory. This value will be applied when the pin is connected to the GPIO module.

The debounce filter feature is not supported by DLN-1 and DLN-2 adapters.

The DlnGpioPinDebounceEnable() function is declared in the dln_gpio.h file.

DlnGpioPinDebounceDisable() Function

The DlnGpioPinDebounceDisable() disables Debounce Filter for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinDebounceDisable(
    HDLN handle,
    uint8_t pin
 );
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS (0x00)

The function deactivated debounce filter successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_COMMAND_NOT_SUPPORTED (0x91)

The adapter does not support debounce filtering.

Remarks
The DLN-1 and DLN-2 adapters do not support the debounce filter feature.

The DlnGpioPinDebounceDisable() function is declared in the dln_gpio.h file.

DlnGpioPinDebounceIsEnabled() Function

The DlnGpioPinDebounceIsEnabled() function informs whether the Debounce Filter is currently enabled for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinOpendrainIsEnabled(
   HDLN handle,
   uint8_t pin,
   uint8_t* enabled
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to check.

enabled

A pointer to an unsigned 8-bit integer. After the function execution, this parameter is set to one of the following values:

ValueDescription

1

Debounce filtering is active.

0

Debounce filtering is not active.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieves the debounce filter settings successfully.

DLN_RES_INVALID_PIN_NUMBER ( 0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_COMMAND_NOT_SUPPORTED (0x91)

The adapter does not support debounce filtering.

Remarks

The DlnGpioPinDebounceIsEnabled() function returns whether or not the debounce filtering feature is enabled for the specified pin. To enable this feature, use the DlnGpioPinDebounceEnable() function. To disable this feature, use the DlnGpioPinDebounceDisable() function. To specify the debounce interval, use the DlnGpioSetDebounce() function (See Debounce Filter for details).

DLN-1, DLN-2 adapters do not support the debounce filter feature.

The DlnGpioPinDebounceIsEnabled() function is declared in the dln_gpio.h file.

DlnGpioSetDebounce() Function

The DlnGpioSetDebounce() function specifies the debounce interval (the minimum duration of pulses to be registered). See Debounce Filter for details.

Syntax
C/C++
DLN_RESULT DlnGpioSetDebounce(
   HDLN handle, 
   uint32_t* duration
);
Parameters
handle

A handle to the DLN-series adapter.

duration

A pointer to an unsigned 32-bit integer. After the function execution, this integer is set to the debounce duration, rounded up to the nearest value supported by the adapter. See Debounce Filter for details.

Return Value
DLN_RES_SUCCESS (0x00)

The function specified the debounce interval successfully.

DLN_RES_COMMAND_NOT_SUPPORTED (0x91)

The adapter does not support debounce filtering.

Remarks

The specified debounce interval is actual for all pins where the debounce filter is enabled. This value should be specified in microseconds (µs): from 1µs up to 4,294,967,295µs (~1h 10m). If a DLN-series adapter does not support the specified value, it rounds it up to the nearest supported value.

The default value of the debounce interval depends on the DLN adapter. Once you call the DlnGpioSetDebounce() function and specify the debounce interval value, you change the default value. If the debounce filter is disabled for a pin or a pin is not assigned to the GPIO module, this value will be applied when the pin is assigned to the GPIO module with the debounce filter enabled.

DLN-1 and DLN-2 adapters do not support the debounce filter feature.

The DlnGpioSetDebounce() function is declared in the dln_gpio.h file.

DlnGpioGetDebounce() Function

The DlnGpioGetDebounce() function retrieves the current value of the debounce interval (the minimum duration of the pulse to be registered). See Debounce Filter for details.

Syntax
C/C++
DLN_RESULT DlnGpioGetDebounce(
   HDLN handle, 
   uint32_t* duration
);
Parameters
handle

A handle to the DLN-series adapter.

duration

A pointer to an unsigned 32-bit integer. After the function executed, this integer is set to the debounce interval value.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieved the debounce interval successfully.

DLN_RES_COMMAND_NOT_SUPPORTED (0x91)

The adapter does not support debounce filtering.

Remarks

The debounce interval is actual for all GPIO pins with the enabled debounce filter. To change the debounce interval value, use the DlnGpioSetDebounce() function.

DLN-1 and DLN-2 adapters do not support the debounce filter feature.

The DlnGpioGetDebounce() function is declared in the dln_gpio.h file.

DlnGpioPinOpendrainEnable() Function

The DlnGpioPinOpendrainEnable() function enables Open Drain Mode for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinOpendrainEnable(
   HDLN handle,
   uint8_t pin
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS (0x00)

The function enabled the open drain mode successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

By default, the Open Drain Mode is disabled for all GPIO pins. The DlnGpioPinOpendrainEnable() function enables the Open Drain Mode for the specified pin. If the pin is not assigned to the GPIO module, this configuration will be saved in the internal memory. When you assign the pin to the GPIO module, the saved configuration will be applied.

DLN-1 and DLN-2 adapters do not support the Open Drain mode.

The DlnGpioPinOpendrainEnable() function is defined in the dln_gpio.h file.

DlnGpioPinOpendrainDisable() Function

The DlnGpioPinOpendrainDisable() disables Open Drain Mode for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinOpendrainDisable(
   HDLN handle,
   uint8_t pin
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS (0x00)

The function disabled the open drain mode successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

The DlnGpioPinOpendrainDisable() function disables the Open Drain Mode for the specified pin. If the pin is not assigned to the GPIO module, this configuration will be saved in the internal memory. When you assign the pin to the GPIO module, the saved configuration will be applied.

Most pins of DLN-1 and DLN-2 adapters do not support the Open Drain mode.

The DlnGpioPinOpendrainDisable() function is defined in the dln_gpio.h file.

DlnGpioPinOpendrainIsEnabled() Function

The DlnGpioPinOpendrainIsEnabled() function informs whether the pin output is currently configured as push-pull or Open Drain.

Syntax
C/C++
DLN_RESULT DlnGpioPinOpendrainIsEnabled(
   HDLN handle,
   uint8_t pin,
   uint8_t* enabled
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin that you want to check.

enabled

A pointer to an unsigned 8-bit integer. After the function execution, this integer is set to the current pin configuration. The following values are available:

ValueDescription

1

The output is Open Drain.

0

The output is push-pull.

Return Value
DLN_RES_SUCCESS (0x00)

The function retrieved the open drain mode configuration successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks
Most pins of DLN-1 and DLN-2 adapters do not support the Open Drain mode.

The DlnGpioPinOpendrainIsEnabled() function is declared in the dln_gpio.h file.

DlnGpioPinPullupEnable() Function

The DlnGpioPinPullupEnable() function activates an embedded pull-up resistor for the specified pin. For more information, read Pull-up/Pull-down Resistors.

Syntax
C/C++
DLN_RESULT DlnGpioPinPullupEnable(
   HDLN handle,
   uint8_t pin
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin for which you want to enable a pull-up resistor.

Return Value
DLN_RES_SUCCESS (0x00)

The function activated the pull-up resistor successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

By default, the pull-up resistors are active for GPIO pins. You can change this configuration by using the DlnGpioPinPullupDisable() function. To check the current configuration setting for a pin, use the DlnGpioPinPullupIsEnabled() function.

The DlnGpioPinPullupEnable() function is declared in the dln_gpio.h file.

DlnGpioPinPullupDisable() Function

The DlnGpioPinPullupDisable() deactivates an embedded pull-up resistor for the specified pin. For more information, read Pull-up/Pull-down Resistors.

Syntax
C/C++
DLN_RESULT DlnGpioPinPullupDisable(
    HDLN handle,
    uint8_t pin
 );
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin for which you want to disable a pull-up resistor.

Return Value
DLN_RES_SUCCESS (0x00)

The function deactivated the pull-up resistor successfully.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

By default, pull-up resistors are active for GPIO pins. You can activate it manually by using the DlnGpioPinPullupEnable() function. To check the current configuration set for a pin, use the DlnGpioPinPullupIsEnabled() function.

The DlnGpioPinPullupDisable() function is declared in the dln_gpio.h file.

DlnGpioPinPullupIsEnabled() Function

The DlnGpioPinPullupIsEnabled() function informs whether an embedded pull-up resistor is currently enabled for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinPullupIsEnabled(
    HDLN handle,
    uint8_t pin,
    uint8_t* enabled
 );
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin from which you want to retrieve information.

enabled

A pointer to an unsigned 8-bit integer. After the function execution, this integer is filled with current state of a pull-up resistor. The following values are available:

ValueDescription

1

The pull-up resistor is active.

0

The pull-up resistor is not active.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the current state of the pull-up resistor.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

By default, the pull-up resistors are active for GPIO pins. You can activate it manually by using the DlnGpioPinPullupEnable() function. To deactivate the Pull-up/Pull-down Resistors for GPIO pins, use the DlnGpioPinPullupDisable() function.

The DlnGpioPinPullupIsEnabled() function is declared in the dln_gpio.h file.

DlnGpioPinPulldownEnable() Function

The DlnGpioPinPulldownEnable() function activates an embedded pull-down resistor for the specified pin. For more information, read Pull-up/Pull-down Resistors.

Syntax
C/C++
DLN_RESULT DlnGpioPinPulldownEnable(
   HDLN handle, 
   uint16_t pin
);
Parameters
handle

A handle to the DLN-series adapter.

pin

The number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS

The function successfully activated the pull-down resistor.

DLN_RES_INVALID_PIN_NUMBER

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_COMMAND_NOT_SUPPORTED

The DLN adapter does not support pull-down resistors.

Remarks
DLN-1 and DLN-2 adapters do not support pull-down resistors.

The DlnGpioPinPulldownEnable() function is declared in the dln_gpio.h file.

DlnGpioPinPulldownDisable() Function

The DlnGpioPinPulldownDisable() function deactivates an embedded pull-down resistor for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinPulldownDisable(
   HDLN handle, 
   uint16_t pin
);
Parameters
handle

A handle to the DLN-series adapter.

pin

The number of the pin that you want to configure.

Return Value
DLN_RES_SUCCESS

The function successfully deactivated the pull-down resistor.

DLN_RES_INVALID_PIN_NUMBER

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_COMMAND_NOT_SUPPORTED

The DLN adapter does not support pull-down resistors.

Remarks
DLN-1 and DLN-2 adapters do not support pull-down resistors.

The DlnGpioPinPulldownDisable() function is declared in the dln_gpio.h file.

DlnGpioPinPulldownIsEnabled() Function

The DlnGpioPinPulldownIsEnabled() function informs whether an embedded pull-down resistor is active for the specified pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinPulldownIsEnabled(
   HDLN handle, 
   uint16_t pin, 
   uint8_t* enabled
);
Parameters
handle

A handle to the DLN-series adapter.

pin

The number of the pin from which you want to retrieve information.

enabled

A pointer to an unsigned 8-bit integer. After the function execution, the integer is set to the current state of a pull-down resistor.

Return Value
DLN_RES_SUCCESS

The function successfully retrieved the current state of the pull-down resistor.

DLN_RES_INVALID_PIN_NUMBER

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_COMMAND_NOT_SUPPORTED

The DLN adapter does not support pull-down resistors.

Remarks
DLN-1 and DLN-2 adapters do not support pull-down resistors.

The DlnGpioPinPulldownIsEnable() function is declared in the dln_gpio.h file.

DlnGpioPinSetCfg() Function

The DlnGpioPinSetCfg() function changes the configuration of a single GPIO pin. It allows customizing the following:

  • Define the pin direction (input or output).

  • Enable or disable the open drain, pull up resistor and/or debounce filter.

  • Define the output value.

  • Define input event parameters.

With this function, you can either reconfigure the pin entirely or change only some of its parameters.

Syntax
C/C++
DLN_RESULT DlnGpioPinSetCfg(
   HDLN handle,
   uint16_t pin,
   uint16_t validFields,
   DLN_GPIO_PIN_CONFIG config
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A pin that you want to configure.

validFields

A bit field that defines the configuration parameters that you want to update. Each of the 16 bits of validFields corresponds to a specific parameter in the DLN_GPIO_PIN_CONFIG structure. If you set the bit to 1, the new configuration parameter will be applied. If you set the bit to 0, the configuration parameter will remain unchanged regardless of its value in the DLN_GPIO_PIN_CONFIG structure. You can also configure the pin parameters, using the constants declared in the dln_gpio.h file. If several constants are used, separate them with "| " (binary "or").Several bits are reserved for future use and must be set to 0.

BitsCorresponds toConstant

0

Bit 0 of DLN_GPIO_PIN_CONFIG::cfg

DLN_GPIO_ENABLE_BIT

1

Bit 1 of DLN_GPIO_PIN_CONFIG::cfg

DLN_GPIO_OUTPUT_BIT

2

Bit 2 of DLN_GPIO_PIN_CONFIG::cfg

DLN_GPIO_OUTPUT_VAL_BIT

3

Bit 3 of DLN_GPIO_PIN_CONFIG::cfg

DLN_GPIO_OPEN_DRAIN_BIT

4

Bit 4 of DLN_GPIO_PIN_CONFIG::cfg

DLN_GPIO_PULL_UP_BIT

5

Bit 5 of DLN_GPIO_PIN_CONFIG::cfg

DLN_GPIO_DEBOUNCE_BIT

6

Reserved

7

Reserved

8

DLN_GPIO_PIN_CONFIG::eventType

DLN_GPIO_EVENT_TYPE_BIT

9

DLN_GPIO_PIN_CONFIG::eventPeriod

DLN_GPIO_EVENT_PERIOD_BIT

10

Reserved

11

Reserved

12

Reserved

13

Reserved

14

Reserved

15

Reserved

In order to include a configuration field in the operation, set the corresponding bit to 1. If you set a bit to 0, the field will be ignored.For example, if you only need to change the isOutput and eventType settings, the validFields byte should look like this: 0000000100000010.You can configure the pin by using the constants declared in the dln_gpio.h file. In this case, the validFields byte should look like this:

C/C++
validFields
= DLN_GPIO_OUTPUT_BIT | DLN_GPIO_EVENT_TYPE_BIT;

config

A new configuration. See the DLN_GPIO_PIN_CONFIG structure for details.

Return Value
DLN_RES_SUCCESS (0x00)

The new configuration was successfully applied.

DLN_RES_INVALID_HANDLE (0x8F)

The specified handle is not valid.

DLN_RES_CONNECTION_LOST (0xA0)

The connection to the DLN server was interrupted.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

DLN_RES_NON_ZERO_RESERVED_BIT (0xAD)

One or more of the reserved bits validFields or config parameters are set to 1.

Remarks

The DlnGpioPinSetCfg() function is declared in the dln_gpio.h file.

DlnGpioPinGetCfg() Function

The DlnGpioPinGetCfg() function retrieves the current configuration of the specified GPIO pin.

Syntax
C/C++
DLN_RESULT DlnGpioPinGetCfg(
   HDLN handle,
   uint16_t pin, 
   DLN_GPIO_PIN_CONFIG* config
);
Parameters
handle

A handle to the DLN-series adapter.

pin

A number of the pin which configuration you want to know.

config

A pointer to the DLN_GPIO_PIN_CONFIG structure which is set to the configuration (after the function execution). This structure contains the following fields:

FieldDescription

cfg

A bit field that defines the pin configuration.

eventType

A type of the event.

eventPeriod

An interval for repeating events.

Return Value
DLN_RES_SUCCESS (0x00)

The function successfully retrieved the pin configuration.

DLN_RES_INVALID_HANDLE (0x8F)

The specified handle is not valid.

DLN_RES_CONNECTION_LOST (0xA0)

Connection to the DLN server was interrupted.

DLN_RES_INVALID_PIN_NUMBER (0xAB)

The pin number is not valid. Use the DlnGpioGetPinCount() function to find the maximum possible pin number.

Remarks

The DlnGpioPinGetCfg() function is declared in the dln_gpio.h file.

GPIO Event Structure

This section describes the structure used for GPIO events. This structure is declared in the dln_gpio.h file.

Rating: 
Голосов пока нет

DLN_GPIO_CONDITION_MET_EV Structure

The DLN_GPIO_CONDITION_MET_EV structure contains information about the current GPIO event on a pin.

Syntax
C/C++
typedef struct
{
        DLN_MSG_HEADER header;
        uint16_t eventCount;
        uint8_t eventType;
        uint16_t pin;
        uint8_t value;
} __PACKED_ATTR DLN_GPIO_CONDITION_MET_EV;
Event Structure Members
header

Defines the DLN message header. It should have the following value: DLN_MSG_ID_GPIO_CONDITION_MET_EV (0x010F)

eventCount

The number of events generated in the series. For the DLN_GPIO_EVENT_ALWAYS events, this field contains the number of events generated after the event configuration changed. For other events, this field contains the number of events generated since the previous level change.

eventType

The type of generating events. The following values are available:

ValueConstantDescription

0

DLN_GPIO_EVENT_NONE

No events are generated.

1

DLN_GPIO_EVENT_CHANGE

Events are generated when the input value changes.

2

DLN_GPIO_EVENT_LEVEL_HIGH

Events are generated when the high level (logic 1) is detected.

3

DLN_GPIO_EVENT_LEVEL_LOW

Events are generated when the low level (logic 0) is detected.

4

DLN_GPIO_EVENT_ALWAYS

The events are generated periodically with the predefined interval.

For more information, read Digital Input Events.

pin

The number of the pin where the event is generated.

value

The current value of the pin.

Remarks

The eventCount parameter contains information about the number of events generated in one event series. A new event series can start if:

  • event generation is enabled;

  • the event type is changed;

  • the level on the pin changed (except for DLN_GPIO_EVENT_ALWAYS events).

When a new series of events starts, the eventCount is reset to zero. This parameter increases by 1 when a new event in the series is generated.

Find examples of the eventCount values in the Digital Input Events section.

GPIO Structures

This section describes the structures used for the GPIO module. These structures are declared in the dln_gpio.h file.

Rating: 
Голосов пока нет

DLN_GPIO_PIN_EVENT_TYPES Structure

The DLN_GPIO_PIN_EVENT_TYPES structure contains information about the event types supported for a pin.

Syntax
C/C++
typedef struct
{
	uint8_t count;
	uint8_t eventTypes[8];
} __PACKED_ATTR DLN_GPIO_PIN_EVENT_TYPES;
Structure Members
count

The number of available event types.

eventTypes

An 8-element array. Each element corresponds to one of the supported event types.

DLN_GPIO_PIN_CONFIG Structure

The DLN_GPIO_PIN_CONFIG structure contains information about the pin configuration.

Syntax
C/C++
typedef struct
{
    uint16_t cfg;
    uint8_t eventType;	
    uint16_t eventPeriod;
} __PACKED_ATTR DLN_GPIO_PIN_CONFIG;
Structure Members
cfg

A bit field that defines the pin configuration and consists of 16 bits. Each of the bits 0-6, 8-9 corresponds to a specific parameter, that defines the pin configuration. The bits 7, 10-15 are reserved.

BitValueDescriptionConstant

0

0

The pin is not configured as a GPIO.

DLN_GPIO_DISABLED

0

1

The pin is configured as a GPIO.

DLN_GPIO_ENABLED

1

0

The pin is an input.

DLN_GPIO_INPUT

1

1

The pin is an output.

DLN_GPIO_OUTPUT

2

0

The output value is 0.

DLN_GPIO_OUTPUT_VAL_0

2

1

The output value is 1.

DLN_GPIO_OUTPUT_VAL_1

3

0

The output is open drain.

DLN_GPIO_OPEN_DRAIN_DISABLED

3

1

The output is push-pull.

DLN_GPIO_OPEN_DRAIN_ENABLED

4

0

The pull-up resistor is not active.

DLN_GPIO_PULLUP_DISABLED

4

1

The pull-up resistor is active.

DLN_GPIO_PULLUP_ENABLED

5

0

The debounce filter is not active.

DLN_GPIO_DEBOUNCE_DISABLED

5

1

The debounce filter is active.

DLN_GPIO_DEBOUNCE_ENABLED

6

0

The pull-down resistor is not active.

DLN_GPIO_PULLDOWN_DISABLED

6

1

The pull-down resistor is active.

DLN_GPIO_PULLDOWN_ENABLED

7

Reserved.

8

0

No events are generated.

DLN_GPIO_EVENT_DISABLED

8

1

Events are generated.

DLN_GPIO_EVENT_ENABLED

9

0

Single events are generated.

DLN_GPIO_EVENT_SINGLE

9

1

Periodical events are generated.

DLN_GPIO_EVENT_PERIODIC

10

Reserved.

11

Reserved.

12

Reserved.

13

Reserved.

14

Reserved.

15

Reserved.

eventType

A type of the event. The following values are available:

ValueConstantDescription

0

DLN_GPIO_EVENT_NONE

No events are generated.

1

DLN_GPIO_EVENT_CHANGE

Events are generated when the input value changes.

2

DLN_GPIO_EVENT_LEVEL_HIGH

Events are generated when the high level (logic 1) is detected.

3

DLN_GPIO_EVENT_LEVEL_LOW

Events are generated when the low level (logic 0) is detected.

4

DLN_GPIO_EVENT_ALWAYS

The events are generated periodically with the predefined interval.

For detailed information, read Digital Input Events.

eventPeriod

An interval in milliseconds (ms) at which the events are generated. If the interval is zero, the DLN adapter generates a single event when the level change meets the specified conditions.