@@ -41,6 +41,8 @@ typedef enum
41
41
TwoWire::TwoWire (uint8_t iom_instance) : IOMaster(iom_instance)
42
42
{
43
43
_transmissionBegun = false ;
44
+ _pullups = AM_HAL_GPIO_PIN_PULLUP_1_5K; // Default
45
+ _clockSpeed = AM_HAL_IOM_100KHZ;
44
46
}
45
47
46
48
void TwoWire::begin (void )
@@ -58,7 +60,7 @@ void TwoWire::begin(void)
58
60
return /* retval*/ ;
59
61
}
60
62
pincfg.uFuncSel = funcsel; // set the proper function select option for this instance/pin/type combination
61
- pincfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K ;
63
+ pincfg.ePullup = _pullups ;
62
64
pincfg.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA;
63
65
pincfg.eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN;
64
66
pincfg.uIOMnum = _instance;
@@ -75,7 +77,7 @@ void TwoWire::begin(void)
75
77
return /* retval*/ ;
76
78
}
77
79
pincfg.uFuncSel = funcsel;
78
- pincfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K ;
80
+ pincfg.ePullup = _pullups ;
79
81
pincfg.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA;
80
82
pincfg.eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN;
81
83
pincfg.uIOMnum = _instance;
@@ -88,7 +90,7 @@ void TwoWire::begin(void)
88
90
89
91
memset ((void *)&_config, 0x00 , sizeof (am_hal_iom_config_t )); // Set the IOM configuration
90
92
_config.eInterfaceMode = AM_HAL_IOM_I2C_MODE;
91
- _config.ui32ClockFreq = AM_HAL_IOM_100KHZ ;
93
+ _config.ui32ClockFreq = _clockSpeed ;
92
94
93
95
initialize (); // Initialize the IOM
94
96
}
@@ -103,11 +105,28 @@ void TwoWire::begin(uint8_t address, bool enableGeneralCall)
103
105
void TwoWire::setClock (uint32_t baudrate)
104
106
{
105
107
// ToDo: disable I2C while switching, if necessary
106
-
107
- _config.ui32ClockFreq = baudrate ;
108
+ _clockSpeed = baudrate;
109
+ _config.ui32ClockFreq = _clockSpeed ;
108
110
initialize (); // Initialize the IOM
109
111
}
110
112
113
+ void TwoWire::setPullups (uint32_t pullupAmount)
114
+ {
115
+ if (pullupAmount == 0 )
116
+ _pullups = AM_HAL_GPIO_PIN_PULLUP_NONE;
117
+ if (pullupAmount > 0 || pullupAmount < 6 )
118
+ _pullups = AM_HAL_GPIO_PIN_PULLUP_1_5K;
119
+ else if (pullupAmount >= 6 || pullupAmount < 12 )
120
+ _pullups = AM_HAL_GPIO_PIN_PULLUP_6K;
121
+ else if (pullupAmount >= 12 || pullupAmount < 24 )
122
+ _pullups = AM_HAL_GPIO_PIN_PULLUP_12K;
123
+ else if (pullupAmount >= 24 )
124
+ _pullups = AM_HAL_GPIO_PIN_PULLUP_24K;
125
+
126
+ // Reinit I2C pins with this new pullup value
127
+ begin ();
128
+ }
129
+
111
130
void TwoWire::end ()
112
131
{
113
132
// sercom->disableWIRE();
0 commit comments