key_obj input_key[CLICK_KEY_NUM]; __attribute__((section(".highcode"))) uint8_t key1_read(void) { return IN1_READ(); } __attribute__((section(".highcode"))) uint8_t key2_read(void) { return IN1_READ(); } __attribute__((section(".highcode"))) uint8_t key3_read(void) { return IN1_READ(); } __attribute__((section(".highcode"))) uint8_t key4_read(void) { return IN1_READ(); } __attribute__((section(".highcode"))) uint8_t key5_read(void) { return IN1_READ(); } void *key_read_func[CLICK_KEY_NUM] = {key1_read,key2_read,key3_read,key4_read,key5_read}; static void key_obj_init(key_obj *obj, uint8_t key_cnt) { uint8_t i; for(i = 0; i < key_cnt; i ++) { (*(obj + i)).act_level = ACTIVE_LEVEL_HIGH; (*(obj + i)).cnts = 0; (*(obj + i)).code = CODE_NONE; (*(obj + i)).cur_status = 0; (*(obj + i)).key_read = key_read_func[i]; } }
中断读取
__attribute__((section(".highcode"))) void button_obj_handle(key_obj *obj, uint8_t key_cnt) { uint8_t i; for(i = 0; i < key_cnt; i ++) { if((*(obj + i)).cur_status == 0) { if(((*(obj + i)).key_read) == (*(obj + i)).act_level) { (*(obj + i)).cur_status = 1; } } else if((*(obj + i)).cur_status == 1) { if(((*(obj + i)).key_read) == (*(obj + i)).act_level) { (*(obj + i)).cur_status = 2; } else { (*(obj + i)).cur_status = 0; } (*(obj + i)).cnts = 0; } } }
十几测试读不到正确的电平,不清楚是不是编译器或者语法问题
热门产品 :
CH339: 7端口多功能USB HUB控制器芯片