From b1b1fb3602100d732bdbd9d3b95adc5eb4d2fa14 Mon Sep 17 00:00:00 2001 From: MacRsh Date: Wed, 20 Dec 2023 16:04:33 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device/adc.c | 30 ++---------------------------- device/dac.c | 28 +--------------------------- device/pin.c | 12 +----------- device/serial.c | 4 ++-- device/timer.c | 4 ++-- document/device/timer.md | 18 ++++++++++-------- include/device/adc.h | 6 ++---- include/device/dac.h | 6 ++---- include/device/pin.h | 7 +++---- include/device/timer.h | 6 +++--- 10 files changed, 28 insertions(+), 93 deletions(-) diff --git a/device/adc.c b/device/adc.c index 5cd4562..f443e9f 100644 --- a/device/adc.c +++ b/device/adc.c @@ -104,7 +104,7 @@ static int mr_adc_ioctl(struct mr_dev *dev, int off, int cmd, void *args) switch (cmd) { - case MR_CTL_ADC_SET_CONFIG: + case MR_CTL_ADC_SET_CHANNEL_STATE: { if (args != MR_NULL) { @@ -114,18 +114,8 @@ static int mr_adc_ioctl(struct mr_dev *dev, int off, int cmd, void *args) } return MR_EINVAL; } - case MR_CTL_ADC_SET_CHANNEL_STATE: - { - if (args != MR_NULL) - { - int state = *((int *)args); - return adc_channel_set_state(adc, off, state); - } - return MR_EINVAL; - } - - case MR_CTL_ADC_GET_CONFIG: + case MR_CTL_ADC_GET_CHANNEL_STATE: { if (args != MR_NULL) { @@ -140,22 +130,6 @@ static int mr_adc_ioctl(struct mr_dev *dev, int off, int cmd, void *args) return MR_EOK; } } - case MR_CTL_ADC_GET_CHANNEL_STATE: - { - if (args != MR_NULL) - { - int *state = (int *)args; - - int ret = adc_channel_get_state(adc, off); - if (ret < 0) - { - return ret; - } - *state = ret; - return MR_EOK; - } - return MR_EINVAL; - } default: { diff --git a/device/dac.c b/device/dac.c index 54c6bb8..1aee89b 100644 --- a/device/dac.c +++ b/device/dac.c @@ -104,7 +104,7 @@ static int mr_dac_ioctl(struct mr_dev *dev, int off, int cmd, void *args) switch (cmd) { - case MR_CTL_DAC_SET_CONFIG: + case MR_CTL_DAC_SET_CHANNEL_STATE: { if (args != MR_NULL) { @@ -114,32 +114,6 @@ static int mr_dac_ioctl(struct mr_dev *dev, int off, int cmd, void *args) } return MR_EINVAL; } - case MR_CTL_DAC_SET_CHANNEL_STATE: - { - if (args != MR_NULL) - { - int state = *((int *)args); - - return dac_channel_set_state(dac, off, state); - } - return MR_EINVAL; - } - - case MR_CTL_DAC_GET_CONFIG: - { - if (args != MR_NULL) - { - struct mr_dac_config *config = (struct mr_dac_config *)args; - - int ret = dac_channel_get_state(dac, off); - if (ret < 0) - { - return ret; - } - config->channel_state = ret; - return MR_EOK; - } - } case MR_CTL_DAC_GET_CHANNEL_STATE: { if (args != MR_NULL) diff --git a/device/pin.c b/device/pin.c index a0af438..d37054a 100644 --- a/device/pin.c +++ b/device/pin.c @@ -121,7 +121,7 @@ static int mr_pin_ioctl(struct mr_dev *dev, int off, int cmd, void *args) switch (cmd) { - case MR_CTL_PIN_SET_CONFIG: + case MR_CTL_PIN_SET_MODE: { if (args != MR_NULL) { @@ -131,16 +131,6 @@ static int mr_pin_ioctl(struct mr_dev *dev, int off, int cmd, void *args) } return MR_EINVAL; } - case MR_CTL_PIN_SET_MODE: - { - if (args != MR_NULL) - { - int mode = *((int *)args); - - return pin_set_mode(pin, off, mode); - } - return MR_EINVAL; - } default: { diff --git a/device/serial.c b/device/serial.c index 61493f6..eca5109 100644 --- a/device/serial.c +++ b/device/serial.c @@ -186,7 +186,7 @@ static int mr_serial_ioctl(struct mr_dev *dev, int off, int cmd, void *args) } case MR_CTL_SERIAL_GET_RD_DATASZ: { - if (args!= MR_NULL) + if (args != MR_NULL) { size_t *datasz = (size_t *)args; @@ -197,7 +197,7 @@ static int mr_serial_ioctl(struct mr_dev *dev, int off, int cmd, void *args) } case MR_CTL_SERIAL_GET_WR_DATASZ: { - if (args!= MR_NULL) + if (args != MR_NULL) { size_t *datasz = (size_t *)args; diff --git a/device/timer.c b/device/timer.c index a2b2e62..915f496 100644 --- a/device/timer.c +++ b/device/timer.c @@ -183,7 +183,7 @@ static int mr_timer_ioctl(struct mr_dev *dev, int off, int cmd, void *args) switch (cmd) { - case MR_CTL_TIMER_SET_CONFIG: + case MR_CTL_TIMER_SET_MODE: { if (args != MR_NULL) { @@ -195,7 +195,7 @@ static int mr_timer_ioctl(struct mr_dev *dev, int off, int cmd, void *args) return MR_EINVAL; } - case MR_CTL_TIMER_GET_CONFIG: + case MR_CTL_TIMER_GET_MODE: { if (args != MR_NULL) { diff --git a/document/device/timer.md b/document/device/timer.md index 622787f..bf1b2e8 100644 --- a/document/device/timer.md +++ b/document/device/timer.md @@ -48,9 +48,9 @@ int mr_dev_ioctl(int desc, int cmd, void *args); | `<0` | 错误码 | - `cmd`:命令码,支持以下命令: - - `MR_CTL_TIMER_SET_CONFIG`:设置TIMER设备配置。 + - `MR_CTL_TIMER_SET_MODE`:设置TIMER设备模式。 - `MR_CTL_TIMER_SET_TIMEOUT_CALL`:设置超时回调函数。 - - `MR_CTL_TIMER_GET_CONFIG`:获取TIMER设备配置。 + - `MR_CTL_TIMER_GET_MODE`:获取TIMER设备模式。 - `MR_CTL_TIMER_GET_TIMEOUT_CALL`:获取超时回调函数。 ### 设置/获取TIMER设备配置 @@ -60,13 +60,15 @@ TIMER设备配置: - `mode`:周期或单次模式。 ```c -/* 设置默认配置 */ -struct mr_timer_config config = MR_TIMER_CONFIG_DEFAULT; +/* 定义TIMER设备模式 */ +#define TIMER_MODE MR_TIMER_MODE_ONESHOT -/* 设置TIMER设备配置 */ -mr_dev_ioctl(ds, MR_CTL_TIMER_SET_CONFIG, &config); -/* 获取TIMER设备配置 */ -mr_dev_ioctl(ds, MR_CTL_TIMER_GET_CONFIG, &config); +/* 设置TIMER设备模式 */ +mr_dev_ioctl(ds, MR_CTL_TIMER_SET_MODE, mr_make_local(int, TIMER_MODE)); + +/* 获取TIMER设备模式 */ +int mode; +mr_dev_ioctl(ds, MR_CTL_TIMER_GET_MODE, &mode); ``` 注:如未手动配置,默认配置为: diff --git a/include/device/adc.h b/include/device/adc.h index b081a8f..19636f4 100644 --- a/include/device/adc.h +++ b/include/device/adc.h @@ -36,12 +36,10 @@ struct mr_adc_config * @brief ADC control command. */ #define MR_CTL_ADC_SET_CHANNEL MR_CTL_SET_OFFSET /**< Set channel */ -#define MR_CTL_ADC_SET_CONFIG MR_CTL_SET_CONFIG /**< Set configuration */ -#define MR_CTL_ADC_SET_CHANNEL_STATE (0x01 << 8) /**< Set channel state */ +#define MR_CTL_ADC_SET_CHANNEL_STATE MR_CTL_SET_CONFIG /**< Set channel state */ #define MR_CTL_ADC_GET_CHANNEL MR_CTL_GET_OFFSET /**< Get channel */ -#define MR_CTL_ADC_GET_CONFIG MR_CTL_GET_CONFIG /**< Get configuration */ -#define MR_CTL_ADC_GET_CHANNEL_STATE (-(0x01 << 8)) /**< Get channel state */ +#define MR_CTL_ADC_GET_CHANNEL_STATE MR_CTL_GET_CONFIG /**< Get channel state */ /** * @brief ADC data type. diff --git a/include/device/dac.h b/include/device/dac.h index 03b88c4..054372c 100644 --- a/include/device/dac.h +++ b/include/device/dac.h @@ -36,12 +36,10 @@ struct mr_dac_config * @brief DAC control command. */ #define MR_CTL_DAC_SET_CHANNEL MR_CTL_SET_OFFSET /**< Set channel */ -#define MR_CTL_DAC_SET_CONFIG MR_CTL_SET_CONFIG /**< Set configuration */ -#define MR_CTL_DAC_SET_CHANNEL_STATE (0x01 << 8) /**< Set channel state */ +#define MR_CTL_DAC_SET_CHANNEL_STATE MR_CTL_SET_CONFIG /**< Set channel state */ #define MR_CTL_DAC_GET_CHANNEL MR_CTL_GET_OFFSET /**< Get channel */ -#define MR_CTL_DAC_GET_CONFIG MR_CTL_GET_CONFIG /**< Get configuration */ -#define MR_CTL_DAC_GET_CHANNEL_STATE (-(0x01 << 8)) /**< Get channel state */ +#define MR_CTL_DAC_GET_CHANNEL_STATE MR_CTL_GET_CONFIG /**< Get channel state */ /** * @brief DAC data type. diff --git a/include/device/pin.h b/include/device/pin.h index ee9642b..b33d12b 100644 --- a/include/device/pin.h +++ b/include/device/pin.h @@ -47,16 +47,15 @@ extern "C" { */ struct mr_pin_config { - uint32_t mode: 1; /**< Mode */ - uint32_t reserved: 31; /**< Reserved */ + uint32_t mode: 4; /**< Mode */ + uint32_t reserved: 28; /**< Reserved */ }; /** * @brief PIN control command. */ #define MR_CTL_PIN_SET_NUMBER MR_CTL_SET_OFFSET /**< Set pin number */ -#define MR_CTL_PIN_SET_CONFIG MR_CTL_SET_CONFIG /**< Set pin configuration */ -#define MR_CTL_PIN_SET_MODE (0x01 << 8) /**< Set pin mode */ +#define MR_CTL_PIN_SET_MODE MR_CTL_SET_CONFIG /**< Set pin mode */ #define MR_CTL_PIN_SET_EXTI_CALL MR_CTL_SET_RD_CALL /**< Set pin exti callback */ #define MR_CTL_PIN_GET_NUMBER MR_CTL_GET_OFFSET /**< Get pin number */ diff --git a/include/device/timer.h b/include/device/timer.h index 4974107..10aa889 100644 --- a/include/device/timer.h +++ b/include/device/timer.h @@ -43,16 +43,16 @@ struct mr_timer_config /** * @brief Timer control command. */ -#define MR_CTL_TIMER_SET_CONFIG MR_CTL_SET_CONFIG /**< Set configuration */ +#define MR_CTL_TIMER_SET_MODE MR_CTL_SET_CONFIG /**< Set timer mode */ #define MR_CTL_TIMER_SET_TIMEOUT_CALL MR_CTL_SET_RD_CALL /**< Set timeout callback */ -#define MR_CTL_TIMER_GET_CONFIG MR_CTL_GET_CONFIG /**< Get configuration */ +#define MR_CTL_TIMER_GET_MODE MR_CTL_GET_CONFIG /**< Get timer mode */ #define MR_CTL_TIMER_GET_TIMEOUT_CALL MR_CTL_GET_RD_CALL /**< Get timeout callback */ /** * @brief Timer data type. */ -typedef uint8_t mr_timer_data_t; /**< Timer read/write data type */ +typedef uint32_t mr_timer_data_t; /**< Timer read/write data type */ /** * @brief Timer ISR events.