/* 摄像头IO口采用直接操作寄存器的方式实现,极大提升io速度 */
#define BSP_FIFO_RCK_PIN "PA.5"
#define BSP_FIFO_RCK_SET_LOW (GPIOA_BASE[GPIOx] &= ~(1ul << 5))
#define BSP_FIFO_RCK_SET_HIGH (GPIOA_BASE[GPIOx] |= (1ul << 5))
/* sccb总线的初始化并设置ov7670相应寄存器 */
sccb_init();
if(sccb_write_reg(0x12, 0x80) == RT_FALSE){
return RT_FALSE;
}
rt_thread_delay(50);
id1 = sccb_read_reg(0x0b);
id2 = sccb_read_reg(0x0a);
rt_kprintf("id1 = 0x%02x, id2 = 0x%02xn", id1, id2);
for(rt_uint16_t i = 0;i < sizeof(ov7670_init_reg_tbl) / sizeof(ov7670_init_reg_tbl[0]);i++){
sccb_write_reg(ov7670_init_reg_tbl[0], ov7670_init_reg_tbl[1]);
}
/* 开启摄像头vsync扫描线程(没有外部中断因此改用轮询的方式实现) */
rt_thread_t thread;
/* 查询VSYNC线程 */
thread = rt_thread_create("ov7670_vsync", ov7670_vsync_thread_entry, RT_NULL, 1024, 5, 100);
if (thread == RT_NULL){
rt_kprintf("ov7670_vsync thread create fail!n");
return RT_FALSE;
}
/* 启动线程 */
rt_thread_startup(thread);
/* 提取hal库实现了uart的数据发送函数 */
void uart1_send(rt_uint8_t *pbuf, rt_uint32_t len)
{
for(rt_uint32_t i = 0;i < len;i++){
hal_uart_clrflag(UART1_BASE, UART_FLAG_TXPND);
hal_uart_write(UART1_BASE, pbuf);
while(hal_uart_getflag(UART1_BASE, UART_FLAG_TXPND) == 0);
}
}
/* LCD底层驱动代码,因为引脚不够,所以无法演示,测试可用,另外程序里也配有寄存器版本的操作代码 */
static rt_uint32_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *message)
{
struct rt_spi_bit_ops *ops = (struct rt_spi_bit_ops *)device->user_data;
rt_uint8_t tmp_buf[1024];
rt_memset(tmp_buf, 0, sizeof(tmp_buf));
if(message->send_buf == RT_NULL){
message->send_buf = tmp_buf;
}else if(message->recv_buf == RT_NULL){
message->recv_buf = tmp_buf;
}else{
return RT_FALSE;
}
if (message->cs_take){
ops->set_cs(ops->data, PIN_LOW);
}
#ifdef SPI_DC
message->length & SPI_DC ? ops->set_dc(ops->data, PIN_HIGH) : ops->set_dc(ops->data, PIN_LOW);
message->length &= ~SPI_DC; /* 复原消息长度 */
// rt_kprintf("message->length = %dn", message->length);
#endif
spi_rw_bytes(device, (rt_uint8_t *)message->send_buf, (rt_uint8_t *)message->recv_buf, message->length);
if (message->cs_release){
ops->set_cs(ops->data, PIN_HIGH);
}
}
static const struct rt_spi_ops spi_bit_bus_ops ={
RT_NULL,
spi_bit_xfer
};
评论