mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
402:09075a3b15e3
Parent:
305:1f0269907d8b
Child:
404:cbc7dfcb0ce9
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c	Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c	Fri Nov 14 09:00:07 2014 +0000
@@ -62,7 +62,8 @@
 int i2c1_inited = 0;
 int i2c2_inited = 0;
 
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
     // Determine the I2C to use
     I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
     I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -71,7 +72,7 @@
     MBED_ASSERT(obj->i2c != (I2CName)NC);
 
     // Enable I2C1 clock and pinout if not done
-    if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+    if ((obj->i2c == I2C_1) && !i2c1_inited) {
         i2c1_inited = 1;
         __HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
         __I2C1_CLK_ENABLE();
@@ -82,14 +83,14 @@
         pin_mode(scl, OpenDrain);
     }
     // Enable I2C2 clock and pinout if not done
-    if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+    if ((obj->i2c == I2C_2) && !i2c2_inited) {
         i2c2_inited = 1;
         __I2C2_CLK_ENABLE();
-    // Configure I2C pins
-    pinmap_pinout(sda, PinMap_I2C_SDA);
-    pinmap_pinout(scl, PinMap_I2C_SCL);
-    pin_mode(sda, OpenDrain);
-    pin_mode(scl, OpenDrain);
+        // Configure I2C pins
+        pinmap_pinout(sda, PinMap_I2C_SDA);
+        pinmap_pinout(scl, PinMap_I2C_SCL);
+        pin_mode(sda, OpenDrain);
+        pin_mode(scl, OpenDrain);
     }
 
     // Reset to clear pending flags if any
@@ -99,14 +100,15 @@
     i2c_frequency(obj, 100000); // 100 kHz per default
 }
 
-void i2c_frequency(i2c_t *obj, int hz) {
+void i2c_frequency(i2c_t *obj, int hz)
+{
     MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
     I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
     int timeout;
 
     // wait before init
     timeout = LONG_TIMEOUT;
-    while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+    while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
 
     // Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0
     switch (hz) {
@@ -134,7 +136,8 @@
     HAL_I2C_Init(&I2cHandle);
 }
 
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     int timeout;
 
@@ -157,7 +160,8 @@
     return 0;
 }
 
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
 
     // Generate the STOP condition
@@ -166,7 +170,8 @@
     return 0;
 }
 
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
     int timeout;
@@ -211,7 +216,8 @@
     return length;
 }
 
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
     int timeout;
@@ -255,7 +261,8 @@
     return count;
 }
 
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     int timeout;
 
@@ -270,7 +277,8 @@
     return (int)i2c->RXDR;
 }
 
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     int timeout;
 
@@ -287,12 +295,13 @@
     return 1;
 }
 
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
     int timeout;
-	
+
     // wait before reset
     timeout = LONG_TIMEOUT;
-    while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+    while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
 
     if (obj->i2c == I2C_1) {
         __I2C1_FORCE_RESET();
@@ -306,7 +315,8 @@
 
 #if DEVICE_I2CSLAVE
 
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     uint16_t tmpreg = 0;
 
@@ -324,7 +334,8 @@
     i2c->OAR1 |= I2C_OAR1_OA1EN;
 }
 
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
 
     I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
     uint16_t tmpreg;
@@ -350,7 +361,8 @@
 #define WriteGeneral   2 // the master is writing to all slave
 #define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
 
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
     I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
     int retValue = NoData;
 
@@ -368,7 +380,8 @@
     return (retValue);
 }
 
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
     char size = 0;
 
     while (size < length) data[size++] = (char)i2c_byte_read(obj, 0);
@@ -376,7 +389,8 @@
     return size;
 }
 
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
     char size = 0;
     I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);