Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
...a python3 port.

PyBCM2835
=========

Python extension to provide functionality from the BCM2835 C library.
Python extension to provide functionality from the BCM2835 C library.
38 changes: 20 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from distutils.core import setup, Extension

pybcm2835 = Extension('PyBCM2835',
include_dirs = ['/usr/local/include'],
libraries = ['bcm2835'],
library_dirs = ['/usr/local/lib'],
sources = ['src/PyBCM2835.c'])
include_dirs=['/usr/local/include'],
libraries=['bcm2835'],
library_dirs=['/usr/local/lib'],
sources=['src/PyBCM2835.c'],
)

setup (name = 'PyBCM2835',
version = '0.1.0',
description = 'Python extension for libbcm2835.',
author='Chris Kloberdanz',
author_email='klobyone@gmail.com',
license='GPLv2',
keywords=["raspberry pi", "bcm2835", "gpio"],
classifiers=[
"Programming Language :: Python",
"Development Status :: 3 - Alpha",
"Topic :: System :: Hardware"
],
url='http://www.github.com/klobyone/PyBCM2385/',
ext_modules = [pybcm2835])
setup(name='PyBCM2835',
version='0.1.0',
description='Python extension for libbcm2835.',
author='Chris Kloberdanz',
author_email='klobyone@gmail.com',
license='GPLv2',
keywords=['raspberry pi', 'bcm2835', 'gpio'],
classifiers=[
'Programming Language :: Python',
'Development Status :: 3 - Alpha',
'Topic :: System :: Hardware'
],
url='http://www.github.com/klobyone/PyBCM2385/',
ext_modules=[pybcm2835]
)
107 changes: 61 additions & 46 deletions src/PyBCM2835.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,56 +539,69 @@ PyBCM2835_spi_transfern(PyObject *self, PyObject *args)
static PyObject *PyBCM2835Error;

