Skip to content

Commit 9b4e9fd

Browse files
committed
Moved pullups enable from twi.c to Wire.cpp
Now utility/twi.* is a pure AVR libc library, that can be used without Arduino
1 parent bedc550 commit 9b4e9fd

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

hardware/arduino/avr/libraries/Wire/Wire.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20+
Modified 2014 by Nicola Corna (nicola@corna.info)
21+
Moved pullups enable from twi.c to Wire.cpp
2022
*/
2123

2224
extern "C" {
@@ -27,6 +29,8 @@ extern "C" {
2729
}
2830

2931
#include "Wire.h"
32+
#include "Arduino.h" // for digitalWrite
33+
#include "pins_arduino.h"
3034

3135
// Initialize Class Variables //////////////////////////////////////////////////
3236

@@ -59,6 +63,10 @@ void TwoWire::begin(void)
5963
txBufferIndex = 0;
6064
txBufferLength = 0;
6165

66+
// activate internal pullups for twi.
67+
digitalWrite(SDA, 1);
68+
digitalWrite(SCL, 1);
69+
6270
twi_init();
6371
}
6472

hardware/arduino/avr/libraries/Wire/utility/twi.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
20+
Modified 2014 by Nicola Corna (nicola@corna.info)
21+
Moved pullups enable from twi.c to Wire.cpp
2022
*/
2123

2224
#include <math.h>
2325
#include <stdlib.h>
26+
#include <stdbool.h>
2427
#include <inttypes.h>
2528
#include <avr/io.h>
2629
#include <avr/interrupt.h>
2730
#include <compat/twi.h>
28-
#include "Arduino.h" // for digitalWrite
2931

3032
#ifndef cbi
3133
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
@@ -35,7 +37,6 @@
3537
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
3638
#endif
3739

38-
#include "pins_arduino.h"
3940
#include "twi.h"
4041

4142
static volatile uint8_t twi_state;
@@ -71,10 +72,6 @@ void twi_init(void)
7172
twi_state = TWI_READY;
7273
twi_sendStop = true; // default value
7374
twi_inRepStart = false;
74-
75-
// activate internal pullups for twi.
76-
digitalWrite(SDA, 1);
77-
digitalWrite(SCL, 1);
7875

7976
// initialize twi prescaler and bit rate
8077
cbi(TWSR, TWPS0);

0 commit comments

Comments
 (0)