11use crate :: common:: { DmaBuffer , DummyDelay } ;
2+ use crate :: i2c:: common:: { I2cConfig , I2cSEvent , I2cXferMode } ;
23use crate :: uart:: UartController ;
34use ast1060_pac:: { I2cbuff , I2cglobal , Scu } ;
45use core:: cmp:: min;
@@ -11,31 +12,6 @@ use proposed_traits::i2c_target::I2CTarget;
1112
1213static I2CGLOBAL_INIT : AtomicBool = AtomicBool :: new ( false ) ;
1314
14- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
15- #[ repr( u32 ) ]
16- pub enum I2cSpeed {
17- Standard = 100_000 ,
18- Fast = 400_000 ,
19- FastPlus = 1_000_000 ,
20- }
21-
22- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
23- #[ repr( u8 ) ]
24- pub enum I2cXferMode {
25- DmaMode ,
26- BuffMode ,
27- ByteMode ,
28- }
29- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
30- #[ repr( u8 ) ]
31- pub enum I2cSEvent {
32- SlaveRdReq ,
33- SlaveWrReq ,
34- SlaveRdProc ,
35- SlaveWrRecvd ,
36- SlaveStop ,
37- }
38-
3915pub trait Instance {
4016 fn ptr ( ) -> * const ast1060_pac:: i2c:: RegisterBlock ;
4117 fn buff_ptr ( ) -> * const ast1060_pac:: i2cbuff:: RegisterBlock ;
@@ -238,78 +214,6 @@ impl embedded_hal::i2c::Error for Error {
238214 }
239215}
240216
241- pub struct TimingConfig {
242- pub manual_scl_high : u8 ,
243- pub manual_scl_low : u8 ,
244- pub manual_sda_hold : u8 ,
245- pub clk_src : u32 ,
246- }
247- pub struct I2cConfig {
248- pub xfer_mode : I2cXferMode ,
249- pub multi_master : bool ,
250- pub smbus_timeout : bool ,
251- pub smbus_alert : bool ,
252- pub timing_config : TimingConfig ,
253- pub speed : I2cSpeed ,
254- }
255- pub struct I2cConfigBuilder {
256- xfer_mode : I2cXferMode ,
257- multi_master : bool ,
258- smbus_timeout : bool ,
259- smbus_alert : bool ,
260- timing_config : Option < TimingConfig > ,
261- speed : I2cSpeed ,
262- }
263- impl I2cConfigBuilder {
264- pub fn new ( ) -> Self {
265- Self {
266- xfer_mode : I2cXferMode :: ByteMode ,
267- multi_master : false ,
268- smbus_alert : false ,
269- smbus_timeout : false ,
270- timing_config : None ,
271- speed : I2cSpeed :: Standard ,
272- }
273- }
274- pub fn xfer_mode ( mut self , mode : I2cXferMode ) -> Self {
275- self . xfer_mode = mode;
276- self
277- }
278- pub fn multi_master ( mut self , enabled : bool ) -> Self {
279- self . multi_master = enabled;
280- self
281- }
282- pub fn smbus_alert ( mut self , enabled : bool ) -> Self {
283- self . smbus_alert = enabled;
284- self
285- }
286- pub fn smbus_timeout ( mut self , enabled : bool ) -> Self {
287- self . smbus_timeout = enabled;
288- self
289- }
290- pub fn speed ( mut self , speed : I2cSpeed ) -> Self {
291- self . speed = speed;
292- self
293- }
294- pub fn timing_config ( mut self , config : TimingConfig ) -> Self {
295- self . timing_config = Some ( config) ;
296- self
297- }
298- pub fn build ( self ) -> I2cConfig {
299- I2cConfig {
300- xfer_mode : self . xfer_mode ,
301- multi_master : self . multi_master ,
302- smbus_timeout : self . smbus_timeout ,
303- smbus_alert : self . smbus_alert ,
304- timing_config : self . timing_config . unwrap_or ( TimingConfig {
305- manual_scl_high : 0 ,
306- manual_scl_low : 0 ,
307- manual_sda_hold : 0 ,
308- clk_src : 0 ,
309- } ) ,
310- speed : self . speed }
311- }
312- }
313217
314218const I2C_TOTAL : usize = 4 ;
315219#[ link_section = ".ram_nc" ]
0 commit comments