From ff9c2a22f132125f835db82961409a84d40ef079 Mon Sep 17 00:00:00 2001 From: rkcf Date: Sun, 5 Feb 2023 11:02:53 -0600 Subject: [PATCH] Style: change comments to be c-style --- main/esp32-sequencer.c | 117 ++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/main/esp32-sequencer.c b/main/esp32-sequencer.c index 4199a7b..4e8c0e5 100644 --- a/main/esp32-sequencer.c +++ b/main/esp32-sequencer.c @@ -45,17 +45,16 @@ #include "pixel_operator_24.c" /* Inputs */ -// Clock In /* Controls */ -#define GPIO_MUTATE_BTN (9) // Mutate Button In -#define GPIO_TAP_TEMPO_BTN (10) // Tap Tempo Button In +#define GPIO_MUTATE_BTN (9) /* Mutate Button In */ +#define GPIO_TAP_TEMPO_BTN (10) /* Tap Tempo Button In */ static QueueHandle_t control_event_queue = NULL; /* Outputs */ -#define GPIO_CLK_OUT (7) // Clock Out -#define GPIO_GATE_OUT (8) // Gate CV Out +#define GPIO_CLK_OUT (7) /* Clock Out */ +#define GPIO_GATE_OUT (8) /* Gate CV Out */ /* LED GPIO Pins */ #define LEDC_CLK_OUT (5) @@ -79,9 +78,9 @@ static QueueHandle_t control_event_queue = NULL; static gptimer_handle_t tap_tempo_timer = NULL; static gptimer_handle_t gate_timer = NULL; -static const uint16_t DEBOUNCE_TIMEOUT = 10; // polling period length when debouncing in ms -static uint64_t debounce_time = 0; // system time of last intterupt -static uint8_t btn_state = 1; // state of gpio last recorded +static const uint16_t DEBOUNCE_TIMEOUT = 10; /* polling period length when debouncing in ms */ +static uint64_t debounce_time = 0; /* system time of last intterupt */ +static uint8_t btn_state = 1; /* state of gpio last recorded */ portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; @@ -110,7 +109,7 @@ static void update_bpm(void) { lv_label_set_text_fmt(bpm_label, "BPM: %d", current_bpm); } -// updates the sequence for the GUI display +/* updates the sequence for the GUI display */ static void update_seq(uint8_t *sequence) { char seq_str[seq_len]; for (uint8_t i = 0; i < seq_len; i++) { @@ -133,7 +132,7 @@ static void randomize_seq(uint8_t *sequence) { static void mutate_seq(uint8_t *sequence) { ESP_LOGI(TAG, "Mutating Sequence"); - // pick a step to mutate + /* pick a step to mutate */ uint8_t step = esp_random() % SEQ_MAX_LEN; if (sequence[step] == 1) { sequence[step] = 0; @@ -145,13 +144,13 @@ static void mutate_seq(uint8_t *sequence) { /* Handle tap tempo button presses */ static void tap_tempo_handler(){ - // check the count to see if we have already started the timer + /* check the count to see if we have already started the timer */ uint64_t count; ESP_ERROR_CHECK(gptimer_get_raw_count(tap_tempo_timer, &count)); - if (count == 0) { // the timer hasn't started yet + if (count == 0) { /* the timer hasn't started yet */ ESP_ERROR_CHECK(gptimer_start(tap_tempo_timer)); ESP_LOGI(TAG, "Starting tap tempo monitoring"); - } else { // stop the timer and calc bpm + } else { /* stop the timer and calc bpm */ ESP_ERROR_CHECK(gptimer_stop(tap_tempo_timer)); ESP_ERROR_CHECK(gptimer_set_raw_count(tap_tempo_timer, 0)); current_bpm = ms_to_bpm(count / 1000); @@ -163,8 +162,8 @@ static void tap_tempo_handler(){ static void IRAM_ATTR gpio_isr_handler(void* arg) { uint32_t gpio_num = (uint32_t)arg; portENTER_CRITICAL_ISR(&mux); - debounce_time = xTaskGetTickCount(); // set time of interrupt - btn_state = gpio_get_level(gpio_num); // set state + debounce_time = xTaskGetTickCount(); /* set time of interrupt */ + btn_state = gpio_get_level(gpio_num); /* set state */ portEXIT_CRITICAL_ISR(&mux); xQueueSendFromISR(control_event_queue, &gpio_num, NULL); } @@ -174,14 +173,14 @@ static void control_event_handler(void* arg) { uint8_t last_btn_state; uint64_t last_debounce_time; while (1) { - // save these so we can make comparisons + /* save these so we can make comparisons */ portENTER_CRITICAL_ISR(&mux); last_btn_state = btn_state; last_debounce_time = debounce_time; portEXIT_CRITICAL_ISR(&mux); uint8_t current_state = gpio_get_level(gpio_num); if (xQueueReceive(control_event_queue, &gpio_num, portMAX_DELAY)) { - // Check if interrupt triggered stays the same for long enough + /* Check if interrupt triggered stays the same for long enough */ if ((current_state == last_btn_state) && (xTaskGetTickCount() - last_debounce_time > DEBOUNCE_TIMEOUT)) { ESP_LOGI(TAG, "Handling control from GPIO %" PRIu32, gpio_num); @@ -199,27 +198,27 @@ static void control_event_handler(void* arg) { } static void controls_init(void) { - // install gpio isr hservice + /* install gpio isr hservice */ gpio_install_isr_service(0); - // Setup Mutate Button + /* Setup Mutate Button */ gpio_reset_pin(GPIO_MUTATE_BTN); gpio_set_direction(GPIO_MUTATE_BTN, GPIO_MODE_INPUT); gpio_set_intr_type(GPIO_MUTATE_BTN, GPIO_INTR_NEGEDGE); - // Hook in handler for mutate button + /* Hook in handler for mutate button */ gpio_isr_handler_add(GPIO_MUTATE_BTN, gpio_isr_handler, (void*)GPIO_MUTATE_BTN); - // Setup tap tempo Button + /* Setup tap tempo Button */ gpio_reset_pin(GPIO_TAP_TEMPO_BTN); gpio_set_direction(GPIO_TAP_TEMPO_BTN, GPIO_MODE_INPUT); gpio_set_intr_type(GPIO_TAP_TEMPO_BTN, GPIO_INTR_NEGEDGE); - // Hook in handler for tap tempo button + /* Hook in handler for tap tempo button */ gpio_isr_handler_add(GPIO_TAP_TEMPO_BTN, gpio_isr_handler, (void *)GPIO_TAP_TEMPO_BTN); - // Setup tap tempo timer + /* Setup tap tempo timer */ gptimer_config_t tap_tempo_timer_config = { .clk_src = GPTIMER_CLK_SRC_DEFAULT, .direction = GPTIMER_COUNT_UP, - .resolution_hz = 1 * 1000 * 1000 // 1MHz; 1 tick = 1 µs + .resolution_hz = 1 * 1000 * 1000 /* 1MHz; 1 tick = 1 µs */ }; ESP_ERROR_CHECK(gptimer_new_timer(&tap_tempo_timer_config, &tap_tempo_timer)); ESP_ERROR_CHECK(gptimer_enable(tap_tempo_timer)); @@ -236,39 +235,39 @@ static void gate_off_alarm_cb(gptimer_handle_t timer, const gptimer_alarm_event_ } static void gpio_init(void) { - // Setup gpio control event queue + /* Setup gpio control event queue */ control_event_queue = xQueueCreate(10, sizeof(uint32_t)); - // Setup Clock CV Output + /* Setup Clock CV Output */ gpio_reset_pin(GPIO_CLK_OUT); gpio_set_direction(GPIO_CLK_OUT, GPIO_MODE_OUTPUT); - // Setup Gate CV Output + /* Setup Gate CV Output */ gpio_reset_pin(GPIO_GATE_OUT); gpio_set_direction(GPIO_GATE_OUT, GPIO_MODE_OUTPUT); - // Setup gate timer + /* Setup gate timer */ gptimer_config_t cv_out_timer_config = { .clk_src = GPTIMER_CLK_SRC_DEFAULT, .direction = GPTIMER_COUNT_UP, - .resolution_hz = 1 * 1000 * 1000 // 1MHz; 1 tick = 1 µs + .resolution_hz = 1 * 1000 * 1000 /* 1MHz; 1 tick = 1 µs */ }; ESP_ERROR_CHECK(gptimer_new_timer(&cv_out_timer_config, &gate_timer)); - // Configure gate timer alarm + /* Configure gate timer alarm */ gptimer_alarm_config_t cv_off_alarm_config = { - .alarm_count = 20 * 1000, // 20ms @ 1MHz + .alarm_count = 20 * 1000, /* 20ms @ 1MHz */ .reload_count = 0, .flags.auto_reload_on_alarm = true }; ESP_ERROR_CHECK(gptimer_set_alarm_action(gate_timer, &cv_off_alarm_config)); - //register gate timer callback + /* Register gate timer callback */ gptimer_event_callbacks_t clk_cbs = {.on_alarm = gate_off_alarm_cb}; ESP_ERROR_CHECK(gptimer_register_event_callbacks(gate_timer, &clk_cbs, NULL)); ESP_ERROR_CHECK(gptimer_enable(gate_timer)); } static void ledc_init(void) { - // Setup LEDC PWM timer configuration + /* Setup LEDC PWM timer configuration */ ledc_timer_config_t ledc_timer = { .speed_mode = LEDC_LOW_SPEED_MODE, .timer_num = LEDC_TIMER_0, @@ -278,7 +277,7 @@ static void ledc_init(void) { }; ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); - // Setup Clock LED + /* Setup Clock LED */ ledc_channel_config_t ledc_clk_channel = { .channel = LEDC_CHANNEL_0, .gpio_num = LEDC_CLK_OUT, @@ -290,7 +289,7 @@ static void ledc_init(void) { }; ESP_ERROR_CHECK(ledc_channel_config(&ledc_clk_channel)); - // Setup Gate LED + /* Setup Gate LED */ ledc_channel_config_t ledc_gate_channel = { .channel = LEDC_CHANNEL_1, .gpio_num = LEDC_GATE_OUT, @@ -330,7 +329,7 @@ static void lvgl_increase_tick(void *arg) { static void display_init(void) { ESP_LOGI(TAG, "Initialing LCD"); - // Configure backlight + /* Configure backlight */ ledc_channel_config_t ledc_lcd_bk_light_channel = { .channel = LEDC_CHANNEL_2, .gpio_num = LCD_BK_LIGHT_PIN, @@ -342,7 +341,7 @@ static void display_init(void) { }; ESP_ERROR_CHECK(ledc_channel_config(&ledc_lcd_bk_light_channel)); - // Setup SPI Bus + /* Setup SPI Bus */ spi_bus_config_t spi_cfg = { .sclk_io_num = LCD_SCLK_PIN, .mosi_io_num = LCD_MOSI_PIN, @@ -353,7 +352,7 @@ static void display_init(void) { }; ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &spi_cfg, SPI_DMA_CH_AUTO)); - // Setup Panel IO + /* Setup Panel IO */ static lv_disp_drv_t disp_drv; esp_lcd_panel_io_handle_t lcd_io_handle = NULL; esp_lcd_panel_io_spi_config_t lcd_spi_config = { @@ -369,7 +368,7 @@ static void display_init(void) { }; ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &lcd_spi_config, &lcd_io_handle)); - // Setup ili9341 panel driver + /* Setup ili9341 panel driver */ esp_lcd_panel_handle_t lcd_handle = NULL; esp_lcd_panel_dev_config_t lcd_config = { .reset_gpio_num = LCD_RST_PIN, @@ -380,22 +379,22 @@ static void display_init(void) { ESP_ERROR_CHECK(esp_lcd_panel_reset(lcd_handle)); ESP_ERROR_CHECK(esp_lcd_panel_init(lcd_handle)); - // Turn on the panel + /* Turn on the panel */ ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(lcd_handle, true)); ESP_LOGI(TAG, "Initalizing LVGL"); lv_init(); - // Allocate draw buffers + /* Allocate draw buffers */ lv_color_t *buf1 = heap_caps_malloc(LCD_H_RES * 80 * sizeof(lv_color_t), MALLOC_CAP_DMA); lv_color_t *buf2 = heap_caps_malloc(LCD_H_RES * 80 * sizeof(lv_color_t), MALLOC_CAP_DMA); - // Initialize draw buffers + /* Initialize draw buffers */ static lv_disp_draw_buf_t disp_buf; lv_disp_draw_buf_init(&disp_buf, buf1, buf2, LCD_H_RES * 80); - // Initialize display driver then register it + /* Initialize display driver then register it */ lv_disp_drv_init(&disp_drv); disp_drv.hor_res = LCD_H_RES; disp_drv.ver_res = LCD_V_RES; @@ -405,7 +404,7 @@ static void display_init(void) { disp_drv.user_data = lcd_handle; lv_disp_t *disp = lv_disp_drv_register(&disp_drv); - // Install LVGL tick timer + /* Install LVGL tick timer */ esp_timer_handle_t lvgl_tick_timer = NULL; const esp_timer_create_args_t lvgl_tick_timer_args = { .callback = &lvgl_increase_tick, @@ -416,49 +415,49 @@ static void display_init(void) { } static void gui_create(void) { - // Setup flex layout + /* Setup flex layout */ /* lv_obj_t * seq_row = lv_obj_create(lv_scr_act()); */ /* lv_obj_set_size(seq_row, 300, 70); */ /* lv_obj_set_flex_flow(seq_row, LV_FLEX_FLOW_ROW); */ - // Initialize style + /* Initialize style */ static lv_style_t gui_style; lv_style_init(&gui_style); - // Set background color + /* Set background color */ /* lv_style_set_bg_color(&gui_style, lv_color_hex(0xa1e5d0)); */ - // Load Font https://www.dafont.com/pixel-operator.font - // Converted with https://lvgl.io/tools/fontconverter + /* Load Font https://www.dafont.com/pixel-operator.font */ + /* Converted with https://lvgl.io/tools/fontconverter */ LV_FONT_DECLARE(pixel_operator_24); - // Set the font in the style + /* Set the font in the style */ lv_style_set_text_font(&gui_style, &pixel_operator_24); lv_style_set_text_color(&gui_style, lv_color_hex(0x000000)); - // Create and set Title lable text + /* Create and set Title lable text */ lv_obj_t * title_label = lv_label_create(lv_scr_act()); lv_label_set_text(title_label, "ESP32 Sequencer\n"); lv_obj_add_style(title_label, &gui_style, LV_STATE_DEFAULT); lv_obj_align(title_label, LV_ALIGN_TOP_MID, 0, 5); - // Create and set BPM lable text + /* Create and set BPM lable text */ bpm_label = lv_label_create(lv_scr_act()); lv_label_set_text_fmt(bpm_label, "BPM: %d", current_bpm); lv_obj_add_style(bpm_label, &gui_style, LV_STATE_DEFAULT); lv_obj_align(bpm_label, LV_ALIGN_BOTTOM_LEFT, 5, -5); - // Create sequence text area + /* Create sequence text area */ sequence_label = lv_label_create(lv_scr_act()); lv_label_set_text(sequence_label, "oooooooo"); lv_obj_add_style(sequence_label, &gui_style, LV_STATE_DEFAULT); lv_obj_align(sequence_label, LV_ALIGN_CENTER, 0, 0); - // Create sequence tracker text area + /* Create sequence tracker text area */ sequence_tracker = lv_label_create(lv_scr_act()); lv_obj_add_style(sequence_tracker, &gui_style, LV_STATE_DEFAULT); lv_label_set_text(sequence_tracker, "_ "); - lv_obj_align(sequence_tracker, LV_ALIGN_CENTER, 0, 5); // slightly lower than main sequence + lv_obj_align(sequence_tracker, LV_ALIGN_CENTER, 0, 5); /* slightly lower than main sequence */ } static void gui_task(void *pvParameter) { @@ -490,7 +489,7 @@ void app_main(void) { gui_create(); xTaskCreatePinnedToCore(gui_task, "gui", 4096*2, NULL, 0, NULL, 1); - // Start task to handle control events + /* Start task to handle control events */ xTaskCreate(control_event_handler, "control event handler", 2048, NULL, 10, NULL); /* Initialize Monitor LEDs */ @@ -503,7 +502,7 @@ void app_main(void) { while (1) { char tracker_str[seq_len]; for (uint8_t step = 0; step < seq_len; step++) { - // advance step tracker + /* advance step tracker */ if (step == 0) { tracker_str[seq_len - 1] = ' '; } else { @@ -511,10 +510,10 @@ void app_main(void) { } tracker_str[step] = '_'; - // set the new sequence label + /* set the new sequence label */ lv_label_set_text(sequence_tracker, tracker_str); - // if step has been set for sequence + /* if step has been set for sequence */ if (sequence[step] == 1) { pulse_cv(true); } else {