You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.5 KiB
81 lines
2.5 KiB
#include "port.h"
|
|
|
|
#include "driver/gpio.h"
|
|
#include "esp_log.h"
|
|
|
|
uint32_t port_get_ticket() { return esp_log_timestamp(); }
|
|
uint32_t port_haspassedms(uint32_t ticket) { return port_get_ticket() - ticket; }
|
|
uint32_t port_delay_ms(uint32_t ms) {
|
|
uint32_t now = port_get_ticket();
|
|
while (port_get_ticket() - now < ms) {
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void gpio_electric_relay_init() {
|
|
{ // ELECTRIC_RELAY1
|
|
gpio_config_t gpio_grb_led_structer;
|
|
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
|
|
gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
|
|
gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_ELECTRIC_RELAY1);
|
|
gpio_grb_led_structer.pull_down_en = 0;
|
|
gpio_grb_led_structer.pull_up_en = 0;
|
|
|
|
gpio_config(&gpio_grb_led_structer);
|
|
}
|
|
{ // ELECTRIC_RELAY2
|
|
gpio_config_t gpio_grb_led_structer;
|
|
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
|
|
gpio_grb_led_structer.mode = GPIO_MODE_OUTPUT;
|
|
gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_ELECTRIC_RELAY2);
|
|
gpio_grb_led_structer.pull_down_en = 0;
|
|
gpio_grb_led_structer.pull_up_en = 0;
|
|
|
|
gpio_config(&gpio_grb_led_structer);
|
|
}
|
|
}
|
|
|
|
void gpio_output_debug_light_init() {
|
|
gpio_config_t gpio_grb_led_structer;
|
|
|
|
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
|
|
gpio_grb_led_structer.mode = GPIO_MODE_INPUT_OUTPUT;
|
|
gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_DEBUG_LIGHT);
|
|
gpio_grb_led_structer.pull_down_en = 0;
|
|
gpio_grb_led_structer.pull_up_en = 0;
|
|
|
|
gpio_config(&gpio_grb_led_structer);
|
|
}
|
|
|
|
void port_do_debug_light_state(uint16_t interval_time) {
|
|
static uint32_t debug_light_time;
|
|
if (port_haspassedms(debug_light_time) > interval_time) {
|
|
gpio_set_level(GPIO_DEBUG_LIGHT, !gpio_get_level(GPIO_DEBUG_LIGHT));
|
|
debug_light_time = port_get_ticket();
|
|
}
|
|
}
|
|
|
|
void gpio_input_key_init() {
|
|
{ // Key1
|
|
gpio_config_t gpio_grb_led_structer;
|
|
|
|
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
|
|
gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
|
|
gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_KEY_INT1);
|
|
gpio_grb_led_structer.pull_down_en = 0;
|
|
gpio_grb_led_structer.pull_up_en = 0;
|
|
|
|
gpio_config(&gpio_grb_led_structer);
|
|
}
|
|
|
|
{ // Key2
|
|
gpio_config_t gpio_grb_led_structer;
|
|
gpio_grb_led_structer.intr_type = GPIO_INTR_DISABLE;
|
|
gpio_grb_led_structer.mode = GPIO_MODE_INPUT;
|
|
gpio_grb_led_structer.pin_bit_mask = (1ULL << GPIO_KEY_INT2);
|
|
gpio_grb_led_structer.pull_down_en = 0;
|
|
gpio_grb_led_structer.pull_up_en = 0;
|
|
gpio_config(&gpio_grb_led_structer);
|
|
}
|
|
}
|