mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/periph_i2c: add tests for periph_i2c_reconfigure features
Add a test to re-configure the I2C pins to GPIO functionality and use them as output. A small delay is added to allow for observing the change in power draw.
This commit is contained in:
parent
8c502322f4
commit
896f9db71f
@ -2,7 +2,9 @@ BOARD ?= samr21-xpro
|
||||
include ../Makefile.tests_common
|
||||
|
||||
FEATURES_REQUIRED = periph_i2c
|
||||
FEATURES_OPTIONAL = periph_i2c_reconfigure
|
||||
|
||||
USEMODULE += shell
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -24,9 +24,12 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "periph_conf.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "periph/i2c.h"
|
||||
#include "shell.h"
|
||||
|
||||
#include <xtimer.h>
|
||||
|
||||
#ifndef I2C_ACK
|
||||
#define I2C_ACK (0)
|
||||
#endif
|
||||
@ -160,6 +163,47 @@ int cmd_i2c_release(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MODULE_PERIPH_I2C_RECONFIGURE
|
||||
int cmd_i2c_gpio(int argc, char **argv)
|
||||
{
|
||||
int dev;
|
||||
|
||||
dev = _check_param(argc, argv, 1, 1, "DEV");
|
||||
if (dev == ARG_ERROR) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpio_t sda_pin = i2c_pin_sda(dev);
|
||||
gpio_t scl_pin = i2c_pin_scl(dev);
|
||||
|
||||
printf("Command: i2c_deinit_pins(%i)\n", dev);
|
||||
i2c_deinit_pins(dev);
|
||||
|
||||
gpio_init(sda_pin, GPIO_OUT);
|
||||
gpio_init(scl_pin, GPIO_OUT);
|
||||
|
||||
xtimer_sleep(1);
|
||||
|
||||
printf("Command: gpio_set()\n");
|
||||
gpio_set(sda_pin);
|
||||
gpio_set(scl_pin);
|
||||
|
||||
xtimer_sleep(1);
|
||||
|
||||
printf("Command: gpio_clear()\n");
|
||||
gpio_clear(sda_pin);
|
||||
gpio_clear(scl_pin);
|
||||
|
||||
xtimer_sleep(1);
|
||||
|
||||
printf("Command: i2c_init_pins(%i)\n", dev);
|
||||
i2c_init_pins(dev);
|
||||
|
||||
printf("Success: i2c_%i re-init\n", dev);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int cmd_i2c_read_reg(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
@ -444,6 +488,9 @@ int cmd_i2c_get_id(int argc, char **argv)
|
||||
static const shell_command_t shell_commands[] = {
|
||||
{ "i2c_acquire", "Get access to the I2C bus", cmd_i2c_acquire },
|
||||
{ "i2c_release", "Release to the I2C bus", cmd_i2c_release },
|
||||
#ifdef MODULE_PERIPH_I2C_RECONFIGURE
|
||||
{ "i2c_gpio", "Re-configures I2C pins to GPIO mode and back.", cmd_i2c_gpio },
|
||||
#endif
|
||||
{ "i2c_read_reg", "Read byte from register", cmd_i2c_read_reg },
|
||||
{ "i2c_read_regs", "Read bytes from registers", cmd_i2c_read_regs },
|
||||
{ "i2c_read_byte", "Read byte from the I2C device", cmd_i2c_read_byte },
|
||||
|
Loading…
Reference in New Issue
Block a user