Parcourir la source

Shuffle almost everything around to prepare for better modularity.

Mathias Gottschlag il y a 4 ans
Parent
révision
40ebd607a9
64 fichiers modifiés avec 619 ajouts et 8 suppressions
  1. 7
    5
      .gitignore
  2. 0
    3
      hackamp/hardware/fp-lib-table
  3. 0
    0
      hardware/base/HackAmp-Footprints.pretty/CP_Elec_16x17.5_Nichicon.kicad_mod
  4. 0
    0
      hardware/base/HackAmp-Footprints.pretty/CSRA64215.kicad_mod
  5. 0
    0
      hardware/base/HackAmp-Footprints.pretty/Fuseholder_Littlefuse_NANO2-154.kicad_mod
  6. 0
    0
      hardware/base/HackAmp-Footprints.pretty/Jack_3.5mm_CUI_SJ-435107RS_Horizontal.kicad_mod
  7. 0
    0
      hardware/base/HackAmp-Footprints.pretty/Jack_3.5mm_Switchcraft_35RASMT4BHNTRX_Horizontal.kicad_mod
  8. 0
    0
      hardware/base/HackAmp-Footprints.pretty/LED_0603_1608Metric_SideView_Inolux.kicad_mod
  9. 0
    0
      hardware/base/HackAmp-Footprints.pretty/L_Bourns_SRR1208.kicad_mod
  10. 0
    0
      hardware/base/HackAmp-Footprints.pretty/RotaryEncoder_TTElectronics_EN12-VS_Vertical_L17.5mm.kicad_mod
  11. 0
    0
      hardware/base/HackAmp-Footprints.pretty/SW_Lever_1P2T_E-Switch_SP1T2B4M7QE.kicad_mod
  12. 0
    0
      hardware/base/HackAmp-Footprints.pretty/TAS5760M_Module_Reverse.kicad_mod
  13. 0
    0
      hardware/base/HackAmp-Footprints.pretty/TE_796638-2_1x02_P5.08mm_Horizontal.kicad_mod
  14. 0
    0
      hardware/base/HackAmp-Footprints.pretty/TexasInstruments_DAP32.kicad_mod
  15. 0
    0
      hardware/base/HackAmp-Footprints.pretty/WM8731_Module_Reverse.kicad_mod
  16. 0
    0
      hardware/base/HackAmp-Symbols.kicad_sym
  17. 0
    0
      hardware/base/base-cache.lib
  18. 0
    0
      hardware/base/base.kicad_pcb
  19. 0
    0
      hardware/base/base.kicad_pro
  20. 0
    0
      hardware/base/base.kicad_sch
  21. 0
    0
      hardware/base/bluetooth.kicad_sch
  22. 3
    0
      hardware/base/fp-lib-table
  23. 0
    0
      hardware/base/front.kicad_sch
  24. 0
    0
      hardware/base/headphone-amp.kicad_sch
  25. 0
    0
      hardware/base/power-supply.kicad_sch
  26. 0
    0
      hardware/base/processor.kicad_sch
  27. 0
    0
      hardware/base/speaker-amp.kicad_sch
  28. 0
    0
      hardware/base/sym-lib-table
  29. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/EnclosureEndPlate_1455L1601.kicad_mod
  30. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/LED_0805_2012Metric_ReverseMount.kicad_mod
  31. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_Jack_3.5mm_CUI_SJ-435107.kicad_mod
  32. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_LED_0603_1608Metric_SideView_Inolux.kicad_mod
  33. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_RotaryEncoder_TT_EN12-V_Knob16mm.kicad_mod
  34. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_SW_E-Switch_100SP-M7.kicad_mod
  35. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_SW_PUSH_6mm_Angled.kicad_mod
  36. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_Vishay_Mold.kicad_mod
  37. 0
    0
      hardware/frontpanel/FrontPanel-Footprints.pretty/Vishay_Mold_Reverse.kicad_mod
  38. 0
    0
      hardware/frontpanel/fp-lib-table
  39. 0
    0
      hardware/frontpanel/frontpanel.kicad_pcb
  40. 0
    0
      hardware/frontpanel/frontpanel.kicad_pro
  41. 0
    0
      hardware/frontpanel/frontpanel.kicad_sch
  42. 0
    0
      hardware/speakers/fp-lib-table
  43. 0
    0
      hardware/speakers/speakers.kicad_pcb
  44. 0
    0
      hardware/speakers/speakers.kicad_pro
  45. 0
    0
      hardware/speakers/speakers.kicad_sch
  46. 0
    0
      hardware/speakers/sym-lib-table
  47. 0
    0
      software/debounce-calculator/Cargo.lock
  48. 0
    0
      software/debounce-calculator/Cargo.toml
  49. 0
    0
      software/debounce-calculator/src/main.rs
  50. 0
    0
      software/wired/.cargo/config
  51. 0
    0
      software/wired/Cargo.lock
  52. 0
    0
      software/wired/Cargo.toml
  53. 0
    0
      software/wired/build.rs
  54. 0
    0
      software/wired/memory.x
  55. 0
    0
      software/wired/openocd.cfg
  56. 0
    0
      software/wired/openocd.gdb
  57. 0
    0
      software/wired/rustfmt.toml
  58. 0
    0
      software/wired/src/audio_buffer.rs
  59. 0
    0
      software/wired/src/halext/i2s.rs
  60. 0
    0
      software/wired/src/halext/mod.rs
  61. 609
    0
      software/wired/src/halext/sai.rs
  62. 0
    0
      software/wired/src/main.rs
  63. 0
    0
      software/wired/src/mixer.rs
  64. 0
    0
      software/wired/src/pins.rs

