예제 #1
0
파일: ssd1306.c 프로젝트: noahp/usb_pwrmon
void ssd1306_writeStringSize2(char *str, uint32_t pos)
{
    uint32_t i = 0, j;

    ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0);  // low col = 0
    ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0);  // hi col = 0
    ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0

    // for each chr in the string, print it to the display
    while((*str != '\0') && ((i+1)*6*8 < 128*64)){
        if(((*str-0x20) < 96) && (*str >= 0x20)){
            for(j=0; j<5; j++){
                ssd1306_data(font5x8[(*str-0x20)*5+j]);
            }
        }
        else{
            for(j=0; j<5; j++){
                ssd1306_data(0);
            }
        }
        ssd1306_data(0);
        str++;
        i++;
    }
    i = (128*64-i*6*8)/8;
    while(i--){
        ssd1306_data(0);
    }
}
예제 #2
0
void SSD1306::display(void) {
  ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0);  // low col = 0
  ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0);  // hi col = 0
  ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0

  for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
    ssd1306_data(buffer[i]);
  }
  // i wonder why we have to do this (check datasheet)
  if (SSD1306_LCDHEIGHT == 32) {
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      ssd1306_data(0);
    }
  }
}
예제 #3
0
void ssd1306_displayBlock(SSD1306 *p, int row, int col, int col_count, int col_offset /* = 0 */)
{
    if (!p) return;

    /* for now always transmit whole image */
    uint8_t rows = p->height;
    uint8_t cols = p->width;

    /* devide by 8 -- black/white display 8 Bits = 1 Byte = 8 Pixels */
    uint8_t pagecount = rows >> 3;
    uint8_t pagestart = row >> 3;
    uint8_t pageend = pagestart + pagecount - 1;
    uint8_t colstart = col;
    uint8_t colend = col + col_count - 1;

    ssd1306_command(p, SSD1306_MEMORYMODE);
    ssd1306_command(p, SSD1306_MEMORY_MODE_VERT);

    ssd1306_command(p, SSD1306_PAGEADDRESS);
    ssd1306_command(p, pagestart);
    ssd1306_command(p, pageend);

    ssd1306_command(p, SSD1306_COLADDRESS);
    ssd1306_command(p, colstart);
    ssd1306_command(p, colend);

    int length = col_count * pagecount;

    ssd1306_data(p, p->bitmap, length);
}
예제 #4
0
파일: ssd1306.c 프로젝트: wythe-lin/ZTKBLE
void ssd1306_clr_gddram(void)
{
	unsigned char	x, y;

	for (y=0; y<8; y++) {
		ssd1306_set_pagecol(y, 0);
		for (x=0; x<128; x++) {
			ssd1306_data(0x00);
		}
	}
}
예제 #5
0
void ssd1306_clear_row_column(unsigned char row, unsigned char column_start, unsigned char column_end)
{
    unsigned char x;
    unsigned char y;

    ssd1306_command(0xB0 + row);
    ssd1306_command(0x01);
    ssd1306_command(0x10);

    for (x = column_start; x < column_end; x++) {
        ssd1306_data(0x00);
    }
}
예제 #6
0
void ssd1306_clear_row(unsigned char row)
{
    unsigned char x;
    unsigned char y;

    ssd1306_command(0xB0 + row);
    ssd1306_command(0x01);
    ssd1306_command(0x10);

    for (x = 0; x < WIDTH; x++) {
        ssd1306_data(0x00);
    }
}
예제 #7
0
void ssd1306_fill(unsigned char color)
{
    unsigned char x;
    unsigned char y;

    for (y = 0; y < SEGMENTS; y++) {
        ssd1306_command(0xB0 + y);
        ssd1306_command(0x01);
        ssd1306_command(0x10);

        for (x = 0; x < WIDTH; x++) {
            ssd1306_data(color);
        }
    }
}
예제 #8
0
void ssd1306_draw_8x16_string(unsigned char x, unsigned char y, const char *string)
{
    unsigned char i;
    const char *chr;
    char printable_char;
    for (chr = string; *chr != '\0'; chr++) {
        printable_char = *chr - ' ';
        if (x > 120) {
            x = 0;
            y++;
        }
        ssd1306_set_coordinate(x, y);
        for (i = 0; i < SEGMENTS; i++) {
            ssd1306_data(pgm_read_byte(&F8X16[printable_char * 16 + i]));
        }

        ssd1306_set_coordinate(x, y + 1);
        for (i = 0; i < SEGMENTS; i++) {
            ssd1306_data(pgm_read_byte(&F8X16[printable_char * 16 + i + 8]));
        }

        x += 8;
    }
}
예제 #9
0
void ssd1306_draw_6x8_string(unsigned char x, unsigned char y, const char *string)
{
    unsigned char i;
    const char *chr;
    char printable_char;

    for (chr = string; *chr != '\0'; chr++) {
        printable_char = *chr - ' ';
        if (x > 126) {
            x = 0;
            y++;
        }
        ssd1306_set_coordinate(x, y);
        for (i = 0; i < 6; i++) {
            ssd1306_data(pgm_read_byte(&F6x8[printable_char][i]));
        }
        x += 6;
    }
}
예제 #10
0
파일: ssd1306.c 프로젝트: noahp/usb_pwrmon
void ssd1306_init(void)
{
    uint32_t i;

    // init necessary io

    // enable clocks for PORTA & PORTB
    SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
    SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;

    // pin 13, B5 output for rst
    PORTB_PCR5 = PORT_PCR_MUX(1);   // gpio
    GPIOB_PCOR = (1 << 5);          // low initially
    GPIOB_PDDR |= (1 << 5);         // output mode

    // pin 6, a6 output for dc
    PORTA_PCR6 = PORT_PCR_MUX(1);   // gpio
    GPIOA_PCOR = (1 << 6);          // low initially
    GPIOA_PDDR |= (1 << 6);         // output mode

    // init spi0
    // configure io pins for spi
    // PTA5, 7, PTB0
    PORTA_PCR5 = PORT_PCR_MUX(3);   // CS
    PORTA_PCR7 = PORT_PCR_MUX(3);   // MOSI
    PORTB_PCR0 = PORT_PCR_MUX(3);   // SCK

    // enable SPI0 module
    SIM_SCGC4 |= SIM_SCGC4_SPI0_MASK;

    // configure as master, cs output driven automatically, CPOL=1
    SPI0_C1 |= (SPI_C1_MSTR_MASK | SPI_C1_SSOE_MASK | SPI_C1_CPOL_MASK);
    SPI0_C2 |= SPI_C2_MODFEN_MASK;

    // select clock divider- SPPR = 0, SPR = 0 (2)
    SPI0_BR = SPI_BR_SPPR(0) | SPI_BR_SPR(3);

    // turn on spi
    SPI0_C1 |= SPI_C1_SPE_MASK;

    // do some setup on the oled display
    // wait a ms after 3.3v comes up on reset
    delay_ms(10);
    // reset low for 10ms
    CLR_RST();  // low
    delay_ms(10);
    SET_RST();  // now high

    // give it a few ms after reset goes high
    delay_ms(5);

    // now initialize display controller
    // Init sequence for 128x64 OLED module
    ssd1306_command(SSD1306_DISPLAYOFF);                    // 0xAE
    ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
    ssd1306_command(0x80);                                  // the suggested ratio 0x80
    ssd1306_command(SSD1306_SETMULTIPLEX);                  // 0xA8
    ssd1306_command(0x3F);
    ssd1306_command(SSD1306_SETDISPLAYOFFSET);              // 0xD3
    ssd1306_command(0x0);                                   // no offset
    ssd1306_command(SSD1306_SETSTARTLINE | 0x0);            // line #0
    ssd1306_command(SSD1306_CHARGEPUMP);                    // 0x8D
    ssd1306_command(0x14);                                  // internall VCC
    ssd1306_command(SSD1306_MEMORYMODE);                    // 0x20
    ssd1306_command(0x00);                                  // 0x0 act like ks0108
    ssd1306_command(SSD1306_SEGREMAP /*| 0x1*/);
    ssd1306_command(SSD1306_COMSCANINC);
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x12);
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    ssd1306_command(0xCF);                                  // internal VCC
    ssd1306_command(SSD1306_SETPRECHARGE);                  // 0xd9
    ssd1306_command(0xF1);                                  // internal VCC
    ssd1306_command(SSD1306_SETVCOMDETECT);                 // 0xDB
    ssd1306_command(0x40);
    ssd1306_command(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
    ssd1306_command(SSD1306_NORMALDISPLAY);                 // 0xA6

    ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel

    // set display to noahs face
    ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0);  // low col = 0
    ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0);  // hi col = 0
    ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0

    for(i=0; i<SSD1306_SIZEOF_SCREENBUF; i++){
        ssd1306_data(noahs_face[i]);
    }
}