added missing GPIO + disable Bluetooth if /BTOFF

This commit is contained in:
demik 2020-12-21 23:06:33 +01:00
parent 9d87790420
commit 99f1f997bc
6 changed files with 64 additions and 19 deletions

View File

@ -1,3 +1,6 @@
### v1.2
- removed ANT1 ink on PCB
### v1.1
- added beads to reduce EMI
- fixed missong OE on TXB0108

View File

@ -28,6 +28,7 @@
#include "esp_hid_gap.h"
#include "blue.h"
#include "gpio.h"
#include "led.h"
#define BTMOUSE_BUTTON1 (1 << 0)
@ -86,10 +87,7 @@ void hidh_callback(void *handler_args, esp_event_base_t base, int32_t id, void *
switch (event) {
case ESP_HIDH_OPEN_EVENT: {
bda = esp_hidh_dev_bda_get(param->open.dev);
ESP_LOGI(TAG, "opened connection with " ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(bda));
esp_hidh_dev_dump(param->open.dev, stdout);
xTaskNotify(t_blue, LED_ON, eSetValueWithOverwrite);
blue_open(param);
break;
}
case ESP_HIDH_BATTERY_EVENT: {
@ -157,8 +155,17 @@ void blue_init(void)
xTaskCreatePinnedToCore(&blue_scan, "hid_task", 6 * 1024, NULL, 2, NULL, 0);
}
void blue_scan(void *pvParameters)
{
void blue_open(esp_hidh_event_data_t *p) {
const uint8_t *bda = NULL;
bda = esp_hidh_dev_bda_get(p->open.dev);
ESP_LOGI(TAG, "opened connection with " ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(bda));
esp_hidh_dev_dump(p->open.dev, stdout);
xTaskNotify(t_blue, LED_ON, eSetValueWithOverwrite);
gpio_output_enable();
}
void blue_scan(void *pvParameters) {
size_t len = 0;
esp_hid_scan_result_t *mouse = NULL;
esp_hid_scan_result_t *results = NULL;
@ -186,13 +193,12 @@ void blue_scan(void *pvParameters)
}
r = r->next;
}
if (mouse) {
// try to connect to the last mouse found
// try to connect to the last mouse found
if (mouse)
esp_hidh_dev_open(mouse->bda, mouse->transport, mouse->ble.addr_type);
}
else {
else
ESP_LOGI(TAG, "devices found but no mouse detected");
}
esp_hid_scan_results_free(results);
}

View File

@ -30,6 +30,7 @@
/* prototypes */
void blue_init(void);
void blue_open(esp_hidh_event_data_t *p);
void blue_scan(void *pvParameters);
/* global variables for tasks handles */

View File

@ -43,6 +43,16 @@ void gpio_init(void) {
gpio_set_direction(GPIO_YELLOWLED, GPIO_MODE_OUTPUT);
gpio_set_direction(GPIO_REDLED, GPIO_MODE_OUTPUT);
/* External chips */
gpio_reset_pin(GPIO_OE);
gpio_set_direction(GPIO_OE, GPIO_MODE_OUTPUT);
/* Modes */
gpio_reset_pin(GPIO_ADBSRC);
gpio_reset_pin(GPIO_BTOFF);
gpio_set_direction(GPIO_ADBSRC, GPIO_MODE_INPUT);
gpio_set_direction(GPIO_BTOFF, GPIO_MODE_INPUT);
/* Quadrature mouse */
gpio_reset_pin(GPIO_CLICK);
gpio_reset_pin(GPIO_QX1);
@ -57,3 +67,11 @@ void gpio_init(void) {
gpio_set_level(GPIO_CLICK, 1);
}
void gpio_output_disable(void) {
gpio_set_level(GPIO_OE, 0);
}
void gpio_output_enable(void) {
gpio_set_level(GPIO_OE, 1);
}

View File

@ -27,6 +27,8 @@
/* prototypes */
void gpio_init(void);
void gpio_output_disable(void);
void gpio_output_enable(void);
/* GPIO pins definitions
*
@ -49,16 +51,21 @@ void gpio_init(void);
* - GPIO17
*/
#define GPIO_ADB 4
#define GPIO_CLICK 2
#define GPIO_QX1 12
#define GPIO_QX2 13
#define GPIO_QY1 14
#define GPIO_QY2 15
#define GPIO_ADB 4
#define GPIO_CLICK 2
#define GPIO_QX1 12
#define GPIO_QX2 13
#define GPIO_QY1 14
#define GPIO_QY2 15
#define GPIO_OE 22
#define GPIO_ADBSRC 32
#define GPIO_BTOFF 33
#define GPIO_GREENLED 21
#define GPIO_BLUELED 25
#define GPIO_YELLOWLED 26
#define GPIO_REDLED 27
#define GPIO_REDLED 27
#endif

View File

@ -27,6 +27,7 @@
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_hidh.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
@ -57,5 +58,14 @@ void app_main(void)
gpio_init();
led_init();
blue_init();
/* Check /BTOFF and enable bluetooth if needed */
if (gpio_get_level(GPIO_BTOFF) == 1)
blue_init();
/* Blink error if no inputs (/BTOFF and no /ADBSRC) */
if (gpio_get_level(GPIO_BTOFF) == 0 && gpio_get_level(GPIO_ADBSRC) == 1) {
ESP_LOGE(TAG, "Bluetooth is off and ADB is in device mode!");
xTaskNotify(t_red, LED_SLOW, eSetValueWithOverwrite);
}
}