mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add examples
This commit is contained in:
parent
265d41b6a3
commit
4128624f93
112 changed files with 158017 additions and 0 deletions
21
RTL00_SDKV35a/example_sources/gpio_level_irq/readme.txt
Normal file
21
RTL00_SDKV35a/example_sources/gpio_level_irq/readme.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Example Description
|
||||
|
||||
This example describes how to implement high/low level trigger on 1 gpio pin.
|
||||
|
||||
Pin name PC_4 and PC_5 map to GPIOC_4 and GPIOC_5:
|
||||
Connect PC_4 and PC_5
|
||||
- PC_4 as gpio input high/low level trigger.
|
||||
- PC_5 as gpio output
|
||||
|
||||
In this example, PC_5 is signal source that change level to high and low periodically.
|
||||
|
||||
PC_4 setup to listen low level events in initial.
|
||||
When PC_4 catch low level events, it disable the irq to avoid receiving duplicate events.
|
||||
(NOTE: the level events will keep invoked if level keeps in same level)
|
||||
|
||||
Then PC_4 is configured to listen high level events and enable irq.
|
||||
As PC_4 catches high level events, it changes back to listen low level events.
|
||||
|
||||
Thus PC_4 can handle both high/low level events.
|
||||
|
||||
In this example, you will see log that prints high/low level event periodically.
|
||||
73
RTL00_SDKV35a/example_sources/gpio_level_irq/src/main.c
Normal file
73
RTL00_SDKV35a/example_sources/gpio_level_irq/src/main.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Routines to access hardware
|
||||
*
|
||||
* Copyright (c) 2015 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_irq_api.h" // mbed
|
||||
#include "gpio_irq_ex_api.h"
|
||||
#include "diag.h"
|
||||
#include "main.h"
|
||||
|
||||
#define GPIO_IRQ_LEVEL_PIN PC_4
|
||||
#define GPIO_SIGNAL_SOURCE PC_5
|
||||
|
||||
gpio_irq_t gpio_level;
|
||||
int current_level = IRQ_LOW;
|
||||
|
||||
void gpio_level_irq_handler (uint32_t id, gpio_irq_event event)
|
||||
{
|
||||
uint32_t *level = (uint32_t *) id;
|
||||
|
||||
// Disable level irq because the irq will keep triggered when it keeps in same level.
|
||||
gpio_irq_disable(&gpio_level);
|
||||
|
||||
// make some software de-bounce here if the signal source is not stable.
|
||||
|
||||
if (*level == IRQ_LOW )
|
||||
{
|
||||
printf("low level event\r\n");
|
||||
|
||||
// Change to listen to high level event
|
||||
*level = IRQ_HIGH;
|
||||
gpio_irq_set(&gpio_level, IRQ_HIGH, 1);
|
||||
gpio_irq_enable(&gpio_level);
|
||||
}
|
||||
else if (*level == IRQ_HIGH)
|
||||
{
|
||||
printf("high level event\r\n");
|
||||
|
||||
// Change to listen to low level event
|
||||
*level = IRQ_LOW;
|
||||
gpio_irq_set(&gpio_level, IRQ_LOW, 1);
|
||||
gpio_irq_enable(&gpio_level);
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
// configure level trigger handler
|
||||
gpio_irq_init(&gpio_level, GPIO_IRQ_LEVEL_PIN, gpio_level_irq_handler, (uint32_t)(¤t_level));
|
||||
gpio_irq_set(&gpio_level, IRQ_LOW, 1);
|
||||
gpio_irq_enable(&gpio_level);
|
||||
|
||||
// configure gpio as signal source for high/low level trigger
|
||||
gpio_t gpio_src;
|
||||
gpio_init(&gpio_src, GPIO_SIGNAL_SOURCE);
|
||||
gpio_dir(&gpio_src, PIN_OUTPUT); // Direction: Output
|
||||
gpio_mode(&gpio_src, PullNone);
|
||||
|
||||
while(1) {
|
||||
gpio_write(&gpio_src, 1);
|
||||
for (i=0; i<20000000; i++) asm("nop");
|
||||
gpio_write(&gpio_src, 0);
|
||||
for (i=0; i<20000000; i++) asm("nop");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue