mmap and bit wise twiddling - Raspberry Pi

Petr Jakes petr.jakes.tpc at gmail.com
Wed May 2 13:40:16 EDT 2012


Hi,
I am trying to work with HW peripherals on Raspberry Pi
To achieve this, it is necessary read/write some values from/to the
memory directly.
I am looking for some wise way how to organize the bit twiddling.
To set some specific bit, for example, it is necessary:
 - read 4 bytes string representation (I am using mmap)
 - transform it to the corresponding integer (I am using numpy)
 - do some bit masking over this integer
 - transport integer to the string representation (numpy again)
 - write it back to the memory
In other words I mean: is there wise way to create an instrument/
machinery to define Class and then simply define all necessary objects
and set the bit values over object attributes so the whole bit-
twiddling remains under the hood.
say:
LED01 = GPIO(4) # gpio PIN number 4 is assigned to the LED01 name
(attribute)
LED01.on()
LED01.off()
 or
gpio = GPIO()
LED01 = gpio.pin04
LED01 = 1 # led diode is shining (or gpio pin 4 is set)
LED01 = 0 # led diode is off
General suggestions, how to organise this work are more then welcome.
Petr Jakes


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /