Gpio setting

HI,i’m using a Q64 module and i must set up 2 pin, 1 IN / 1 OUT.I have realized this example making reference to Q64/WMP100 signals matching table.

#include "adl_global.h"

#define GPIO_OUTPUT_PIN 19
#define GPIO_INPUT_PIN 21

// GPIO service handle
static s32 MyGPIOHandle_OUT;
static s32 MyGPIOHandle_IN;
s32 ReadValue;
adl_ioDefs_t GpioConfig_OUT = ADL_IO_GPIO | GPIO_OUTPUT_PIN | ADL_IO_DIR_OUT;
adl_ioDefs_t GpioConfig_IN = ADL_IO_GPIO | GPIO_INPUT_PIN | ADL_IO_DIR_IN;

const u16 wm_apmCustomStackSize = 1024*3;

s32 MyGpioEventHandle;

void MyGpioEventHandler ( s32 GpioHandle, adl_ioEvent_e Event, u32 Size, void * Param ){

	s32 ReadValue_IN;
	s32 ReadValue_OUT;

	TRACE (( 1, "EVENT" ));

// Check event
switch ( Event ){

	case ADL_IO_EVENT_INPUT_CHANGED :
		//...
	}
}

// *** MAIN *** //

void adl_main ( adl_InitType_e  InitType ){
    adl_ioWriteSingle ( MyGPIOHandle_OUT, &GpioConfig_OUT, FALSE );
   adl_ioWriteSingle ( MyGPIOHandle_IN, &GpioConfig_IN, TRUE );
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
    MyGpioEventHandle = adl_ioEventSubscribe (MyGpioEventHandler);
    MyGPIOHandle_OUT = adl_ioSubscribe ( 1, &GpioConfig_OUT, 0, 0, 0 );
    TRACE (( 1, "GPIO (%d): %d", GPIO_OUTPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
    MyGPIOHandle_IN = adl_ioSubscribe ( 1, &GpioConfig_IN, 1, 1, MyGpioEventHandle );
    TRACE (( 1, "GPIO (%d): %d", GPIO_INPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
}

In these conditions ReadValue = -3 (ADL_RET_ERR_UNKNOWN_HDL)…
Instead if use command At+wiom=1, " GPIO19" , 1.1 for example,no problem…

if I try to change pin

#define GPIO_OUTPUT_PIN 3
#define GPIO_INPUT_PIN 16

ReadValue = 0 !!! but i have not more the matching of the pin…
Help :slight_smile:

Regards

Hiya,

In your main code, you haven’t subscribed to the ADL GPIO service before calling adl_ioWriteSingle() and adl_ioReadSingle() so your GPIO handles are undefined. Therefore the values of your handles are essentially ‘random noise’ - they contain watever value the RAM had in it when the CPU started.

Try something like this, instead (interleaved with your existing code…):

// *** MAIN *** //

// GPIO service handle
static s32 MyGPIOHandle_OUT = ERROR;    // mark handles as 'unused'
static s32 MyGPIOHandle_IN = ERROR;

void adl_main ( adl_InitType_e  InitType )
{
    // set up and connect to GPIO
    MyGpioEventHandle = adl_ioEventSubscribe (MyGpioEventHandler);
    MyGPIOHandle_IN = adl_ioSubscribe ( 1, &GpioConfig_IN, 1, 1, MyGpioEventHandle );
    TRACE (( 1, "GPIO_IN handle: %d", MyGPIOHandle_IN ));
    MyGPIOHandle_OUT = adl_ioSubscribe ( 1, &GpioConfig_OUT, 0, 0, 0 );
    TRACE (( 1, "GPIO_OUT handle: %d", MyGPIOHandle_OUT  ));

    // operate on GPIO
    adl_ioWriteSingle ( MyGPIOHandle_OUT, &GpioConfig_OUT, FALSE );
    adl_ioWriteSingle ( MyGPIOHandle_IN, &GpioConfig_IN, TRUE );
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));

    TRACE (( 1, "GPIO (%d): %d", GPIO_OUTPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));

    TRACE (( 1, "GPIO (%d): %d", GPIO_INPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
}

Let us how you get on.

ciao, Dave

Thanks Dave,
i try your code, but I obtain the same error (-3),it is as if I cannot setting those pin.
Help :slight_smile:
Regards

Hiya,

I’ll load your code into a Q2686 module when I’m at work tomorrow. Stay tuned.

ciao, Dave

On q2686 all ok , I do not receive no error

Hi

On Q64, the GPIO mapping is different and hence it is not always that something which works on WMP would also work on Q64 … Just read the Q64 User Guide once or better still ask your Distributor for the concerned mapping of GPIOs on Q64.

cheers… :smiley: