Skip to content

Commit

Permalink
Merge pull request #11 from m5stack/dev_ble_keyboard
Browse files Browse the repository at this point in the history
Add App Keyboard
  • Loading branch information
Forairaaaaa authored Dec 13, 2023
2 parents 72ff4ae + 16518eb commit b0c678d
Show file tree
Hide file tree
Showing 34 changed files with 4,505 additions and 69 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cmake_minimum_required(VERSION 3.16)
# add_definitions(-DMC_USE_CUSTOM_CONF)
# add_definitions(-DNO_BOOT_PLAY_SHIT)

include_directories(./main/apps/utils/usb_keyboard_wrap/hid_device)


include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(cardputer)
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ template <typename... Args>
FMT_CONSTEXPR FMT_INLINE void init_named_args(std::nullptr_t, int, int,
const Args&...) {}

#undef B1

template <bool B = false> constexpr auto count() -> size_t { return B ? 1 : 0; }
template <bool B1, bool B2, bool... Tail> constexpr auto count() -> size_t {
return (B1 ? 1 : 0) + count<B2, Tail...>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,8 @@ template <typename F> struct basic_fp {

using fp = basic_fp<unsigned long long>;

#undef F

// Normalizes the value converted from double and multiplied by (1 << SHIFT).
template <int SHIFT = 0, typename F>
FMT_CONSTEXPR basic_fp<F> normalize(basic_fp<F> value) {
Expand Down
12 changes: 9 additions & 3 deletions dependencies.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dependencies:
espressif/cmake_utilities:
component_hash: c3f351bed6fdb3d91bee6076740cb13d22e2c7bfcdd78969a65b46943885bbd4
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
source:
service_url: https://api.components.espressif.com/
type: service
version: 0.5.2
version: 0.5.3
espressif/esp-now:
component_hash: 7355037518944af5d0ea20fe48aa0a8cf82081599b6fbd83f086ee8b39df87c1
source:
Expand All @@ -16,6 +16,12 @@ dependencies:
source:
type: idf
version: 4.4.6
manifest_hash: 4152ab7064ca9cbbd8d1d8f29a55ce717a41aec30188ca3c34b7db8227f03084
leeebo/tinyusb_src:
component_hash: 117cb2432654d6f194e0a9a47f87e5f3143312c8b4897601d7b3b9651757734f
source:
service_url: https://api.components.espressif.com/
type: service
version: 0.15.0~7
manifest_hash: b6597783385c4b38496cd80e4e82d7c706daa89f68f0c09c37f36971218c34c5
target: esp32s3
version: 1.0.0
7 changes: 7 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ set(PIKA_PYTHON_INCS
./apps/app_repl/pikapython/pikascript-core/
)



idf_component_register(SRCS "cardputer.cpp" ${APPS_SRCS} ${HAL_SRCS}
INCLUDE_DIRS "." "./hal" ${PIKA_PYTHON_INCS})


idf_component_get_property(tusb_lib leeebo__tinyusb_src COMPONENT_LIB)
cmake_policy(SET CMP0079 NEW)
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})
26 changes: 26 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
menu "USB HID Device Example"

choice HID_SUBCLASS
prompt "HID Device"
default SUBCLASS_MOUSE

config SUBCLASS_MOUSE
bool "Mouse"
config SUBCLASS_KEYBOARD
bool "Keyboard"
endchoice

config TUSB_VID
hex "USB Device VID"
default 0x303A
config TUSB_PID
hex "USB Device PID"
default 0x8000
config TUSB_MANUFACTURER
string "USB Device Manufacture"
default "Espressif"
config TUSB_PRODUCT
string "Product Name"
default "HID Demo"

endmenu
103 changes: 103 additions & 0 deletions main/apps/app_keyboard/app_keyboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @file app_keyboard.cpp
* @author Forairaaaaa
* @brief
* @version 0.1
* @date 2023-12-07
*
* @copyright Copyright (c) 2023
*
*/
#include "app_keyboard.h"
#include "spdlog/spdlog.h"
#include "../utils/wifi_common_test/wifi_common_test.h"
#include "../utils/theme/theme_define.h"


using namespace MOONCAKE::APPS;


// #define TEST_USE_BLE
// #define TEST_USE_USB


void AppKeyboard::onCreate()
{
spdlog::info("{} onCreate", getAppName());

// Get hal
_data.hal = mcAppGetDatabase()->Get("HAL")->value<HAL::Hal *>();
}


void AppKeyboard::onResume()
{
ANIM_APP_OPEN();

{
_data.hal->canvas()->fillScreen(THEME_COLOR_BG);
_data.hal->canvas()->setFont(FONT_REPL);
_data.hal->canvas()->setTextColor(TFT_ORANGE, THEME_COLOR_BG);
_data.hal->canvas()->setTextSize(1);
_data.hal->canvas_update();

// Start ble keyboard
spdlog::info("remain before: {}", uxTaskGetStackHighWaterMark(NULL));
}

_select_kb_type();

// #ifdef TEST_USE_BLE
// _ble_kb_init();
// #endif
// #ifdef TEST_USE_USB
// _usb_kb_init();
// #endif

if (_data.kb_type == kb_type_ble)
_ble_kb_init();
else if (_data.kb_type == kb_type_usb)
_usb_kb_init();
}


void AppKeyboard::onRunning()
{
if (_data.hal->homeButton()->pressed())
{
_data.hal->playNextSound();
spdlog::info("quit app {}", getAppName());
destroyApp();
}

// #ifdef TEST_USE_BLE
// _ble_kb_update_infos();
// _ble_kb_update_kb_input();
// #endif
// #ifdef TEST_USE_USB
// _usb_kb_update_infos();
// _usb_kb_update_kb_input();
// #endif

if (_data.kb_type == kb_type_ble)
{
_ble_kb_update_infos();
_ble_kb_update_kb_input();
}
else if (_data.kb_type == kb_type_usb)
{
_usb_kb_update_infos();
_usb_kb_update_kb_input();
}
}


void AppKeyboard::onDestroy()
{
spdlog::info("{} onDestroy", getAppName());
// ble_keyboard_wrap_deinit();

delay(200);
esp_restart();
delay(10000);
}
66 changes: 66 additions & 0 deletions main/apps/app_keyboard/app_keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @file app_keyboard.h
* @author Forairaaaaa
* @brief
* @version 0.1
* @date 2023-12-07
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include <mooncake.h>
#include "../../hal/hal.h"
#include "../utils/theme/theme_define.h"
#include "../utils/anim/anim_define.h"
#include "../utils/icon/icon_define.h"

#include "assets/keyboard_big.h"
#include "assets/keyboard_small.h"


namespace MOONCAKE
{
namespace APPS
{
class AppKeyboard : public APP_BASE
{
private:
enum KeyboardType_t
{
kb_type_ble = 0,
kb_type_usb,
};

struct Data_t
{
HAL::Hal* hal = nullptr;
uint32_t update_infos_time_count = 0;
uint32_t update_kb_time_count = 0;
KeyboardType_t kb_type = kb_type_ble;
};
Data_t _data;
void _select_kb_type();
void _ble_kb_init();
void _ble_kb_update_infos();
void _ble_kb_update_kb_input();
void _usb_kb_init();
void _usb_kb_update_infos();
void _usb_kb_update_kb_input();

public:
void onCreate() override;
void onResume() override;
void onRunning() override;
void onDestroy() override;
};

class AppKeyboard_Packer : public APP_PACKER_BASE
{
std::string getAppName() override { return "KEYBOARD"; }
void* getAppIcon() override { return (void*)(new AppIcon_t(image_data_keyboard_big, image_data_keyboard_small)); }
void* newApp() override { return new AppKeyboard; }
void deleteApp(void *app) override { delete (AppKeyboard*)app; }
};
}
}
Loading

0 comments on commit b0c678d

Please sign in to comment.