From a07fda3470376ba08230550d88be4748055ce693 Mon Sep 17 00:00:00 2001 From: wangqinglin <53550140+HelloByeAll@users.noreply.github.com> Date: Thu, 20 Jul 2023 06:45:43 +0800 Subject: [PATCH] =?UTF-8?q?[bsp][stm32][airm2m]=E6=9B=B4=E6=96=B0pin?= =?UTF-8?q?=20num=E5=91=BD=E4=BB=A4=20(#7390)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../air32f103/libraries/rt_drivers/drv_gpio.c | 9 ++-- bsp/stm32/libraries/HAL_Drivers/drv_gpio.c | 10 +++-- bsp/synwit/swm320/drivers/drv_gpio.c | 11 +++-- bsp/synwit/swm341/drivers/drv_gpio.c | 11 +++-- .../ch32_drivers/drv_gpio_ch32f10x.c | 14 ++++-- .../ch32_drivers/drv_gpio_ch32f20x.c | 14 ++++-- .../Libraries/ch56x_drivers/ch56x_gpio.c | 2 + components/drivers/misc/pin.c | 43 ++++++------------- 8 files changed, 65 insertions(+), 49 deletions(-) diff --git a/bsp/airm2m/air32f103/libraries/rt_drivers/drv_gpio.c b/bsp/airm2m/air32f103/libraries/rt_drivers/drv_gpio.c index 24247559c2..14c1d26921 100644 --- a/bsp/airm2m/air32f103/libraries/rt_drivers/drv_gpio.c +++ b/bsp/airm2m/air32f103/libraries/rt_drivers/drv_gpio.c @@ -113,11 +113,11 @@ static rt_base_t air32_pin_get(const char *name) if ((name_len < 4) || (name_len >= 6)) { - return -RT_EINVAL; + goto out; } if ((name[0] != 'P') || (name[2] != '.')) { - return -RT_EINVAL; + goto out; } if ((name[1] >= 'A') && (name[1] <= 'Z')) @@ -126,7 +126,7 @@ static rt_base_t air32_pin_get(const char *name) } else { - return -RT_EINVAL; + goto out; } for (i = 3; i < name_len; i++) @@ -138,6 +138,9 @@ static rt_base_t air32_pin_get(const char *name) pin = PIN_NUM(hw_port_num, hw_pin_num); return pin; +out: + rt_kprintf("Px.y x:A~Z y:0~15, e.g. PA.0\n"); + return -RT_EINVAL; } static void air32_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c b/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c index 8b020f5402..d58b9c9557 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c @@ -172,11 +172,11 @@ static rt_base_t stm32_pin_get(const char *name) if ((name_len < 4) || (name_len >= 6)) { - return -RT_EINVAL; + goto out; } if ((name[0] != 'P') || (name[2] != '.')) { - return -RT_EINVAL; + goto out; } if ((name[1] >= 'A') && (name[1] <= 'Z')) @@ -185,7 +185,7 @@ static rt_base_t stm32_pin_get(const char *name) } else { - return -RT_EINVAL; + goto out; } for (i = 3; i < name_len; i++) @@ -197,6 +197,10 @@ static rt_base_t stm32_pin_get(const char *name) pin = PIN_NUM(hw_port_num, hw_pin_num); return pin; + +out: + rt_kprintf("Px.y x:A~Z y:0-15, e.g. PA.0\n"); + return -RT_EINVAL; } static void stm32_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value) diff --git a/bsp/synwit/swm320/drivers/drv_gpio.c b/bsp/synwit/swm320/drivers/drv_gpio.c index 3a6df7960d..daffdffb9e 100644 --- a/bsp/synwit/swm320/drivers/drv_gpio.c +++ b/bsp/synwit/swm320/drivers/drv_gpio.c @@ -444,11 +444,11 @@ static rt_base_t swm_pin_get(const char *name) if ((name_len < 4) || (name_len >= 6)) { - return -RT_EINVAL; + goto out; } if ((name[0] != 'P') || (name[2] != '.')) { - return -RT_EINVAL; + goto out; } switch(name[1]) @@ -472,7 +472,7 @@ static rt_base_t swm_pin_get(const char *name) pin = 76; break; default: - return -RT_EINVAL; + goto out; } for (i = 3; i < name_len; i++) @@ -486,10 +486,13 @@ static rt_base_t swm_pin_get(const char *name) } else { - return -RT_EINVAL; + goto out; } return pin; +out: + rt_kprintf("PA0~PA12, PB0~PB12, PC0~PC7, PM0~PM21, PN0~PN19, PP0~PP23\n"); + return -RT_EINVAL; } const static struct rt_pin_ops swm_pin_ops = diff --git a/bsp/synwit/swm341/drivers/drv_gpio.c b/bsp/synwit/swm341/drivers/drv_gpio.c index 0f33be1b0d..586530359b 100644 --- a/bsp/synwit/swm341/drivers/drv_gpio.c +++ b/bsp/synwit/swm341/drivers/drv_gpio.c @@ -466,11 +466,11 @@ static rt_base_t swm_pin_get(const char *name) if ((name_len < 4) || (name_len >= 6)) { - return -RT_EINVAL; + goto out; } if ((name[0] != 'P') || (name[2] != '.')) { - return -RT_EINVAL; + goto out; } switch(name[1]) @@ -497,7 +497,7 @@ static rt_base_t swm_pin_get(const char *name) pin = 96; break; default: - return -RT_EINVAL; + goto out; } for (i = 3; i < name_len; i++) @@ -511,10 +511,13 @@ static rt_base_t swm_pin_get(const char *name) } else { - return -RT_EINVAL; + goto out; } return pin; +out: + rt_kprintf("Px.y x:A/B/C/D/E/M/N y:0~15, e.g. PA.0\n"); + return -RT_EINVAL; } static const struct rt_pin_ops swm_pin_ops = diff --git a/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f10x.c b/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f10x.c index 1454731693..576ae11333 100644 --- a/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f10x.c +++ b/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f10x.c @@ -436,6 +436,7 @@ rt_err_t ch32f1_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint8 /*PX.XX*/ rt_base_t ch32f1_pin_get(const char *name) { + rt_base_t pin; rt_uint16_t portsource, pinsource; int sz; @@ -445,17 +446,24 @@ rt_base_t ch32f1_pin_get(const char *name) { portsource = name[1] - 0x41; pinsource = name[3] - 0x30; - return pin_info_list_find_pin(portsource, pinsource); } if (sz == 5) { portsource = name[1]; pinsource = (name[3] - 0x30) * 10 + (name[4] - 0x30); - return pin_info_list_find_pin(portsource, pinsource); } + pin = pin_info_list_find_pin(portsource, pinsource); - return -1; + if (pin < 0) + { + goto out; + } + return pin; + +out: + rt_kprintf("PA.0~PA.15 PB.0~PB.15 PC.0~PC.15 PD.0~PD.2\n"); + return -RT_EINVAL; } const static struct rt_pin_ops pin_ops = { diff --git a/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f20x.c b/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f20x.c index 1bcf843961..51d59c1e1b 100644 --- a/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f20x.c +++ b/bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f20x.c @@ -467,6 +467,7 @@ rt_err_t ch32f2_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint8 /*PX.XX*/ rt_base_t ch32f2_pin_get(const char *name) { + rt_base_t pin; rt_uint16_t portsource, pinsource; int sz; @@ -476,17 +477,24 @@ rt_base_t ch32f2_pin_get(const char *name) { portsource = name[1] - 0x41; pinsource = name[3] - 0x30; - return pin_info_list_find_pin(portsource, pinsource); } if (sz == 5) { portsource = name[1]; pinsource = (name[3] - 0x30) * 10 + (name[4] - 0x30); - return pin_info_list_find_pin(portsource, pinsource); } + pin = pin_info_list_find_pin(portsource, pinsource); - return -1; + if (pin < 0) + { + goto out; + } + return pin; + +out: + rt_kprintf("Px.y x:A~E y:0~15, e.g. PA.0\n"); + return -RT_EINVAL; } const static struct rt_pin_ops pin_ops = { diff --git a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c index 08a855f63f..8cc42421e0 100644 --- a/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c +++ b/bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c @@ -190,6 +190,8 @@ static rt_base_t gpio_pin_get(const char *name) } } +out: + rt_kprintf("PX.nn X: A,B,C,D... nn: 0~31, e.g. PA.0\n"); return -1; } diff --git a/components/drivers/misc/pin.c b/components/drivers/misc/pin.c index fd0b8e5f61..504c243677 100644 --- a/components/drivers/misc/pin.c +++ b/components/drivers/misc/pin.c @@ -156,10 +156,6 @@ rt_base_t rt_pin_get(const char *name) { RT_ASSERT(_hw_pin.ops != RT_NULL); - if (name[0] != 'P' && name[0] != 'p') - { - return -RT_EINVAL; - } if (_hw_pin.ops->pin_get == RT_NULL) { return -RT_ENOSYS; @@ -176,36 +172,25 @@ rt_base_t rt_pin_get(const char *name) /* * convert function for port name - * support PE02, PE2, PE.02, PE.2, pe02, pe2, pe.02, pe.2 */ static rt_base_t _pin_cmd_conv(const char *name) { - int size = 0; - char format_name[6] = { 0 }; - format_name[0] = toupper(name[0]); - format_name[1] = toupper(name[1]); - - size = rt_strlen(name); - size = (size > 5) ? 5 : size; - size -= 2; - if (name[2] != '.') - { - format_name[2] = '.'; - } - strncat(format_name, name + 2, size); - return rt_pin_get(format_name); + return rt_pin_get(name); } static void _pin_cmd_print_usage(void) { - rt_kprintf("pin [option]\n"); - rt_kprintf(" num: get pin number from hardware pin\n"); - rt_kprintf(" num can be PE02, PE2, PE.02, PE.2, pe02, pe2, pe.02, pe.2\n"); - rt_kprintf(" e.g. MSH >pin num PA.16\n"); - rt_kprintf(" mode: set pin mode to output/input/input_pullup/input_pulldown/output_od\n e.g. MSH >pin mode PA.16 output\n"); - rt_kprintf(" read: read pin level of hardware pin\n e.g. MSH >pin read PA.16\n"); - rt_kprintf(" write: write pin level(high/low or on/off) to hardware pin\n e.g. MSH >pin write PA.16 high\n"); - rt_kprintf(" help: this help list\n"); + rt_kprintf("pin [option] GPIO\n"); + rt_kprintf(" num: get pin number from hardware pin\n"); + rt_kprintf(" mode: set pin mode to output/input/input_pullup/input_pulldown/output_od\n"); + rt_kprintf(" e.g. MSH >pin mode GPIO output\n"); + rt_kprintf(" read: read pin level of hardware pin\n"); + rt_kprintf(" e.g. MSH >pin read GPIO\n"); + rt_kprintf(" write: write pin level(high/low or on/off) to hardware pin\n"); + rt_kprintf(" e.g. MSH >pin write GPIO high\n"); + rt_kprintf(" help: this help list\n"); + rt_kprintf("GPIO e.g.:"); + rt_pin_get(" "); } /* e.g. MSH >pin num PA.16 */ @@ -307,11 +292,11 @@ static void _pin_cmd_read(int argc, char *argv[]) value = rt_pin_read(pin); if (value == PIN_HIGH) { - rt_kprintf("pin[%d] = on\n", pin); + rt_kprintf("pin[%d] = high\n", pin); } else { - rt_kprintf("pin[%d] = off\n", pin); + rt_kprintf("pin[%d] = low\n", pin); } }