mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-08 05:48:28 +00:00
[fix] fix some bsp driver
This commit is contained in:
parent
a11dcbed30
commit
8b74fe873c
28 changed files with 1704 additions and 1196 deletions
|
@ -1,78 +0,0 @@
|
||||||
/**
|
|
||||||
* @file audio_proto.c
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#include "drv_device.h"
|
|
||||||
#include "audio_core.h"
|
|
||||||
#include "hal_dma.h"
|
|
||||||
|
|
||||||
volatile int (*buffer_ready_callback_func)(char bufIndex);
|
|
||||||
volatile audio_core_t * audio_core_cfg_store;
|
|
||||||
volatile int bufferIndex = 0;
|
|
||||||
|
|
||||||
void audio_core_transfer_done(struct device *dev, void *args, uint32_t size, uint32_t state){
|
|
||||||
|
|
||||||
if(!state){
|
|
||||||
if(buffer_ready_callback_func){
|
|
||||||
buffer_ready_callback_func(bufferIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bufferIndex){
|
|
||||||
bufferIndex = 0;
|
|
||||||
device_write(audio_core_cfg_store->audio_device,0,audio_core_cfg_store->buff1,audio_core_cfg->buff_size);
|
|
||||||
}else{
|
|
||||||
bufferIndex = 1;
|
|
||||||
device_write(audio_core_cfg_store->audio_device,0,audio_core_cfg_store->buff2,audio_core_cfg->buff_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_core_init(audio_core_t * audio_core_cfg){
|
|
||||||
|
|
||||||
if(audio_core_cfg->audio_dma == NULL ||
|
|
||||||
audio_core_cfg->buff_size == NULL||
|
|
||||||
audio_core_cfg->buff1 == NULL ||
|
|
||||||
audio_core_cfg->buff2 == NULL){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
memset(audio_core_cfg->buff1,0,audio_core_cfg->buff_size);
|
|
||||||
memset(audio_core_cfg->buff2,0,audio_core_cfg->buff_size);
|
|
||||||
|
|
||||||
device_control(audio_core_cfg->audio_device,DEVICE_CTRL_ATTACH_TX_DMA,(void*)audio_core_cfg->audio_dma);
|
|
||||||
|
|
||||||
device_set_callback(audio_core_cfg->audio_dma, audio_core_transfer_done);
|
|
||||||
|
|
||||||
buffer_ready_callback_func = audio_core_cfg->buffer_ready_callback;
|
|
||||||
audio_core_cfg_store = audio_core_cfg;
|
|
||||||
|
|
||||||
device_control(audio_core_cfg->audio_dma, DEVICE_CTRL_SET_INT, NULL);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_core_start(void){
|
|
||||||
device_write(audio_core_cfg_store->audio_device,0,audio_core_cfg_store->buff1,audio_core_cfg_store->buff_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int audio_core_stop(void){
|
|
||||||
dma_channel_stop(audio_core_cfg_store->audio_dma);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
# bl音频协议框架
|
|
||||||
|
|
||||||
## 核心音频播放组件
|
|
||||||
|
|
||||||
如下图所示
|
|
||||||
|
|
||||||
[](https://imgtu.com/i/c1Q8qe)
|
|
||||||
|
|
||||||
|
|
||||||
整体框架分为两个部分,一个部分是由核心组件提供的双缓存结构,另一个部分是用户的实际使用代码。
|
|
||||||
|
|
||||||
**核心组件需要两个构件**
|
|
||||||
|
|
||||||
1 双缓存,用户需要在自己的应用中开辟两块长度相同的内存块,将其指针传入核心组件。
|
|
||||||
|
|
||||||
2 dma组件,用户需要将配置好了的 dma device 指针传入核心组件,此dma的作用是将设备的数据通过P->M写回Buffer 或者 将数据通过M->P写入Device。搬运的request需要在device的配置参数中给定。
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**核心组件后的运行逻辑**
|
|
||||||
|
|
||||||
当用户打开音频构架的核心组件代码后
|
|
||||||
组件会首先初始化Buffer1和Buffer2的内容,初始化为0,并且立即打开DMA搬运。
|
|
||||||
当DMA搬运结束,会触发Buffer_Ready中断回调。
|
|
||||||
|
|
||||||
在录音的应用下
|
|
||||||
|
|
||||||
打开核心组件后,DMA会根据Device的DMA Request,把录音数据搬运到Buffer1和Buffer2,用户需要做的是在Buffer_Ready中断回调发生后,将对应Buffer取出来,保存、或者通过下文提到的协议发送。
|
|
||||||
|
|
||||||
在播放音频的应用下
|
|
||||||
|
|
||||||
打开核心组件后,DMA会立即播放Buffer1和Buffer2的数据,但是因为最开始的时候已经初始化Buffer数据为0,所以不会有任何声音播放。用户需要在Buffer_Ready中断回调发生后,以合适的方式,将需要播放的PCM音频数据更新到Buffer中(此过程必须在下一个Buffer消耗完成之前,否则会产生问题),如果在buffer2的数据消耗结束之前还没能完成buffer1的数据更新,那么需要考虑如何加快数据更新速度,或者增加Buffer的size以提供更多操作时间。
|
|
||||||
|
|
||||||
|
|
||||||
## 2 通讯协议约定
|
|
||||||
|
|
||||||
当用户代码部分需要与外界进行通讯时,需要统一规范一个交互的协议,这样不同的音频应用可以兼容相同的audio_cube。
|
|
||||||
|
|
||||||
1 传输音频文件流(目前仅支持wav格式播放)
|
|
||||||
2 每次传输的字节数,使用规范的约定字节数
|
|
||||||
3 是否支持校验
|
|
||||||
4 播放/暂停 停止 音量调整的固定协议
|
|
|
@ -1,76 +0,0 @@
|
||||||
/**
|
|
||||||
* @file wav_info_parser.c
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "wav_info_parser.h"
|
|
||||||
|
|
||||||
/* get File pointer from top of file*/
|
|
||||||
int wav_data_parser(uint8_t buff[1024], wav_information_t *wav_information)
|
|
||||||
{
|
|
||||||
uint32_t offset=0;
|
|
||||||
uint32_t chunk_id;
|
|
||||||
|
|
||||||
/* RIFF WAVE Chunk */
|
|
||||||
chunk_id = ((chunk_riff_t *)&buff[offset])->chunk_id;
|
|
||||||
if(chunk_id == 0x46464952)
|
|
||||||
{
|
|
||||||
wav_information->chunk_riff_offset = offset;
|
|
||||||
wav_information->chunk_riff = *((chunk_riff_t *)&buff[offset]);
|
|
||||||
offset += sizeof(chunk_riff_t);
|
|
||||||
}else{
|
|
||||||
wav_information->chunk_riff_offset = -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/* Format Chunk */
|
|
||||||
chunk_id = ((chunk_format_t *)&buff[offset])->chunk_id;
|
|
||||||
if(chunk_id == 0x20746D66 && offset<1000) /* fmt */
|
|
||||||
{
|
|
||||||
wav_information->chunk_format_offset = offset;
|
|
||||||
wav_information->chunk_format = *((chunk_format_t *)&buff[offset]);
|
|
||||||
offset += ((chunk_format_t*)&buff[offset])->chunk_size + 8;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
wav_information->chunk_format_offset = -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/* Fact/list Chunk */
|
|
||||||
chunk_id = ((chunk_fact_t *)&buff[offset])->chunk_id;
|
|
||||||
if((chunk_id == 0X74636166 || chunk_id == 0X5453494C) && offset<1000) /*fact or list*/
|
|
||||||
{
|
|
||||||
wav_information->chunk_fact_offset = offset;
|
|
||||||
wav_information->chunk_fact = *((chunk_fact_t *)&buff[offset]);
|
|
||||||
offset += ((chunk_fact_t*)&buff[offset])->chunk_size + 8;
|
|
||||||
}else{
|
|
||||||
wav_information->chunk_fact_offset = -1;
|
|
||||||
}
|
|
||||||
/* Data Chunk */
|
|
||||||
chunk_id = ((chunk_data_t *)&buff[offset])->chunk_id;
|
|
||||||
if(chunk_id == 0X61746164 && offset<1000 )
|
|
||||||
{
|
|
||||||
wav_information->chunk_data_offset = offset;
|
|
||||||
wav_information->chunk_data = *((chunk_data_t *)&buff[offset]);
|
|
||||||
}else{
|
|
||||||
wav_information->chunk_data_offset = -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
/**
|
|
||||||
* @file wav_info_parser.h
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __WAV_INFO_PARSER__
|
|
||||||
#define __WAV_INFO_PARSER__
|
|
||||||
|
|
||||||
#include "bl_common.h"
|
|
||||||
|
|
||||||
/* RIFF (RIFF WAVE Chunk) */
|
|
||||||
typedef struct __attribute__((packed))
|
|
||||||
{
|
|
||||||
uint32_t chunk_id;
|
|
||||||
uint32_t chunk_size;
|
|
||||||
uint32_t format;
|
|
||||||
}chunk_riff_t ;
|
|
||||||
|
|
||||||
/* fmt (Format Chunk)*/
|
|
||||||
typedef struct __attribute__((packed))
|
|
||||||
{
|
|
||||||
uint32_t chunk_id;
|
|
||||||
uint32_t chunk_size ;
|
|
||||||
uint16_t audio_format;
|
|
||||||
uint16_t num_of_channels;
|
|
||||||
uint32_t sample_rate;
|
|
||||||
uint32_t byte_rate;
|
|
||||||
uint16_t block_align;
|
|
||||||
uint16_t bits_per_sample;
|
|
||||||
}chunk_format_t;
|
|
||||||
|
|
||||||
//fact (Fact Chunk)
|
|
||||||
typedef struct __attribute__((packed))
|
|
||||||
{
|
|
||||||
uint32_t chunk_id;
|
|
||||||
uint32_t chunk_size ;
|
|
||||||
uint32_t data_fact_size;
|
|
||||||
}chunk_fact_t;
|
|
||||||
|
|
||||||
//data (Data Chunk)
|
|
||||||
typedef struct __attribute__((packed))
|
|
||||||
{
|
|
||||||
uint32_t chunk_id;
|
|
||||||
uint32_t chunk_size ;
|
|
||||||
}chunk_data_t;
|
|
||||||
|
|
||||||
//
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
CHUNK_RIFF,
|
|
||||||
CHUNK_FORMAT,
|
|
||||||
CHUNK_FACT,
|
|
||||||
CHUNK_DATA,
|
|
||||||
}mav_chunk_t;
|
|
||||||
|
|
||||||
//.wav information
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int chunk_riff_offset;
|
|
||||||
chunk_riff_t chunk_riff;
|
|
||||||
int chunk_format_offset;
|
|
||||||
chunk_format_t chunk_format;
|
|
||||||
int chunk_fact_offset;
|
|
||||||
chunk_fact_t chunk_fact;
|
|
||||||
int chunk_data_offset;
|
|
||||||
chunk_data_t chunk_data;
|
|
||||||
}wav_information_t;
|
|
||||||
|
|
||||||
int wav_data_parser(uint8_t buff[1024], wav_information_t *wav_information);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "bsp_il9341.h"
|
#include "bsp_il9341.h"
|
||||||
#include "hal_spi.h"
|
#include "hal_spi.h"
|
||||||
#include "hal_dma.h"
|
#include "hal_dma.h"
|
||||||
|
|
||||||
/** @addtogroup BL702_Peripheral_Case
|
/** @addtogroup BL702_Peripheral_Case
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
@ -66,9 +67,14 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct device* spi0;
|
static struct device* spi0;
|
||||||
struct device* dma_ch3;
|
static struct device* dma_ch3;
|
||||||
struct device* dma_ch4;
|
static struct device* dma_ch4;
|
||||||
|
|
||||||
|
void dma_ch3_callback(struct device *dev, void *args, uint32_t size, uint32_t event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Private_Functions */
|
/*@} end of group TFT_LCD_Private_Functions */
|
||||||
|
|
||||||
|
@ -77,43 +83,64 @@ struct device* dma_ch4;
|
||||||
*/
|
*/
|
||||||
void spi0_init(void)
|
void spi0_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
spi_register(SPI0_INDEX,"spi0",DEVICE_OFLAG_RDWR);
|
|
||||||
dma_register(DMA0_CH3_INDEX, "dma0_ch3", DEVICE_OFLAG_RDWR);
|
|
||||||
dma_register(DMA0_CH4_INDEX, "dma0_ch4", DEVICE_OFLAG_RDWR);
|
|
||||||
gpio_set_mode(LCD_CS_PIN,GPIO_OUTPUT_MODE);
|
gpio_set_mode(LCD_CS_PIN,GPIO_OUTPUT_MODE);
|
||||||
gpio_set_mode(LCD_DC_PIN,GPIO_OUTPUT_MODE);
|
gpio_set_mode(LCD_DC_PIN,GPIO_OUTPUT_MODE);
|
||||||
gpio_write(LCD_CS_PIN,1); //CS1
|
gpio_write(LCD_CS_PIN,1); //CS1
|
||||||
gpio_write(LCD_DC_PIN,1);//DC
|
gpio_write(LCD_DC_PIN,1); //DC
|
||||||
|
|
||||||
spi0 = device_find("spi0");
|
spi0 = device_find("spi0");
|
||||||
if(spi0)
|
if(spi0)
|
||||||
|
{
|
||||||
|
device_close(spi0);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
spi_register(SPI0_INDEX,"spi0",DEVICE_OFLAG_RDWR);
|
||||||
|
spi0 = device_find("spi0");
|
||||||
|
}
|
||||||
|
if(spi0)
|
||||||
{
|
{
|
||||||
device_open(spi0,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
|
device_open(spi0,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
|
||||||
}
|
}
|
||||||
|
|
||||||
dma_ch3 = device_find("dma0_ch3");
|
dma_ch3 = device_find("dma0_ch3");
|
||||||
|
if(dma_ch3)
|
||||||
|
{
|
||||||
|
device_close(dma_ch3);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
dma_register(DMA0_CH3_INDEX, "dma0_ch3", DEVICE_OFLAG_RDWR);
|
||||||
|
dma_ch3 = device_find("dma0_ch3");
|
||||||
|
}
|
||||||
if (dma_ch3)
|
if (dma_ch3)
|
||||||
{
|
{
|
||||||
((dma_device_t*)dma_ch3)->direction = DMA_MEMORY_TO_PERIPH;
|
DMA_DEV(dma_ch3)->direction = DMA_MEMORY_TO_PERIPH;
|
||||||
((dma_device_t*)dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
|
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
|
||||||
((dma_device_t*)dma_ch3)->src_req = DMA_REQUEST_NONE;
|
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_NONE;
|
||||||
((dma_device_t*)dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
|
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
|
||||||
((dma_device_t*)dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
|
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
|
||||||
((dma_device_t*)dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
|
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
|
||||||
device_open(dma_ch3, 0);
|
device_open(dma_ch3, 0);
|
||||||
device_set_callback(dma_ch3, NULL);
|
device_set_callback(dma_ch3, NULL);
|
||||||
device_control(dma_ch3, DEVICE_CTRL_SET_INT, NULL);
|
device_control(dma_ch3, DEVICE_CTRL_SET_INT, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
dma_ch4 = device_find("dma0_ch4");
|
dma_ch4 = device_find("dma0_ch4");
|
||||||
|
if(dma_ch4)
|
||||||
|
{
|
||||||
|
device_close(dma_ch4);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
dma_register(DMA0_CH4_INDEX, "dma0_ch4", DEVICE_OFLAG_RDWR);
|
||||||
|
dma_ch4 = device_find("dma0_ch4");
|
||||||
|
}
|
||||||
if (dma_ch4)
|
if (dma_ch4)
|
||||||
{
|
{
|
||||||
((dma_device_t*)dma_ch4)->direction = DMA_PERIPH_TO_MEMORY;
|
DMA_DEV(dma_ch4)->direction = DMA_PERIPH_TO_MEMORY;
|
||||||
((dma_device_t*)dma_ch4)->transfer_mode = DMA_LLI_ONCE_MODE;
|
DMA_DEV(dma_ch4)->transfer_mode = DMA_LLI_ONCE_MODE;
|
||||||
((dma_device_t*)dma_ch4)->src_req = DMA_REQUEST_SPI0_RX;
|
DMA_DEV(dma_ch4)->src_req = DMA_REQUEST_SPI0_RX;
|
||||||
((dma_device_t*)dma_ch4)->dst_req = DMA_REQUEST_NONE;
|
DMA_DEV(dma_ch4)->dst_req = DMA_REQUEST_NONE;
|
||||||
((dma_device_t*)dma_ch4)->src_width = DMA_TRANSFER_WIDTH_8BIT ;
|
DMA_DEV(dma_ch4)->src_width = DMA_TRANSFER_WIDTH_8BIT ;
|
||||||
((dma_device_t*)dma_ch4)->dst_width = DMA_TRANSFER_WIDTH_8BIT ;
|
DMA_DEV(dma_ch4)->dst_width = DMA_TRANSFER_WIDTH_8BIT ;
|
||||||
device_open(dma_ch4, 0);
|
device_open(dma_ch4, 0);
|
||||||
device_set_callback(dma_ch4, NULL);
|
device_set_callback(dma_ch4, NULL);
|
||||||
device_control(dma_ch4, DEVICE_CTRL_CLR_INT, NULL);
|
device_control(dma_ch4, DEVICE_CTRL_CLR_INT, NULL);
|
||||||
|
@ -187,6 +214,50 @@ void LCD_WR_Word(uint32_t data)
|
||||||
CS1_HIGH;
|
CS1_HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LCD_WR_SPI_DMA(uint16_t *img, uint32_t len)
|
||||||
|
{
|
||||||
|
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_32BIT;
|
||||||
|
DMA_DEV(dma_ch3)->src_burst_size =0;
|
||||||
|
DMA_DEV(dma_ch3)->dst_burst_size =1;
|
||||||
|
device_control(spi0,DEVICE_CTRL_TX_DMA_RESUME,NULL);
|
||||||
|
CS1_LOW;
|
||||||
|
DC_HIGH;
|
||||||
|
dma_reload(dma_ch3, (uint32_t)img, (uint32_t)DMA_ADDR_SPI_TDR, len);
|
||||||
|
dma_channel_start(dma_ch3);
|
||||||
|
while(dma_channel_check_busy(dma_ch3));
|
||||||
|
device_control(spi0,DEVICE_CTRL_TX_DMA_SUSPEND,NULL);
|
||||||
|
CS1_HIGH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************//**
|
||||||
|
* @brief LCD set dir
|
||||||
|
*
|
||||||
|
* @param dir: dir
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
void LCD_Set_Dir(uint8_t dir )
|
||||||
|
{
|
||||||
|
LCD_WR_Cmd(0x36);
|
||||||
|
switch (dir)
|
||||||
|
{
|
||||||
|
case 0 :
|
||||||
|
LCD_WR_Byte(0x08);
|
||||||
|
break;
|
||||||
|
case 1 :
|
||||||
|
LCD_WR_Byte(0xA8);
|
||||||
|
break;
|
||||||
|
case 2 :
|
||||||
|
LCD_WR_Byte(0xC8);
|
||||||
|
break;
|
||||||
|
case 3 :
|
||||||
|
LCD_WR_Byte(0x68);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************//**
|
/****************************************************************************//**
|
||||||
* @brief LCD set address
|
* @brief LCD set address
|
||||||
|
@ -201,6 +272,7 @@ void LCD_WR_Word(uint32_t data)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void LCD_Set_Addr(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2)
|
void LCD_Set_Addr(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2)
|
||||||
{
|
{
|
||||||
|
|
||||||
LCD_WR_Cmd(0x2a);
|
LCD_WR_Cmd(0x2a);
|
||||||
LCD_WR_Word(x2<<24 | (x2<<8&0xff0000) | (x1<<8&0xff00) | (x1>>8&0xff));
|
LCD_WR_Word(x2<<24 | (x2<<8&0xff0000) | (x1<<8&0xff00) | (x1>>8&0xff));
|
||||||
|
|
||||||
|
@ -265,6 +337,8 @@ void LCD_Init(void)
|
||||||
LCD_WR_HalfWord(0x1800);
|
LCD_WR_HalfWord(0x1800);
|
||||||
LCD_WR_Cmd(0xb6); /* Display Function Control */
|
LCD_WR_Cmd(0xb6); /* Display Function Control */
|
||||||
LCD_WR_HalfWord(0xa20a);
|
LCD_WR_HalfWord(0xa20a);
|
||||||
|
LCD_WR_Cmd(0x0c); /* display pixel format */
|
||||||
|
LCD_WR_Byte(0xd5); /* RGB 16bits,MCU 16bits */
|
||||||
LCD_WR_Cmd(0xf2); /* 3Gamma Function Disable */
|
LCD_WR_Cmd(0xf2); /* 3Gamma Function Disable */
|
||||||
LCD_WR_Byte(0x00);
|
LCD_WR_Byte(0x00);
|
||||||
LCD_WR_Cmd(0xf7);
|
LCD_WR_Cmd(0xf7);
|
||||||
|
@ -474,6 +548,17 @@ void LCD_DrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LCD_DrawPicture_cam(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* picture)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
LCD_Set_Addr(x1,y1,x2,y2);
|
||||||
|
for(i=0;i<ABS16((x2-x1+1)*(y2-y1+1));i++)
|
||||||
|
{
|
||||||
|
// LCD_WR_Byte(picture[i]);
|
||||||
|
// LCD_WR_Word(picture[i]);
|
||||||
|
LCD_WR_HalfWord(picture[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************//**
|
/****************************************************************************//**
|
||||||
* @brief LCD use uart to receive picture data and send to display
|
* @brief LCD use uart to receive picture data and send to display
|
||||||
|
|
|
@ -75,6 +75,7 @@ void LCD_WR_Cmd(uint8_t command);
|
||||||
void LCD_WR_Byte(uint8_t data);
|
void LCD_WR_Byte(uint8_t data);
|
||||||
void LCD_WR_HalfWord(uint16_t data);
|
void LCD_WR_HalfWord(uint16_t data);
|
||||||
void LCD_WR_Word(uint32_t data);
|
void LCD_WR_Word(uint32_t data);
|
||||||
|
void LCD_Set_Dir(uint8_t dir);
|
||||||
void LCD_Set_Addr(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2);
|
void LCD_Set_Addr(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2);
|
||||||
void LCD_Init(void);
|
void LCD_Init(void);
|
||||||
void LCD_Clear(uint16_t color);
|
void LCD_Clear(uint16_t color);
|
||||||
|
@ -84,6 +85,8 @@ void LCD_DrawRectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t
|
||||||
void LCD_DrawCircle(uint16_t x,uint16_t y,uint16_t r,uint16_t color);
|
void LCD_DrawCircle(uint16_t x,uint16_t y,uint16_t r,uint16_t color);
|
||||||
void LCD_DrawArea(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
|
void LCD_DrawArea(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
|
||||||
void LCD_DrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* picture);
|
void LCD_DrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* picture);
|
||||||
|
void LCD_DrawPicture_cam(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* picture);
|
||||||
|
void LCD_WR_SPI_DMA(uint16_t *img, uint32_t len);
|
||||||
// void LCD_UartDrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,UART_ID_Type uartId);
|
// void LCD_UartDrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,UART_ID_Type uartId);
|
||||||
void LCD_DrawChinese(uint16_t x,uint16_t y,uint8_t* character,uint16_t bColor,uint16_t cColor);
|
void LCD_DrawChinese(uint16_t x,uint16_t y,uint8_t* character,uint16_t bColor,uint16_t cColor);
|
||||||
|
|
||||||
|
|
|
@ -1,515 +0,0 @@
|
||||||
/**
|
|
||||||
* @file bsp_il9431.c
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bsp_il9431.h"
|
|
||||||
#include "hal_spi.h"
|
|
||||||
|
|
||||||
/** @addtogroup BL702_Peripheral_Case
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup TFT_LCD
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Private_Macros
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Private_Macros */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Private_Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Private_Types */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Private_Variables
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Private_Variables */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Global_Variables
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Global_Variables */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Private_Fun_Declaration
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Private_Fun_Declaration */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Private_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
struct device* spi_lcd;
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Private_Functions */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Public_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
void spi_lcd_init(void)
|
|
||||||
{
|
|
||||||
spi_register(SPI0_INDEX,"spi_lcd",DEVICE_OFLAG_RDWR);
|
|
||||||
gpio_set_mode(LCD_CS_PIN,GPIO_OUTPUT_MODE);
|
|
||||||
gpio_set_mode(LCD_DC_PIN,GPIO_OUTPUT_MODE);
|
|
||||||
gpio_write(LCD_CS_PIN,1); //CS1
|
|
||||||
gpio_write(LCD_DC_PIN,1);//DC
|
|
||||||
spi_lcd = device_find("spi_lcd");
|
|
||||||
if(spi_lcd)
|
|
||||||
{
|
|
||||||
device_open(spi_lcd,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD write command
|
|
||||||
*
|
|
||||||
* @param command: Command to write
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_WR_Cmd(uint8_t command)
|
|
||||||
{
|
|
||||||
CS1_LOW;
|
|
||||||
DC_LOW;
|
|
||||||
spi_transmit(spi_lcd,&command,1,SPI_TRANSFER_TYPE_8BIT);
|
|
||||||
CS1_HIGH;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD write 8-bit data
|
|
||||||
*
|
|
||||||
* @param data: 8-bit data to write
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_WR_Byte(uint8_t data)
|
|
||||||
{
|
|
||||||
CS1_LOW;
|
|
||||||
DC_HIGH;
|
|
||||||
spi_transmit(spi_lcd,&data,1,SPI_TRANSFER_TYPE_8BIT);
|
|
||||||
CS1_HIGH;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD write 16-bit data
|
|
||||||
*
|
|
||||||
* @param data: 16-bit data to write
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_WR_HalfWord(uint16_t data)
|
|
||||||
{
|
|
||||||
CS1_LOW;
|
|
||||||
DC_HIGH;
|
|
||||||
spi_transmit(spi_lcd,&data,1,SPI_TRANSFER_TYPE_16BIT);
|
|
||||||
CS1_HIGH;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD write 32-bit data
|
|
||||||
*
|
|
||||||
* @param data: 32-bit data to write
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_WR_Word(uint32_t data)
|
|
||||||
{
|
|
||||||
CS1_LOW;
|
|
||||||
DC_HIGH;
|
|
||||||
spi_transmit(spi_lcd,&data,1,SPI_TRANSFER_TYPE_32BIT);
|
|
||||||
CS1_HIGH;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD set address
|
|
||||||
*
|
|
||||||
* @param x1: Coordinate x start
|
|
||||||
* @param y1: Coordinate y start
|
|
||||||
* @param x2: Coordinate x end
|
|
||||||
* @param y2: Coordinate y end
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_Set_Addr(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2)
|
|
||||||
{
|
|
||||||
LCD_WR_Cmd(0x2a);
|
|
||||||
LCD_WR_Word(x2<<24 | (x2<<8&0xff0000) | (x1<<8&0xff00) | (x1>>8&0xff));
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0x2b);
|
|
||||||
LCD_WR_Word(y2<<24 | (y2<<8&0xff0000) | (y1<<8&0xff00) | (y1>>8&0xff));
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0x2C);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief SPI LCD init
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_Init(void)
|
|
||||||
{
|
|
||||||
spi_lcd_init();
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0x11); /* Exit sleep */
|
|
||||||
bflb_platform_delay_ms(60);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xcf);
|
|
||||||
LCD_WR_HalfWord(0xd900);
|
|
||||||
LCD_WR_Byte(0X30);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xed);
|
|
||||||
LCD_WR_Word(0x81120364);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xe8);
|
|
||||||
LCD_WR_HalfWord(0x1085);
|
|
||||||
LCD_WR_Byte(0x78);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xcb);
|
|
||||||
LCD_WR_Word(0x34002c39);
|
|
||||||
LCD_WR_Byte(0x02);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xf7);
|
|
||||||
LCD_WR_Byte(0x20);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xea);
|
|
||||||
LCD_WR_HalfWord(0x0000);
|
|
||||||
|
|
||||||
LCD_WR_Cmd(0xc0); /* Power control */
|
|
||||||
LCD_WR_Byte(0x23); /* VRH[5:0] */
|
|
||||||
LCD_WR_Cmd(0xc1); /* Power control */
|
|
||||||
LCD_WR_Byte(0x12); /* SAP[2:0];BT[3:0] */
|
|
||||||
LCD_WR_Cmd(0xc2);
|
|
||||||
LCD_WR_Byte(0x11);
|
|
||||||
LCD_WR_Cmd(0xC5); /* VCM control */
|
|
||||||
LCD_WR_HalfWord(0x3040);
|
|
||||||
LCD_WR_Cmd(0xc7); /* VCM control2 */
|
|
||||||
LCD_WR_Byte(0xa9);
|
|
||||||
LCD_WR_Cmd(0x3a);
|
|
||||||
LCD_WR_Byte(0x55);
|
|
||||||
LCD_WR_Cmd(0x36); /* Memory Access Control */
|
|
||||||
LCD_WR_Byte(0x08);
|
|
||||||
LCD_WR_Cmd(0xb1); /* Frame Rate Control */
|
|
||||||
LCD_WR_HalfWord(0x1800);
|
|
||||||
LCD_WR_Cmd(0xb6); /* Display Function Control */
|
|
||||||
LCD_WR_HalfWord(0xa20a);
|
|
||||||
LCD_WR_Cmd(0xf2); /* 3Gamma Function Disable */
|
|
||||||
LCD_WR_Byte(0x00);
|
|
||||||
LCD_WR_Cmd(0xf7);
|
|
||||||
LCD_WR_Byte(0x20);
|
|
||||||
LCD_WR_Cmd(0x26); /* Gamma curve selected */
|
|
||||||
LCD_WR_Byte(0x01);
|
|
||||||
LCD_WR_Cmd(0xe0); /* Set Gamma */
|
|
||||||
LCD_WR_Word(0x0b23241f);
|
|
||||||
LCD_WR_Word(0xd850080f);
|
|
||||||
LCD_WR_Word(0x000a083b);
|
|
||||||
LCD_WR_HalfWord(0x0000);
|
|
||||||
LCD_WR_Byte(0x00);
|
|
||||||
LCD_WR_Cmd(0Xe1); /* Set Gamma */
|
|
||||||
LCD_WR_Word(0x041c1b00);
|
|
||||||
LCD_WR_Word(0x272f0710);
|
|
||||||
LCD_WR_Word(0x0f150744);
|
|
||||||
LCD_WR_HalfWord(0x3f3f);
|
|
||||||
LCD_WR_Byte(0x1f);
|
|
||||||
LCD_WR_Cmd(0x29); /* Display on */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD clear display
|
|
||||||
*
|
|
||||||
* @param color: Color to fill
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_Clear(uint16_t color)
|
|
||||||
{
|
|
||||||
uint16_t i,j;
|
|
||||||
LCD_Set_Addr(0,0,LCD_W-1,LCD_H-1);
|
|
||||||
for(i=0;i<LCD_W;i++){
|
|
||||||
for (j=0;j<LCD_H;j++){
|
|
||||||
LCD_WR_HalfWord(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD draw a point
|
|
||||||
*
|
|
||||||
* @param x: Coordinate x
|
|
||||||
* @param y: Coordinate y
|
|
||||||
* @param color: Color of the point
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
|
|
||||||
{
|
|
||||||
LCD_Set_Addr(x,y,x,y);
|
|
||||||
LCD_WR_HalfWord(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD draw line
|
|
||||||
*
|
|
||||||
* @param x1: Coordinate x start
|
|
||||||
* @param y1: Coordinate y start
|
|
||||||
* @param x2: Coordinate x end
|
|
||||||
* @param y2: Coordinate y end
|
|
||||||
* @param color: Color of the line
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color)
|
|
||||||
{
|
|
||||||
int xVariation,yVariation,temp;
|
|
||||||
int absX,absY,i;
|
|
||||||
xVariation = x2-x1;
|
|
||||||
yVariation = y2-y1;
|
|
||||||
absX = ABS32(xVariation);
|
|
||||||
absY = ABS32(yVariation);
|
|
||||||
|
|
||||||
if(absX > absY){
|
|
||||||
for(i=0;i<absX+1;i++){
|
|
||||||
temp = yVariation*100/absX*i/100;
|
|
||||||
if(xVariation>0){
|
|
||||||
LCD_DrawPoint(x1+i,y1+temp,color);
|
|
||||||
}else{
|
|
||||||
LCD_DrawPoint(x1-i,y1+temp,color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
for(i=0;i<absY+1;i++){
|
|
||||||
temp = xVariation*100/absY*i/100;
|
|
||||||
if(yVariation>0){
|
|
||||||
LCD_DrawPoint(x1+temp,y1+i,color);
|
|
||||||
}else{
|
|
||||||
LCD_DrawPoint(x1+temp,y1-i,color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD draw rectangle
|
|
||||||
*
|
|
||||||
* @param x1: Coordinate x start
|
|
||||||
* @param y1: Coordinate y start
|
|
||||||
* @param x2: Coordinate x end
|
|
||||||
* @param y2: Coordinate y end
|
|
||||||
* @param color: Color of the rectangle
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawRectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color)
|
|
||||||
{
|
|
||||||
LCD_DrawLine(x1,y1,x2,y1,color);
|
|
||||||
LCD_DrawLine(x2,y1,x2,y2,color);
|
|
||||||
LCD_DrawLine(x2,y2,x1,y2,color);
|
|
||||||
LCD_DrawLine(x1,y2,x1,y1,color);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD draw circle
|
|
||||||
*
|
|
||||||
* @param x: Center coordinate x
|
|
||||||
* @param y: Center coordinate y
|
|
||||||
* @param r: Radius
|
|
||||||
* @param color: Color of the circle
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawCircle(uint16_t x,uint16_t y,uint16_t r,uint16_t color)
|
|
||||||
{
|
|
||||||
int a = 0,b;
|
|
||||||
int di;
|
|
||||||
b = r;
|
|
||||||
di = 3-(r<<1);
|
|
||||||
while(a <= b)
|
|
||||||
{
|
|
||||||
LCD_DrawPoint(x-b,y-a,color);
|
|
||||||
LCD_DrawPoint(x+b,y-a,color);
|
|
||||||
LCD_DrawPoint(x-a,y+b,color);
|
|
||||||
LCD_DrawPoint(x-b,y-a,color);
|
|
||||||
LCD_DrawPoint(x-a,y-b,color);
|
|
||||||
LCD_DrawPoint(x+b,y+a,color);
|
|
||||||
LCD_DrawPoint(x+a,y-b,color);
|
|
||||||
LCD_DrawPoint(x+a,y+b,color);
|
|
||||||
LCD_DrawPoint(x-b,y+a,color);
|
|
||||||
a++;
|
|
||||||
if(di<0){
|
|
||||||
di += 4*a+6;
|
|
||||||
}else{
|
|
||||||
di += 10+4*(a-b);
|
|
||||||
b--;
|
|
||||||
}
|
|
||||||
LCD_DrawPoint(x+a,y+b,color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD fill the area with color
|
|
||||||
*
|
|
||||||
* @param x1: Coordinate x start
|
|
||||||
* @param y1: Coordinate y start
|
|
||||||
* @param x2: Coordinate x end
|
|
||||||
* @param y2: Coordinate y end
|
|
||||||
* @param color: Color to fill
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawArea(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color)
|
|
||||||
{
|
|
||||||
uint16_t i,j;
|
|
||||||
LCD_Set_Addr(x1,y1,x2,y2);
|
|
||||||
for(i=y1;i<=y2;i++)
|
|
||||||
{
|
|
||||||
for(j=x1;j<=x2;j++)LCD_WR_HalfWord(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD draw picture
|
|
||||||
*
|
|
||||||
* @param x1: Coordinate x start
|
|
||||||
* @param y1: Coordinate y start
|
|
||||||
* @param x2: Coordinate x end
|
|
||||||
* @param y2: Coordinate y end
|
|
||||||
* @param picture: Color array of the picture
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* picture)
|
|
||||||
{
|
|
||||||
uint32_t i;
|
|
||||||
LCD_Set_Addr(x1,y1,x2,y2);
|
|
||||||
for(i=0;i<ABS16((x2-x1+1)*(y2-y1+1));i++)
|
|
||||||
{
|
|
||||||
LCD_WR_HalfWord(picture[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD use uart to receive picture data and send to display
|
|
||||||
*
|
|
||||||
* @param x1: Coordinate x start
|
|
||||||
* @param y1: Coordinate y start
|
|
||||||
* @param x2: Coordinate x end
|
|
||||||
* @param y2: Coordinate y end
|
|
||||||
* @param uartId: Color array of the picture
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
// void LCD_UartDrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,UART_ID_Type uartId)
|
|
||||||
// {
|
|
||||||
// uint32_t rxLen = 0,i;
|
|
||||||
// uint32_t recvCnt = 0;
|
|
||||||
// uint8_t uartRxBuf[UART_RX_FIFO_SIZE] = {0};
|
|
||||||
// LCD_Set_Addr(x1,y1,x2,y2);
|
|
||||||
|
|
||||||
// UART_Enable(uartId,UART_RX);
|
|
||||||
|
|
||||||
// while(rxLen < 2*(x2-x1+1)*(y2-y1+1)){
|
|
||||||
// while((recvCnt=UART_GetRxFifoCount(uartId)) == 0){}
|
|
||||||
// rxLen += UART_ReceiveData(uartId,uartRxBuf,recvCnt);
|
|
||||||
// for(i=0;i<recvCnt;i++){
|
|
||||||
// LCD_WR_Byte(uartRxBuf[i]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// UART_Disable(uartId,UART_RX);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************//**
|
|
||||||
* @brief LCD draw a 32*32 chinese character in lattice mode
|
|
||||||
*
|
|
||||||
* @param x: Coordinate x
|
|
||||||
* @param y: Coordinate y
|
|
||||||
* @param character: Array of the character
|
|
||||||
* @param bColor: Color of the background
|
|
||||||
* @param cColor: Color of the character
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
void LCD_DrawChinese(uint16_t x,uint16_t y,uint8_t* character,uint16_t bColor,uint16_t cColor)
|
|
||||||
{
|
|
||||||
uint8_t i,j;
|
|
||||||
LCD_Set_Addr(x,y,x+31,y+31);
|
|
||||||
for(j=0;j<128;j++)
|
|
||||||
{
|
|
||||||
for(i=0;i<8;i++)
|
|
||||||
{
|
|
||||||
if((*character&(1<<i)) != 0)
|
|
||||||
{
|
|
||||||
LCD_WR_HalfWord(cColor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LCD_WR_HalfWord(bColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
character++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Public_Functions */
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD */
|
|
||||||
|
|
||||||
/*@} end of group BL702_Peripheral_Case */
|
|
|
@ -1,96 +0,0 @@
|
||||||
/**
|
|
||||||
* @file bsp_il9431.h
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef __TFT_LCD_H__
|
|
||||||
#define __TFT_LCD_H__
|
|
||||||
|
|
||||||
#include "hal_gpio.h"
|
|
||||||
/** @addtogroup BL702_Peripheral_Driver
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup TFT_LCD
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Public_Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Public_Types */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Public_Constants
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Public_Constants */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Public_Macros
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
#define LCD_CS_PIN GPIO_PIN_10
|
|
||||||
#define LCD_DC_PIN GPIO_PIN_22
|
|
||||||
|
|
||||||
#define CS1_HIGH gpio_write(LCD_CS_PIN,1)
|
|
||||||
#define CS1_LOW gpio_write(LCD_CS_PIN,0)
|
|
||||||
#define DC_HIGH gpio_write(LCD_DC_PIN,1)
|
|
||||||
#define DC_LOW gpio_write(LCD_DC_PIN,0)
|
|
||||||
#define LCD_W 240 /* LCD width */
|
|
||||||
#define LCD_H 320 /* LCD height */
|
|
||||||
/* Turn 24-bit RGB color to 16-bit */
|
|
||||||
#define RGB(r,g,b) (((r>>3)<<3|(g>>5)|(g>>2)<<13|(b>>3)<<8)&0xffff)
|
|
||||||
/* Calculate 32-bit or 16-bit absolute value */
|
|
||||||
#define ABS32(value) ((value^(value>>31))-(value>>31))
|
|
||||||
#define ABS16(value) ((value^(value>>15))-(value>>15))
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Public_Macros */
|
|
||||||
|
|
||||||
/** @defgroup TFT_LCD_Public_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Tft_lcd Functions
|
|
||||||
*/
|
|
||||||
void LCD_WR_Cmd(uint8_t command);
|
|
||||||
void LCD_WR_Byte(uint8_t data);
|
|
||||||
void LCD_WR_HalfWord(uint16_t data);
|
|
||||||
void LCD_WR_Word(uint32_t data);
|
|
||||||
void LCD_Set_Addr(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2);
|
|
||||||
void LCD_Init(void);
|
|
||||||
void LCD_Clear(uint16_t color);
|
|
||||||
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
|
|
||||||
void LCD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
|
|
||||||
void LCD_DrawRectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
|
|
||||||
void LCD_DrawCircle(uint16_t x,uint16_t y,uint16_t r,uint16_t color);
|
|
||||||
void LCD_DrawArea(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
|
|
||||||
void LCD_DrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t* picture);
|
|
||||||
// void LCD_UartDrawPicture(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,UART_ID_Type uartId);
|
|
||||||
void LCD_DrawChinese(uint16_t x,uint16_t y,uint8_t* character,uint16_t bColor,uint16_t cColor);
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD_Public_Functions */
|
|
||||||
|
|
||||||
/*@} end of group TFT_LCD */
|
|
||||||
|
|
||||||
/*@} end of group BL702_Peripheral_Driver */
|
|
||||||
|
|
||||||
#endif /* __TFT_LCD_H__ */
|
|
835
bsp/bsp_common/image_sensor/bsp_image_sensor.c
Normal file
835
bsp/bsp_common/image_sensor/bsp_image_sensor.c
Normal file
|
@ -0,0 +1,835 @@
|
||||||
|
/**
|
||||||
|
* @file bsp_gc0308.c
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "bsp_image_sensor.h"
|
||||||
|
#include "bl702_glb.h"
|
||||||
|
#include "hal_gpio.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_i2c.h"
|
||||||
|
#include "hal_cam.h"
|
||||||
|
#include "hal_mjpeg.h"
|
||||||
|
#include "hal_clock.h"
|
||||||
|
|
||||||
|
#define IMAGE_SENSOR_BF2013 0
|
||||||
|
#define IMAGE_SENSOR_GC0308 1
|
||||||
|
#define IMAGE_SENSOR_USE IMAGE_SENSOR_GC0308
|
||||||
|
|
||||||
|
/* sensor out format */
|
||||||
|
#define RGB565 0
|
||||||
|
#define UYVY 1
|
||||||
|
#define FORMAT_SEL RGB565
|
||||||
|
|
||||||
|
#if (IMAGE_SENSOR_USE == IMAGE_SENSOR_BF2013)
|
||||||
|
#define I2C_CAMERA_ADDR 0x6E
|
||||||
|
#define BF2013_ID_MSB 0xFC
|
||||||
|
#define BF2013_ID_LSB 0xFD
|
||||||
|
#elif (IMAGE_SENSOR_USE == IMAGE_SENSOR_GC0308)
|
||||||
|
#define I2C_CAMERA_ADDR 0x21
|
||||||
|
#define GC0308_ID 0x00
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct device *image_sensor_i2c = NULL;
|
||||||
|
|
||||||
|
static const uint8_t sensorRegList[][2] =
|
||||||
|
{
|
||||||
|
#if (IMAGE_SENSOR_USE == IMAGE_SENSOR_BF2013)
|
||||||
|
{0x12, 0x80},
|
||||||
|
{0x67, 0x00},
|
||||||
|
{0x68, 0x00},
|
||||||
|
//{0xb9, 0x80},//use Test pattern
|
||||||
|
//{0x69,0x20},
|
||||||
|
{0x3a, 0x02},
|
||||||
|
{0x09, 0x01},
|
||||||
|
{0x15, 0x02},
|
||||||
|
{0x12, 0x00},
|
||||||
|
{0x1e, 0x00},
|
||||||
|
{0x13, 0x00},
|
||||||
|
{0x01, 0x14},
|
||||||
|
{0x02, 0x21},
|
||||||
|
{0x8c, 0x02},
|
||||||
|
{0x8d, 0x64},
|
||||||
|
{0x87, 0x18},
|
||||||
|
{0x13, 0x07},
|
||||||
|
//{0x11,0x80},//pclk=mclk
|
||||||
|
{0x11, 0x30}, //pclk=mclk/8
|
||||||
|
{0x2b, 0x20},
|
||||||
|
{0x92, 0x40},
|
||||||
|
{0x9d, 0x99},
|
||||||
|
{0x06, 0xe0},
|
||||||
|
{0x29, 0x54},
|
||||||
|
{0xeb, 0x30},
|
||||||
|
{0xbb, 0x20},
|
||||||
|
{0xf5, 0x21},
|
||||||
|
{0xe1, 0x3c},
|
||||||
|
{0x16, 0x01},
|
||||||
|
{0xe0, 0x0b},
|
||||||
|
{0x2f, 0xf6},
|
||||||
|
{0x33, 0x20},
|
||||||
|
{0x34, 0x08},
|
||||||
|
{0x35, 0x50},
|
||||||
|
{0x65, 0x4a},
|
||||||
|
{0x66, 0x50},
|
||||||
|
{0x36, 0x05},
|
||||||
|
{0x37, 0xf6},
|
||||||
|
{0x38, 0x46},
|
||||||
|
{0x9b, 0xf6},
|
||||||
|
{0x9c, 0x46},
|
||||||
|
{0xbc, 0x01},
|
||||||
|
{0xbd, 0xf6},
|
||||||
|
{0xbe, 0x46},
|
||||||
|
{0x82, 0x14},
|
||||||
|
{0x83, 0x23},
|
||||||
|
{0x9a, 0x23},
|
||||||
|
{0x70, 0x6f},
|
||||||
|
{0x72, 0x3f},
|
||||||
|
{0x73, 0x3f},
|
||||||
|
{0x74, 0x27},
|
||||||
|
{0x77, 0x90},
|
||||||
|
{0x79, 0x48},
|
||||||
|
{0x7a, 0x1e},
|
||||||
|
{0x7b, 0x30},
|
||||||
|
{0x84, 0x1a},
|
||||||
|
{0x85, 0x20},
|
||||||
|
{0x89, 0x02},
|
||||||
|
{0x8a, 0x64},
|
||||||
|
{0x86, 0x30},
|
||||||
|
{0x96, 0xa6},
|
||||||
|
{0x97, 0x0c},
|
||||||
|
{0x98, 0x18},
|
||||||
|
{0x80, 0x55},
|
||||||
|
{0x24, 0x70},
|
||||||
|
{0x25, 0x80},
|
||||||
|
{0x94, 0x0a},
|
||||||
|
{0x1f, 0x20},
|
||||||
|
{0x22, 0x20},
|
||||||
|
{0x26, 0x20},
|
||||||
|
{0x56, 0x40},
|
||||||
|
{0x61, 0xd3},
|
||||||
|
{0x79, 0x48},
|
||||||
|
{0x3b, 0x60},
|
||||||
|
{0x3c, 0x20},
|
||||||
|
{0x39, 0x80},
|
||||||
|
{0x3f, 0xb0},
|
||||||
|
{0x39, 0x80},
|
||||||
|
{0x40, 0x58},
|
||||||
|
{0x41, 0x54},
|
||||||
|
{0x42, 0x4e},
|
||||||
|
{0x43, 0x44},
|
||||||
|
{0x44, 0x3e},
|
||||||
|
{0x45, 0x39},
|
||||||
|
{0x46, 0x35},
|
||||||
|
{0x47, 0x31},
|
||||||
|
{0x48, 0x2e},
|
||||||
|
{0x49, 0x2b},
|
||||||
|
{0x4b, 0x29},
|
||||||
|
{0x4c, 0x27},
|
||||||
|
{0x4e, 0x23},
|
||||||
|
{0x4f, 0x20},
|
||||||
|
{0x50, 0x1e},
|
||||||
|
{0x51, 0x05},
|
||||||
|
{0x52, 0x10},
|
||||||
|
{0x53, 0x0b},
|
||||||
|
{0x54, 0x15},
|
||||||
|
{0x57, 0x87},
|
||||||
|
{0x58, 0x72},
|
||||||
|
{0x59, 0x5f},
|
||||||
|
{0x5a, 0x7e},
|
||||||
|
{0x5b, 0x1f},
|
||||||
|
{0x5c, 0x0e},
|
||||||
|
{0x5d, 0x95},
|
||||||
|
{0x60, 0x28},
|
||||||
|
{0xb0, 0xe0},
|
||||||
|
{0xb1, 0xc0},
|
||||||
|
{0xb2, 0xb0},
|
||||||
|
{0xb3, 0x88},
|
||||||
|
{0x6a, 0x01},
|
||||||
|
{0x23, 0x66},
|
||||||
|
{0xa0, 0x03},
|
||||||
|
{0xa1, 0x31},
|
||||||
|
{0xa2, 0x0b},
|
||||||
|
{0xa3, 0x26},
|
||||||
|
{0xa4, 0x05},
|
||||||
|
{0xa5, 0x25},
|
||||||
|
{0xa6, 0x06},
|
||||||
|
{0xa7, 0x80},
|
||||||
|
{0xa8, 0x80},
|
||||||
|
{0xa9, 0x20},
|
||||||
|
{0xaa, 0x20},
|
||||||
|
{0xab, 0x20},
|
||||||
|
{0xac, 0x3c},
|
||||||
|
{0xad, 0xf0},
|
||||||
|
{0xc8, 0x18},
|
||||||
|
{0xc9, 0x20},
|
||||||
|
{0xca, 0x17},
|
||||||
|
{0xcb, 0x1f},
|
||||||
|
{0xaf, 0x00},
|
||||||
|
{0xc5, 0x18},
|
||||||
|
{0xc6, 0x00},
|
||||||
|
{0xc7, 0x20},
|
||||||
|
{0xae, 0x80},
|
||||||
|
{0xcc, 0x40},
|
||||||
|
{0xcd, 0x58},
|
||||||
|
{0xee, 0x4c},
|
||||||
|
{0x8e, 0x07},
|
||||||
|
{0x8f, 0x79},
|
||||||
|
|
||||||
|
#elif (IMAGE_SENSOR_USE == IMAGE_SENSOR_GC0308)
|
||||||
|
{0xfe, 0x80},
|
||||||
|
{0xfe, 0x00}, //set page0
|
||||||
|
{0xd2, 0x00}, //close/en AEC; d2[7] set 1b'0 en AEC
|
||||||
|
{0x22, 0x55}, //close AWB
|
||||||
|
{0x5a, 0x56},
|
||||||
|
{0x5b, 0x40},
|
||||||
|
{0x5c, 0x4a},
|
||||||
|
{0x22, 0x57}, //Open AWB
|
||||||
|
#if 0
|
||||||
|
//config for 39 FPS
|
||||||
|
{0x01 , 0x6a},//HB 106
|
||||||
|
//{0x02 , 0x70},//VB 112
|
||||||
|
{0x02 , 0x0c},//change VB from 112 to 12
|
||||||
|
{0x0f , 0x00},
|
||||||
|
{0xe2 , 0x00},//anti-flicker step [11:8]
|
||||||
|
{0xe3 , 0x96},//anti-flicker step [7:0]
|
||||||
|
{0xe4 , 0x01},//exp level 1 50.00fps or 20ms
|
||||||
|
{0xe5 , 0x2c},
|
||||||
|
{0xe6 , 0x03},//exp level 2 16.67fps
|
||||||
|
{0xe7 , 0x84},
|
||||||
|
{0xe8 , 0x04},//exp level 3 12.5fps
|
||||||
|
{0xe9 , 0xb0},
|
||||||
|
{0xea , 0x09},//exp level 4 6.00fps
|
||||||
|
{0xeb , 0xc4},
|
||||||
|
#elif 0
|
||||||
|
//config for 33.33 FPS
|
||||||
|
{0x01, 0x6a}, //HB 106
|
||||||
|
{0x02, 0x52}, //VB 82
|
||||||
|
{0x0f, 0x00},
|
||||||
|
{0xe2, 0x00}, //anti-flicker step [11:8]
|
||||||
|
{0xe3, 0x96}, //anti-flicker step [7:0]
|
||||||
|
{0xe4, 0x01}, //exp level 1 33.33fps or 30ms
|
||||||
|
{0xe5, 0x2c},
|
||||||
|
{0xe6, 0x03}, //exp level 2 16.67fps
|
||||||
|
{0xe7, 0x84},
|
||||||
|
{0xe8, 0x04}, //exp level 3 12.5fps
|
||||||
|
{0xe9, 0xb0},
|
||||||
|
{0xea, 0x09}, //exp level 4 6.00fps
|
||||||
|
{0xeb, 0xc4},
|
||||||
|
#else
|
||||||
|
//config for 25 FPS
|
||||||
|
{0x01, 0x6a}, //HB 106
|
||||||
|
//{0x02 , 0x70},//VB 112
|
||||||
|
{0x02, 0xe8}, //change VB from 112 to 232
|
||||||
|
{0x0f, 0x00},
|
||||||
|
{0xe2, 0x00}, //anti-flicker step [11:8]
|
||||||
|
{0xe3, 0x96}, //anti-flicker step [7:0]
|
||||||
|
{0xe4, 0x02}, //exp level 1 25.00fps or 40ms
|
||||||
|
{0xe5, 0x58},
|
||||||
|
{0xe6, 0x03}, //exp level 2 16.67fps
|
||||||
|
{0xe7, 0x84},
|
||||||
|
{0xe8, 0x04}, //exp level 3 12.5fps
|
||||||
|
{0xe9, 0xb0},
|
||||||
|
{0xea, 0x09}, //exp level 4 6.00fps
|
||||||
|
{0xeb, 0xc4},
|
||||||
|
#endif
|
||||||
|
{0xec, 0x20}, //select max exposure level 1 - highest fps
|
||||||
|
{0xed, 0x04}, //set AEC select exp min
|
||||||
|
{0x05, 0x00},
|
||||||
|
{0x06, 0x00},
|
||||||
|
{0x07, 0x00},
|
||||||
|
{0x08, 0x00},
|
||||||
|
{0x09, 0x01},
|
||||||
|
{0x0a, 0xe8},
|
||||||
|
//{0x0a , 0x70},//change win_height from 488 to 368
|
||||||
|
{0x0b, 0x02},
|
||||||
|
{0x0c, 0x88}, //win_width 648
|
||||||
|
{0x0d, 0x02},
|
||||||
|
{0x0e, 0x02},
|
||||||
|
{0x10, 0x22},
|
||||||
|
{0x11, 0xfd},
|
||||||
|
{0x12, 0x2a},
|
||||||
|
{0x13, 0x00},
|
||||||
|
//{0x14 , 0x10},
|
||||||
|
{0x14, 0x13}, //enable mirror & flip
|
||||||
|
//-------------H_V_Switch(4)---------------//
|
||||||
|
/*
|
||||||
|
1://normal
|
||||||
|
{0x14 , 0x10},
|
||||||
|
2://IMAGE_H_MIRROR
|
||||||
|
{0x14 , 0x11},
|
||||||
|
3://IMAGE_V_MIRROR
|
||||||
|
{0x14 , 0x12},
|
||||||
|
4://IMAGE_HV_MIRROR
|
||||||
|
{0x14 , 0x13},*/
|
||||||
|
{0x15, 0x0a},
|
||||||
|
{0x16, 0x05},
|
||||||
|
{0x17, 0x01},
|
||||||
|
{0x18, 0x44},
|
||||||
|
{0x19, 0x44},
|
||||||
|
{0x1a, 0x1e},
|
||||||
|
{0x1b, 0x00},
|
||||||
|
{0x1c, 0xc1},
|
||||||
|
{0x1d, 0x08},
|
||||||
|
{0x1e, 0x60},
|
||||||
|
{0x1f, 0x17},
|
||||||
|
{0x20, 0xff},
|
||||||
|
{0x21, 0xf8},
|
||||||
|
{0x22, 0x57},
|
||||||
|
#if FORMAT_SEL == RGB565
|
||||||
|
{0x24, 0xa6}, //a6 RGB565
|
||||||
|
#elif FORMAT_SEL == UYVY
|
||||||
|
{0x24, 0xa0}, //a0 Cb Y Cr Y
|
||||||
|
#endif
|
||||||
|
{0x25, 0x0f},
|
||||||
|
//output sync_mode
|
||||||
|
//{0x26 , 0x02},//0x03 20101016 zhj
|
||||||
|
{0x26, 0x03}, //sync mode, high high
|
||||||
|
{0x2f, 0x01},
|
||||||
|
{0x30, 0xf7},
|
||||||
|
{0x31, 0x50},
|
||||||
|
{0x32, 0x00},
|
||||||
|
{0x39, 0x04},
|
||||||
|
{0x3a, 0x18},
|
||||||
|
{0x3b, 0x20},
|
||||||
|
{0x3c, 0x00},
|
||||||
|
{0x3d, 0x00},
|
||||||
|
{0x3e, 0x00},
|
||||||
|
{0x3f, 0x00},
|
||||||
|
{0x50, 0x10},
|
||||||
|
{0x53, 0x82},
|
||||||
|
{0x54, 0x80},
|
||||||
|
{0x55, 0x80},
|
||||||
|
{0x56, 0x82},
|
||||||
|
{0x8b, 0x40},
|
||||||
|
{0x8c, 0x40},
|
||||||
|
{0x8d, 0x40},
|
||||||
|
{0x8e, 0x2e},
|
||||||
|
{0x8f, 0x2e},
|
||||||
|
{0x90, 0x2e},
|
||||||
|
{0x91, 0x3c},
|
||||||
|
{0x92, 0x50},
|
||||||
|
{0x5d, 0x12},
|
||||||
|
{0x5e, 0x1a},
|
||||||
|
{0x5f, 0x24},
|
||||||
|
{0x60, 0x07},
|
||||||
|
{0x61, 0x15},
|
||||||
|
{0x62, 0x08},
|
||||||
|
{0x64, 0x03},
|
||||||
|
{0x66, 0xe8},
|
||||||
|
{0x67, 0x86},
|
||||||
|
{0x68, 0xa2},
|
||||||
|
{0x69, 0x18},
|
||||||
|
{0x6a, 0x0f},
|
||||||
|
{0x6b, 0x00},
|
||||||
|
{0x6c, 0x5f},
|
||||||
|
{0x6d, 0x8f},
|
||||||
|
{0x6e, 0x55},
|
||||||
|
{0x6f, 0x38},
|
||||||
|
{0x70, 0x15},
|
||||||
|
{0x71, 0x33},
|
||||||
|
{0x72, 0xdc},
|
||||||
|
{0x73, 0x80},
|
||||||
|
{0x74, 0x02},
|
||||||
|
{0x75, 0x3f},
|
||||||
|
{0x76, 0x02},
|
||||||
|
{0x77, 0x36},
|
||||||
|
{0x78, 0x88},
|
||||||
|
{0x79, 0x81},
|
||||||
|
{0x7a, 0x81},
|
||||||
|
{0x7b, 0x22},
|
||||||
|
{0x7c, 0xff},
|
||||||
|
{0x93, 0x48},
|
||||||
|
{0x94, 0x00},
|
||||||
|
{0x95, 0x05},
|
||||||
|
{0x96, 0xe8},
|
||||||
|
{0x97, 0x40},
|
||||||
|
{0x98, 0xf0},
|
||||||
|
{0xb1, 0x38},
|
||||||
|
{0xb2, 0x38},
|
||||||
|
{0xbd, 0x38},
|
||||||
|
{0xbe, 0x36},
|
||||||
|
#if 1
|
||||||
|
{0xd0, 0xc9},
|
||||||
|
{0xd1, 0x10},
|
||||||
|
{0xd3, 0x80},
|
||||||
|
{0xd5, 0xf2},
|
||||||
|
{0xd6, 0x16},
|
||||||
|
#else
|
||||||
|
//default AEC setting
|
||||||
|
{0xd0, 0xca},
|
||||||
|
{0xd1, 0xa1},
|
||||||
|
{0xd3, 0xa0},
|
||||||
|
{0xd5, 0xf2},
|
||||||
|
{0xd6, 0x18},
|
||||||
|
#endif
|
||||||
|
{0xdb, 0x92},
|
||||||
|
{0xdc, 0xa5},
|
||||||
|
{0xdf, 0x23},
|
||||||
|
{0xd9, 0x00},
|
||||||
|
{0xda, 0x00},
|
||||||
|
{0xe0, 0x09},
|
||||||
|
{0xed, 0x04},
|
||||||
|
#if 0
|
||||||
|
//default max dgain
|
||||||
|
{0xee , 0xa0},
|
||||||
|
{0xef , 0x40},
|
||||||
|
#else
|
||||||
|
//increased max dgain
|
||||||
|
{0xee, 0xf0},
|
||||||
|
{0xef, 0x60},
|
||||||
|
#endif
|
||||||
|
{0x80, 0x03},
|
||||||
|
{0x80, 0x03},
|
||||||
|
{0x9F, 0x10},
|
||||||
|
{0xA0, 0x20},
|
||||||
|
{0xA1, 0x38},
|
||||||
|
{0xA2, 0x4E},
|
||||||
|
{0xA3, 0x63},
|
||||||
|
{0xA4, 0x76},
|
||||||
|
{0xA5, 0x87},
|
||||||
|
{0xA6, 0xA2},
|
||||||
|
{0xA7, 0xB8},
|
||||||
|
{0xA8, 0xCA},
|
||||||
|
{0xA9, 0xD8},
|
||||||
|
{0xAA, 0xE3},
|
||||||
|
{0xAB, 0xEB},
|
||||||
|
{0xAC, 0xF0},
|
||||||
|
{0xAD, 0xF8},
|
||||||
|
{0xAE, 0xFD},
|
||||||
|
{0xAF, 0xFF},
|
||||||
|
/*
|
||||||
|
GC0308_GAMMA_Select,
|
||||||
|
1://smallest gamma curve
|
||||||
|
{0x9F , 0x0B},
|
||||||
|
{0xA0 , 0x16},
|
||||||
|
{0xA1 , 0x29},
|
||||||
|
{0xA2 , 0x3C},
|
||||||
|
{0xA3 , 0x4F},
|
||||||
|
{0xA4 , 0x5F},
|
||||||
|
{0xA5 , 0x6F},
|
||||||
|
{0xA6 , 0x8A},
|
||||||
|
{0xA7 , 0x9F},
|
||||||
|
{0xA8 , 0xB4},
|
||||||
|
{0xA9 , 0xC6},
|
||||||
|
{0xAA , 0xD3},
|
||||||
|
{0xAB , 0xDD},
|
||||||
|
{0xAC , 0xE5},
|
||||||
|
{0xAD , 0xF1},
|
||||||
|
{0xAE , 0xFA},
|
||||||
|
{0xAF , 0xFF},
|
||||||
|
2:
|
||||||
|
{0x9F , 0x0E},
|
||||||
|
{0xA0 , 0x1C},
|
||||||
|
{0xA1 , 0x34},
|
||||||
|
{0xA2 , 0x48},
|
||||||
|
{0xA3 , 0x5A},
|
||||||
|
{0xA4 , 0x6B},
|
||||||
|
{0xA5 , 0x7B},
|
||||||
|
{0xA6 , 0x95},
|
||||||
|
{0xA7 , 0xAB},
|
||||||
|
{0xA8 , 0xBF},
|
||||||
|
{0xA9 , 0xCE},
|
||||||
|
{0xAA , 0xD9},
|
||||||
|
{0xAB , 0xE4},
|
||||||
|
{0xAC , 0xEC},
|
||||||
|
{0xAD , 0xF7},
|
||||||
|
{0xAE , 0xFD},
|
||||||
|
{0xAF , 0xFF},
|
||||||
|
3:
|
||||||
|
{0x9F , 0x10},
|
||||||
|
{0xA0 , 0x20},
|
||||||
|
{0xA1 , 0x38},
|
||||||
|
{0xA2 , 0x4E},
|
||||||
|
{0xA3 , 0x63},
|
||||||
|
{0xA4 , 0x76},
|
||||||
|
{0xA5 , 0x87},
|
||||||
|
{0xA6 , 0xA2},
|
||||||
|
{0xA7 , 0xB8},
|
||||||
|
{0xA8 , 0xCA},
|
||||||
|
{0xA9 , 0xD8},
|
||||||
|
{0xAA , 0xE3},
|
||||||
|
{0xAB , 0xEB},
|
||||||
|
{0xAC , 0xF0},
|
||||||
|
{0xAD , 0xF8},
|
||||||
|
{0xAE , 0xFD},
|
||||||
|
{0xAF , 0xFF},
|
||||||
|
4:
|
||||||
|
{0x9F , 0x14},
|
||||||
|
{0xA0 , 0x28},
|
||||||
|
{0xA1 , 0x44},
|
||||||
|
{0xA2 , 0x5D},
|
||||||
|
{0xA3 , 0x72},
|
||||||
|
{0xA4 , 0x86},
|
||||||
|
{0xA5 , 0x95},
|
||||||
|
{0xA6 , 0xB1},
|
||||||
|
{0xA7 , 0xC6},
|
||||||
|
{0xA8 , 0xD5},
|
||||||
|
{0xA9 , 0xE1},
|
||||||
|
{0xAA , 0xEA},
|
||||||
|
{0xAB , 0xF1},
|
||||||
|
{0xAC , 0xF5},
|
||||||
|
{0xAD , 0xFB},
|
||||||
|
{0xAE , 0xFE},
|
||||||
|
{0xAF , 0xFF},
|
||||||
|
5://largest gamma curve
|
||||||
|
{0x9F , 0x15},
|
||||||
|
{0xA0 , 0x2A},
|
||||||
|
{0xA1 , 0x4A},
|
||||||
|
{0xA2 , 0x67},
|
||||||
|
{0xA3 , 0x79},
|
||||||
|
{0xA4 , 0x8C},
|
||||||
|
{0xA5 , 0x9A},
|
||||||
|
{0xA6 , 0xB3},
|
||||||
|
{0xA7 , 0xC5},
|
||||||
|
{0xA8 , 0xD5},
|
||||||
|
{0xA9 , 0xDF},
|
||||||
|
{0xAA , 0xE8},
|
||||||
|
{0xAB , 0xEE},
|
||||||
|
{0xAC , 0xF3},
|
||||||
|
{0xAD , 0xFA},
|
||||||
|
{0xAE , 0xFD},
|
||||||
|
{0xAF , 0xFF},
|
||||||
|
*/
|
||||||
|
//-----------GAMMA Select End--------------//
|
||||||
|
{0xc0, 0x00},
|
||||||
|
{0xc1, 0x10},
|
||||||
|
{0xc2, 0x1C},
|
||||||
|
{0xc3, 0x30},
|
||||||
|
{0xc4, 0x43},
|
||||||
|
{0xc5, 0x54},
|
||||||
|
{0xc6, 0x65},
|
||||||
|
{0xc7, 0x75},
|
||||||
|
{0xc8, 0x93},
|
||||||
|
{0xc9, 0xB0},
|
||||||
|
{0xca, 0xCB},
|
||||||
|
{0xcb, 0xE6},
|
||||||
|
{0xcc, 0xFF},
|
||||||
|
{0xf0, 0x02},
|
||||||
|
{0xf1, 0x01},
|
||||||
|
{0xf2, 0x01},
|
||||||
|
{0xf3, 0x30},
|
||||||
|
{0xf9, 0x9f},
|
||||||
|
{0xfa, 0x78},
|
||||||
|
//{0xfa , 0x58},//Change measure window Y1 from 480 to 352
|
||||||
|
//-------------------------------------------------
|
||||||
|
{0xfe, 0x01}, // set page1
|
||||||
|
{0x00, 0xf5},
|
||||||
|
{0x02, 0x1a},
|
||||||
|
{0x0a, 0xa0},
|
||||||
|
{0x0b, 0x60},
|
||||||
|
{0x0c, 0x08},
|
||||||
|
{0x0e, 0x4c},
|
||||||
|
{0x0f, 0x39},
|
||||||
|
{0x11, 0x3f},
|
||||||
|
{0x12, 0x72},
|
||||||
|
{0x13, 0x13},
|
||||||
|
{0x14, 0x42},
|
||||||
|
{0x15, 0x43},
|
||||||
|
{0x16, 0xc2},
|
||||||
|
{0x17, 0xa8},
|
||||||
|
{0x18, 0x18},
|
||||||
|
{0x19, 0x40},
|
||||||
|
{0x1a, 0xd0},
|
||||||
|
{0x1b, 0xf5},
|
||||||
|
{0x70, 0x40},
|
||||||
|
{0x71, 0x58},
|
||||||
|
{0x72, 0x30},
|
||||||
|
{0x73, 0x48},
|
||||||
|
{0x74, 0x20},
|
||||||
|
{0x75, 0x60},
|
||||||
|
{0x77, 0x20},
|
||||||
|
{0x78, 0x32},
|
||||||
|
{0x30, 0x03},
|
||||||
|
{0x31, 0x40},
|
||||||
|
{0x32, 0xe0},
|
||||||
|
{0x33, 0xe0},
|
||||||
|
{0x34, 0xe0},
|
||||||
|
{0x35, 0xb0},
|
||||||
|
{0x36, 0xc0},
|
||||||
|
{0x37, 0xc0},
|
||||||
|
{0x38, 0x04},
|
||||||
|
{0x39, 0x09},
|
||||||
|
{0x3a, 0x12},
|
||||||
|
{0x3b, 0x1C},
|
||||||
|
{0x3c, 0x28},
|
||||||
|
{0x3d, 0x31},
|
||||||
|
{0x3e, 0x44},
|
||||||
|
{0x3f, 0x57},
|
||||||
|
{0x40, 0x6C},
|
||||||
|
{0x41, 0x81},
|
||||||
|
{0x42, 0x94},
|
||||||
|
{0x43, 0xA7},
|
||||||
|
{0x44, 0xB8},
|
||||||
|
{0x45, 0xD6},
|
||||||
|
{0x46, 0xEE},
|
||||||
|
{0x47, 0x0d},
|
||||||
|
{0xfe, 0x00}, //set page0
|
||||||
|
//-----------Update the registers 2010/07/06-------------//
|
||||||
|
//Registers of Page0
|
||||||
|
{0xfe, 0x00}, //set page0
|
||||||
|
{0x10, 0x26},
|
||||||
|
{0x11, 0x0d}, //fd,modified by mormo 2010/07/06
|
||||||
|
{0x1a, 0x2a}, //1e,modified by mormo 2010/07/06
|
||||||
|
{0x1c, 0x49}, //c1,modified by mormo 2010/07/06
|
||||||
|
{0x1d, 0x9a}, //08,modified by mormo 2010/07/06
|
||||||
|
{0x1e, 0x61}, //60,modified by mormo 2010/07/06
|
||||||
|
{0x3a, 0x20},
|
||||||
|
{0x50, 0x14}, //10,modified by mormo 2010/07/06
|
||||||
|
{0x53, 0x80},
|
||||||
|
{0x56, 0x80},
|
||||||
|
{0x8b, 0x20}, //LSC
|
||||||
|
{0x8c, 0x20},
|
||||||
|
{0x8d, 0x20},
|
||||||
|
{0x8e, 0x14},
|
||||||
|
{0x8f, 0x10},
|
||||||
|
{0x90, 0x14},
|
||||||
|
{0x94, 0x02},
|
||||||
|
{0x95, 0x07},
|
||||||
|
{0x96, 0xe0},
|
||||||
|
{0xb1, 0x40}, //YCPT
|
||||||
|
{0xb2, 0x40},
|
||||||
|
{0xb3, 0x40},
|
||||||
|
{0xb6, 0xe0},
|
||||||
|
//{0xd0 , 0xcb},//AECT c9,modifed by mormo 2010/07/06
|
||||||
|
//{0xd3 , 0x48},//80,modified by mormor 2010/07/06
|
||||||
|
{0xf2, 0x02},
|
||||||
|
//{0xf7 , 0x12},
|
||||||
|
//{0xf8 , 0x0a},
|
||||||
|
//Registers
|
||||||
|
{0xfe, 0x01}, // set page1
|
||||||
|
{0x02, 0x20},
|
||||||
|
{0x04, 0x10},
|
||||||
|
{0x05, 0x08},
|
||||||
|
{0x06, 0x20},
|
||||||
|
{0x08, 0x0a},
|
||||||
|
{0x0e, 0x44},
|
||||||
|
{0x0f, 0x32},
|
||||||
|
{0x10, 0x41},
|
||||||
|
{0x11, 0x37},
|
||||||
|
{0x12, 0x22},
|
||||||
|
{0x13, 0x19},
|
||||||
|
{0x14, 0x44},
|
||||||
|
{0x15, 0x44},
|
||||||
|
{0x19, 0x50},
|
||||||
|
{0x1a, 0xd8},
|
||||||
|
{0x32, 0x10},
|
||||||
|
{0x35, 0x00},
|
||||||
|
{0x36, 0x80},
|
||||||
|
{0x37, 0x00},
|
||||||
|
//-----------Update the registers end---------//
|
||||||
|
{0xfe, 0x00}, //set page0
|
||||||
|
{0xd2, 0x90},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint8_t image_sensor_read_id(void);
|
||||||
|
static uint8_t image_sensor_regs_config(void);
|
||||||
|
|
||||||
|
void cam_clk_out(void)
|
||||||
|
{
|
||||||
|
GLB_Set_I2S_CLK(ENABLE, GLB_I2S_OUT_REF_CLK_NONE);
|
||||||
|
PDS_Set_Audio_PLL_Freq(AUDIO_PLL_24576000_HZ);
|
||||||
|
GLB_Set_Chip_Out_1_CLK_Sel(GLB_CHIP_CLK_OUT_I2S_REF_CLK);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t image_sensor_init(BL_Fun_Type mjpeg_en, cam_device_t *cam_cfg, mjpeg_device_t *mjpeg_cfg)
|
||||||
|
{
|
||||||
|
i2c_register(I2C0_INDEX, "i2c", DEVICE_OFLAG_RDWR);
|
||||||
|
image_sensor_i2c = device_find("i2c");
|
||||||
|
if(image_sensor_i2c){
|
||||||
|
device_open(image_sensor_i2c, 0);
|
||||||
|
}
|
||||||
|
if(image_sensor_read_id())
|
||||||
|
{
|
||||||
|
MSG("err1\r\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(image_sensor_regs_config())
|
||||||
|
{
|
||||||
|
MSG("err2\r\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cam_stop();
|
||||||
|
mjpeg_stop();
|
||||||
|
|
||||||
|
if(mjpeg_en)
|
||||||
|
{
|
||||||
|
cam_init(cam_cfg);
|
||||||
|
mjpeg_init(mjpeg_cfg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cam_init(cam_cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************//**
|
||||||
|
* @brief image_sensor_write_byte
|
||||||
|
*
|
||||||
|
* @param addr: Register address
|
||||||
|
* @param data: data
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
uint8_t image_sensor_write_byte(uint8_t cmd, uint8_t data)
|
||||||
|
{
|
||||||
|
i2c_msg_t msg1;
|
||||||
|
|
||||||
|
msg1.slaveaddr = I2C_CAMERA_ADDR,
|
||||||
|
msg1.len = 1,
|
||||||
|
msg1.buf = &data;
|
||||||
|
msg1.flags = SUB_ADDR_1BYTE | I2C_WR;
|
||||||
|
msg1.subaddr = cmd;
|
||||||
|
|
||||||
|
return i2c_transfer(image_sensor_i2c, &msg1, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************//**
|
||||||
|
* @brief image_sensor_read_byte
|
||||||
|
*
|
||||||
|
* @param addr: Register address
|
||||||
|
* @param rdata: data
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
uint8_t image_sensor_read_byte(uint8_t cmd)
|
||||||
|
{
|
||||||
|
i2c_msg_t msg1;
|
||||||
|
uint8_t temp;
|
||||||
|
msg1.len = 1,
|
||||||
|
msg1.buf = &temp;
|
||||||
|
msg1.subaddr = cmd;
|
||||||
|
msg1.slaveaddr = I2C_CAMERA_ADDR,
|
||||||
|
msg1.flags = SUB_ADDR_1BYTE | I2C_RD;
|
||||||
|
i2c_transfer(image_sensor_i2c, &msg1, 1);
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************/ /**
|
||||||
|
* @brief CAMERA Read ID
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
*
|
||||||
|
* @return SUCCESS or ERROR
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
static uint8_t image_sensor_read_id(void)
|
||||||
|
{
|
||||||
|
uint8_t buf[2] = {0};
|
||||||
|
|
||||||
|
buf[0] = image_sensor_read_byte(GC0308_ID);
|
||||||
|
// MSG("image_sensor id:0x%2x\r\n",buf[0]);
|
||||||
|
if (buf[0] == 0x9b)
|
||||||
|
{
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t image_sensor_regs_config(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(sensorRegList) / sizeof(sensorRegList[0]); i++)
|
||||||
|
{
|
||||||
|
if (image_sensor_write_byte(sensorRegList[i][0],sensorRegList[i][1]) != SUCCESS)
|
||||||
|
{
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
bflb_platform_delay_ms(1);
|
||||||
|
}
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************/ /**
|
||||||
|
* @brief Dump image sensor register while is set
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
void image_sensor_dump_regs(void)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(sensorRegList) / sizeof(sensorRegList[0]); i++)
|
||||||
|
{
|
||||||
|
MSG("reg[%02x]: %02x\n", sensorRegList[i][0], image_sensor_read_byte(sensorRegList[i][0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* cam cdc case use gpio & timer*/
|
||||||
|
|
||||||
|
void tr_gpio_init(void)
|
||||||
|
{
|
||||||
|
gpio_set_mode(GPIO_PIN_22, GPIO_OUTPUT_PP_MODE);
|
||||||
|
gpio_write(GPIO_PIN_22, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct device* timer_ch0_comp2 = NULL;
|
||||||
|
|
||||||
|
void timer_ch0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||||
|
{
|
||||||
|
static uint32_t i = 0;
|
||||||
|
if( i & 1)
|
||||||
|
{
|
||||||
|
gpio_write(GPIO_PIN_22, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gpio_write(GPIO_PIN_22, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tr_timer_init(void)
|
||||||
|
{
|
||||||
|
timer_user_cfg_t timer_user_cfg;
|
||||||
|
timer_user_cfg.timeout_val = 1000*1000; /* us */
|
||||||
|
timer_user_cfg.comp_it = TIMER_COMP0_IT;
|
||||||
|
|
||||||
|
timer_register(TIMER_CH0_INDEX, "timer_ch0_comp2", DEVICE_OFLAG_RDWR);
|
||||||
|
|
||||||
|
timer_ch0_comp2 = device_find("timer_ch0_comp2");
|
||||||
|
if(timer_ch0_comp2)
|
||||||
|
{
|
||||||
|
device_open(timer_ch0_comp2, 0);
|
||||||
|
device_set_callback(timer_ch0_comp2, timer_ch0_irq_callback);
|
||||||
|
device_control(timer_ch0_comp2, DEVICE_CTRL_TIMER_CH_START, (void *)(&timer_user_cfg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void trigger_init(void)
|
||||||
|
{
|
||||||
|
tr_gpio_init();
|
||||||
|
tr_timer_init();
|
||||||
|
}
|
36
bsp/bsp_common/image_sensor/bsp_image_sensor.h
Normal file
36
bsp/bsp_common/image_sensor/bsp_image_sensor.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* @file bsp_gc0308.h
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef _IMAGE_SENSOR_H_
|
||||||
|
#define _IMAGE_SENSOR_H_
|
||||||
|
|
||||||
|
#include "bflb_platform.h"
|
||||||
|
#include "bl702_cam.h"
|
||||||
|
#include "bl702_mjpeg.h"
|
||||||
|
#include "hal_cam.h"
|
||||||
|
#include "hal_mjpeg.h"
|
||||||
|
|
||||||
|
uint8_t image_sensor_init(BL_Fun_Type mjpeg_en, cam_device_t *cam_cfg, mjpeg_device_t *mjpeg_cfg);
|
||||||
|
void cam_clk_out(void);
|
||||||
|
void trigger_init(void);
|
||||||
|
|
||||||
|
#endif
|
|
@ -111,6 +111,10 @@ void lv_port_disp_init(void)
|
||||||
/*Set the resolution of the display*/
|
/*Set the resolution of the display*/
|
||||||
Disp_Drv.hor_res = 240;
|
Disp_Drv.hor_res = 240;
|
||||||
Disp_Drv.ver_res = 320;
|
Disp_Drv.ver_res = 320;
|
||||||
|
/* hardware rotation */
|
||||||
|
Disp_Drv.sw_rotate = 0;
|
||||||
|
/* rotation */
|
||||||
|
Disp_Drv.rotated = LV_DISP_ROT_NONE;
|
||||||
|
|
||||||
/*Used to copy the buffer's content to the display*/
|
/*Used to copy the buffer's content to the display*/
|
||||||
Disp_Drv.flush_cb = disp_flush;
|
Disp_Drv.flush_cb = disp_flush;
|
||||||
|
@ -163,15 +167,21 @@ void disp_init(void)
|
||||||
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
|
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
|
||||||
{
|
{
|
||||||
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
||||||
|
static uint8_t rotated_dir = 0;
|
||||||
uint32_t length = (area->y2 - area->y1 +1) * (area->x2 - area->x1 +1) ;
|
uint32_t length = (area->y2 - area->y1 +1) * (area->x2 - area->x1 +1) ;
|
||||||
|
|
||||||
|
if(rotated_dir != disp_drv->rotated)
|
||||||
|
{
|
||||||
|
rotated_dir = disp_drv->rotated;
|
||||||
|
LCD_Set_Dir(rotated_dir);
|
||||||
|
}
|
||||||
|
|
||||||
LCD_Set_Addr(area->x1,area->y1,area->x2,area->y2);
|
LCD_Set_Addr(area->x1,area->y1,area->x2,area->y2);
|
||||||
|
|
||||||
device_control(lcd_spi,DEVICE_CTRL_TX_DMA_RESUME,NULL);
|
device_control(lcd_spi,DEVICE_CTRL_TX_DMA_RESUME,NULL);
|
||||||
|
device_control(lcd_dma_tx, DEVICE_CTRL_SET_INT, NULL);
|
||||||
CS1_LOW;
|
CS1_LOW;
|
||||||
DC_HIGH;
|
DC_HIGH;
|
||||||
device_control(lcd_dma_tx, DEVICE_CTRL_SET_INT, NULL);
|
|
||||||
dma_reload(lcd_dma_tx, (uint32_t)color_p, (uint32_t)DMA_ADDR_SPI_TDR, length*2);
|
dma_reload(lcd_dma_tx, (uint32_t)color_p, (uint32_t)DMA_ADDR_SPI_TDR, length*2);
|
||||||
dma_channel_start(lcd_dma_tx);
|
dma_channel_start(lcd_dma_tx);
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "lv_port_fs.h"
|
#include "lv_port_fs.h"
|
||||||
|
#include "ff.h"
|
||||||
typedef uint8_t lv_fs_res_t;
|
#include "stdio.h"
|
||||||
|
#include "bflb_platform.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
|
@ -24,19 +25,13 @@ typedef uint8_t lv_fs_res_t;
|
||||||
/* Create a type to store the required data about your file.
|
/* Create a type to store the required data about your file.
|
||||||
* If you are using a File System library
|
* If you are using a File System library
|
||||||
* it already should have a File type.
|
* it already should have a File type.
|
||||||
* For example FatFS has `FIL`. In this case use `typedef FIL file_t`*/
|
* For example FatFS has `file_t `. In this case use `typedef file_t file_t`*/
|
||||||
typedef struct {
|
typedef FIL file_t;
|
||||||
/*Add the data you need to store about a file*/
|
|
||||||
uint32_t dummy1;
|
|
||||||
uint32_t dummy2;
|
|
||||||
}file_t;
|
|
||||||
|
|
||||||
/*Similarly to `file_t` create a type for directory reading too */
|
/*Similarly to `file_t` create a type for directory reading too */
|
||||||
typedef struct {
|
typedef DIR dir_t;
|
||||||
/*Add the data you need to store about directory reading*/
|
|
||||||
uint32_t dummy1;
|
FATFS FS_OBJ_SD;
|
||||||
uint32_t dummy2;
|
|
||||||
}dir_t;
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
|
@ -58,9 +53,12 @@ static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * rddir_p, const char *p
|
||||||
static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * rddir_p, char *fn);
|
static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * rddir_p, char *fn);
|
||||||
static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * rddir_p);
|
static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * rddir_p);
|
||||||
|
|
||||||
|
extern void fatfs_sd_driver_register(void);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
|
typedef uint8_t lv_fs_res_t;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
|
@ -91,7 +89,7 @@ void lv_port_fs_init(void)
|
||||||
|
|
||||||
/*Set up fields...*/
|
/*Set up fields...*/
|
||||||
fs_drv.file_size = sizeof(file_t);
|
fs_drv.file_size = sizeof(file_t);
|
||||||
fs_drv.letter = 'P';
|
fs_drv.letter = 'S';
|
||||||
fs_drv.open_cb = fs_open;
|
fs_drv.open_cb = fs_open;
|
||||||
fs_drv.close_cb = fs_close;
|
fs_drv.close_cb = fs_close;
|
||||||
fs_drv.read_cb = fs_read;
|
fs_drv.read_cb = fs_read;
|
||||||
|
@ -115,6 +113,47 @@ void lv_port_fs_init(void)
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
lv_fs_res_t res_fatfs_to_lv(FRESULT res)
|
||||||
|
{
|
||||||
|
if(res==FR_OK)
|
||||||
|
{
|
||||||
|
return LV_FS_RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (res)
|
||||||
|
{
|
||||||
|
case (FR_DISK_ERR):
|
||||||
|
res = LV_FS_RES_HW_ERR;
|
||||||
|
break;
|
||||||
|
case (FR_NO_FILE):
|
||||||
|
res = LV_FS_RES_NOT_EX;
|
||||||
|
break;
|
||||||
|
case (FR_NO_PATH):
|
||||||
|
res = LV_FS_RES_NOT_EX;
|
||||||
|
break;
|
||||||
|
case (FR_NOT_ENOUGH_CORE):
|
||||||
|
res = LV_FS_RES_OUT_OF_MEM;
|
||||||
|
break;
|
||||||
|
case (FR_LOCKED):
|
||||||
|
res = LV_FS_RES_LOCKED;
|
||||||
|
case (FR_TOO_MANY_OPEN_FILES):
|
||||||
|
res = LV_FS_RES_LOCKED;
|
||||||
|
break;
|
||||||
|
case (FR_NO_FILESYSTEM):
|
||||||
|
res = LV_FS_RES_FS_ERR;
|
||||||
|
break;
|
||||||
|
case (FR_WRITE_PROTECTED):
|
||||||
|
res = LV_FS_RES_DENIED;
|
||||||
|
break;
|
||||||
|
case (FR_TIMEOUT):
|
||||||
|
res = LV_FS_RES_TOUT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = LV_FS_RES_UNKNOWN;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Initialize your Storage device and File system. */
|
/* Initialize your Storage device and File system. */
|
||||||
static void fs_init(void)
|
static void fs_init(void)
|
||||||
|
@ -122,6 +161,9 @@ static void fs_init(void)
|
||||||
/*E.g. for FatFS initialize the SD card and FatFS itself*/
|
/*E.g. for FatFS initialize the SD card and FatFS itself*/
|
||||||
|
|
||||||
/*You code here*/
|
/*You code here*/
|
||||||
|
fatfs_sd_driver_register();
|
||||||
|
f_mount(&FS_OBJ_SD,"sd:",1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,28 +176,43 @@ static void fs_init(void)
|
||||||
*/
|
*/
|
||||||
static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
|
static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
|
||||||
{
|
{
|
||||||
// lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
BYTE fatfs_mode;
|
||||||
|
char *path_buf = NULL;
|
||||||
|
|
||||||
// if(mode == LV_FS_MODE_WR)
|
switch (drv->letter)
|
||||||
// {
|
{
|
||||||
// /*Open a file for write*/
|
case 'S':
|
||||||
|
path_buf = (char *)lv_mem_alloc(sizeof(char) * (strlen(path) + 4));
|
||||||
|
sprintf(path_buf, "SD:/%s", path);
|
||||||
|
break;
|
||||||
|
|
||||||
// /* Add your code here*/
|
default:
|
||||||
// }
|
return LV_FS_RES_NOT_EX;
|
||||||
// else if(mode == LV_FS_MODE_RD)
|
break;
|
||||||
// {
|
}
|
||||||
// /*Open a file for read*/
|
|
||||||
|
|
||||||
// /* Add your code here*/
|
switch (mode)
|
||||||
// }
|
{
|
||||||
// else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
|
case (LV_FS_MODE_RD):
|
||||||
// {
|
fatfs_mode = FA_READ;
|
||||||
// /*Open a file for read and write*/
|
break;
|
||||||
|
case (LV_FS_MODE_WR):
|
||||||
|
fatfs_mode = FA_WRITE;
|
||||||
|
break;
|
||||||
|
case (LV_FS_MODE_WR|LV_FS_MODE_RD):
|
||||||
|
fatfs_mode = FA_WRITE|FA_READ;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fatfs_mode = LV_FS_MODE_RD;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// /* Add your code here*/
|
res = f_open((file_t *)file_p, path_buf, fatfs_mode);
|
||||||
// }
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
// return res;
|
lv_mem_free(path_buf);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,11 +224,13 @@ static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path,
|
||||||
*/
|
*/
|
||||||
static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p)
|
static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p)
|
||||||
{
|
{
|
||||||
// lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
// /* Add your code here*/
|
/* Add your code here*/
|
||||||
|
res = f_close((file_t *)file_p);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
// return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,9 +245,11 @@ static lv_fs_res_t fs_close (lv_fs_drv_t * drv, void * file_p)
|
||||||
*/
|
*/
|
||||||
static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
|
static lv_fs_res_t fs_read (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
|
||||||
{
|
{
|
||||||
// lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
// /* Add your code here*/
|
/* Add your code here*/
|
||||||
|
res = f_read((file_t *)file_p, buf, btr, br);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +268,8 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
res = f_write((file_t *)file_p, buf, btw, bw);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -224,6 +287,8 @@ static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos)
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
res = f_lseek((file_t *)file_p, pos);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -237,11 +302,11 @@ static lv_fs_res_t fs_seek (lv_fs_drv_t * drv, void * file_p, uint32_t pos)
|
||||||
*/
|
*/
|
||||||
static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
|
static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
|
||||||
{
|
{
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
//lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
*size_p = f_size((file_t *)file_p);
|
||||||
return res;
|
return LV_FS_RES_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Give the position of the read write pointer
|
* Give the position of the read write pointer
|
||||||
|
@ -253,11 +318,11 @@ static lv_fs_res_t fs_size (lv_fs_drv_t * drv, void * file_p, uint32_t * size_p)
|
||||||
*/
|
*/
|
||||||
static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
|
static lv_fs_res_t fs_tell (lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
|
||||||
{
|
{
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
//lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
*pos_p = f_tell((file_t *)file_p);
|
||||||
return res;
|
return LV_FS_RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -271,7 +336,23 @@ static lv_fs_res_t fs_remove (lv_fs_drv_t * drv, const char *path)
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
char *path_buf = NULL;
|
||||||
|
|
||||||
|
switch (drv->letter)
|
||||||
|
{
|
||||||
|
case 'S':
|
||||||
|
path_buf = (char *)lv_mem_alloc(sizeof(char) * (strlen(path) + 4));
|
||||||
|
sprintf(path_buf, "SD:/%s", path);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return LV_FS_RES_NOT_EX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = f_unlink(path_buf);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
|
lv_mem_free(path_buf);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,6 +368,8 @@ static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p)
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
res = f_truncate((file_t *)file_p);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -303,7 +386,27 @@ static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const cha
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
char *path_old_buf = NULL;
|
||||||
|
char *path_new_buf = NULL;
|
||||||
|
|
||||||
|
switch (drv->letter)
|
||||||
|
{
|
||||||
|
case 'S':
|
||||||
|
path_old_buf = (char *)lv_mem_alloc(sizeof(char) * (strlen(oldname) + 4));
|
||||||
|
path_new_buf = (char *)lv_mem_alloc(sizeof(char) * (strlen(newname) + 4));
|
||||||
|
sprintf(path_old_buf, "SD:/%s", oldname);
|
||||||
|
sprintf(path_new_buf, "SD:/%s", newname);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return LV_FS_RES_NOT_EX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = f_rename(path_old_buf, path_new_buf);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
|
lv_mem_free(path_old_buf);
|
||||||
|
lv_mem_free(path_new_buf);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,9 +421,26 @@ static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const cha
|
||||||
static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p)
|
static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * free_p)
|
||||||
{
|
{
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
char *path = NULL;
|
||||||
|
FATFS *fs_obj;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
switch (drv->letter)
|
||||||
|
{
|
||||||
|
case 'S':
|
||||||
|
path = "SD:";
|
||||||
|
fs_obj = &FS_OBJ_SD;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return LV_FS_RES_NOT_EX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = f_getfree(path , free_p, &fs_obj);
|
||||||
|
*free_p = (fs_obj->csize) * (*free_p) / 1024;
|
||||||
|
*total_p = (fs_obj->csize) * (fs_obj->n_fatent - 2) /1024;
|
||||||
|
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +456,23 @@ static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * rddir_p, const char *p
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
char *path_buf = NULL;
|
||||||
|
|
||||||
|
switch (drv->letter)
|
||||||
|
{
|
||||||
|
case 'S':
|
||||||
|
path_buf = (char *)lv_mem_alloc(sizeof(char) * (strlen(path) + 4));
|
||||||
|
sprintf(path_buf, "SD:/%s", path);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return LV_FS_RES_NOT_EX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = f_opendir(rddir_p, path_buf);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
|
lv_mem_free(path_buf);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,8 +487,16 @@ static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * rddir_p, const char *p
|
||||||
static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * rddir_p, char *fn)
|
static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * rddir_p, char *fn)
|
||||||
{
|
{
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
FILINFO entry;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
res = f_readdir(rddir_p, &entry);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
|
|
||||||
|
if(res == LV_FS_RES_OK)
|
||||||
|
{
|
||||||
|
sprintf(fn,"%s%s",(entry.fattrib & AM_DIR)? "/" : "", entry.fname);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -368,7 +512,8 @@ static lv_fs_res_t fs_dir_close (lv_fs_drv_t * drv, void * rddir_p)
|
||||||
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
|
||||||
|
|
||||||
/* Add your code here*/
|
/* Add your code here*/
|
||||||
|
f_closedir((dir_t*)rddir_p);
|
||||||
|
res = res_fatfs_to_lv(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
void lv_port_fs_init(void);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
@ -10,12 +10,8 @@
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "lv_port_indev.h"
|
#include "lv_port_indev.h"
|
||||||
#include "xpt2046.h"
|
|
||||||
#include "bflb_platform.h"
|
#include "bflb_platform.h"
|
||||||
|
|
||||||
#include "bl702_glb.h"
|
|
||||||
#include "bl702_spi.h"
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
@ -38,9 +34,9 @@ static lv_coord_t touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||||
// static bool mouse_is_pressed(void);
|
// static bool mouse_is_pressed(void);
|
||||||
// static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
|
// static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||||
|
|
||||||
// static void keypad_init(void);
|
static void keypad_init(void);
|
||||||
// static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||||
// static uint32_t keypad_get_key(void);
|
static uint32_t keypad_get_key(void);
|
||||||
|
|
||||||
// static void encoder_init(void);
|
// static void encoder_init(void);
|
||||||
// static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
// static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||||
|
@ -55,10 +51,10 @@ static lv_coord_t touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
lv_indev_t * indev_touchpad;
|
lv_indev_t * indev_touchpad;
|
||||||
lv_indev_t * indev_mouse;
|
//lv_indev_t * indev_mouse;
|
||||||
lv_indev_t * indev_keypad;
|
lv_indev_t * indev_keypad;
|
||||||
lv_indev_t * indev_encoder;
|
//lv_indev_t * indev_encoder;
|
||||||
lv_indev_t * indev_button;
|
//lv_indev_t * indev_button;
|
||||||
|
|
||||||
// static int32_t encoder_diff;
|
// static int32_t encoder_diff;
|
||||||
// static lv_indev_state_t encoder_state;
|
// static lv_indev_state_t encoder_state;
|
||||||
|
@ -122,13 +118,13 @@ void lv_port_indev_init(void)
|
||||||
* -----------------*/
|
* -----------------*/
|
||||||
|
|
||||||
/*Initialize your keypad or keyboard if you have*/
|
/*Initialize your keypad or keyboard if you have*/
|
||||||
// keypad_init();
|
keypad_init();
|
||||||
|
|
||||||
/*Register a keypad input device*/
|
/*Register a keypad input device*/
|
||||||
// lv_indev_drv_init(&indev_drv);
|
lv_indev_drv_init(&indev_drv);
|
||||||
// indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
||||||
// indev_drv.read_cb = keypad_read;
|
indev_drv.read_cb = keypad_read;
|
||||||
// indev_keypad = lv_indev_drv_register(&indev_drv);
|
indev_keypad = lv_indev_drv_register(&indev_drv);
|
||||||
|
|
||||||
/* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
/* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
||||||
* add objects to the group with `lv_group_add_obj(group, obj)`
|
* add objects to the group with `lv_group_add_obj(group, obj)`
|
||||||
|
@ -181,6 +177,8 @@ void lv_port_indev_init(void)
|
||||||
/*------------------
|
/*------------------
|
||||||
* Touchpad
|
* Touchpad
|
||||||
* -----------------*/
|
* -----------------*/
|
||||||
|
#include "touch.h"
|
||||||
|
#include "hal_spi.h"
|
||||||
|
|
||||||
/*Initialize your touchpad*/
|
/*Initialize your touchpad*/
|
||||||
static void touchpad_init(void)
|
static void touchpad_init(void)
|
||||||
|
@ -225,27 +223,14 @@ static lv_coord_t touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
|
||||||
{
|
{
|
||||||
/*Your code comes here*/
|
/*Your code comes here*/
|
||||||
lv_disp_t *p_disp_drv_cb;
|
lv_disp_t *p_disp_drv_cb;
|
||||||
lv_disp_rot_t rotate;
|
|
||||||
uint8_t res;
|
uint8_t res;
|
||||||
SPI_ClockCfg_Type clockCfg =
|
|
||||||
{
|
|
||||||
2, /* Length of start condition */
|
|
||||||
2, /* Length of stop condition */
|
|
||||||
2, /* Length of data phase 0,affecting clock */
|
|
||||||
2, /* Length of data phase 1,affecting clock */
|
|
||||||
2 /* Length of interval between frame */
|
|
||||||
};
|
|
||||||
|
|
||||||
p_disp_drv_cb = lv_disp_get_default();
|
p_disp_drv_cb = lv_disp_get_default();
|
||||||
rotate = lv_disp_get_rotation(p_disp_drv_cb);
|
|
||||||
while(p_disp_drv_cb->driver.buffer->flushing);
|
while(p_disp_drv_cb->driver.buffer->flushing);
|
||||||
clockCfg.dataPhase0Len = 5;
|
device_control(touch_spi, DEVICE_CTRL_SPI_CONFIG_CLOCK, (void*)3600000);
|
||||||
clockCfg.dataPhase1Len = 5;
|
res = touch_read(x,y);
|
||||||
SPI_ClockConfig(SPI_ID_0, &clockCfg);
|
device_control(touch_spi, DEVICE_CTRL_SPI_CONFIG_CLOCK, (void*)36000000);
|
||||||
res = xpt2046_read((uint16_t*)x,(uint16_t*)y,rotate);
|
|
||||||
clockCfg.dataPhase0Len = 1;
|
|
||||||
clockCfg.dataPhase1Len = 1;
|
|
||||||
SPI_ClockConfig(SPI_ID_0, &clockCfg);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,63 +281,130 @@ static lv_coord_t touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
|
||||||
/*------------------
|
/*------------------
|
||||||
* Keypad
|
* Keypad
|
||||||
* -----------------*/
|
* -----------------*/
|
||||||
|
#include "hal_adc.h"
|
||||||
|
#include "hal_gpio.h"
|
||||||
|
uint8_t PinList[] = {GPIO_PIN_18};
|
||||||
|
adc_channel_t posChList[] = {ADC_CHANNEL8};
|
||||||
|
adc_channel_t negChList[] = {ADC_CHANNEL_GND};
|
||||||
|
|
||||||
|
adc_channel_val_t result_val;
|
||||||
|
struct device* adc_key;
|
||||||
|
|
||||||
|
uint16_t key_value[] = {283,89,198,0,406};
|
||||||
|
|
||||||
/* Initialize your keypad */
|
/* Initialize your keypad */
|
||||||
// static void keypad_init(void)
|
static void keypad_init(void)
|
||||||
// {
|
{
|
||||||
// /*Your code comes here*/
|
/*Your code comes here*/
|
||||||
// }
|
adc_channel_cfg_t adc_channel_cfg;
|
||||||
|
|
||||||
/* Will be called by the library to read the mouse */
|
adc_channel_cfg.pos_channel = posChList;
|
||||||
// static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
adc_channel_cfg.neg_channel = negChList;
|
||||||
// {
|
adc_channel_cfg.num = 1;
|
||||||
// static uint32_t last_key = 0;
|
|
||||||
|
|
||||||
// /*Get the current x and y coordinates*/
|
adc_register(ADC0_INDEX, "adc_key", DEVICE_OFLAG_STREAM_RX);
|
||||||
// mouse_get_xy(&data->point.x, &data->point.y);
|
|
||||||
|
|
||||||
// /*Get whether the a key is pressed and save the pressed key*/
|
adc_key = device_find("adc_key");
|
||||||
// uint32_t act_key = keypad_get_key();
|
if(adc_key)
|
||||||
// if(act_key != 0) {
|
{
|
||||||
// data->state = LV_INDEV_STATE_PR;
|
ADC_DEV(adc_key)->continuous_conv_mode = ENABLE;
|
||||||
|
device_open(adc_key, DEVICE_OFLAG_STREAM_RX);
|
||||||
|
device_control(adc_key,DEVICE_CTRL_ADC_CHANNEL_CONFIG,&adc_channel_cfg);
|
||||||
|
adc_channel_start(adc_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// /*Translate the keys to LVGL control characters according to your key definitions*/
|
/* Will be called by the library to read the keypad */
|
||||||
// switch(act_key) {
|
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||||
// case 1:
|
{
|
||||||
// act_key = LV_KEY_NEXT;
|
static uint32_t last_key = 0;
|
||||||
// break;
|
|
||||||
// case 2:
|
|
||||||
// act_key = LV_KEY_PREV;
|
|
||||||
// break;
|
|
||||||
// case 3:
|
|
||||||
// act_key = LV_KEY_LEFT;
|
|
||||||
// break;
|
|
||||||
// case 4:
|
|
||||||
// act_key = LV_KEY_RIGHT;
|
|
||||||
// break;
|
|
||||||
// case 5:
|
|
||||||
// act_key = LV_KEY_ENTER;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// last_key = act_key;
|
/*Get the current x and y coordinates*/
|
||||||
// } else {
|
//mouse_get_xy(&data->point.x, &data->point.y);
|
||||||
// data->state = LV_INDEV_STATE_REL;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// data->key = last_key;
|
/*Get whether the a key is pressed and save the pressed key*/
|
||||||
|
uint32_t act_key = keypad_get_key();
|
||||||
|
if(act_key != 0) {
|
||||||
|
data->state = LV_INDEV_STATE_PR;
|
||||||
|
/*Translate the keys to LVGL control characters according to your key definitions*/
|
||||||
|
switch(act_key) {
|
||||||
|
case 1:
|
||||||
|
act_key = LV_KEY_LEFT;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
act_key = LV_KEY_RIGHT;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
act_key = LV_KEY_UP;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
act_key = LV_KEY_DOWN;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
act_key = LV_KEY_ENTER;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
last_key = act_key;
|
||||||
|
|
||||||
// /*Return `false` because we are not buffering and no more data to read*/
|
} else {
|
||||||
// return false;
|
data->state = LV_INDEV_STATE_REL;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
data->key = last_key;
|
||||||
|
|
||||||
|
/*Return `false` because we are not buffering and no more data to read*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*Get the currently being pressed key. 0 if no key is pressed*/
|
/*Get the currently being pressed key. 0 if no key is pressed*/
|
||||||
// static uint32_t keypad_get_key(void)
|
static uint32_t keypad_get_key(void)
|
||||||
// {
|
{
|
||||||
// /*Your code comes here*/
|
static uint8_t old_key_v = 0;
|
||||||
|
static uint8_t old_key_num = 0;
|
||||||
|
static uint8_t last_key;
|
||||||
|
uint8_t key;
|
||||||
|
uint16_t key_voltage;
|
||||||
|
/*Your code comes here*/
|
||||||
|
device_read(adc_key, 0, (void *)&result_val,sizeof(result_val)/sizeof(adc_channel_val_t));
|
||||||
|
key_voltage = result_val.volt * 1000;
|
||||||
|
|
||||||
// return 0;
|
for(key=0;key<sizeof(key_value)/sizeof(key_value[0]);key++)
|
||||||
// }
|
{
|
||||||
|
if(DIFF(key_voltage,key_value[key]) < KEY_ADC_DIFF_MAX )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key+=1;
|
||||||
|
if( key > sizeof(key_value))
|
||||||
|
{
|
||||||
|
key = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == last_key)
|
||||||
|
{
|
||||||
|
old_key_v = key;
|
||||||
|
old_key_num = 0;
|
||||||
|
}
|
||||||
|
else if(key==old_key_v)
|
||||||
|
{
|
||||||
|
old_key_num++;
|
||||||
|
if(old_key_num >= KEY_NOISE_NUM_MAX)
|
||||||
|
{
|
||||||
|
last_key = key;
|
||||||
|
old_key_num = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
old_key_num = 0;
|
||||||
|
old_key_v = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return last_key;
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------
|
/*------------------
|
||||||
* Encoder
|
* Encoder
|
||||||
|
|
|
@ -22,6 +22,10 @@ extern "C" {
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
#define KEY_ADC_DIFF_MAX 15
|
||||||
|
#define DIFF(x,y) (((x)>(y))?((x)-(y)):((y)-(x)))
|
||||||
|
|
||||||
|
#define KEY_NOISE_NUM_MAX 2
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
|
@ -30,6 +34,14 @@ extern "C" {
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
/**********************
|
||||||
|
* STATIC VARIABLES
|
||||||
|
**********************/
|
||||||
|
extern lv_indev_t * indev_touchpad;
|
||||||
|
//extern lv_indev_t * indev_mouse;
|
||||||
|
extern lv_indev_t * indev_keypad;
|
||||||
|
//extern lv_indev_t * indev_encoder;
|
||||||
|
//extern lv_indev_t * indev_button;
|
||||||
|
|
||||||
void lv_port_indev_init(void);
|
void lv_port_indev_init(void);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ static uint8_t uart_dbg_disable=0;
|
||||||
Shell shell;
|
Shell shell;
|
||||||
char shellBuffer[512];
|
char shellBuffer[512];
|
||||||
|
|
||||||
void uart0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
void uart_iqr_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ void shell_init(void)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void uart0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
void uart_iqr_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||||
{
|
{
|
||||||
if (state == UART_EVENT_RX_FIFO)
|
if (state == UART_EVENT_RX_FIFO)
|
||||||
{
|
{
|
||||||
|
@ -88,22 +88,25 @@ __WEAK__ void bl_show_info(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__WEAK__ enum uart_index_type board_get_debug_uart_index(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void bflb_platform_init(uint32_t baudrate)
|
void bflb_platform_init(uint32_t baudrate)
|
||||||
{
|
{
|
||||||
disable_irq();
|
disable_irq();
|
||||||
|
|
||||||
board_init();
|
board_init();
|
||||||
|
|
||||||
mtimer_init();
|
|
||||||
|
|
||||||
if(!uart_dbg_disable){
|
if(!uart_dbg_disable){
|
||||||
uart_register(UART0_INDEX, "debug_log", DEVICE_OFLAG_RDWR);
|
uart_register(board_get_debug_uart_index(), "debug_log", DEVICE_OFLAG_RDWR);
|
||||||
struct device *uart = device_find("debug_log");
|
struct device *uart = device_find("debug_log");
|
||||||
|
|
||||||
if (uart)
|
if (uart)
|
||||||
{
|
{
|
||||||
device_open(uart, DEVICE_OFLAG_STREAM_TX | DEVICE_OFLAG_INT_RX);
|
device_open(uart, DEVICE_OFLAG_STREAM_TX | DEVICE_OFLAG_INT_RX);
|
||||||
device_set_callback(uart, uart0_irq_callback);
|
device_set_callback(uart, uart_iqr_callback);
|
||||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +119,7 @@ void bflb_platform_init(uint32_t baudrate)
|
||||||
|
|
||||||
if (!mmheap_init_with_pool(&_HeapBase, (size_t)&_HeapSize))
|
if (!mmheap_init_with_pool(&_HeapBase, (size_t)&_HeapSize))
|
||||||
{
|
{
|
||||||
MSG("dynamic memory init success,heap size = 0x%x \r\n", &_HeapSize);
|
// MSG("dynamic memory init success,heap size = 0x%x \r\n", &_HeapSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -146,6 +149,11 @@ void bflb_platform_print_set(uint8_t disable)
|
||||||
uart_dbg_disable=disable;
|
uart_dbg_disable=disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bflb_platform_print_get(void)
|
||||||
|
{
|
||||||
|
return uart_dbg_disable;
|
||||||
|
}
|
||||||
|
|
||||||
void bflb_platform_deinit(void)
|
void bflb_platform_deinit(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -170,12 +178,12 @@ void bflb_platform_dump(uint8_t *data, uint32_t len)
|
||||||
|
|
||||||
void bflb_platform_init_time()
|
void bflb_platform_init_time()
|
||||||
{
|
{
|
||||||
mtimer_init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bflb_platform_deinit_time()
|
void bflb_platform_deinit_time()
|
||||||
{
|
{
|
||||||
mtimer_deinit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bflb_platform_set_alarm_time(uint64_t time,void( *interruptFun )( void ))
|
void bflb_platform_set_alarm_time(uint64_t time,void( *interruptFun )( void ))
|
||||||
|
@ -185,17 +193,17 @@ void bflb_platform_set_alarm_time(uint64_t time,void( *interruptFun )( void ))
|
||||||
|
|
||||||
void bflb_platform_clear_time()
|
void bflb_platform_clear_time()
|
||||||
{
|
{
|
||||||
mtimer_clear_time();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bflb_platform_start_time()
|
void bflb_platform_start_time()
|
||||||
{
|
{
|
||||||
mtimer_start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bflb_platform_stop_time()
|
void bflb_platform_stop_time()
|
||||||
{
|
{
|
||||||
mtimer_stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t bflb_platform_get_time_ms()
|
uint64_t bflb_platform_get_time_ms()
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
//#include "mcu_sdk_version.h"
|
//#include "mcu_sdk_version.h"
|
||||||
|
|
||||||
|
#define printf(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
||||||
#define MSG(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
#define MSG(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
||||||
#define MSG_DBG(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
#define MSG_DBG(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
||||||
#define MSG_ERR(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
#define MSG_ERR(a,...) bflb_platform_printf(a,##__VA_ARGS__)
|
||||||
|
@ -79,6 +80,8 @@ void check_failed(uint8_t *file, uint32_t line);
|
||||||
|
|
||||||
void bflb_platform_init(uint32_t baudrate);
|
void bflb_platform_init(uint32_t baudrate);
|
||||||
void bflb_platform_printf(char *fmt,...);
|
void bflb_platform_printf(char *fmt,...);
|
||||||
|
void bflb_platform_print_set(uint8_t disable);
|
||||||
|
uint8_t bflb_platform_print_get(void);
|
||||||
void bflb_platform_dump(uint8_t *data, uint32_t len);
|
void bflb_platform_dump(uint8_t *data, uint32_t len);
|
||||||
void bflb_platform_deinit(void);
|
void bflb_platform_deinit(void);
|
||||||
|
|
||||||
|
|
142
bsp/bsp_common/psram/bsp_sf_psram.c
Normal file
142
bsp/bsp_common/psram/bsp_sf_psram.c
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/**
|
||||||
|
* @file bsp_sf_psram.c
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bsp_sf_psram.h"
|
||||||
|
#include "bflb_platform.h"
|
||||||
|
#include "bl702_psram.h"
|
||||||
|
#include "bl702_l1c.h"
|
||||||
|
#include "bl702_sec_eng.h"
|
||||||
|
#include "bl702_glb.h"
|
||||||
|
|
||||||
|
/* bsp sf psram private variables */
|
||||||
|
|
||||||
|
SPI_Psram_Cfg_Type apMemory1604 = {
|
||||||
|
.readIdCmd = 0x9F,
|
||||||
|
.readIdDmyClk = 0,
|
||||||
|
.burstToggleCmd = 0xC0,
|
||||||
|
.resetEnableCmd = 0x66,
|
||||||
|
.resetCmd = 0x99,
|
||||||
|
.enterQuadModeCmd = 0x35,
|
||||||
|
.exitQuadModeCmd = 0xF5,
|
||||||
|
.readRegCmd = 0xB5,
|
||||||
|
.readRegDmyClk = 1,
|
||||||
|
.writeRegCmd = 0xB1,
|
||||||
|
.readCmd = 0x03,
|
||||||
|
.readDmyClk = 0,
|
||||||
|
.fReadCmd = 0x0B,
|
||||||
|
.fReadDmyClk = 1,
|
||||||
|
.fReadQuadCmd = 0xEB,
|
||||||
|
.fReadQuadDmyClk = 3,
|
||||||
|
.writeCmd = 0x02,
|
||||||
|
.quadWriteCmd = 0x38,
|
||||||
|
.pageSize = 512,
|
||||||
|
.ctrlMode = PSRAM_SPI_CTRL_MODE,
|
||||||
|
.driveStrength = PSRAM_DRIVE_STRENGTH_50_OHMS,
|
||||||
|
.burstLength = PSRAM_BURST_LENGTH_512_BYTES,
|
||||||
|
};
|
||||||
|
|
||||||
|
SF_Ctrl_Cmds_Cfg cmdsCfg = {
|
||||||
|
.cmdsEn = ENABLE,
|
||||||
|
.burstToggleEn = ENABLE,
|
||||||
|
.wrapModeEn = DISABLE,
|
||||||
|
.wrapLen = SF_CTRL_WRAP_LEN_512,
|
||||||
|
};
|
||||||
|
SF_Ctrl_Psram_Cfg sfCtrlPsramCfg = {
|
||||||
|
.owner = SF_CTRL_OWNER_SAHB,
|
||||||
|
.padSel = SF_CTRL_PAD_SEL_DUAL_CS_SF2,
|
||||||
|
.bankSel = SF_CTRL_SEL_PSRAM,
|
||||||
|
.psramRxClkInvertSrc = ENABLE,
|
||||||
|
.psramRxClkInvertSel = DISABLE,
|
||||||
|
.psramDelaySrc = ENABLE,
|
||||||
|
.psramClkDelay = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* bsp sf psram gpio init */
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void ATTR_TCM_SECTION bsp_sf_psram_gpio_init(void)
|
||||||
|
{
|
||||||
|
GLB_GPIO_Cfg_Type cfg;
|
||||||
|
uint8_t gpiopins[7];
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
|
cfg.gpioMode = GPIO_MODE_AF;
|
||||||
|
cfg.pullType = GPIO_PULL_UP;
|
||||||
|
cfg.drive = 3;
|
||||||
|
cfg.smtCtrl = 1;
|
||||||
|
cfg.gpioFun = GPIO_FUN_FLASH_PSRAM;
|
||||||
|
|
||||||
|
gpiopins[0] = BFLB_EXTPSRAM_CLK_GPIO;
|
||||||
|
gpiopins[1] = BFLB_EXTPSRAM_CS_GPIO;
|
||||||
|
gpiopins[2] = BFLB_EXTPSRAM_DATA0_GPIO;
|
||||||
|
gpiopins[3] = BFLB_EXTPSRAM_DATA1_GPIO;
|
||||||
|
gpiopins[4] = BFLB_EXTPSRAM_DATA2_GPIO;
|
||||||
|
gpiopins[5] = BFLB_EXTPSRAM_DATA3_GPIO;
|
||||||
|
gpiopins[6] = BFLB_EXTFLASH_CS_GPIO;
|
||||||
|
|
||||||
|
for(i=0; i<sizeof(gpiopins); i++){
|
||||||
|
cfg.gpioPin = gpiopins[i];
|
||||||
|
if(i==0 || i==1 || i==6){
|
||||||
|
/*flash clk and cs is output*/
|
||||||
|
cfg.gpioMode = GPIO_MODE_OUTPUT;
|
||||||
|
}else{
|
||||||
|
/*data are bidir*/
|
||||||
|
cfg.gpioMode = GPIO_MODE_AF;
|
||||||
|
}
|
||||||
|
GLB_GPIO_Init(&cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bsp sf psram init */
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param sw_reset
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void ATTR_TCM_SECTION bsp_sf_psram_init(uint8_t sw_reset)
|
||||||
|
{
|
||||||
|
uint8_t psramId[8] = {0};
|
||||||
|
bsp_sf_psram_gpio_init();
|
||||||
|
|
||||||
|
Psram_Init(&apMemory1604, &cmdsCfg, &sfCtrlPsramCfg);
|
||||||
|
if(sw_reset){
|
||||||
|
Psram_SoftwareReset(&apMemory1604, apMemory1604.ctrlMode);
|
||||||
|
}
|
||||||
|
Psram_ReadId(&apMemory1604, psramId);
|
||||||
|
Psram_Cache_Write_Set(&apMemory1604, SF_CTRL_QIO_MODE, ENABLE, DISABLE, DISABLE);
|
||||||
|
L1C_Cache_Enable_Set(L1C_WAY_DISABLE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATTR_TCM_SECTION bsp_sf_psram_read_id(uint8_t *data)
|
||||||
|
{
|
||||||
|
Psram_ReadId(&apMemory1604, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
46
bsp/bsp_common/psram/bsp_sf_psram.h
Normal file
46
bsp/bsp_common/psram/bsp_sf_psram.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* @file bsp_sf_psram.h
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __BSP_SF_PSRAM_H__
|
||||||
|
#define __BSP_SF_PSRAM_H__
|
||||||
|
|
||||||
|
#include "bl702.h"
|
||||||
|
|
||||||
|
#define BSP_PSRAM_BASE BL702_PSRAM_XIP_BASE
|
||||||
|
|
||||||
|
#define PSRAM_SIZE 2*1024*1024
|
||||||
|
|
||||||
|
#define BFLB_EXTFLASH_CS_GPIO GLB_GPIO_PIN_25
|
||||||
|
#define BFLB_EXTPSRAM_CLK_GPIO GLB_GPIO_PIN_27
|
||||||
|
#define BFLB_EXTPSRAM_CS_GPIO GLB_GPIO_PIN_17
|
||||||
|
#define BFLB_EXTPSRAM_DATA0_GPIO GLB_GPIO_PIN_28
|
||||||
|
#define BFLB_EXTPSRAM_DATA1_GPIO GLB_GPIO_PIN_24
|
||||||
|
#define BFLB_EXTPSRAM_DATA2_GPIO GLB_GPIO_PIN_23
|
||||||
|
#define BFLB_EXTPSRAM_DATA3_GPIO GLB_GPIO_PIN_26
|
||||||
|
|
||||||
|
void bsp_sf_psram_gpio_init(void);
|
||||||
|
void bsp_sf_psram_init(uint8_t sw_reset);
|
||||||
|
void bsp_sf_psram_read_id(uint8_t *data);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __BSP_SF_PSRAM_H__ */
|
|
@ -27,27 +27,41 @@
|
||||||
#include "bl702_spi.h"
|
#include "bl702_spi.h"
|
||||||
#include "bsp_spi_sd.h"
|
#include "bsp_spi_sd.h"
|
||||||
|
|
||||||
struct device* spi0;
|
static struct device* spi0;
|
||||||
struct device* dma_ch3;
|
static struct device* dma_ch3;
|
||||||
struct device* dma_ch4;
|
static struct device* dma_ch4;
|
||||||
|
|
||||||
SD_CardInfoTypedef SD_CardInfo = {0};
|
SD_CardInfoTypedef SD_CardInfo = {0};
|
||||||
|
|
||||||
|
|
||||||
uint8_t SD_SPI_Init(void)
|
uint8_t SD_SPI_Init(void)
|
||||||
{
|
{
|
||||||
spi_register(0,"spi0",DEVICE_OFLAG_RDWR);
|
|
||||||
dma_register(DMA0_CH3_INDEX, "ch3", DEVICE_OFLAG_RDWR);
|
|
||||||
dma_register(DMA0_CH4_INDEX, "ch4", DEVICE_OFLAG_RDWR);
|
|
||||||
gpio_set_mode(SPI_PIN_CS,GPIO_OUTPUT_MODE);
|
gpio_set_mode(SPI_PIN_CS,GPIO_OUTPUT_MODE);
|
||||||
gpio_write(SPI_PIN_CS,1);
|
gpio_write(SPI_PIN_CS,1);
|
||||||
|
|
||||||
spi0 = device_find("spi0");
|
spi0 = device_find("spi0");
|
||||||
if(spi0)
|
if(spi0)
|
||||||
{
|
{
|
||||||
device_open(spi0,DEVICE_OFLAG_DMA_TX|DEVICE_OFLAG_DMA_RX);
|
device_close(spi0);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
spi_register(SPI0_INDEX,"spi0",DEVICE_OFLAG_RDWR);
|
||||||
|
spi0 = device_find("spi0");
|
||||||
|
}
|
||||||
|
if(spi0)
|
||||||
|
{
|
||||||
|
device_open(spi0,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
|
||||||
}
|
}
|
||||||
|
|
||||||
dma_ch3 = device_find("ch3");
|
dma_ch3 = device_find("dma0_ch3");
|
||||||
|
if(dma_ch3)
|
||||||
|
{
|
||||||
|
device_close(dma_ch3);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
dma_register(DMA0_CH3_INDEX, "dma0_ch3", DEVICE_OFLAG_RDWR);
|
||||||
|
dma_ch3 = device_find("dma0_ch3");
|
||||||
|
}
|
||||||
if (dma_ch3)
|
if (dma_ch3)
|
||||||
{
|
{
|
||||||
((dma_device_t*)dma_ch3)->direction = DMA_MEMORY_TO_PERIPH;
|
((dma_device_t*)dma_ch3)->direction = DMA_MEMORY_TO_PERIPH;
|
||||||
|
@ -57,11 +71,17 @@ uint8_t SD_SPI_Init(void)
|
||||||
((dma_device_t*)dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
|
((dma_device_t*)dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
|
||||||
((dma_device_t*)dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
|
((dma_device_t*)dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
|
||||||
device_open(dma_ch3, 0);
|
device_open(dma_ch3, 0);
|
||||||
device_set_callback(dma_ch3, NULL);
|
|
||||||
device_control(dma_ch3, DEVICE_CTRL_SET_INT, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dma_ch4 = device_find("ch4");
|
dma_ch4 = device_find("dma0_ch4");
|
||||||
|
if(dma_ch4)
|
||||||
|
{
|
||||||
|
device_close(dma_ch4);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
dma_register(DMA0_CH4_INDEX, "dma0_ch4", DEVICE_OFLAG_RDWR);
|
||||||
|
dma_ch4 = device_find("dma0_ch4");
|
||||||
|
}
|
||||||
if (dma_ch4)
|
if (dma_ch4)
|
||||||
{
|
{
|
||||||
((dma_device_t*)dma_ch4)->direction = DMA_PERIPH_TO_MEMORY;
|
((dma_device_t*)dma_ch4)->direction = DMA_PERIPH_TO_MEMORY;
|
||||||
|
@ -71,62 +91,34 @@ uint8_t SD_SPI_Init(void)
|
||||||
((dma_device_t*)dma_ch4)->src_width = DMA_TRANSFER_WIDTH_8BIT ;
|
((dma_device_t*)dma_ch4)->src_width = DMA_TRANSFER_WIDTH_8BIT ;
|
||||||
((dma_device_t*)dma_ch4)->dst_width = DMA_TRANSFER_WIDTH_8BIT ;
|
((dma_device_t*)dma_ch4)->dst_width = DMA_TRANSFER_WIDTH_8BIT ;
|
||||||
device_open(dma_ch4, 0);
|
device_open(dma_ch4, 0);
|
||||||
device_set_callback(dma_ch4, NULL);
|
|
||||||
device_control(dma_ch4, DEVICE_CTRL_SET_INT, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
BL_Err_Type SPI_ReadWriteByte(uint8_t *txBuff, uint8_t *rxBuff, uint32_t length)
|
BL_Err_Type SPI_ReadWriteByte(uint8_t *txBuff, uint8_t *rxBuff, uint32_t length)
|
||||||
{
|
{
|
||||||
static SPI_FifoCfg_Type SPI_fifoconfig={
|
|
||||||
.txFifoThreshold = 1,
|
|
||||||
.rxFifoThreshold = 1,
|
|
||||||
.txFifoDmaEnable = ENABLE,
|
|
||||||
.rxFifoDmaEnable = ENABLE,
|
|
||||||
};
|
|
||||||
|
|
||||||
// DMA自动与手动无法同时使用,DmaEnable开启后,一旦进行手动发送,之后DMA发送就会卡死
|
while(device_control(dma_ch3,DMA_CHANNEL_GET_STATUS,NULL)||device_control(dma_ch4,DMA_CHANNEL_GET_STATUS,NULL));
|
||||||
// test code:
|
|
||||||
// MSG("SPI_DMA_test 1\r\n");
|
|
||||||
// dma_reload(dma_ch3, (uint32_t)txBuff, (uint32_t)DMA_ADDR_SPI_TDR, length);
|
|
||||||
// dma_reload(dma_ch4, (uint32_t)DMA_ADDR_SPI_RDR, (uint32_t)rxBuff, length);
|
|
||||||
// dma_channel_start(dma_ch3);
|
|
||||||
// dma_channel_start(dma_ch4);
|
|
||||||
// while (device_control(dma_ch3, DMA_CHANNEL_GET_STATUS, NULL) || device_control(dma_ch4, DMA_CHANNEL_GET_STATUS, NULL))
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// MSG("SPI_DMA_test 2\r\n");
|
|
||||||
// spi_transmit_receive(spi0,txBuff,rxBuff,length,SPI_DATASIZE_8BIT);
|
|
||||||
// MSG("SPI_DMA_test 3\r\n");
|
|
||||||
|
|
||||||
if(length<500)
|
if(length<500)
|
||||||
{
|
{
|
||||||
if(SPI_fifoconfig.txFifoDmaEnable == ENABLE || SPI_fifoconfig.rxFifoDmaEnable == ENABLE)
|
|
||||||
{
|
|
||||||
SPI_fifoconfig.txFifoDmaEnable = DISABLE;
|
|
||||||
SPI_fifoconfig.rxFifoDmaEnable = DISABLE;
|
|
||||||
SPI_FifoConfig(SPI_ID_0,&SPI_fifoconfig);
|
|
||||||
}
|
|
||||||
spi_transmit_receive(spi0,txBuff,rxBuff,length,SPI_DATASIZE_8BIT);
|
spi_transmit_receive(spi0,txBuff,rxBuff,length,SPI_DATASIZE_8BIT);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
if(SPI_fifoconfig.txFifoDmaEnable == DISABLE || SPI_fifoconfig.rxFifoDmaEnable == DISABLE)
|
{
|
||||||
{
|
device_control(spi0, DEVICE_CTRL_TX_DMA_RESUME, NULL);
|
||||||
SPI_fifoconfig.txFifoDmaEnable = ENABLE;
|
device_control(spi0, DEVICE_CTRL_RX_DMA_RESUME, NULL);
|
||||||
SPI_fifoconfig.rxFifoDmaEnable = ENABLE;
|
device_control(dma_ch3, DEVICE_CTRL_CLR_INT, NULL);
|
||||||
SPI_FifoConfig(SPI_ID_0,&SPI_fifoconfig);
|
device_control(dma_ch4, DEVICE_CTRL_CLR_INT, NULL);
|
||||||
}
|
|
||||||
dma_reload(dma_ch3, (uint32_t)txBuff, (uint32_t)DMA_ADDR_SPI_TDR, length);
|
dma_reload(dma_ch3, (uint32_t)txBuff, (uint32_t)DMA_ADDR_SPI_TDR, length);
|
||||||
dma_reload(dma_ch4, (uint32_t)DMA_ADDR_SPI_RDR, (uint32_t)rxBuff, length);
|
dma_reload(dma_ch4, (uint32_t)DMA_ADDR_SPI_RDR, (uint32_t)rxBuff, length);
|
||||||
dma_channel_start(dma_ch3);
|
dma_channel_start(dma_ch3);
|
||||||
dma_channel_start(dma_ch4);
|
dma_channel_start(dma_ch4);
|
||||||
while(device_control(dma_ch3,DMA_CHANNEL_GET_STATUS,NULL)||device_control(dma_ch4,DMA_CHANNEL_GET_STATUS,NULL))
|
|
||||||
{
|
while(device_control(dma_ch3,DMA_CHANNEL_GET_STATUS,NULL)||device_control(dma_ch4,DMA_CHANNEL_GET_STATUS,NULL));
|
||||||
}
|
device_control(spi0, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);
|
||||||
dma_channel_stop(dma_ch3);
|
device_control(spi0, DEVICE_CTRL_RX_DMA_SUSPEND, NULL);
|
||||||
dma_channel_stop(dma_ch4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#ifndef __SPI_SD_H__
|
#ifndef __SPI_SD_H__
|
||||||
#define __SPI_SD_H__
|
#define __SPI_SD_H__
|
||||||
|
|
||||||
#define SPI_PIN_CS GPIO_PIN_10
|
#define SPI_PIN_CS GPIO_PIN_16
|
||||||
|
|
||||||
//SD传输数据结束后是否释放总线宏定义
|
//SD传输数据结束后是否释放总线宏定义
|
||||||
#define NO_RELEASE 0
|
#define NO_RELEASE 0
|
||||||
|
|
41
bsp/bsp_common/touch/touch.c
Normal file
41
bsp/bsp_common/touch/touch.c
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* @file touch.c
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include"touch.h"
|
||||||
|
|
||||||
|
void touch_init(void)
|
||||||
|
{
|
||||||
|
#if defined (TOUCH_CONTROLLER_XPT2046)
|
||||||
|
xpt2046_init();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t touch_read(int16_t * x, int16_t * y)
|
||||||
|
{
|
||||||
|
#if defined (TOUCH_CONTROLLER_XPT2046)
|
||||||
|
return xpt2046_read( x, y);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* @file audio_core.h
|
* @file touch.h
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
@ -21,25 +21,18 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __AUDIO_PROTO__
|
#ifndef _TOUCH_H_
|
||||||
#define __AUDIO_PROTO__
|
#define _TOUCH_H_
|
||||||
|
|
||||||
#include "misc.h"
|
#define TOUCH_CONTROLLER_XPT2046
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
|
|
||||||
uint8_t *buff1;
|
#ifdef TOUCH_CONTROLLER_XPT2046
|
||||||
uint8_t *buff2;
|
#include "xpt2046.h"
|
||||||
uint32_t buff_size;
|
#endif
|
||||||
|
|
||||||
struct device * audio_dma;
|
|
||||||
struct device * audio_device;
|
void touch_init(void);
|
||||||
|
uint8_t touch_read(int16_t * x, int16_t * y);
|
||||||
int (*buffer_ready_callback)(char bufIndex);
|
|
||||||
|
|
||||||
}audio_core_t;
|
|
||||||
|
|
||||||
int audio_core_init(audio_core_t * audio_core_cfg);
|
|
||||||
int audio_core_start(void);
|
|
||||||
int audio_core_stop(void);
|
|
||||||
#endif
|
#endif
|
|
@ -73,14 +73,20 @@ static uint16_t xpt2046_cmd(uint8_t cmd)
|
||||||
void xpt2046_init(void)
|
void xpt2046_init(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(TOUCH_PIN_CS,GPIO_OUTPUT_MODE);
|
gpio_set_mode(TOUCH_PIN_CS,GPIO_OUTPUT_MODE);
|
||||||
gpio_write(TOUCH_PIN_CS,1); //CS2
|
gpio_write(TOUCH_PIN_CS,1);
|
||||||
touch_spi = device_find("spi0");
|
touch_spi = device_find("spi0");
|
||||||
if(touch_spi)
|
if(touch_spi)
|
||||||
{
|
{
|
||||||
return ;
|
device_close(touch_spi);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
spi_register(SPI0_INDEX,"spi0",DEVICE_OFLAG_RDWR);
|
||||||
|
touch_spi = device_find("spi0");
|
||||||
|
}
|
||||||
|
if(touch_spi)
|
||||||
|
{
|
||||||
|
device_open(touch_spi,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
|
||||||
}
|
}
|
||||||
spi_register(SPI0_INDEX,"spi0",DEVICE_OFLAG_RDWR);
|
|
||||||
device_open(touch_spi,DEVICE_OFLAG_STREAM_TX|DEVICE_OFLAG_STREAM_RX);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +104,6 @@ static uint8_t xpt2048_is_touch_detected()
|
||||||
uint16_t z1 = xpt2046_cmd(CMD_Z1_READ) ;
|
uint16_t z1 = xpt2046_cmd(CMD_Z1_READ) ;
|
||||||
uint16_t z2 = xpt2046_cmd(CMD_Z2_READ) ;
|
uint16_t z2 = xpt2046_cmd(CMD_Z2_READ) ;
|
||||||
|
|
||||||
|
|
||||||
// this is not what the confusing datasheet says but it seems to
|
// this is not what the confusing datasheet says but it seems to
|
||||||
// be enough to detect real touches on the panel
|
// be enough to detect real touches on the panel
|
||||||
uint16_t z = z1 + 4096 - z2;
|
uint16_t z = z1 + 4096 - z2;
|
||||||
|
@ -122,7 +127,7 @@ static uint8_t xpt2048_is_touch_detected()
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static uint8_t xpt2046_ads_get(uint16_t *x, uint16_t *y)
|
static uint8_t xpt2046_ads_get(int16_t *x, int16_t *y)
|
||||||
{
|
{
|
||||||
for(uint8_t i=0; i<XPT2046_AVG_NUM; i++)
|
for(uint8_t i=0; i<XPT2046_AVG_NUM; i++)
|
||||||
{
|
{
|
||||||
|
@ -134,9 +139,9 @@ static uint8_t xpt2046_ads_get(uint16_t *x, uint16_t *y)
|
||||||
avg_buf_y[i] = xpt2046_cmd(CMD_Y_READ);
|
avg_buf_y[i] = xpt2046_cmd(CMD_Y_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t x_min=avg_buf_x[0],x_max=avg_buf_x[0];
|
int16_t x_min=avg_buf_x[0],x_max=avg_buf_x[0];
|
||||||
uint16_t y_min=avg_buf_y[0],y_max=avg_buf_y[0];
|
int16_t y_min=avg_buf_y[0],y_max=avg_buf_y[0];
|
||||||
uint32_t x_sum=avg_buf_x[0],y_sum=avg_buf_y[0];
|
int32_t x_sum=avg_buf_x[0],y_sum=avg_buf_y[0];
|
||||||
|
|
||||||
for(uint8_t i=1; i<XPT2046_AVG_NUM; i++)
|
for(uint8_t i=1; i<XPT2046_AVG_NUM; i++)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +169,7 @@ static uint8_t xpt2046_ads_get(uint16_t *x, uint16_t *y)
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static uint8_t xpt2046_corr(uint16_t * x, uint16_t * y, int8_t rotated)
|
static uint8_t xpt2046_adc2xy(int16_t * x, int16_t * y )
|
||||||
{
|
{
|
||||||
if((*x) > XPT2046_X_MIN)
|
if((*x) > XPT2046_X_MIN)
|
||||||
(*x) -= XPT2046_X_MIN;
|
(*x) -= XPT2046_X_MIN;
|
||||||
|
@ -176,36 +181,12 @@ static uint8_t xpt2046_corr(uint16_t * x, uint16_t * y, int8_t rotated)
|
||||||
else
|
else
|
||||||
(*y) = 0;
|
(*y) = 0;
|
||||||
|
|
||||||
if(rotated==TOUCH_ROT_90 || rotated==TOUCH_ROT_270)
|
(*x) = (uint32_t)((uint32_t)(*x) * 240) /
|
||||||
{
|
|
||||||
uint16_t temp = *x;
|
|
||||||
*x = *y;
|
|
||||||
*y = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*x) = (uint32_t)((uint32_t)(*x) * LV_HOR_RES) /
|
|
||||||
(XPT2046_X_MAX - XPT2046_X_MIN);
|
(XPT2046_X_MAX - XPT2046_X_MIN);
|
||||||
|
|
||||||
(*y) = (uint32_t)((uint32_t)(*y) * LV_VER_RES) /
|
(*y) = (uint32_t)((uint32_t)(*y) * 320) /
|
||||||
(XPT2046_Y_MAX - XPT2046_Y_MIN);
|
(XPT2046_Y_MAX - XPT2046_Y_MIN);
|
||||||
|
|
||||||
switch (rotated)
|
|
||||||
{
|
|
||||||
case TOUCH_ROT_NONE:
|
|
||||||
break;
|
|
||||||
case TOUCH_ROT_90:
|
|
||||||
*y = -*y;
|
|
||||||
break;
|
|
||||||
case TOUCH_ROT_180:
|
|
||||||
*x = -*x;
|
|
||||||
*y = -*y;
|
|
||||||
break;
|
|
||||||
case TOUCH_ROT_270:
|
|
||||||
*x = -*x;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,18 +198,18 @@ static uint8_t xpt2046_corr(uint16_t * x, uint16_t * y, int8_t rotated)
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
uint8_t xpt2046_read(uint16_t * x, uint16_t * y, int8_t rotated)
|
uint8_t xpt2046_read(int16_t * x, int16_t * y)
|
||||||
{
|
{
|
||||||
static uint16_t xt=0,yt=0;
|
static int16_t xt=0,yt=0;
|
||||||
static uint8_t avg_last = 0;
|
static uint8_t avg_last = 0;
|
||||||
uint16_t x1,y1;
|
int16_t x1,y1;
|
||||||
|
|
||||||
if(xpt2046_ads_get(&x1, &y1)==0)
|
if(xpt2046_ads_get(&x1, &y1)==0)
|
||||||
{
|
{
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xpt2046_corr(&x1,&y1,rotated)==0)
|
if(xpt2046_adc2xy(&x1,&y1)==0)
|
||||||
{
|
{
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#ifndef _XPT2046_H_
|
||||||
|
#define _XPT2046_H_
|
||||||
|
|
||||||
|
#include "bflb_platform.h"
|
||||||
|
|
||||||
#define TOUCH_PIN_CS GPIO_PIN_11
|
#define TOUCH_PIN_CS GPIO_PIN_11
|
||||||
//#define TOUCH_PIN_PEN GPIO_PIN_11
|
//#define TOUCH_PIN_PEN GPIO_PIN_11
|
||||||
|
@ -39,5 +42,9 @@
|
||||||
#define XPT2046_X_MAX 3850
|
#define XPT2046_X_MAX 3850
|
||||||
#define XPT2046_Y_MAX 3700
|
#define XPT2046_Y_MAX 3700
|
||||||
|
|
||||||
|
extern struct device* touch_spi;
|
||||||
|
|
||||||
void xpt2046_init(void);
|
void xpt2046_init(void);
|
||||||
uint8_t xpt2046_read(uint16_t * x, uint16_t * y, int8_t rotated);
|
uint8_t xpt2046_read(int16_t * x, int16_t * y);
|
||||||
|
|
||||||
|
#endif
|
|
@ -78,6 +78,7 @@ void uart1_init(void)
|
||||||
if (uart1)
|
if (uart1)
|
||||||
{
|
{
|
||||||
device_open(uart1, DEVICE_OFLAG_DMA_TX | DEVICE_OFLAG_INT_RX); //uart0 tx dma mode
|
device_open(uart1, DEVICE_OFLAG_DMA_TX | DEVICE_OFLAG_INT_RX); //uart0 tx dma mode
|
||||||
|
device_control(uart1, DEVICE_CTRL_SUSPEND, NULL);
|
||||||
device_set_callback(uart1, uart_irq_callback);
|
device_set_callback(uart1, uart_irq_callback);
|
||||||
device_control(uart1, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT | UART_RTO_IT));
|
device_control(uart1, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT | UART_RTO_IT));
|
||||||
}
|
}
|
||||||
|
@ -121,29 +122,38 @@ void uart1_config(uint32_t baudrate, uart_databits_t databits, uart_parity_t par
|
||||||
device_control(uart1, DEVICE_CTRL_CONFIG, &cfg);
|
device_control(uart1, DEVICE_CTRL_CONFIG, &cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t uart1_dtr;
|
||||||
|
static uint8_t uart1_rts;
|
||||||
|
|
||||||
|
void uart1_set_dtr_rts(uint8_t dtr, uint8_t rts)
|
||||||
|
{
|
||||||
|
uart1_dtr = dtr;
|
||||||
|
uart1_rts = rts;
|
||||||
|
}
|
||||||
|
|
||||||
void uart1_dtr_init(void)
|
void uart1_dtr_init(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(GPIO_PIN_22, GPIO_OUTPUT_MODE);
|
gpio_set_mode(uart1_dtr, GPIO_OUTPUT_MODE);
|
||||||
}
|
}
|
||||||
void uart1_rts_init(void)
|
void uart1_rts_init(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(GPIO_PIN_21, GPIO_OUTPUT_MODE);
|
gpio_set_mode(uart1_rts, GPIO_OUTPUT_MODE);
|
||||||
}
|
}
|
||||||
void uart1_dtr_deinit(void)
|
void uart1_dtr_deinit(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(GPIO_PIN_22, GPIO_INPUT_MODE);
|
gpio_set_mode(uart1_dtr, GPIO_INPUT_MODE);
|
||||||
}
|
}
|
||||||
void uart1_rts_deinit(void)
|
void uart1_rts_deinit(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(GPIO_PIN_21, GPIO_INPUT_MODE);
|
gpio_set_mode(uart1_rts, GPIO_INPUT_MODE);
|
||||||
}
|
}
|
||||||
void dtr_pin_set(uint8_t status)
|
void dtr_pin_set(uint8_t status)
|
||||||
{
|
{
|
||||||
gpio_write(GPIO_PIN_22, status);
|
gpio_write(uart1_dtr, status);
|
||||||
}
|
}
|
||||||
void rts_pin_set(uint8_t status)
|
void rts_pin_set(uint8_t status)
|
||||||
{
|
{
|
||||||
gpio_write(GPIO_PIN_21, status);
|
gpio_write(uart1_rts, status);
|
||||||
}
|
}
|
||||||
void ringbuffer_lock()
|
void ringbuffer_lock()
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,6 +32,7 @@ extern Ring_Buffer_Type uart1_rx_rb;
|
||||||
|
|
||||||
void uart1_init(void);
|
void uart1_init(void);
|
||||||
void uart1_config(uint32_t baudrate,uart_databits_t databits,uart_parity_t parity,uart_stopbits_t stopbits);
|
void uart1_config(uint32_t baudrate,uart_databits_t databits,uart_parity_t parity,uart_stopbits_t stopbits);
|
||||||
|
void uart1_set_dtr_rts(uint8_t dtr, uint8_t rts);
|
||||||
void uart1_dtr_init(void);
|
void uart1_dtr_init(void);
|
||||||
void uart1_rts_init(void);
|
void uart1_rts_init(void);
|
||||||
void uart1_dtr_deinit(void);
|
void uart1_dtr_deinit(void);
|
||||||
|
|
|
@ -79,6 +79,7 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
|
||||||
}
|
}
|
||||||
int usbd_ep_close(const uint8_t ep)
|
int usbd_ep_close(const uint8_t ep)
|
||||||
{
|
{
|
||||||
|
device_control(usb,DEVICE_CTRL_USB_DC_SET_NACK,(void*)(uint32_t)ep);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int usbd_ep_set_stall(const uint8_t ep)
|
int usbd_ep_set_stall(const uint8_t ep)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue