diff --git a/main/main.c b/main/main.c index 6f2ff6f..606c0f4 100644 --- a/main/main.c +++ b/main/main.c @@ -13,13 +13,16 @@ // #include "ble_spp_server_demo.h" #include "motor_drive.h" +#include "port.h" #define MAIN_LOG_TAG "MAIN" #define ble_uart_tx_size 128 #define ble_uart_rx_size 128 #define KEY_INT1 27 #define KEY_INT2 14 +#define DEBUG_LIGHT 12 #define GPIO_KEY_INPUT_PIN_SEL ((1ULL << KEY_INT1) | (1ULL << KEY_INT2)) +#define GPIO_DEBUG_LIGHT_OUTPUT_PIN_SEL ((1ULL << DEBUG_LIGHT)) static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0}; static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0}; @@ -108,18 +111,37 @@ void gpio_input_key_init() { 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 = GPIO_DEBUG_LIGHT_OUTPUT_PIN_SEL; + 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() { + static uint32_t debug_light_time; + if (port_haspassedms(debug_light_time) > 500) { + gpio_set_level(DEBUG_LIGHT, !gpio_get_level(DEBUG_LIGHT)); + debug_light_time = port_get_ticket(); + } +} + void app_main(void) { - gpio_input_key_init(); bleuart_init(&ble_uart_init_struct); bleuart_reg_cb(blerxcb); motor_init(&ble_uart_motor_structer); motor_reg_event_cb(motor_on_event); + gpio_output_debug_light_init(); while (true) { - // bleuart_schedule(); - // motor_module_schedule(); - // ESP_LOGI("log1", "%d", gpio_get_level(27)); - ESP_LOGI("log2", "%d", gpio_get_level(14)); + port_do_debug_light_state(); + bleuart_schedule(); + motor_module_schedule(); } }