[bsp][stm32][airm2m]<pin>更新pin num命令 (#7390)

This commit is contained in:
wangqinglin 2023-07-20 06:45:43 +08:00 committed by GitHub
parent 58e0ddf287
commit a07fda3470
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 49 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 =

View File

@ -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 =

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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;
}

View File

@ -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("pin [option] GPIO\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(" 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);
}
}