+ 7
- 5
.gitignore Voir le fichier

@@ -2,9 +2,11 @@
2 2
 *.kicad_pcb-bak
3 3
 *.sch-bak
4 4
 *.kicad_prl
5
-/hackamp/firmware/target
6
-/hackamp/hardware/hackamp-backups
7
-/modules/tas5760m-amp-module/tas5760m-amp-module-backups
8
-/frontpanel/frontpanel-backups
9
-/other/debounce-calculator/target
5
+/software/debounce-calculator/target
6
+/software/wired/target
7
+/hardware/base/base-backups
8
+/hardware/wired/wired-backups
9
+/hardware/wireless/wireless-backups
10
+/hardware/speakers/speakers-backups
11
+/hardware/frontpanel/frontpanel-backups
10 12
 fp-info-cache

+ 0
- 3
hackamp/hardware/fp-lib-table Voir le fichier

@@ -1,3 +0,0 @@
1
-(fp_lib_table
2
-  (lib (name HackAmp-Footprints)(type KiCad)(uri ${KIPRJMOD}/HackAmp-Footprints.pretty)(options "")(descr ""))
3
-)

hackamp/hardware/HackAmp-Footprints.pretty/CP_Elec_16x17.5_Nichicon.kicad_mod → hardware/base/HackAmp-Footprints.pretty/CP_Elec_16x17.5_Nichicon.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/CSRA64215.kicad_mod → hardware/base/HackAmp-Footprints.pretty/CSRA64215.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/Fuseholder_Littlefuse_NANO2-154.kicad_mod → hardware/base/HackAmp-Footprints.pretty/Fuseholder_Littlefuse_NANO2-154.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/Jack_3.5mm_CUI_SJ-435107RS_Horizontal.kicad_mod → hardware/base/HackAmp-Footprints.pretty/Jack_3.5mm_CUI_SJ-435107RS_Horizontal.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/Jack_3.5mm_Switchcraft_35RASMT4BHNTRX_Horizontal.kicad_mod → hardware/base/HackAmp-Footprints.pretty/Jack_3.5mm_Switchcraft_35RASMT4BHNTRX_Horizontal.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/LED_0603_1608Metric_SideView_Inolux.kicad_mod → hardware/base/HackAmp-Footprints.pretty/LED_0603_1608Metric_SideView_Inolux.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/L_Bourns_SRR1208.kicad_mod → hardware/base/HackAmp-Footprints.pretty/L_Bourns_SRR1208.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/RotaryEncoder_TTElectronics_EN12-VS_Vertical_L17.5mm.kicad_mod → hardware/base/HackAmp-Footprints.pretty/RotaryEncoder_TTElectronics_EN12-VS_Vertical_L17.5mm.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/SW_Lever_1P2T_E-Switch_SP1T2B4M7QE.kicad_mod → hardware/base/HackAmp-Footprints.pretty/SW_Lever_1P2T_E-Switch_SP1T2B4M7QE.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/TAS5760M_Module_Reverse.kicad_mod → hardware/base/HackAmp-Footprints.pretty/TAS5760M_Module_Reverse.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/TE_796638-2_1x02_P5.08mm_Horizontal.kicad_mod → hardware/base/HackAmp-Footprints.pretty/TE_796638-2_1x02_P5.08mm_Horizontal.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/TexasInstruments_DAP32.kicad_mod → hardware/base/HackAmp-Footprints.pretty/TexasInstruments_DAP32.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Footprints.pretty/WM8731_Module_Reverse.kicad_mod → hardware/base/HackAmp-Footprints.pretty/WM8731_Module_Reverse.kicad_mod Voir le fichier


hackamp/hardware/HackAmp-Symbols.kicad_sym → hardware/base/HackAmp-Symbols.kicad_sym Voir le fichier


