mirror of
https://github.com/WeActStudio/WeActStudio.EpaperModule.git
synced 2026-08-16 13:13:45 +02:00
first commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
/*---------------------------------------
|
||||
- WeAct Studio Official Link
|
||||
- taobao: weactstudio.taobao.com
|
||||
- aliexpress: weactstudio.aliexpress.com
|
||||
- github: github.com/WeActTC
|
||||
- gitee: gitee.com/WeAct-TC
|
||||
- blog: www.weact-tc.cn
|
||||
---------------------------------------*/
|
||||
|
||||
#include "board.h"
|
||||
#include "delay.h"
|
||||
|
||||
uint8_t g_speed = FAST;
|
||||
|
||||
void led_init(void)
|
||||
{
|
||||
gpio_init_type gpio_init_struct;
|
||||
|
||||
/* enable the led clock */
|
||||
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
||||
|
||||
/* set default parameter */
|
||||
gpio_default_para_init(&gpio_init_struct);
|
||||
|
||||
/* configure the led gpio */
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_13;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||
gpio_init(GPIOC, &gpio_init_struct);
|
||||
}
|
||||
|
||||
void led_toggle(void)
|
||||
{
|
||||
GPIOC->odt ^= GPIO_PINS_13;
|
||||
}
|
||||
|
||||
void led_set(confirm_state bit_state)
|
||||
{
|
||||
gpio_bits_write(GPIOC, GPIO_PINS_13, bit_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief configure button gpio
|
||||
* @param button: specifies the button to be configured.
|
||||
* @retval none
|
||||
*/
|
||||
void button_init(void)
|
||||
{
|
||||
gpio_init_type gpio_init_struct;
|
||||
|
||||
/* enable the button clock */
|
||||
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||
|
||||
/* set default parameter */
|
||||
gpio_default_para_init(&gpio_init_struct);
|
||||
|
||||
/* configure button pin as input with pull-up/pull-down */
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_0;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_init(GPIOA, &gpio_init_struct);
|
||||
}
|
||||
|
||||
flag_status button_getstate(void)
|
||||
{
|
||||
return gpio_input_data_bit_read(GPIOA, GPIO_PINS_0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief configure button exint
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void button_exint_init(void)
|
||||
{
|
||||
exint_init_type exint_init_struct;
|
||||
|
||||
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
|
||||
gpio_exint_line_config(GPIO_PORT_SOURCE_GPIOA, GPIO_PINS_SOURCE0);
|
||||
|
||||
exint_default_para_init(&exint_init_struct);
|
||||
exint_init_struct.line_enable = TRUE;
|
||||
exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT;
|
||||
exint_init_struct.line_select = EXINT_LINE_0;
|
||||
exint_init_struct.line_polarity = EXINT_TRIGGER_FALLING_EDGE;
|
||||
exint_init(&exint_init_struct);
|
||||
|
||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||
nvic_irq_enable(EXINT0_IRQn, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief button handler function
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void button_isr(void)
|
||||
{
|
||||
/* delay 5ms */
|
||||
delay_ms(5);
|
||||
|
||||
/* clear interrupt pending bit */
|
||||
exint_flag_clear(EXINT_LINE_0);
|
||||
|
||||
/* check input pin state */
|
||||
if (RESET == gpio_input_data_bit_read(GPIOA, GPIO_PINS_0))
|
||||
{
|
||||
if (g_speed == SLOW)
|
||||
g_speed = FAST;
|
||||
else
|
||||
g_speed = SLOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief exint0 interrupt handler
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void EXINT0_IRQHandler(void)
|
||||
{
|
||||
button_isr();
|
||||
}
|
||||
Reference in New Issue
Block a user