#include <linux/init.h>
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/delay.h>
//0 1 2 3 4 5 6 7 8 9
char table1[10][2]={
{0x1,0x3f},{0x1,0x06},{0x1,0x5b},{0x1,0x4f},
{0x1,0x66},{0x1,0x6d},{0x1,0x7d},{0x1,0x07},
{0x1,0x7f},{0x1,0x6f},
};
char table2[10][2]={
{0x2,0x3f},{0x2,0x06},{0x2,0x5b},{0x2,0x4f},
{0x2,0x66},{0x2,0x6d},{0x2,0x7d},{0x2,0x07},
{0x2,0x7f},{0x2,0x6f},
};
char table3[10][2]={
{0x4,0x3f},{0x4,0x06},{0x4,0x5b},{0x4,0x4f},
{0x4,0x66},{0x4,0x6d},{0x4,0x7d},{0x4,0x07},
{0x4,0x7f},{0x4,0x6f},
};
int i,j;
void my_delay(unsigned int ms)
{
msleep(ms);
}
int m74hc595_probe(struct spi_device *spi)
{
for(i=0;i<10;i++)
{
for(j=0;j<3000;j++)
{
spi_write(spi,table1[i],sizeof(table1[i]));
spi_write(spi,table2[i],sizeof(table2[i]));
spi_write(spi,table3[i],sizeof(table3[i]));
}
}
return 0;
}
int m74hc595_remove(struct spi_device *spi)
{
printk("%s:%d\n",__FILE__,__LINE__);
return 0;
}
//设备树匹配表
struct of_device_id of_table[]={
{.compatible="hqyj,m74hc595"},
{},
};
MODULE_DEVICE_TABLE(of,of_table);
//定义SPI对象并且初始化
struct spi_driver m74hc595 ={
.probe=m74hc595_probe,
.remove=m74hc595_remove,
.driver={
.name="m74hc595",
.of_match_table=of_table,
},
};
module_spi_driver(m74hc595);
MODULE_LICENSE("GPL");
22111班5.4作业
于 2023-05-04 20:15:00 首次发布