hackamp/hardware/hackamp-cache.lib → hardware/base/base-cache.lib Voir le fichier


hackamp/hardware/hackamp.kicad_pcb → hardware/base/base.kicad_pcb Voir le fichier


hackamp/hardware/hackamp.kicad_pro → hardware/base/base.kicad_pro Voir le fichier


hackamp/hardware/hackamp.kicad_sch → hardware/base/base.kicad_sch Voir le fichier


hackamp/hardware/bluetooth.kicad_sch → hardware/base/bluetooth.kicad_sch Voir le fichier


+ 3
- 0
hardware/base/fp-lib-table Voir le fichier

@@ -0,0 +1,3 @@
1
+(fp_lib_table
2
+  (lib (name "HackAmp-Footprints")(type "KiCad")(uri "${KIPRJMOD}/HackAmp-Footprints.pretty")(options "")(descr ""))
3
+)

hackamp/hardware/front.kicad_sch → hardware/base/front.kicad_sch Voir le fichier


hackamp/hardware/headphone-amp.kicad_sch → hardware/base/headphone-amp.kicad_sch Voir le fichier


hackamp/hardware/power-supply.kicad_sch → hardware/base/power-supply.kicad_sch Voir le fichier


hackamp/hardware/processor.kicad_sch → hardware/base/processor.kicad_sch Voir le fichier


hackamp/hardware/speaker-amp.kicad_sch → hardware/base/speaker-amp.kicad_sch Voir le fichier


hackamp/hardware/sym-lib-table → hardware/base/sym-lib-table Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/EnclosureEndPlate_1455L1601.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/EnclosureEndPlate_1455L1601.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/LED_0805_2012Metric_ReverseMount.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/LED_0805_2012Metric_ReverseMount.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/PanelCutout_Jack_3.5mm_CUI_SJ-435107.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_Jack_3.5mm_CUI_SJ-435107.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/PanelCutout_LED_0603_1608Metric_SideView_Inolux.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_LED_0603_1608Metric_SideView_Inolux.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/PanelCutout_RotaryEncoder_TT_EN12-V_Knob16mm.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_RotaryEncoder_TT_EN12-V_Knob16mm.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/PanelCutout_SW_E-Switch_100SP-M7.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_SW_E-Switch_100SP-M7.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/PanelCutout_SW_PUSH_6mm_Angled.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_SW_PUSH_6mm_Angled.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/PanelCutout_Vishay_Mold.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/PanelCutout_Vishay_Mold.kicad_mod Voir le fichier


frontpanel/FrontPanel-Footprints.pretty/Vishay_Mold_Reverse.kicad_mod → hardware/frontpanel/FrontPanel-Footprints.pretty/Vishay_Mold_Reverse.kicad_mod Voir le fichier


frontpanel/fp-lib-table → hardware/frontpanel/fp-lib-table Voir le fichier


frontpanel/frontpanel.kicad_pcb → hardware/frontpanel/frontpanel.kicad_pcb Voir le fichier


frontpanel/frontpanel.kicad_pro → hardware/frontpanel/frontpanel.kicad_pro Voir le fichier


frontpanel/frontpanel.kicad_sch → hardware/frontpanel/frontpanel.kicad_sch Voir le fichier


modules/tas5760m-amp-module/fp-lib-table → hardware/speakers/fp-lib-table Voir le fichier


modules/tas5760m-amp-module/tas5760m-amp-module.kicad_pcb → hardware/speakers/speakers.kicad_pcb Voir le fichier


modules/tas5760m-amp-module/tas5760m-amp-module.kicad_pro → hardware/speakers/speakers.kicad_pro Voir le fichier


modules/tas5760m-amp-module/tas5760m-amp-module.kicad_sch → hardware/speakers/speakers.kicad_sch Voir le fichier


modules/tas5760m-amp-module/sym-lib-table → hardware/speakers/sym-lib-table Voir le fichier


other/debounce-calculator/Cargo.lock → software/debounce-calculator/Cargo.lock Voir le fichier


other/debounce-calculator/Cargo.toml → software/debounce-calculator/Cargo.toml Voir le fichier


other/debounce-calculator/src/main.rs → software/debounce-calculator/src/main.rs Voir le fichier


hackamp/firmware/.cargo/config → software/wired/.cargo/config Voir le fichier


hackamp/firmware/Cargo.lock → software/wired/Cargo.lock Voir le fichier


hackamp/firmware/Cargo.toml → software/wired/Cargo.toml Voir le fichier


hackamp/firmware/build.rs → software/wired/build.rs Voir le fichier


hackamp/firmware/memory.x → software/wired/memory.x Voir le fichier


hackamp/firmware/openocd.cfg → software/wired/openocd.cfg Voir le fichier


