/*
这段代码是一个用于蓝牙键盘的固件,主要用于处理键盘扫描、按键事件、蓝牙连接、电池监控以及RGB LED和PWM LED的更新。以下是详细的代码功能解释:
1. **初始化配置**:`setupConfig`函数初始化键盘的配置,包括LED状态、连接模式、电池监控等。`loadConfig`函数加载存储在Flash中的配置信息,如果没有找到有效配置,将调用`resetConfig`函数进行重置并保存新配置。
2. **键盘扫描**:`scanMatrix`函数负责扫描键盘矩阵,检测按键的按下和释放事件,并将这些事件转换为键盘报告。
3. **按键处理**:`process_user_macros`和`process_keyboard_function`函数处理用户的宏和键盘功能键。`process_user_special_keys`函数处理特殊的按键事件。
4. **通信**:`sendKeyPresses`函数负责将键盘报告发送到连接的计算机或其他设备。`sendlayer`函数发送当前键盘层信息。
5. **电池监控**:`batterymonitor`类用于监控电池状态,包括电压、百分比和类型。
6. **RGB LED和PWM LED**:`updateRGB`和`updatePWM`函数用于更新RGB LED和PWM LED的状态。
7. **主循环**:`loop`函数是固件的主循环,负责执行各种任务,包括更新蓝牙连接状态、电池状态、RGB LED和PWM LED状态,以及发送键盘报告。
8. **空闲任务**:`vApplicationIdleHook`函数是FreeRTOS的空闲任务,用于在没有其他任务执行时降低设备的功耗。
9. **其他任务**:`keyscantimer_callback`函数是键盘扫描计时器的回调函数,负责扫描键盘和发送键盘报告。`batterytimer_callback`函数是电池计时器的回调函数,用于更新电池状态,但在这个代码中已被注释掉。`NormalPriorityloop`和`LowestPriorityloop`是优先级不同的循环,用于执行不同优先级的任务。
注意,这段代码使用了一些自定义的宏和函数,如`EXPAND_ALT_CODE`,它们可能是用来扩展特殊按键组合的。此外,代码中使用了`cppcheck-suppress`注释,用于抑制某些cppcheck的警告,这可能表明某些函数或代码段是故意被忽略的。
*/
/**************************************************************************************************************************/
#include <Arduino.h>
#include <bluefruit.h>
#include "firmware.h"
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>
/**************************************************************************************************************************/
byte rows[] MATRIX_ROW_PINS; // Contains the GPIO Pin Numbers defined in keyboard_config.h
byte columns[] MATRIX_COL_PINS; // Contains the GPIO Pin Numbers defined in keyboard_config.h
SoftwareTimer keyscantimer, batterytimer;
using namespace Adafruit_LittleFS_Namespace;
#define SETTINGS_FILE "/settings"
File file(InternalFS);
PersistentState keyboardconfig;
DynamicState keyboardstate;
#ifdef ENABLE_AUDIO
BlueMicro_tone speaker(&keyboardconfig, &keyboardstate); /// A speaker to play notes and tunes...
#endif
led_handler statusLEDs(&keyboardconfig, &keyboardstate); /// Typically a Blue LED and a Red LED
#ifdef BLUEMICRO_CONFIGURED_DISPLAY
BlueMicro_Display OLED(&keyboardconfig, &keyboardstate); /// Typically a Blue LED and a Red LED
#endif
KeyScanner keys(&keyboardconfig, &keyboardstate);
Battery batterymonitor;
static std::vector<uint16_t> stringbuffer; // buffer for macros to type into...
static std::vector<HIDKeyboard> reportbuffer;
/**************************************************************************************************************************/
void setupConfig() {
InternalFS.begin();
loadConfig();
keyboardstate.statusble=0; //initialize to a known state.
keyboardstate.statuskb=0; //initialize to a known state.
keyboardstate.user1=0; //initialize to a known state.
keyboardstate.user2=0; //initialize to a known state.
keyboardstate.user3=0; //initialize to a known state.
keyboardstate.helpmode = false;
keyboardstate.timestamp = millis();
keyboardstate.lastupdatetime = keyboardstate.timestamp;
keyboardstate.lastreporttime = 0;
keyboardstate.lastuseractiontime = 0;
keyboardstate.connectionState = CONNECTION_NONE;
keyboardstate.needReset = false;
keyboardstate.needUnpair = false;
keyboardstate.needFSReset = false;
keyboardstate.save2flash = false;
}
/**************************************************************************************************************************/
void loadConfig()
{
file.open(SETTINGS_FILE, FILE_O_READ);
if(file)
{
file.read(&keyboardconfig, sizeof(keyboardconfig));
file.close();
}
else
{
resetConfig();
saveConfig();
}
if (keyboardconfig.version != BLUEMICRO_CONFIG_VERSION) // SETTINGS_FILE format changed. we need to reset and re-save it.
{
resetConfig();
saveConfig();
}
}
/**************************************************************************************************************************/
void resetConfig()
{
keyboardconfig.version=BLUEMICRO_CONFIG_VERSION;
keyboardconfig.pinPWMLED=BACKLIGHT_LED_PIN;
keyboardconfig.pinRGBLED=WS2812B_LED_PIN;
keyboardconfig.pinBLELED=STATUS_BLE_LED_PIN;
keyboardconfig.pinKBLED=STATUS_KB_LED_PIN;
keyboardconfig.enablePWMLED=BACKLIGHT_PWM_ON;
keyboardconfig.enableRGBLED=WS2812B_LED_ON;
keyboardconfig.enableBLELED=BLE_LED_ACTIVE;
keyboardconfig.enableKBLED=STATUS_KB_LED_ACTIVE;
keyboardconfig.polarityBLELED=BLE_LED_POLARITY;
keyboardconfig.polarityKBLED=STATUS_KB_LED_POLARITY;
keyboardconfig.enableVCCSwitch=VCC_ENABLE_GPIO;
keyboardconfig.polarityVCCSwitch=VCC_DEFAULT_ON;
keyboardconfig.enableChargerControl=VCC_ENABLE_CHARGER;
keyboardconfig.polarityChargerControl=true;
#ifdef BLUEMICRO_CONFIGURED_DISPLAY
keyboardconfig.enableDisplay = true;// enabled if it's compiled with one...
#else
keyboardconfig.enableDisplay = false;// disabled if it's not compiled with one...
#endif
#ifdef SPEAKER_PIN
keyboardconfig.enableAudio = true;// enabled if it's compiled with one...
#else
keyboardconfig.enableAudio = false;// disabled if it's not compiled with one...
#endif
keyboardconfig.enableSerial = SERIAL_DEBUG_CLI_DEFAULT_ON;
keyboardconfig.mode = 0;
keyboardconfig.user1 = 0;
keyboardconfig.user2 = 0;
keyboardconfig.matrixscaninterval=HIDREPORTINGINTERVAL;
keyboardconfig.batteryinterval=BATTERYINTERVAL;
keyboardconfig.keysendinterval=HIDREPORTINGINTERVAL;
keyboardconfig.lowpriorityloopinterval=LOWPRIORITYLOOPINTERVAL;
keyboardconfig.lowestpriorityloopinterval = HIDREPORTINGINTERVAL*2;
keyboardconfig.connectionMode = CONNECTION_MODE_AUTO;
keyboardconfig.BLEProfile = 0;
keyboardconfig.BLEProfileEdiv[0] = 0xFFFF;
keyboardconfig.BLEProfileEdiv[1] = 0xFFFF;
keyboardconfig.BLEProfileEdiv[2] = 0xFFFF;
memset(keyboardconfig.BLEProfileAddr[0], 0, 6);
memset(keyboardconfig.BLEProfileAddr[1], 0, 6);
memset(keyboardconfig.BLEProfileAddr[2], 0, 6);
strcpy(keyboardconfig.BLEProfileName[0], "unpaired");
strcpy(keyboardconfig.BLEProfileName[1], "unpaired");
strcpy(keyboardconfig.BLEProfileName[2], "unpaired");
}
/**************************************************************************************************************************/
void saveConfig()
{
InternalFS.remove(SETTINGS_FILE);
if (file.open(SETTINGS_FILE, FILE_O_WRITE))
{
file.write((uint8_t*)&keyboardconfig, sizeof(keyboardconfig));
file.close();
}
}
/**************************************************************************************************************************/
/**************************************************************************************************************************/
void setup() {
usb_setup(); // does nothing for 832 - see usb.
没有合适的资源?快使用搜索试试~ 我知道了~
(源码)基于BlueMicroBLE框架的自定义键盘固件构建系统.zip
共304个文件
h:175个
cpp:119个
ino:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 10 浏览量
2024-11-18
10:27:46
上传
评论
收藏 744KB ZIP 举报
温馨提示
# 基于BlueMicroBLE框架的自定义键盘固件构建系统 ## 项目简介 ## 项目的主要特性和功能 多硬件支持支持nRF52832和nRF52840两种硬件平台,用户可以根据自己的需求选择合适的硬件配置。 键盘功能定制用户可以自定义键盘布局和功能,包括按键处理、蓝牙和USB通信、电池监控、RGB LED和PWM LED的控制等。 调试与错误记录项目包含调试和错误信息记录功能,帮助开发者理解和解决潜在问题。 ## 安装使用步骤 ### 首次使用初始化固件 进入仓库的“Settings”。 找到“Actions”部分,选择“Allow all actions”。 3. 编辑工作流文件 修改以下条目 keyboard: ['4x4Tutorials'] keymap: ['base'] keyboardconfig: ['single']
资源推荐
资源详情
资源评论
收起资源包目录
(源码)基于BlueMicroBLE框架的自定义键盘固件构建系统.zip (304个子文件)
firmware_main.cpp 53KB
firmware_main.cpp 53KB
firmware_main.cpp 53KB
firmware_main.cpp 52KB
firmware_main.cpp 52KB
firmware_main.cpp 52KB
firmware_main.cpp 52KB
bluetooth.cpp 29KB
bluetooth.cpp 29KB
bluetooth.cpp 29KB
bluetooth.cpp 29KB
bluetooth.cpp 29KB
bluetooth.cpp 29KB
bluetooth.cpp 29KB
KeyScanner.cpp 20KB
KeyScanner.cpp 20KB
KeyScanner.cpp 20KB
KeyScanner.cpp 20KB
KeyScanner.cpp 20KB
KeyScanner.cpp 20KB
KeyScanner.cpp 19KB
combo_engine.cpp 18KB
debug_cli.cpp 17KB
BlueMicro_tone.cpp 17KB
BlueMicro_tone.cpp 16KB
debug_cli.cpp 16KB
debug_cli.cpp 15KB
usb.cpp 15KB
debug_cli.cpp 15KB
debug_cli.cpp 15KB
debug_cli.cpp 15KB
debug_cli.cpp 15KB
combo_engine.cpp 13KB
nrf52battery.cpp 13KB
keymap.cpp 12KB
combo_engine.cpp 12KB
combo_engine.cpp 12KB
combo_engine.cpp 12KB
combo_engine.cpp 12KB
nrf52battery.cpp 11KB
combo_engine.cpp 11KB
nrf52battery.cpp 11KB
nrf52battery.cpp 11KB
nrf52battery.cpp 11KB
nrf52battery.cpp 11KB
usb.cpp 11KB
keymap.cpp 11KB
nrf52battery.cpp 10KB
BlueMicro_display.cpp 10KB
BlueMicro_display.cpp 10KB
BlueMicro_display.cpp 9KB
LedPwm.cpp 9KB
BlueMicro_display.cpp 9KB
BlueMicro_display.cpp 8KB
nrf52gpio.cpp 8KB
BlueMicro_display.cpp 8KB
BlueMicro_display.cpp 8KB
nrf52gpio.cpp 8KB
keymap.cpp 8KB
nrf52gpio.cpp 8KB
nrf52gpio.cpp 8KB
nrf52gpio.cpp 8KB
nrf52gpio.cpp 8KB
nrf52gpio.cpp 7KB
sleep.cpp 7KB
LedRGB.cpp 7KB
usb.cpp 7KB
LedPwm.cpp 6KB
BlueMicro_tone.cpp 6KB
LedPwm.cpp 6KB
LedPwm.cpp 6KB
LedRGB.cpp 6KB
usb.cpp 6KB
BlueMicro_tone.cpp 6KB
LedRGB.cpp 6KB
usb.cpp 6KB
LedPwm.cpp 6KB
Key.cpp 6KB
LedPwm.cpp 6KB
LedPwm.cpp 5KB
LedRGB.cpp 5KB
LedRGB.cpp 5KB
HID.cpp 5KB
HID.cpp 5KB
BlueMicro_tone.cpp 5KB
Key.cpp 5KB
LedRGB.cpp 5KB
LedRGB.cpp 5KB
Key.cpp 5KB
usb.cpp 5KB
Key.cpp 5KB
Key.cpp 5KB
BlueMicro_tone.cpp 5KB
usb.cpp 5KB
BlueMicro_tone.cpp 5KB
Key.cpp 5KB
HID.cpp 5KB
HID.cpp 5KB
sleep.cpp 5KB
Key.cpp 5KB
共 304 条
- 1
- 2
- 3
- 4
资源评论
t0_54coder
- 粉丝: 2410
- 资源: 3444
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功