diff --git a/scripts/waveform_hdrgen.py b/scripts/waveform_hdrgen.py index bb2e5c38..7d872232 100755 --- a/scripts/waveform_hdrgen.py +++ b/scripts/waveform_hdrgen.py @@ -18,24 +18,36 @@ total_size = 0 -def phase_to_c(phase): - """ - Convert a 5 bit phase to a 4 bit C LUT. - """ - global total_size +def phase_to_c(phase,bits_per_pixel_c=4): + + N1 = len(phase) + N2 = len(phase[0]) + N = 2**bits_per_pixel_c + + if N1%N != 0: + raise ValueError(f"first dimension of phases is {N1}. Allowed are multiples of {N}") + + step1 = int(N1/N) + + if N2%N != 0: + raise ValueError(f"second dimension of phases is {N2}. Allowed are multiples of {N}") + + step2 = int(N2/N) targets = [] - for t in range(0, 32, 2): + for t in range(0, N1, step1): chunk = 0 line = [] - for f in range(0, 32, 2): + i = 0 + for f in range(0, N2, step2): fr = phase[t][f] chunk = (chunk << 2) | fr - if f and f % 8 == 6: + i += 1 + if i == 4: + i = 0 line.append(chunk) chunk = 0 targets.append(line) - total_size += len(line) return targets @@ -61,7 +73,7 @@ def list_to_c(l): modes = [] -mode_filter = list(range(len(waveforms["modes"]))) +mode_filter = [wm["mode"] for wm in waveforms["modes"]] if args.export_modes: mode_filter = list(map(int, args.export_modes.split(","))) @@ -72,6 +84,8 @@ def list_to_c(l): temp_intervals = [] for bounds in waveforms["temperature_ranges"]["range_bounds"]: + if bounds["to"] < tmin or bounds["from"] > tmax: + continue temp_intervals.append(f"{{ .min = {bounds['from']}, .max = {bounds['to']} }}") modes = [] @@ -84,7 +98,7 @@ def list_to_c(l): ranges = [] for i, r in enumerate(mode["ranges"]): bounds = waveforms["temperature_ranges"]["range_bounds"][i] - if bounds["from"] < tmin or bounds["from"] > tmax: + if bounds["to"] < tmin or bounds["from"] > tmax: continue phases = [] diff --git a/src/highlevel.c b/src/highlevel.c index c3ed5ac4..9b00f188 100644 --- a/src/highlevel.c +++ b/src/highlevel.c @@ -172,12 +172,12 @@ enum EpdDrawError epd_hl_update_area( x += 1; } - if (x_last % 2) { + if (!(x_last % 2)) { *(lbb + x_last / 2) = (*(lfb + x_last / 2) & 0x0F) | (*(lbb + x_last / 2) & 0xF0); x_last -= 1; } - memcpy(lbb + (x / 2), lfb + (x / 2), (x_last - x) / 2); + memcpy(lbb + (x / 2), lfb + (x / 2), (x_last - x + 1) / 2); } } diff --git a/src/output_lcd/lcd_driver.c b/src/output_lcd/lcd_driver.c index 234d87c8..f5f31c86 100644 --- a/src/output_lcd/lcd_driver.c +++ b/src/output_lcd/lcd_driver.c @@ -653,7 +653,7 @@ void IRAM_ATTR epd_lcd_start_frame() { lcd.lcd_res_h + (lcd.dummy_bytes > 0), end_line ); - lcd_ll_set_vertical_timing(lcd.hal.dev, 1, 1, initial_lines, 1); + lcd_ll_set_vertical_timing(lcd.hal.dev, 1, 0, initial_lines, 1); // generate the hsync at the very beginning of line lcd_ll_set_hsync_position(lcd.hal.dev, 1);