PyMODINIT_FUNC initGPIO(void) #endif { int i; PyObject *module = NULL; #if PY_MAJOR_VERSION > 2 if ((module = PyModule_Create(&rpigpiomodule)) == NULL) return NULL; #else if ((module = Py_InitModule3("RPi.GPIO", rpi_gpio_methods, moduledocstring)) == NULL) return; #endif define_constants(module); for (i=0; i<54; i++) gpio_direction[i] = -1; // detect board revision and set up accordingly revision = get_rpi_revision(); if (revision == -1) { PyErr_SetString(PyExc_RuntimeError, "This module can only be run on a Raspberry Pi!"); setup_error = 1; #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } else if (revision == 1) { pin_to_gpio = &pin_to_gpio_rev1; } else if (revision == 2) { pin_to_gpio = &pin_to_gpio_rev2; } else { // assume model B+ pin_to_gpio = &pin_to_gpio_rev3; } rpi_revision = Py_BuildValue("i", revision); PyModule_AddObject(module, "RPI_REVISION", rpi_revision); // Add PWM class if (PWM_init_PWMType() == NULL) #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif Py_INCREF(&PWMType); PyModule_AddObject(module, "PWM", (PyObject*)&PWMType); if (!PyEval_ThreadsInitialized()) PyEval_InitThreads(); // register exit functions - last declared is called first if (Py_AtExit(cleanup) != 0) { setup_error = 1; cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } if (Py_AtExit(event_cleanup_all) != 0) { setup_error = 1; cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } #if PY_MAJOR_VERSION > 2 return module; #else return; #endif }
PyMODINIT_FUNC initGPIO(void) #endif { int i; PyObject *module = NULL; char cpuRev[1024] = {'\0'}; #if PY_MAJOR_VERSION > 2 if ((module = PyModule_Create(&lmkgpiomodule)) == NULL) return NULL; #else if ((module = Py_InitModule3("LMK.GPIO", lmk_gpio_methods, moduledocstring)) == NULL) return; #endif if (get_cpuinfo_revision(cpuRev) == NULL) #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif revision = get_lmk_revision(); debug("BOARD: revision(%d)\n",revision); define_constants(module); for (i=0; i<256; i++) gpio_direction[i] = -1; if (revision == -1) { PyErr_SetString(PyExc_RuntimeError, "This module can only be run on a Raspberry Pi!"); setup_error = 1; #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } lmk_revision = Py_BuildValue("i", revision); PyModule_AddObject(module, "LMK_REVISION", lmk_revision); // Add PWM class if (PWM_init_PWMType() == NULL){ #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } Py_INCREF(&PWMType); PyModule_AddObject(module, "PWM", (PyObject*)&PWMType); if (!PyEval_ThreadsInitialized()){ PyEval_InitThreads(); } //Initialized only once if (mmap_gpio_mem()) #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif // register exit functions - last declared is called first if (Py_AtExit(cleanup) != 0) { setup_error = 1; cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } if (Py_AtExit(event_cleanup_all) != 0) { setup_error = 1; cleanup(); #if PY_MAJOR_VERSION > 2 return NULL; #else return; #endif } #if PY_MAJOR_VERSION > 2 return module; #else return; #endif }