summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-01-30 12:33:19 +0800
committerGitHub <[email protected]>2021-01-30 12:33:19 +0800
commit97cc8a8f72838deb0273a3e60ae29319edd7e4f7 (patch)
tree240ca2dbffead9d828c59719b447844ab63c5e52 /components/drivers
parent7405618eafd9d0acd1d6da7ccd014700e9c17768 (diff)
parent45963a16b07857fadec81ff1d7cf6d16deeaddb5 (diff)
Merge pull request #14 from RT-Thread/master
pr
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/include/drivers/rt_drv_pwm.h8
-rw-r--r--components/drivers/misc/rt_drv_pwm.c74
-rw-r--r--components/drivers/sensors/sensor.c11
-rw-r--r--components/drivers/spi/spi_flash.h3
4 files changed, 84 insertions, 12 deletions
diff --git a/components/drivers/include/drivers/rt_drv_pwm.h b/components/drivers/include/drivers/rt_drv_pwm.h
index 16de4c6ab8..7a8e17b916 100644
--- a/components/drivers/include/drivers/rt_drv_pwm.h
+++ b/components/drivers/include/drivers/rt_drv_pwm.h
@@ -18,12 +18,20 @@
#define PWM_CMD_DISABLE (128 + 1)
#define PWM_CMD_SET (128 + 2)
#define PWM_CMD_GET (128 + 3)
+#define PWMN_CMD_ENABLE (128 + 4)
+#define PWMN_CMD_DISABLE (128 + 5)
struct rt_pwm_configuration
{
rt_uint32_t channel; /* 0-n */
rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */
rt_uint32_t pulse; /* unit:ns (pulse<=period) */
+
+ /*
+ * RT_TRUE : The channel of pwm is complememtary.
+ * RT_FALSE : The channel of pwm is nomal.
+ */
+ rt_bool_t complementary;
};
struct rt_device_pwm;
diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c
index 97d38d51b3..572580c45c 100644
--- a/components/drivers/misc/rt_drv_pwm.c
+++ b/components/drivers/misc/rt_drv_pwm.c
@@ -136,7 +136,8 @@ rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel)
return -RT_EIO;
}
- configuration.channel = channel;
+ configuration.channel = (channel > 0) ? (channel) : (-channel); /* Make it is positive num forever */
+ configuration.complementary = (channel > 0) ? (RT_FALSE) : (RT_TRUE); /* If nagetive, it's complementary */
result = rt_device_control(&device->parent, PWM_CMD_ENABLE, &configuration);
return result;
@@ -152,7 +153,8 @@ rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel)
return -RT_EIO;
}
- configuration.channel = channel;
+ configuration.channel = (channel > 0) ? (channel) : (-channel); /* Make it is positive num forever */
+ configuration.complementary = (channel > 0) ? (RT_FALSE) : (RT_TRUE); /* If nagetive, it's complementary */
result = rt_device_control(&device->parent, PWM_CMD_DISABLE, &configuration);
return result;
@@ -176,6 +178,20 @@ rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t perio
return result;
}
+rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg)
+{
+ rt_err_t result = RT_EOK;
+
+ if (!device)
+ {
+ return -RT_EIO;
+ }
+
+ result = rt_device_control(&device->parent, PWM_CMD_GET, cfg);
+
+ return result;
+}
+
#ifdef RT_USING_FINSH
#include <finsh.h>
@@ -191,6 +207,7 @@ static int pwm_enable(int argc, char **argv)
if (argc != 3)
{
rt_kprintf("Usage: pwm_enable pwm1 1\n");
+ rt_kprintf(" pwm_enable <pwm_dev> <channel/-channel>\n");
result = -RT_ERROR;
goto _exit;
}
@@ -202,12 +219,13 @@ static int pwm_enable(int argc, char **argv)
goto _exit;
}
+ /* If channel is complementary(1), make the channel number to nagetive */
result = rt_pwm_enable(device, atoi(argv[2]));
_exit:
return result;
}
-MSH_CMD_EXPORT(pwm_enable, pwm_enable pwm1 1);
+MSH_CMD_EXPORT(pwm_enable, pwm_enable <pwm_dev> <channel/-channel>);
static int pwm_disable(int argc, char **argv)
{
@@ -216,7 +234,8 @@ static int pwm_disable(int argc, char **argv)
if (argc != 3)
{
- rt_kprintf("Usage: pwm_enable pwm1 1\n");
+ rt_kprintf("Usage: pwm_disable pwm1 1\n");
+ rt_kprintf(" pwm_disable <pwm_dev> <channel/-channel> \n");
result = -RT_ERROR;
goto _exit;
}
@@ -228,12 +247,13 @@ static int pwm_disable(int argc, char **argv)
goto _exit;
}
+ /* If channel is complementary(1), make the channel number to nagetive */
result = rt_pwm_disable(device, atoi(argv[2]));
_exit:
return result;
}
-MSH_CMD_EXPORT(pwm_disable, pwm_disable pwm1 1);
+MSH_CMD_EXPORT(pwm_disable, pwm_disable <pwm_dev> <channel/-channel>);
static int pwm_set(int argc, char **argv)
{
@@ -243,6 +263,7 @@ static int pwm_set(int argc, char **argv)
if (argc != 5)
{
rt_kprintf("Usage: pwm_set pwm1 1 100 50\n");
+ rt_kprintf("Usage: pwm_set <pwm_dev> <channel> <period> <pulse>\n");
result = -RT_ERROR;
goto _exit;
}
@@ -259,7 +280,48 @@ static int pwm_set(int argc, char **argv)
_exit:
return result;
}
-MSH_CMD_EXPORT(pwm_set, pwm_set pwm1 1 100 50);
+MSH_CMD_EXPORT(pwm_set, pwm_set <pwm_dev> <channel> <period> <pulse>);
+
+
+static int pwm_get(int argc, char **argv)
+{
+ int result = 0;
+ struct rt_device_pwm *device = RT_NULL;
+ struct rt_pwm_configuration cfg = {0};
+
+ if (argc != 3)
+ {
+ rt_kprintf("Usage: pwm_get pwm1 1\n");
+ rt_kprintf(" pwm_get <pwm_dev> <channel>\n");
+ result = -RT_ERROR;
+ goto _exit;
+ }
+
+ device = (struct rt_device_pwm *)rt_device_find(argv[1]);
+ if (!device)
+ {
+ result = -RT_EIO;
+ goto _exit;
+ }
+
+ cfg.channel = atoi(argv[2]);
+ result = rt_pwm_get(device, &cfg);
+ if (result != RT_EOK)
+ {
+ rt_kprintf("Get info of device: [%s] error.\n", argv[1]);
+ }
+ else
+ {
+ rt_kprintf("Get info of device: [%s]:\n", argv[1]);
+ rt_kprintf("period : %d\n", cfg.period);
+ rt_kprintf("pulse : %d\n", cfg.pulse);
+ rt_kprintf("Duty cycle : %d%%\n", (int)(((double)(cfg.pulse)/(cfg.period)) * 100));
+ }
+
+_exit:
+ return result;
+}
+MSH_CMD_EXPORT(pwm_get, pwm_get <pwm_dev> <channel>);
#endif /* FINSH_USING_MSH */
#endif /* RT_USING_FINSH */
diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c
index bbfcea97be..660b86f85b 100644
--- a/components/drivers/sensors/sensor.c
+++ b/components/drivers/sensors/sensor.c
@@ -216,12 +216,6 @@ static rt_err_t rt_sensor_close(rt_device_t dev)
sensor->config.power = RT_SENSOR_POWER_DOWN;
}
- /* Sensor disable interrupt */
- if (sensor->config.irq_pin.pin != RT_PIN_NONE)
- {
- rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE);
- }
-
if (sensor->module != RT_NULL && sensor->info.fifo_max > 0 && sensor->data_buf != RT_NULL)
{
for (i = 0; i < sensor->module->sen_num; i ++)
@@ -240,6 +234,11 @@ static rt_err_t rt_sensor_close(rt_device_t dev)
}
}
}
+ /* Sensor disable interrupt */
+ if (sensor->config.irq_pin.pin != RT_PIN_NONE)
+ {
+ rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE);
+ }
__exit:
if (sensor->module)
diff --git a/components/drivers/spi/spi_flash.h b/components/drivers/spi/spi_flash.h
index 30db32474a..82b1ab2ecd 100644
--- a/components/drivers/spi/spi_flash.h
+++ b/components/drivers/spi/spi_flash.h
@@ -6,11 +6,14 @@
* Change Logs:
* Date Author Notes
* 2016/5/20 bernard the first version
+ * 2020/1/7 redoc add include
*/
#ifndef SPI_FLASH_H__
#define SPI_FLASH_H__
+#include <rtdevice.h>
+
struct spi_flash_device
{
struct rt_device flash_device;