From 24b4fc1413a44dac26a1058e39e099da07c8f5ec Mon Sep 17 00:00:00 2001 From: demik Date: Fri, 8 Jan 2021 09:21:38 +0100 Subject: [PATCH] try to init adb --- main/CMakeLists.txt | 3 ++- main/adb.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ main/gpio.c | 9 +++++++ main/main.c | 9 ++++++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 main/adb.c diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 179b749..047615a 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,4 +1,5 @@ -set(srcs "blue.c" +set(srcs "adb.c" + "blue.c" "esp_hid_gap.c" "gpio.c" "led.c" diff --git a/main/adb.c b/main/adb.c new file mode 100644 index 0000000..50c9e23 --- /dev/null +++ b/main/adb.c @@ -0,0 +1,63 @@ +/* + * adb.c + * quack + * + * Created by Michel DEPEIGE on 7/01/2020. + * Copyright (c) 2020 Michel DEPEIGE. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING); if not, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + */ + +#include +#include "driver/gpio.h" +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "esp_spi_flash.h" + +#include "adb.h" +#include "gpio.h" + +void adb_init(void) { + gpio_set_pull_mode(GPIO_ADB, GPIO_PULLUP_ONLY); + + /* If jumper is set, switch to ADB host mode */ + if (gpio_get_level(GPIO_ADBSRC) == 0) + xTaskCreatePinnedToCore(&adb_task_host, "ADB_HOST", 6 * 1024, NULL, 4, NULL, 1); + else + xTaskCreatePinnedToCore(&adb_task_mouse, "ADB_MOUSE", 6 * 1024, NULL, 4, NULL, 1); +} + +void adb_task_host(void *pvParameters) { + adb_send_reset(); + + while (1) { + vTaskDelay(1000 / portTICK_PERIOD_MS); + } +} + +void adb_task_mouse(void *pvParameters) { + +} + +void adb_send_reset() { + gpio_set_level(GPIO_ADB, 0); + vTaskDelay(3 / portTICK_PERIOD_MS); + gpio_set_level(GPIO_ADB, 1); + vTaskDelay(1 / portTICK_PERIOD_MS); +} diff --git a/main/gpio.c b/main/gpio.c index 807eeed..6a303f9 100644 --- a/main/gpio.c +++ b/main/gpio.c @@ -53,18 +53,27 @@ void gpio_init(void) { gpio_set_direction(GPIO_ADBSRC, GPIO_MODE_INPUT); gpio_set_direction(GPIO_BTOFF, GPIO_MODE_INPUT); + /* ADB */ + gpio_set_direction(GPIO_ADB, GPIO_MODE_INPUT|GPIO_MODE_OUTPUT); + /* Quadrature mouse */ gpio_reset_pin(GPIO_CLICK); gpio_reset_pin(GPIO_QX1); gpio_reset_pin(GPIO_QX2); gpio_reset_pin(GPIO_QY1); gpio_reset_pin(GPIO_QY2); + gpio_set_pull_mode(GPIO_CLICK, GPIO_PULLDOWN_ONLY); + gpio_set_pull_mode(GPIO_QX1, GPIO_PULLDOWN_ONLY); + gpio_set_pull_mode(GPIO_QX2, GPIO_PULLDOWN_ONLY); + gpio_set_pull_mode(GPIO_QY1, GPIO_PULLDOWN_ONLY); + gpio_set_pull_mode(GPIO_QY2, GPIO_PULLDOWN_ONLY); gpio_set_direction(GPIO_CLICK, GPIO_MODE_OUTPUT); gpio_set_direction(GPIO_QX1, GPIO_MODE_OUTPUT); gpio_set_direction(GPIO_QX2, GPIO_MODE_OUTPUT); gpio_set_direction(GPIO_QY1, GPIO_MODE_OUTPUT); gpio_set_direction(GPIO_QY2, GPIO_MODE_OUTPUT); + gpio_set_level(GPIO_CLICK, 1); } diff --git a/main/main.c b/main/main.c index 0db2221..e756709 100644 --- a/main/main.c +++ b/main/main.c @@ -32,6 +32,7 @@ #include "esp_system.h" #include "esp_spi_flash.h" +#include "adb.h" #include "blue.h" #include "led.h" #include "gpio.h" @@ -58,10 +59,16 @@ void app_main(void) gpio_init(); led_init(); + adb_init(); - /* Check /BTOFF and enable bluetooth if needed */ + /* + * Check /BTOFF and enable bluetooth if needed + * of bluetooth is disabled, enable ADB and Quadrature outputs + */ if (gpio_get_level(GPIO_BTOFF) == 1) blue_init(); + else + gpio_output_enable(); /* Blink error if no inputs (/BTOFF and no /ADBSRC) */ if (gpio_get_level(GPIO_BTOFF) == 0 && gpio_get_level(GPIO_ADBSRC) == 1) {