/* SPI initialization and configuration */
int lgw_spi_open(void **spi_target_ptr) {
	struct mpsse_context *mpsse = NULL;
	int a, b;
	
	/* check input variables */
	CHECK_NULL(spi_target_ptr); /* cannot be null, must point on a void pointer (*spi_target_ptr can be null) */
	
	/* try to open the first available FTDI device matching VID/PID parameters */
	mpsse = OpenIndex(VID,PID,SPI0, SIX_MHZ, MSB, IFACE_A, NULL, NULL, 0);
	if (mpsse == NULL) {
		DEBUG_MSG("ERROR: MPSSE OPEN FUNCTION RETURNED NULL\n");
		return LGW_SPI_ERROR;
	}
	if (mpsse->open != 1) {
		DEBUG_MSG("ERROR: MPSSE OPEN FUNCTION FAILED\n");
		return LGW_SPI_ERROR;
	}
	
	/* toggle pin ADBUS5 of the FT232H */
	/* On the MTAC-LORA, it resets the SX1301 */
	a = PinLow(mpsse, GPIOL1);
	b = PinHigh(mpsse, GPIOL1);
	if ((a != MPSSE_OK) || (b != MPSSE_OK)) {
		DEBUG_MSG("ERROR: IMPOSSIBLE TO TOGGLE GPIOL1/ADBUS5\n");
		return LGW_SPI_ERROR;
	}
	
	DEBUG_PRINTF("SPI port opened and configured ok\ndesc: %s\nPID: 0x%04X\nVID: 0x%04X\nclock: %d\nLibmpsse version: 0x%02X\n", GetDescription(mpsse), GetPid(mpsse), GetVid(mpsse), GetClock(mpsse), Version());
	*spi_target_ptr = (void *)mpsse;
	return LGW_SPI_SUCCESS;
}
int main(void)
{
    struct mpsse_context *io = NULL;
    int i = 0, retval = EXIT_FAILURE;

    uint8_t bus = 6;
    uint8_t ports[] = { 11, 7, 4 };
    int ports_size = 3;
    
    io = OpenPorts(0x0403, 0x6010, GPIO, 0, MSB, IFACE_A, bus, ports, ports_size);
    
    if(io && io->open)
    {
        for(i=0; i<10; i++)
        {
            PinHigh(io, GPIOH7);
            printf("GPIOH7 State: %d\n", PinState(io, GPIOH7, -1));
            sleep(1);
            
            PinLow(io, GPIOH7);
            printf("GPIOH7 State: %d\n", PinState(io, GPIOH7, -1));
            sleep(1);
        }
	
        retval = EXIT_SUCCESS;
    }
    else
    {
        printf("Failed to open MPSSE: %s\n", ErrorString(io));
    }
    
    Close(io);
    
    return retval;
}
Beispiel #3
0
int main(void)
{
	struct mpsse_context *io = NULL;
	int i = 0, retval = EXIT_FAILURE;

	io = MPSSE(GPIO, 0, 0);
	
	if(io && io->open)
	{
		for(i=0; i<10; i++)
		{
			PinHigh(io, GPIOL0);
			printf("GPIOL0 State: %d\n", PinState(io, GPIOL0, -1));
			sleep(1);
			
			PinLow(io, GPIOL0);
			printf("GPIOL0 State: %d\n", PinState(io, GPIOL0, -1));
			sleep(1);
		}
	
		retval = EXIT_SUCCESS;
	}
	else
	{
		printf("Failed to open MPSSE: %s\n", ErrorString(io));
	}
		
	Close(io);

	return retval;
}
Beispiel #4
0
int main(void)
{
	struct mpsse_context *io = NULL;
	int retval = EXIT_FAILURE;
	int i = 0;
	int j = 0;

	io = MPSSE(BITBANG, 0, 0);

	if(io && io->open)
	{
		for(i=0; i<10; i++)
		{
			for (j=0; j<8; j++)
			{
				PinHigh(io, j);
				printf("Pin %d is: %d\n", j, PinState(io, j, -1));
				usleep(100000);

				PinLow(io, j);
				printf("Pin %d is: %d\n", j, PinState(io, j, -1));
			}
		}

		retval = EXIT_SUCCESS;
	}
	else
	{
		printf("Failed to open MPSSE: %s\n", ErrorString(io));
	}

	Close(io);

	return retval;
}
Beispiel #5
0
/*!
  switch audio to radio r
  */
void ParallelPort::switchRadios(int r)
{
    int radioPin=settings.value(s_radios_focus,defaultParallelPortRadioPin).toInt();
    bool invert=settings.value(s_radios_focusinvert,false).toBool();
    if (r==0) {
        if (invert) {
            PinHigh(radioPin);
        } else {
            PinLow(radioPin);
        }
    } else {
        if (invert) {
            PinLow(radioPin);
        } else {
            PinHigh(radioPin);
        }
    }
}
Beispiel #6
0
// switch ptt routing
void ParallelPort::switchTransmit(int r)
{
    int txPin=settings.value(s_radios_txfocus,defaultParallelPortTxPin).toInt();
    bool invert=settings.value(s_radios_txfocusinvert,false).toBool();
    if (r==0) {
        if (invert) {
            PinHigh(txPin);
        } else {
            PinLow(txPin);
        }
    } else {
        if (invert) {
            PinLow(txPin);
        } else {
            PinHigh(txPin);
        }
    }
}
int set_spartan_program_b(struct mpsse_context *mpsse, unsigned char value) {
	int ret;

	if (!value)
		ret = PinHigh(mpsse, GPIOL3);
	else
		ret = PinLow(mpsse, GPIOL3);

	return ret;
}
Beispiel #8
0
/*!
  toggle pin stereoPin on parallel port
  */
void ParallelPort::toggleStereoPin()
{
    int stereoPin=settings.value(s_radios_stereo,defaultParallelPortStereoPin).toInt();
    if (stereoPinStatus) {
        PinLow(stereoPin);
        stereoPinStatus = false;
    } else {
        PinHigh(stereoPin);
        stereoPinStatus = true;
    }
}