void ssd1306_init(void)
{
ssd1306_write_byte(0xAE, SSD1306_CMD);//--turn off oled panel
ssd1306_write_byte(0x00, SSD1306_CMD);//---set low column address
ssd1306_write_byte(0x10, SSD1306_CMD);//---set high column address
ssd1306_write_byte(0x40, SSD1306_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
ssd1306_write_byte(0x81, SSD1306_CMD);//--set contrast control register
ssd1306_write_byte(0xCF, SSD1306_CMD);// Set SEG Output Current Brightness
ssd1306_write_byte(0xA1, SSD1306_CMD);//--Set SEG/Column Mapping
ssd1306_write_byte(0xC0, SSD1306_CMD);//Set COM/Row Scan Direction
ssd1306_write_byte(0xA6, SSD1306_CMD);//--set normal display
ssd1306_write_byte(0xA8, SSD1306_CMD);//--set multiplex ratio(1 to 64)
ssd1306_write_byte(0x3f, SSD1306_CMD);//--1/64 duty
ssd1306_write_byte(0xD3, SSD1306_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
ssd1306_write_byte(0x00, SSD1306_CMD);//-not offset
ssd1306_write_byte(0xd5, SSD1306_CMD);//--set display clock divide ratio/oscillator frequency
ssd1306_write_byte(0x80, SSD1306_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
ssd1306_write_byte(0xD9, SSD1306_CMD);//--set pre-charge period
ssd1306_write_byte(0xF1, SSD1306_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
ssd1306_write_byte(0xDA, SSD1306_CMD);//--set com pins hardware configuration
ssd1306_write_byte(0x12, SSD1306_CMD);
ssd1306_write_byte(0xDB, SSD1306_CMD);//--set vcomh
ssd1306_write_byte(0x40, SSD1306_CMD);//Set VCOM Deselect Level
ssd1306_write_byte(0x20, SSD1306_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
ssd1306_write_byte(0x02, SSD1306_CMD);//
ssd1306_write_byte(0x8D, SSD1306_CMD);//--set Charge Pump enable/disable
ssd1306_write_byte(0x14, SSD1306_CMD);//--set(0x10) disable
ssd1306_write_byte(0xA4, SSD1306_CMD);// Disable Entire Display On (0xa4/0xa5)
ssd1306_write_byte(0xA6, SSD1306_CMD);// Disable Inverse Display On (0xa6/a7)
ssd1306_write_byte(0xAF, SSD1306_CMD);//--turn on oled panel
ssd1306_display_on();
ssd1306_clear_screen(0xff);
}
static int ssd1306_detect(struct i2c_adapter *adapter, int address, int kind)
{
printk("ssd1306_detect\n");
ssd1306_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
ssd1306_client->addr = address;
ssd1306_client->adapter = adapter;
ssd1306_client->driver = &ssd1306_driver;
strcpy(ssd1306_client->name, "ssd1306");
i2c_attach_client(ssd1306_client);
ssd1306_init();
ssd1306_clear_screen(0x00);
ssd1306_display_off();
ssd1306_display_string(18, 0, "hello, Linux!", 16, 1);
ssd1306_display_string(0, 16, "this is an i2c driver demo!", 16, 1);
ssd1306_refresh_gram();
ssd1306_display_on();
return 0;
}
static int ssd1306_attach_adapter(struct i2c_adapter *adapter)
{
return i2c_probe(adapter, &addr_data, ssd1306_detect);
}
static int ssd1306_detach_client(struct i2c_client *client)
{
printk("ssd1306_detach\n");
ssd1306_display_off();
ssd1306_clear_screen(0x00);
i2c_detach_client(client);
return 0;
}
static int ssd1306_module_init(void)
{
i2c_add_driver(&ssd1306_driver);
return 0;
}
static void ssd1306_module_exit(void)
{
i2c_del_driver(&ssd1306_driver);
}
module_init(ssd1306_module_init);
module_exit(ssd1306_module_exit);
MODULE_LICENSE("GPL");