void LCD_Init() { rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); //MOSI gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO10); //CLK gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO11); //RST gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12); //A0 gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO13); //CS gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO14); NCS_HI(); RST_HI(); lcd_delay(5); RST_LO(); lcd_delay(120); //11ms RST_HI(); lcd_delay(2500); AspiCmd(0xE2); lcd_delay(2500); lcd_screen_init(); lcd_delay(120); lcd_screen_init(); lcd_delay(120); AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled memset(img, 0, sizeof(img)); memset(dirty, 0, sizeof(dirty)); //Clear screen for (int y = 0; y < LCD_HEIGHT; y++) { lcd_set_row(y); AspiCmd(0xAF); CLK_HI(); A0_HI(); NCS_LO(); for (int x = 0; x < 212; x++) { //write_pixel(((x/53) % 2) ^ ((y / 16) %2)); write_pixel(0); } NCS_HI(); A0_HI(); AspiData(0); } }
/* Screen is 212 x 64 with 4bpp */ void LCD_DrawStop(void) { for (int y = 0; y < LCD_HEIGHT; y++) { if(! (dirty[y / 8] & (1 << (y % 8)))) continue; u8 *p = &img[(y / 8) * LCD_WIDTH]; u8 mask = 1 << (y % 8); lcd_set_row(y); AspiCmd(0xAF); CLK_HI(); A0_HI(); NCS_LO(); for (int x = 0; x < LCD_WIDTH; x++) { write_pixel(p[x] & mask); } NCS_HI(); A0_HI(); AspiData(0); } memset(dirty, 0, sizeof(dirty)); }
void refreshDisplay() { for (uint32_t y=0; y<DISPLAY_H; y++) { uint8_t *p = &DisplayBuf[(y>>3)*DISPLAY_W]; uint8_t mask = (1 << (y%8)); GPIO_TypeDef *gpiod = GPIOD ; uint32_t *bsrr = (uint32_t *)&gpiod->BSRRL ; Set_Address(0, y); AspiCmd(0xAF); gpiod->BSRRL = PIN_LCD_CLK ; // Clock high gpiod->BSRRL = PIN_LCD_A0 ; // A0 high gpiod->BSRRH = PIN_LCD_NCS ; // CS low for (uint32_t x=0; x<DISPLAY_W; x+=2) { uint32_t data ; data = 0 ; if ( p[x] & mask ) { data = 0xF0 ; } if (p[x+1] & mask ) { data += 0x0F ; } if(data&0x80) { gpiod->BSRRL = PIN_LCD_MOSI ; } else { gpiod->BSRRH = PIN_LCD_MOSI ; } gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x40) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x20) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x10) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x08) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x04) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x02) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x01) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low __no_operation() ; gpiod->BSRRL = PIN_LCD_CLK ; // Clock high } gpiod->BSRRL = PIN_LCD_NCS ; // CS high gpiod->BSRRL = PIN_LCD_A0 ; AspiData(0); } }