Skip to content

Commit

Permalink
Merge pull request #12063 from maribu/i2c_release
Browse files Browse the repository at this point in the history
drivers/periph/i2c: Updated i2c_release() to return void
  • Loading branch information
gschorcht authored Oct 1, 2019
2 parents d7d7923 + 1a51b01 commit 02d81b7
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 45 deletions.
3 changes: 1 addition & 2 deletions cpu/atmega_common/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,11 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

mutex_unlock(&locks[dev]);
return 0;
}

static void i2c_poweron(i2c_t dev)
Expand Down
11 changes: 4 additions & 7 deletions cpu/cc2538/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void _i2c_master_slave_addr(uint16_t addr, bool receive)
{
DEBUG("%s (%" PRIx16 ", %d)\n", __FUNCTION__, addr, (int)receive);
assert(!(addr & 0x80));
I2CM_SA = (addr << 1) | receive;
I2CM_SA = (addr << 1) | (receive ? 0x1 : 0x0);
}

static void _i2c_master_data_put(uint8_t data)
Expand Down Expand Up @@ -241,14 +241,11 @@ int i2c_acquire(i2c_t dev)
return -1;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);
DEBUG("%s\n", __FUNCTION__);
if (dev < I2C_NUMOF) {
mutex_unlock(&lock);
return 0;
}
return -1;
mutex_unlock(&lock);
}

int i2c_read_bytes(i2c_t dev, uint16_t addr,
Expand Down
4 changes: 2 additions & 2 deletions cpu/cc26x0/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @}
*/

#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -133,11 +134,10 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);
mutex_unlock(&_lock);
return 0;
}

int i2c_read_bytes(i2c_t dev, uint16_t addr,
Expand Down
7 changes: 4 additions & 3 deletions cpu/efm32/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @}
*/

#include <assert.h>
#include <errno.h>

#include "cpu.h"
Expand Down Expand Up @@ -152,15 +153,15 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

/* disable peripheral */
CMU_ClockEnable(i2c_config[dev].cmu, false);

/* release lock */
mutex_unlock(&i2c_lock[dev]);

return 0;
}

int i2c_read_bytes(i2c_t dev, uint16_t address, void *data, size_t length, uint8_t flags)
Expand Down
6 changes: 3 additions & 3 deletions cpu/esp32/periph/i2c_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
Expand Down Expand Up @@ -277,15 +278,14 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
DEBUG ("%s\n", __func__);

CHECK_PARAM_RET (dev < I2C_NUMOF, -1)
assert(dev < I2C_NUMOF);

_i2c_reset_hw (dev);
mutex_unlock(&_i2c_bus[dev].lock);
return 0;
}

/*
Expand Down
6 changes: 3 additions & 3 deletions cpu/esp32/periph/i2c_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

#include <assert.h>
#include <errno.h>
#include <stdbool.h>

Expand Down Expand Up @@ -186,12 +187,11 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
CHECK_PARAM_RET (dev < I2C_NUMOF, -1)
assert(dev < I2C_NUMOF);

mutex_unlock(&_i2c_bus[dev].lock);
return 0;
}

int /* IRAM */ i2c_read_bytes(i2c_t dev, uint16_t addr, void *data, size_t len, uint8_t flags)
Expand Down
6 changes: 3 additions & 3 deletions cpu/esp8266/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

#include <assert.h>
#include <stdbool.h>
#include <errno.h>

Expand Down Expand Up @@ -201,12 +202,11 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
CHECK_PARAM_RET (dev < I2C_NUMOF, -1)
assert(dev < I2C_NUMOF);

mutex_unlock(&i2c_bus_lock[dev]);
return 0;
}

int /* IRAM */ i2c_read_bytes(i2c_t dev, uint16_t addr, void *data, size_t len, uint8_t flags)
Expand Down
5 changes: 3 additions & 2 deletions cpu/kinetis/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @}
*/

#include <assert.h>
#include <stdint.h>
#include <errno.h>

