Преглед изворни кода

[Driver][MISC] Update ADC/PWM (#11003)

* [DM][MISC] Make Kconfig(ADC/PWM) import for DM

* [Driver][MISC][ADC] Fixup ADC

1. Fixup error no.
2. Fixup type of control for args.
3. Fixup value no init.

* [Driver][MISC][PWM] Enable `rt_pwm_get` API

Signed-off-by: GuEe-GUI <2991707448@qq.com>
GUI пре 2 месеци
родитељ
комит
6618fa1cf6

+ 8 - 0
components/drivers/include/drivers/dev_pwm.h

@@ -201,6 +201,14 @@ rt_err_t rt_pwm_set_dead_time(struct rt_device_pwm *device, int channel, rt_uint
 */
 */
 rt_err_t rt_pwm_set_phase(struct rt_device_pwm *device, int channel, rt_uint32_t phase);
 rt_err_t rt_pwm_set_phase(struct rt_device_pwm *device, int channel, rt_uint32_t phase);
 
 
+/**
+ * @brief get the PWM configuration
+ * @param device the PWM device
+ * @param cfg the configuration of PWM
+ * @return rt_err_t error code
+ */
+rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg);
+
 /*! @}*/
 /*! @}*/
 
 
 #endif /* __DEV_PWM_H__ */
 #endif /* __DEV_PWM_H__ */

+ 10 - 2
components/drivers/misc/Kconfig

@@ -1,7 +1,11 @@
-config RT_USING_ADC
+menuconfig RT_USING_ADC
     bool "Using ADC device drivers"
     bool "Using ADC device drivers"
     default n
     default n
 
 
+if RT_USING_DM && RT_USING_ADC
+    osource "$(SOC_DM_ADC_DIR)/Kconfig"
+endif
+
 config RT_USING_DAC
 config RT_USING_DAC
     bool "Using DAC device drivers"
     bool "Using DAC device drivers"
     default n
     default n
@@ -18,10 +22,14 @@ config RT_USING_RANDOM
     bool "Using RANDOM device drivers"
     bool "Using RANDOM device drivers"
     default n
     default n
 
 
-config RT_USING_PWM
+menuconfig RT_USING_PWM
     bool "Using PWM device drivers"
     bool "Using PWM device drivers"
     default n
     default n
 
 
+if RT_USING_DM && RT_USING_PWM
+    osource "$(SOC_DM_PWM_DIR)/Kconfig"
+endif
+
 config RT_USING_PULSE_ENCODER
 config RT_USING_PULSE_ENCODER
     bool "Using PULSE ENCODER device drivers"
     bool "Using PULSE ENCODER device drivers"
     default n
     default n

+ 2 - 2
components/drivers/misc/adc.c

@@ -43,7 +43,7 @@ static rt_ssize_t _adc_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size
 static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args)
 static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args)
 {
 {
     rt_adc_device_t adc = (struct rt_adc_device *)dev;
     rt_adc_device_t adc = (struct rt_adc_device *)dev;
-    rt_err_t        result = RT_ERROR;
+    rt_err_t        result = -RT_ERROR;
 
 
     if (cmd == RT_ADC_CMD_ENABLE && adc->ops->enabled)
     if (cmd == RT_ADC_CMD_ENABLE && adc->ops->enabled)
     {
     {
@@ -167,7 +167,7 @@ rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_int8_t channel)
     RT_ASSERT(dev);
     RT_ASSERT(dev);
 
 
     rt_uint32_t value;
     rt_uint32_t value;
-    rt_int16_t  vref, voltage;
+    rt_int16_t  vref, voltage = 0;
     rt_uint8_t  resolution;
     rt_uint8_t  resolution;
     rt_err_t    result;
     rt_err_t    result;
 
 

+ 1 - 1
components/drivers/misc/rt_drv_pwm.c

@@ -285,7 +285,7 @@ rt_err_t rt_pwm_set_phase(struct rt_device_pwm *device, int channel, rt_uint32_t
     return result;
     return result;
 }
 }
 
 
-static rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg)
+rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg)
 {
 {
     rt_err_t result = RT_EOK;
     rt_err_t result = RT_EOK;