11-- ----------------------------------------------------------------------------
22-- --
3- -- Copyright (C) 2015, AdaCore --
3+ -- Copyright (C) 2015-2026 , AdaCore --
44-- --
55-- Redistribution and use in source and binary forms, with or without --
66-- modification, are permitted provided that the following conditions are --
@@ -115,11 +115,9 @@ package body STM32.DAC is
115115 when DAC_Resolution_12_Bits =>
116116 case Alignment is
117117 when Left_Aligned =>
118- This.DHR12L1.DACC1DHR :=
119- UInt12 (Value and Max_12bit_Resolution);
118+ This.DHR12L1.DACC1DHR := UInt12 (Value and Max_12bit_Resolution);
120119 when Right_Aligned =>
121- This.DHR12R1.DACC1DHR :=
122- UInt12 (Value and Max_12bit_Resolution);
120+ This.DHR12R1.DACC1DHR := UInt12 (Value and Max_12bit_Resolution);
123121 end case ;
124122 when DAC_Resolution_8_Bits =>
125123 This.DHR8R1.DACC1DHR := UInt8 (Value and Max_8bit_Resolution);
@@ -130,11 +128,9 @@ package body STM32.DAC is
130128 when DAC_Resolution_12_Bits =>
131129 case Alignment is
132130 when Left_Aligned =>
133- This.DHR12L2.DACC2DHR :=
134- UInt12 (Value and Max_12bit_Resolution);
131+ This.DHR12L2.DACC2DHR := UInt12 (Value and Max_12bit_Resolution);
135132 when Right_Aligned =>
136- This.DHR12R2.DACC2DHR :=
137- UInt12 (Value and Max_12bit_Resolution);
133+ This.DHR12R2.DACC2DHR := UInt12 (Value and Max_12bit_Resolution);
138134 end case ;
139135 when DAC_Resolution_8_Bits =>
140136 This.DHR8R2.DACC2DHR := UInt8 (Value and Max_8bit_Resolution);
@@ -143,6 +139,35 @@ package body STM32.DAC is
143139 end case ;
144140 end Set_Output ;
145141
142+ -- ---------------------------
143+ -- Set_Dual_Channel_Output --
144+ -- ---------------------------
145+
146+ procedure Set_Dual_Channel_Output
147+ (This : in out Digital_To_Analog_Converter;
148+ Channel_2_Data : UInt16;
149+ Channel_1_Data : UInt16;
150+ Resolution : DAC_Resolution;
151+ Alignment : Data_Alignment)
152+ is
153+ begin
154+ -- See RM0385 Rev 8, sections 16.5.9 .. 16.5.11 for these registers
155+ case Resolution is
156+ when DAC_Resolution_12_Bits =>
157+ case Alignment is
158+ when Left_Aligned =>
159+ This.DHR12LD.DACC2DHR := UInt12 (Channel_2_Data and Max_12bit_Resolution);
160+ This.DHR12LD.DACC1DHR := UInt12 (Channel_1_Data and Max_12bit_Resolution);
161+ when Right_Aligned =>
162+ This.DHR12RD.DACC2DHR := UInt12 (Channel_2_Data and Max_12bit_Resolution);
163+ This.DHR12RD.DACC1DHR := UInt12 (Channel_1_Data and Max_12bit_Resolution);
164+ end case ;
165+ when DAC_Resolution_8_Bits =>
166+ This.DHR8RD.DACC2DHR := UInt8 (Channel_2_Data and Max_8bit_Resolution);
167+ This.DHR8RD.DACC1DHR := UInt8 (Channel_1_Data and Max_8bit_Resolution);
168+ end case ;
169+ end Set_Dual_Channel_Output ;
170+
146171 -- ----------------------------------
147172 -- Trigger_Conversion_By_Software --
148173 -- ----------------------------------
@@ -194,21 +219,15 @@ package body STM32.DAC is
194219 when DAC_Resolution_12_Bits =>
195220 case Alignment is
196221 when Left_Aligned =>
197- This.DHR12LD.DACC1DHR :=
198- UInt12 (Channel_1_Value and Max_12bit_Resolution);
199- This.DHR12LD.DACC2DHR :=
200- UInt12 (Channel_2_Value and Max_12bit_Resolution);
222+ This.DHR12LD.DACC1DHR := UInt12 (Channel_1_Value and Max_12bit_Resolution);
223+ This.DHR12LD.DACC2DHR := UInt12 (Channel_2_Value and Max_12bit_Resolution);
201224 when Right_Aligned =>
202- This.DHR12RD.DACC1DHR :=
203- UInt12 (Channel_1_Value and Max_12bit_Resolution);
204- This.DHR12RD.DACC2DHR :=
205- UInt12 (Channel_2_Value and Max_12bit_Resolution);
225+ This.DHR12RD.DACC1DHR := UInt12 (Channel_1_Value and Max_12bit_Resolution);
226+ This.DHR12RD.DACC2DHR := UInt12 (Channel_2_Value and Max_12bit_Resolution);
206227 end case ;
207228 when DAC_Resolution_8_Bits =>
208- This.DHR8RD.DACC1DHR :=
209- UInt8 (Channel_1_Value and Max_8bit_Resolution);
210- This.DHR8RD.DACC2DHR :=
211- UInt8 (Channel_2_Value and Max_8bit_Resolution);
229+ This.DHR8RD.DACC1DHR := UInt8 (Channel_1_Value and Max_8bit_Resolution);
230+ This.DHR8RD.DACC2DHR := UInt8 (Channel_2_Value and Max_8bit_Resolution);
212231 end case ;
213232 end Set_Dual_Output_Voltages ;
214233
@@ -682,10 +701,36 @@ package body STM32.DAC is
682701 when DAC_Resolution_8_Bits =>
683702 Result := This.DHR8R2'Address;
684703 end case ;
685-
686704 end case ;
687705
688706 return Result;
689707 end Data_Address ;
690708
709+ -- --------------------------------
710+ -- Data_Address_Dual_Conversion --
711+ -- --------------------------------
712+
713+ function Data_Address_Dual_Conversion
714+ (This : Digital_To_Analog_Converter;
715+ Resolution : DAC_Resolution;
716+ Alignment : Data_Alignment)
717+ return Address
718+ is
719+ Result : Address;
720+ begin
721+ case Resolution is
722+ when DAC_Resolution_12_Bits =>
723+ case Alignment is
724+ when Left_Aligned =>
725+ Result := This.DHR12LD'Address;
726+ when Right_Aligned =>
727+ Result := This.DHR12RD'Address;
728+ end case ;
729+ when DAC_Resolution_8_Bits =>
730+ Result := This.DHR8RD'Address;
731+ end case ;
732+
733+ return Result;
734+ end Data_Address_Dual_Conversion ;
735+
691736end STM32.DAC ;
0 commit comments