Comments (7)
Just to do something, I started to make a small library that melts your brzo library and the old Wire together. It creates a new class called Wire2 (because it cannot be named Wire). So in an Arduino code, you need to include this translating library and rename any Wire to Wire2.
I will call this library Wire2brzo. So instead of #include <Wire.h>
it's going to be #include <Wire2brzo.h>
. Then everything works with the object Wire2
and functions like Wire2.begin()
.
That was the easy (but not for me) step.
Next, more difficult, step is to let my library do the same as the original Wire library by using your code.
I'll start my attempt with the base functions like begin
, write
, read
, beginTransmission
, endTransmission
. Next must be requestFrom
. If I manage to get those working, all is enough as a replacement to test it with my problematic PN532...
(Fingers crossed, I am not a programmer)
from brzo_i2c.
I think(...) that it's not very hard to replace these 'Wire' like functions:
begin
beginTransmission
endTransmission
write / send
read / receive
With those respectively:
brzo_i2c_setup
brzo_i2c_start_transaction
brzo_i2c_end_transaction
brzo_i2c_write
brzo_i2c_read
More a problem will be Wire like functions as:
requestFrom
And I think these Wire functions will need a lot of extra coding:
available
onReceive
onRequest
I would personally be happy if the first part and a requestFrom
equivalent can be added somehow.
from brzo_i2c.
Yes, it's true, it would be nice to have a wrapper for a drop in replacement of the wire library and its methods.
When I started to develop brzo i2c
I had this case in mind, of course. However on the other hand, there are some "concepts" in the wire library which I don't like (or either never fully understood). For instance, this asymmetry between sending and receiving bytes, i.e. .beginTransmission
, and then only .write
commands, no reads, and finally end this transmission with .endTransmission
, where all the date is trasmitted over the i2c bus. Versus .requestFrom
and then the read
commands, where the bytes are read from the i2c slave; and no bracket for beginning and ending a transmission. Or, how errors are treated and reported back to the caller...
But, jumping over this "I don't like" stuff and thinking on ;-)
There are many overloads of the methods in the wire library. So, I think I/we would have to find a compromise which one should be made ported. For instance, you can write a single byte or as I did in brzo i2c
, write from a buffer.
Then, overall, I need to think a bit more on how these two concepts could be married :-) But nothing is impossible!
from brzo_i2c.
@supersjimmie Thanks for your effort. That sound really great.
@pasko-zh
Just a usage question. I could not get it to work. I want to send some data from an existing uint8_t array like this:
[... setup and begin ...]
uint8_t buffer[10] = [0,0,1,1,1,2,3,3,4,5];
brzo_i2c_write(&buffer[4], 5, true);
[... end ...]
That should send 1,2,3,3,4
right?
from brzo_i2c.
Not quite :-) In brzo_i2c_write
it expects a pointer to a buffer, it then sends the n elements starting from the beginning of the buffer. (Inside the function I pass the pointer to the first element to the inline assembly, [r_adr_array_element] "+r" (&data[0]) ...
Maybe my use cases were a bit too narrow, but I thought one would always send n bytes from the beginning of the buffer. But I could change that...
EDIT: I will change this in the next version. Since I don't have a compiler/esp in front of me for the
next days it will take ~ 1 week.
EDIT 2: I have moved this to a new issue, #2 .
from brzo_i2c.
I would really like that. Maybe just expect a raw pointer (like memcpy) and dont do the (&data[0]) query in this library. Than one could just pass in a pointer that points to the start of the array you would like.
from brzo_i2c.
I have included a section in the wiki on "How to migrate from Wire Library", see here
from brzo_i2c.
Related Issues (20)
- I2C stucks after clock stretching time exceeds HOT 25
- Question: Logic Levels and ... HOT 2
- Cannot compile for Heltec Wifi Kit 32 HOT 3
- INA219 HOT 8
- Multiple I2C HOT 2
- gpio_init() will cause I2C bus busy (code: 1) HOT 5
- Migrating ADS1015 from Wire HOT 5
- AM2320 sensor not found HOT 11
- I2C bus handle for multiple instances posibility HOT 1
- Support speeds < 100KHz HOT 2
- after 1 slave fails others stop working HOT 4
- Have you thought about a i2c slave implementation. HOT 2
- Novice obsession HOT 2
- GCC 10 compilation issue with Arduino HOT 5
- SDA set before SCL while preparing STOP in brzo_i2c_read() HOT 7
- MEMW not always present
- Clock stretch logic
- Arduino IDE compile error with new ESP8266 core 3.0.0 HOT 30
- SCL cock stretching HOT 3
- Platformio installation instructions confusing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brzo_i2c.