static PyMethodDef PyBCM2835Methods[] = {
{"init", (PyCFunction)PyBCM2835_init, METH_NOARGS, "Initialize BCM2835 library."},
{"close", (PyCFunction)PyBCM2835_close, METH_NOARGS, "Close BCM2835 library."},
{"set_debug", (PyCFunction)PyBCM2835_set_debug, METH_VARARGS, "Set debug level."},
{"gpio_fsel", (PyCFunction)PyBCM2835_gpio_fsel, METH_VARARGS, "Sets the Function Select register for the given pin, which configures the pin as Input, Output or one of the 6 alternate functions."},
{"gpio_set", (PyCFunction)PyBCM2835_gpio_set, METH_VARARGS, "Sets the specified pin output to HIGH."},
{"gpio_clr", (PyCFunction)PyBCM2835_gpio_clr, METH_VARARGS, "Sets the specified pin output to LOW."},
{"gpio_lev", (PyCFunction)PyBCM2835_gpio_lev, METH_VARARGS, "Reads the current level on the specified pin and returns either HIGH or LOW. Works whether or not the pin is an input or an output."},
{"gpio_eds", (PyCFunction)PyBCM2835_gpio_eds, METH_VARARGS, "Event Detect Status. Tests whether the specified pin has detected a level or edge."},
{"gpio_set_eds", (PyCFunction)PyBCM2835_gpio_set_eds, METH_VARARGS, "Sets the Event Detect Status register for a given pin to 1, which has the effect of clearing the flag. Use this afer seeing an Event Detect Status on the pin."},
{"gpio_ren", (PyCFunction)PyBCM2835_gpio_ren, METH_VARARGS, "Enable Rising Edge Detect Enable for the specified pin. When a rising edge is detected, sets the appropriate pin in Event Detect Status. The GPRENn registers use synchronous edge detection. This means the input signal is sampled using the system clock and then it is looking for a ?011? pattern on the sampled signal. This has the effect of suppressing glitches."},
{"gpio_clr_ren", (PyCFunction)PyBCM2835_gpio_clr_ren, METH_VARARGS, "Disable Rising Edge Detect Enable for the specified pin."},
{"gpio_fen", (PyCFunction)PyBCM2835_gpio_fen, METH_VARARGS, "Disable Falling Edge Detect Enable for the specified pin."},
{"gpio_clr_fen", (PyCFunction)PyBCM2835_gpio_clr_fen, METH_VARARGS, "Disable Falling Edge Detect Enable for the specified pin."},
{"gpio_hen", (PyCFunction)PyBCM2835_gpio_hen, METH_VARARGS, "Enable High Detect Enable for the specified pin. When a HIGH level is detected on the pin, sets the appropriate pin in Event Detect Status."},
{"gpio_clr_hen", (PyCFunction)PyBCM2835_gpio_clr_hen, METH_VARARGS, "Disable High Detect Enable for the specified pin."},
{"gpio_len", (PyCFunction)PyBCM2835_gpio_len, METH_VARARGS, "Enable Low Detect Enable for the specified pin. When a LOW level is detected on the pin, sets the appropriate pin in Event Detect Status."},
{"gpio_clr_len", (PyCFunction)PyBCM2835_gpio_clr_len, METH_VARARGS, "Disable Low Detect Enable for the specified pin."},
{"gpio_aren", (PyCFunction)PyBCM2835_gpio_aren, METH_VARARGS, "Enable Asynchronous Rising Edge Detect Enable for the specified pin. When a rising edge is detected, sets the appropriate pin in Event Detect Status. Asynchronous means the incoming signal is not sampled by the system clock. As such rising edges of very short duration can be detected."},
{"gpio_clr_aren", (PyCFunction)PyBCM2835_gpio_clr_aren, METH_VARARGS, "Disable Asynchronous Rising Edge Detect Enable for the specified pin."},
{"gpio_afen", (PyCFunction)PyBCM2835_gpio_afen, METH_VARARGS, "Enable Asynchronous Falling Edge Detect Enable for the specified pin. When a falling edge is detected, sets the appropriate pin in Event Detect Status. Asynchronous means the incoming signal is not sampled by the system clock. As such falling edges of very short duration can be detected."},
{"gpio_clr_afen", (PyCFunction)PyBCM2835_gpio_clr_afen, METH_VARARGS, "Disable Asynchronous Falling Edge Detect Enable for the specified pin."},
{"gpio_pud", (PyCFunction)PyBCM2835_gpio_pud, METH_VARARGS, "Sets the Pull-up/down register for the given pin."},
{"gpio_pudclk", (PyCFunction)PyBCM2835_gpio_pudclk, METH_VARARGS, "Clocks the Pull-up/down value set earlier by bcm2835_gpio_pud() into the pin."},
{"gpio_pad", (PyCFunction)PyBCM2835_gpio_pad, METH_VARARGS, "Reads and returns the Pad Control for the given GPIO group."},
{"gpio_set_pad", (PyCFunction)PyBCM2835_gpio_set_pad, METH_VARARGS, "Sets the Pad Control for the given GPIO group."},
{"delay", (PyCFunction)PyBCM2835_delay, METH_VARARGS, "Delays for the specified number of milliseconds."},
{"delay_microseconds", (PyCFunction)PyBCM2835_delay_microseconds, METH_VARARGS, "Delays for the specified number of microseconds."},
{"gpio_write", (PyCFunction)PyBCM2835_gpio_write, METH_VARARGS, "Sets the output state of the specified pin."},
{"gpio_set_pud", (PyCFunction)PyBCM2835_gpio_set_pud, METH_VARARGS, "Sets the Pull-up/down mode for the specified pin."},
{"spi_begin", (PyCFunction)PyBCM2835_spi_begin, METH_NOARGS, "Start SPI operations."},
{"spi_end", (PyCFunction)PyBCM2835_spi_end, METH_NOARGS, "End SPI operations."},
{"spi_setBitOrder", (PyCFunction)PyBCM2835_spi_setBitOrder, METH_VARARGS, "Sets the SPI bit order NOTE: has no effect."},
{"spi_setClockDivider", (PyCFunction)PyBCM2835_spi_setClockDivider, METH_VARARGS, "Sets the SPI clock divider and therefore the SPI clock speed."},
{"spi_setDataMode", (PyCFunction)PyBCM2835_spi_setDataMode, METH_VARARGS, "Sets the SPI data mode Sets the clock polariy and phase."},
{"spi_chipSelect", (PyCFunction)PyBCM2835_spi_chipSelect, METH_VARARGS, "Sets the chip select pin(s) When an bcm2835_spi_transfer() is made, the selected pin(s) will be asserted during the transfer."},
{"spi_setChipSelectPolarity", (PyCFunction)PyBCM2835_spi_setChipSelectPolarity, METH_VARARGS, "Sets the chip select pin polarity for a given pin."},
{"spi_transfer", (PyCFunction)PyBCM2835_spi_transfer, METH_VARARGS, "Transfers one byte to and from the currently selected SPI slave."},
{"spi_transfernb", (PyCFunction)PyBCM2835_spi_transfernb, METH_VARARGS, "Transfers any number of bytes to and from the currently selected SPI slave."},
{"spi_transfern", (PyCFunction)PyBCM2835_spi_transfern, METH_VARARGS, "Transfers any number of bytes to and from the currently selected SPI slave using bcm2835_spi_transfernb. "},
{NULL, NULL, 0, NULL} /* Sentinel */
{"init", (PyCFunction)PyBCM2835_init, METH_NOARGS, "Initialize BCM2835 library."},
{"close", (PyCFunction)PyBCM2835_close, METH_NOARGS, "Close BCM2835 library."},
{"set_debug", (PyCFunction)PyBCM2835_set_debug, METH_VARARGS, "Set debug level."},
{"gpio_fsel", (PyCFunction)PyBCM2835_gpio_fsel, METH_VARARGS, "Sets the Function Select register for the given pin, which configures the pin as Input, Output or one of the 6 alternate functions."},
{"gpio_set", (PyCFunction)PyBCM2835_gpio_set, METH_VARARGS, "Sets the specified pin output to HIGH."},
{"gpio_clr", (PyCFunction)PyBCM2835_gpio_clr, METH_VARARGS, "Sets the specified pin output to LOW."},
{"gpio_lev", (PyCFunction)PyBCM2835_gpio_lev, METH_VARARGS, "Reads the current level on the specified pin and returns either HIGH or LOW. Works whether or not the pin is an input or an output."},
{"gpio_eds", (PyCFunction)PyBCM2835_gpio_eds, METH_VARARGS, "Event Detect Status. Tests whether the specified pin has detected a level or edge."},
{"gpio_set_eds", (PyCFunction)PyBCM2835_gpio_set_eds, METH_VARARGS, "Sets the Event Detect Status register for a given pin to 1, which has the effect of clearing the flag. Use this afer seeing an Event Detect Status on the pin."},
{"gpio_ren", (PyCFunction)PyBCM2835_gpio_ren, METH_VARARGS, "Enable Rising Edge Detect Enable for the specified pin. When a rising edge is detected, sets the appropriate pin in Event Detect Status. The GPRENn registers use synchronous edge detection. This means the input signal is sampled using the system clock and then it is looking for a ?011? pattern on the sampled signal. This has the effect of suppressing glitches."},
{"gpio_clr_ren", (PyCFunction)PyBCM2835_gpio_clr_ren, METH_VARARGS, "Disable Rising Edge Detect Enable for the specified pin."},
{"gpio_fen", (PyCFunction)PyBCM2835_gpio_fen, METH_VARARGS, "Disable Falling Edge Detect Enable for the specified pin."},
{"gpio_clr_fen", (PyCFunction)PyBCM2835_gpio_clr_fen, METH_VARARGS, "Disable Falling Edge Detect Enable for the specified pin."},
{"gpio_hen", (PyCFunction)PyBCM2835_gpio_hen, METH_VARARGS, "Enable High Detect Enable for the specified pin. When a HIGH level is detected on the pin, sets the appropriate pin in Event Detect Status."},
{"gpio_clr_hen", (PyCFunction)PyBCM2835_gpio_clr_hen, METH_VARARGS, "Disable High Detect Enable for the specified pin."},
{"gpio_len", (PyCFunction)PyBCM2835_gpio_len, METH_VARARGS, "Enable Low Detect Enable for the specified pin. When a LOW level is detected on the pin, sets the appropriate pin in Event Detect Status."},
{"gpio_clr_len", (PyCFunction)PyBCM2835_gpio_clr_len, METH_VARARGS, "Disable Low Detect Enable for the specified pin."},
{"gpio_aren", (PyCFunction)PyBCM2835_gpio_aren, METH_VARARGS, "Enable Asynchronous Rising Edge Detect Enable for the specified pin. When a rising edge is detected, sets the appropriate pin in Event Detect Status. Asynchronous means the incoming signal is not sampled by the system clock. As such rising edges of very short duration can be detected."},
{"gpio_clr_aren", (PyCFunction)PyBCM2835_gpio_clr_aren, METH_VARARGS, "Disable Asynchronous Rising Edge Detect Enable for the specified pin."},
{"gpio_afen", (PyCFunction)PyBCM2835_gpio_afen, METH_VARARGS, "Enable Asynchronous Falling Edge Detect Enable for the specified pin. When a falling edge is detected, sets the appropriate pin in Event Detect Status. Asynchronous means the incoming signal is not sampled by the system clock. As such falling edges of very short duration can be detected."},
{"gpio_clr_afen", (PyCFunction)PyBCM2835_gpio_clr_afen, METH_VARARGS, "Disable Asynchronous Falling Edge Detect Enable for the specified pin."},
{"gpio_pud", (PyCFunction)PyBCM2835_gpio_pud, METH_VARARGS, "Sets the Pull-up/down register for the given pin."},
{"gpio_pudclk", (PyCFunction)PyBCM2835_gpio_pudclk, METH_VARARGS, "Clocks the Pull-up/down value set earlier by bcm2835_gpio_pud() into the pin."},
{"gpio_pad", (PyCFunction)PyBCM2835_gpio_pad, METH_VARARGS, "Reads and returns the Pad Control for the given GPIO group."},
{"gpio_set_pad", (PyCFunction)PyBCM2835_gpio_set_pad, METH_VARARGS, "Sets the Pad Control for the given GPIO group."},
{"delay", (PyCFunction)PyBCM2835_delay, METH_VARARGS, "Delays for the specified number of milliseconds."},
{"delay_microseconds", (PyCFunction)PyBCM2835_delay_microseconds, METH_VARARGS, "Delays for the specified number of microseconds."},
{"gpio_write", (PyCFunction)PyBCM2835_gpio_write, METH_VARARGS, "Sets the output state of the specified pin."},
{"gpio_set_pud", (PyCFunction)PyBCM2835_gpio_set_pud, METH_VARARGS, "Sets the Pull-up/down mode for the specified pin."},
{"spi_begin", (PyCFunction)PyBCM2835_spi_begin, METH_NOARGS, "Start SPI operations."},
{"spi_end", (PyCFunction)PyBCM2835_spi_end, METH_NOARGS, "End SPI operations."},
{"spi_setBitOrder", (PyCFunction)PyBCM2835_spi_setBitOrder, METH_VARARGS, "Sets the SPI bit order NOTE: has no effect."},
{"spi_setClockDivider", (PyCFunction)PyBCM2835_spi_setClockDivider, METH_VARARGS, "Sets the SPI clock divider and therefore the SPI clock speed."},
{"spi_setDataMode", (PyCFunction)PyBCM2835_spi_setDataMode, METH_VARARGS, "Sets the SPI data mode Sets the clock polariy and phase."},
{"spi_chipSelect", (PyCFunction)PyBCM2835_spi_chipSelect, METH_VARARGS, "Sets the chip select pin(s) When an bcm2835_spi_transfer() is made, the selected pin(s) will be asserted during the transfer."},
{"spi_setChipSelectPolarity", (PyCFunction)PyBCM2835_spi_setChipSelectPolarity, METH_VARARGS, "Sets the chip select pin polarity for a given pin."},
{"spi_transfer", (PyCFunction)PyBCM2835_spi_transfer, METH_VARARGS, "Transfers one byte to and from the currently selected SPI slave."},
{"spi_transfernb", (PyCFunction)PyBCM2835_spi_transfernb, METH_VARARGS, "Transfers any number of bytes to and from the currently selected SPI slave."},
{"spi_transfern", (PyCFunction)PyBCM2835_spi_transfern, METH_VARARGS, "Transfers any number of bytes to and from the currently selected SPI slave using bcm2835_spi_transfernb. "},
{NULL, NULL, 0, NULL} /* Sentinel */
};


