Implement your own RPi. GPIO (1)-Python C Extension, rpi. gpio-python

Source: Internet
Author: User

Implement your own RPi. GPIO (1)-Python C Extension, rpi. gpio-python

Raspberry Pi has a Python module of RPi. GPIO. After import, you can directly use Python to operate the GPIO hardware module of the ARM chip. I think this is very interesting, so I want to implement this module on my own DM8148 platform.

DM8148 is a Da Vinci digital image processing chip launched by TI. It has slightly lower performance but lower power consumption than DM8168. In the past, many image processing companies used DM8168, but the heat dissipation and power consumption problems have been a headache, so I was able to pre-develop a more low-power DM8148. DM8148 can be understood as the heterogeneous core of ARM + DSP. What we need to use is its ARM core of Cortex A8.

Our company purchased a DVR-RDK instead of TI's EZSDK. The DVR-RDK4.0-provided compiler arm-arago-linux-gnueabi-gcc directory already contains Python2.6, I also cross-compiled Python2.7, but many libraries have problems, directly use the built-in Python2.6.

Python cannot directly operate on the hardware. directly operating on the hardware can only be implemented using C, and then calling C through the Python Extensions function. The following is a Demo of Python Extensions, which is copied from a Python tutorial:

 1 #include <python2.6/Python.h> 2 static PyObject *helloworld(PyObject *self) 3 { 4   return Py_BuildValue("s", "Hello, Python extensions!!"); 5 } 6 static char helloworld_docs[] = "helloworld():Any message you want to put hele! 7 "; 8 static PyMethodDef helloworld_funcs[] = { 9     {"helloworld", (PyCFunction)helloworld, METH_NOARGS, helloworld_docs},10     {NULL}11 };12 void inithelloworld(void)13 {14   Py_InitModule3("helloworld", helloworld_funcs, "Extension module example!");15 }

Cross-Compilation:

arm-arago-linux-gnueabi-gcc hello.c -g -I/home/jugg/CodeSourcery/cgt_a8/arago/linux-devkit/arm-arago-linux-gnueabi/usr/include/python2.6 -shared -L/home/jugg/CodeSourcery/cgt_a8/arago/linux-devkit/arm-arago-linux-gnueabi/usr/lib/python2.6 -o helloworld.so

Then copy the obtained helloworld. so to the Python library path:

cp ./helloworld.so /home/jugg/working_space/nfs/rfs_814x/usr/lib/python2.6/lib-dynload

Test on the DM8148 Board:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.