#include "t_lev_decode.h" #if 0 #include "t_icu.h" #include "t_gpio.h" #include "t_timer.h" #include "bk3231s_reg.h" uint8_t test_uart_tx[] ={0xab}; //int test_ir_count; uint8_t ir_state = 0; uint8_t ir_cnt = 0; uint8_t ir_index = 0; uint8_t g_ir_code[4] = {0}; uint8_t ir_tmp = 0; uint8_t g_ir_recv_done_flag = 0; //uint8_t test_ir2_count; uint32_t ir_check_clock; extern int timer_flag; void my_rx_timer_stop() { Timer_Stop(0); GPIO_output(0, 7, 0); } ///time count us void my_rx_timer_start(int time_count) { my_rx_timer_stop(); timer_flag =0; Timer_Start(0,time_count); } void ir_timer_handle(uint8_t ir_gpio) { GPIO_output(0, 6, 1); GPIO_output(0, 6, 0); if(ir_gpio == 0) { if(ir_state == 0) { ir_state = 1; GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP); GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_UP); } else if(ir_state == 1) { ir_state = 0; } else if(ir_state == 2) { if(ir_index >= 8) { ir_index = 0; g_ir_code[ir_cnt] = ir_tmp; ir_tmp = 0; ir_cnt++; if(ir_cnt >= 4) { ir_cnt = 0; ir_state = 0; g_ir_recv_done_flag = 1; //U_UART_PRINTF("BB~:%x,%x,%x,%x\r\n", g_ir_code[0],g_ir_code[1],g_ir_code[2],g_ir_code[3]); GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP); GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN); } } } } else if(ir_gpio == 1) { //U_UART_PRINTF("ir_d\n"); if(ir_state == 0) { ir_state = 0; } else if(ir_state == 1) { ir_state = 2; } else if(ir_state == 2) { ir_tmp |= 0x01; if(ir_index >= 8) { ir_index = 0; g_ir_code[ir_cnt] = ir_tmp; ir_tmp = 0; ir_cnt++; if(ir_cnt >= 4) { ir_cnt = 0; ir_state = 0; g_ir_recv_done_flag = 1; //Enable_ICU_Intr(); //U_UART_PRINTF("AA:%x,%x,%x,%x\r\n",g_ir_code[0],g_ir_code[1],g_ir_code[2],g_ir_code[3]); GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP); GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN); REG_AHB0_FIQ_PRIORITY_EN |= INT_STATUS_GPIO; } } } } } void clean_ir_status(void) { ir_cnt = 0; ir_state = 0; ir_index =0; } extern void deg_io_toggle(void); //extern int ir_check_clock; void ir_callback(void) { GPIO_output(0, 4, 0); GPIO_output(0, 4, 1); //U_UART_PRINTF("ir_c\n"); //deg_io_toggle(); // return; if(!GpioGetIn(MODE_KEY_PORT,MODE_KEY_PIN)) { //U_UART_PRINTF("ir_d\n"); if(ir_state == 0) { my_rx_timer_start(8000); } else if(ir_state == 1) { ir_check_clock = HW_Get_Native_Clk_Avoid_Race()+32000; ir_state = 0; } else if(ir_state == 2) { ir_check_clock = HW_Get_Native_Clk_Avoid_Race()+32000; } } else if(GpioGetIn(MODE_KEY_PORT,MODE_KEY_PIN)) { //U_UART_PRINTF("ir_p\n"); // bprintf("~%d %d %d %d\r\n",ir_state,ir_cnt,ir_index,timer_cnt); if(ir_state == 0) { GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP); GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN); } else if(ir_state == 1) { ir_check_clock = HW_Get_Native_Clk_Avoid_Race() + 32000; my_rx_timer_start(2400); } else if(ir_state == 2) { ir_check_clock = HW_Get_Native_Clk_Avoid_Race() + 32000; ir_tmp <<= 1; ir_index++; my_rx_timer_start(650); } } } void t_ir_init(void) { GPIO_config(0, 4, 1); GPIO_output(0, 4, 0); GPIO_config(0, 6, 1); GPIO_output(0, 6, 0); //bprintf("Key_init handle\r\n"); //Timer_Initial(); IcuPphCfg( ICU_PPH_GPIO, ICU_MCU_CLK_SRC_APH, ICU_CLK_SRC_FREQ_DPLL_96M, ICU_CLK_PRE_DIV_NONE, ICU_CLK_EN, EN, EN, DISEN); GpioGenCfg(MODE_KEY_PORT,MODE_KEY_PIN,GPIO_MODE_GPIO,GPIO_IO_IN,GPIO_PULL_UP); GpioIntCfg(MODE_KEY_PORT,MODE_KEY_PIN,EN,GPIO_INTERRUPT_EDGE_DOWN); //中断触发,中断使能 REG_AHB0_FIQ_PRIORITY_EN |= INT_STATUS_GPIO; GpioIntHandleCbCfg((GPIO_INT_HANDLE_CB_PFN)&ir_callback); } void t_ir_check(uint32_t current_clk) { if( current_clk > ir_check_clock && ir_check_clock > 0) { ir_check_clock = 0; clean_ir_status(); } } #endif