static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"PyBCM2835",
NULL,
-1,
PyBCM2835Methods,
NULL,
NULL,
NULL,
NULL,
};

PyMODINIT_FUNC
initPyBCM2835(void)
PyInit_PyBCM2835(void)
{
PyObject *m;
PyObject *m;

m = Py_InitModule("PyBCM2835", PyBCM2835Methods);
if (m == NULL)
return;
m = PyModule_Create(&moduledef);
if (m == NULL)
return NULL;

// Constants
PyModule_AddIntConstant(m,"HIGH",1);
Expand Down Expand Up @@ -671,7 +684,7 @@ initPyBCM2835(void)
PyModule_AddIntConstant(m,"BCM2835_SPI0_CS_CS",BCM2835_SPI0_CS_CS);
//PyModule_AddIntConstant(m,"",);

// Function Select
// Function Select
PyModule_AddIntConstant(m,"GPIO_FSEL_INPT",BCM2835_GPIO_FSEL_INPT);
PyModule_AddIntConstant(m,"GPIO_FSEL_OUTP",BCM2835_GPIO_FSEL_OUTP);
PyModule_AddIntConstant(m,"GPIO_FSEL_ALT0",BCM2835_GPIO_FSEL_ALT0);
Expand Down Expand Up @@ -766,4 +779,6 @@ initPyBCM2835(void)
PyBCM2835Error = PyErr_NewException("PyBCM2835.error", NULL, NULL);
Py_INCREF(PyBCM2835Error);
PyModule_AddObject(m, "error", PyBCM2835Error);

return m;
}