quack/main/main.c

79 lines
2.2 KiB
C
Raw Normal View History

2020-12-16 20:00:00 +00:00
/*
* main.c
* quack
*
* Created by Michel DEPEIGE on 14/12/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
*
2020-09-14 20:32:07 +00:00
*/
2020-12-16 20:00:00 +00:00
2020-09-14 20:32:07 +00:00
#include <stdio.h>
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_hidh.h"
2020-09-14 20:32:07 +00:00
#include "esp_log.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
2021-01-08 08:21:38 +00:00
#include "adb.h"
2020-09-14 20:32:07 +00:00
#include "blue.h"
2020-12-14 18:59:33 +00:00
#include "led.h"
2020-09-14 20:32:07 +00:00
#include "gpio.h"
2020-12-16 20:00:00 +00:00
/* global TAG for ESP_LOG */
2020-09-14 20:32:07 +00:00
static const char* TAG = "quack";
void app_main(void)
{
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
ESP_LOGI(TAG, "This is %s chip with %d CPU cores, WiFi%s%s, "
2020-12-31 07:53:57 +00:00
"revision %d, %dMB %s flash",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
chip_info.revision,
spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
2020-09-14 20:32:07 +00:00
ESP_LOGI(TAG, "Minimum free heap size: %d bytes", esp_get_minimum_free_heap_size());
gpio_init();
2020-12-14 18:59:33 +00:00
led_init();
2021-01-08 08:21:38 +00:00
adb_init();
2021-01-08 08:21:38 +00:00
/*
* Check /BTOFF and enable bluetooth if needed
* of bluetooth is disabled, enable ADB and Quadrature outputs
*/
2020-12-31 07:53:57 +00:00
if (gpio_get_level(GPIO_BTOFF) == 1)
blue_init();
2021-01-08 08:21:38 +00:00
else
gpio_output_enable();
2020-12-31 07:53:57 +00:00
/* 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);
}
2020-09-14 20:32:07 +00:00
}