mirror of
https://github.com/NathanReeves/BlueCubeMod
synced 2024-11-23 01:22:16 -05:00
Merge pull request #6 from MangaValk/master
fixed v2 firmware to work using latest esp_idf
This commit is contained in:
commit
cc2aa07256
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
Firmware/BlueCubeModv2/build/
|
||||||
|
7
Firmware/BlueCubeModv2/CMakeLists.txt
Normal file
7
Firmware/BlueCubeModv2/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
# The following lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(BlueCubeModv2)
|
2
Firmware/BlueCubeModv2/main/CMakeLists.txt
Normal file
2
Firmware/BlueCubeModv2/main/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
idf_component_register(SRCS "main.c"
|
||||||
|
INCLUDE_DIRS "")
|
@ -4,6 +4,9 @@
|
|||||||
//
|
//
|
||||||
// Created by Nathan Reeves 2019
|
// Created by Nathan Reeves 2019
|
||||||
//
|
//
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include "esp_spi_flash.h"
|
||||||
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_hidd_api.h"
|
#include "esp_hidd_api.h"
|
||||||
@ -61,6 +64,11 @@ static uint8_t cy_send = 0;
|
|||||||
static uint8_t lt_send = 0;
|
static uint8_t lt_send = 0;
|
||||||
static uint8_t rt_send = 0;
|
static uint8_t rt_send = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//static esp_hidd_callbacks_t callbacks;
|
||||||
|
static esp_hidd_app_param_t app_param;
|
||||||
|
static esp_hidd_qos_param_t both_qos;
|
||||||
|
|
||||||
//RMT Transmitter Init - for reading GameCube controller
|
//RMT Transmitter Init - for reading GameCube controller
|
||||||
rmt_item32_t items[25];
|
rmt_item32_t items[25];
|
||||||
rmt_config_t rmt_tx;
|
rmt_config_t rmt_tx;
|
||||||
@ -409,6 +417,12 @@ static uint8_t emptyReport[] = {
|
|||||||
|
|
||||||
void send_buttons()
|
void send_buttons()
|
||||||
{
|
{
|
||||||
|
// // test
|
||||||
|
// if(but1_send == 0)
|
||||||
|
// but1_send = 0x02; // X
|
||||||
|
// else
|
||||||
|
// but1_send = 0;
|
||||||
|
|
||||||
xSemaphoreTake(xSemaphore, portMAX_DELAY);
|
xSemaphoreTake(xSemaphore, portMAX_DELAY);
|
||||||
report30[1] = timer;
|
report30[1] = timer;
|
||||||
//buttons
|
//buttons
|
||||||
@ -431,12 +445,12 @@ void send_buttons()
|
|||||||
if(!paired)
|
if(!paired)
|
||||||
{
|
{
|
||||||
emptyReport[1] = timer;
|
emptyReport[1] = timer;
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(emptyReport), emptyReport);
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(emptyReport), emptyReport);
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(report30), report30);
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(report30), report30);
|
||||||
vTaskDelay(15);
|
vTaskDelay(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,26 +558,6 @@ void send_task(void* pvParameters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback for notifying when hidd application is registered or not registered
|
|
||||||
void application_cb(esp_bd_addr_t bd_addr, esp_hidd_application_state_t state) {
|
|
||||||
const char* TAG = "application_cb";
|
|
||||||
|
|
||||||
switch(state) {
|
|
||||||
case ESP_HIDD_APP_STATE_NOT_REGISTERED:
|
|
||||||
ESP_LOGI(TAG, "app not registered");
|
|
||||||
break;
|
|
||||||
case ESP_HIDD_APP_STATE_REGISTERED:
|
|
||||||
ESP_LOGI(TAG, "app is now registered!");
|
|
||||||
if(bd_addr == NULL) {
|
|
||||||
ESP_LOGI(TAG, "bd_addr is null...");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ESP_LOGW(TAG, "unknown app state %i", state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//LED blink
|
//LED blink
|
||||||
void startBlink()
|
void startBlink()
|
||||||
{
|
{
|
||||||
@ -579,171 +573,6 @@ void startBlink()
|
|||||||
}
|
}
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
// callback for hidd connection changes
|
|
||||||
void connection_cb(esp_bd_addr_t bd_addr, esp_hidd_connection_state_t state) {
|
|
||||||
const char* TAG = "connection_cb";
|
|
||||||
|
|
||||||
switch(state) {
|
|
||||||
case ESP_HIDD_CONN_STATE_CONNECTED:
|
|
||||||
ESP_LOGI(TAG, "connected to %02x:%02x:%02x:%02x:%02x:%02x",
|
|
||||||
bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
|
|
||||||
ESP_LOGI(TAG, "setting bluetooth non connectable");
|
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
|
|
||||||
|
|
||||||
//clear blinking LED - solid
|
|
||||||
vTaskDelete(BlinkHandle);
|
|
||||||
BlinkHandle = NULL;
|
|
||||||
gpio_set_level(LED_GPIO, 1);
|
|
||||||
//start solid
|
|
||||||
xSemaphoreTake(xSemaphore, portMAX_DELAY);
|
|
||||||
connected = true;
|
|
||||||
xSemaphoreGive(xSemaphore);
|
|
||||||
//restart send_task
|
|
||||||
if(SendingHandle != NULL)
|
|
||||||
{
|
|
||||||
vTaskDelete(SendingHandle);
|
|
||||||
SendingHandle = NULL;
|
|
||||||
}
|
|
||||||
xTaskCreatePinnedToCore(send_task, "send_task", 2048, NULL, 2, &SendingHandle, 0);
|
|
||||||
break;
|
|
||||||
case ESP_HIDD_CONN_STATE_CONNECTING:
|
|
||||||
ESP_LOGI(TAG, "connecting");
|
|
||||||
break;
|
|
||||||
case ESP_HIDD_CONN_STATE_DISCONNECTED:
|
|
||||||
xTaskCreate(startBlink, "blink_task", 1024, NULL, 1, &BlinkHandle);
|
|
||||||
//start blink
|
|
||||||
ESP_LOGI(TAG, "disconnected from %02x:%02x:%02x:%02x:%02x:%02x",
|
|
||||||
bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
|
|
||||||
ESP_LOGI(TAG, "making self discoverable");
|
|
||||||
paired = 0;
|
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
|
||||||
xSemaphoreTake(xSemaphore, portMAX_DELAY);
|
|
||||||
connected = false;
|
|
||||||
xSemaphoreGive(xSemaphore);
|
|
||||||
break;
|
|
||||||
case ESP_HIDD_CONN_STATE_DISCONNECTING:
|
|
||||||
ESP_LOGI(TAG, "disconnecting");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ESP_LOGI(TAG, "unknown connection status");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//callback for discovering
|
|
||||||
void get_device_cb()
|
|
||||||
{
|
|
||||||
ESP_LOGI("hi", "found a device");
|
|
||||||
}
|
|
||||||
|
|
||||||
// callback for when hid host requests a report
|
|
||||||
void get_report_cb(uint8_t type, uint8_t id, uint16_t buffer_size) {
|
|
||||||
const char* TAG = "get_report_cb";
|
|
||||||
ESP_LOGI(TAG, "got a get_report request from host");
|
|
||||||
}
|
|
||||||
|
|
||||||
// callback for when hid host sends a report
|
|
||||||
void set_report_cb(uint8_t type, uint8_t id, uint16_t len, uint8_t* p_data) {
|
|
||||||
const char* TAG = "set_report_cb";
|
|
||||||
ESP_LOGI(TAG, "got a report from host");
|
|
||||||
}
|
|
||||||
|
|
||||||
// callback for when hid host requests a protocol change
|
|
||||||
void set_protocol_cb(uint8_t protocol) {
|
|
||||||
const char* TAG = "set_protocol_cb";
|
|
||||||
ESP_LOGI(TAG, "got a set_protocol request from host");
|
|
||||||
}
|
|
||||||
|
|
||||||
// callback for when hid host sends interrupt data
|
|
||||||
void intr_data_cb(uint8_t report_id, uint16_t len, uint8_t* p_data) {
|
|
||||||
const char* TAG = "intr_data_cb";
|
|
||||||
//switch pairing sequence
|
|
||||||
if(len == 49)
|
|
||||||
{
|
|
||||||
if(p_data[10] == 2)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply02), reply02);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 8)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply08), reply08);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 0 && p_data[12] == 96)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1060), reply1060);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 80 && p_data[12] == 96)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1050), reply1050);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 3)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply03), reply03);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 4)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply04), reply04);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 128 && p_data[12] == 96)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1080), reply1080);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 152 && p_data[12] == 96)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1098), reply1098);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 16 && p_data[12] == 128)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1010), reply1010);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 61 && p_data[12] == 96)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply103D), reply103D);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 16 && p_data[11] == 32 && p_data[12] == 96)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1020), reply1020);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 64 && p_data[11] == 1)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply4001), reply4001);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 72 && p_data[11] == 1)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply4801), reply4801);
|
|
||||||
}
|
|
||||||
if(p_data[10] == 48 && p_data[11] == 1)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply3001), reply3001);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(p_data[10] == 33 && p_data[11] == 33)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply3333), reply3333);
|
|
||||||
paired = 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
if(p_data[10] == 64 && p_data[11] == 2)
|
|
||||||
{
|
|
||||||
esp_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply4001), reply4001);
|
|
||||||
}
|
|
||||||
//ESP_LOGI(TAG, "got an interrupt report from host, subcommand: %d %d %d Length: %d", p_data[10], p_data[11], p_data[12], len);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
//ESP_LOGI("heap size:", "%d", xPortGetFreeHeapSize());
|
|
||||||
//ESP_LOGI(TAG, "pairing packet size != 49, subcommand: %d %d %d Length: %d", p_data[10], p_data[11], p_data[12], len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// callback for when hid host does a virtual cable unplug
|
|
||||||
void vc_unplug_cb(void) {
|
|
||||||
const char* TAG = "vc_unplug_cb";
|
|
||||||
ESP_LOGI(TAG, "host did a virtual cable unplug");
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_bt_address()
|
void set_bt_address()
|
||||||
{
|
{
|
||||||
@ -819,7 +648,236 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void app_main() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void esp_bt_hidd_cb(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param)
|
||||||
|
{
|
||||||
|
static const char* TAG = "esp_bt_hidd_cb";
|
||||||
|
switch (event) {
|
||||||
|
case ESP_HIDD_INIT_EVT:
|
||||||
|
if (param->init.status == ESP_HIDD_SUCCESS) {
|
||||||
|
ESP_LOGI(TAG, "setting hid parameters");
|
||||||
|
esp_bt_hid_device_register_app(&app_param, &both_qos, &both_qos);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "init hidd failed!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_DEINIT_EVT:
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_REGISTER_APP_EVT:
|
||||||
|
if (param->register_app.status == ESP_HIDD_SUCCESS) {
|
||||||
|
ESP_LOGI(TAG, "setting hid parameters success!");
|
||||||
|
ESP_LOGI(TAG, "setting to connectable, discoverable");
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
if (param->register_app.in_use && param->register_app.bd_addr != NULL) {
|
||||||
|
ESP_LOGI(TAG, "start virtual cable plug!");
|
||||||
|
esp_bt_hid_device_connect(param->register_app.bd_addr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "setting hid parameters failed!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_UNREGISTER_APP_EVT:
|
||||||
|
if (param->unregister_app.status == ESP_HIDD_SUCCESS) {
|
||||||
|
ESP_LOGI(TAG, "unregister app success!");
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "unregister app failed!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_OPEN_EVT:
|
||||||
|
if (param->open.status == ESP_HIDD_SUCCESS) {
|
||||||
|
if (param->open.conn_status == ESP_HIDD_CONN_STATE_CONNECTING) {
|
||||||
|
ESP_LOGI(TAG, "connecting...");
|
||||||
|
} else if (param->open.conn_status == ESP_HIDD_CONN_STATE_CONNECTED) {
|
||||||
|
ESP_LOGI(TAG, "connected to %02x:%02x:%02x:%02x:%02x:%02x", param->open.bd_addr[0],
|
||||||
|
param->open.bd_addr[1], param->open.bd_addr[2], param->open.bd_addr[3], param->open.bd_addr[4],
|
||||||
|
param->open.bd_addr[5]);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "making self non-discoverable and non-connectable.");
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
|
||||||
|
|
||||||
|
|
||||||
|
//clear blinking LED - solid
|
||||||
|
vTaskDelete(BlinkHandle);
|
||||||
|
BlinkHandle = NULL;
|
||||||
|
gpio_set_level(LED_GPIO, 1);
|
||||||
|
//start solid
|
||||||
|
xSemaphoreTake(xSemaphore, portMAX_DELAY);
|
||||||
|
connected = true;
|
||||||
|
xSemaphoreGive(xSemaphore);
|
||||||
|
//restart send_task
|
||||||
|
if(SendingHandle != NULL)
|
||||||
|
{
|
||||||
|
vTaskDelete(SendingHandle);
|
||||||
|
SendingHandle = NULL;
|
||||||
|
}
|
||||||
|
xTaskCreatePinnedToCore(send_task, "send_task", 2048, NULL, 2, &SendingHandle, 0);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "unknown connection status");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "open failed!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_CLOSE_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_CLOSE_EVT");
|
||||||
|
if (param->close.status == ESP_HIDD_SUCCESS) {
|
||||||
|
if (param->close.conn_status == ESP_HIDD_CONN_STATE_DISCONNECTING) {
|
||||||
|
ESP_LOGI(TAG, "disconnecting...");
|
||||||
|
} else if (param->close.conn_status == ESP_HIDD_CONN_STATE_DISCONNECTED) {
|
||||||
|
ESP_LOGI(TAG, "disconnected!");
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "making self discoverable and connectable again.");
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
|
||||||
|
xTaskCreate(startBlink, "blink_task", 1024, NULL, 1, &BlinkHandle);
|
||||||
|
//start blink
|
||||||
|
xSemaphoreTake(xSemaphore, portMAX_DELAY);
|
||||||
|
connected = false;
|
||||||
|
xSemaphoreGive(xSemaphore);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "unknown connection status");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "close failed!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_SEND_REPORT_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_SEND_REPORT_EVT id:0x%02x, type:%d", param->send_report.report_id,
|
||||||
|
param->send_report.report_type);
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_REPORT_ERR_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_REPORT_ERR_EVT");
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_GET_REPORT_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_GET_REPORT_EVT id:0x%02x, type:%d, size:%d", param->get_report.report_id,
|
||||||
|
param->get_report.report_type, param->get_report.buffer_size);
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_SET_REPORT_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_SET_REPORT_EVT");
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_SET_PROTOCOL_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_SET_PROTOCOL_EVT");
|
||||||
|
if (param->set_protocol.protocol_mode == ESP_HIDD_BOOT_MODE) {
|
||||||
|
ESP_LOGI(TAG, " - boot protocol");
|
||||||
|
} else if (param->set_protocol.protocol_mode == ESP_HIDD_REPORT_MODE) {
|
||||||
|
ESP_LOGI(TAG, " - report protocol");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_INTR_DATA_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_INTR_DATA_EVT");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//switch pairing sequence
|
||||||
|
if(param->intr_data.len == 49)
|
||||||
|
{
|
||||||
|
if(param->intr_data.data[10] == 2)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply02), reply02);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 8)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply08), reply08);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 0 && param->intr_data.data[12] == 96)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1060), reply1060);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 80 && param->intr_data.data[12] == 96)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1050), reply1050);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 3)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply03), reply03);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 4)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply04), reply04);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 128 && param->intr_data.data[12] == 96)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1080), reply1080);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 152 && param->intr_data.data[12] == 96)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1098), reply1098);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 16 && param->intr_data.data[12] == 128)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1010), reply1010);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 61 && param->intr_data.data[12] == 96)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply103D), reply103D);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 16 && param->intr_data.data[11] == 32 && param->intr_data.data[12] == 96)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply1020), reply1020);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 64 && param->intr_data.data[11] == 1)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply4001), reply4001);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 72 && param->intr_data.data[11] == 1)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply4801), reply4801);
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 48 && param->intr_data.data[11] == 1)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply3001), reply3001);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(param->intr_data.data[10] == 33 && param->intr_data.data[11] == 33)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply3333), reply3333);
|
||||||
|
paired = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(param->intr_data.data[10] == 64 && param->intr_data.data[11] == 2)
|
||||||
|
{
|
||||||
|
esp_bt_hid_device_send_report(ESP_HIDD_REPORT_TYPE_INTRDATA, 0xa1, sizeof(reply4001), reply4001);
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "got an interrupt report from host, subcommand: %d %d %d Length: %d", param->intr_data.data[10], param->intr_data.data[11], param->intr_data.data[12], param->intr_data.len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI("heap size:", "%d", xPortGetFreeHeapSize());
|
||||||
|
ESP_LOGI(TAG, "pairing packet size != 49, subcommand: %d %d %d Length: %d", param->intr_data.data[10], param->intr_data.data[11], param->intr_data.data[12], param->intr_data.len);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_HIDD_VC_UNPLUG_EVT:
|
||||||
|
ESP_LOGI(TAG, "ESP_HIDD_VC_UNPLUG_EVT");
|
||||||
|
if (param->vc_unplug.status == ESP_HIDD_SUCCESS) {
|
||||||
|
if (param->close.conn_status == ESP_HIDD_CONN_STATE_DISCONNECTED) {
|
||||||
|
ESP_LOGI(TAG, "disconnected!");
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "making self discoverable and connectable again.");
|
||||||
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "unknown connection status");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "close failed!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void app_main(void);
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
//GameCube Contoller reading init
|
//GameCube Contoller reading init
|
||||||
rmt_tx_init();
|
rmt_tx_init();
|
||||||
rmt_rx_init();
|
rmt_rx_init();
|
||||||
@ -837,9 +895,6 @@ void app_main() {
|
|||||||
gpio_set_level(LED_GPIO, 0);
|
gpio_set_level(LED_GPIO, 0);
|
||||||
const char* TAG = "app_main";
|
const char* TAG = "app_main";
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
static esp_hidd_callbacks_t callbacks;
|
|
||||||
static esp_hidd_app_param_t app_param;
|
|
||||||
static esp_hidd_qos_param_t both_qos;
|
|
||||||
|
|
||||||
xSemaphore = xSemaphoreCreateMutex();
|
xSemaphore = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
@ -865,14 +920,6 @@ void app_main() {
|
|||||||
app_param.desc_list_len = hid_descriptor_gc_len;
|
app_param.desc_list_len = hid_descriptor_gc_len;
|
||||||
memset(&both_qos, 0, sizeof(esp_hidd_qos_param_t));
|
memset(&both_qos, 0, sizeof(esp_hidd_qos_param_t));
|
||||||
|
|
||||||
callbacks.application_state_cb = application_cb;
|
|
||||||
callbacks.connection_state_cb = connection_cb;
|
|
||||||
callbacks.get_report_cb = get_report_cb;
|
|
||||||
callbacks.set_report_cb = set_report_cb;
|
|
||||||
callbacks.set_protocol_cb = set_protocol_cb;
|
|
||||||
callbacks.intr_data_cb = intr_data_cb;
|
|
||||||
callbacks.vc_unplug_cb = vc_unplug_cb;
|
|
||||||
|
|
||||||
ret = nvs_flash_init();
|
ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
@ -905,20 +952,31 @@ void app_main() {
|
|||||||
ESP_LOGE(TAG, "enable bluedroid failed: %s\n", esp_err_to_name(ret));
|
ESP_LOGE(TAG, "enable bluedroid failed: %s\n", esp_err_to_name(ret));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_bt_gap_register_callback(esp_bt_gap_cb);
|
|
||||||
ESP_LOGI(TAG, "setting hid parameters");
|
|
||||||
esp_hid_device_register_app(&app_param, &both_qos, &both_qos);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "starting hid device");
|
if ((ret = esp_bt_gap_register_callback(esp_bt_gap_cb)) != ESP_OK) {
|
||||||
esp_hid_device_init(&callbacks);
|
ESP_LOGE(TAG, "gap register failed: %s\n", esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "setting device name");
|
ESP_LOGI(TAG, "setting device name");
|
||||||
esp_bt_dev_set_device_name("Pro Controller");
|
esp_bt_dev_set_device_name("Pro Controller");
|
||||||
|
|
||||||
ESP_LOGI(TAG, "setting to connectable, discoverable");
|
ESP_LOGI(TAG, "setting cod major, Pro Controller");
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
esp_bt_cod_t cod;
|
||||||
|
cod.major = 0x05;
|
||||||
|
cod.minor = 0b0000010;
|
||||||
|
esp_bt_gap_set_cod(cod,ESP_BT_SET_COD_MAJOR_MINOR );
|
||||||
|
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "register hid device callback");
|
||||||
|
esp_bt_hid_device_register_callback(esp_bt_hidd_cb);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "starting hid device");
|
||||||
|
esp_bt_hid_device_init();
|
||||||
|
|
||||||
//start blinking
|
//start blinking
|
||||||
xTaskCreate(startBlink, "blink_task", 1024, NULL, 1, &BlinkHandle);
|
xTaskCreate(startBlink, "blink_task", 1024, NULL, 1, &BlinkHandle);
|
||||||
|
|
||||||
|
print_bt_address();
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
0
Firmware/BlueCubeModv2/sdkconfig.ci
Normal file
0
Firmware/BlueCubeModv2/sdkconfig.ci
Normal file
7
Firmware/BlueCubeModv2/sdkconfig.defaults
Normal file
7
Firmware/BlueCubeModv2/sdkconfig.defaults
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
CONFIG_BT_ENABLED=y
|
||||||
|
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=n
|
||||||
|
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y
|
||||||
|
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||||
|
CONFIG_BT_CLASSIC_ENABLED=y
|
||||||
|
CONFIG_BT_HID_ENABLED=y
|
||||||
|
CONFIG_BT_HID_DEVICE_ENABLED=y
|
Loading…
Reference in New Issue
Block a user