设为首页 加入收藏

TOP

SPI子系统之驱动SSD1306 OLED(六)
2016-12-28 08:16:17 】 浏览:1175
Tags:SPI 子系统 驱动 SSD1306 OLED
is chip too.
*/
if (!(status == 0 && cs_change)) {
ndelay(nsecs);
bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
ndelay(nsecs);
}


spin_lock_irqsave(&bitbang->lock, flags);
}
bitbang->busy = 0;
/* [cgw]: 退出临界区 */
spin_unlock_irqrestore(&bitbang->lock, flags);
}


代码:


spi_platform_dev.c


#include



static struct spi_board_info board_info[1] = {
{
.modalias = "spi_ssd1306", /* [cgw]: spi设备名,和设备驱动名对应 */
.bus_num = 0, /* [cgw]: spi总线号,即spi0 */
.chip_select = 2, /* [cgw]: spi总线上的设备号,即spi0.2 */
.max_speed_hz = 50000, /* [cgw]: spi时钟 */
.mode = SPI_MODE_3, /* [cgw]: spi数据模式 */
},
};



static void ssd1306_chip_select(struct s3c2410_spigpio_info *spi, int cs)
{
/* [cgw]: 选中设备号为2的spi设备 */
if (spi->board_info->chip_select == 2) {
s3c2410_gpio_cfgpin(S3C2410_GPG2, S3C2410_GPIO_OUTPUT);
/* [cgw]: 选中设备 */
if (BITBANG_CS_ACTIVE == cs) {
s3c2410_gpio_setpin(S3C2410_GPG2, 0);
/* [cgw]: 释放设备 */
} else if (BITBANG_CS_INACTIVE == cs) {
s3c2410_gpio_setpin(S3C2410_GPG2, 1);
}
}
}


/* [cgw]: */
static struct s3c2410_spigpio_info spi_dev = {
.pin_clk = S3C2410_GPG7,
.pin_mosi = S3C2410_GPG5,
.pin_miso = S3C2410_GPG6,
.board_size = 1, /* [cgw]: 设置板上spi接口数量为1 */
.board_info = &board_info[0],
.chip_select = ssd1306_chip_select
};


static void spi_dev_release(struct device * dev)
{
printk("spi_dev_release! \n");
}


/* [cgw]: 分配一个平台设备 */
static struct platform_device spi_platform_dev = {
.name = "s3c24xx-spi-gpio", /* [cgw]: 设置平台设备名,和平台驱动名对应 */
.id = -1,
.dev = {
.release = spi_dev_release,
.platform_data = (void *)&spi_dev, /* [cgw]: 通过platform_data传递spi_dev给平台驱动
* 平台驱动可以访问spi_dev
*/
},
};



static int spi_dev_init(void)
{
/* [cgw]: 注册spi_platform_dev平台设备 */
platform_device_register(&spi_platform_dev);
return 0;
}


static void spi_dev_exit(void)
{
/* [cgw]: 注销spi_platform_dev平台设备 */
platform_device_unregister(&spi_platform_dev);
}


module_init(spi_dev_init);
module_exit(spi_dev_exit);


MODULE_LICENSE("GPL");


spi_ssd1306_drv.c


#include
#include
#include
#include
#include
#include
#include
#include


#define SSD1306_CMD 0
#define SSD1306_DAT 1


#define SSD1306_WIDTH 128
#define SSD1306_HEIGHT 64


static uint8_t s_chDispalyBuffer[128][8];


const uint8_t c_chFont1608[95][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xCC,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",1*/
{0x00,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x00,0x00},/*""",2*/
{0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x00,0x00},/*"#",3*/
{0x00,0x00,0x0E,0x18,0x11,0x04,0x3F,0xFF,0x10,0x84,0x0C,0x78,0x00,0x00,0x00,0x00},/*"$",4*/
{0x0F,0x00,0x10,0x84,0x0F,0x38,0x00,0xC0,0x07,0x78,0x18,0x84,0x00,0x78,0x00,0x00},/*"%",5*/
{0x00,0x78,0x0F,0x84,0x10,0xC4,0x11,0x24,0x0E,0x98,0x00,0xE4,0x00,0x84,0x00,0x08},/*"&",6*/
{0x08,0x00,0x68,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x18,0x18,0x20,0x04,0x40,0x02,0x00,0x00},/*"(",8*/
{0x00,0x00,0x40,0x02,0x2

首页 上一页 3 4 5 6 7 8 9 下一页 尾页 6/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Linux网络驱动--snull 下一篇深入理解 Spring 事务原理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目