From fc5d37d391b39e720e42f93ad219f07948ba76db Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Wed, 10 Dec 2014 00:32:17 +0000 Subject: [PATCH] i2c: set_frequency now takes a mraa_i2c_mode_t Signed-off-by: Brendan Le Foll --- api/mraa/i2c.h | 4 ++-- api/mraa/i2c.hpp | 6 +++--- api/mraa/types.h | 9 +++++++++ src/i2c/i2c.c | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/api/mraa/i2c.h b/api/mraa/i2c.h index b2e57d7..9ba9779 100644 --- a/api/mraa/i2c.h +++ b/api/mraa/i2c.h @@ -72,10 +72,10 @@ mraa_i2c_context mraa_i2c_init_raw(unsigned int bus); * Sets the frequency of the i2c context. Most platforms do not support this. * * @param dev The i2c context - * @param hz The bus frequency in hertz + * @param mode The bus mode * @return Result of operation */ -mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, int hz); +mraa_result_t mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode); /** * Simple bulk read from an i2c context, this will always begin with the i2c diff --git a/api/mraa/i2c.hpp b/api/mraa/i2c.hpp index 63106f5..7f3b99a 100644 --- a/api/mraa/i2c.hpp +++ b/api/mraa/i2c.hpp @@ -74,11 +74,11 @@ class I2c { * the set frequency. Anyone can change this at any time and this will * affect every slave on the bus * - * @param hz Frequency to set the bus to in hz + * @param mode Frequency to set the bus to * @return Result of operation */ - mraa_result_t frequency(int hz) { - return mraa_i2c_frequency(m_i2c, hz); + mraa_result_t frequency(mraa_i2c_mode_t mode) { + return mraa_i2c_frequency(m_i2c, mode); } /** diff --git a/api/mraa/types.h b/api/mraa/types.h index 90cb4f4..93d4968 100644 --- a/api/mraa/types.h +++ b/api/mraa/types.h @@ -174,6 +174,15 @@ typedef enum { MRAA_PIN_UART = 7 /**< UART */ } mraa_pinmodes_t; +/** + * Enum reprensenting different i2c speeds/modes + */ +typedef enum { + MRAA_I2C_STD = 0, /**< up to 100Khz */ + MRAA_I2C_FAST = 1, /**< up to 400Khz */ + MRAA_I2C_HIGH = 2 /**< up to 3.4Mhz */ +} mraa_i2c_mode_t; + #ifdef __cplusplus } #endif diff --git a/src/i2c/i2c.c b/src/i2c/i2c.c index caa8130..3207db2 100644 --- a/src/i2c/i2c.c +++ b/src/i2c/i2c.c @@ -135,7 +135,7 @@ mraa_i2c_init_raw(unsigned int bus) } mraa_result_t -mraa_i2c_frequency(mraa_i2c_context dev, int hz) +mraa_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode) { dev->hz = hz;