Migrated args from tuples to arrays

This commit is contained in:
Sebastian 2018-09-02 23:48:36 +02:00
parent ca92459649
commit 169aa5963f
1 changed files with 61 additions and 59 deletions

View File

@ -36,8 +36,8 @@ enum Command {
INVON, INVON,
DISPOFF, DISPOFF,
DISPON, DISPON,
CASET(u8, u8, u8, u8), CASET([u8; 4]),
RASET(u8, u8, u8, u8), RASET([u8; 4]),
RAMWR, RAMWR,
RAMRD, RAMRD,
@ -45,27 +45,27 @@ enum Command {
COLMOD(u8), COLMOD(u8),
MADCTL(u8), MADCTL(u8),
FRMCTR1(u8, u8, u8), FRMCTR1([u8; 3]),
FRMCTR2(u8, u8, u8), FRMCTR2([u8; 3]),
FRMCTR3(u8, u8, u8, u8, u8, u8), FRMCTR3([u8; 6]),
INVCTR(u8), INVCTR(u8),
DISSET5(u8, u8), DISSET5([u8; 2]),
PWCTR1(u8, u8), PWCTR1([u8; 2]),
PWCTR2(u8), PWCTR2(u8),
PWCTR3(u8, u8), PWCTR3([u8; 2]),
PWCTR4(u8, u8), PWCTR4([u8; 2]),
PWCTR5(u8, u8), PWCTR5([u8; 2]),
PWCTR6(u8, u8), PWCTR6([u8; 2]),
VMCTR1(u8, u8), VMCTR1([u8; 2]),
RDID1, RDID1,
RDID2, RDID2,
RDID3, RDID3,
RDID4, RDID4,
GMCTRP1(u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8), GMCTRP1([u8; 16]),
GMCTRN1(u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8, u8), GMCTRN1([u8; 16]),
} }
fn command_to_byte(cmd : Command) -> u8 { fn command_to_byte(cmd : Command) -> u8 {
@ -84,8 +84,8 @@ fn command_to_byte(cmd : Command) -> u8 {
Command::INVON => 0x21, Command::INVON => 0x21,
Command::DISPOFF => 0x28, Command::DISPOFF => 0x28,
Command::DISPON => 0x29, Command::DISPON => 0x29,
Command::CASET(_, _, _, _) => 0x2A, Command::CASET(_) => 0x2A,
Command::RASET(_, _, _, _) => 0x2B, Command::RASET(_) => 0x2B,
Command::RAMWR => 0x2C, Command::RAMWR => 0x2C,
Command::RAMRD => 0x2E, Command::RAMRD => 0x2E,
@ -93,27 +93,27 @@ fn command_to_byte(cmd : Command) -> u8 {
Command::COLMOD(_) => 0x3A, Command::COLMOD(_) => 0x3A,
Command::MADCTL(_) => 0x36, Command::MADCTL(_) => 0x36,
Command::FRMCTR1(_, _, _) => 0xB1, Command::FRMCTR1(_) => 0xB1,
Command::FRMCTR2(_, _, _) => 0xB2, Command::FRMCTR2(_) => 0xB2,
Command::FRMCTR3(_, _, _, _, _, _) => 0xB3, Command::FRMCTR3(_) => 0xB3,
Command::INVCTR(_) => 0xB4, Command::INVCTR(_) => 0xB4,
Command::DISSET5(_,_) => 0xB6, Command::DISSET5(_) => 0xB6,
Command::PWCTR1(_, _) => 0xC0, Command::PWCTR1(_) => 0xC0,
Command::PWCTR2(_) => 0xC1, Command::PWCTR2(_) => 0xC1,
Command::PWCTR3(_, _) => 0xC2, Command::PWCTR3(_) => 0xC2,
Command::PWCTR4(_, _) => 0xC3, Command::PWCTR4(_) => 0xC3,
Command::PWCTR5(_, _) => 0xC4, Command::PWCTR5(_) => 0xC4,
Command::PWCTR6(_, _) => 0xFC, Command::PWCTR6(_) => 0xFC,
Command::VMCTR1(_, _) => 0xC5, Command::VMCTR1(_) => 0xC5,
Command::RDID1 => 0xDA, Command::RDID1 => 0xDA,
Command::RDID2 => 0xDB, Command::RDID2 => 0xDB,
Command::RDID3 => 0xDC, Command::RDID3 => 0xDC,
Command::RDID4 => 0xDD, Command::RDID4 => 0xDD,
Command::GMCTRP1(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,) => 0xE0, Command::GMCTRP1(_) => 0xE0,
Command::GMCTRN1(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,) => 0xE1 Command::GMCTRN1(_) => 0xE1
} }
} }
@ -123,44 +123,44 @@ const ST7735_BLUE_INIT : [(Command, u32); 18] = [
(Command::SWRESET, 50), // 1: Software reset, 50 ms delay (Command::SWRESET, 50), // 1: Software reset, 50 ms delay
(Command::SLPOUT, 500), // 2: Out of sleep mode, 500ms delay (Command::SLPOUT, 500), // 2: Out of sleep mode, 500ms delay
(Command::COLMOD(0x05), 10), // 3: Set color mode, 16-bit color, 10ms delay (Command::COLMOD(0x05), 10), // 3: Set color mode, 16-bit color, 10ms delay
(Command::FRMCTR1(0x00, 0x06, 0x03), 10), // 4: Frame rate control, (Command::FRMCTR1([0x00, 0x06, 0x03]), 10), // 4: Frame rate control,
// fastest refresh, // fastest refresh,
// 6 lines front porch, // 6 lines front porch,
// 3 lines back porch // 3 lines back porch
// 10ms delay // 10ms delay
(Command::MADCTL(0x08), 0), // 5: Memory access ctrl (directions) (Command::MADCTL(0x08), 0), // 5: Memory access ctrl (directions)
// Row addr/col addr, bottom to top refresh // Row addr/col addr, bottom to top refresh
(Command::DISSET5(0x15,0x02), 0), // 6: Display settings #5, (Command::DISSET5([0x15,0x02]), 0), // 6: Display settings #5,
// 1 clk cycle nonoverlap, 2 cycle gate // 1 clk cycle nonoverlap, 2 cycle gate
// Fix on VTL // Fix on VTL
(Command::INVCTR(0x00), 0), // 7: Display inversion control, (Command::INVCTR(0x00), 0), // 7: Display inversion control,
// Line inversion // Line inversion
(Command::PWCTR1(0x02, 0x07), 10), // 8: Power control, (Command::PWCTR1([0x02, 0x07]), 10), // 8: Power control,
// GVDD = 4.7V // GVDD = 4.7V
// 1.0uA // 1.0uA
// 10 ms delay // 10 ms delay
(Command::PWCTR2(0x05), 0), // 9: Power control, (Command::PWCTR2(0x05), 0), // 9: Power control,
// GH = 14.7V, VGL = -7.35V // GH = 14.7V, VGL = -7.35V
(Command::PWCTR3(0x01, 0x02), 0), // 10: Power control, (Command::PWCTR3([0x01, 0x02]), 0), // 10: Power control,
// Opamp current small // Opamp current small
// Boost frequency // Boost frequency
(Command::VMCTR1(0x3C, 0x38), 10), // 11: Power control (Command::VMCTR1([0x3C, 0x38]), 10), // 11: Power control
// VCOMH = 4V // VCOMH = 4V
// VCOML = -1.1V // VCOML = -1.1V
// 10 ms delay // 10 ms delay
(Command::PWCTR6(0x11, 0x15), 0), // 12: Power control (Command::PWCTR6([0x11, 0x15]), 0), // 12: Power control
(Command::GMCTRP1(0x09, 0x16, 0x09, 0x20, // 13: Magical unicorn dust (Command::GMCTRP1([0x09, 0x16, 0x09, 0x20, // 13: Magical unicorn dust
0x21, 0x1B, 0x13, 0x19, 0x21, 0x1B, 0x13, 0x19,
0x17, 0x15, 0x1E, 0x2B, 0x17, 0x15, 0x1E, 0x2B,
0x04, 0x05, 0x02, 0x0E), 0), 0x04, 0x05, 0x02, 0x0E]), 0),
(Command::GMCTRN1(0x0B, 0x14, 0x08, 0x1E, // 14: Sparkles and rainbows (Command::GMCTRN1([0x0B, 0x14, 0x08, 0x1E, // 14: Sparkles and rainbows
0x22, 0x1D, 0x18, 0x1E, 0x22, 0x1D, 0x18, 0x1E,
0x1B, 0x1A, 0x24, 0x2B, 0x1B, 0x1A, 0x24, 0x2B,
0x06, 0x06, 0x02, 0x0F), 10), // 10ms delay 0x06, 0x06, 0x02, 0x0F]), 10), // 10ms delay
(Command::CASET(0x00, 0x02, 0x00, 0x81), 0), // 15: Column addr set (Command::CASET([0x00, 0x02, 0x00, 0x81]), 0), // 15: Column addr set
// XSTART = 2 // XSTART = 2
// XEND = 129 // XEND = 129
(Command::RASET(0x00, 0x02, 0x00, 0x81), 0), // 16: Row addr set (Command::RASET([0x00, 0x02, 0x00, 0x81]), 0), // 16: Row addr set
// XSTART = 1 // XSTART = 1
// XEND = 160 // XEND = 160
(Command::NORON, 10), // 17: Normal display on, 10ms delay (Command::NORON, 10), // 17: Normal display on, 10ms delay
@ -172,25 +172,25 @@ const ST7735_BLUE_INIT : [(Command, u32); 18] = [
const ST7735_RED_INIT : [(Command, u32); 15] = [ const ST7735_RED_INIT : [(Command, u32); 15] = [
(Command::SWRESET, 150), // 1: Software reset, 150ms delay (Command::SWRESET, 150), // 1: Software reset, 150ms delay
(Command::SLPOUT, 500), // 2: Out of sleep mode (Command::SLPOUT, 500), // 2: Out of sleep mode
(Command::FRMCTR1(0x01, 0x2C, 0x2D), 0), // 3: Frame rate ctrl - normal mode (Command::FRMCTR1([0x01, 0x2C, 0x2D]), 0), // 3: Frame rate ctrl - normal mode
// Rate = fosc/(1x2+40) * (LINE+2C+2D) // Rate = fosc/(1x2+40) * (LINE+2C+2D)
(Command::FRMCTR2(0x01, 0x2C, 0x2D), 0), // 4: Frame rate control - idle mode (Command::FRMCTR2([0x01, 0x2C, 0x2D]), 0), // 4: Frame rate control - idle mode
// Rate = fosc/(1x2+40) * (LINE+2C+2D) // Rate = fosc/(1x2+40) * (LINE+2C+2D)
(Command::FRMCTR3(0x01, 0x2C, 0x2D, // 5: Frame rate ctrl - partial mode (Command::FRMCTR3([0x01, 0x2C, 0x2D, // 5: Frame rate ctrl - partial mode
0x01, 0x2C, 0x2D), 0), // Dot inversion mode 0x01, 0x2C, 0x2D]), 0), // Dot inversion mode
// Line inversion mode // Line inversion mode
(Command::INVCTR(0x07), 0), // 6: Display inversion ctrl (Command::INVCTR(0x07), 0), // 6: Display inversion ctrl
// No inversion // No inversion
(Command::PWCTR1(0xA2, 0x02), 0), // 7: Power control, -4.6V AUTO mode (Command::PWCTR1([0xA2, 0x02]), 0), // 7: Power control, -4.6V AUTO mode
(Command::PWCTR2(0xC5), 0), // 8: Power control (Command::PWCTR2(0xC5), 0), // 8: Power control
// VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
(Command::PWCTR3(0x0A, 0x00), 0), // 9: Power control: (Command::PWCTR3([0x0A, 0x00]), 0), // 9: Power control:
// Opamp current small // Opamp current small
// Boost frequency // Boost frequency
(Command::PWCTR4(0x8A, 0x2A),0), // 10: Power control, 2 args, no delay: (Command::PWCTR4([0x8A, 0x2A]),0), // 10: Power control, 2 args, no delay:
// BCLK/2, Opamp current small & Medium low // BCLK/2, Opamp current small & Medium low
(Command::PWCTR5(0x8A, 0xEE), 0), // 11: Power control (Command::PWCTR5([0x8A, 0xEE]), 0), // 11: Power control
(Command::VMCTR1(0x0E, 0x4D), 0), // 12: Power control (Command::VMCTR1([0x0E, 0x4D]), 0), // 12: Power control
(Command::INVOFF, 0), // 13: Don't invert display (Command::INVOFF, 0), // 13: Don't invert display
(Command::MADCTL(0xC8), 0), // 14: Memory access control (directions), 1 arg: (Command::MADCTL(0xC8), 0), // 14: Memory access control (directions), 1 arg:
@ -202,44 +202,44 @@ const ST7735_RED_INIT : [(Command, u32); 15] = [
// Init for 7735R, part 2 (green tab only) // Init for 7735R, part 2 (green tab only)
const ST7735_RED_INIT_GREEN2 : [(Command, u32); 2] = [ const ST7735_RED_INIT_GREEN2 : [(Command, u32); 2] = [
(Command::CASET(0x00, 0x02, 0x00, 0x7F+0x02), 0), // 1: Column addr set (Command::CASET([0x00, 0x02, 0x00, 0x7F+0x02]), 0), // 1: Column addr set
// XSTART = 0 // XSTART = 0
// XEND = 127 // XEND = 127
(Command::RASET(0x00, 0x01, 0x00, 0x9F+0x01), 0) // 2: Row addr set (Command::RASET([0x00, 0x01, 0x00, 0x9F+0x01]), 0) // 2: Row addr set
// XSTART = 0 // XSTART = 0
// XEND = 159 // XEND = 159
]; ];
// Init for 7735R, part 2 (red tab only) // Init for 7735R, part 2 (red tab only)
const ST7735_RED_INIT_RED2 : [(Command, u32); 2] = [ const ST7735_RED_INIT_RED2 : [(Command, u32); 2] = [
(Command::CASET(0x00, 0x00, 0x00, 0x7F), 0), // 1: Column addr set, 4 args, no delay: (Command::CASET([0x00, 0x00, 0x00, 0x7F]), 0), // 1: Column addr set, 4 args, no delay:
// XSTART = 0 // XSTART = 0
// XEND = 127 // XEND = 127
(Command::RASET(0x00, 0x00, 0x00, 0x9F),0) // 2: Row addr set, 4 args, no delay: (Command::RASET([0x00, 0x00, 0x00, 0x9F]),0) // 2: Row addr set, 4 args, no delay:
// XSTART = 0 // XSTART = 0
// XEND = 159 // XEND = 159
]; ];
// Init for 7735R, part 2 (green 1.44 tab) // Init for 7735R, part 2 (green 1.44 tab)
const ST7735_RED_INIT_GREEN1442 : [(Command, u32); 2] = [ const ST7735_RED_INIT_GREEN1442 : [(Command, u32); 2] = [
(Command::CASET(0x00, 0x00, 0x00, 0x7F), 0), // 1: Column addr set, 4 args, no delay: (Command::CASET([0x00, 0x00, 0x00, 0x7F]), 0), // 1: Column addr set, 4 args, no delay:
// XSTART = 0 // XSTART = 0
// XEND = 127 // XEND = 127
(Command::RASET(0x00, 0x00, 0x00, 0x7F), 0) // 2: Row addr set, 4 args, no delay: (Command::RASET([0x00, 0x00, 0x00, 0x7F]), 0) // 2: Row addr set, 4 args, no delay:
// XSTART = 0 // XSTART = 0
// XEND = 127 // XEND = 127
]; ];
// Init for 7735R, part 3 (red or green tab) // Init for 7735R, part 3 (red or green tab)
const ST7735_RED_INIT3: [(Command, u32); 4] = [ const ST7735_RED_INIT3: [(Command, u32); 4] = [
(Command::GMCTRP1(0x02, 0x1c, 0x07, 0x12, // 1: Magical unicorn dust (Command::GMCTRP1([0x02, 0x1c, 0x07, 0x12, // 1: Magical unicorn dust
0x37, 0x32, 0x29, 0x2d, 0x37, 0x32, 0x29, 0x2d,
0x29, 0x25, 0x2B, 0x39, 0x29, 0x25, 0x2B, 0x39,
0x00, 0x01, 0x03, 0x10), 0), 0x00, 0x01, 0x03, 0x10]), 0),
(Command::GMCTRN1(0x03, 0x1d, 0x07, 0x06, // 2: Sparkles and rainbows (Command::GMCTRN1([0x03, 0x1d, 0x07, 0x06, // 2: Sparkles and rainbows
0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2C, 0x29, 0x2D,
0x2E, 0x2E, 0x37, 0x3F, 0x2E, 0x2E, 0x37, 0x3F,
0x00, 0x00, 0x02, 0x10), 0), 0x00, 0x00, 0x02, 0x10]), 0),
(Command::NORON, 10), // 3: Normal display, 10 ms delay (Command::NORON, 10), // 3: Normal display, 10 ms delay
(Command::DISPON, 100) // 4: Main screen turn on, 100 ms delay (Command::DISPON, 100) // 4: Main screen turn on, 100 ms delay
]; ];
@ -432,6 +432,8 @@ impl<SPIAddr, GPIOAddr> St7735IO<SPIAddr, GPIOAddr>
pub fn write_command(&mut self, cmd : Command) { pub fn write_command(&mut self, cmd : Command) {
let cmd_byte = command_to_byte(cmd); let cmd_byte = command_to_byte(cmd);
self.write_command_byte(cmd_byte); self.write_command_byte(cmd_byte);
} }
pub fn init(&mut self) { pub fn init(&mut self) {