leo25 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Use SDA and SCL pin abstractions in Wire library #601

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

In twi.c of the Wire library, the following lines should be replaced to take 
advantage of the pin abstractions in pins_arduino.h.

twi.c lines 67-77:

  #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
    // activate internal pull-ups for twi
    // as per note from atmega8 manual pg167
    sbi(PORTC, 4);
    sbi(PORTC, 5);
  #else
    // activate internal pull-ups for twi
    // as per note from atmega128 manual pg204
    sbi(PORTD, 0);
    sbi(PORTD, 1);
  #endif

Wiring uses the following in place of the code above:
  // TODO let's consider not activate internal pullups for Wire
  pinMode(SDA, INPUT);
  pullup(SDA);
  pinMode(SCL, INPUT);
  pullup(SCL);

This would require importing Arduino.h in twi.c (which I could see potential 
arguments against... but perhaps there is another way to accomplish what I'm 
getting at) and setting the pullup using the Arduino method (since pullup() 
doesn't exist in Arduino as far as I know). Also it may be useful to set the 
pullups as suggested in issue 506, but making sure the pins are abstracted.

Why?

This will ensure that the Wire library can work with an board describe in the 
variants directory of Arduino 1.0 and higher.

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

None that I can think of (aside from any potential issues introduced by 
addressing Issue 506).

Original issue reported on code.google.com by jeff.ho...@gmail.com on 27 Aug 2011 at 5:33

GoogleCodeExporter commented 9 years ago
Sounds good.  We can probably include pins_arduino.h instead of Arduino.h to 
help limit what we bring in.

Original comment by dmel...@gmail.com on 28 Aug 2011 at 6:09

GoogleCodeExporter commented 9 years ago
https://github.com/arduino/Arduino/commit/71289521bfb88d61693d4349c51b9e123d5bc4
2c

Original comment by dmel...@gmail.com on 8 Sep 2011 at 8:51