pieter-jan / pj_rpi Goto Github PK
View Code? Open in Web Editor NEWRaspberry Pi C Library
Raspberry Pi C Library
Hello.
I tried to use GPIO28 and GPIO29 as I2C.
So, I used SET_GPIO_ALT(28, 0) and SET_GPIO_ALT(29, 0) after INP_GPIO(28) and INP_GPIO(29), respectively.
But, my code, which worked fine with I2C-1, doesn't work with that command.
GPIO28, GPIO29 pins are not woking in I2C mode.
I looked through the bcm2385 library and it looks all the parts related to GPIO setting is the same.
Any idea?
define them like this and we will not forget to call INP_GPIO:
Hi there!
I tend to forget things... so why not wrap the INP_GPIO macro inside the OUT_GPIO and SET_GPIO_ALT ones? Like so:
#define OUT_GPIO(g) do { \
INP_GPIO(g); \
*(gpio.addr + ((g)/10)) |= (1<<(((g)%10)*3)); \
} while(0)
#define SET_GPIO_ALT(g,a) do { \
INP_GPIO(g); \
*(gpio.addr + (((g)/10))) |= (((a)<=3?(a) + 4:(a)==4?3:2)<<(((g)%10)*3)); \
} while(0)
Also helps to get cleaner code. Tested on my rpi and works great ;)
should be
otherwise, consider the following code:
if (GPIO_READ(echo) != 0) {
}
the operator "&=" has very low prority, even lower than "!=".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.