summaryrefslogtreecommitdiff
path: root/components/drivers/include
diff options
context:
space:
mode:
authorHubretXie <[email protected]>2019-11-26 09:30:21 +0800
committerGitHub <[email protected]>2019-11-26 09:30:21 +0800
commit17f7f1c7ca2581b2e308888f8acb99ca8a541422 (patch)
tree5236e93ab1e4e24508d4ebf4540b6743dd7c9a41 /components/drivers/include
parent9662e18c3688681cd95ebd65242773dbe7c1366b (diff)
parente459084fe028c837762d40326a9be3dfdc179894 (diff)
Merge pull request #8 from RT-Thread/master
sync
Diffstat (limited to 'components/drivers/include')
-rw-r--r--components/drivers/include/drivers/can.h6
-rw-r--r--components/drivers/include/drivers/encoder.h58
-rw-r--r--components/drivers/include/drivers/i2c.h6
-rw-r--r--components/drivers/include/drivers/pm.h24
-rw-r--r--components/drivers/include/drivers/pulse_encoder.h58
-rw-r--r--components/drivers/include/drivers/rt_inputcapture.h60
-rw-r--r--components/drivers/include/rtdevice.h8
7 files changed, 139 insertions, 81 deletions
diff --git a/components/drivers/include/drivers/can.h b/components/drivers/include/drivers/can.h
index c61fb19eaa..d4fcc845b4 100644
--- a/components/drivers/include/drivers/can.h
+++ b/components/drivers/include/drivers/can.h
@@ -221,7 +221,7 @@ struct rt_can_msg
rt_uint32_t rsv : 1;
rt_uint32_t len : 8;
rt_uint32_t priv : 8;
- rt_uint32_t hdr : 8;
+ rt_int32_t hdr : 8;
rt_uint32_t reserved : 8;
rt_uint8_t data[8];
};
@@ -252,7 +252,7 @@ struct rt_can_rx_fifo
#define RT_CAN_EVENT_RX_IND 0x01 /* Rx indication */
#define RT_CAN_EVENT_TX_DONE 0x02 /* Tx complete */
-#define RT_CAN_EVENT_TX_FAIL 0x03 /* Tx complete */
+#define RT_CAN_EVENT_TX_FAIL 0x03 /* Tx fail */
#define RT_CAN_EVENT_RX_TIMEOUT 0x05 /* Rx timeout */
#define RT_CAN_EVENT_RXOF_IND 0x06 /* Rx overflow */
@@ -278,7 +278,7 @@ struct rt_can_ops
int (*recvmsg)(struct rt_can_device *can, void *buf, rt_uint32_t boxno);
};
-rt_err_t rt_hw_can_register(struct rt_can_device *can,
+rt_err_t rt_hw_can_register(struct rt_can_device *can,
const char *name,
const struct rt_can_ops *ops,
void *data);
diff --git a/components/drivers/include/drivers/encoder.h b/components/drivers/include/drivers/encoder.h
deleted file mode 100644
index f338f9e845..0000000000
--- a/components/drivers/include/drivers/encoder.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2019-08-08 balanceTWK the first version
- */
-
-#ifndef __ENCODER_H__
-#define __ENCODER_H__
-
-#include <rtthread.h>
-#include <rtdevice.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* encoder control command */
-#define ENCODER_CMD_GET_TYPE (128 + 0) /* get a encoder type information */
-#define ENCODER_CMD_ENABLE (128 + 1) /* enable encoder */
-#define ENCODER_CMD_DISABLE (128 + 2) /* disable encoder */
-#define ENCODER_CMD_CLEAR_COUNT (128 + 3) /* clear encoder count */
-
-/* encoder type */
-enum rt_encoder_type
-{
- UNKNOWN_ENCODER_TYPE = 0x00, /* Unknown encoder type */
- SINGLE_PHASE_ENCODER, /* single phase encoder */
- AB_PHASE_ENCODER /* two phase encoder */
-};
-
-struct rt_encoder_device;
-
-struct rt_encoder_ops
-{
- rt_err_t (*init)(struct rt_encoder_device *encoder);
- rt_int32_t (*get_count)(struct rt_encoder_device *encoder);
- rt_err_t (*clear_count)(struct rt_encoder_device *encoder);
- rt_err_t (*control)(struct rt_encoder_device *encoder, rt_uint32_t cmd, void *args);
-};
-
-struct rt_encoder_device
-{
- struct rt_device parent;
- const struct rt_encoder_ops *ops;
- enum rt_encoder_type type;
-};
-
-rt_err_t rt_device_encoder_register(struct rt_encoder_device *encoder, const char *name, void *user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __ENCODER_H__ */
diff --git a/components/drivers/include/drivers/i2c.h b/components/drivers/include/drivers/i2c.h
index c6376efa89..17d57288cd 100644
--- a/components/drivers/include/drivers/i2c.h
+++ b/components/drivers/include/drivers/i2c.h
@@ -67,12 +67,6 @@ struct rt_i2c_client
rt_uint16_t client_addr;
};
-#ifdef RT_I2C_DEBUG
-#define i2c_dbg(fmt, ...) rt_kprintf(fmt, ##__VA_ARGS__)
-#else
-#define i2c_dbg(fmt, ...)
-#endif
-
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
const char *bus_name);
struct rt_i2c_bus_device *rt_i2c_bus_device_find(const char *bus_name);
diff --git a/components/drivers/include/drivers/pm.h b/components/drivers/include/drivers/pm.h
index e35b21cd48..dd5875aa1d 100644
--- a/components/drivers/include/drivers/pm.h
+++ b/components/drivers/include/drivers/pm.h
@@ -86,8 +86,8 @@ struct rt_pm;
*/
struct rt_pm_ops
{
- void (*sleep)(struct rt_pm *pm, uint8_t mode);
- void (*run)(struct rt_pm *pm, uint8_t mode);
+ void (*sleep)(struct rt_pm *pm, rt_uint8_t mode);
+ void (*run)(struct rt_pm *pm, rt_uint8_t mode);
void (*timer_start)(struct rt_pm *pm, rt_uint32_t timeout);
void (*timer_stop)(struct rt_pm *pm);
rt_tick_t (*timer_get_tick)(struct rt_pm *pm);
@@ -95,9 +95,9 @@ struct rt_pm_ops
struct rt_device_pm_ops
{
- int (*suspend)(const struct rt_device *device, uint8_t mode);
- void (*resume)(const struct rt_device *device, uint8_t mode);
- int (*frequency_change)(const struct rt_device *device, uint8_t mode);
+ int (*suspend)(const struct rt_device *device, rt_uint8_t mode);
+ void (*resume)(const struct rt_device *device, rt_uint8_t mode);
+ int (*frequency_change)(const struct rt_device *device, rt_uint8_t mode);
};
struct rt_device_pm
@@ -137,22 +137,22 @@ enum
struct rt_pm_notify
{
- void (*notify)(uint8_t event, uint8_t mode, void *data);
+ void (*notify)(rt_uint8_t event, rt_uint8_t mode, void *data);
void *data;
};
-void rt_pm_request(uint8_t sleep_mode);
-void rt_pm_release(uint8_t sleep_mode);
-int rt_pm_run_enter(uint8_t run_mode);
+void rt_pm_request(rt_uint8_t sleep_mode);
+void rt_pm_release(rt_uint8_t sleep_mode);
+int rt_pm_run_enter(rt_uint8_t run_mode);
void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops);
void rt_pm_device_unregister(struct rt_device *device);
-void rt_pm_notify_set(void (*notify)(uint8_t event, uint8_t mode, void *data), void *data);
-void rt_pm_default_set(uint8_t sleep_mode);
+void rt_pm_notify_set(void (*notify)(rt_uint8_t event, rt_uint8_t mode, void *data), void *data);
+void rt_pm_default_set(rt_uint8_t sleep_mode);
void rt_system_pm_init(const struct rt_pm_ops *ops,
- uint8_t timer_mask,
+ rt_uint8_t timer_mask,
void *user_data);
#endif /* __PM_H__ */
diff --git a/components/drivers/include/drivers/pulse_encoder.h b/components/drivers/include/drivers/pulse_encoder.h
new file mode 100644
index 0000000000..0c7df04cd6
--- /dev/null
+++ b/components/drivers/include/drivers/pulse_encoder.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-08-08 balanceTWK the first version
+ */
+
+#ifndef __PULSE_ENCODER_H__
+#define __PULSE_ENCODER_H__
+
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* pulse_encoder control command */
+#define PULSE_ENCODER_CMD_GET_TYPE (128 + 0) /* get a pulse_encoder type information */
+#define PULSE_ENCODER_CMD_ENABLE (128 + 1) /* enable pulse_encoder */
+#define PULSE_ENCODER_CMD_DISABLE (128 + 2) /* disable pulse_encoder */
+#define PULSE_ENCODER_CMD_CLEAR_COUNT (128 + 3) /* clear pulse_encoder count */
+
+/* pulse_encoder type */
+enum rt_pulse_encoder_type
+{
+ UNKNOWN_PULSE_ENCODER_TYPE = 0x00, /* Unknown pulse_encoder type */
+ SINGLE_PHASE_PULSE_ENCODER, /* single phase pulse_encoder */
+ AB_PHASE_PULSE_ENCODER /* two phase pulse_encoder */
+};
+
+struct rt_pulse_encoder_device;
+
+struct rt_pulse_encoder_ops
+{
+ rt_err_t (*init)(struct rt_pulse_encoder_device *pulse_encoder);
+ rt_int32_t (*get_count)(struct rt_pulse_encoder_device *pulse_encoder);
+ rt_err_t (*clear_count)(struct rt_pulse_encoder_device *pulse_encoder);
+ rt_err_t (*control)(struct rt_pulse_encoder_device *pulse_encoder, rt_uint32_t cmd, void *args);
+};
+
+struct rt_pulse_encoder_device
+{
+ struct rt_device parent;
+ const struct rt_pulse_encoder_ops *ops;
+ enum rt_pulse_encoder_type type;
+};
+
+rt_err_t rt_device_pulse_encoder_register(struct rt_pulse_encoder_device *pulse_encoder, const char *name, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PULSE_ENCODER_H__ */
diff --git a/components/drivers/include/drivers/rt_inputcapture.h b/components/drivers/include/drivers/rt_inputcapture.h
new file mode 100644
index 0000000000..0cadf6444c
--- /dev/null
+++ b/components/drivers/include/drivers/rt_inputcapture.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-08-13 balanceTWK first version.
+ */
+
+#ifndef __RT_INPUT_CAPTURE_H__
+#define __RT_INPUT_CAPTURE_H__
+
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* capture control command */
+#define INPUTCAPTURE_CMD_CLEAR_BUF (128 + 0) /* clear capture buf */
+#define INPUTCAPTURE_CMD_SET_WATERMARK (128 + 1) /* Set the callback threshold */
+
+struct rt_inputcapture_data
+{
+ rt_uint32_t pulsewidth_us;
+ rt_bool_t is_high;
+};
+
+struct rt_inputcapture_device
+{
+ struct rt_device parent;
+
+ const struct rt_inputcapture_ops *ops;
+ struct rt_ringbuffer *ringbuff;
+ rt_size_t watermark;
+};
+
+/**
+ * capture operators
+ */
+struct rt_inputcapture_ops
+{
+ rt_err_t (*init)(struct rt_inputcapture_device *inputcapture);
+ rt_err_t (*open)(struct rt_inputcapture_device *inputcapture);
+ rt_err_t (*close)(struct rt_inputcapture_device *inputcapture);
+ rt_err_t (*get_pulsewidth)(struct rt_inputcapture_device *inputcapture, rt_uint32_t *pulsewidth_us);
+};
+
+void rt_hw_capture_isr(struct rt_inputcapture_device *inputcapture, rt_bool_t level);
+
+rt_err_t rt_device_inputcapture_register(struct rt_inputcapture_device *inputcapture,
+ const char *name,
+ void *data);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __RT_INPUT_CAPTURE_H__ */
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h
index 0c009e9580..623c085430 100644
--- a/components/drivers/include/rtdevice.h
+++ b/components/drivers/include/rtdevice.h
@@ -126,8 +126,12 @@ extern "C" {
#include "drivers/crypto.h"
#endif
-#ifdef RT_USING_ENCODER
-#include "drivers/encoder.h"
+#ifdef RT_USING_PULSE_ENCODER
+#include "drivers/pulse_encoder.h"
+#endif
+
+#ifdef RT_USING_INPUT_CAPTURE
+#include "drivers/rt_inputcapture.h"
#endif
#ifdef __cplusplus