From 8c706e2a4c8c8a9752ce9846c23f44c3df16c75c Mon Sep 17 00:00:00 2001 From: "Peter D. Gray" Date: Mon, 12 Jun 2023 11:26:13 -0400 Subject: [PATCH] QR display --- stm32/COLDCARD_Q1/modlcd.c | 103 ++++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 8 deletions(-) diff --git a/stm32/COLDCARD_Q1/modlcd.c b/stm32/COLDCARD_Q1/modlcd.c index 5c58a50a..9edf9ff5 100644 --- a/stm32/COLDCARD_Q1/modlcd.c +++ b/stm32/COLDCARD_Q1/modlcd.c @@ -29,10 +29,25 @@ #define CASET 0x2a #define RASET 0x2b #define RAMWR 0x2c - +#define DISPOFF 0x28 +#define DISPON 0x29 #define SWAB16(n) (( ((n)>>8) | ((n) << 8) )&0xffff) +/* have not needed +static inline void wait_vsync(void) { + // PB11 is TEAR input: a positive pulse every 60Hz that + // corresponds to vertical blanking time + uint32_t timeout = 1000000; + for(; timeout; timeout--) { + if(mp_hal_pin_read(PIN_LCD_TEAR)) { + return; + } + } + //puts("TEAR timeout"); +} +*/ + static inline void write_cmd(const spi_t *spi, uint8_t cmd) { // write a command byte @@ -40,7 +55,7 @@ static inline void write_cmd(const spi_t *spi, uint8_t cmd) mp_hal_pin_write(PIN_LCD_DATA_CMD, 0); mp_hal_pin_write(PIN_LCD_CS, 0); - spi_transfer(spi, 1, (const uint8_t *)&cmd, NULL, SPI_TRANSFER_TIMEOUT(1)); + HAL_SPI_Transmit(spi->spi, (uint8_t *)&cmd, 1, SPI_TRANSFER_TIMEOUT(1)); mp_hal_pin_write(PIN_LCD_CS, 1); } @@ -50,17 +65,15 @@ static inline void write_cmd2(const spi_t *spi, uint8_t cmd, uint16_t arg1, uint // Write a command byte, followed by 2 big-endian 16 bit arguments. uint16_t args[2] = { SWAB16(arg1), SWAB16(arg2)}; + // might be faster to avoid DMA for little transfers, so do that mp_hal_pin_write(PIN_LCD_CS, 1); mp_hal_pin_write(PIN_LCD_DATA_CMD, 0); mp_hal_pin_write(PIN_LCD_CS, 0); - //spi_transfer(spi, 1, (const uint8_t *)&cmd, NULL, SPI_TRANSFER_TIMEOUT(1)); HAL_SPI_Transmit(spi->spi, (uint8_t *)&cmd, 1, SPI_TRANSFER_TIMEOUT(1)); mp_hal_pin_write(PIN_LCD_DATA_CMD, 1); - // faster to avoid DMA for little transfers, so do that - //spi_transfer(spi, 4, (const uint8_t *)&args, NULL, SPI_TRANSFER_TIMEOUT(4)); HAL_SPI_Transmit(spi->spi, (uint8_t *)&args, 4, SPI_TRANSFER_TIMEOUT(4)); mp_hal_pin_write(PIN_LCD_CS, 1); @@ -79,6 +92,20 @@ static void write_data(const spi_t *spi, int len, const uint8_t *data) mp_hal_pin_write(PIN_LCD_CS, 1); } +static void write_data_repeated(const spi_t *spi, int count, int len, const uint8_t *data) +{ + // Send a bunch of pixel data, and repeat it N tim.es + mp_hal_pin_write(PIN_LCD_CS, 1); + mp_hal_pin_write(PIN_LCD_DATA_CMD, 1); + mp_hal_pin_write(PIN_LCD_CS, 0); + + for(int i=0; i>= 1) { + uint16_t here = ((*p) & m) ? COL_BLACK : COL_WHITE; + for(int r=0; r