#define PY_SSIZE_T_CLEAN #include #include static PyObject * gpio_set_mode(PyObject * self, PyObject * args) { unsigned port; short mode; if (!PyArg_ParseTuple(args, "Ih", &port, &mode)) return NULL; hwd::gpio::set_mode(port, mode); Py_RETURN_NONE; } static PyObject * gpio_write(PyObject * self, PyObject * args) { unsigned port; short value; if (!PyArg_ParseTuple(args, "Ih", &port, &value)) return NULL; hwd::gpio::write(port, value); Py_RETURN_NONE; } static PyObject * gpio_read(PyObject * self, PyObject * args) { unsigned port; if (!PyArg_ParseTuple(args, "I", &port)) return NULL; const short value = hwd::gpio::read(port); return PyLong_FromLong(value); } static PyMethodDef gpio_methods[] = { {"set_mode", gpio_set_mode, METH_VARARGS, "set_mode(port, mode)\n--\n\nSets *mode* of a *port*."}, {"write", gpio_write, METH_VARARGS, "write(port, value)\n--\n\nWrites *value* to a *port*."}, {"read", gpio_read, METH_VARARGS, "read(port)\n--\n\nReads a value from a *port*."}, {NULL, NULL, 0, NULL} }; static struct PyModuleDef gpio_module = { PyModuleDef_HEAD_INIT, "gpio", NULL, -1, gpio_methods }; PyMODINIT_FUNC PyInit_gpio(void) { return PyModule_Create(&gpio_module); }