1818CONF_DOUT_PIN = "dout_pin"
1919CONF_SAMPLE_RATE = "sample_rate"
2020CONF_BITS_PER_SAMPLE = "bits_per_sample"
21+ CONF_MCLK_MULTIPLE = "mclk_multiple"
2122CONF_DMA_BUF_COUNT = "dma_buf_count"
2223CONF_DMA_BUF_LEN = "dma_buf_len"
2324CONF_USE_APLL = "use_apll"
3132 "right" : i2s_channel_fmt_t .I2S_CHANNEL_FMT_ONLY_RIGHT ,
3233}
3334
35+
36+ def validate_mclk_divisible_by_3 (config ):
37+ if config [CONF_BITS_PER_SAMPLE ] == 24 and config [CONF_MCLK_MULTIPLE ] % 3 != 0 :
38+ raise cv .Invalid (
39+ f"{ CONF_MCLK_MULTIPLE } must be divisible by 3 when bits per sample is 24"
40+ )
41+ return config
42+
43+
3444CONFIG_SCHEMA = cv .All (
3545 cv .Schema (
3646 {
4151 cv .Optional (CONF_DOUT_PIN ): pins .internal_gpio_output_pin_schema ,
4252 cv .Optional (CONF_SAMPLE_RATE , 48000 ): cv .positive_not_null_int ,
4353 cv .Optional (CONF_BITS_PER_SAMPLE , 32 ): cv .one_of (8 , 16 , 24 , 32 , int = True ),
54+ cv .Optional (CONF_MCLK_MULTIPLE , default = 256 ):
55+ cv .one_of (128 , 192 , 256 , 384 , 512 , 576 , 768 , 1024 , 1152 , int = True ),
4456 cv .Optional (CONF_DMA_BUF_COUNT , 8 ): cv .positive_not_null_int ,
4557 cv .Optional (CONF_DMA_BUF_LEN , 256 ): cv .positive_not_null_int ,
4658 cv .Optional (CONF_USE_APLL , False ): cv .boolean ,
4961 }
5062 ).extend (cv .COMPONENT_SCHEMA ),
5163 cv .has_at_least_one_key (CONF_DIN_PIN , CONF_DOUT_PIN ),
64+ validate_mclk_divisible_by_3
5265)
5366
5467
@@ -69,6 +82,7 @@ async def to_code(config):
6982 cg .add (var .set_dout_pin (dout_pin ))
7083 cg .add (var .set_sample_rate (config [CONF_SAMPLE_RATE ]))
7184 cg .add (var .set_bits_per_sample (config [CONF_BITS_PER_SAMPLE ]))
85+ cg .add (var .set_mclk_multiple (config [CONF_MCLK_MULTIPLE ]))
7286 cg .add (var .set_dma_buf_count (config [CONF_DMA_BUF_COUNT ]))
7387 cg .add (var .set_dma_buf_len (config [CONF_DMA_BUF_LEN ]))
7488 cg .add (var .set_use_apll (config [CONF_USE_APLL ]))
0 commit comments