代码拉取完成,页面将自动刷新
同步操作将从 wei/key_board 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "key_board/key_board_sample.h"
struct key_pin_t {
GPIO_TypeDef *port;
uint16_t pin;
GPIO_PinState valid;
GPIO_PinState invalid;
};
const struct key_pin_t key_pin_sig[] = {
{
.port = KEY_PORT_J12,
.pin = KEY_PIN_J12,
.valid = KEY_PRESS_LEVEL_J12,
.invalid = KEY_RELEASE_LEVEL_J12
},
{
.port = KEY_PORT_J34,
.pin = KEY_PIN_J34,
.valid = KEY_PRESS_LEVEL_J34,
.invalid = KEY_RELEASE_LEVEL_J34
},
};
#if (USER_KEY_BOARD_MATRIX)
const struct key_pin_t key_pin_ctrl[] = {
{
.port = KEY_PORT_J135,
.pin = KEY_PIN_J135,
.valid = KEY_CTL_LINE_ENABLE,
.invalid = KEY_CTL_LINE_DISABLE
},
{
.port = KEY_PORT_J246,
.pin = KEY_PIN_J246,
.valid = KEY_CTL_LINE_ENABLE,
.invalid = KEY_CTL_LINE_DISABLE
},
};
#endif
static inline bool pin_level_get(const void *desc)
{
struct key_pin_t *pdesc;
pdesc = (struct key_pin_t *)desc;
return HAL_GPIO_ReadPin(pdesc->port, pdesc->pin) == pdesc->valid;
}
#if (USER_KEY_BOARD_MATRIX)
static inline void pin_level_set(const void *desc, bool flag)
{
struct key_pin_t *pdesc;
pdesc = (struct key_pin_t *)desc;
HAL_GPIO_WritePin(pdesc->port, pdesc->pin, flag ? pdesc->valid : pdesc->invalid);
}
#endif
const struct key_public_sig_t key_public_sig[] = {
KEY_PUBLIC_SIG_DEF(KEY_UP, &key_pin_sig[0], pin_level_get, KEY_FLAG_PRESS_CONTINUOUS | KEY_FLAG_PRESS_LONG | KEY_FLAG_RELEASE_LONG | KEY_FLAG_PRESS_MULTI | KEY_FLAG_RELEASE_MULTI),
KEY_PUBLIC_SIG_DEF(KEY_DOWN, &key_pin_sig[1], pin_level_get, KEY_FLAG_PRESS_CONTINUOUS | KEY_FLAG_PRESS_LONG | KEY_FLAG_RELEASE_LONG | KEY_FLAG_PRESS_MULTI | KEY_FLAG_RELEASE_MULTI),
#if (USER_KEY_BOARD_MATRIX)
KEY_PUBLIC_SIG_DEF(KEY_LEFT, &key_pin_sig[0], pin_level_get, KEY_FLAG_PRESS_CONTINUOUS | KEY_FLAG_PRESS_LONG | KEY_FLAG_RELEASE_LONG | KEY_FLAG_PRESS_MULTI | KEY_FLAG_RELEASE_MULTI),
KEY_PUBLIC_SIG_DEF(KEY_RIGHT, &key_pin_sig[1], pin_level_get, KEY_FLAG_PRESS_CONTINUOUS | KEY_FLAG_PRESS_LONG | KEY_FLAG_RELEASE_LONG | KEY_FLAG_PRESS_MULTI | KEY_FLAG_RELEASE_MULTI)
#endif
};
#if (USER_KEY_BOARD_MATRIX)
const struct key_public_ctrl_t key_public_ctrl[] = {
KEY_PUBLIC_CTRL_DEF(&key_pin_ctrl[0], pin_level_set),
KEY_PUBLIC_CTRL_DEF(&key_pin_ctrl[1], pin_level_set),
};
#endif
/*按键 GPIO 初始化*/
void GPIO_Key_Board_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
unsigned int i;
RCC_KEY_BOARD_CLK_ENABLE();
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
for(i = 0;i < GET_ARRAY_SIZE(key_pin_sig);i++)
{
GPIO_InitStruct.Pin = key_pin_sig[i].pin;
HAL_GPIO_Init(key_pin_sig[i].port, &GPIO_InitStruct);
}
#if (USER_KEY_BOARD_MATRIX)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
for(i = 0;i < GET_ARRAY_SIZE(key_pin_ctrl);i++)
{
GPIO_InitStruct.Pin = key_pin_ctrl[i].pin;
HAL_GPIO_Init(key_pin_ctrl[i].port, &GPIO_InitStruct);
}
#endif
key_board_init();
#if (USER_KEY_BOARD_MATRIX)
key_board_register(KEY_BOARD_MATRIX, key_public_sig, GET_ARRAY_SIZE(key_public_sig), key_public_ctrl, GET_ARRAY_SIZE(key_public_ctrl));
#else
key_board_register(KEY_BOARD_NORMAL, key_public_sig, GET_ARRAY_SIZE(key_public_sig), NULL, 0);
#endif
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。