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
39 changes: 38 additions & 1 deletion bsp/at32/libraries/rt_drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions bsp/stm32/libraries/HAL_Drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading