コード例 #1
0
ファイル: ssd1306.c プロジェクト: nickfox-taterli/libssd1306
void ssd1306_reset(SSD1306 *p)
{
    if (!p) return;

    rpiIO_digitalWrite(p->resetPin, 0);
    ssd1306_delay(10);
    rpiIO_digitalWrite(p->resetPin, 1);
}
コード例 #2
0
int
main(int argc, char * argv[])
{
	printf("Starting SSD1306 Test\n");

	int spiChannel = 0;
	int resetPin = 17;
	int dcPin = 21;
	printf("Using SPI Channel %d\n", spiChannel);
	printf("Reset Pin = %d, DC Pin = %d\n", resetPin, dcPin);


	/*
	 * 10 MHz did work on a breadboard
	 * safer to use slower speeds probably
	 * 200 kHz is the approximate minimum
	 * otherwise not all data will be transmitted
	 */

	int clock = 200000;
	SSD1306 * disp = ssd1306_create(spiChannel, resetPin, dcPin, clock);

	printf("Init\n");
	ssd1306_init(disp, SSD1306_ROWS_64, SSD1306_VCCSATE_SWITCHCAP);

	int y = 0;
	int x = 0;
	for (; x < 100; x += 1) {
		for (y = 0; y < 10; ++y) {
			ssd1306_setPixel(disp, x, y, 1);
		}
	}


	for (x = 0; x < 100; x += 10) {
		for (y = 0; y < 10; ++y) {
			ssd1306_setPixel(disp, x, y, 0);
		}
	}

	printf("Display 10 white Boxes\n");
	ssd1306_display(disp);
	ssd1306_delay(1000);

	printf("Clear\n");
	ssd1306_clear(disp, 0);

	printf("Draw Lines\n");
	int i;
	for (i=0; i < 128; i+=4) {
		ssd1306_drawLine(disp, 0, 0, i, 64-1, 1);
		ssd1306_display(disp);
	}

	for (i=0; i < 64; i+=4) {
		ssd1306_drawLine(disp, 0, 0, 128-1, i, 1);
		ssd1306_display(disp);
	}

	printf("Start Scrool Right\n");
	ssd1306_startScrollRight(disp, 0x00, 0x0F);
	ssd1306_delay(2000);
	ssd1306_stopScroll(disp);
	ssd1306_delay(1000);

	printf("Start Scrool Left\n");
	ssd1306_startScrollLeft(disp, 0x00, 0x0F);
	ssd1306_delay(2000);
	ssd1306_stopScroll(disp);
	ssd1306_delay(1000);

	ssd1306_destroy(disp);

	return 0;
}
コード例 #3
0
ファイル: ssd1306.c プロジェクト: nickfox-taterli/libssd1306
static void begin(SSD1306 *p)
{
    ssd1306_delay(1);

    ssd1306_reset(p);

    ssd1306_command(p, SSD1306_DISPLAYOFF);
    ssd1306_command(p, SSD1306_SETDISPLAYCLOCKDIV);
    ssd1306_command(p, 0x80);
    ssd1306_command(p, SSD1306_SETMULTIPLEX);
    if (p->rowtype == SSD1306_ROWS_32)
    {
        ssd1306_command(p, 0x1F);
    }
    else if (p->rowtype == SSD1306_ROWS_64)
    {
        ssd1306_command(p, 0x3F);
    }
    ssd1306_command(p, SSD1306_SETDISPLAYOFFSET);
    ssd1306_command(p, 0x00);
    ssd1306_command(p, SSD1306_SETSTARTLINE | 0x00);

    ssd1306_command(p, SSD1306_CHARGEPUMP);
    if (p->vccstate == SSD1306_VCCSATE_EXTERNAL)
    {
        ssd1306_command(p, 0x10);
    }
    else
    {
        ssd1306_command(p, 0x14);
    }

    ssd1306_command(p, SSD1306_MEMORYMODE);
    ssd1306_command(p, 0x00);
    ssd1306_command(p, SSD1306_SEGREMAP | 0x01);
    ssd1306_command(p, SSD1306_COMSCANDEC);

    if (p->rowtype == SSD1306_ROWS_32)
    {
        ssd1306_command(p, SSD1306_SETCOMPINS);
        ssd1306_command(p, 0x02);
        ssd1306_command(p, SSD1306_SETCONTRAST);
        ssd1306_command(p, 0x8F);
    }
    else if (p->rowtype == SSD1306_ROWS_64)
    {
        ssd1306_command(p, SSD1306_SETCOMPINS);
        ssd1306_command(p, 0x12);
        ssd1306_command(p, SSD1306_SETCONTRAST);
        if (p->vccstate == SSD1306_VCCSATE_EXTERNAL)
        {
            ssd1306_command(p, 0x9F);
        }
        else
        {
            ssd1306_command(p, 0xCF);
        }
    }

    ssd1306_command(p, SSD1306_SETPRECHARGE);
    if (p->vccstate == SSD1306_VCCSATE_EXTERNAL)
    {
        ssd1306_command(p, 0x22);
    }
    else
    {
        ssd1306_command(p, 0xF1);
    }

    ssd1306_command(p, SSD1306_SETVCOMDETECT);
    ssd1306_command(p, 0x40);
    ssd1306_command(p, SSD1306_DISPLAYALLON_RESUME);
    ssd1306_command(p, SSD1306_NORMALDISPLAY);

    ssd1306_command(p, SSD1306_DISPLAYON);
}