Skip to content

Commit 78f6426

Browse files
Driver i2c: improve frequency setting function
1 parent 3618415 commit 78f6426

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

drivers/I2C.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "drivers/I2C.h"
1919
#include "drivers/DigitalInOut.h"
2020
#include "platform/mbed_wait_api.h"
21+
#include "platform/mbed_assert.h"
2122

2223
#if DEVICE_I2C
2324

@@ -58,6 +59,7 @@ I2C::~I2C()
5859
void I2C::frequency(int hz)
5960
{
6061
lock();
62+
MBED_ASSERT(_hz > 0);
6163
_hz = (uint32_t)hz;
6264

6365
// We want to update the frequency even if we are already the bus owners

drivers/I2CSlave.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include "platform/mbed_assert.h"
1718
#include "drivers/I2CSlave.h"
1819

1920
#if DEVICE_I2CSLAVE
@@ -33,7 +34,8 @@ I2CSlave::~I2CSlave()
3334

3435
void I2CSlave::frequency(int hz)
3536
{
36-
i2c_frequency(&_i2c, hz);
37+
MBED_ASSERT(hz > 0);
38+
i2c_frequency(&_i2c, (uint32_t)hz);
3739
}
3840

3941
void I2CSlave::timeout(uint32_t timeout)

0 commit comments

Comments
 (0)