diff --git a/.eide/eide.json b/.eide/eide.json index b4e7241..a9a788f 100644 --- a/.eide/eide.json +++ b/.eide/eide.json @@ -1,5 +1,5 @@ { - "name": "violet_firmware_zf", + "name": "firmware_clover", "type": "RISC-V", "dependenceList": [], "srcDirs": [ @@ -7,8 +7,7 @@ "libraries/sdk", "libraries/zf_common", "libraries/zf_device", - "libraries/zf_driver", - "3rd-lib/PID-Library" + "libraries/zf_driver" ], "virtualFolder": { "name": "", diff --git a/.vscode/launch.json b/.vscode/launch.json index a467a37..a02ddac 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ "request": "launch", "name": "openocd", "servertype": "openocd", - "executable": "build\\Debug\\violet_firmware_zf.elf", + "executable": "build\\Debug\\firmware_clover.elf", "runToEntryPoint": "main", "configFiles": [ "${workspaceFolder}/tools/wch-riscv.cfg" diff --git a/3rd-lib/PID-Library/LICENSE b/3rd-lib/PID-Library/LICENSE deleted file mode 100644 index 4fbde9a..0000000 --- a/3rd-lib/PID-Library/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Majid Derhambakhsh - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation 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 -furnished 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 FOR 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. diff --git a/3rd-lib/PID-Library/README.md b/3rd-lib/PID-Library/README.md deleted file mode 100644 index 78a691c..0000000 --- a/3rd-lib/PID-Library/README.md +++ /dev/null @@ -1,164 +0,0 @@ -![Banner](Banner.png) - -# PID-Library (C Version) -PID Controller library for ARM Cortex M (STM32) - -> #### Download Arduino Library : [Arduino-PID-Library](https://github.com/br3ttb/Arduino-PID-Library) - -## Release -- #### Version : 1.0.0 - -- #### Type : Embedded Software. - -- #### Support : - - ARM STM32 series - -- #### Program Language : C/C++ - -- #### Properties : - -- #### Changes : - -- #### Required Library/Driver : - - -## Overview -### Initialization and de-initialization functions: -```c++ -void PID(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection); -void PID2(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDCD_TypeDef ControllerDirection); -``` - -### Operation functions: -```c++ -/* ::::::::::: Computing ::::::::::: */ -uint8_t PID_Compute(PID_TypeDef *uPID); - -/* ::::::::::: PID Mode :::::::::::: */ -void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode); -PIDMode_TypeDef PID_GetMode(PID_TypeDef *uPID); - -/* :::::::::: PID Limits ::::::::::: */ -void PID_SetOutputLimits(PID_TypeDef *uPID, float Min, float Max); - -/* :::::::::: PID Tunings :::::::::: */ -void PID_SetTunings(PID_TypeDef *uPID, float Kp, float Ki, float Kd); -void PID_SetTunings2(PID_TypeDef *uPID, float Kp, float Ki, float Kd, PIDPON_TypeDef POn); - -/* ::::::::: PID Direction ::::::::: */ -void PID_SetControllerDirection(PID_TypeDef *uPID, PIDCD_TypeDef Direction); -PIDCD_TypeDef PID_GetDirection(PID_TypeDef *uPID); - -/* ::::::::: PID Sampling :::::::::: */ -void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime); - -/* ::::::: Get Tunings Param ::::::: */ -float PID_GetKp(PID_TypeDef *uPID); -float PID_GetKi(PID_TypeDef *uPID); -float PID_GetKd(PID_TypeDef *uPID); -``` - -### Macros: -```diff -non -``` - -## Guide - -#### This library can be used as follows: -#### 1. Add pid.h header -#### 2. Create PID struct and initialize it, for example: -* Initializer: - ```c++ - PID(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection); - ``` -* Parameters: - * uPID : Pointer to pid struct - * Input : The variable we're trying to control (float) - * Output : The variable that will be adjusted by the pid (float) - * Setpoint : The value we want to Input to maintain (float) - * Kp,Ki,Kd : Tuning Parameters. these affect how the pid will change the output (float>=0) - * POn : Either P_ON_E (Default) or P_ON_M. Allows Proportional on Measurement to be specified. - * ControllerDirection : Either DIRECT or REVERSE. determines which direction the output will move when faced with a given error. DIRECT is most common - - -* Example: - ```c++ - PID_TypeDef TPID; - - float Temp, PIDOut, TempSetpoint; - - PID(&TPID, &Temp, &PIDOut, &TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT); - ``` -#### 3. Set 'mode', 'sample time' and 'output limit', for example: -* Functions: - ```c++ - void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode); - void PID_SetOutputLimits(PID_TypeDef *uPID, float Min, float Max); - void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime); - ``` -* Parameters: - * uPID : Pointer to pid struct - * Mode : _PID_MODE_AUTOMATIC or _PID_MODE_MANUAL - * Min : Low end of the range. must be < max (float) - * Max : High end of the range. must be > min (float) - * NewSampleTime : How often, in milliseconds, the PID will be evaluated. (int>0) - -* Example: - ```c++ - PID_SetMode(&TPID, _PID_MODE_AUTOMATIC); - PID_SetSampleTime(&TPID, 500); - PID_SetOutputLimits(&TPID, 1, 100); - ``` - -#### 4. Using Compute function, for example: - -```c++ -PID_Compute(&TPID); -``` - -## Examples - -#### Example 1: PID Compute for temperature -```c++ -#include "main.h" -#include "pid.h" - -PID_TypeDef TPID; - -char OutBuf[50]; -float Temp, PIDOut, TempSetpoint; - -int main(void) -{ - - HW_Init(); - - PID(&TPID, &Temp, &PIDOut, &TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT); - - PID_SetMode(&TPID, _PID_MODE_AUTOMATIC); - PID_SetSampleTime(&TPID, 500); - PID_SetOutputLimits(&TPID, 1, 100); - - while (1) - { - - Temp = GetTemp(); - PID_Compute(&TPID); - - sprintf(OutBuf, "Temp%3.2f : %u\n", Temp, (uint16_t)PIDOut); - UART_Transmit((uint8_t *)OutBuf, strlen(OutBuf)); - - Delay_ms(500); - - } -} - -``` - -## Tests performed: -- [x] Run on STM32 Fx cores - -## Developers: -- ### Majid Derhambakhsh - diff --git a/3rd-lib/PID-Library/pid.c b/3rd-lib/PID-Library/pid.c deleted file mode 100644 index 650e38a..0000000 --- a/3rd-lib/PID-Library/pid.c +++ /dev/null @@ -1,293 +0,0 @@ - /* ------------------------------------------------------------------------------- -~ File : pid.c -~ Author : Majid Derhambakhsh -~ Version: V1.0.0 -~ Created: 02/11/2021 03:43:00 AM -~ Brief : -~ Support: - E-Mail : Majid.do16@gmail.com (subject : Embedded Library Support) - - Github : https://github.com/Majid-Derhambakhsh ------------------------------------------------------------------------------- -~ Description: - -~ Attention : - -~ Changes : ------------------------------------------------------------------------------- -*/ - -#include "pid.h" - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ~~~~~~~~~~~~~~~~~ Initialize ~~~~~~~~~~~~~~~~ */ -void PID_Init(PID_TypeDef *uPID) -{ - /* ~~~~~~~~~~ Set parameter ~~~~~~~~~~ */ - uPID->OutputSum = *uPID->MyOutput; - uPID->LastInput = *uPID->MyInput; - - if (uPID->OutputSum > uPID->OutMax) - { - uPID->OutputSum = uPID->OutMax; - } - else if (uPID->OutputSum < uPID->OutMin) - { - uPID->OutputSum = uPID->OutMin; - } - - -} - -void PID(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection) -{ - /* ~~~~~~~~~~ Set parameter ~~~~~~~~~~ */ - uPID->MyOutput = Output; - uPID->MyInput = Input; - uPID->MySetpoint = Setpoint; - uPID->InAuto = (PIDMode_TypeDef)_FALSE; - - PID_SetOutputLimits(uPID, 0, _PID_8BIT_PWM_MAX); - - uPID->SampleTime = _PID_SAMPLE_TIME_MS_DEF; /* default Controller Sample Time is 0.1 seconds */ - - PID_SetControllerDirection(uPID, ControllerDirection); - PID_SetTunings2(uPID, Kp, Ki, Kd, POn); - -} - -void PID2(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDCD_TypeDef ControllerDirection) -{ - PID(uPID, Input, Output, Setpoint, Kp, Ki, Kd, _PID_P_ON_E, ControllerDirection); -} - -/* ~~~~~~~~~~~~~~~~~ Computing ~~~~~~~~~~~~~~~~~ */ -uint8_t PID_Compute(PID_TypeDef *uPID) -{ - - float input=0; - float error=0; - float dInput=0; - float output=0; - - /* ~~~~~~~~~~ Check PID mode ~~~~~~~~~~ */ - if (!uPID->InAuto) - { - return _FALSE; - } - - - /* ..... Compute all the working error variables ..... */ - input = *uPID->MyInput; - error = *uPID->MySetpoint - input; - dInput = (input - uPID->LastInput); - - uPID->OutputSum += (uPID->Ki * error); - - /* ..... Add Proportional on Measurement, if P_ON_M is specified ..... */ - if (!uPID->POnE) - { - uPID->OutputSum -= uPID->Kp * dInput; - } - - if (uPID->OutputSum > uPID->OutMax) - { - uPID->OutputSum = uPID->OutMax; - } - else if (uPID->OutputSum < uPID->OutMin) - { - uPID->OutputSum = uPID->OutMin; - } - else { } - - /* ..... Add Proportional on Error, if P_ON_E is specified ..... */ - if (uPID->POnE) - { - output = uPID->Kp * error; - } - else - { - output = 0; - } - - /* ..... Compute Rest of PID Output ..... */ - output += uPID->OutputSum - uPID->Kd * dInput; - - if (output > uPID->OutMax) - { - output = uPID->OutMax; - } - else if (output < uPID->OutMin) - { - output = uPID->OutMin; - } - else { } - - *uPID->MyOutput = output; - - /* ..... Remember some variables for next time ..... */ - uPID->LastInput = input; - - return _TRUE; -} - -/* ~~~~~~~~~~~~~~~~~ PID Mode ~~~~~~~~~~~~~~~~~~ */ -void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode) -{ - - uint8_t newAuto = (Mode == _PID_MODE_AUTOMATIC); - - /* ~~~~~~~~~~ Initialize the PID ~~~~~~~~~~ */ - if (newAuto && !uPID->InAuto) - { - PID_Init(uPID); - } - - uPID->InAuto = (PIDMode_TypeDef)newAuto; - -} -PIDMode_TypeDef PID_GetMode(PID_TypeDef *uPID) -{ - return uPID->InAuto ? _PID_MODE_AUTOMATIC : _PID_MODE_MANUAL; -} - -/* ~~~~~~~~~~~~~~~~ PID Limits ~~~~~~~~~~~~~~~~~ */ -void PID_SetOutputLimits(PID_TypeDef *uPID, float Min, float Max) -{ - /* ~~~~~~~~~~ Check value ~~~~~~~~~~ */ - if (Min >= Max) - { - return; - } - - uPID->OutMin = Min; - uPID->OutMax = Max; - - /* ~~~~~~~~~~ Check PID Mode ~~~~~~~~~~ */ - if (uPID->InAuto) - { - - /* ..... Check out value ..... */ - if (*uPID->MyOutput > uPID->OutMax) - { - *uPID->MyOutput = uPID->OutMax; - } - else if (*uPID->MyOutput < uPID->OutMin) - { - *uPID->MyOutput = uPID->OutMin; - } - else { } - - /* ..... Check out value ..... */ - if (uPID->OutputSum > uPID->OutMax) - { - uPID->OutputSum = uPID->OutMax; - } - else if (uPID->OutputSum < uPID->OutMin) - { - uPID->OutputSum = uPID->OutMin; - } - else { } - - } - -} - -/* ~~~~~~~~~~~~~~~~ PID Tunings ~~~~~~~~~~~~~~~~ */ -void PID_SetTunings(PID_TypeDef *uPID, float Kp, float Ki, float Kd) -{ - PID_SetTunings2(uPID, Kp, Ki, Kd, uPID->POn); -} -void PID_SetTunings2(PID_TypeDef *uPID, float Kp, float Ki, float Kd, PIDPON_TypeDef POn) -{ - - float SampleTimeInSec; - - /* ~~~~~~~~~~ Check value ~~~~~~~~~~ */ - if (Kp < 0 || Ki < 0 || Kd < 0) - { - return; - } - - /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - uPID->POn = POn; - uPID->POnE = (PIDPON_TypeDef)(POn == _PID_P_ON_E); - - uPID->DispKp = Kp; - uPID->DispKi = Ki; - uPID->DispKd = Kd; - - /* ~~~~~~~~~ Calculate time ~~~~~~~~ */ - SampleTimeInSec = ((float)uPID->SampleTime) / 1000; - - uPID->Kp = Kp; - uPID->Ki = Ki * SampleTimeInSec; - uPID->Kd = Kd / SampleTimeInSec; - - /* ~~~~~~~~ Check direction ~~~~~~~~ */ - if (uPID->ControllerDirection == _PID_CD_REVERSE) - { - - uPID->Kp = (0 - uPID->Kp); - uPID->Ki = (0 - uPID->Ki); - uPID->Kd = (0 - uPID->Kd); - - } - -} - -/* ~~~~~~~~~~~~~~~ PID Direction ~~~~~~~~~~~~~~~ */ -void PID_SetControllerDirection(PID_TypeDef *uPID, PIDCD_TypeDef Direction) -{ - /* ~~~~~~~~~~ Check parameters ~~~~~~~~~~ */ - if ((uPID->InAuto) && (Direction !=uPID->ControllerDirection)) - { - - uPID->Kp = (0 - uPID->Kp); - uPID->Ki = (0 - uPID->Ki); - uPID->Kd = (0 - uPID->Kd); - - } - - uPID->ControllerDirection = Direction; - -} -PIDCD_TypeDef PID_GetDirection(PID_TypeDef *uPID) -{ - return uPID->ControllerDirection; -} - -/* ~~~~~~~~~~~~~~~ PID Sampling ~~~~~~~~~~~~~~~~ */ -void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime) -{ - - float ratio; - - /* ~~~~~~~~~~ Check value ~~~~~~~~~~ */ - if (NewSampleTime > 0) - { - - ratio = (float)NewSampleTime / (float)uPID->SampleTime; - - uPID->Ki *= ratio; - uPID->Kd /= ratio; - uPID->SampleTime = (uint32_t)NewSampleTime; - - } - -} - -/* ~~~~~~~~~~~~~ Get Tunings Param ~~~~~~~~~~~~~ */ -float PID_GetKp(PID_TypeDef *uPID) -{ - return uPID->DispKp; -} -float PID_GetKi(PID_TypeDef *uPID) -{ - return uPID->DispKi; -} -float PID_GetKd(PID_TypeDef *uPID) -{ - return uPID->DispKd; -} diff --git a/3rd-lib/PID-Library/pid.h b/3rd-lib/PID-Library/pid.h deleted file mode 100644 index 7583788..0000000 --- a/3rd-lib/PID-Library/pid.h +++ /dev/null @@ -1,176 +0,0 @@ - /* ------------------------------------------------------------------------------- -~ File : pid.h -~ Author : Majid Derhambakhsh -~ Version: V1.0.0 -~ Created: 02/11/2021 03:43:00 AM -~ Brief : -~ Support: - E-Mail : Majid.do16@gmail.com (subject : Embedded Library Support) - - Github : https://github.com/Majid-Derhambakhsh ------------------------------------------------------------------------------- -~ Description: - -~ Attention : - -~ Changes : ------------------------------------------------------------------------------- -*/ - -#ifndef __PID_H_ -#define __PID_H_ - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Include ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#include -#include - -#include "zf_common_headfile.h" - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Defines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ------------------------ Library ------------------------ */ -#define _PID_LIBRARY_VERSION 1.0.0 - -/* ------------------------ Public ------------------------- */ -#define _PID_8BIT_PWM_MAX UINT8_MAX -#define _PID_SAMPLE_TIME_MS_DEF 100 - -#ifndef _FALSE - - #define _FALSE 0 - -#endif - -#ifndef _TRUE - - #define _TRUE 1 - -#endif - -/* ---------------------- By compiler ---------------------- */ -#ifndef GetTime - - /* ---------------------- By compiler ---------------------- */ - - #ifdef __CODEVISIONAVR__ /* Check compiler */ - - #define GetTime() 0 - - /* ------------------------------------------------------------------ */ - - #elif defined(__GNUC__) /* Check compiler */ - - #define GetTime() 0 - - /* ------------------------------------------------------------------ */ - - - #else - #endif /* __CODEVISIONAVR__ */ - /* ------------------------------------------------------------------ */ - -#endif - -/* --------------------------------------------------------- */ - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* PID Mode */ -typedef enum -{ - - _PID_MODE_MANUAL = 0, - _PID_MODE_AUTOMATIC = 1 - -}PIDMode_TypeDef; - -/* PID P On x */ -typedef enum -{ - - _PID_P_ON_M = 0, /* Proportional on Measurement */ - _PID_P_ON_E = 1 - -}PIDPON_TypeDef; - -/* PID Control direction */ -typedef enum -{ - - _PID_CD_DIRECT = 0, - _PID_CD_REVERSE = 1 - -}PIDCD_TypeDef; - -/* PID Structure */ -typedef struct -{ - - PIDPON_TypeDef POnE; - PIDMode_TypeDef InAuto; - - PIDPON_TypeDef POn; - PIDCD_TypeDef ControllerDirection; - - uint32_t LastTime; - uint32_t SampleTime; - - float DispKp; - float DispKi; - float DispKd; - - float Kp; - float Ki; - float Kd; - - float *MyInput; - float *MyOutput; - float *MySetpoint; - - float OutputSum; - float LastInput; - - float OutMin; - float OutMax; - -}PID_TypeDef; - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enum ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Struct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Class ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Prototype ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* :::::::::::::: Init ::::::::::::: */ -void PID_Init(PID_TypeDef *uPID); - -void PID(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection); -void PID2(PID_TypeDef *uPID, float *Input, float *Output, float *Setpoint, float Kp, float Ki, float Kd, PIDCD_TypeDef ControllerDirection); - -/* ::::::::::: Computing ::::::::::: */ -uint8_t PID_Compute(PID_TypeDef *uPID); - -/* ::::::::::: PID Mode :::::::::::: */ -void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode); -PIDMode_TypeDef PID_GetMode(PID_TypeDef *uPID); - -/* :::::::::: PID Limits ::::::::::: */ -void PID_SetOutputLimits(PID_TypeDef *uPID, float Min, float Max); - -/* :::::::::: PID Tunings :::::::::: */ -void PID_SetTunings(PID_TypeDef *uPID, float Kp, float Ki, float Kd); -void PID_SetTunings2(PID_TypeDef *uPID, float Kp, float Ki, float Kd, PIDPON_TypeDef POn); - -/* ::::::::: PID Direction ::::::::: */ -void PID_SetControllerDirection(PID_TypeDef *uPID, PIDCD_TypeDef Direction); -PIDCD_TypeDef PID_GetDirection(PID_TypeDef *uPID); - -/* ::::::::: PID Sampling :::::::::: */ -void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime); - -/* ::::::: Get Tunings Param ::::::: */ -float PID_GetKp(PID_TypeDef *uPID); -float PID_GetKi(PID_TypeDef *uPID); -float PID_GetKd(PID_TypeDef *uPID); - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End of the program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -#endif /* __PID_H_ */ diff --git a/app/by_button.c b/app/by_button.c new file mode 100644 index 0000000..b68a838 --- /dev/null +++ b/app/by_button.c @@ -0,0 +1,29 @@ +#include "by_button.h" + +#include "zf_common_headfile.h" + +button_event_t button_event; + +void by_button_init(void) +{ + gpio_init(BUTTON_LEFT_PIN, GPI, 1, GPI_PULL_UP); + gpio_init(BUTTON_DOWN_PIN, GPI, 1, GPI_PULL_UP); + gpio_init(BUTTON_UP_PIN, GPI, 1, GPI_PULL_UP); + gpio_init(BUTTON_CENTER_PIN, GPI, 1, GPI_PULL_UP); + gpio_init(BUTTON_RIGHT_PIN, GPI, 1, GPI_PULL_UP); + gpio_init(BUTTON_SIDE_PIN, GPI, 1, GPI_PULL_UP); + + exti_init(BUTTON_LEFT_PIN, EXTI_TRIGGER_FALLING); + exti_init(BUTTON_DOWN_PIN, EXTI_TRIGGER_FALLING); + exti_init(BUTTON_UP_PIN, EXTI_TRIGGER_FALLING); + exti_init(BUTTON_CENTER_PIN, EXTI_TRIGGER_BOTH); + exti_init(BUTTON_RIGHT_PIN, EXTI_TRIGGER_FALLING); + exti_init(BUTTON_SIDE_PIN, EXTI_TRIGGER_FALLING); +} + +uint8_t by_button_get_status(void) +{ + uint8_t temp_s = (uint8_t)button_event; + button_event = button_event_none; + return temp_s; +} \ No newline at end of file diff --git a/app/by_button.h b/app/by_button.h new file mode 100644 index 0000000..12e2877 --- /dev/null +++ b/app/by_button.h @@ -0,0 +1,33 @@ +#ifndef _BY_BUTTON_H__ +#define _BY_BUTTON_H__ + +#include +#include + +#define LONG_PRESS_THRESHOLD_MS (300ULL) +#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL) + +#define BUTTON_UP_PIN E12 +#define BUTTON_DOWN_PIN E11 +#define BUTTON_LEFT_PIN E10 +#define BUTTON_RIGHT_PIN E14 +#define BUTTON_CENTER_PIN E13 +#define BUTTON_SIDE_PIN E15 + +typedef enum button_event_t{ + button_event_none = 0, + button_event_up, + button_event_down, + button_event_left, + button_event_right, + button_event_center_sp, + button_event_center_lp, + button_event_side, +}button_event_t; + +extern button_event_t button_event; + +void by_button_init(void); +uint8_t by_button_get_status(void); + +#endif diff --git a/app/by_buzzer.c b/app/by_buzzer.c index 52188df..6af01c9 100644 --- a/app/by_buzzer.c +++ b/app/by_buzzer.c @@ -1,12 +1,13 @@ #include "by_buzzer.h" -#include "by_rt_button.h" -#include "zf_common_headfile.h" #include +#include "zf_common_headfile.h" + +#define BUZZER_QUEUE_LENGTH 40 + +uint16_t queue_long = 0; +uint32_t a[40] = {0}; -uint16_t queue_long = 0; -const uint32_t max_long = 40; -uint32_t a[40]; void queue_init(void) { memset(a, 0, sizeof(a)); @@ -14,7 +15,7 @@ void queue_init(void) void queue_add_element(int element) { - if (queue_long < max_long) { + if (queue_long < BUZZER_QUEUE_LENGTH) { a[queue_long] = element; queue_long += 1; } @@ -38,5 +39,15 @@ void queue_pop_read(void) void by_buzzer_init(void) { + queue_init(); pwm_init(BUZZER_PIN, 2000, 0); + + by_buzzer_add(1250); + by_buzzer_add(1500); + by_buzzer_add(1750); +} + +void by_buzzer_add(uint16_t tone) +{ + queue_add_element(tone); } diff --git a/app/by_buzzer.h b/app/by_buzzer.h index c410955..060c1b8 100644 --- a/app/by_buzzer.h +++ b/app/by_buzzer.h @@ -1,24 +1,23 @@ #ifndef _BY_BUZZER_H__ #define _BY_BUZZER_H__ -#include "by_rt_button.h" - -#include "stdio.h" -#include "ch32v30x.h" +#include "zf_common_headfile.h" #define BY_PRESS_SHORT 2000 #define BY_PRESS_LONG 2500 #define BY_FORWARD 1500 #define BY_BACKWARD 1800 -#define BUZZER_PIN TIM3_PWM_MAP0_CH2_A7 -extern void by_buzzer_init(void); -extern void queue_init(void); -extern void queue_add_element(int element); -extern void queue_pop_element(void); -extern void queue_pop_read(void); +#define BUZZER_PIN TIM4_PWM_MAP1_CH3_D14 extern uint32_t a[40]; extern uint16_t queue_long; extern const uint32_t max_long; extern uint8_t queue_flag; + +extern void queue_init(void); +extern void queue_add_element(int element); +extern void queue_pop_element(void); +extern void queue_pop_read(void); +extern void by_buzzer_init(void); +extern void by_buzzer_add(uint16_t tone); #endif \ No newline at end of file diff --git a/app/by_fan_control.c b/app/by_fan_control.c deleted file mode 100644 index 22a4463..0000000 --- a/app/by_fan_control.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "by_fan_control.h" -#include "zf_common_headfile.h" -#define Fan_pwm_up1 TIM8_PWM_MAP0_CH1_C6 -#define Fan_pwm_up2 TIM8_PWM_MAP0_CH2_C7 -#define Fan_pwm_power1 TIM4_PWM_MAP1_CH3_D14 -#define Fan_pwm_power2 TIM4_PWM_MAP1_CH4_D15 -#define Fan_pwm_power3 TIM4_PWM_MAP1_CH2_D13 -#define Fan_pwm_power4 TIM4_PWM_MAP1_CH1_D12 - -uint32_t myclip(uint32_t x, uint32_t low, uint32_t up) -{ - return (x > up ? up : x < low ? low - : x); -} - -void by_pwm_init(void) -{ - pwm_init(Fan_pwm_up1, 50, 500); // 浮力风扇左 - pwm_init(Fan_pwm_up2, 50, 500); // 浮力风扇右 - - pwm_init(Fan_pwm_power1, 50, 500); // 动力风扇左1 - pwm_init(Fan_pwm_power2, 50, 500); // 动力风扇右1 - pwm_init(Fan_pwm_power3, 50, 500); // 动力风扇左2 - pwm_init(Fan_pwm_power4, 50, 500); // 动力风扇右2 - // system_delay_ms(3000); - // // pwm_init(Fan_pwm_power1, 50, 1000); // 动力风扇左1 - // // pwm_init(Fan_pwm_power2, 50, 1000); // 动力风扇右1 - // // pwm_init(Fan_pwm_power3, 50, 1000); // 动力风扇左2 - // // pwm_init(Fan_pwm_power4, 50, 1000); // 动力风扇右2 - // // system_delay_ms(5000); - // pwm_set_duty(Fan_pwm_power1, 600); - // pwm_set_duty(Fan_pwm_power2, 600); - // pwm_set_duty(Fan_pwm_power3, 600); - // pwm_set_duty(Fan_pwm_power4, 600); - // while(1); -} - -void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2) -{ - update_pwm_duty1=myclip(update_pwm_duty1, 500, 900); - update_pwm_duty2=myclip(update_pwm_duty2, 500, 900); - pwm_set_duty(Fan_pwm_up1, update_pwm_duty1); - pwm_set_duty(Fan_pwm_up2, update_pwm_duty2); -} - -void by_pwm_power_duty(uint32_t power_pwm_duty_l1, uint32_t power_pwm_duty_r1, uint32_t power_pwm_duty_l2, uint32_t power_pwm_duty_r2) -{ - - power_pwm_duty_l1=myclip(power_pwm_duty_l1, 500, 900); - power_pwm_duty_r1=myclip(power_pwm_duty_r1, 500, 900); - power_pwm_duty_l2=myclip(power_pwm_duty_l2, 500, 900); - power_pwm_duty_r2=myclip(power_pwm_duty_r2, 500, 900); - - pwm_set_duty(Fan_pwm_power1, power_pwm_duty_l1); - pwm_set_duty(Fan_pwm_power2, power_pwm_duty_r1); - pwm_set_duty(Fan_pwm_power3, power_pwm_duty_l2); - pwm_set_duty(Fan_pwm_power4, power_pwm_duty_r2); -} diff --git a/app/by_fan_control.h b/app/by_fan_control.h deleted file mode 100644 index d06fd22..0000000 --- a/app/by_fan_control.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _BY_FAN_CONTROL_H_ -#define _BY_FAN_CONTROL_H_ - -#include "stdio.h" -#include "ch32v30x.h" - -extern void by_pwm_init(void); -void by_pwm_update_duty(uint32_t update_pwm_duty1,uint32_t update_pwm_duty2); -void by_pwm_power_duty(uint32_t power_pwm_duty_l1, uint32_t power_pwm_duty_r1,uint32_t power_pwm_duty_l2, uint32_t power_pwm_duty_r2); - -#endif \ No newline at end of file diff --git a/app/by_imu.c b/app/by_imu.c deleted file mode 100644 index 5a0e864..0000000 --- a/app/by_imu.c +++ /dev/null @@ -1,192 +0,0 @@ -#include "by_imu.h" -#include "zf_common_headfile.h" -#include - -#define delta_T 0.002f // 2ms 计算一次 - -float I_ex, I_ey, I_ez; // 误差积分 - -quater_param_t Q_info = {1, 0, 0}; // 全局四元数 -euler_param_t eulerAngle; // 欧拉角 - -icm_param_t icm_data; -gyro_param_t GyroOffset; - -bool GyroOffset_init = 0; - -float param_Kp = 0.17f; // 加速度计的收敛速率比例增益 0.17 -float param_Ki = 0.004f; // 陀螺仪收敛速率的积分增益 0.004 - -float fast_sqrt(float x) -{ - float halfx = 0.5f * x; - float y = x; - long i = *(long *)&y; - i = 0x5f3759df - (i >> 1); - y = *(float *)&i; - y = y * (1.5f - (halfx * y * y)); - return y; -} - -void gyroOffset_init(void) /////////陀螺仪零飘初始化 -{ - float xdata_temp = 0; - float ydata_temp = 0; - float zdata_temp = 0; - - imu660ra_get_gyro(); - xdata_temp = imu660ra_gyro_x; - ydata_temp = imu660ra_gyro_y; - zdata_temp = imu660ra_gyro_z; - - GyroOffset.Xdata = 0; - GyroOffset.Ydata = 0; - GyroOffset.Zdata = 0; - for (uint16_t i = 0; i < 5000; i++) { - imu660ra_get_gyro(); - - xdata_temp = imu660ra_gyro_x * 0.3f + xdata_temp * 0.7f; - ydata_temp = imu660ra_gyro_y * 0.3f + ydata_temp * 0.7f; - zdata_temp = imu660ra_gyro_z * 0.3f + zdata_temp * 0.7f; - - GyroOffset.Xdata += xdata_temp; - GyroOffset.Ydata += ydata_temp; - GyroOffset.Zdata += zdata_temp; - system_delay_ms(5); - } - - GyroOffset.Xdata /= 5000.0f; - GyroOffset.Ydata /= 5000.0f; - GyroOffset.Zdata /= 5000.0f; - - // GyroOffset.Xdata = -1.034f; - // GyroOffset.Ydata = -2.21f; - // GyroOffset.Zdata = -3.15f; - - GyroOffset_init = 1; -} -// 转化为实际物理值 -void ICM_getValues() -{ -#define alpha 0.2738f - // icm_data.acc_x = imu660ra_acc_x * alpha + icm_data.acc_x * (1 - alpha); - // icm_data.acc_y = imu660ra_acc_y * alpha + icm_data.acc_y * (1 - alpha); - // icm_data.acc_z = imu660ra_acc_z * alpha + icm_data.acc_z * (1 - alpha); - - icm_data.acc_x = imu660ra_acc_x; - icm_data.acc_y = imu660ra_acc_y; - icm_data.acc_z = imu660ra_acc_z; - - icm_data.gyro_x = icm_data.gyro_x * alpha + ((imu660ra_gyro_x - GyroOffset.Xdata) / 939.65f) * (1 - alpha); - icm_data.gyro_y = icm_data.gyro_y * alpha + ((imu660ra_gyro_y - GyroOffset.Ydata) / 939.65f) * (1 - alpha); - icm_data.gyro_z = icm_data.gyro_z * alpha + ((imu660ra_gyro_z - GyroOffset.Zdata) / 939.65f) * (1 - alpha); -} - -// 互补滤波 -void ICM_AHRSupdate(float gx, float gy, float gz, float ax, float ay, float az) -{ - float halfT = 0.5 * delta_T; - float vx, vy, vz; // 当前的机体坐标系上的重力单位向量 - float ex, ey, ez; // 四元数计算值与加速度计测量值的误差 - float q0 = Q_info.q0; - float q1 = Q_info.q1; - float q2 = Q_info.q2; - float q3 = Q_info.q3; - float q0q0 = q0 * q0; - float q0q1 = q0 * q1; - float q0q2 = q0 * q2; - // float q0q3 = q0 * q3; - float q1q1 = q1 * q1; - // float q1q2 = q1 * q2; - float q1q3 = q1 * q3; - float q2q2 = q2 * q2; - float q2q3 = q2 * q3; - float q3q3 = q3 * q3; - // float delta_2 = 0; - - // 对加速度数据进行归一化 得到单位加速度 - float norm = fast_sqrt(ax * ax + ay * ay + az * az); - ax = ax * norm; - ay = ay * norm; - az = az * norm; - - // 根据当前四元数的姿态值来估算出各重力分量。用于和加速计实际测量出来的各重力分量进行对比,从而实现对四轴姿态的修正 - vx = 2.0f * (q1q3 - q0q2); - vy = 2.0f * (q0q1 + q2q3); - vz = q0q0 - q1q1 - q2q2 + q3q3; - // vz = 1.0f - 2.0f * q1q1 - 2.0f * q2q2; - // vz = (q0*q0-0.5f+q3 * q3) * 2; - - // 叉积来计算估算的重力和实际测量的重力这两个重力向量之间的误差。 - ex = ay * vz - az * vy; - ey = az * vx - ax * vz; - ez = ax * vy - ay * vx; - - // 用叉乘误差来做 PI 修正陀螺零偏, - // 通过调节 param_Kp,param_Ki 两个参数, - // 可以控制加速度计修正陀螺仪积分姿态的速度。 - I_ex += halfT * ex; // integral error scaled by Ki - I_ey += halfT * ey; - I_ez += halfT * ez; - - gx = gx + param_Kp * ex + param_Ki * I_ex; - gy = gy + param_Kp * ey + param_Ki * I_ey; - gz = gz + param_Kp * ez + param_Ki * I_ez; - - /*数据修正完成,下面是四元数微分方程*/ - - // 四元数微分方程,其中 halfT 为测量周期的 1/2,gx gy gz 为陀螺仪角速度,以下都是已知量,这里使用了一阶龙哥库塔求解四元数微分方程 - q0 = q0 + (-q1 * gx - q2 * gy - q3 * gz) * halfT; - q1 = q1 + (q0 * gx + q2 * gz - q3 * gy) * halfT; - q2 = q2 + (q0 * gy - q1 * gz + q3 * gx) * halfT; - q3 = q3 + (q0 * gz + q1 * gy - q2 * gx) * halfT; - // delta_2=(2*halfT*gx)*(2*halfT*gx)+(2*halfT*gy)*(2*halfT*gy)+(2*halfT*gz)*(2*halfT*gz); - // 整合四元数率 四元数微分方程 四元数更新算法,二阶毕卡法 - // q0 = (1-delta_2/8)*q0 + (-q1*gx - q2*gy - q3*gz)*halfT; - // q1 = (1-delta_2/8)*q1 + (q0*gx + q2*gz - q3*gy)*halfT; - // q2 = (1-delta_2/8)*q2 + (q0*gy - q1*gz + q3*gx)*halfT; - // q3 = (1-delta_2/8)*q3 + (q0*gz + q1*gy - q2*gx)*halfT - - // normalise quaternion - norm = fast_sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); - Q_info.q0 = q0 * norm; - Q_info.q1 = q1 * norm; - Q_info.q2 = q2 * norm; - Q_info.q3 = q3 * norm; -} -void ICM_getEulerianAngles(void) -{ - - // 采集陀螺仪数据 - imu660ra_get_acc(); - imu660ra_get_gyro(); - imu660ra_get_temperature(); - - ICM_getValues(); - ICM_AHRSupdate(icm_data.gyro_x, icm_data.gyro_y, icm_data.gyro_z, icm_data.acc_x, icm_data.acc_y, icm_data.acc_z); - float q0 = Q_info.q0; - float q1 = Q_info.q1; - float q2 = Q_info.q2; - float q3 = Q_info.q3; - - // 四元数计算欧拉角 - eulerAngle.pitch = asinf(-2 * q1 * q3 + 2 * q0 * q2) * 180.0f / M_PI; // pitch - eulerAngle.roll = atan2f(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2 * q2 + 1) * 180.0f / M_PI; // roll - eulerAngle.yaw = atan2f(2 * q1 * q2 + 2 * q0 * q3, -2 * q2 * q2 - 2 * q3 * q3 + 1) * 180.0f / M_PI; // yaw - - /* 姿态限制*/ - if (eulerAngle.roll > 90 || eulerAngle.roll < -90) { - if (eulerAngle.pitch > 0) { - eulerAngle.pitch = 180 - eulerAngle.pitch; - } - if (eulerAngle.pitch < 0) { - eulerAngle.pitch = -(180 + eulerAngle.pitch); - } - } - - if (eulerAngle.yaw > 180) { - eulerAngle.yaw -= 180; - } else if (eulerAngle.yaw < -180) { - eulerAngle.yaw += 180; - } -} diff --git a/app/by_imu.h b/app/by_imu.h deleted file mode 100644 index 63b681b..0000000 --- a/app/by_imu.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _BY_IMU_H__ -#define _BY_IMU_H__ - -#include -#include "ch32v30x.h" -typedef struct { - float gyro_x; - float gyro_y; - float gyro_z; - float acc_x; - float acc_y; - float acc_z; -} icm_param_t; - -typedef struct { - float q0; - float q1; - float q2; - float q3; -} quater_param_t; - -typedef struct { - float pitch; //俯仰角 - float roll; //偏航角 - float yaw; //翻滚角 -} euler_param_t; - -typedef struct { - float Xdata; - float Ydata; - float Zdata; -} gyro_param_t; - -extern icm_param_t icm_data; -extern euler_param_t eulerAngle; -extern gyro_param_t GyroOffset; - -void gyroOffset_init(void); - -float fast_sqrt(float x); - -void ICM_AHRSupdate(float gx, float gy, float gz, float ax, float ay, float az); - -void ICM_getValues(); - -void ICM_getEulerianAngles(void); -#endif \ No newline at end of file diff --git a/app/by_rt_button.c b/app/by_rt_button.c index 40b5471..d14c013 100644 --- a/app/by_rt_button.c +++ b/app/by_rt_button.c @@ -1,6 +1,5 @@ #include "by_rt_button.h" #include "zf_common_headfile.h" -#include "by_imu.h" uint8_t rotate_button; void by_gpio_init(void) @@ -24,35 +23,4 @@ uint8_t by_get_rb_status(void) uint8_t temp_s = rotate_button; rotate_button = 0; return temp_s; -} - -void by_ips_show(void) -{ - ips200_show_string(0, 0, "button status:"); - // ips200_show_uint(104, 0, by_get_rb_status(), 1); - switch (by_get_rb_status()) { - case 1: - ips200_show_string(104, 0, "press"); - break; - case 2: - ips200_show_string(104, 0, "up "); - break; - case 3: - ips200_show_string(104, 0, "down "); - break; - - default: - ips200_show_string(104, 0, " "); - break; - } - // 按钮 - ips200_show_string(0, 16, "imu:"); - ips200_show_float(46, 32, eulerAngle.pitch, 3, 2); - ips200_show_float(46, 48, eulerAngle.roll, 3, 2); - ips200_show_float(46, 64, eulerAngle.yaw, 3, 2); - // ips200_show_float(46 , 32, icm_data.gyro_x, 2, 2); - // ips200_show_float(106, 32, icm_data.gyro_y, 2, 2); - // ips200_show_float(166, 32, icm_data.gyro_z, 2, 2); - ips200_show_float(46, 80, imu660ra_temperature, 2, 2); - // printf("%d,%d,%d\n", (int16_t)(icm_data.gyro_x * 10), (int16_t)(icm_data.gyro_y * 10), (int16_t)(icm_data.gyro_z * 10)); -} +} \ No newline at end of file diff --git a/app/by_rt_button.h b/app/by_rt_button.h index c42d6e0..714e02f 100644 --- a/app/by_rt_button.h +++ b/app/by_rt_button.h @@ -4,9 +4,6 @@ #include "stdio.h" #include "ch32v30x.h" -#define LONG_PRESS_THRESHOLD_MS (300ULL) -#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL) - typedef enum rotate_button_event { rotate_button_press_short = 1, rotate_button_press_long = 2, diff --git a/app/isr.c b/app/isr.c index 33d4983..137e5f6 100644 --- a/app/isr.c +++ b/app/isr.c @@ -35,11 +35,8 @@ #include "zf_common_headfile.h" #include "by_rt_button.h" -#include "by_imu.h" -#include "jj_blueteeth.h" +#include "by_button.h" #include "by_buzzer.h" -#include "jj_motion.h" -#include "jj_blueteeth.h" void NMI_Handler(void) __attribute__((interrupt())); void HardFault_Handler(void) __attribute__((interrupt())); @@ -94,8 +91,6 @@ void USART1_IRQHandler(void) void USART2_IRQHandler(void) { if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { - uart_query_byte(UART_2, &bt_buffer); - bt_rx_flag = true; USART_ClearITPendingBit(USART2, USART_IT_RXNE); } } @@ -201,14 +196,6 @@ void EXTI9_5_IRQHandler(void) EXTI_ClearITPendingBit(EXTI_Line8); } if (SET == EXTI_GetITStatus(EXTI_Line9)) { - - if (SET == gpio_get_level(E10)) { - rotate_button = rotate_button_backward; - queue_add_element(BY_BACKWARD); - } else { - rotate_button = rotate_button_forward; - queue_add_element(BY_FORWARD); - } EXTI_ClearITPendingBit(EXTI_Line9); } } @@ -216,57 +203,63 @@ void EXTI9_5_IRQHandler(void) void EXTI15_10_IRQHandler(void) { if (SET == EXTI_GetITStatus(EXTI_Line10)) { - - // ˴дû (A10/B10..E10) Ŵ - - // ˴дû (A10/B10..E10) Ŵ - + system_delay_ms(10); + if (RESET == gpio_get_level(BUTTON_LEFT_PIN)) { + button_event = button_event_left; + } + by_buzzer_add(1250); EXTI_ClearITPendingBit(EXTI_Line10); } if (SET == EXTI_GetITStatus(EXTI_Line11)) { + system_delay_ms(10); + if (RESET == gpio_get_level(BUTTON_DOWN_PIN)) { + button_event = button_event_down; + } + by_buzzer_add(1250); + EXTI_ClearITPendingBit(EXTI_Line11); + } + if (SET == EXTI_GetITStatus(EXTI_Line12)) { + system_delay_ms(10); + if (RESET == gpio_get_level(BUTTON_UP_PIN)) { + button_event = button_event_up; + } + by_buzzer_add(1250); + EXTI_ClearITPendingBit(EXTI_Line12); + } + if (SET == EXTI_GetITStatus(EXTI_Line13)) { static uint64_t time_via = 0; system_delay_ms(10); - if (RESET == gpio_get_level(E11)) { + if (RESET == gpio_get_level(BUTTON_CENTER_PIN)) { time_via = system_get_tick(); - EXTI_ClearITPendingBit(EXTI_Line11); - } else if (SET == gpio_get_level(E11)) { + } else if (SET == gpio_get_level(BUTTON_CENTER_PIN)) { time_via = system_get_tick() - time_via; if (time_via > LONG_PRESS_THRESHOLD_TICK) { - rotate_button = rotate_button_press_long; - queue_add_element(BY_PRESS_LONG); - + button_event = button_event_center_lp; + by_buzzer_add(2000); } else { - rotate_button = rotate_button_press_short; - queue_add_element(BY_PRESS_SHORT); + button_event = button_event_center_sp; + by_buzzer_add(1800); } time_via = 0; - EXTI_ClearITPendingBit(EXTI_Line11); } - if (SET == EXTI_GetITStatus(EXTI_Line12)) { - EXTI_ClearITPendingBit(EXTI_Line12); + EXTI_ClearITPendingBit(EXTI_Line13); + } + if (SET == EXTI_GetITStatus(EXTI_Line14)) { + system_delay_ms(10); + if (RESET == gpio_get_level(BUTTON_RIGHT_PIN)) { + button_event = button_event_right; + by_buzzer_add(1250); } - if (SET == EXTI_GetITStatus(EXTI_Line13)) { - // -----------------* ToF INT ж Ԥжϴ *----------------- - tof_module_exti_handler(); - // -----------------* ToF INT ж Ԥжϴ *----------------- - // ˴дû (A13/B13..E13) Ŵ - - // ˴дû (A13/B13..E13) Ŵ - - EXTI_ClearITPendingBit(EXTI_Line13); - } - if (SET == EXTI_GetITStatus(EXTI_Line14)) { - // -----------------* DM1XA ź Ԥжϴ *----------------- - dm1xa_light_callback(); - // -----------------* DM1XA ź Ԥжϴ *----------------- - EXTI_ClearITPendingBit(EXTI_Line14); - } - if (SET == EXTI_GetITStatus(EXTI_Line15)) { - // -----------------* DM1XA /ź Ԥжϴ *----------------- - dm1xa_sound_callback(); - // -----------------* DM1XA /ź Ԥжϴ *----------------- - EXTI_ClearITPendingBit(EXTI_Line15); + EXTI_ClearITPendingBit(EXTI_Line14); + } + if (SET == EXTI_GetITStatus(EXTI_Line15)) { + system_delay_ms(10); + if (RESET == gpio_get_level(BUTTON_SIDE_PIN)) { + button_event = button_event_side; + by_buzzer_add(2000); + by_buzzer_add(1500); } + EXTI_ClearITPendingBit(EXTI_Line15); } } @@ -274,8 +267,6 @@ void TIM1_UP_IRQHandler(void) { if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM1, TIM_IT_Update); - - sport_motion2(bt_fly); } } @@ -310,7 +301,6 @@ void TIM5_IRQHandler(void) void TIM6_IRQHandler(void) { if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) { - ICM_getEulerianAngles(); TIM_ClearITPendingBit(TIM6, TIM_IT_Update); } } diff --git a/app/jj_blueteeth.c b/app/jj_blueteeth.c deleted file mode 100644 index 7e47f67..0000000 --- a/app/jj_blueteeth.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "jj_blueteeth.h" -#include "jj_motion.h" -#include "by_fan_control.h" -bool bt_rx_flag = false; -uint8 bt_buffer; // 接收字符存入 -float bt_angle = 0.0f; -uint32_t bt_run_flag = 0; -uint8_t bt_flow_flag = 0; -uint32_t bt_fly = 0; -uint32_t bt_flow = 0; -enum bt_order { - Start_work = 0x01, - Turn_Left = 0x02, - Turn_Right = 0x03, - Speed_up = 0x04, - Speed_down = 0x05, - Stop_fly = 0x06, - Flow_on = 0x08, - Flow_up = 0x09, - Flow_down = 0x10, -}; -/** - * @brief 蓝牙初始化 - * @retval 无 - */ -void jj_bt_init() -{ - uart_init(UART_2, 115200, UART2_MAP1_TX_D5, UART2_MAP1_RX_D6); - // uart_tx_interrupt(UART_2, 1); - uart_rx_interrupt(UART_2, ENABLE); -} -/** - *@brief 蓝牙中断回调函数 - */ -void jj_bt_run() -{ - if (bt_rx_flag) { - switch (bt_buffer) { - case Start_work: - bt_angle = 0.0f; - break; - case Turn_Left: - bt_angle = 10.0f; - break; - case Turn_Right: - bt_angle = -10.0f; - break; - case Speed_down: - bt_fly -= 10; - break; - case Speed_up: - bt_fly += 10; - break; - case Stop_fly: - bt_run_flag = !bt_run_flag; - break; - case Flow_on: - bt_flow_flag = !bt_flow_flag; - break; - case Flow_up: - bt_flow += 20; - break; - case Flow_down: - bt_flow -= 20; - break; - default: - break; - } - - if (bt_flow_flag == 0) { - bt_flow = 0; - } - by_pwm_update_duty(bt_flow + 500, bt_flow + 500); - bt_rx_flag = false; - } -} - -void bt_printf(const char *format, ...) -{ - char sbuf[40]; - va_list args; - va_start(args, format); - vsnprintf(sbuf, 40, format, args); - va_end(args); - - for (uint16_t i = 0; i < strlen(sbuf); i++) { - while (USART_GetFlagStatus((USART_TypeDef *)uart_index[UART_2], USART_FLAG_TC) == RESET) - ; - USART_SendData((USART_TypeDef *)uart_index[UART_2], sbuf[i]); - } - -} \ No newline at end of file diff --git a/app/jj_blueteeth.h b/app/jj_blueteeth.h deleted file mode 100644 index 11f1a64..0000000 --- a/app/jj_blueteeth.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _JJ_BLUETEETH_H_ -#define _JJ_BLUETEETH_H_ -#include "stdio.h" -#include "zf_driver_uart.h" - -extern bool bt_rx_flag; -extern uint8_t bt_buffer; -extern uint32_t bt_fly; -extern uint32_t bt_run_flag; -extern float bt_angle; -void jj_bt_init(); -void jj_bt_run(); -void bt_printf(const char *format, ...); -#endif \ No newline at end of file diff --git a/app/jj_motion.c b/app/jj_motion.c deleted file mode 100644 index 3dbdb66..0000000 --- a/app/jj_motion.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "jj_motion.h" -#include "by_fan_control.h" -#include "by_imu.h" -#include "../3rd-lib/PID-Library/pid.h" -#include "jj_blueteeth.h" -#include "gl_common.h" -PID_TypeDef angle_pid; -PID_TypeDef gyro_z_pid; -PID_TypeDef img_x_pid; -float an_Kp = 8.0f; -float an_Ki = 0.0f; -float an_Kd = 2.0f; -float im_Kp = 1.0f; -float im_Ki = 0.0f; -float im_Kd = 0.0f; -float set_x = 0.0f; -float img_x = 40.0f; -float yaw0 = 0; -float out_M = 0; -float out_yaw; -uint32_t cnt1 = 0; -/** - * @brief - * - * @param fy y轴的加速度 - */ -void sport_motion2(uint32_t fy) -{ - cnt1++; - yaw0 = imu660ra_gyro_z; - if (cnt1 >= 50) { - PID_Compute(&angle_pid); - cnt1 = 0; - } - PID_Compute(&gyro_z_pid); - if (bt_run_flag == 1) { - by_pwm_power_duty((int32_t)(500 + fy + out_M), (int32_t)(500 + fy - out_M), - (int32_t)(500 + fy + out_M), (int32_t)(500 + fy - out_M)); - } else { - by_pwm_power_duty(500, 500, 500, 500); - } -} -/** - * @brief 结构体初始化 - * - */ -void sport_pid_init() -{ - - PID(&angle_pid, &bt_angle, &out_yaw, &set_x, im_Kp, im_Ki, im_Kd, 0, 0); - PID(&gyro_z_pid, &yaw0, &out_M, &out_yaw, an_Kp, an_Ki, an_Kd, 1, 1); - PID_Init(&angle_pid); - PID_Init(&gyro_z_pid); - - PID_SetOutputLimits(&angle_pid, -500.0f, 500.0f); - PID_SetOutputLimits(&gyro_z_pid, -400.0f, 400.0f); - - PID_SetMode(&gyro_z_pid, 1); - PID_SetMode(&angle_pid, 1); -} diff --git a/app/jj_motion.h b/app/jj_motion.h deleted file mode 100644 index 2b4b1c2..0000000 --- a/app/jj_motion.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _JJ_MOTION_H_ -#define _JJ_MOTION_H_ -#include "ch32v30x.h" -#include "../3rd-lib/PID-Library/pid.h" -extern PID_TypeDef angle_pid; -extern PID_TypeDef gyro_z_pid; -extern float an_Kp; -extern float an_Ki; -extern float an_Kd; -extern float im_Kp; -extern float im_Ki; -extern float im_Kd; -extern float out_M; -extern float out_yaw; -extern float yaw0; -void sport_pid_init(); -void sport_motion2(uint32_t fy); -#endif \ No newline at end of file diff --git a/app/jj_param.c b/app/jj_param.c index a2a9b94..ced4ada 100644 --- a/app/jj_param.c +++ b/app/jj_param.c @@ -2,20 +2,19 @@ #include "./page/page_ui_widget.h" #include "./page/page.h" #include "zf_common_headfile.h" -#include "jj_motion.h" PARAM_INFO Param_Data[DATA_NUM]; soft_iic_info_struct eeprom_param; TYPE_UNION iic_buffer[DATA_IN_FLASH_NUM]; void jj_param_eeprom_init() { - soft_iic_init(&eeprom_param, K24C02_DEV_ADDR, K24C02_SOFT_IIC_DELAY, K24C02_SCL_PIN, K24C02_SDA_PIN); // eeprom初始化 - PARAM_REG(angle_Kp, &an_Kp, EFLOAT, 1, "an_P"); // 注冊 - PARAM_REG(angle_Ki, &an_Ki, EFLOAT, 1, "an_I"); // 注冊 - PARAM_REG(angle_Kd, &an_Kd, EFLOAT, 1, "an_D"); // 注冊 - PARAM_REG(imgax_Kp, &im_Kp, EFLOAT, 1, "im_P"); // 注冊 - PARAM_REG(imgax_Ki, &im_Ki, EFLOAT, 1, "im_I"); // 注冊 - PARAM_REG(imgax_Kd, &im_Kd, EFLOAT, 1, "im_D"); // 注冊 + soft_iic_init(&eeprom_param, K24C02_DEV_ADDR, K24C02_SOFT_IIC_DELAY, K24C02_SCL_PIN, K24C02_SDA_PIN); // eeprom 初始化 + // PARAM_REG(angle_Kp, &an_Kp, EFLOAT, 1, "an_P"); // 注冊 + // PARAM_REG(angle_Ki, &an_Ki, EFLOAT, 1, "an_I"); // 注冊 + // PARAM_REG(angle_Kd, &an_Kd, EFLOAT, 1, "an_D"); // 注冊 + // PARAM_REG(imgax_Kp, &im_Kp, EFLOAT, 1, "im_P"); // 注冊 + // PARAM_REG(imgax_Ki, &im_Ki, EFLOAT, 1, "im_I"); // 注冊 + // PARAM_REG(imgax_Kd, &im_Kd, EFLOAT, 1, "im_D"); // 注冊 for (uint8 i = 0; i < DATA_IN_FLASH_NUM; i++) { diff --git a/app/main.c b/app/main.c index d68f3d6..f08a31a 100644 --- a/app/main.c +++ b/app/main.c @@ -22,46 +22,34 @@ * 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明) ********************************************************************************************************************/ #include "gl_headfile.h" -#include "by_rt_button.h" -#include "by_fan_control.h" #include "./page/page.h" -#include "jj_blueteeth.h" #include "jj_param.h" -#include "./page/page_ui_widget.h" #include "by_buzzer.h" -#include "jj_motion.h" -#include "by_imu.h" int main(void) { - clock_init(SYSTEM_CLOCK_120M); + clock_init(SYSTEM_CLOCK_144M); system_delay_init(); debug_init(); - mt9v03x_init(); + // mt9v03x_init(); ips200_init(IPS200_TYPE_SPI); - by_gpio_init(); - by_exit_init(); - by_pwm_init(); - jj_bt_init(); + usb_cdc_init(); by_buzzer_init(); - while (imu660ra_init()) - ; - jj_param_eeprom_init(); + by_button_init(); + // while (imu660ra_init()) + // ; + // jj_param_eeprom_init(); Page_Init(); - sport_pid_init(); pit_ms_init(TIM6_PIT, 2); pit_ms_init(TIM1_PIT, 2); - // gyroOffset_init(); while (1) { Page_Run(); - jj_bt_run(); queue_pop_read(); - bt_printf("hello:%f,%f\n",out_M,out_yaw); if (mt9v03x_finish_flag) { // 该操作消耗大概 1970 个 tick,折合约 110us memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t))); - //adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17); - //ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); + // adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17); + // ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); mt9v03x_finish_flag = 0; state_type = COMMON_STATE; @@ -72,27 +60,25 @@ int main(void) ElementJudge(); ElementRun(); MidLineTrack(); - } } } - - -void adaptiveThreshold(uint8_t* img_data, uint8_t* output_data, int width, int height, int block, uint8_t clip_value){ - int half_block = block / 2; - for(int y=half_block; y thres ? 255 : 0; } - } - thres = thres / (block * block) - clip_value; - // 进行二值化 - output_data[x+y*width] = img_data[x+y*width]>thres ? 255 : 0; } - } } diff --git a/app/page/page.c b/app/page/page.c index 794ddaa..942940c 100644 --- a/app/page/page.c +++ b/app/page/page.c @@ -1,6 +1,6 @@ #include "page.h" -#include "by_rt_button.h" +#include "by_button.h" PAGE_LIST pagelist[page_max]; static uint8_t page_busy = 0; @@ -89,8 +89,8 @@ uint8_t Page_GetStatus(void) */ void Page_Run(void) { - uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态 - if(temp_status){ + uint8_t temp_status = by_button_get_status(); // 轮询旋钮状态 + if (temp_status) { pagelist[now_page].EventCallback(temp_status); } @@ -118,7 +118,7 @@ void Page_Run(void) } /** - * @brief 页面初始化(注册,构建) ATTENTION 在此处添加新加入的页面 + * @brief 页面初始化(注册,构建)ATTENTION 在此处添加新加入的页面 * */ void Page_Init(void) diff --git a/app/page/page.h b/app/page/page.h index f65d8bf..3d51e41 100644 --- a/app/page/page.h +++ b/app/page/page.h @@ -13,7 +13,7 @@ #include "zf_common_headfile.h" -#include "by_rt_button.h" +#include "by_button.h" enum PageID { PAGE_NULL = -1, @@ -28,11 +28,11 @@ enum PageID { page_max, }; -typedef enum page_event{ - page_event_forward = rotate_button_forward, - page_event_backward = rotate_button_backward, - page_event_press_short = rotate_button_press_short, - page_event_press_long = rotate_button_press_long, +typedef enum page_event { + page_event_forward = button_event_up, + page_event_backward = button_event_down, + page_event_press_short = button_event_center_sp, + page_event_press_long = button_event_center_lp, } page_event; typedef void (*CallbackFunction_t)(void); @@ -45,16 +45,16 @@ typedef struct { EventFunction_t EventCallback; } PAGE_LIST; -//页面注册函数 -#define PAGE_REG(name)\ -do{\ - extern void PageRegister_##name(unsigned char pageID);\ - PageRegister_##name(name);\ -}while(0) +// 页面注册函数 +#define PAGE_REG(name) \ + do { \ + extern void PageRegister_##name(unsigned char pageID); \ + PageRegister_##name(name); \ + } while (0) void Page_Register(uint8_t pageID, char *pageText, - CallbackFunction_t setupCallback, CallbackFunction_t loopCallback, - CallbackFunction_t exitCallback, EventFunction_t eventCallback); + CallbackFunction_t setupCallback, CallbackFunction_t loopCallback, + CallbackFunction_t exitCallback, EventFunction_t eventCallback); void Page_EventTransmit(unsigned char event); void Page_Shift(unsigned char pageID); diff --git a/app/page/page_param.c b/app/page/page_param.c index 40dc086..ef57df5 100644 --- a/app/page/page_param.c +++ b/app/page/page_param.c @@ -1,11 +1,10 @@ #include "jj_param.h" #include "page_ui_widget.h" -#include "jj_motion.h" #include "page.h" #define LINE_HEAD 0 #define LINE_END DATA_NUM - 2 -static char Text[] = "RealTime Param"; +static char Text[] = "Param"; int event_flag = 0; int32_t index_power = 0; static int8_t Curser = LINE_HEAD; // 定义光标位置 @@ -75,7 +74,6 @@ static void Event(page_event event) return; } else if (page_event_press_long == event) { jj_param_update(); - sport_pid_init(); Page_Shift(page_menu); return; } diff --git a/libraries/sdk/Ld/Link.ld b/libraries/sdk/Ld/Link.ld index aa73cb2..e6f4187 100644 --- a/libraries/sdk/Ld/Link.ld +++ b/libraries/sdk/Ld/Link.ld @@ -1 +1,185 @@ -ENTRY( _start ) __stack_size = 2048; PROVIDE( _stack_size = __stack_size ); MEMORY { /* CH32V30x_D8C - CH32V305RB-CH32V305FB CH32V30x_D8 - CH32V303CB-CH32V303RB */ /* FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K */ /* CH32V30x_D8C - CH32V307VC-CH32V307WC-CH32V307RC CH32V30x_D8 - CH32V303VC-CH32V303RC FLASH + RAM supports the following configuration FLASH-192K + RAM-128K FLASH-224K + RAM-96K FLASH-256K + RAM-64K FLASH-288K + RAM-32K */ RAM (xrw) : ORIGIN = 0x20000040, LENGTH = 63K FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K } SECTIONS { .init : { _sinit = .; . = ALIGN(4); KEEP(*(SORT_NONE(.init))) . = ALIGN(4); _einit = .; } >FLASH AT>FLASH .vector : { *(.vector); . = ALIGN(64); } >FLASH AT>FLASH .text : { . = ALIGN(4); *(.text) *(.text.*) *(.rodata) *(.rodata*) *(.glue_7) *(.glue_7t) *(.gnu.linkonce.t.*) . = ALIGN(4); } >FLASH AT>FLASH .fini : { KEEP(*(SORT_NONE(.fini))) . = ALIGN(4); } >FLASH AT>FLASH PROVIDE( _etext = . ); PROVIDE( _eitcm = . ); .preinit_array : { PROVIDE_HIDDEN (__preinit_array_start = .); KEEP (*(.preinit_array)) PROVIDE_HIDDEN (__preinit_array_end = .); } >FLASH AT>FLASH .init_array : { PROVIDE_HIDDEN (__init_array_start = .); KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) PROVIDE_HIDDEN (__init_array_end = .); } >FLASH AT>FLASH .fini_array : { PROVIDE_HIDDEN (__fini_array_start = .); KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) PROVIDE_HIDDEN (__fini_array_end = .); } >FLASH AT>FLASH .ctors : { /* gcc uses crtbegin.o to find the start of the constructors, so we make sure it is first. Because this is a wildcard, it doesn't matter if the user does not actually link against crtbegin.o; the linker won't look for a file to match a wildcard. The wildcard also means that it doesn't matter which directory crtbegin.o is in. */ KEEP (*crtbegin.o(.ctors)) KEEP (*crtbegin?.o(.ctors)) /* We don't want to include the .ctor section from the crtend.o file until after the sorted ctors. The .ctor section from the crtend file contains the end of ctors marker and it must be last */ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) } >FLASH AT>FLASH .dtors : { KEEP (*crtbegin.o(.dtors)) KEEP (*crtbegin?.o(.dtors)) KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) } >FLASH AT>FLASH .dalign : { . = ALIGN(4); PROVIDE(_data_vma = .); } >RAM AT>FLASH .dlalign : { . = ALIGN(4); PROVIDE(_data_lma = .); } >FLASH AT>FLASH .data : { *(.gnu.linkonce.r.*) *(.data .data.*) *(.gnu.linkonce.d.*) . = ALIGN(8); PROVIDE( __global_pointer$ = . + 0x800 ); *(.sdata .sdata.*) *(.sdata2.*) *(.gnu.linkonce.s.*) . = ALIGN(8); *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) . = ALIGN(4); PROVIDE( _edata = .); } >RAM AT>FLASH .bss : { . = ALIGN(4); PROVIDE( _sbss = .); *(.sbss*) *(.gnu.linkonce.sb.*) *(.bss*) *(.gnu.linkonce.b.*) *(COMMON*) . = ALIGN(4); PROVIDE( _ebss = .); } >RAM AT>FLASH PROVIDE( _end = _ebss); PROVIDE( end = . ); .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size : { PROVIDE( _heap_end = . ); . = ALIGN(4); PROVIDE(_susrstack = . ); . = . + __stack_size; PROVIDE( _eusrstack = .); } >RAM } \ No newline at end of file +ENTRY( _start ) + +__stack_size = 2048; + +PROVIDE( _stack_size = __stack_size ); + + +MEMORY +{ +/* CH32V30x_D8C - CH32V305RB-CH32V305FB + CH32V30x_D8 - CH32V303CB-CH32V303RB +*/ +/* + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K +*/ + +/* CH32V30x_D8C - CH32V307VC-CH32V307WC-CH32V307RC + CH32V30x_D8 - CH32V303VC-CH32V303RC + FLASH + RAM supports the following configuration + FLASH-192K + RAM-128K + FLASH-224K + RAM-96K + FLASH-256K + RAM-64K + FLASH-288K + RAM-32K +*/ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 224K +} + + +SECTIONS +{ + + .init : + { + _sinit = .; + . = ALIGN(4); + KEEP(*(SORT_NONE(.init))) + . = ALIGN(4); + _einit = .; + } >FLASH AT>FLASH + + .vector : + { + *(.vector); + . = ALIGN(64); + } >FLASH AT>FLASH + + .text : + { + . = ALIGN(4); + *(.text) + *(.text.*) + *(.rodata) + *(.rodata*) + *(.glue_7) + *(.glue_7t) + *(.gnu.linkonce.t.*) + . = ALIGN(4); + } >FLASH AT>FLASH + + .fini : + { + KEEP(*(SORT_NONE(.fini))) + . = ALIGN(4); + } >FLASH AT>FLASH + + PROVIDE( _etext = . ); + PROVIDE( _eitcm = . ); + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH AT>FLASH + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH AT>FLASH + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH AT>FLASH + + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } >FLASH AT>FLASH + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } >FLASH AT>FLASH + + .dalign : + { + . = ALIGN(4); + PROVIDE(_data_vma = .); + } >RAM AT>FLASH + + .dlalign : + { + . = ALIGN(4); + PROVIDE(_data_lma = .); + } >FLASH AT>FLASH + + .data : + { + *(.gnu.linkonce.r.*) + *(.data .data.*) + *(.gnu.linkonce.d.*) + . = ALIGN(8); + PROVIDE( __global_pointer$ = . + 0x800 ); + *(.sdata .sdata.*) + *(.sdata2.*) + *(.gnu.linkonce.s.*) + . = ALIGN(8); + *(.srodata.cst16) + *(.srodata.cst8) + *(.srodata.cst4) + *(.srodata.cst2) + *(.srodata .srodata.*) + . = ALIGN(4); + PROVIDE( _edata = .); + } >RAM AT>FLASH + + .bss : + { + . = ALIGN(4); + PROVIDE( _sbss = .); + *(.sbss*) + *(.gnu.linkonce.sb.*) + *(.bss*) + *(.gnu.linkonce.b.*) + *(COMMON*) + . = ALIGN(4); + PROVIDE( _ebss = .); + } >RAM AT>FLASH + + PROVIDE( _end = _ebss); + PROVIDE( end = . ); + + .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size : + { + PROVIDE( _heap_end = . ); + . = ALIGN(4); + PROVIDE(_susrstack = . ); + . = . + __stack_size; + PROVIDE( _eusrstack = .); + } >RAM + +} + + + diff --git a/libraries/zf_device/zf_device_ips200.c b/libraries/zf_device/zf_device_ips200.c index fcfd78e..201c737 100644 --- a/libraries/zf_device/zf_device_ips200.c +++ b/libraries/zf_device/zf_device_ips200.c @@ -322,8 +322,8 @@ static void ips200_set_region(uint16 x1, uint16 y1, uint16 x2, uint16 y2) // zf_assert(y2 < ips200_y_max); ips200_write_command(0x2a); - ips200_write_16bit_data(x1); - ips200_write_16bit_data(x2); + ips200_write_16bit_data(x1+80); + ips200_write_16bit_data(x2+80); ips200_write_command(0x2b); ips200_write_16bit_data(y1); diff --git a/libraries/zf_device/zf_device_ips200.h b/libraries/zf_device/zf_device_ips200.h index 6169e6b..38a6c07 100644 --- a/libraries/zf_device/zf_device_ips200.h +++ b/libraries/zf_device/zf_device_ips200.h @@ -110,7 +110,7 @@ // 例:C5-C12 IPS200_DATAPORT 设置为 GPIOC DATA_START_NUM 设置为 5 // --------------------双排 SPI 接口两寸屏幕引脚定义--------------------// -#define IPS200_DEFAULT_DISPLAY_DIR (IPS200_PORTAIT) // 默认的显示方向 +#define IPS200_DEFAULT_DISPLAY_DIR (IPS200_CROSSWISE_180) // 默认的显示方向 #define IPS200_DEFAULT_PENCOLOR (RGB565_YELLOW) // 默认的画笔颜色 #define IPS200_DEFAULT_BGCOLOR (RGB565_BLACK) // 默认的背景颜色 #define IPS200_DEFAULT_DISPLAY_FONT (IPS200_8X16_FONT) // 默认的字体模式 diff --git a/libraries/zf_device/zf_device_k24c02.h b/libraries/zf_device/zf_device_k24c02.h index 6d4a614..b8f479c 100644 --- a/libraries/zf_device/zf_device_k24c02.h +++ b/libraries/zf_device/zf_device_k24c02.h @@ -54,8 +54,8 @@ #if K24C02_USE_SOFT_IIC // ɫIJȷ ɫҵľûõ //==================================================== IIC ==================================================== #define K24C02_SOFT_IIC_DELAY (500) // IIC ʱʱ ֵԽС IIC ͨԽ -#define K24C02_SCL_PIN (E3) // IIC SCL K24C02 SCL -#define K24C02_SDA_PIN (E2 ) // IIC SDA K24C02 SDA +#define K24C02_SCL_PIN (D13) // IIC SCL K24C02 SCL +#define K24C02_SDA_PIN (D14) // IIC SDA K24C02 SDA //==================================================== IIC ==================================================== #else //====================================================Ӳ IIC ==================================================== @@ -69,7 +69,7 @@ #define K24C02_TIMEOUT_COUNT (0x00FF) // K24C02 ʱ //================================================ K24C02 ڲַ================================================ -#define K24C02_DEV_ADDR (0xA0 >> 1) // IICдʱĵַֽ +1Ϊȡ +#define K24C02_DEV_ADDR (0xA0 >> 1) // IIC дʱĵַֽ +1 Ϊȡ //================================================ K24C02 ڲַ================================================ #define K24C02_SIZE (256) // 256 byte diff --git a/libraries/zf_device/zf_device_mt9v03x_dvp.h b/libraries/zf_device/zf_device_mt9v03x_dvp.h index 8792a05..c1b8d56 100644 --- a/libraries/zf_device/zf_device_mt9v03x_dvp.h +++ b/libraries/zf_device/zf_device_mt9v03x_dvp.h @@ -95,18 +95,18 @@ #define MT9V03X_IMAGE_SIZE ( MT9V03X_W * MT9V03X_H ) // ͼСܳ 65535 #define MT9V03X_COF_BUFFER_SIZE ( 64 ) // ôڻС 64 -#define MT9V03X_AUTO_EXP_DEF (0 ) // Զع ĬϲԶع Χ [0-63] 0Ϊر - // Զع⿪ EXP_TIMEԶعʱ +#define MT9V03X_AUTO_EXP_DEF (0 ) // Զع ĬϲԶع Χ [0-63] 0 Ϊر + // Զع⿪ EXP_TIME Զعʱ // һDzҪԶع ߷dzȵԳԶع⣬ͼȶ #define MT9V03X_EXP_TIME_DEF (512) // عʱ ͷյԶعʱ䣬ùΪعֵ -#define MT9V03X_FPS_DEF (50 ) // ͼ֡ ͷյԶFPSΪFPS -#define MT9V03X_LR_OFFSET_DEF (0 ) // ͼƫ ֵ ƫ ֵ ƫ Ϊ188 376 752ʱ޷ƫ +#define MT9V03X_FPS_DEF (50 ) // ͼ֡ ͷյԶ FPSΪ FPS +#define MT9V03X_LR_OFFSET_DEF (0 ) // ͼƫ ֵ ƫ ֵ ƫ Ϊ 188 376 752 ʱ޷ƫ // ͷƫݺԶƫƣüƫ -#define MT9V03X_UD_OFFSET_DEF (0 ) // ͼƫ ֵ ƫ ֵ ƫ Ϊ120 240 480ʱ޷ƫ +#define MT9V03X_UD_OFFSET_DEF (0 ) // ͼƫ ֵ ƫ ֵ ƫ Ϊ 120 240 480 ʱ޷ƫ // ͷƫݺԶƫƣüƫ #define MT9V03X_GAIN_DEF (32 ) // ͼ Χ [16-64] عʱ̶¸ıͼ̶ -#define MT9V03X_PCLK_MODE_DEF (1 ) // ʱģʽ Χ [0-1] Ĭϣ0 ѡΪ[0ź,1ź] - // ͨΪ0ʹCH32V307DVPӿڻSTM32DCMIӿڲɼҪΪ1 +#define MT9V03X_PCLK_MODE_DEF (1 ) // ʱģʽ Χ [0-1] Ĭϣ0 ѡΪ[0źţ1ź] + // ͨΪ 0ʹ CH32V307 DVP ӿڻ STM32 DCMI ӿڲɼҪΪ 1 // MT9V034 V1.5 Լϰ汾ָ֧ // ͷö @@ -121,7 +121,7 @@ typedef enum MT9V03X_LR_OFFSET, // ͼƫ MT9V03X_UD_OFFSET, // ͼƫ MT9V03X_GAIN, // ͼƫ - MT9V03X_PCLK_MODE, // ʱģʽ(MT9V034 V1.5Լϰ汾ָ֧) + MT9V03X_PCLK_MODE, // ʱģʽ ( MT9V034 V1.5 Լϰ汾ָ֧) MT9V03X_CONFIG_FINISH, // λҪռλ MT9V03X_COLOR_GET_WHO_AM_I = 0xEF,