Пример #1
1
int main(int argc, char *argv[]){
  int gpio = atoi(argv[1]);   
  unsigned int i;
  
  gpioExport(gpio); 
  gpioDirection(gpio, gpioDIRECTION_IN);
    
  while(1){
    printf("Read: %c\n", gpioRead(gpio));
    for(i=0; i<9000000; ++i);
  }  
  return 0;
}
Пример #2
0
Stm32p::Stm32p(QObject *parent) :
    QObject(parent)
{
    STM32 = new stm32Driver(STM32F401_ADDRESS);

    sectorStartAddress << 0x08000000 << 0x08004000 << 0x08008000 << 0x0800C000 << 0x08010000 << 0x08020000 << 0x08040000 << 0x08060000;
    sectorEndAddress   << 0x08003FFF << 0x08007FFF << 0x0800BFFF << 0x0800FFFF << 0x0801FFFF << 0x0803FFFF << 0x0805FFFF << 0x0807FFFF;
    sectorErased << false << false << false << false << false << false << false << false;

    startAfterProgramming = false;
    doneProgramming = false;

    gpioExport();
}
Пример #3
0
// Initialize GPIO module
void MW_gpioInit(int32_T gpio, boolean_T direction, uint32_T internalResistor, const uint8_T *pinName)
{
    GPIO_info *gpioInfoPtr;
    
    gpioInfo = realloc(gpioInfo, (numGpio + 1) * sizeof(GPIO_info));
    if (gpioInfo == NULL) {
        fprintf(stderr, "Error allocating memory for GPIO pin %d.\n", gpio);
        MW_gpioExit();
    }
    gpioInfoPtr = gpioInfo + numGpio;
    
    //Fill in GPIO info structure for the GPIO module
#ifdef _DEBUG
    printf("gpio = %d, direction = %d, internalRes = %d, pinName = %s\n", 
        gpio, direction, internalResistor, pinName);
#endif
    gpioInfoPtr->gpio             = gpio;
    gpioInfoPtr->direction        = direction;
    gpioInfoPtr->internalResistor = internalResistor;
    gpioInfoPtr->fd               = -1;
    strcpy(&(gpioInfoPtr->pinName[0]), pinName); 
    numGpio++;
    
    // Set pin muxing and claim GPIO pin
    if (setGpioPinMux(pinName, direction, internalResistor) < 0) {
        fprintf(stderr, "Error setting PIN MUX.\n");
        MW_gpioExit();
    }
    if (gpioExport(gpio) < 0) {
        fprintf(stderr, "Error exporting GPIO pin.\n");
        MW_gpioExit();
    }
	if (gpioSetDirection(gpio, direction) < 0) { 
        fprintf(stderr, "Error setting GPIO pin direction.\n");
        MW_gpioExit();
    }
	gpioInfoPtr->fd = gpioOpen(gpio, direction);
    if (gpioInfoPtr->fd < 0) {
        fprintf(stderr, "Error opening GPIO.\n");
        MW_gpioExit();
    }
#ifdef _DEBUG
    MW_dumpGpioInfo("INIT");
#endif
}
Пример #4
0
bool SysfsGPIO::configureGPIO(GPIO_Pin gpionr, QString direction)
{
    //First check that the export file is there,
    //if it is missing then the sysfs gpio "module" is not loaded.
    QFile gpioExport("/sys/class/gpio/export");
    if(!gpioExport.exists())
    {
        myErr() << "missing file: /sys/class/gpio/export";
        return false;
    }

    //If value does not exist then export
    QFile gpioDirection(QString("/sys/class/gpio/gpio%1/direction").arg(gpionr));
    if(!gpioDirection.exists())
    {
        //myOut() << gpioDirection.fileName();

        if (!gpioExport.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            myErr() << gpioExport.fileName();
            return false;
        }

        QTextStream out(&gpioExport);
        out << gpionr << "\n";
        gpioExport.close();
        sleep(1);
    }

    {
        if (!gpioDirection.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            myErr() << gpioDirection.fileName();
            return false;
        }

        QTextStream out(&gpioDirection);
        out << direction << "\n";
        gpioDirection.close();
    }

    return true;
}
Пример #5
0
// custom the robot behaviors
// init_robot_gpio
void init_robot_gpio(void)
{
  gpioExport(OUT1);
  gpioSetDirection(OUT1, outputPin);
  gpioExport(OUT2);
  gpioSetDirection(OUT2, outputPin);
  gpioExport(OUT3);
  gpioSetDirection(OUT3, outputPin);
  gpioExport(OUT4);
  gpioSetDirection(OUT4, outputPin);
  gpioExport(ENGINE_LEFT);
  gpioSetDirection(ENGINE_LEFT, outputPin);
  gpioExport(ENGINE_RIGHT);
  gpioSetDirection(ENGINE_RIGHT, outputPin);
}
Пример #6
0
static int
ili9341_init(ILI9341PyObject *self, PyObject *args, PyObject *kwds) {
	int i;
	int bus, chip_select, pin_dc, pin_reset;
	char path[SPIDEV_MAXPATH];
	static char *kwlist[] = {"bus", "chip_select", "dc", "reset", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwlist, &bus, &chip_select, &pin_dc, &pin_reset))
		return -1;

	if (snprintf(path, SPIDEV_MAXPATH, "/dev/spidev%d.%d", bus, chip_select) >= SPIDEV_MAXPATH) {
		return -1;
	}

	if ((self->fd = open(path, O_RDWR)) < 0) {
		return -1;
	}

	// setup CS and RST pins
	self->pin_dc = pin_dc;
	self->pin_reset = pin_reset;

	gpioExport(self->pin_dc);
	gpioSetDirection(self->pin_dc, OUTPUT);
	self->fd_dc = gpioOpenSet(self->pin_dc);

	gpioExport(self->pin_reset);
	gpioSetDirection(self->pin_reset, OUTPUT);
	self->fd_reset = gpioOpenSet(self->pin_reset);

	self->width = ILI9341_TFTWIDTH;
	self->height = ILI9341_TFTHEIGHT;
	self->color = 0xffff;
	self->bg_color = 0;
	self->cursor_x = 0;
	self->cursor_y = 0;

	self->font = System5x7;
	self->char_spacing = 1;

	TFT_DC_HIGH;

	TFT_RST_LOW;
	for(i=0; i<0x7FFFFF; i++);
	TFT_RST_HIGH;

	TFT_sendCMD(self, 0xEF);
	TFT_sendDATA(self, 0x03);
	TFT_sendDATA(self, 0x80);
	TFT_sendDATA(self, 0x02);
  
	TFT_sendCMD(self, 0xCB);
	TFT_sendDATA(self, 0x39);
	TFT_sendDATA(self, 0x2C);
	TFT_sendDATA(self, 0x00);
	TFT_sendDATA(self, 0x34);
	TFT_sendDATA(self, 0x02);
  
	TFT_sendCMD(self, 0xCF);
	TFT_sendDATA(self, 0x00);
	TFT_sendDATA(self, 0xC1);
	TFT_sendDATA(self, 0x30);

	TFT_sendCMD(self, 0xE8);
	TFT_sendDATA(self, 0x85);
	TFT_sendDATA(self, 0x00);
	TFT_sendDATA(self, 0x78);

	TFT_sendCMD(self, 0xEA);
	TFT_sendDATA(self, 0x00);
	TFT_sendDATA(self, 0x00);

	TFT_sendCMD(self, 0xED);
	TFT_sendDATA(self, 0x64);
	TFT_sendDATA(self, 0x03);
	TFT_sendDATA(self, 0x12);
	TFT_sendDATA(self, 0x81);

	TFT_sendCMD(self, 0xF7);
	TFT_sendDATA(self, 0x20);

	TFT_sendCMD(self, ILI9341_PWCTR1);    	//Power control
	TFT_sendDATA(self, 0x23);   	//VRH[5:0]

	TFT_sendCMD(self, ILI9341_PWCTR2);    	//Power control
	TFT_sendDATA(self, 0x10);   	//SAP[2:0];BT[3:0]

	TFT_sendCMD(self, ILI9341_VMCTR1);    	//VCM control
	TFT_sendDATA(self, 0x3e);   	//Contrast
	TFT_sendDATA(self, 0x28);

	TFT_sendCMD(self, ILI9341_VMCTR2);    	//VCM control2
	TFT_sendDATA(self, 0x86);  	 //--

	TFT_sendCMD(self, ILI9341_MADCTL);    	// Memory Access Control
	TFT_sendDATA(self, MADCTL_MX | MADCTL_BGR);

	TFT_sendCMD(self, ILI9341_PIXFMT);
	TFT_sendDATA(self, 0x55);

	TFT_sendCMD(self, ILI9341_FRMCTR1);
	TFT_sendDATA(self, 0x00);
	TFT_sendDATA(self, 0x18);

	TFT_sendCMD(self, ILI9341_DFUNCTR);    	// Display Function Control
	TFT_sendDATA(self, 0x08);
	TFT_sendDATA(self, 0x82);
	TFT_sendDATA(self, 0x27);

	TFT_sendCMD(self, 0xF2);    	// 3Gamma Function Disable
	TFT_sendDATA(self, 0x00);

	TFT_sendCMD(self, ILI9341_GAMMASET);    	//Gamma curve selected
	TFT_sendDATA(self, 0x01);

	TFT_sendCMD(self, ILI9341_GMCTRP1);    	//Set Gamma
	TFT_sendDATA(self, 0x0F);
	TFT_sendDATA(self, 0x31);
	TFT_sendDATA(self, 0x2B);
	TFT_sendDATA(self, 0x0C);
	TFT_sendDATA(self, 0x0E);
	TFT_sendDATA(self, 0x08);
	TFT_sendDATA(self, 0x4E);
	TFT_sendDATA(self, 0xF1);
	TFT_sendDATA(self, 0x37);
	TFT_sendDATA(self, 0x07);
	TFT_sendDATA(self, 0x10);
	TFT_sendDATA(self, 0x03);
	TFT_sendDATA(self, 0x0E);
	TFT_sendDATA(self, 0x09);
	TFT_sendDATA(self, 0x00);

	TFT_sendCMD(self, ILI9341_GMCTRN1);    	//Set Gamma
	TFT_sendDATA(self, 0x00);
	TFT_sendDATA(self, 0x0E);
	TFT_sendDATA(self, 0x14);
	TFT_sendDATA(self, 0x03);
	TFT_sendDATA(self, 0x11);
	TFT_sendDATA(self, 0x07);
	TFT_sendDATA(self, 0x31);
	TFT_sendDATA(self, 0xC1);
	TFT_sendDATA(self, 0x48);
	TFT_sendDATA(self, 0x08);
	TFT_sendDATA(self, 0x0F);
	TFT_sendDATA(self, 0x0C);
	TFT_sendDATA(self, 0x31);
	TFT_sendDATA(self, 0x36);
	TFT_sendDATA(self, 0x0F);

	TFT_sendCMD(self, ILI9341_SLPOUT);    	//Exit Sleep
	for(i=0; i<0x7FFFFF; i++);

	TFT_sendCMD(self, ILI9341_DISPON);    //Display on
	TFT_sendCMD(self, 0x2c);

	return 0;
}