46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include "Key.h"
|
||
|
||
#include <../2025_include_user/Host.h>
|
||
|
||
Key::KeyData Key::keys[] = {
|
||
{KEY1, Key_Key1_PORT, Key_Key1_PIN, 0},
|
||
{KEY2, Key_Key2_PORT, Key_Key2_PIN, 0},
|
||
{KEY3, Key_Key3_PORT, Key_Key3_PIN, 0},
|
||
{KEY4, Key_Key4_PORT, Key_Key4_PIN, 0},
|
||
};
|
||
|
||
// extern "C" {
|
||
// void vKeyTask(void *pvParameters) {
|
||
// while (true) {
|
||
// for (uint8_t i = 0; i < (sizeof(Key::keys) / sizeof(Key::keys[0])); i++) {
|
||
// if (DL_GPIO_readPins(Key::keys[i].port, Key::keys[i].pin) == 0) {
|
||
// // print("Key%d: %d\r\n", i, 1);
|
||
// Key::keys[i].state = 1;
|
||
// } else {
|
||
// // print("Key%d: %d\r\n", i, 0);
|
||
// Key::keys[i].state = 0;
|
||
// }
|
||
// }
|
||
//
|
||
// vTaskDelay(pdMS_TO_TICKS(1)); // 每10ms检测一次按键,释放CPU
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
void Key::init() {
|
||
// xTaskCreate(vKeyTask, "vKeyTask", 32, nullptr, 1, nullptr);
|
||
NVIC_EnableIRQ(Key_GPIOA_INT_IRQN);
|
||
NVIC_EnableIRQ(GPIO_MULTIPLE_GPIOB_INT_IRQN);
|
||
}
|
||
|
||
uint8_t Key::getState(const uint8_t id) {
|
||
const uint8_t state = keys[id].state;
|
||
keys[id].state = 0;
|
||
return state;
|
||
}
|
||
|
||
void Key::setState(const uint8_t id, const uint8_t state) {
|
||
keys[id].state = state;
|
||
}
|
||
|