diff --git a/spidev_module.c b/spidev_module.c index 95068fd..cf12a1d 100644 --- a/spidev_module.c +++ b/spidev_module.c @@ -1335,30 +1335,6 @@ static PyGetSetDef SpiDev_getset[] = { {NULL}, }; -static PyObject * -SpiDev_open_dev(SpiDevObject *self, char *dev_path); - -PyDoc_STRVAR(SpiDev_open_doc, - "open(bus, device)\n\n" - "Connects the object to the specified SPI device.\n" - "open(X,Y) will open /dev/spidev.\n"); - -static PyObject * -SpiDev_open(SpiDevObject *self, PyObject *args, PyObject *kwds) -{ - int bus, device; - char path[SPIDEV_MAXPATH]; - static char *kwlist[] = {"bus", "device", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii:open", kwlist, &bus, &device)) - return NULL; - if (snprintf(path, SPIDEV_MAXPATH, "/dev/spidev%d.%d", bus, device) >= SPIDEV_MAXPATH) { - PyErr_SetString(PyExc_OverflowError, - "Bus and/or device number is invalid."); - return NULL; - } - return SpiDev_open_dev(self, path); -} - static PyObject * SpiDev_open_dev(SpiDevObject *self, char *dev_path) { @@ -1388,6 +1364,28 @@ SpiDev_open_dev(SpiDevObject *self, char *dev_path) return Py_None; } + +PyDoc_STRVAR(SpiDev_open_doc, + "open(bus, device)\n\n" + "Connects the object to the specified SPI device.\n" + "open(X,Y) will open /dev/spidev.\n"); + +static PyObject * +SpiDev_open(SpiDevObject *self, PyObject *args, PyObject *kwds) +{ + int bus, device; + char path[SPIDEV_MAXPATH]; + static char *kwlist[] = {"bus", "device", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii:open", kwlist, &bus, &device)) + return NULL; + if (snprintf(path, SPIDEV_MAXPATH, "/dev/spidev%d.%d", bus, device) >= SPIDEV_MAXPATH) { + PyErr_SetString(PyExc_OverflowError, + "Bus and/or device number is invalid."); + return NULL; + } + return SpiDev_open_dev(self, path); +} + static int SpiDev_init(SpiDevObject *self, PyObject *args, PyObject *kwds) {