mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-16 01:05:15 +08:00
[componnets][pin]add pin operate command in MSH (#5892)
* 1. 在AT32的BSP的drv_gpio中增加了at32_pin_get函数,用于实现rt_pin_ops对象中的pin_get 2. 在MSH中增加了PIN的操作命令 3. 为了方便在MSH命令中解析字符串,增加了一些字符串相关的函数
This commit is contained in:
1 parent
04a17d469a
commit
e8d775f888
7 files changed
+403
-29
No files matched your search
@@ -102,6 +102,43 @@ static uint32_t pin_irq_enable_mask = 0;
|
||||
|
||||
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
|
||||
|
||||
static rt_base_t at32_pin_get(const char *name)
|
||||
{
|
||||
rt_base_t pin = 0;
|
||||
int hw_port_num, hw_pin_num = 0;
|
||||
int i, name_len;
|
||||
|
||||
name_len = rt_strlen(name);
|
||||
|
||||
if ((name_len < 4) || (name_len >= 6))
|
||||
{
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
if ((name[0] != 'P') || (name[2] != '.'))
|
||||
{
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
|
||||
if ((name[1] >= 'A') && (name[1] <= 'Z'))
|
||||
{
|
||||
hw_port_num = (int)(name[1] - 'A');
|
||||
}
|
||||
else
|
||||
{
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
|
||||
for (i = 3; i < name_len; i++)
|
||||
{
|
||||
hw_pin_num *= 10;
|
||||
hw_pin_num += name[i] - '0';
|
||||
}
|
||||
|
||||
pin = PIN_NUM(hw_port_num, hw_pin_num);
|
||||
|
||||
return pin;
|
||||
}
|
||||
|
||||
static void at32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
|
||||
{
|
||||
gpio_type *gpio_port;
|
||||
@@ -423,7 +460,7 @@ const static struct rt_pin_ops _at32_pin_ops =
|
||||
at32_pin_attach_irq,
|
||||
at32_pin_dettach_irq,
|
||||
at32_pin_irq_enable,
|
||||
RT_NULL,
|
||||
at32_pin_get,
|
||||
};
|
||||
|
||||
rt_inline void pin_irq_handler(int irqno)
|
||||
|
||||
@@ -161,6 +161,7 @@ static uint32_t pin_irq_enable_mask = 0;
|
||||
|
||||
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
|
||||
|
||||
/* e.g. PE.7 */
|
||||
static rt_base_t stm32_pin_get(const char *name)
|
||||
{
|
||||
rt_base_t pin = 0;
|
||||
|
||||
+241
-22
File diff suppressed because it is too large.
Load diff
@@ -4,6 +4,7 @@ cwd = GetCurrentDir()
|
||||
src = Split('''
|
||||
shell.c
|
||||
msh.c
|
||||
msh_parse.c
|
||||
''')
|
||||
|
||||
if GetDepend('MSH_USING_BUILT_IN_COMMANDS'):
|
||||
|
||||
@@ -10,17 +10,17 @@
|
||||
#ifndef __FINSH_H__
|
||||
#define __FINSH_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdef.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma section("FSymTab$f",read)
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#pragma section("FSymTab$f",read)
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
typedef long (*syscall_func)(void);
|
||||
#ifdef FINSH_USING_SYMTAB
|
||||
#ifdef __TI_COMPILER_VERSION__
|
||||
#define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab"))
|
||||
#endif
|
||||
#define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab"))
|
||||
#endif /* __TI_COMPILER_VERSION__ */
|
||||
#ifdef FINSH_USING_DESCRIPTION
|
||||
#ifdef _MSC_VER
|
||||
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-25 WangQiang the first verion for msh parse
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define forstrloop(str) for (; '\0' != *(str); (str)++)
|
||||
|
||||
/**
|
||||
* This function will check integer.
|
||||
*
|
||||
* @param strvalue string
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
rt_bool_t msh_isint(char *strvalue)
|
||||
{
|
||||
if ((RT_NULL == strvalue) || ('\0' == strvalue[0]))
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
if (('+' == *strvalue) || ('-' == *strvalue))
|
||||
{
|
||||
strvalue++;
|
||||
}
|
||||
forstrloop(strvalue)
|
||||
{
|
||||
if (!isdigit((int)(*strvalue)))
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
}
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will check hex.
|
||||
*
|
||||
* @param strvalue string
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
rt_bool_t msh_ishex(char *strvalue)
|
||||
{
|
||||
int c;
|
||||
if ((RT_NULL == strvalue) || ('\0' == strvalue[0]))
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
if ('0' != *(strvalue++))
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
if ('x' != *(strvalue++))
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
forstrloop(strvalue)
|
||||
{
|
||||
c = tolower(*strvalue);
|
||||
if (!isxdigit(c))
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
}
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will transform for string to hex.
|
||||
*
|
||||
* @param strvalue string
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
int msh_strtohex(char *strvalue)
|
||||
{
|
||||
char c = 0;
|
||||
int value = 0;
|
||||
strvalue += 2;
|
||||
forstrloop(strvalue)
|
||||
{
|
||||
value *= 16;
|
||||
c = tolower(*strvalue);
|
||||
value += isdigit(c) ? c - '0' : c - 'a' + 10;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-25 WangQiang the first verion for msh parse
|
||||
*/
|
||||
|
||||
#ifndef MSH_PARSE_H
|
||||
#define MSH_PARSE_H
|
||||
|
||||
#include <rtdef.h>
|
||||
|
||||
rt_bool_t msh_isint(char *strvalue);
|
||||
rt_bool_t msh_ishex(char *strvalue);
|
||||
int msh_strtohex(char *strvalue);
|
||||
|
||||
#endif /* MSH_PARSE_H */
|
||||
Reference in new issue
Block a user