1use core::marker::PhantomData;
2
3use embedded_hal::i2c::I2c;
4use embedded_hal::spi::SpiDevice;
5use embedded_hal_async::i2c::I2c as AsyncI2c;
6use embedded_hal_async::spi::SpiDevice as AsyncSpiDevice;
7
8use crate::registers::TransportKind;
9use crate::{
10 AccelRange, AsyncI2cTransport, AsyncSpiTransport, GyroRange, SyncI2cTransport, SyncSpiTransport,
11};
12
13pub struct Bmi323<T> {
17 pub(crate) transport: T,
18 pub(crate) kind: TransportKind,
19 pub(crate) accel_range: AccelRange,
20 pub(crate) gyro_range: GyroRange,
21}
22
23pub struct Bmi323Async<T> {
27 pub(crate) transport: T,
28 pub(crate) kind: TransportKind,
29 pub(crate) accel_range: AccelRange,
30 pub(crate) gyro_range: GyroRange,
31 pub(crate) _not_sync: PhantomData<fn() -> ()>,
32}
33
34impl<I2C> Bmi323<SyncI2cTransport<I2C>>
35where
36 I2C: I2c,
37{
38 pub fn new_i2c(i2c: I2C, address: u8) -> Self {
42 Self {
43 transport: SyncI2cTransport { bus: i2c, address },
44 kind: TransportKind::I2c,
45 accel_range: AccelRange::G8,
46 gyro_range: GyroRange::Dps2000,
47 }
48 }
49
50 pub fn destroy(self) -> I2C {
52 self.transport.bus
53 }
54}
55
56impl<SPI> Bmi323<SyncSpiTransport<SPI>>
57where
58 SPI: SpiDevice<u8>,
59{
60 pub fn new_spi(spi: SPI) -> Self {
62 Self {
63 transport: SyncSpiTransport { bus: spi },
64 kind: TransportKind::Spi,
65 accel_range: AccelRange::G8,
66 gyro_range: GyroRange::Dps2000,
67 }
68 }
69
70 pub fn destroy(self) -> SPI {
72 self.transport.bus
73 }
74}
75
76impl<I2C> Bmi323Async<AsyncI2cTransport<I2C>>
77where
78 I2C: AsyncI2c,
79{
80 pub fn new_i2c(i2c: I2C, address: u8) -> Self {
84 Self {
85 transport: AsyncI2cTransport { bus: i2c, address },
86 kind: TransportKind::I2c,
87 accel_range: AccelRange::G8,
88 gyro_range: GyroRange::Dps2000,
89 _not_sync: PhantomData,
90 }
91 }
92
93 pub fn destroy(self) -> I2C {
95 self.transport.bus
96 }
97}
98
99impl<SPI> Bmi323Async<AsyncSpiTransport<SPI>>
100where
101 SPI: AsyncSpiDevice<u8>,
102{
103 pub fn new_spi(spi: SPI) -> Self {
105 Self {
106 transport: AsyncSpiTransport { bus: spi },
107 kind: TransportKind::Spi,
108 accel_range: AccelRange::G8,
109 gyro_range: GyroRange::Dps2000,
110 _not_sync: PhantomData,
111 }
112 }
113
114 pub fn destroy(self) -> SPI {
116 self.transport.bus
117 }
118}