@@ -41,6 +41,8 @@ typedef enum
4141TwoWire::TwoWire (uint8_t iom_instance) : IOMaster(iom_instance)
4242{
4343 _transmissionBegun = false ;
44+ _pullups = AM_HAL_GPIO_PIN_PULLUP_1_5K; // Default
45+ _clockSpeed = AM_HAL_IOM_100KHZ;
4446}
4547
4648void TwoWire::begin (void )
@@ -58,7 +60,7 @@ void TwoWire::begin(void)
5860 return /* retval*/ ;
5961 }
6062 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 ;
6264 pincfg.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA;
6365 pincfg.eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN;
6466 pincfg.uIOMnum = _instance;
@@ -75,7 +77,7 @@ void TwoWire::begin(void)
7577 return /* retval*/ ;
7678 }
7779 pincfg.uFuncSel = funcsel;
78- pincfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K ;
80+ pincfg.ePullup = _pullups ;
7981 pincfg.eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_12MA;
8082 pincfg.eGPOutcfg = AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN;
8183 pincfg.uIOMnum = _instance;
@@ -88,7 +90,7 @@ void TwoWire::begin(void)
8890
8991 memset ((void *)&_config, 0x00 , sizeof (am_hal_iom_config_t )); // Set the IOM configuration
9092 _config.eInterfaceMode = AM_HAL_IOM_I2C_MODE;
91- _config.ui32ClockFreq = AM_HAL_IOM_100KHZ ;
93+ _config.ui32ClockFreq = _clockSpeed ;
9294
9395 initialize (); // Initialize the IOM
9496}
@@ -103,11 +105,28 @@ void TwoWire::begin(uint8_t address, bool enableGeneralCall)
103105void TwoWire::setClock (uint32_t baudrate)
104106{
105107 // ToDo: disable I2C while switching, if necessary
106-
107- _config.ui32ClockFreq = baudrate ;
108+ _clockSpeed = baudrate;
109+ _config.ui32ClockFreq = _clockSpeed ;
108110 initialize (); // Initialize the IOM
109111}
110112
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+
111130void TwoWire::end ()
112131{
113132 // sercom->disableWIRE();
0 commit comments