Exemple #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;
}
Exemple #2
0
/*
 * Frontend of STM programmer
 */
void Stm32p::startProgram()
{
    vddStateSet(false);
    QThread::msleep(300);

    gpioDirection(GPIO_OUT);

    /* GPIO low when reset released enters bootloader */
    gpioStateSet(false);
    vddStateSet(true);

    /* The voltagesupervisor keeps reset active for max 300ms */
    QThread::msleep(400);

    QByteArray bootloaderVersion = STM32->cmdGetBootloaderVersion();
    if (bootloaderVersion == QByteArray())
        qCritical() << "Get Version Failed";
    else
        printf("Bootloader version v%s.%s\n", qPrintable(bootloaderVersion.toHex().at(0)), qPrintable(bootloaderVersion.toHex().at(1)));


    QByteArray chipId = STM32->cmdGetId();
    if (chipId == QByteArray())
        qCritical() << "Get ID Failed";
    else
        printf("Device id is 0x%s\n", qPrintable(chipId.toHex()));

    if (!hexFile.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        qCritical() << "Error opening file";
        return;
    }

    QByteArray data;
    unsigned long address = 0;
    QTextStream infile(&hexFile);

    while (parseHex(&infile, &address, &data))
    {
        for (int i=0; i<sectorErased.size(); ++i)
            if (address >= sectorStartAddress.at(i) && address <= sectorEndAddress.at(i) && !sectorErased.at(i))
            {
                printf("Erasing sector %d (0x%08lx...%08lx)\n", i, sectorStartAddress.at(i), sectorEndAddress.at(i));
                STM32->cmdEraseMemory(i);
                sectorErased.replace(i, true);
            }
        printf("Programming 0x%08lx\r", address);
        STM32->cmdWriteMemory(address, data);
    }
    printf("\n");

    doneProgramming = true;

}
Exemple #3
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;
}