Skip to content

Commit a97e46b

Browse files
committed
espressif: Fix ParallelBus clock speed
The observed does not match the datasheet, so go with what was observed.
1 parent 3f4bbc5 commit a97e46b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ports/espressif/i2s_lcd_esp32s2_driver.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static esp_err_t i2s_lcd_reg_config(i2s_dev_t *i2s_dev, uint16_t data_width, uin
190190
i2s_dev->clkm_conf.clkm_div_num = 2; // 160MHz / 2 = 80MHz
191191
i2s_dev->clkm_conf.clkm_div_b = 0;
192192
i2s_dev->clkm_conf.clkm_div_a = 0;
193-
i2s_dev->clkm_conf.clk_sel = 2;
193+
i2s_dev->clkm_conf.clk_sel = 2; // PLL_160M_CLK
194194
i2s_dev->clkm_conf.clk_en = 1;
195195

196196
i2s_dev->conf.val = 0;
@@ -211,7 +211,18 @@ static esp_err_t i2s_lcd_reg_config(i2s_dev_t *i2s_dev, uint16_t data_width, uin
211211
i2s_dev->conf2.lcd_en = 1;
212212

213213
// Configure sampling rate
214-
i2s_dev->sample_rate_conf.tx_bck_div_num = 40000000 / clk_freq; // Fws = Fbck / 2
214+
// The datasheet states that Fws = Fbck / (W*2), but empirically storing
215+
// 1 in the register gives the highest value of 20MHz, storing 2 gives
216+
// 10MHz, (and storing 0 causes a freeze instead of acting as though 64 was
217+
// specified).
218+
int div_num = (20000000 + clk_freq - 1) / clk_freq;
219+
if (div_num == 0) {
220+
div_num = 1;
221+
}
222+
if (div_num > 63) {
223+
div_num = 63;
224+
}
225+
i2s_dev->sample_rate_conf.tx_bck_div_num = div_num;
215226
i2s_dev->sample_rate_conf.tx_bits_mod = data_width;
216227
// Configuration data format
217228

0 commit comments

Comments
 (0)