Compare commits
No commits in common. "595e25466c9bed45036b4bfac040413f083d7b41" and "5ae607eec495755d4a7e66c32ad80c0403840ce3" have entirely different histories.
595e25466c
...
5ae607eec4
|
|
@ -4,4 +4,3 @@ sdkconfig.old
|
||||||
.espport
|
.espport
|
||||||
managed_components/
|
managed_components/
|
||||||
dependencies.lock
|
dependencies.lock
|
||||||
sdkconfig
|
|
||||||
|
|
|
||||||
4
Makefile
4
Makefile
|
|
@ -1,8 +1,6 @@
|
||||||
IDF_PATH := $(HOME)/.espressif/v6.0/esp-idf
|
IDF_PATH ?= $(HOME)/esp/esp-idf
|
||||||
PORT := $(or $(ESP_PORT),$(shell cat .espport 2>/dev/null),/dev/cu.usbmodem1101)
|
PORT := $(or $(ESP_PORT),$(shell cat .espport 2>/dev/null),/dev/cu.usbmodem1101)
|
||||||
|
|
||||||
export IDF_PYTHON_ENV_PATH := $(HOME)/.espressif/python_env/idf6.0_py3.12_env
|
|
||||||
|
|
||||||
IDF = . $(IDF_PATH)/export.sh > /dev/null 2>&1 && idf.py
|
IDF = . $(IDF_PATH)/export.sh > /dev/null 2>&1 && idf.py
|
||||||
|
|
||||||
.PHONY: all flash monitor clean menuconfig size erase select
|
.PHONY: all flash monitor clean menuconfig size erase select
|
||||||
|
|
|
||||||
|
|
@ -3413,8 +3413,8 @@ AD5940Err AD5940_HSRtiaCal(HSRTIACal_Type *pCalCfg, void *pResult)
|
||||||
float ExcitVolt; /* Excitation voltage, unit is mV */
|
float ExcitVolt; /* Excitation voltage, unit is mV */
|
||||||
uint32_t RtiaVal;
|
uint32_t RtiaVal;
|
||||||
uint32_t const HpRtiaTable[]={200,1000,5000,10000,20000,40000,80000,160000,0};
|
uint32_t const HpRtiaTable[]={200,1000,5000,10000,20000,40000,80000,160000,0};
|
||||||
uint32_t const HSTIADERLOADTable[]={0,10,30,50,100,UINT32_MAX};
|
uint32_t const HSTIADERLOADTable[]={0,10,30,50,100,999999999999};
|
||||||
uint32_t const HSTIADERTIATable[] = {50,100,200,1000,5000,10000,20000,40000,80000,160000,0,UINT32_MAX};
|
uint32_t const HSTIADERTIATable[] = {50,100,200,1000,5000,10000,20000,40000,80000,160000,0,999999999999999};
|
||||||
uint32_t WgAmpWord;
|
uint32_t WgAmpWord;
|
||||||
|
|
||||||
iImpCar_Type DftRcalVolt, DftRtiaVolt;
|
iImpCar_Type DftRcalVolt, DftRtiaVolt;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
idf_component_register(SRCS "ad5941_port.c" "ad5941_bridge.c"
|
idf_component_register(SRCS "ad5941_port.c" "ad5941_bridge.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES ad5941 esp_driver_spi esp_driver_gpio driver esp_rom)
|
REQUIRES ad5941 driver esp_rom)
|
||||||
|
|
|
||||||
86
main/ble.c
86
main/ble.c
|
|
@ -30,20 +30,13 @@ static const ble_uuid128_t midi_chr_uuid = BLE_UUID128_INIT(
|
||||||
0xf3, 0x6b, 0x10, 0x9d, 0x66, 0xf2, 0xa9, 0xa1,
|
0xf3, 0x6b, 0x10, 0x9d, 0x66, 0xf2, 0xa9, 0xa1,
|
||||||
0x12, 0x41, 0x68, 0x38, 0xdb, 0xe5, 0x72, 0x77);
|
0x12, 0x41, 0x68, 0x38, 0xdb, 0xe5, 0x72, 0x77);
|
||||||
|
|
||||||
#define MAX_CONNECTIONS 2
|
|
||||||
|
|
||||||
static EventGroupHandle_t ble_events;
|
static EventGroupHandle_t ble_events;
|
||||||
static QueueHandle_t cmd_queue;
|
static QueueHandle_t cmd_queue;
|
||||||
|
static uint16_t conn_hdl = BLE_HS_CONN_HANDLE_NONE;
|
||||||
static uint16_t midi_val_hdl;
|
static uint16_t midi_val_hdl;
|
||||||
static uint16_t hid_input_val_hdl;
|
static uint16_t hid_input_val_hdl;
|
||||||
|
static bool midi_notify_en;
|
||||||
static struct {
|
static bool hid_notify_en;
|
||||||
uint16_t hdl;
|
|
||||||
bool midi_notify;
|
|
||||||
bool hid_notify;
|
|
||||||
} conns[MAX_CONNECTIONS];
|
|
||||||
|
|
||||||
static int conn_count;
|
|
||||||
|
|
||||||
/* ---- HID keyboard report map ---- */
|
/* ---- HID keyboard report map ---- */
|
||||||
|
|
||||||
|
|
@ -443,19 +436,14 @@ static const struct ble_gatt_svc_def gatt_svcs[] = {
|
||||||
|
|
||||||
/* ---- send empty keyboard report ---- */
|
/* ---- send empty keyboard report ---- */
|
||||||
|
|
||||||
static int conn_find(uint16_t hdl)
|
static void send_empty_hid_report(void)
|
||||||
{
|
|
||||||
for (int i = 0; i < conn_count; i++)
|
|
||||||
if (conns[i].hdl == hdl) return i;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void send_empty_hid_report(uint16_t hdl)
|
|
||||||
{
|
{
|
||||||
|
if (conn_hdl == BLE_HS_CONN_HANDLE_NONE || !hid_notify_en)
|
||||||
|
return;
|
||||||
static const uint8_t empty[8] = {0};
|
static const uint8_t empty[8] = {0};
|
||||||
struct os_mbuf *om = ble_hs_mbuf_from_flat(empty, sizeof(empty));
|
struct os_mbuf *om = ble_hs_mbuf_from_flat(empty, sizeof(empty));
|
||||||
if (om)
|
if (om)
|
||||||
ble_gatts_notify_custom(hdl, hid_input_val_hdl, om);
|
ble_gatts_notify_custom(conn_hdl, hid_input_val_hdl, om);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- GAP / advertising ---- */
|
/* ---- GAP / advertising ---- */
|
||||||
|
|
@ -468,49 +456,33 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case BLE_GAP_EVENT_CONNECT:
|
case BLE_GAP_EVENT_CONNECT:
|
||||||
if (event->connect.status == 0) {
|
if (event->connect.status == 0) {
|
||||||
uint16_t hdl = event->connect.conn_handle;
|
conn_hdl = event->connect.conn_handle;
|
||||||
if (conn_count < MAX_CONNECTIONS) {
|
|
||||||
conns[conn_count].hdl = hdl;
|
|
||||||
conns[conn_count].midi_notify = false;
|
|
||||||
conns[conn_count].hid_notify = false;
|
|
||||||
conn_count++;
|
|
||||||
}
|
|
||||||
xEventGroupSetBits(ble_events, CONNECTED_BIT);
|
xEventGroupSetBits(ble_events, CONNECTED_BIT);
|
||||||
ble_att_set_preferred_mtu(128);
|
ble_att_set_preferred_mtu(128);
|
||||||
ble_gattc_exchange_mtu(hdl, NULL, NULL);
|
ble_gattc_exchange_mtu(conn_hdl, NULL, NULL);
|
||||||
ble_gap_security_initiate(hdl);
|
ble_gap_security_initiate(conn_hdl);
|
||||||
printf("BLE: connected (%d/%d)\n", conn_count, MAX_CONNECTIONS);
|
printf("BLE: connected\n");
|
||||||
if (conn_count < MAX_CONNECTIONS)
|
|
||||||
start_adv();
|
|
||||||
} else {
|
} else {
|
||||||
start_adv();
|
start_adv();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BLE_GAP_EVENT_DISCONNECT: {
|
case BLE_GAP_EVENT_DISCONNECT:
|
||||||
uint16_t hdl = event->disconnect.conn.conn_handle;
|
conn_hdl = BLE_HS_CONN_HANDLE_NONE;
|
||||||
int idx = conn_find(hdl);
|
midi_notify_en = false;
|
||||||
if (idx >= 0) {
|
hid_notify_en = false;
|
||||||
conns[idx] = conns[--conn_count];
|
|
||||||
}
|
|
||||||
if (conn_count == 0)
|
|
||||||
xEventGroupClearBits(ble_events, CONNECTED_BIT);
|
xEventGroupClearBits(ble_events, CONNECTED_BIT);
|
||||||
printf("BLE: disconnected (%d/%d)\n", conn_count, MAX_CONNECTIONS);
|
printf("BLE: disconnected\n");
|
||||||
start_adv();
|
start_adv();
|
||||||
break;
|
break;
|
||||||
}
|
case BLE_GAP_EVENT_SUBSCRIBE:
|
||||||
case BLE_GAP_EVENT_SUBSCRIBE: {
|
|
||||||
int idx = conn_find(event->subscribe.conn_handle);
|
|
||||||
if (idx >= 0) {
|
|
||||||
if (event->subscribe.attr_handle == midi_val_hdl)
|
if (event->subscribe.attr_handle == midi_val_hdl)
|
||||||
conns[idx].midi_notify = event->subscribe.cur_notify;
|
midi_notify_en = event->subscribe.cur_notify;
|
||||||
if (event->subscribe.attr_handle == hid_input_val_hdl) {
|
if (event->subscribe.attr_handle == hid_input_val_hdl) {
|
||||||
conns[idx].hid_notify = event->subscribe.cur_notify;
|
hid_notify_en = event->subscribe.cur_notify;
|
||||||
if (conns[idx].hid_notify)
|
if (hid_notify_en)
|
||||||
send_empty_hid_report(event->subscribe.conn_handle);
|
send_empty_hid_report();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case BLE_GAP_EVENT_REPEAT_PAIRING: {
|
case BLE_GAP_EVENT_REPEAT_PAIRING: {
|
||||||
struct ble_gap_conn_desc desc;
|
struct ble_gap_conn_desc desc;
|
||||||
ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
|
ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
|
||||||
|
|
@ -575,9 +547,10 @@ static void host_task(void *param)
|
||||||
|
|
||||||
static int send_sysex(const uint8_t *sysex, uint16_t len)
|
static int send_sysex(const uint8_t *sysex, uint16_t len)
|
||||||
{
|
{
|
||||||
if (conn_count == 0)
|
if (conn_hdl == BLE_HS_CONN_HANDLE_NONE || !midi_notify_en)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* BLE MIDI SysEx: [header, ts, F0, payload..., ts, F7] */
|
||||||
uint16_t pkt_len = len + 3;
|
uint16_t pkt_len = len + 3;
|
||||||
uint8_t pkt[80];
|
uint8_t pkt[80];
|
||||||
if (pkt_len > sizeof(pkt))
|
if (pkt_len > sizeof(pkt))
|
||||||
|
|
@ -589,15 +562,10 @@ static int send_sysex(const uint8_t *sysex, uint16_t len)
|
||||||
pkt[len + 1] = 0x80;
|
pkt[len + 1] = 0x80;
|
||||||
pkt[len + 2] = 0xF7;
|
pkt[len + 2] = 0xF7;
|
||||||
|
|
||||||
int sent = 0;
|
|
||||||
for (int i = 0; i < conn_count; i++) {
|
|
||||||
if (!conns[i].midi_notify) continue;
|
|
||||||
struct os_mbuf *om = ble_hs_mbuf_from_flat(pkt, pkt_len);
|
struct os_mbuf *om = ble_hs_mbuf_from_flat(pkt, pkt_len);
|
||||||
if (!om) continue;
|
if (!om) return -1;
|
||||||
if (ble_gatts_notify_custom(conns[i].hdl, midi_val_hdl, om) == 0)
|
|
||||||
sent++;
|
return ble_gatts_notify_custom(conn_hdl, midi_val_hdl, om);
|
||||||
}
|
|
||||||
return sent > 0 ? 0 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- public API ---- */
|
/* ---- public API ---- */
|
||||||
|
|
@ -636,7 +604,7 @@ int ble_init(void)
|
||||||
|
|
||||||
int ble_is_connected(void)
|
int ble_is_connected(void)
|
||||||
{
|
{
|
||||||
return conn_count > 0;
|
return conn_hdl != BLE_HS_CONN_HANDLE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ble_wait_for_connection(void)
|
void ble_wait_for_connection(void)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
CONFIG_IDF_TARGET="esp32s3"
|
|
||||||
CONFIG_BT_ENABLED=y
|
|
||||||
CONFIG_BT_NIMBLE_ENABLED=y
|
|
||||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=2
|
|
||||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
|
|
||||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
|
||||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
|
||||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
|
|
||||||
Loading…
Reference in New Issue