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
13
RTL00_SDKV35a/example_sources/gpio_light_weight/readme.txt
Normal file
13
RTL00_SDKV35a/example_sources/gpio_light_weight/readme.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
Example Description
|
||||
|
||||
This example describes how to use GPIO read/write in a light weight way.
|
||||
|
||||
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, the LED is on when the push button is pressed.
|
77
RTL00_SDKV35a/example_sources/gpio_light_weight/src/main.c
Normal file
77
RTL00_SDKV35a/example_sources/gpio_light_weight/src/main.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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 "main.h"
|
||||
|
||||
#define GPIO_LED_PIN PC_5
|
||||
#define GPIO_PUSHBT_PIN PC_4
|
||||
|
||||
/* You can improve time cost of gpio write by import source code of
|
||||
* function "gpio_direct_write" based on your needs.
|
||||
* In this example, enable CACHE_WRITE_ACTION as demonstration.
|
||||
*/
|
||||
#define CACHE_WRITE_ACTION (0)
|
||||
|
||||
#if defined(CACHE_WRITE_ACTION) && (CACHE_WRITE_ACTION == 1)
|
||||
const u8 _GPIO_SWPORT_DR_TBL[] = {
|
||||
GPIO_PORTA_DR,
|
||||
GPIO_PORTB_DR,
|
||||
GPIO_PORTC_DR
|
||||
};
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gpio_t gpio_led;
|
||||
gpio_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
|
||||
gpio_init(&gpio_btn, GPIO_PUSHBT_PIN);
|
||||
gpio_dir(&gpio_btn, PIN_INPUT); // Direction: Input
|
||||
gpio_mode(&gpio_btn, PullUp); // Pull-High
|
||||
|
||||
#if defined(CACHE_WRITE_ACTION) && (CACHE_WRITE_ACTION == 1)
|
||||
u8 port_num = HAL_GPIO_GET_PORT_BY_NAME(gpio_led.hal_pin.pin_name);;
|
||||
u8 pin_num = HAL_GPIO_GET_PIN_BY_NAME(gpio_led.hal_pin.pin_name);;
|
||||
u8 dr_tbl = _GPIO_SWPORT_DR_TBL[port_num];
|
||||
u32 RegValue;
|
||||
#endif
|
||||
|
||||
while(1){
|
||||
#if defined(CACHE_WRITE_ACTION) && (CACHE_WRITE_ACTION == 1)
|
||||
if (gpio_read(&gpio_btn)) {
|
||||
// turn off LED
|
||||
RegValue = HAL_READ32(GPIO_REG_BASE, dr_tbl);
|
||||
RegValue &= ~(1 << pin_num);
|
||||
HAL_WRITE32(GPIO_REG_BASE, dr_tbl, RegValue);
|
||||
} else {
|
||||
// turn on LED
|
||||
RegValue = HAL_READ32(GPIO_REG_BASE, dr_tbl);
|
||||
RegValue |= (1<< pin_num);
|
||||
HAL_WRITE32(GPIO_REG_BASE, dr_tbl, RegValue);
|
||||
}
|
||||
#else
|
||||
if (gpio_read(&gpio_btn)) {
|
||||
// turn off LED
|
||||
gpio_direct_write(&gpio_led, 0);
|
||||
} else {
|
||||
// turn on LED
|
||||
gpio_direct_write(&gpio_led, 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue