1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
use crate::config::*;
use crate::state::State;
use diff_in_place::DiffInPlace;
#[derive(Debug)]
pub enum IS31FL3733Error {
StateError,
DeviceError,
OutOfSpaceError,
}
pub trait Mode {}
#[derive(Debug)]
pub struct Async;
#[derive(Debug)]
pub struct Blocking;
impl Mode for Async {}
impl Mode for Blocking {}
pub struct IS31FL3733<BUS, M: Mode> {
bus: BUS,
address: u8,
state: State,
_phantom: core::marker::PhantomData<M>,
}
// General implementation
impl<BUS, M: Mode> IS31FL3733<BUS, M> {
/// Create a new IS31FL3733 driver
/// # Arguments
/// * `i2c` - The I2C bus to use
/// * `address` - The I2C address of the device
///
/// # Returns
/// A new IS31FL3733 driver
pub fn new(bus: BUS, address: u8) -> Self {
Self {
bus,
address,
state: State::default(),
_phantom: core::marker::PhantomData,
}
}
pub fn into_inner(self) -> BUS {
self.bus
}
pub fn inner(&self) -> &BUS {
&self.bus
}
pub fn inner_mut(&mut self) -> &mut BUS {
&mut self.bus
}
}
impl<BUS: embedded_hal::i2c::I2c> IS31FL3733<BUS, Blocking> {
pub fn new_blocking(bus: BUS, address: u8) -> Self {
Self {
bus,
address,
state: State::default(),
_phantom: core::marker::PhantomData,
}
}
fn write(&mut self, address: u8, data: &[u8]) -> Result<(), BUS::Error> {
self.bus.transaction(
self.address,
&mut [
embedded_hal::i2c::Operation::Write(&[address]),
embedded_hal::i2c::Operation::Write(data),
],
)?;
Ok(())
}
fn read(&mut self, address: u8, data: &mut [u8]) -> Result<(), BUS::Error> {
self.bus.transaction(
self.address,
&mut [
embedded_hal::i2c::Operation::Write(&[address]),
embedded_hal::i2c::Operation::Read(data),
],
)?;
Ok(())
}
fn write_register(
&mut self,
register: u8,
data: u8,
) -> Result<(), BUS::Error> {
self.write(register, &[data])
}
fn read_register(&mut self, register: u8) -> Result<u8, BUS::Error> {
let mut data = [0];
self.read(register, &mut data)?;
Ok(data[0])
}
/// Initialize the device
///
/// # Returns
/// * Ok(()) if the device was initialized successfully
/// * Err(IS31FL3733Error::DeviceError) if the device did not respond as expected
pub fn initialize(&mut self) -> Result<(), IS31FL3733Error> {
self.set_page(RESET_REGISTER.page)?;
let reset_result = self
.read_register(RESET_REGISTER.register)
.map_err(|_| IS31FL3733Error::DeviceError)?;
if reset_result != 0x00 {
return Err(IS31FL3733Error::DeviceError);
}
self.set_configuration(CONFIGURATION_SOFTWARE_SHUTDOWN_DISABLE)?;
self.set_page(self.state.page)?;
Ok(())
}
/// Set the global current control
///
/// # Arguments
/// * `gcc` - The global current control value
///
/// # Returns
/// * Ok(()) if the global current control was set successfully
pub fn set_global_current_control(
&mut self,
gcc: u8,
) -> Result<(), IS31FL3733Error> {
if self.state.global_current_control != gcc {
self.set_page(GCC_REGISTER.page)?;
self.write_register(GCC_REGISTER.register, gcc)
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.global_current_control = gcc;
}
Ok(())
}
/// Set the configuration register
///
/// # Arguments
/// * `configuration` - The configuration register value
///
/// # Returns
/// * Ok(()) if the configuration register was set successfully
pub fn set_configuration(
&mut self,
configuration: u8,
) -> Result<(), IS31FL3733Error> {
if self.state.configuration_register != configuration {
self.set_page(CONFIGURATION_REGISTER.page)?;
self.write_register(CONFIGURATION_REGISTER.register, configuration)
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.configuration_register = configuration;
}
Ok(())
}
/// Unlock the page register
///
/// # Returns
/// * Ok(()) if the command register was unlocked successfully
fn unlock(&mut self) -> Result<(), IS31FL3733Error> {
self.write_register(COMMAND_WRITE_LOCK_REGISTER, COMMAND_WRITE_UNLOCK)
.map_err(|_| IS31FL3733Error::DeviceError)?;
Ok(())
}
/// Set the page register, must be unlocked first using `unlock()`
///
/// # Arguments
/// * `page` - The page to set
///
/// # Returns
/// * Ok(()) if the page register was set successfully
fn set_page(&mut self, page: u8) -> Result<(), IS31FL3733Error> {
if page != self.state.page {
self.unlock()?;
self.write_register(COMMAND_REGISTER, page)
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.page = page;
}
Ok(())
}
/// Set the LEDs state on the device. Each bit in the array represents a LED.
/// Only the delta between the current state and the new state is written to the device.
///
/// # Arguments
/// * `leds` - The new state of the LEDs
///
/// * Ok(()) if the LEDs were set successfully
pub fn update_leds(
&mut self,
leds: &[u8; TOTAL_LED_COUNT / 8],
) -> Result<(), IS31FL3733Error> {
let current = self.state.leds;
current.try_diff_in_place(
leds,
|index, leds| -> Result<(), IS31FL3733Error> {
self.write_leds(index, leds)?;
Ok(())
},
)?;
Ok(())
}
/// Sets the state of the LEDs on the device, starting from a
/// specific index.
///
/// # Arguments
/// * `index` - The index of the first LED array to update
/// * `leds` - The new brightness of the LEDs, one bit per LED
///
/// # Returns
/// * Ok(()) if the brightness was set successfully
pub fn write_leds(
&mut self,
index: usize,
leds: &[u8],
) -> Result<(), IS31FL3733Error> {
core::assert!(index + leds.len() <= TOTAL_LED_COUNT / 8);
self.set_page(LED_CONTROL_REGISTER_BASE.page)?;
self.write(LED_CONTROL_REGISTER_BASE.register + index as u8, leds)
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.leds[index..index + leds.len()].copy_from_slice(leds);
Ok(())
}
/// Set the LEDs brightness on the device. Each byte in the array represents a LED.
/// Only the delta between the current state and the new state is written to the device.
///
/// # Arguments
/// * `brightness` - The new state of the LEDs
///
/// * Ok(()) if the LEDs were set successfully
pub fn update_brightness(
&mut self,
brightness: &[u8; TOTAL_LED_COUNT],
) -> Result<(), IS31FL3733Error> {
let current = self.state.brightness;
current.try_diff_in_place(
brightness,
|index, brightness| -> Result<(), IS31FL3733Error> {
self.write_brightness(index, brightness)?;
Ok(())
},
)?;
Ok(())
}
/// Sets the brightness of the LEDs on the device, starting from a
/// specific index.
///
/// # Arguments
/// * `index` - The index of the first LED to update
/// * `brightness` - The new brightness of the LEDs, one byte per LED
///
/// # Returns
/// * Ok(()) if the brightness was set successfully
pub fn write_brightness(
&mut self,
index: usize,
brightness: &[u8],
) -> Result<(), IS31FL3733Error> {
core::assert!(index + brightness.len() <= TOTAL_LED_COUNT);
self.set_page(PWM_REGISTER_BASE.page)?;
self.write(PWM_REGISTER_BASE.register + index as u8, brightness)
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.brightness[index..index + brightness.len()]
.copy_from_slice(brightness);
Ok(())
}
}
impl<BUS: embedded_hal_async::i2c::I2c> IS31FL3733<BUS, Async> {
pub fn new_async(bus: BUS, address: u8) -> Self {
Self {
bus,
address,
state: State::default(),
_phantom: core::marker::PhantomData,
}
}
async fn write(
&mut self,
address: u8,
data: &[u8],
) -> Result<(), BUS::Error> {
self.bus
.transaction(
self.address,
&mut [
embedded_hal_async::i2c::Operation::Write(&[address]),
embedded_hal_async::i2c::Operation::Write(data),
],
)
.await?;
Ok(())
}
async fn read(
&mut self,
address: u8,
data: &mut [u8],
) -> Result<(), BUS::Error> {
self.bus
.transaction(
self.address,
&mut [
embedded_hal_async::i2c::Operation::Write(&[address]),
embedded_hal_async::i2c::Operation::Read(data),
],
)
.await?;
Ok(())
}
async fn write_register(
&mut self,
register: u8,
data: u8,
) -> Result<(), BUS::Error> {
self.write(register, &[data]).await
}
async fn read_register(&mut self, register: u8) -> Result<u8, BUS::Error> {
let mut data = [0];
self.read(register, &mut data).await?;
Ok(data[0])
}
/// Initialize the device
///
/// # Returns
/// * Ok(()) if the device was initialized successfully
/// * Err(IS31FL3733Error::DeviceError) if the device did not respond as expected
pub async fn initialize(&mut self) -> Result<(), IS31FL3733Error> {
self.set_page(RESET_REGISTER.page).await?;
let reset_result = self
.read_register(RESET_REGISTER.register)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
if reset_result != 0x00 {
return Err(IS31FL3733Error::DeviceError);
}
self.set_configuration(CONFIGURATION_SOFTWARE_SHUTDOWN_DISABLE)
.await?;
self.set_page(self.state.page).await?;
Ok(())
}
/// Set the global current control
///
/// # Arguments
/// * `gcc` - The global current control value
///
/// # Returns
/// * Ok(()) if the global current control was set successfully
pub async fn set_global_current_control(
&mut self,
gcc: u8,
) -> Result<(), IS31FL3733Error> {
if self.state.global_current_control != gcc {
self.set_page(GCC_REGISTER.page).await?;
self.write_register(GCC_REGISTER.register, gcc)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.global_current_control = gcc;
}
Ok(())
}
/// Set the configuration register
///
/// # Arguments
/// * `configuration` - The configuration register value
///
/// # Returns
/// * Ok(()) if the configuration register was set successfully
pub async fn set_configuration(
&mut self,
configuration: u8,
) -> Result<(), IS31FL3733Error> {
if self.state.configuration_register != configuration {
self.set_page(CONFIGURATION_REGISTER.page).await?;
self.write_register(CONFIGURATION_REGISTER.register, configuration)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.configuration_register = configuration;
}
Ok(())
}
/// Unlock the page register
///
/// # Returns
/// * Ok(()) if the command register was unlocked successfully
async fn unlock(&mut self) -> Result<(), IS31FL3733Error> {
self.write_register(COMMAND_WRITE_LOCK_REGISTER, COMMAND_WRITE_UNLOCK)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
Ok(())
}
/// Set the page register, must be unlocked first using `unlock()`
///
/// # Arguments
/// * `page` - The page to set
///
/// # Returns
/// * Ok(()) if the page register was set successfully
async fn set_page(&mut self, page: u8) -> Result<(), IS31FL3733Error> {
if page != self.state.page {
self.unlock().await?;
self.write_register(COMMAND_REGISTER, page)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.page = page;
}
Ok(())
}
/// Set the LEDs state on the device. Each bit in the array represents a LED.
/// Only the delta between the current state and the new state is written to the device.
///
/// # Arguments
/// * `leds` - The new state of the LEDs
///
/// # Returns
/// * Ok(()) if the LEDs were set successfully
pub async fn update_leds(
&mut self,
leds: &[u8; TOTAL_LED_COUNT / 8],
) -> Result<(), IS31FL3733Error> {
// note: I couldn't figure out a way to make diff_in_place work with async without having
// to use boxed futures, which is not no_std compatible, so I'm reluctantly inlining here
let current = self.state.leds;
let byte_for_byte = current.iter().zip(leds.iter());
let mut run_state = DiffState::Same;
for (current, (left, right)) in byte_for_byte.enumerate() {
match (run_state, left == right) {
(DiffState::Same, false) => {
// We are starting an unequal run, preserve the current index
run_state = DiffState::Different(current);
}
(DiffState::Different(run_start), true) => {
// We are ending an unequal run, call the diff function
self.write_leds(run_start, &leds[run_start..current])
.await?;
run_state = DiffState::Same;
}
_ => {
// Run state is unchanged
}
}
}
// If we are still in a different run, call the diff function
if let DiffState::Different(run_start) = run_state {
self.write_leds(run_start, &leds[run_start..]).await?;
}
Ok(())
}
/// Sets the state of the LEDs on the device, starting from a
/// specific index.
///
/// # Arguments
/// * `index` - The index of the first LED array to update
/// * `leds` - The new brightness of the LEDs, one bit per LED
///
/// # Returns
/// * Ok(()) if the brightness was set successfully
pub async fn write_leds(
&mut self,
index: usize,
leds: &[u8],
) -> Result<(), IS31FL3733Error> {
core::assert!(index + leds.len() <= TOTAL_LED_COUNT / 8);
self.set_page(LED_CONTROL_REGISTER_BASE.page).await?;
self.write(LED_CONTROL_REGISTER_BASE.register + index as u8, leds)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.leds[index..index + leds.len()].copy_from_slice(leds);
Ok(())
}
/// Set the LEDs brightness on the device. Each byte in the array represents a LED.
/// Only the delta between the current state and the new state is written to the device.
///
/// # Arguments
/// * `brightness` - The new state of the LEDs
///
/// * Ok(()) if the LEDs were set successfully
pub async fn update_brightness(
&mut self,
brightness: &[u8; TOTAL_LED_COUNT],
) -> Result<(), IS31FL3733Error> {
let current = self.state.brightness;
let byte_for_byte = current.iter().zip(brightness.iter());
let mut run_state = DiffState::Same;
for (current, (left, right)) in byte_for_byte.enumerate() {
match (run_state, left == right) {
(DiffState::Same, false) => {
// We are starting an unequal run, preserve the current index
run_state = DiffState::Different(current);
}
(DiffState::Different(run_start), true) => {
// We are ending an unequal run, call the diff function
self.write_brightness(
run_start,
&brightness[run_start..current],
)
.await?;
run_state = DiffState::Same;
}
_ => {
// Run state is unchanged
}
}
}
// If we are still in a different run, call the diff function
if let DiffState::Different(run_start) = run_state {
self.write_brightness(run_start, &brightness[run_start..])
.await?;
}
Ok(())
}
/// Sets the brightness of the LEDs on the device, starting from a
/// specific index.
///
/// # Arguments
/// * `index` - The index of the first LED to update
/// * `brightness` - The new brightness of the LEDs, one byte per LED
///
/// # Returns
/// * Ok(()) if the brightness was set successfully
pub async fn write_brightness(
&mut self,
index: usize,
brightness: &[u8],
) -> Result<(), IS31FL3733Error> {
core::assert!(index + brightness.len() <= TOTAL_LED_COUNT);
self.set_page(PWM_REGISTER_BASE.page).await?;
self.write(PWM_REGISTER_BASE.register + index as u8, brightness)
.await
.map_err(|_| IS31FL3733Error::DeviceError)?;
self.state.brightness[index..index + brightness.len()]
.copy_from_slice(brightness);
Ok(())
}
}
#[derive(Copy, Clone)]
enum DiffState {
Same,
Different(usize),
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::*;
#[test]
fn init_test() {
const EXPECTED_WRITE_DATA: [u8; 7] =
[0xfe, 0xc5, 0xfd, 0x03, 0x11, 0x00, 0x01];
const EXPECTED_READ_DATA: [u8; 1] = [0];
let mut bus = FakeI2cBus::<32, 32, Blocking>::new_with_read_data(
&EXPECTED_READ_DATA,
);
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
is31fl3733.initialize().unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
#[test]
fn configuration_test() {
const EXPECTED_WRITE_DATA: &[u8] =
&[0xfe, 0xc5, 0xfd, 0x03, 0x00, 0xaa, 0x00, 0xab];
let mut bus = FakeI2cBus::<32, 32, _>::new_blocking();
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
is31fl3733.set_configuration(0xaa).unwrap();
is31fl3733.set_configuration(0xaa).unwrap();
is31fl3733.set_configuration(0xab).unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
#[test]
fn global_current_control_test() {
const EXPECTED_WRITE_DATA: &[u8] =
&[0xfe, 0xc5, 0xfd, 0x03, 0x01, 0xaa, 0x01, 0xab];
let mut bus = FakeI2cBus::<32, 32, _>::new_blocking();
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
is31fl3733.set_global_current_control(0xaa).unwrap();
is31fl3733.set_global_current_control(0xaa).unwrap();
is31fl3733.set_global_current_control(0xab).unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
#[test]
fn state_update_test() {
#[rustfmt::skip]
const EXPECTED_WRITE_DATA: &[u8] = &[
254, 197, // Write unlock
253, 1, // Set page to 1
20, 255, 255, // set brightness leds 20 to 21 to 0xff
188, 240, 240, 240, 240, // set brightness leds 188 to 192 to 0xff
254, 197, // Write unlock
253, 0, // Set page to 0
10, 255, 255, // set leds 10 to 11 to 0xff
];
let mut bus = FakeI2cBus::<32, 32, _>::new_blocking();
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
let mut new_brightness = [0; 192];
new_brightness[20..22].fill(0xff);
new_brightness[188..].fill(0xf0);
is31fl3733.update_brightness(&new_brightness).unwrap();
let mut new_leds = [0; 24];
new_leds[10..12].fill(0xff);
is31fl3733.update_leds(&new_leds).unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
mod _async {
use super::*;
use lite_async_test::async_test;
#[async_test]
async fn init_test() {
const EXPECTED_WRITE_DATA: [u8; 7] =
[0xfe, 0xc5, 0xfd, 0x03, 0x11, 0x00, 0x01];
const EXPECTED_READ_DATA: [u8; 1] = [0];
let mut bus = FakeI2cBus::<32, 32, Async>::new_with_read_data(
&EXPECTED_READ_DATA,
);
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
is31fl3733.initialize().await.unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
#[async_test]
async fn configuration_test() {
const EXPECTED_WRITE_DATA: &[u8] =
&[0xfe, 0xc5, 0xfd, 0x03, 0x00, 0xaa, 0x00, 0xab];
let mut bus = FakeI2cBus::<32, 32, Async>::new();
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
is31fl3733.set_configuration(0xaa).await.unwrap();
is31fl3733.set_configuration(0xaa).await.unwrap();
is31fl3733.set_configuration(0xab).await.unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
#[async_test]
async fn global_current_control_test() {
const EXPECTED_WRITE_DATA: &[u8] =
&[0xfe, 0xc5, 0xfd, 0x03, 0x01, 0xaa, 0x01, 0xab];
let mut bus = FakeI2cBus::<32, 32, Async>::new();
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
is31fl3733.set_global_current_control(0xaa).await.unwrap();
is31fl3733.set_global_current_control(0xaa).await.unwrap();
is31fl3733.set_global_current_control(0xab).await.unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
#[async_test]
async fn state_update_test() {
#[rustfmt::skip]
const EXPECTED_WRITE_DATA: &[u8] = &[
254, 197, // Write unlock
253, 1, // Set page to 1
20, 255, 255, // set brightness leds 20 to 21 to 0xff
188, 240, 240, 240, 240, // set brightness leds 188 to 192 to 0xff
254, 197, // Write unlock
253, 0, // Set page to 0
10, 255, 255, // set leds 10 to 11 to 0xff
];
let mut bus = FakeI2cBus::<32, 32, _>::new_async();
let mut is31fl3733 = IS31FL3733::new(&mut bus, 0x60);
let mut new_brightness = [0; 192];
new_brightness[20..22].fill(0xff);
new_brightness[188..].fill(0xf0);
is31fl3733.update_brightness(&new_brightness).await.unwrap();
let mut new_leds = [0; 24];
new_leds[10..12].fill(0xff);
is31fl3733.update_leds(&new_leds).await.unwrap();
assert_eq!(bus.write_data_as_ref(), EXPECTED_WRITE_DATA);
}
}
}