提交 77a5ddf9 编写于 作者: S Siwei Xu 提交者: Bernard Xiong

[bsp/n32g452xx] add rt_pin_get support

上级 169fca84
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
#define __N32_PIN(index, rcc, gpio, gpio_index) \ #define __N32_PIN(index, rcc, gpio, gpio_index) \
{ \ { \
0, RCC_##rcc##_PERIPH_GPIO##gpio, GPIO##gpio, GPIO_PIN_##gpio_index \ 0, RCC_##rcc##_PERIPH_GPIO##gpio, GPIO##gpio, GPIO_PIN_##gpio_index \
, GPIO##gpio##_PORT_SOURCE, GPIO_PIN_SOURCE##gpio_index \ , GPIO##gpio##_PORT_SOURCE, GPIO_PIN_SOURCE##gpio_index, "P" #gpio "." #gpio_index \
} }
#define __N32_PIN_DEFAULT {-1, 0, 0, 0, 0, 0} #define __N32_PIN_DEFAULT {-1, 0, 0, 0, 0, 0, ""}
/* N32 GPIO driver */ /* N32 GPIO driver */
struct pin_index struct pin_index
...@@ -33,6 +33,7 @@ struct pin_index ...@@ -33,6 +33,7 @@ struct pin_index
uint32_t pin; uint32_t pin;
uint8_t port_source; uint8_t port_source;
uint8_t pin_source; uint8_t pin_source;
const char* name;
}; };
static const struct pin_index pins[] = static const struct pin_index pins[] =
...@@ -473,6 +474,23 @@ const struct pin_index *get_pin(uint8_t pin) ...@@ -473,6 +474,23 @@ const struct pin_index *get_pin(uint8_t pin)
return index; return index;
}; };
rt_base_t n32_pin_get(const char *name)
{
rt_base_t i;
for (i = 0; i < ITEM_NUM(pins); i++)
{
if (rt_strcmp(pins[i].name, name) == 0)
{
/* in get_pin function, use pin parameter as index of pins array */
return i;
}
}
/* refers content of pins array, map to __N32_PIN_DEFAULT */
return 0;
}
void n32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) void n32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
{ {
const struct pin_index *index; const struct pin_index *index;
...@@ -754,6 +772,7 @@ const static struct rt_pin_ops _n32_pin_ops = ...@@ -754,6 +772,7 @@ const static struct rt_pin_ops _n32_pin_ops =
n32_pin_attach_irq, n32_pin_attach_irq,
n32_pin_dettach_irq, n32_pin_dettach_irq,
n32_pin_irq_enable, n32_pin_irq_enable,
n32_pin_get
}; };
int n32_hw_pin_init(void) int n32_hw_pin_init(void)
......
...@@ -12,19 +12,24 @@ ...@@ -12,19 +12,24 @@
#include <rtdevice.h> #include <rtdevice.h>
/* defined the LED1 pin: PB5 */ /* defined the LED1 pin: PB5 */
#define LED1_PIN 57 #define LED1_NAME "PB.5"
rt_base_t led1_pin;
int main(void) int main(void)
{ {
uint32_t Speed = 200; uint32_t Speed = 200;
/* get LED1 pin id by name */
led1_pin = rt_pin_get(LED1_NAME);
/* set LED1 pin mode to output */ /* set LED1 pin mode to output */
rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT); rt_pin_mode(led1_pin, PIN_MODE_OUTPUT);
while (1) while (1)
{ {
rt_pin_write(LED1_PIN, PIN_LOW); rt_pin_write(led1_pin, PIN_LOW);
rt_thread_mdelay(Speed); rt_thread_mdelay(Speed);
rt_pin_write(LED1_PIN, PIN_HIGH); rt_pin_write(led1_pin, PIN_HIGH);
rt_thread_mdelay(Speed); rt_thread_mdelay(Speed);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册