149 lines
2.2 KiB
C
149 lines
2.2 KiB
C
/*
|
|
* main_task.c
|
|
*
|
|
* Created on: Mar 31, 2023
|
|
* Author: gxms0
|
|
*/
|
|
|
|
/* Global include */
|
|
|
|
#include "drv_i2c.h"
|
|
#include "drv_tim.h"
|
|
#include "drv_adc.h"
|
|
#include "drv_led.h"
|
|
#include "drv_key.h"
|
|
#include "drv_uart.h"
|
|
|
|
|
|
#include "pmw3901.h"
|
|
#include "at24cxx.h"
|
|
#include "mpu6500.h"
|
|
#include "qmc5883l.h"
|
|
#include "bmp280.h"
|
|
|
|
/* Global typedef */
|
|
|
|
/* Global define */
|
|
|
|
/* Global Variable */
|
|
AT24C_t at24c;
|
|
|
|
MPU_t mpu6500;
|
|
QMC_t qmc5883;
|
|
BMP_t bmp280;
|
|
|
|
|
|
|
|
uint8_t Red_Count = 0;
|
|
uint8_t Green_Count = 0;
|
|
uint8_t Blue_Count = 0;
|
|
|
|
uint8_t tx[20] = "123467890asdfghjklq";
|
|
uint8_t rx[150] = {0};
|
|
|
|
|
|
|
|
#include "main_task.h"
|
|
|
|
|
|
|
|
//硬件初始化
|
|
void bsp_init()
|
|
{
|
|
//外设初始化
|
|
led_init();
|
|
tim_init();
|
|
adc_init();
|
|
key_init();
|
|
|
|
usart_init();
|
|
i2c_init();
|
|
|
|
//设备初始化
|
|
pmw3901_init();
|
|
|
|
at24cxx_init(&at24c,&i2c2,AT24CXX_ADDR);
|
|
|
|
//读取设置参数
|
|
at24xcc_read(&at24c, 0x00,rx, sizeof(tx));
|
|
|
|
|
|
|
|
//传感器初始化
|
|
mpu6xxx_init(&mpu6500,&i2c1,MPU6500_ADDR);
|
|
qmcxxx_init(&qmc5883,&i2c1,QMC5883_ADDR);
|
|
bmpxxx_init(&bmp280,&i2c1,BMP280_ADDR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//主循环
|
|
void main_loop()
|
|
{
|
|
uint32_t tick = 0;
|
|
|
|
tick = get_ticks();
|
|
|
|
while(1)
|
|
{
|
|
delay_ms(5);
|
|
tick = get_ticks();
|
|
|
|
adc_thread(tick);
|
|
key_thread();
|
|
|
|
/*
|
|
size_t len = usart_read(&uart3, rx, sizeof(rx));
|
|
|
|
if (len) {
|
|
usart_write(&uart1, rx, len);
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
pmw3901_thread();
|
|
|
|
|
|
//printf( "pmw3901 %f,%f,%f,%d\r\n",pmw3901_1.dx,pmw3901_1.dy,pmw3901_1.dz,pmw3901_1.quality);
|
|
//printf("keys:%d,%d,%d,%d\n",keys[0],keys[1],keys[2],keys[3]);
|
|
printf("keys:%d,%d,%d,%d\tadc:%4.4f,%4.4f,%4.4f,%4.4f\t tick:%u\n",key1.state,key2.state,key3.state,key4.state, voltage.Voltage[0],voltage.Voltage[1],voltage.Voltage[2],voltage.Voltage[3],tick);
|
|
|
|
Red_Count += 1;
|
|
Green_Count += 1;
|
|
Blue_Count += 1;
|
|
|
|
if(Red_Count % 2){
|
|
led_setToggle(0);
|
|
|
|
led_setToggle(3);
|
|
led_setToggle(4);
|
|
led_setToggle(5);
|
|
led_setToggle(6);
|
|
}
|
|
|
|
if(Green_Count % 3){
|
|
led_setToggle(1);
|
|
}
|
|
|
|
if(Blue_Count % 5){
|
|
led_setToggle(2);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|