2020-12-16 20:00:00 +00:00
|
|
|
/*
|
|
|
|
* gpio.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_system.h"
|
|
|
|
#include "esp_spi_flash.h"
|
|
|
|
|
|
|
|
#include "gpio.h"
|
|
|
|
|
|
|
|
void gpio_init(void) {
|
2020-12-14 18:59:33 +00:00
|
|
|
/* LEDs */
|
|
|
|
gpio_reset_pin(GPIO_GREENLED);
|
|
|
|
gpio_reset_pin(GPIO_BLUELED);
|
|
|
|
gpio_reset_pin(GPIO_YELLOWLED);
|
|
|
|
gpio_reset_pin(GPIO_REDLED);
|
|
|
|
gpio_set_direction(GPIO_GREENLED, GPIO_MODE_OUTPUT);
|
|
|
|
gpio_set_direction(GPIO_BLUELED, GPIO_MODE_OUTPUT);
|
|
|
|
gpio_set_direction(GPIO_YELLOWLED, GPIO_MODE_OUTPUT);
|
|
|
|
gpio_set_direction(GPIO_REDLED, GPIO_MODE_OUTPUT);
|
2020-12-21 22:06:33 +00:00
|
|
|
|
2020-12-31 07:53:57 +00:00
|
|
|
/* External chips */
|
2021-05-03 22:45:23 +00:00
|
|
|
gpio_reset_pin(GPIO_DIR);
|
2020-12-31 07:53:57 +00:00
|
|
|
gpio_reset_pin(GPIO_OE);
|
2021-05-03 22:45:23 +00:00
|
|
|
gpio_set_direction(GPIO_DIR, GPIO_MODE_OUTPUT);
|
2020-12-31 07:53:57 +00:00
|
|
|
gpio_set_direction(GPIO_OE, GPIO_MODE_OUTPUT);
|
2020-12-21 22:06:33 +00:00
|
|
|
|
2020-12-31 07:53:57 +00:00
|
|
|
/* 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);
|
|
|
|
|
2021-01-08 08:21:38 +00:00
|
|
|
/* ADB */
|
2021-04-01 18:58:23 +00:00
|
|
|
gpio_set_direction(GPIO_ADB, GPIO_MODE_INPUT);
|
2021-05-03 22:45:23 +00:00
|
|
|
gpio_set_level(GPIO_DIR, 0);
|
2021-01-08 08:21:38 +00:00
|
|
|
|
2020-12-31 07:53:57 +00:00
|
|
|
/* 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);
|
2021-01-08 08:21:38 +00:00
|
|
|
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);
|
2020-12-31 07:53:57 +00:00
|
|
|
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);
|
2020-09-14 20:32:07 +00:00
|
|
|
}
|
2020-12-21 22:06:33 +00:00
|
|
|
|
|
|
|
void gpio_output_disable(void) {
|
2021-05-03 22:45:23 +00:00
|
|
|
gpio_set_level(GPIO_OE, 1);
|
2020-12-21 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_output_enable(void) {
|
2021-05-03 22:45:23 +00:00
|
|
|
gpio_set_level(GPIO_OE, 0);
|
2020-12-21 22:06:33 +00:00
|
|
|
}
|