mirror of
https://github.com/pvvx/RTL00_WEB.git
synced 2025-07-31 20:31:05 +00:00
update
This commit is contained in:
parent
34d3652711
commit
39f77eb92b
1844 changed files with 899433 additions and 7 deletions
13
USDK/example_sources/gpio_irq/readme.txt
Normal file
13
USDK/example_sources/gpio_irq/readme.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Example Description
|
||||
|
||||
This example describes how to use GPIO read/write by mbed api.
|
||||
|
||||
Requirement Components:
|
||||
a LED
|
||||
a push button
|
||||
|
||||
Pin name PC_4 and PC_5 map to GPIOC_4 and GPIOC_5:
|
||||
- PC_4 as input with internal pull-high, connect a push button to this pin and ground.
|
||||
- PC_5 as output, connect a LED to this pin and ground.
|
||||
|
||||
In this example, push the button to trigger interrupt to turn on/off the LED.
|
||||
59
USDK/example_sources/gpio_irq/src/main.c
Normal file
59
USDK/example_sources/gpio_irq/src/main.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Routines to access hardware
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#include "device.h"
|
||||
#include "gpio_api.h" // mbed
|
||||
#include "gpio_irq_api.h" // mbed
|
||||
#include "diag.h"
|
||||
#include "main.h"
|
||||
|
||||
#define GPIO_LED_PIN PC_5
|
||||
#define GPIO_IRQ_PIN PC_4
|
||||
|
||||
int led_ctrl;
|
||||
gpio_t gpio_led;
|
||||
|
||||
extern u32 ConfigDebugWarn;
|
||||
|
||||
void gpio_demo_irq_handler (uint32_t id, gpio_irq_event event)
|
||||
{
|
||||
gpio_t *gpio_led;
|
||||
|
||||
DBG_GPIO_WARN("%s==>\n", __FUNCTION__);
|
||||
gpio_led = (gpio_t *)id;
|
||||
|
||||
led_ctrl = !led_ctrl;
|
||||
gpio_write(gpio_led, led_ctrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main program.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void main(void)
|
||||
{
|
||||
gpio_irq_t gpio_btn;
|
||||
|
||||
// Init LED control pin
|
||||
gpio_init(&gpio_led, GPIO_LED_PIN);
|
||||
gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output
|
||||
gpio_mode(&gpio_led, PullNone); // No pull
|
||||
|
||||
// Initial Push Button pin as interrupt source
|
||||
gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, gpio_demo_irq_handler, (uint32_t)(&gpio_led));
|
||||
gpio_irq_set(&gpio_btn, IRQ_FALL, 1); // Falling Edge Trigger
|
||||
gpio_irq_enable(&gpio_btn);
|
||||
|
||||
led_ctrl = 1;
|
||||
gpio_write(&gpio_led, led_ctrl);
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue