Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bsp/airm2m/air32f103/libraries/rt_drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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++)
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions bsp/stm32/libraries/HAL_Drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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++)
Expand All @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions bsp/synwit/swm320/drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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++)
Expand All @@ -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 =
Expand Down
11 changes: 7 additions & 4 deletions bsp/synwit/swm341/drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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++)
Expand All @@ -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 =
Expand Down
14 changes: 11 additions & 3 deletions bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f10x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

if (pin < 0)
{
goto out;
}
return pin;

return -1;
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 = {
Expand Down
14 changes: 11 additions & 3 deletions bsp/wch/arm/Libraries/ch32_drivers/drv_gpio_ch32f20x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

if (pin < 0)
{
goto out;
}
return pin;

return -1;
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 = {
Expand Down
2 changes: 2 additions & 0 deletions bsp/wch/risc-v/Libraries/ch56x_drivers/ch56x_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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;
}

Expand Down
43 changes: 14 additions & 29 deletions components/drivers/misc/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
}
}

Expand Down