quack/main/main.c

84 lines
2.3 KiB
C
Raw Permalink 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 Apache License, Version 2.0 (the "License");
* You may obtain a copy of the License at:
2020-12-16 20:00:00 +00:00
*
* http://www.apache.org/licenses/LICENSE-2.0
2020-12-16 20:00:00 +00:00
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
2020-12-16 20:00:00 +00:00
*
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"
2023-12-28 20:40:18 +00:00
#include "esp_flash.h"
#include "esp_hidh.h"
2020-09-14 20:32:07 +00:00
#include "esp_log.h"
#include "esp_system.h"
2023-12-28 20:40:18 +00:00
#include "esp_chip_info.h"
2020-09-14 20:32:07 +00:00
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"
2021-04-20 22:33:42 +00:00
#include "quad.h"
2020-09-14 20:32:07 +00:00
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)
{
2023-12-28 20:40:18 +00:00
uint32_t flash_size;
esp_flash_get_size(NULL, &flash_size);
2020-09-14 20:32:07 +00:00
/* 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, "
2023-12-28 20:40:18 +00:00
"revision %d, %" PRIu32 "MB %s flash",
2020-12-31 07:53:57 +00:00
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
2023-12-28 20:40:18 +00:00
chip_info.revision, flash_size / (1024 * 1024),
2020-12-31 07:53:57 +00:00
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
2020-09-14 20:32:07 +00:00
2023-12-28 20:40:18 +00:00
ESP_LOGI(TAG, "Minimum free heap size: %" PRIu32 " bytes", esp_get_minimum_free_heap_size());
2021-04-20 22:33:42 +00:00
ESP_LOGI(TAG, "");
ESP_LOGI(TAG, "\\_o< \\_o< \\_o< \\_O<");
ESP_LOGI(TAG, "");
2020-09-14 20:32:07 +00:00
gpio_init();
2020-12-14 18:59:33 +00:00
led_init();
2021-04-20 22:33:42 +00:00
quad_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
2021-04-20 22:33:42 +00:00
* of bluetooth is disabled, enable quadrature outputs
2021-01-08 08:21:38 +00:00
*/
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();
2021-04-20 22:33:42 +00:00
/* put LED error ON if no inputs (/BTOFF and no /ADBSRC) */
2020-12-31 07:53:57 +00:00
if (gpio_get_level(GPIO_BTOFF) == 0 && gpio_get_level(GPIO_ADBSRC) == 1) {
ESP_LOGE(TAG, "Bluetooth is off and ADB is NOT in host mode!");
2021-04-20 22:33:42 +00:00
xTaskNotify(t_red, LED_ON, eSetValueWithOverwrite);
2020-12-31 07:53:57 +00:00
}
2020-09-14 20:32:07 +00:00
}