Skip to content

Commit

Permalink
Split SpiDev_open to prepare for open by path function.
Browse files Browse the repository at this point in the history
Prep for adding open_path Python method in doceme#129
  • Loading branch information
tim-seoss committed Apr 24, 2023
1 parent ac2671e commit 50c47a3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions spidev_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,9 @@ 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"
Expand All @@ -1345,8 +1348,6 @@ SpiDev_open(SpiDevObject *self, PyObject *args, PyObject *kwds)
{
int bus, device;
char path[SPIDEV_MAXPATH];
uint8_t tmp8;
uint32_t tmp32;
static char *kwlist[] = {"bus", "device", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii:open", kwlist, &bus, &device))
return NULL;
Expand All @@ -1355,7 +1356,15 @@ SpiDev_open(SpiDevObject *self, PyObject *args, PyObject *kwds)
"Bus and/or device number is invalid.");
return NULL;
}
if ((self->fd = open(path, O_RDWR, 0)) == -1) {
return SpiDev_open_dev(self, path);
}

static PyObject *
SpiDev_open_dev(SpiDevObject *self, char *dev_path)
{
uint8_t tmp8;
uint32_t tmp32;
if ((self->fd = open(dev_path, O_RDWR, 0)) == -1) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
Expand Down

0 comments on commit 50c47a3

Please sign in to comment.