diff options
| author | Meco Man <[email protected]> | 2022-04-22 18:59:27 -0400 |
|---|---|---|
| committer | guo <[email protected]> | 2022-04-23 23:03:59 +0800 |
| commit | 175ca2ee09698f554993fb2ff440cad1c9af89f4 (patch) | |
| tree | 871af8f7605bc7f6a7d7e79437866bd699aeabfb /components/drivers/misc | |
| parent | 778be73cac4795c97ab01872e94dbf09f2014634 (diff) | |
[dac] add get resolution method
Diffstat (limited to 'components/drivers/misc')
| -rw-r--r-- | components/drivers/misc/adc.c | 2 | ||||
| -rw-r--r-- | components/drivers/misc/dac.c | 20 |
2 files changed, 14 insertions, 8 deletions
diff --git a/components/drivers/misc/adc.c b/components/drivers/misc/adc.c index ae324a16ec..9c87919793 100644 --- a/components/drivers/misc/adc.c +++ b/components/drivers/misc/adc.c @@ -58,7 +58,7 @@ static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args) if(resolution != 0) { *((rt_uint8_t*)args) = resolution; - LOG_D("ADC resolution:%d", resolution); + LOG_D("resolution: %d bits", resolution); result = RT_EOK; } } diff --git a/components/drivers/misc/dac.c b/components/drivers/misc/dac.c index 548a7bde99..ecbadfd502 100644 --- a/components/drivers/misc/dac.c +++ b/components/drivers/misc/dac.c @@ -40,21 +40,27 @@ static rt_size_t _dac_write(rt_device_t dev, rt_off_t pos, const void *buffer, r static rt_err_t _dac_control(rt_device_t dev, int cmd, void *args) { - rt_err_t result = RT_EOK; + rt_err_t result = -RT_EINVAL; rt_dac_device_t dac = (struct rt_dac_device *)dev; - if (dac->ops->enabled == RT_NULL) - { - return -RT_ENOSYS; - } - if (cmd == RT_DAC_CMD_ENABLE) + if (cmd == RT_DAC_CMD_ENABLE && dac->ops->enabled) { result = dac->ops->enabled(dac, (rt_uint32_t)args); } - else if (cmd == RT_DAC_CMD_DISABLE) + else if (cmd == RT_DAC_CMD_DISABLE && dac->ops->enabled) { result = dac->ops->disabled(dac, (rt_uint32_t)args); } + else if (cmd == RT_DAC_CMD_GET_RESOLUTION && dac->ops->get_resolution) + { + rt_uint8_t resolution = dac->ops->get_resolution(dac); + if(resolution != 0) + { + *((rt_uint8_t*)args) = resolution; + LOG_D("resolution: %d bits", resolution); + result = RT_EOK; + } + } return result; } |