Expand Down Expand Up @@ -114,15 +115,15 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);
/* Check that the bus was properly stopped before releasing */
/* It is a programming error to release the bus after sending a start
* condition but before sending a stop condition */
assert(i2c_state[dev].active == 0);

mutex_unlock(&i2c_state[dev].mtx);
return 0;
}

static uint8_t i2c_find_divider(unsigned freq, unsigned speed)
Expand Down
4 changes: 2 additions & 2 deletions cpu/nrf51/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @}
*/
#include <assert.h>
#include <errno.h>
#include "cpu.h"
#include "mutex.h"
Expand Down Expand Up @@ -139,12 +140,11 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

mutex_unlock(&locks[dev]);
return 0;
}

int i2c_read_bytes(i2c_t dev, uint16_t address, void *data, size_t length,
Expand Down
4 changes: 2 additions & 2 deletions cpu/nrf52/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @}
*/

#include <assert.h>
#include <string.h>
#include <errno.h>

Expand Down Expand Up @@ -113,15 +114,14 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Disabled;
mutex_unlock(&locks[dev]);

DEBUG("[i2c] released dev %i\n", (int)dev);
return 0;
}

int i2c_write_regs(i2c_t dev, uint16_t addr, uint16_t reg,
Expand Down
4 changes: 2 additions & 2 deletions cpu/sam0_common/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @}
*/

#include <assert.h>
#include <stdint.h>
#include <errno.h>

Expand Down Expand Up @@ -164,11 +165,10 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);
mutex_unlock(&locks[dev]);
return 0;
}

int i2c_read_bytes(i2c_t dev, uint16_t addr,
Expand Down
4 changes: 2 additions & 2 deletions cpu/stm32_common/periph/i2c_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @}
*/

#include <assert.h>
#include <stdint.h>
#include <errno.h>

Expand Down Expand Up @@ -145,14 +146,13 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

periph_clk_dis(i2c_config[dev].bus, i2c_config[dev].rcc_mask);

mutex_unlock(&locks[dev]);
return 0;
}

int i2c_write_regs(i2c_t dev, uint16_t addr, uint16_t reg,
Expand Down
4 changes: 2 additions & 2 deletions cpu/stm32_common/periph/i2c_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @}
*/

#include <assert.h>
#include <stdint.h>
#include <errno.h>

Expand Down Expand Up @@ -195,7 +196,7 @@ int i2c_acquire(i2c_t dev)
return 0;
}

int i2c_release(i2c_t dev)
void i2c_release(i2c_t dev)
{
assert(dev < I2C_NUMOF);

Expand All @@ -207,7 +208,6 @@ int i2c_release(i2c_t dev)
#endif

mutex_unlock(&locks[dev]);
return 0;
}

int i2c_read_bytes(i2c_t dev, uint16_t address, void *data, size_t length,
Expand Down
4 changes: 1 addition & 3 deletions drivers/include/periph/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ int i2c_acquire(i2c_t dev);
* @brief Release the given I2C device to be used by others
*
* @param[in] dev I2C device to release
*
* @return 0 on success, -1 on error
*/
int i2c_release(i2c_t dev);
void i2c_release(i2c_t dev);

/**
* @brief Convenience function for reading one byte from a given register
Expand Down
10 changes: 3 additions & 7 deletions tests/periph_i2c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ int cmd_i2c_acquire(int argc, char **argv)

int cmd_i2c_release(int argc, char **argv)
{
int res;
int dev;

dev = _check_param(argc, argv, 1, 1, "DEV");
Expand All @@ -155,13 +154,10 @@ int cmd_i2c_release(int argc, char **argv)
}

printf("Command: i2c_release(%i)\n", dev);
res = i2c_release(dev);
i2c_release(dev);

if (res == I2C_ACK) {
printf("Success: i2c_%i released\n", dev);
return 0;
}
return _print_i2c_error(res);
printf("Success: i2c_%i released\n", dev);
return 0;
}

int cmd_i2c_read_reg(int argc, char **argv)
Expand Down

0 comments on commit 02d81b7

Please sign in to comment.