提交 200c0ff4 编写于 作者: Y yangqingsheng

tflite_micro_person_detection_init

上级 55168d95
#ifndef _DELAY_H
#define _DELAY_H
#include <sys.h>
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//ALIENTEK STM32F429开发板
//使用SysTick的普通计数模式对延迟进行管理(支持ucosii)
//包括delay_us,delay_ms
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//创建日期:2015/6/10
//版本:V1.0
//版权所有,盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
//All rights reserved
//********************************************************************************
//修改说明
//////////////////////////////////////////////////////////////////////////////////
void delay_us(uint32_t nus);
void delay_ms(uint32_t time_ms);
#endif
/*****************************************************************************
* | File : LCD_2IN4_Driver.h
* | Author : Waveshare team
* | Function : LCD driver
* | Info :
*----------------
* | This version: V1.0
* | Date : 2020-07-29
* | Info :
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef __LCD_2IN4_DRIVER_H
#define __LCD_2IN4_DRIVER_H
#include "lcd_Config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LCD_2IN4_WIDTH 240 //LCD width
#define LCD_2IN4_HEIGHT 320 //LCD height
#define LCD_2IN4_CS_0 DEV_Digital_Write(DEV_CS_PIN, 0)
#define LCD_2IN4_CS_1 DEV_Digital_Write(DEV_CS_PIN, 1)
#define LCD_2IN4_RST_0 DEV_Digital_Write(DEV_RST_PIN,0)
#define LCD_2IN4_RST_1 DEV_Digital_Write(DEV_RST_PIN,1)
#define LCD_2IN4_DC_0 DEV_Digital_Write(DEV_DC_PIN, 0)
#define LCD_2IN4_DC_1 DEV_Digital_Write(DEV_DC_PIN, 1)
void LCD_2IN4_Init(void);
void LCD_2IN4_Clear(UWORD Color);
void LCD_2IN4_Display(UWORD *image,int width, int height);
void LCD_2IN4_DrawPaint(UWORD x, UWORD y, UWORD Color);
void LCD_2IN4_SetBackLight(UWORD Value);
void LCD_2IN4_WriteData_Word(UWORD da);
void LCD_2IN4_SetCursor(UWORD X, UWORD Y);
void LCD_2IN4_SetWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend);
void LCD_2IN4_ClearWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,UWORD color);
#ifdef __cplusplus
}
#endif
#endif
/*****************************************************************************
* | File : DEV_Config.h
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V1.0
* | Date : 2018-11-22
* | Info :
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef _DEV_CONFIG_H_
#define _DEV_CONFIG_H_
#include "stm32l4xx_hal.h"
#include <stdint.h>
#include <stdio.h>
#include "spi.h"
#include "tim.h"
#include "main.h"
#define UBYTE uint8_t
#define UWORD uint16_t
#define UDOUBLE uint32_t
/**
* GPIO config
**/
#define DC_Pin GPIO_PIN_12
#define DC_GPIO_Port GPIOB
#define RST_Pin GPIO_PIN_11
#define RST_GPIO_Port GPIOA
#define CS_Pin GPIO_PIN_12
#define CS_GPIO_Port GPIOA
#define DEV_RST_PIN RST_GPIO_Port,RST_Pin //PA11
#define DEV_DC_PIN DC_GPIO_Port,DC_Pin //PB12
#define DEV_CS_PIN CS_GPIO_Port,CS_Pin //PA12
#define DEV_BL_PIN TIM4->CCR1 //PB6
/**
* GPIO read and write
**/
#define DEV_Digital_Write(_pin, _value) HAL_GPIO_WritePin(_pin, _value == 0? GPIO_PIN_RESET:GPIO_PIN_SET)
#define DEV_Digital_Read(_pin) HAL_GPIO_ReadPin(_pin)
/**
* SPI
**/
#define DEV_SPI_WRITE(_dat) DEV_SPI_WRite(_dat);
/**
* delay x ms
**/
#define DEV_Delay_ms(__xms) HAL_Delay(__xms)
/**
* PWM_BL
**/
#define DEV_Set_PWM(_Value) DEV_BL_PIN= _Value
/*-----------------------------------------------------------------------------*/
void DEV_SPI_WRite(UBYTE _dat);
int DEV_Module_Init(void);
void DEV_Module_Exit(void);
#endif
#ifndef _OV2640_H
#define _OV2640_H
#include "sys.h"
#include "sccb.h"
/*
* picture size
*/
#define OV2640_PIXEL_WIDTH ((uint16_t)96)
#define OV2640_PIXEL_HEIGHT ((uint16_t)96)
//#define OV2640_PWDN PGout(9) //POWER DOWN控制信号
//#define OV2640_RST PGout(15) //复位控制信号
void OV2640_PWDN(uint8_t signal);
void OV2640_RST(uint8_t signal);
//////////////////////////////////////////////////////////////////////////////////
#define OV2640_MID 0X7FA2
#define OV2640_PID 0X2642
//当选择DSP地址(0XFF=0X00)时,OV2640的DSP寄存器地址映射表
#define OV2640_DSP_R_BYPASS 0x05
#define OV2640_DSP_Qs 0x44
#define OV2640_DSP_CTRL 0x50
#define OV2640_DSP_HSIZE1 0x51
#define OV2640_DSP_VSIZE1 0x52
#define OV2640_DSP_XOFFL 0x53
#define OV2640_DSP_YOFFL 0x54
#define OV2640_DSP_VHYX 0x55
#define OV2640_DSP_DPRP 0x56
#define OV2640_DSP_TEST 0x57
#define OV2640_DSP_ZMOW 0x5A
#define OV2640_DSP_ZMOH 0x5B
#define OV2640_DSP_ZMHH 0x5C
#define OV2640_DSP_BPADDR 0x7C
#define OV2640_DSP_BPDATA 0x7D
#define OV2640_DSP_CTRL2 0x86
#define OV2640_DSP_CTRL3 0x87
#define OV2640_DSP_SIZEL 0x8C
#define OV2640_DSP_HSIZE2 0xC0
#define OV2640_DSP_VSIZE2 0xC1
#define OV2640_DSP_CTRL0 0xC2
#define OV2640_DSP_CTRL1 0xC3
#define OV2640_DSP_R_DVP_SP 0xD3
#define OV2640_DSP_IMAGE_MODE 0xDA
#define OV2640_DSP_RESET 0xE0
#define OV2640_DSP_MS_SP 0xF0
#define OV2640_DSP_SS_ID 0x7F
#define OV2640_DSP_SS_CTRL 0xF8
#define OV2640_DSP_MC_BIST 0xF9
#define OV2640_DSP_MC_AL 0xFA
#define OV2640_DSP_MC_AH 0xFB
#define OV2640_DSP_MC_D 0xFC
#define OV2640_DSP_P_STATUS 0xFE
#define OV2640_DSP_RA_DLMT 0xFF
//当选择传感器地址(0XFF=0X01)时,OV2640的DSP寄存器地址映射表
#define OV2640_SENSOR_GAIN 0x00
#define OV2640_SENSOR_COM1 0x03
#define OV2640_SENSOR_REG04 0x04
#define OV2640_SENSOR_REG08 0x08
#define OV2640_SENSOR_COM2 0x09
#define OV2640_SENSOR_PIDH 0x0A
#define OV2640_SENSOR_PIDL 0x0B
#define OV2640_SENSOR_COM3 0x0C
#define OV2640_SENSOR_COM4 0x0D
#define OV2640_SENSOR_AEC 0x10
#define OV2640_SENSOR_CLKRC 0x11
#define OV2640_SENSOR_COM7 0x12
#define OV2640_SENSOR_COM8 0x13
#define OV2640_SENSOR_COM9 0x14
#define OV2640_SENSOR_COM10 0x15
#define OV2640_SENSOR_HREFST 0x17
#define OV2640_SENSOR_HREFEND 0x18
#define OV2640_SENSOR_VSTART 0x19
#define OV2640_SENSOR_VEND 0x1A
#define OV2640_SENSOR_MIDH 0x1C
#define OV2640_SENSOR_MIDL 0x1D
#define OV2640_SENSOR_AEW 0x24
#define OV2640_SENSOR_AEB 0x25
#define OV2640_SENSOR_W 0x26
#define OV2640_SENSOR_REG2A 0x2A
#define OV2640_SENSOR_FRARL 0x2B
#define OV2640_SENSOR_ADDVSL 0x2D
#define OV2640_SENSOR_ADDVHS 0x2E
#define OV2640_SENSOR_YAVG 0x2F
#define OV2640_SENSOR_REG32 0x32
#define OV2640_SENSOR_ARCOM2 0x34
#define OV2640_SENSOR_REG45 0x45
#define OV2640_SENSOR_FLL 0x46
#define OV2640_SENSOR_FLH 0x47
#define OV2640_SENSOR_COM19 0x48
#define OV2640_SENSOR_ZOOMS 0x49
#define OV2640_SENSOR_COM22 0x4B
#define OV2640_SENSOR_COM25 0x4E
#define OV2640_SENSOR_BD50 0x4F
#define OV2640_SENSOR_BD60 0x50
#define OV2640_SENSOR_REG5D 0x5D
#define OV2640_SENSOR_REG5E 0x5E
#define OV2640_SENSOR_REG5F 0x5F
#define OV2640_SENSOR_REG60 0x60
#define OV2640_SENSOR_HISTO_LOW 0x61
#define OV2640_SENSOR_HISTO_HIGH 0x62
uint8_t OV2640_Init(void);
void OV2640_JPEG_Mode(void);
void OV2640_RGB565_Mode(void);
void OV2640_Auto_Exposure(uint8_t level);
void OV2640_Light_Mode(uint8_t mode);
void OV2640_Color_Saturation(uint8_t sat);
void OV2640_Brightness(uint8_t bright);
void OV2640_Contrast(uint8_t contrast);
void OV2640_Special_Effects(uint8_t eft);
void OV2640_Color_Bar(uint8_t sw);
void OV2640_Window_Set(uint16_t sx,uint16_t sy,uint16_t width,uint16_t height);
uint8_t OV2640_OutSize_Set(uint16_t width,uint16_t height);
uint8_t OV2640_ImageWin_Set(uint16_t offx,uint16_t offy,uint16_t width,uint16_t height);
uint8_t OV2640_ImageSize_Set(uint16_t width,uint16_t height);
#endif
#ifndef _OV2640CFG_H
#define _OV2640CFG_H
#include "ov2640.h"
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//ALIENTEK STM32F407开发板
//OV2640 驱动代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//创建日期:2014/5/14
//版本:V1.0
//版权所有,盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//OV2640 SXGA初始化寄存器序列表
//此模式下帧率为15帧
//SXGA(1600*1200)
const uint8_t ov2640_sxga_init_reg_tbl[][2]=
{
0xff, 0x00,
0x2c, 0xff,
0x2e, 0xdf,
0xff, 0x01,
0x3c, 0x32,
//
0x11, 0x00,
0x09, 0x02,
0x04, 0xD8,//水平镜像,垂直翻转
0x13, 0xe5,
0x14, 0x48,
0x2c, 0x0c,
0x33, 0x78,
0x3a, 0x33,
0x3b, 0xfB,
//
0x3e, 0x00,
0x43, 0x11,
0x16, 0x10,
//
0x39, 0x92,
//
0x35, 0xda,
0x22, 0x1a,
0x37, 0xc3,
0x23, 0x00,
0x34, 0xc0,
0x36, 0x1a,
0x06, 0x88,
0x07, 0xc0,
0x0d, 0x87,
0x0e, 0x41,
0x4c, 0x00,
0x48, 0x00,
0x5B, 0x00,
0x42, 0x03,
//
0x4a, 0x81,
0x21, 0x99,
//
0x24, 0x40,
0x25, 0x38,
0x26, 0x82,
0x5c, 0x00,
0x63, 0x00,
0x46, 0x00,
0x0c, 0x3c,
//
0x61, 0x70,
0x62, 0x80,
0x7c, 0x05,
//
0x20, 0x80,
0x28, 0x30,
0x6c, 0x00,
0x6d, 0x80,
0x6e, 0x00,
0x70, 0x02,
0x71, 0x94,
0x73, 0xc1,
0x3d, 0x34,
0x5a, 0x57,
//
0x12, 0x00,//UXGA 1600*1200
0x17, 0x11,
0x18, 0x75,
0x19, 0x01,
0x1a, 0x97,
0x32, 0x36,
0x03, 0x0f,
0x37, 0x40,
//
0x4f, 0xca,
0x50, 0xa8,
0x5a, 0x23,
0x6d, 0x00,
0x6d, 0x38,
//
0xff, 0x00,
0xe5, 0x7f,
0xf9, 0xc0,
0x41, 0x24,
0xe0, 0x14,
0x76, 0xff,
0x33, 0xa0,
0x42, 0x20,
0x43, 0x18,
0x4c, 0x00,
0x87, 0xd5,
0x88, 0x3f,
0xd7, 0x03,
0xd9, 0x10,
0xd3, 0x82,
//
0xc8, 0x08,
0xc9, 0x80,
//
0x7c, 0x00,
0x7d, 0x00,
0x7c, 0x03,
0x7d, 0x48,
0x7d, 0x48,
0x7c, 0x08,
0x7d, 0x20,
0x7d, 0x10,
0x7d, 0x0e,
//
0x90, 0x00,
0x91, 0x0e,
0x91, 0x1a,
0x91, 0x31,
0x91, 0x5a,
0x91, 0x69,
0x91, 0x75,
0x91, 0x7e,
0x91, 0x88,
0x91, 0x8f,
0x91, 0x96,
0x91, 0xa3,
0x91, 0xaf,
0x91, 0xc4,
0x91, 0xd7,
0x91, 0xe8,
0x91, 0x20,
//
0x92, 0x00,
0x93, 0x06,
0x93, 0xe3,
0x93, 0x05,
0x93, 0x05,
0x93, 0x00,
0x93, 0x04,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
//
0x96, 0x00,
0x97, 0x08,
0x97, 0x19,
0x97, 0x02,
0x97, 0x0c,
0x97, 0x24,
0x97, 0x30,
0x97, 0x28,
0x97, 0x26,
0x97, 0x02,
0x97, 0x98,
0x97, 0x80,
0x97, 0x00,
0x97, 0x00,
//
0xc3, 0xef,
0xa4, 0x00,
0xa8, 0x00,
0xc5, 0x11,
0xc6, 0x51,
0xbf, 0x80,
0xc7, 0x10,
0xb6, 0x66,
0xb8, 0xA5,
0xb7, 0x64,
0xb9, 0x7C,
0xb3, 0xaf,
0xb4, 0x97,
0xb5, 0xFF,
0xb0, 0xC5,
0xb1, 0x94,
0xb2, 0x0f,
0xc4, 0x5c,
//
0xc0, 0xc8,
0xc1, 0x96,
0x8c, 0x00,
0x86, 0x3d,
0x50, 0x00,
0x51, 0x90,
0x52, 0x2c,
0x53, 0x00,
0x54, 0x00,
0x55, 0x88,
0x5a, 0x90,
0x5b, 0x2C,
0x5c, 0x05,
0xd3, 0x02,//auto设置要小心
//
0xc3, 0xed,
0x7f, 0x00,
0xda, 0x09,
0xe5, 0x1f,
0xe1, 0x67,
0xe0, 0x00,
0xdd, 0x7f,
0x05, 0x00,
};
//OV2640 SVGA初始化寄存器序列表
//此模式下,帧率可以达到30帧
//SVGA 800*600
const uint8_t ov2640_svga_init_reg_tbl[][2]=
{
0xff, 0x00,
0x2c, 0xff,
0x2e, 0xdf,
0xff, 0x01,
0x3c, 0x32,
//
0x11, 0x00,
0x09, 0x02,
0x04, 0xD8,//水平镜像,垂直翻转
0x13, 0xe5,
0x14, 0x48,
0x2c, 0x0c,
0x33, 0x78,
0x3a, 0x33,
0x3b, 0xfB,
//
0x3e, 0x00,
0x43, 0x11,
0x16, 0x10,
//
0x39, 0x92,
//
0x35, 0xda,
0x22, 0x1a,
0x37, 0xc3,
0x23, 0x00,
0x34, 0xc0,
0x36, 0x1a,
0x06, 0x88,
0x07, 0xc0,
0x0d, 0x87,
0x0e, 0x41,
0x4c, 0x00,
0x48, 0x00,
0x5B, 0x00,
0x42, 0x03,
//
0x4a, 0x81,
0x21, 0x99,
//
0x24, 0x40,
0x25, 0x38,
0x26, 0x82,
0x5c, 0x00,
0x63, 0x00,
0x46, 0x22,
0x0c, 0x3c,
//
0x61, 0x70,
0x62, 0x80,
0x7c, 0x05,
//
0x20, 0x80,
0x28, 0x30,
0x6c, 0x00,
0x6d, 0x80,
0x6e, 0x00,
0x70, 0x02,
0x71, 0x94,
0x73, 0xc1,
0x3d, 0x34,
0x5a, 0x57,
//根据分辨率不同而设置
0x12, 0x40,//SVGA 800*600
0x17, 0x11,
0x18, 0x43,
0x19, 0x00,
0x1a, 0x4b,
0x32, 0x09,
0x37, 0xc0,
//
0x4f, 0xca,
0x50, 0xa8,
0x5a, 0x23,
0x6d, 0x00,
0x3d, 0x38,
//
0xff, 0x00,
0xe5, 0x7f,
0xf9, 0xc0,
0x41, 0x24,
0xe0, 0x14,
0x76, 0xff,
0x33, 0xa0,
0x42, 0x20,
0x43, 0x18,
0x4c, 0x00,
0x87, 0xd5,
0x88, 0x3f,
0xd7, 0x03,
0xd9, 0x10,
0xd3, 0x82,
//
0xc8, 0x08,
0xc9, 0x80,
//
0x7c, 0x00,
0x7d, 0x00,
0x7c, 0x03,
0x7d, 0x48,
0x7d, 0x48,
0x7c, 0x08,
0x7d, 0x20,
0x7d, 0x10,
0x7d, 0x0e,
//
0x90, 0x00,
0x91, 0x0e,
0x91, 0x1a,
0x91, 0x31,
0x91, 0x5a,
0x91, 0x69,
0x91, 0x75,
0x91, 0x7e,
0x91, 0x88,
0x91, 0x8f,
0x91, 0x96,
0x91, 0xa3,
0x91, 0xaf,
0x91, 0xc4,
0x91, 0xd7,
0x91, 0xe8,
0x91, 0x20,
//
0x92, 0x00,
0x93, 0x06,
0x93, 0xe3,
0x93, 0x05,
0x93, 0x05,
0x93, 0x00,
0x93, 0x04,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
//
0x96, 0x00,
0x97, 0x08,
0x97, 0x19,
0x97, 0x02,
0x97, 0x0c,
0x97, 0x24,
0x97, 0x30,
0x97, 0x28,
0x97, 0x26,
0x97, 0x02,
0x97, 0x98,
0x97, 0x80,
0x97, 0x00,
0x97, 0x00,
//
0xc3, 0xed,
0xa4, 0x00,
0xa8, 0x00,
0xc5, 0x11,
0xc6, 0x51,
0xbf, 0x80,
0xc7, 0x10,
0xb6, 0x66,
0xb8, 0xA5,
0xb7, 0x64,
0xb9, 0x7C,
0xb3, 0xaf,
0xb4, 0x97,
0xb5, 0xFF,
0xb0, 0xC5,
0xb1, 0x94,
0xb2, 0x0f,
0xc4, 0x5c,
//根据分辨率不同而设置
0xc0, 0x64,
0xc1, 0x4B,
0x8c, 0x00,
0x86, 0x3D,
0x50, 0x00,
0x51, 0xC8,
0x52, 0x96,
0x53, 0x00,
0x54, 0x00,
0x55, 0x00,
0x5a, 0xC8,
0x5b, 0x96,
0x5c, 0x00,
0xd3, 0x02,//auto设置要小心
//
0xc3, 0xed,
0x7f, 0x00,
0xda, 0x09,
0xe5, 0x1f,
0xe1, 0x67,
0xe0, 0x00,
0xdd, 0x7f,
0x05, 0x00,
};
const uint8_t ov2640_jpeg_reg_tbl[][2]=
{
0xff, 0x01,
0xe0, 0x14,
0xe1, 0x77,
0xe5, 0x1f,
0xd7, 0x03,
0xda, 0x10,
0xe0, 0x00,
};
const uint8_t ov2640_rgb565_reg_tbl[][2]=
{
0xFF, 0x00,
0xDA, 0x09,
0xD7, 0x03,
0xDF, 0x02,
0x33, 0xa0,
0x3C, 0x00,
0xe1, 0x67,
0xff, 0x01,
0xe0, 0x00,
0xe1, 0x00,
0xe5, 0x00,
0xd7, 0x00,
0xda, 0x00,
0xe0, 0x00,
};
const uint8_t ov2640_yuv422_reg_tbl[][2]=
{
0xFF, 0x00,
0xDA, 0x10,
0xD7, 0x03,
0xDF, 0x00,
0x33, 0x80,
0x3C, 0x40,
0xe1, 0x77,
0x00, 0x00,
};
#endif
#ifndef __SCCB_H
#define __SCCB_H
#include "sys.h"
#include "gpio.h"
//IO操作函数
#define SCCB_SDA_IN() {GPIOB->MODER&=~(3<<(5*2));GPIOB->MODER|=0<<5*2;} //PD7 输入
#define SCCB_SDA_OUT() {GPIOB->MODER&=~(3<<(5*2));GPIOB->MODER|=1<<5*2;} //PD7 输出
#define SCCB_ID 0X60 //OV2640的ID
//IO方向设置
#define SCCB_SDA_IN() {GPIOB->MODER&=~(3<<(5*2));GPIOB->MODER|=0<<5*2;} //PD7 输入
#define SCCB_SDA_OUT() {GPIOB->MODER&=~(3<<(5*2));GPIOB->MODER|=1<<5*2;} //PD7 输出
#define SCCB_ID 0X60 //OV2640的ID
void SCCB_Init(void);
void SCCB_Start(void);
void SCCB_Stop(void);
void SCCB_No_Ack(void);
uint8_t SCCB_WR_Byte(uint8_t dat);
uint8_t SCCB_RD_Byte(void);
uint8_t SCCB_WR_Reg(uint8_t reg,uint8_t data);
uint8_t SCCB_RD_Reg(uint8_t reg);
void SCCB_SCL(uint8_t sccb_scl);
void SCCB_SDA(uint8_t sccb_sda);
uint8_t SCCB_READ_SDA(void);
#endif
#include "delay.h"
#include "sys.h"
#ifdef __cplusplus
extern "C" {
#endif
void delay_us(uint32_t time_us) {
uint32_t clk = 80; // CPU 80MHz
uint32_t ticks = time_us * clk; // time is us
uint32_t told = SysTick->VAL;
uint32_t tnow = told;
uint32_t tcnt = 0;
for(; tcnt<ticks; tnow=SysTick->VAL)
{
if(tnow != told) {
if(tnow < told) {
tcnt += told - tnow;
} else {
tcnt += SysTick->LOAD-tnow + told;
} told = tnow;
}
}
}
void delay_ms(uint32_t time_ms) {
uint32_t clk = 80; // CPU 80MHz
uint32_t ticks = time_ms * clk * 1000; // time is ms
uint32_t told = SysTick->VAL;
uint32_t tnow = told;
uint32_t tcnt = 0;
for(; tcnt<ticks; tnow=SysTick->VAL)
{
if(tnow != told) {
if(tnow < told) {
tcnt += told - tnow;
} else {
tcnt += SysTick->LOAD-tnow + told;
} told = tnow;
}
}
}
#ifdef __cplusplus
}
#endif
#include "lcd_2inch4.h"
#include <string.h>
/*******************************************************************************
function:
Hardware reset
*******************************************************************************/
static void LCD_2IN4_Reset(void)
{
LCD_2IN4_RST_1;
DEV_Delay_ms(100);
LCD_2IN4_RST_0;
DEV_Delay_ms(100);
LCD_2IN4_RST_1;
DEV_Delay_ms(100);
}
/*******************************************************************************
function:
Write data and commands
*******************************************************************************/
static void LCD_2IN4_Write_Command(UBYTE data)
{
LCD_2IN4_CS_0;
LCD_2IN4_DC_0;
DEV_SPI_WRITE(data);
}
static void LCD_2IN4_WriteData_Byte(UBYTE data)
{
LCD_2IN4_CS_0;
LCD_2IN4_DC_1;
DEV_SPI_WRITE(data);
LCD_2IN4_CS_1;
}
void LCD_2IN4_WriteData_Word(UWORD data)
{
LCD_2IN4_CS_0;
LCD_2IN4_DC_1;
DEV_SPI_WRITE((data>>8) & 0xff);
DEV_SPI_WRITE(data);
LCD_2IN4_CS_1;
}
/******************************************************************************
function:
Common register initialization
******************************************************************************/
void LCD_2IN4_Init(void)
{
LCD_2IN4_Reset();
LCD_2IN4_SetBackLight(500);//򿪱
HAL_Delay(100);
//************* Start Initial Sequence **********//
LCD_2IN4_Write_Command(0x11); //Sleep out
HAL_Delay(120); //Delay 120ms
//************* Start Initial Sequence **********//
LCD_2IN4_Write_Command(0xCF);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_WriteData_Byte(0xC1);
LCD_2IN4_WriteData_Byte(0X30);
LCD_2IN4_Write_Command(0xED);
LCD_2IN4_WriteData_Byte(0x64);
LCD_2IN4_WriteData_Byte(0x03);
LCD_2IN4_WriteData_Byte(0X12);
LCD_2IN4_WriteData_Byte(0X81);
LCD_2IN4_Write_Command(0xE8);
LCD_2IN4_WriteData_Byte(0x85);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_WriteData_Byte(0x79);
LCD_2IN4_Write_Command(0xCB);
LCD_2IN4_WriteData_Byte(0x39);
LCD_2IN4_WriteData_Byte(0x2C);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_WriteData_Byte(0x34);
LCD_2IN4_WriteData_Byte(0x02);
LCD_2IN4_Write_Command(0xF7);
LCD_2IN4_WriteData_Byte(0x20);
LCD_2IN4_Write_Command(0xEA);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_Write_Command(0xC0); //Power control
LCD_2IN4_WriteData_Byte(0x1D); //VRH[5:0]
LCD_2IN4_Write_Command(0xC1); //Power control
LCD_2IN4_WriteData_Byte(0x12); //SAP[2:0];BT[3:0]
LCD_2IN4_Write_Command(0xC5); //VCM control
LCD_2IN4_WriteData_Byte(0x33);
LCD_2IN4_WriteData_Byte(0x3F);
LCD_2IN4_Write_Command(0xC7); //VCM control
LCD_2IN4_WriteData_Byte(0x92);
LCD_2IN4_Write_Command(0x3A); // Memory Access Control
LCD_2IN4_WriteData_Byte(0x55);
LCD_2IN4_Write_Command(0x36); // Memory Access Control
LCD_2IN4_WriteData_Byte(0x08);
LCD_2IN4_Write_Command(0xB1);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_WriteData_Byte(0x12);
LCD_2IN4_Write_Command(0xB6); // Display Function Control
LCD_2IN4_WriteData_Byte(0x0A);
LCD_2IN4_WriteData_Byte(0xA2);
LCD_2IN4_Write_Command(0x44);
LCD_2IN4_WriteData_Byte(0x02);
LCD_2IN4_Write_Command(0xF2); // 3Gamma Function Disable
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_Write_Command(0x26); //Gamma curve selected
LCD_2IN4_WriteData_Byte(0x01);
LCD_2IN4_Write_Command(0xE0); //Set Gamma
LCD_2IN4_WriteData_Byte(0x0F);
LCD_2IN4_WriteData_Byte(0x22);
LCD_2IN4_WriteData_Byte(0x1C);
LCD_2IN4_WriteData_Byte(0x1B);
LCD_2IN4_WriteData_Byte(0x08);
LCD_2IN4_WriteData_Byte(0x0F);
LCD_2IN4_WriteData_Byte(0x48);
LCD_2IN4_WriteData_Byte(0xB8);
LCD_2IN4_WriteData_Byte(0x34);
LCD_2IN4_WriteData_Byte(0x05);
LCD_2IN4_WriteData_Byte(0x0C);
LCD_2IN4_WriteData_Byte(0x09);
LCD_2IN4_WriteData_Byte(0x0F);
LCD_2IN4_WriteData_Byte(0x07);
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_Write_Command(0XE1); //Set Gamma
LCD_2IN4_WriteData_Byte(0x00);
LCD_2IN4_WriteData_Byte(0x23);
LCD_2IN4_WriteData_Byte(0x24);
LCD_2IN4_WriteData_Byte(0x07);
LCD_2IN4_WriteData_Byte(0x10);
LCD_2IN4_WriteData_Byte(0x07);
LCD_2IN4_WriteData_Byte(0x38);
LCD_2IN4_WriteData_Byte(0x47);
LCD_2IN4_WriteData_Byte(0x4B);
LCD_2IN4_WriteData_Byte(0x0A);
LCD_2IN4_WriteData_Byte(0x13);
LCD_2IN4_WriteData_Byte(0x06);
LCD_2IN4_WriteData_Byte(0x30);
LCD_2IN4_WriteData_Byte(0x38);
LCD_2IN4_WriteData_Byte(0x0F);
LCD_2IN4_Write_Command(0x29); //Display on
}
/******************************************************************************
function: Set the cursor position
parameter :
Xstart: Start UWORD x coordinate
Ystart: Start UWORD y coordinate
Xend : End UWORD coordinates
Yend : End UWORD coordinatesen
******************************************************************************/
void LCD_2IN4_SetWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
{
LCD_2IN4_Write_Command(0x2a);
LCD_2IN4_WriteData_Byte(Xstart >>8);
LCD_2IN4_WriteData_Byte(Xstart & 0xff);
LCD_2IN4_WriteData_Byte((Xend - 1) >> 8);
LCD_2IN4_WriteData_Byte((Xend - 1) & 0xff);
LCD_2IN4_Write_Command(0x2b);
LCD_2IN4_WriteData_Byte(Ystart >>8);
LCD_2IN4_WriteData_Byte(Ystart & 0xff);
LCD_2IN4_WriteData_Byte((Yend - 1) >> 8);
LCD_2IN4_WriteData_Byte((Yend - 1) & 0xff);
LCD_2IN4_Write_Command(0x2C);
}
/******************************************************************************
function: Settings window
parameter :
Xstart: Start UWORD x coordinate
Ystart: Start UWORD y coordinate
******************************************************************************/
void LCD_2IN4_SetCursor(UWORD X, UWORD Y)
{
LCD_2IN4_Write_Command(0x2a);
LCD_2IN4_WriteData_Byte(X >> 8);
LCD_2IN4_WriteData_Byte(X);
LCD_2IN4_WriteData_Byte(X >> 8);
LCD_2IN4_WriteData_Byte(X);
LCD_2IN4_Write_Command(0x2b);
LCD_2IN4_WriteData_Byte(Y >> 8);
LCD_2IN4_WriteData_Byte(Y);
LCD_2IN4_WriteData_Byte(Y >> 8);
LCD_2IN4_WriteData_Byte(Y);
LCD_2IN4_Write_Command(0x2C);
}
/******************************************************************************
function: Clear screen function, refresh the screen to a certain color
parameter :
Color : The color you want to clear all the screen
******************************************************************************/
void LCD_2IN4_Clear(UWORD Color)
{
UWORD i,j;
LCD_2IN4_SetWindow(0, 0, LCD_2IN4_WIDTH, LCD_2IN4_HEIGHT);
DEV_Digital_Write(DEV_DC_PIN, 1);
for(i = 0; i < LCD_2IN4_WIDTH; i++){
for(j = 0; j < LCD_2IN4_HEIGHT; j++){
LCD_2IN4_WriteData_Word(Color);
}
}
}
/******************************************************************************
function: Refresh a certain area to the same color
parameter :
Xstart: Start UWORD x coordinate
Ystart: Start UWORD y coordinate
Xend : End UWORD coordinates
Yend : End UWORD coordinates
color : Set the color
******************************************************************************/
void LCD_2IN4_ClearWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,UWORD color)
{
UWORD i,j;
LCD_2IN4_SetWindow(Xstart, Ystart, Xend,Yend);
for(i = Ystart; i <= Yend; i++){
for(j = Xstart; j <= Xend; j++){
LCD_2IN4_WriteData_Word(color);
}
}
}
/******************************************************************************
function: Show a picture
parameter :
image: Picture buffer
******************************************************************************/
void LCD_2IN4_Display(UWORD *image,int width, int height)
{
UWORD i,j;
if(width > LCD_2IN4_WIDTH || height > LCD_2IN4_HEIGHT){
printf("Picture size out of range!\r\n");
return;
}
LCD_2IN4_SetWindow(0, 0, width, height);
DEV_Digital_Write(DEV_DC_PIN, 1);
for(i = 0; i < width; i++){
for(j = 0; j < height; j++){
LCD_2IN4_WriteData_Word(*(image+i*height+j));
}
}
}
/******************************************************************************
function: Draw a point
parameter :
X : Set the X coordinate
Y : Set the Y coordinate
Color : Set the color
******************************************************************************/
void LCD_2IN4_DrawPaint(UWORD x, UWORD y, UWORD Color)
{
LCD_2IN4_SetCursor(x, y);
LCD_2IN4_WriteData_Word(Color);
}
/*******************************************************************************
function:
Setting backlight
parameter :
value : Range 0~1000 Duty cycle is value/1000
*******************************************************************************/
void LCD_2IN4_SetBackLight(UWORD Value)
{
DEV_Set_PWM(Value);
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/**
******************************************************************************
* File Name : gpio.h
* Description : This file contains all the functions prototypes for
* the gpio
* Description : This file contains all the functions prototypes for
* the gpio
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
......
此差异已折叠。
......@@ -8,8 +8,14 @@
#include "stm32l4xx_hal.h"
#include "usart.h"
#include "gpio.h"
#include "dcmi.h"
#include "dma.h"
#include "i2c.h"
#include "spi.h"
#include "tim.h"
#include "ov2640.h"
#include "lcd_2inch4.h"
#include "tos_k.h"
void board_init(void);
void SystemClock_Config(void);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册