// print text // ---------------------------------------------------------- void RAIO_print_text( uint16_t pos_x, uint16_t pos_y, unsigned char *str, uint8_t BG_color, uint8_t FG_color ) { union my_union number; // set cursor number.value = pos_x; RAIO_SetRegister( CURH0, number.split.low ); RAIO_SetRegister( CURH1, number.split.high ); number.value = pos_y; RAIO_SetRegister( CURV0, number.split.low ); RAIO_SetRegister( CURV1, number.split.high ); // set color Text_Background_Color( BG_color ); Text_Foreground_Color( FG_color ); // set text mode RAIO_SetRegister( MWCR0, 0x80 ); // write text to display TFT_RegWrite( MRWC ); while ( *str != '\0' ) { TFT_DataWrite( *str ); ++str; TFT_wait_for_raio(); } TFT_wait_for_raio(); // set graphic mode RAIO_SetRegister( MWCR0, 0x00 ); }
// set draw mode // ---------------------------------------------------------- void RAIO_StartDrawing( int16_t whattodraw ) { switch( whattodraw ) // -> see DRAW_MODES { case CIRCLE_NONFILL: {RAIO_SetRegister( DCR, 0x40 ); break;} case CIRCLE_FILL: {RAIO_SetRegister( DCR, 0x60 ); break;} case SQUARE_NONFILL: {RAIO_SetRegister( DCR, 0x90 ); break;} case SQUARE_FILL: {RAIO_SetRegister( DCR, 0xB0 ); break;} case LINE: {RAIO_SetRegister( DCR, 0x80 ); break;} default: break; } TFT_wait_for_raio(); }
// clear screen // ---------------------------------------------------------- void RAIO_clear_screen( void ) { // for more informations see RA8870 specification page 40 // // | Bit | Function // |-----|------------------------------------------------- // | 7 | 0 = stop clear 1 = start clear // | 6 | 0 = fullwindow 1 = activewindow // | 5-1 | NA // | 0 | 0 = Memory clear with BTE background color 1 = Memory clear with font background color // // Reg 0x43 define font background color ( RRRGGGBB ) // Reg 0x60, 0x61, 0x62 define BTE background color ( BGCR0=red[4:0], BGCR1=green[5:0], BGCR2=blue[4:0] ) RAIO_SetRegister( MCLR , 0x80 ); TFT_wait_for_raio(); }
// initialization of RAIO8870 // ---------------------------------------------------------- void RAIO_init( void ) { static uint8_t PLL_Initial_Flag = 0; // *************** PLL settings (System Clock) if ( !PLL_Initial_Flag ) // wait until PLL is ready { PLL_Initial_Flag = 1; // set Flag to avoid repeated PLL init RAIO_SetRegister( PLLC1, 0x07 ); // set sys_clk bcm2835_delayMicroseconds( 200 ); RAIO_SetRegister( PLLC2, 0x03 ); // set sys_clk bcm2835_delayMicroseconds( 200 ); RAIO_SetRegister( PWRR, 0x01 ); // Raio software reset ( bit 0 ) set RAIO_SetRegister( PWRR, 0x00 ); // Raio software reset ( bit 0 ) set to 0 delay( 100 ); // *************** color modes (color depths) #ifdef CM_65K // System Configuration Register RAIO_SetRegister( SYSR, 0x0A ); // digital TFT // parallel data out // no external memory // 8bit memory data bus // 16bpp 65K color // 16bit MCU-interface (data) RAIO_SetRegister( DPCR, 0x00 ); // one layer #elif defined(CM_4K) // System Configuration Register RAIO_SetRegister( SYSR, 0x06 ); // digital TFT // parallel data out // no external memory // 8bit memory data bus // 12bpp 4K color // 16bit MCU-interface (data) RAIO_SetRegister( DPCR, 0x80 ); // two layers RAIO_SetRegister( MWCR1, BankNo_WR ); RAIO_SetRegister( LTPR0, BankNo_RD ); #else #error "color_mode not defined" #endif } // *************** horizontal settings // 0x27+1 * 8 = 320 pixel RAIO_SetRegister( HDWR , (DISPLAY_WIDTH / 8) - 1 ); RAIO_SetRegister( HNDFTR, 0x02 ); // Horizontal Non-Display Period Fine Tuning // HNDR , Horizontal Non-Display Period Bit[4:0] // Horizontal Non-Display Period (pixels) = (HNDR + 1)*8 RAIO_SetRegister( HNDR, 0x03 ); // 0x06 RAIO_SetRegister( HSTR, 0x04 ); //HSTR , HSYNC Start Position[4:0], HSYNC Start Position(PCLK) = (HSTR + 1)*8 0x02 // HPWR , HSYNC Polarity ,The period width of HSYNC. // 1xxxxxxx activ high 0xxxxxxx activ low // HSYNC Width [4:0] HSYNC Pulse width // (PCLK) = (HPWR + 1)*8 RAIO_SetRegister( HPWR, 0x03 ); // 0x00 // ********************* vertical settings // 0x0EF +1 = 240 pixel RAIO_SetRegister( VDHR0 , ( (DISPLAY_HEIGHT-1) & 0xFF ) ); RAIO_SetRegister( VDHR1 , ( (DISPLAY_HEIGHT-1) >> 8) ); // VNDR0 , Vertical Non-Display Period Bit [7:0] // Vertical Non-Display area = (VNDR + 1) // VNDR1 , Vertical Non-Display Period Bit [8] // Vertical Non-Display area = (VNDR + 1) RAIO_SetRegister( VNDR0, 0x10 ); RAIO_SetRegister( VNDR1, 0x00 ); // VPWR , VSYNC Polarity ,VSYNC Pulse Width[6:0] // VSYNC , Pulse Width(PCLK) = (VPWR + 1) RAIO_SetRegister( VPWR, 0x00 ); // *************** miscellaneous settings // active Window Active_Window( 0, DISPLAY_WIDTH-1, 0, DISPLAY_HEIGHT-1 ); // PCLK fetch data on rising edge RAIO_SetRegister( PCLK, 0x00 ); // Backlight dimming RAIO_SetBacklightPWMValue(50); Text_Background_Color( COLOR_WHITE ); // memory clear with background color RAIO_SetRegister( MCLR, 0x81 ); TFT_wait_for_raio(); RAIO_SetRegister( IODR, 0x07 ); RAIO_SetRegister( PWRR, 0x80 ); }
void RAIO_screen_off( void ) { RAIO_SetRegister( PWRR , 0x40 ); TFT_wait_for_raio(); }