hackamp/firmware/openocd.gdb → software/wired/openocd.gdb Voir le fichier


hackamp/firmware/rustfmt.toml → software/wired/rustfmt.toml Voir le fichier


hackamp/firmware/src/audio_buffer.rs → software/wired/src/audio_buffer.rs Voir le fichier


hackamp/firmware/src/halext/i2s.rs → software/wired/src/halext/i2s.rs Voir le fichier


hackamp/firmware/src/halext/mod.rs → software/wired/src/halext/mod.rs Voir le fichier


+ 609
- 0
software/wired/src/halext/sai.rs Voir le fichier

@@ -0,0 +1,609 @@
1
+//! SAI interface with DMA data transfer.
2
+
3
+// TODO: Unify capitalization of template parameters.
4
+
5
+use core::marker::PhantomData;
6
+use core::ops::Deref;
7
+
8
+use stm32f4xx_hal::gpio::gpiod::PD6;
9
+use stm32f4xx_hal::gpio::gpioe::{PE2, PE3, PE4, PE5, PE6};
10
+use stm32f4xx_hal::gpio::gpiof::{PF6, PF7, PF8, PF9};
11
+use stm32f4xx_hal::gpio::{Alternate, AF6};
12
+use stm32f4xx_hal::stm32::sai::CH;
13
+use stm32f4xx_hal::stm32::{RCC, SAI};
14
+
15
+use super::i2s::I2SClocks;
16
+
17
+struct NoMck;
18
+
19
+/// Trait for master clock pins.
20
+pub trait PinMck<Block> {}
21
+impl PinMck<SAIA> for PE2<Alternate<AF6>> {}
22
+impl PinMck<SAIB> for PF7<Alternate<AF6>> {}
23
+impl<Block> PinMck<Block> for NoMck {}
24
+
25
+/// Trait for frame select pins.
26
+pub trait PinFs<Block> {}
27
+impl PinFs<SAIA> for PE4<Alternate<AF6>> {}
28
+impl PinFs<SAIB> for PF9<Alternate<AF6>> {}
29
+
30
+/// Trait for bit clock pins.
31
+pub trait PinSck<Block> {}
32
+impl PinSck<SAIA> for PE5<Alternate<AF6>> {}
33
+impl PinSck<SAIB> for PF8<Alternate<AF6>> {}
34
+
35
+/// Trait for data pins.
36
+pub trait PinSd<Block> {}
37
+impl PinSd<SAIA> for PD6<Alternate<AF6>> {}
38
+impl PinSd<SAIA> for PE6<Alternate<AF6>> {}
39
+impl PinSd<SAIB> for PE3<Alternate<AF6>> {}
40
+impl PinSd<SAIB> for PF6<Alternate<AF6>> {}
41
+
42
+/// Pins required for an asynchronous SAI master channel.
43
+pub trait MasterPins<Block> {}
44
+
45
+impl<Block, MCK, FS, SCK, SD> MasterPins<Block> for (MCK, FS, SCK, SD)
46
+where
47
+    MCK: PinMck<Block>,
48
+    FS: PinFs<Block>,
49
+    SCK: PinSck<Block>,
50
+    SD: PinSd<Block>,
51
+{
52
+}
53
+
54
+/// Pins required for an asynchronous SAI slave channel.
55
+pub trait SlavePins<Block> {}
56
+
57
+impl<Block, MCK, FS, SCK, SD> SlavePins<Block> for (MCK, FS, SCK, SD)
58
+where
59
+    MCK: PinMck<Block>,
60
+    FS: PinFs<Block>,
61
+    SCK: PinSck<Block>,
62
+    SD: PinSd<Block>,
63
+{
64
+}
65
+
66
+// TODO: SAIA is on Channel 0, Stream 1 and 3.
67
+// TODO: SAIB is on Channel 0, Stream 5 and Channel 1, Stream 4.
68
+
69
+/// Asynchronous SAI sub-block which has not yet been configured.
70
+///
71
+/// Asynchronous means that the sub-block has its own set of clock pins.
72
+pub struct Asynchronous;
73
+
74
+/// Asynchronous SAI sub-block which as been configured as a master.
75
+pub struct AsyncMaster<Pins> {
76
+    pins: Pins,
77
+}
78
+
79
+/// Asynchronous SAI sub-block which as been configured as a slave.
80
+pub struct AsyncSlave<Pins> {
81
+    pins: Pins,
82
+}
83
+
84
+/// Synchronous SAI sub-block.
85
+///
86
+/// Synchronous sub-blocks are always configured as slaves.
87
+pub struct Synchronous;
88
+
89
+/// SAI sub-block which has neither been configured as a receiver nor as a transmitter.
90
+pub struct NoDir;
91
+
92
+/// SAI sub-block which has been configured as a receiver.
93
+pub struct Receive;
94
+
95
+/// SAI sub-block which has been configured as a transmitter.
96
+pub struct Transmit;
97
+
98
+/// "A" channel of the SAI.
99
+pub struct SAIA;
100
+
101
+impl Deref for SAIA {
102
+    type Target = CH;
103
+
104
+    fn deref(&self) -> &Self::Target {
105
+        unsafe { &(*SAI::ptr()).cha }
106
+    }
107
+}
108
+
109
+/// "B" channel of the SAI.
110
+pub struct SAIB;
111
+
112
+impl Deref for SAIB {
113
+    type Target = CH;
114
+
115
+    fn deref(&self) -> &Self::Target {
116
+        unsafe { &(*SAI::ptr()).chb }
117
+    }
118
+}
119
+
120
+/// Wrapper for a single channel of the SAI and its configuration.
121
+pub struct SubBlock<Channel, Config, Direction> {
122
+    channel: Channel,
123
+    config: Config,
124
+    direction: Direction,
125
+}
126
+
127
+/// Functions to configure the two sub-blocks of an SAI instance.
128
+///
129
+/// For the two sub-blocks of a single SAI instance, only specific combinations of modes are valid.
130
+/// This trait has one method for each such combination.
131
+pub trait SAIExt {
132
+    /// Splits the SAI instance into two asynchronous sub-blocks.
133
+    fn split(
134
+        self,
135
+    ) -> (
136
+        SubBlock<SAIA, Asynchronous, NoDir>,
137
+        SubBlock<SAIB, Asynchronous, NoDir>,
138
+    )
139
+    where
140
+        Self: Sized;
141
+
142
+    /// Splits the SAI instance so that the A block uses the synchronization signals of the B
143
+    /// block.
144
+    fn split_sync_a(
145
+        self,
146
+    ) -> (
147
+        SubBlock<SAIA, Synchronous, NoDir>,
148
+        SubBlock<SAIB, Asynchronous, NoDir>,
149
+    )
150
+    where
151
+        Self: Sized;
152
+
153
+    /// Splits the SAI instance so that the B block uses the synchronization signals of the A
154
+    /// block.
155
+    fn split_sync_b(
156
+        self,
157
+    ) -> (
158
+        SubBlock<SAIA, Asynchronous, NoDir>,
159
+        SubBlock<SAIB, Synchronous, NoDir>,
160
+    )
161
+    where
162
+        Self: Sized;
163
+
164
+    /*/// Un-splits the two sub-blocks and resets the SAI.
165
+    fn uninit<ConfigA, ConfigB>(a: SubBlock<SAIA, ConfigA>, b: SubBlock<SAIB, ConfigB>) -> Self
166
+    where
167
+        Self: Sized;*/
168
+
169
+    /// Enables and resets the SAI instance.
170
+    fn reset(&mut self);
171
+}
172
+
173
+impl SAIExt for SAI {
174
+    fn split(
175
+        mut self,
176
+    ) -> (
177
+        SubBlock<SAIA, Asynchronous, NoDir>,
178
+        SubBlock<SAIB, Asynchronous, NoDir>,
179
+    )
180
+    where
181
+        Self: Sized,
182
+    {
183
+        self.reset();
184
+        (
185
+            SubBlock {
186
+                channel: SAIA,
187
+                config: Asynchronous,
188
+                direction: NoDir,
189
+            },
190
+            SubBlock {
191
+                channel: SAIB,
192
+                config: Asynchronous,
193
+                direction: NoDir,
194
+            },
195
+        )
196
+    }
197
+
198
+    fn split_sync_a(
199
+        mut self,
200
+    ) -> (
201
+        SubBlock<SAIA, Synchronous, NoDir>,
202
+        SubBlock<SAIB, Asynchronous, NoDir>,
203
+    )
204
+    where
205
+        Self: Sized,
206
+    {
207
+        self.reset();
208
+        (
209
+            SubBlock {
210
+                channel: SAIA,
211
+                config: Synchronous,
212
+                direction: NoDir,
213
+            },
214
+            SubBlock {
215
+                channel: SAIB,
216
+                config: Asynchronous,
217
+                direction: NoDir,
218
+            },
219
+        )
220
+    }
221
+
222
+    fn split_sync_b(
223
+        mut self,
224
+    ) -> (
225
+        SubBlock<SAIA, Asynchronous, NoDir>,
226
+        SubBlock<SAIB, Synchronous, NoDir>,
227
+    )
228
+    where
229
+        Self: Sized,
230
+    {
231
+        self.reset();
232
+        (
233
+            SubBlock {
234
+                channel: SAIA,
235
+                config: Asynchronous,
236
+                direction: NoDir,
237
+            },
238
+            SubBlock {
239
+                channel: SAIB,
240
+                config: Synchronous,
241
+                direction: NoDir,
242
+            },
243
+        )
244
+    }
245
+
246
+    /*fn uninit<ConfigA, ConfigB>(a: SubBlock<SAIA, ConfigA>, b: SubBlock<SAIB, ConfigB>) -> Self {
247
+        // TODO
248
+    }*/
249
+
250
+    fn reset(&mut self) {
251
+        let rcc = unsafe { &*RCC::ptr() };
252
+        rcc.apb2enr.modify(|_, w| w.sai1en().set_bit());
253
+        rcc.apb2rstr.modify(|_, w| w.sai1rst().set_bit());
254
+        rcc.apb2rstr.modify(|_, w| w.sai1rst().clear_bit());
255
+    }
256
+}
257
+
258
+impl<Channel> SubBlock<Channel, Asynchronous, NoDir>
259
+where
260
+    Channel: Deref<Target = CH>,
261
+{
262
+    /// Configures the channel as a master and a receiver.
263
+    pub fn master_rx<Pins>(self, pins: Pins) -> SubBlock<Channel, AsyncMaster<Pins>, Receive>
264
+    where
265
+        Pins: MasterPins<Channel>,
266
+    {
267
+        // TODO: Clock/data type configuration?
268
+        SubBlock {
269
+            channel: self.channel,
270
+            config: AsyncMaster { pins },
271
+            direction: Receive,
272
+        }
273
+    }
274
+
275
+    /// Configures the channel as a master and a receiver.
276
+    pub fn master_tx<Pins>(self, pins: Pins) -> SubBlock<Channel, AsyncMaster<Pins>, Transmit>
277
+    where
278
+        Pins: MasterPins<Channel>,
279
+    {
280
+        // TODO: Clock/data type configuration?
281
+        SubBlock {
282
+            channel: self.channel,
283
+            config: AsyncMaster { pins },
284
+            direction: Transmit,
285
+        }
286
+    }
287
+
288
+    /// Configures the channel as a slave and a receiver.
289
+    pub fn slave_rx<Pins>(self, pins: Pins) -> SubBlock<Channel, AsyncSlave<Pins>, Receive>
290
+    where
291
+        Pins: SlavePins<Channel>,
292
+    {
293
+        // TODO: Data type configuration?
294
+        SubBlock {
295
+            channel: self.channel,
296
+            config: AsyncSlave { pins },
297
+            direction: Receive,
298
+        }
299
+    }
300
+
301
+    /// Configures the channel as a master and a receiver.
302
+    pub fn slave_tx<Pins>(self, pins: Pins) -> SubBlock<Channel, AsyncSlave<Pins>, Transmit>
303
+    where
304
+        Pins: SlavePins<Channel>,
305
+    {
306
+        // TODO: Data type configuration?
307
+        SubBlock {
308
+            channel: self.channel,
309
+            config: AsyncSlave { pins },
310
+            direction: Transmit,
311
+        }
312
+    }
313
+}
314
+
315
+impl<Channel, Config> SubBlock<Channel, Config, Receive>
316
+where
317
+    Channel: Deref<Target = CH>,
318
+{
319
+    // TODO
320
+}
321
+
322
+impl<Channel, Config> SubBlock<Channel, Config, Transmit>
323
+where
324
+    Channel: Deref<Target = CH>,
325
+{
326
+    // TODO
327
+}
328
+
329
+/// Wrapper around `Receive` and `Transmit` blocks to provide full-duplex I2S transfers.
330
+pub struct Duplex<Channel1, Config1, Channel2, Config2> {
331
+    rx: SubBlock<Channel1, Config1, Receive>,
332
+    tx: SubBlock<Channel2, Config2, Transmit>,
333
+}
334
+
335
+impl<Channel1, Config1, Channel2, Config2> Duplex<Channel1, Config1, Channel2, Config2>
336
+where
337
+    Channel1: Deref<Target = CH>,
338
+    Channel2: Deref<Target = CH>,
339
+{
340
+    /// Wraps the specified receiver/transmitter objects.
341
+    pub fn new(
342
+        rx: SubBlock<Channel1, Config1, Receive>,
343
+        tx: SubBlock<Channel2, Config2, Transmit>,
344
+    ) -> Self {
345
+        // TODO
346
+        Self { rx, tx }
347
+    }
348
+
349
+    pub fn try_read(&mut self) -> nb::Result<(u32, u32), Self::Error> {
350
+        // TODO
351
+    }
352
+
353
+    pub fn try_send(&mut self) -> nb::Result<(u32, u32), Self::Error> {
354
+        // TODO
355
+    }
356
+}
357
+
358
+/*impl<
359
+        SAIX: SAIExt<SAIX>,
360
+        RxBlockInner: SubBlock<SAI = SAIX>,
361
+        RxBlock: SubBlockConfig<SubBlock = RxBlockInner>,
362
+        TxBlockInner: SubBlock<SAI = SAIX>,
363
+        TxBlock: SubBlockConfig<SubBlock = TxBlockInner>,
364
+    > Duplex<SAIX, RxBlockInner, RxBlock, TxBlockInner, TxBlock>
365
+{
366
+    /// Wraps the specified receiver/transmitter objects.
367
+    pub fn new(rx: Receive<RxBlock>, tx: Transmit<TxBlock>) -> Self {
368
+        // TODO
369
+        Self {
370
+            rx,
371
+            tx,
372
+            _rx_inner: PhantomData,
373
+            _tx_inner: PhantomData,
374
+        }
375
+    }
376
+
377
+    /// Starts transmitting and receiving data.
378
+    ///
379
+    /// For I2S masters, this function starts the clock signals.
380
+    pub fn start(&mut self) {
381
+        // TODO
382
+    }
383
+
384
+    /// Stops transmitting and receiving data.
385
+    pub fn stop(&mut self) {
386
+        // TODO
387
+    }
388
+}*/
389
+
390
+/*// Use cases:
391
+// - SAI should be usable as two simplex I2S interfaces, both either slave or master.
392
+// - SAI should be usable as one duplex I2S interface, either as slave or master.
393
+// - SAI should be usable as two simple I2S interfaces with synchronization
394
+
395
+/// Mode of an SAI sub-block (sync/async, master/slave).
396
+pub trait SubBlockConfig {
397
+    type SubBlock: SubBlock;
398
+    // TODO
399
+}
400
+
401
+/// SAI block configured to use the synchronization signals of its asynchronous sibling block.
402
+pub struct Synchronous<Block> {
403
+    block: Block,
404
+}
405
+
406
+impl<Block> Synchronous<Block>
407
+where
408
+    Block: SubBlock,
409
+{
410
+    /// Configures this sub-block as a slave.
411
+    pub fn slave<SDPin: SD<Block>>(mut self, sd: SDPin) -> SyncSlave<Block, SDPin> {
412
+        self.block.set_slave();
413
+        SyncSlave {
414
+            block: self.block,
415
+            sd,
416
+        }
417
+    }
418
+}
419
+
420
+/// SAI sub-block configured as a synchronous slave.
421
+pub struct SyncSlave<Block, SDPin> {
422
+    block: Block,
423
+    sd: SDPin,
424
+    // TODO
425
+}
426
+
427
+impl<Block, SDPin> SyncSlave<Block, SDPin> {
428
+    /// Uninitializes the sub-block, releasing the pins.
429
+    pub fn destroy(self) -> (Asynchronous<Block>, SDPin) {
430
+        // TODO: Disable?
431
+        (Asynchronous { block: self.block }, self.sd)
432
+    }
433
+}
434
+
435
+impl<Block, SDPin> SubBlockConfig for SyncSlave<Block, SDPin>
436
+where
437
+    Block: SubBlock,
438
+{
439
+    type SubBlock = Block;
440
+    // TODO
441
+}
442
+
443
+/// SAI block configured to provide its own synchronization signals (either as inputs in the case
444
+/// o a slave or via a clock generator in the case of a master).
445
+pub struct Asynchronous<Block> {
446
+    block: Block,
447
+}
448
+
449
+impl<Block> Asynchronous<Block>
450
+where
451
+    Block: SubBlock,
452
+{
453
+    /// Configures this sub-block as a master.
454
+    pub fn master<MCKPin, FSPin, SCKPin, SDPin>(
455
+        mut self,
456
+        mck: MCKPin,
457
+        fs: FSPin,
458
+        sck: SCKPin,
459
+        sd: SDPin,
460
+        _clocks: I2SClocks,
461
+    ) -> AsyncMaster<Block, MCKPin, FSPin, SCKPin, SDPin>
462
+    where
463
+        MCKPin: MCK<Block>,
464
+        FSPin: FS<Block>,
465
+        SCKPin: SCK<Block>,
466
+        SDPin: SD<Block>,
467
+    {
468
+        self.block.set_master();
469
+        AsyncMaster {
470
+            block: self.block,
471
+            mck,
472
+            fs,
473
+            sck,
474
+            sd,
475
+        }
476
+    }
477
+
478
+    /// Configures this sub-block as a slave.
479
+    pub fn slave<FSPin, SCKPin, SDPin>(
480
+        mut self,
481
+        fs: FSPin,
482
+        sck: SCKPin,
483
+        sd: SDPin,
484
+    ) -> AsyncSlave<Block, FSPin, SCKPin, SDPin>
485
+    where
486
+        FSPin: FS<Block>,
487
+        SCKPin: SCK<Block>,
488
+        SDPin: SD<Block>,
489
+    {
490
+        self.block.set_slave();
491
+        AsyncSlave {
492
+            block: self.block,
493
+            fs,
494
+            sck,
495
+            sd,
496
+        }
497
+    }
498
+}
499
+
500
+/// SAI sub-block configured as a master.
501
+pub struct AsyncMaster<Block, MCKPin, FSPin, SCKPin, SDPin> {
502
+    block: Block,
503
+    mck: MCKPin,
504
+    fs: FSPin,
505
+    sck: SCKPin,
506
+    sd: SDPin,
507
+}
508
+
509
+impl<Block, MCKPin, FSPin, SCKPin, SDPin> AsyncMaster<Block, MCKPin, FSPin, SCKPin, SDPin> {
510
+    /// Uninitializes the sub-block, releasing the pins.
511
+    pub fn destroy(self) -> (Asynchronous<Block>, MCKPin, FSPin, SCKPin, SDPin) {
512
+        // TODO: Disable?
513
+        (
514
+            Asynchronous { block: self.block },
515
+            self.mck,
516
+            self.fs,
517
+            self.sck,
518
+            self.sd,
519
+        )
520
+    }
521
+}
522
+
523
+impl<Block, MCKPin, FSPin, SCKPin, SDPin> SubBlockConfig
524
+    for AsyncMaster<Block, MCKPin, FSPin, SCKPin, SDPin>
525
+where
526
+    Block: SubBlock,
527
+{
528
+    type SubBlock = Block;
529
+    // TODO
530
+}
531
+
532
+/// SAI sub-block configured as an asynchronous slave.
533
+pub struct AsyncSlave<Block, FSPin, SCKPin, SDPin> {
534
+    block: Block,
535
+    fs: FSPin,
536
+    sck: SCKPin,
537
+    sd: SDPin,
538
+}
539
+
540
+impl<Block, FSPin, SCKPin, SDPin> AsyncSlave<Block, FSPin, SCKPin, SDPin> {
541
+    /// Uninitializes the sub-block, releasing the pins.
542
+    pub fn destroy(self) -> (Asynchronous<Block>, FSPin, SCKPin, SDPin) {
543
+        // TODO: Disable?
544
+        (
545
+            Asynchronous { block: self.block },
546
+            self.fs,
547
+            self.sck,
548
+            self.sd,
549
+        )
550
+    }
551
+}
552
+
553
+impl<Block, FSPin, SCKPin, SDPin> SubBlockConfig for AsyncSlave<Block, FSPin, SCKPin, SDPin>
554
+where
555
+    Block: SubBlock,
556
+{
557
+    type SubBlock = Block;
558
+    // TODO
559
+}
560
+
561
+/// SAI sub-block configured as a transmitter.
562
+pub struct Transmit<Block: SubBlockConfig> {
563
+    block: Block,
564
+}
565
+
566
+impl<Block: SubBlockConfig> Transmit<Block> {
567
+    /// Initializes the sub-block as a transmitter.
568
+    pub fn new(block: Block) -> Self {
569
+        // TODO: Configuration.
570
+        Self { block }
571
+    }
572
+
573
+    /// Starts transmitting data.
574
+    ///
575
+    /// For I2S masters, this function starts the clock signals.
576
+    pub fn start(&mut self) {
577
+        // TODO
578
+    }
579
+
580
+    /// Stops transmitting data.
581
+    pub fn stop(&mut self) {
582
+        // TODO
583
+    }
584
+}
585
+
586
+/// SAI sub-block configured as a receiver.
587
+pub struct Receive<Block: SubBlockConfig> {
588
+    block: Block,
589
+}
590
+
591
+impl<Block: SubBlockConfig> Receive<Block> {
592
+    /// Initializes the sub-block as a receiver.
593
+    pub fn new(block: Block) -> Self {
594
+        // TODO: Configuration.
595
+        Self { block }
596
+    }
597
+
598
+    /// Starts receiving data.
599
+    ///
600
+    /// For I2S masters, this function starts the clock signals.
601
+    pub fn start(&mut self) {
602
+        // TODO
603
+    }
604
+
605
+    /// Stops receiving data.
606
+    pub fn stop(&mut self) {
607
+        // TODO
608
+    }
609
+}*/

hackamp/firmware/src/main.rs → software/wired/src/main.rs Voir le fichier


hackamp/firmware/src/mixer.rs → software/wired/src/mixer.rs Voir le fichier


hackamp/firmware/src/pins.rs → software/wired/src/pins.rs Voir le fichier


Loading…
Annuler
Enregistrer