|
1 | | -use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand}; |
2 | | - |
3 | 1 | use super::{Lcd, SubBank}; |
4 | 2 |
|
5 | | -impl<S> WriteOnlyDataCommand for Lcd<S> |
6 | | -where |
7 | | - S: SubBank, |
8 | | -{ |
9 | | - fn send_commands(&mut self, cmd: DataFormat<'_>) -> Result<(), DisplayError> { |
10 | | - match cmd { |
11 | | - DataFormat::U8(slice) => { |
12 | | - for value in slice { |
13 | | - self.write_command(u16::from(*value)); |
14 | | - } |
15 | | - } |
16 | | - DataFormat::U16(slice) => { |
17 | | - for value in slice { |
18 | | - self.write_command(*value); |
19 | | - } |
20 | | - } |
21 | | - DataFormat::U16BE(slice) | DataFormat::U16LE(slice) => { |
22 | | - // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
23 | | - for value in slice { |
24 | | - self.write_command(*value); |
| 3 | +macro_rules! impl_display_interface { |
| 4 | + ($display_interface:ident) => { |
| 5 | + impl<S> $display_interface::WriteOnlyDataCommand for Lcd<S> |
| 6 | + where |
| 7 | + S: SubBank, |
| 8 | + { |
| 9 | + fn send_commands( |
| 10 | + &mut self, |
| 11 | + cmd: $display_interface::DataFormat<'_>, |
| 12 | + ) -> Result<(), $display_interface::DisplayError> { |
| 13 | + use $display_interface::DataFormat; |
| 14 | + match cmd { |
| 15 | + DataFormat::U8(slice) => { |
| 16 | + for value in slice { |
| 17 | + self.write_command(u16::from(*value)); |
| 18 | + } |
| 19 | + } |
| 20 | + DataFormat::U16(slice) => { |
| 21 | + for value in slice { |
| 22 | + self.write_command(*value); |
| 23 | + } |
| 24 | + } |
| 25 | + DataFormat::U16BE(slice) | DataFormat::U16LE(slice) => { |
| 26 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 27 | + for value in slice { |
| 28 | + self.write_command(*value); |
| 29 | + } |
| 30 | + } |
| 31 | + DataFormat::U8Iter(iter) => { |
| 32 | + for value in iter { |
| 33 | + self.write_command(u16::from(value)); |
| 34 | + } |
| 35 | + } |
| 36 | + DataFormat::U16BEIter(iter) | DataFormat::U16LEIter(iter) => { |
| 37 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 38 | + for value in iter { |
| 39 | + self.write_command(value); |
| 40 | + } |
| 41 | + } |
| 42 | + _ => return Err($display_interface::DisplayError::DataFormatNotImplemented), |
25 | 43 | } |
| 44 | + Ok(()) |
26 | 45 | } |
27 | | - DataFormat::U8Iter(iter) => { |
28 | | - for value in iter { |
29 | | - self.write_command(u16::from(value)); |
30 | | - } |
31 | | - } |
32 | | - DataFormat::U16BEIter(iter) | DataFormat::U16LEIter(iter) => { |
33 | | - // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
34 | | - for value in iter { |
35 | | - self.write_command(value); |
36 | | - } |
37 | | - } |
38 | | - _ => return Err(DisplayError::DataFormatNotImplemented), |
39 | | - } |
40 | | - Ok(()) |
41 | | - } |
42 | 46 |
|
43 | | - fn send_data(&mut self, buf: DataFormat<'_>) -> Result<(), DisplayError> { |
44 | | - match buf { |
45 | | - DataFormat::U8(slice) => { |
46 | | - for value in slice { |
47 | | - self.write_data(u16::from(*value)); |
| 47 | + fn send_data( |
| 48 | + &mut self, |
| 49 | + buf: $display_interface::DataFormat<'_>, |
| 50 | + ) -> Result<(), $display_interface::DisplayError> { |
| 51 | + use $display_interface::DataFormat; |
| 52 | + match buf { |
| 53 | + DataFormat::U8(slice) => { |
| 54 | + for value in slice { |
| 55 | + self.write_data(u16::from(*value)); |
| 56 | + } |
| 57 | + } |
| 58 | + DataFormat::U16(slice) => { |
| 59 | + for value in slice { |
| 60 | + self.write_data(*value); |
| 61 | + } |
| 62 | + } |
| 63 | + DataFormat::U16BE(slice) | DataFormat::U16LE(slice) => { |
| 64 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 65 | + for value in slice { |
| 66 | + self.write_data(*value); |
| 67 | + } |
| 68 | + } |
| 69 | + DataFormat::U8Iter(iter) => { |
| 70 | + for value in iter { |
| 71 | + self.write_data(u16::from(value)); |
| 72 | + } |
| 73 | + } |
| 74 | + DataFormat::U16BEIter(iter) | DataFormat::U16LEIter(iter) => { |
| 75 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 76 | + for value in iter { |
| 77 | + self.write_data(value); |
| 78 | + } |
| 79 | + } |
| 80 | + _ => return Err($display_interface::DisplayError::DataFormatNotImplemented), |
48 | 81 | } |
| 82 | + Ok(()) |
49 | 83 | } |
50 | | - DataFormat::U16(slice) => { |
51 | | - for value in slice { |
52 | | - self.write_data(*value); |
53 | | - } |
54 | | - } |
55 | | - DataFormat::U16BE(slice) | DataFormat::U16LE(slice) => { |
56 | | - // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
57 | | - for value in slice { |
58 | | - self.write_data(*value); |
59 | | - } |
60 | | - } |
61 | | - DataFormat::U8Iter(iter) => { |
62 | | - for value in iter { |
63 | | - self.write_data(u16::from(value)); |
64 | | - } |
65 | | - } |
66 | | - DataFormat::U16BEIter(iter) | DataFormat::U16LEIter(iter) => { |
67 | | - // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
68 | | - for value in iter { |
69 | | - self.write_data(value); |
70 | | - } |
71 | | - } |
72 | | - _ => return Err(DisplayError::DataFormatNotImplemented), |
73 | 84 | } |
74 | | - Ok(()) |
75 | | - } |
| 85 | + }; |
76 | 86 | } |
| 87 | + |
| 88 | +impl_display_interface!(display_interface); |
| 89 | +impl_display_interface!(display_interface_04); |
0 commit comments