@@ -26,8 +26,17 @@ pub(super) mod config {
26
26
clk_cfg : TdmClkConfig ,
27
27
28
28
/// TDM mode channel slot configuration.
29
+ #[ cfg( esp_idf_version_major = "4" ) ]
29
30
slot_cfg : TdmSlotConfig ,
30
31
32
+ /// TDM mode channel rx slot configuration.
33
+ #[ cfg( not( esp_idf_version_major = "4" ) ) ]
34
+ pub ( super ) slot_rx_cfg : Option < TdmSlotConfig > ,
35
+
36
+ /// TDM mode channel tx slot configuration.
37
+ #[ cfg( not( esp_idf_version_major = "4" ) ) ]
38
+ pub ( super ) slot_tx_cfg : Option < TdmSlotConfig > ,
39
+
31
40
/// TDM mode channel data configuration.
32
41
#[ cfg( not( esp_idf_version_major = "4" ) ) ]
33
42
gpio_cfg : TdmGpioConfig ,
@@ -40,14 +49,21 @@ pub(super) mod config {
40
49
pub fn new (
41
50
channel_cfg : Config ,
42
51
clk_cfg : TdmClkConfig ,
43
- slot_cfg : TdmSlotConfig ,
52
+ #[ cfg( esp_idf_version_major = "4" ) ] slot_cfg : TdmSlotConfig ,
53
+ #[ cfg( not( esp_idf_version_major = "4" ) ) ] slot_rx_cfg : Option < TdmSlotConfig > ,
54
+ #[ cfg( not( esp_idf_version_major = "4" ) ) ] slot_tx_cfg : Option < TdmSlotConfig > ,
44
55
#[ cfg( not( esp_idf_version_major = "4" ) ) ] gpio_cfg : TdmGpioConfig ,
45
56
) -> Self {
46
57
Self {
47
58
channel_cfg,
48
59
clk_cfg,
60
+ #[ cfg( esp_idf_version_major = "4" ) ]
49
61
slot_cfg,
50
62
#[ cfg( not( esp_idf_version_major = "4" ) ) ]
63
+ slot_rx_cfg,
64
+ #[ cfg( not( esp_idf_version_major = "4" ) ) ]
65
+ slot_tx_cfg,
66
+ #[ cfg( not( esp_idf_version_major = "4" ) ) ]
51
67
gpio_cfg,
52
68
}
53
69
}
@@ -62,12 +78,23 @@ pub(super) mod config {
62
78
dout : Option < PeripheralRef < ' d , impl OutputPin > > ,
63
79
mclk : Option < PeripheralRef < ' d , impl InputPin + OutputPin > > ,
64
80
ws : PeripheralRef < ' d , impl InputPin + OutputPin > ,
65
- ) -> i2s_tdm_config_t {
66
- i2s_tdm_config_t {
67
- clk_cfg : self . clk_cfg . as_sdk ( ) ,
68
- slot_cfg : self . slot_cfg . as_sdk ( ) ,
69
- gpio_cfg : self . gpio_cfg . as_sdk ( bclk, din, dout, mclk, ws) ,
70
- }
81
+ ) -> ( Option < i2s_tdm_config_t > , Option < i2s_tdm_config_t > ) {
82
+ let clk_cfg = self . clk_cfg . as_sdk ( ) ;
83
+ let gpio_cfg = self . gpio_cfg . as_sdk ( bclk, din, dout, mclk, ws) ;
84
+
85
+ let rx = self . slot_rx_cfg . map ( |slot_cfg| i2s_tdm_config_t {
86
+ clk_cfg,
87
+ slot_cfg : slot_cfg. as_sdk ( ) ,
88
+ gpio_cfg,
89
+ } ) ;
90
+
91
+ let tx = self . slot_tx_cfg . map ( |slot_cfg| i2s_tdm_config_t {
92
+ clk_cfg,
93
+ slot_cfg : slot_cfg. as_sdk ( ) ,
94
+ gpio_cfg,
95
+ } ) ;
96
+
97
+ ( rx, tx)
71
98
}
72
99
73
100
/// Convert to the ESP-IDF SDK `i2s_driver_config_t` representation.
@@ -984,27 +1011,32 @@ impl<'d, Dir> I2sDriver<'d, Dir> {
984
1011
mclk : Option < impl Peripheral < P = impl InputPin + OutputPin > + ' d > ,
985
1012
ws : impl Peripheral < P = impl InputPin + OutputPin > + ' d ,
986
1013
) -> Result < Self , EspError > {
1014
+ // Check that the configuration is correct for the selected mode
1015
+ if rx && config. slot_rx_cfg . is_none ( ) || tx && config. slot_tx_cfg . is_none ( ) {
1016
+ return Err ( EspError :: from_infallible :: < ESP_ERR_INVALID_ARG > ( ) ) ;
1017
+ }
1018
+
987
1019
let chan_cfg = config. channel_cfg . as_sdk ( I2S :: port ( ) ) ;
988
1020
989
1021
let this = Self :: internal_new :: < I2S > ( & chan_cfg, rx, tx) ?;
990
1022
991
1023
// Create the channel configuration.
992
- let tdm_config = config. as_sdk (
1024
+ let ( tdm_rx_config , tdm_tx_config ) = config. as_sdk (
993
1025
bclk. into_ref ( ) ,
994
1026
din. map ( |d_in| d_in. into_ref ( ) ) ,
995
1027
dout. map ( |d_out| d_out. into_ref ( ) ) ,
996
1028
mclk. map ( |m_clk| m_clk. into_ref ( ) ) ,
997
1029
ws. into_ref ( ) ,
998
1030
) ;
999
1031
1000
- if rx {
1032
+ if let Some ( tdm_config ) = tdm_rx_config {
1001
1033
unsafe {
1002
1034
// Open the RX channel.
1003
1035
esp ! ( i2s_channel_init_tdm_mode( this. rx_handle, & tdm_config) ) ?;
1004
1036
}
1005
1037
}
1006
1038
1007
- if tx {
1039
+ if let Some ( tdm_config ) = tdm_tx_config {
1008
1040
unsafe {
1009
1041
// Open the TX channel.
1010
1042
esp ! ( i2s_channel_init_tdm_mode( this. tx_handle, & tdm_config) ) ?;
0 commit comments