├── Readme.md
├── STM32
├── Core
│ ├── core_cm3.c
│ ├── core_cm3.h
│ ├── startup_stm32f100_hd_vl.s
│ ├── startup_stm32f100_ld_vl.s
│ ├── startup_stm32f100_md_vl.s
│ ├── startup_stm32f101_103_hd_Min256k.s
│ ├── startup_stm32f101_103_ld_Max32k.s
│ ├── startup_stm32f101_103_md_Max128k.s
│ ├── startup_stm32f101_103_xl_Max1024k.s
│ └── startup_stm32f105_107_cl.s
├── Driver
│ ├── Baffle
│ │ └── Baffle.h
│ ├── CapacityDetector
│ │ ├── CapacityDetector.c
│ │ └── CapacityDetector.h
│ ├── Conveyor
│ │ ├── Conveyor.c
│ │ └── Conveyor.h
│ ├── Readme.md
│ ├── Slider
│ │ ├── Slider.c
│ │ └── Slider.h
│ ├── Stepper
│ │ ├── Stepper.c
│ │ └── Stepper.h
│ └── Ultrasonic_Ranging
│ │ ├── Ultrasonic_Ranging.c
│ │ └── Ultrasonic_Ranging.h
├── Hardware
│ ├── FreeIO
│ │ ├── FreeIO.c
│ │ └── FreeIO.h
│ └── TIM
│ │ ├── TIM_Init.c
│ │ └── TIM_Init.h
├── Project
│ ├── Commands.c
│ ├── Commands.c.orig
│ ├── Commands.h
│ ├── DebugConfig
│ │ └── Target_1_STM32F103C8_1.0.0.dbgconf
│ ├── EventRecorderStub.scvd
│ ├── Objects
│ │ └── Project.hex
│ ├── Project.uvguix.h13
│ ├── Project.uvoptx
│ ├── Project.uvprojx
│ ├── USART1_IRQ.c
│ ├── USART1_IRQ.c.orig
│ ├── USART1_IRQ.h
│ ├── USART1_IRQ.h.orig
│ ├── main.c
│ ├── main.c.orig
│ ├── stm32f10x.h
│ ├── stm32f10x.h.orig
│ ├── stm32f10x_conf.h
│ ├── stm32f10x_conf.h.orig
│ ├── stm32f10x_it.c
│ ├── stm32f10x_it.c.orig
│ ├── stm32f10x_it.h
│ ├── stm32f10x_it.h.orig
│ ├── system_stm32f10x.c
│ ├── system_stm32f10x.c.orig
│ ├── system_stm32f10x.h
│ └── system_stm32f10x.h.orig
├── Readme.md
├── Software
│ ├── ANO_tc
│ │ ├── ANO_tc.c
│ │ └── ANO_tc.h
│ ├── BLUEROCKER
│ │ ├── BlueRocker.c
│ │ ├── BlueRocker.c.orig
│ │ └── BlueRocker.h
│ ├── Bit_operation
│ │ └── Bit_operation.h
│ ├── PID
│ │ ├── PID.c
│ │ ├── PID.c.orig
│ │ └── PID.h
│ ├── SystemClock
│ │ ├── SystemClock.c
│ │ └── SystemClock.h
│ ├── sys
│ │ ├── sys.c
│ │ └── sys.h
│ └── usart
│ │ ├── usart.c
│ │ └── usart.h
├── Stm32F10x_FWLIB
│ ├── inc
│ │ ├── misc.h
│ │ ├── stm32f10x_adc.h
│ │ ├── stm32f10x_bkp.h
│ │ ├── stm32f10x_can.h
│ │ ├── stm32f10x_cec.h
│ │ ├── stm32f10x_crc.h
│ │ ├── stm32f10x_dac.h
│ │ ├── stm32f10x_dbgmcu.h
│ │ ├── stm32f10x_dma.h
│ │ ├── stm32f10x_exti.h
│ │ ├── stm32f10x_flash.h
│ │ ├── stm32f10x_fsmc.h
│ │ ├── stm32f10x_gpio.h
│ │ ├── stm32f10x_i2c.h
│ │ ├── stm32f10x_iwdg.h
│ │ ├── stm32f10x_pwr.h
│ │ ├── stm32f10x_rcc.h
│ │ ├── stm32f10x_rtc.h
│ │ ├── stm32f10x_sdio.h
│ │ ├── stm32f10x_spi.h
│ │ ├── stm32f10x_tim.h
│ │ ├── stm32f10x_usart.h
│ │ └── stm32f10x_wwdg.h
│ └── src
│ │ ├── misc.c
│ │ ├── stm32f10x_adc.c
│ │ ├── stm32f10x_bkp.c
│ │ ├── stm32f10x_can.c
│ │ ├── stm32f10x_cec.c
│ │ ├── stm32f10x_crc.c
│ │ ├── stm32f10x_dac.c
│ │ ├── stm32f10x_dbgmcu.c
│ │ ├── stm32f10x_dma.c
│ │ ├── stm32f10x_exti.c
│ │ ├── stm32f10x_flash.c
│ │ ├── stm32f10x_fsmc.c
│ │ ├── stm32f10x_gpio.c
│ │ ├── stm32f10x_i2c.c
│ │ ├── stm32f10x_iwdg.c
│ │ ├── stm32f10x_pwr.c
│ │ ├── stm32f10x_rcc.c
│ │ ├── stm32f10x_rtc.c
│ │ ├── stm32f10x_sdio.c
│ │ ├── stm32f10x_spi.c
│ │ ├── stm32f10x_tim.c
│ │ ├── stm32f10x_usart.c
│ │ └── stm32f10x_wwdg.c
└── keilkill.bat
├── Software
├── FunctionAreas
│ └── FunctionAreas.py
├── GarbageFunction
│ └── GarbageMessage.py
├── Hardware
│ └── Slave.py
├── ImageProcessing
│ ├── Detector.py
│ ├── ResizeTo.py
│ ├── StandardExample.jpg
│ ├── VideoPlayer.py
│ ├── multiModeMask.jpg
│ └── singleModeMask.jpg
├── QtUI
│ ├── ConvertUIToPy.bat
│ ├── ProcessBar.py
│ ├── RoundProcessBar.png
│ ├── UI.py
│ ├── UI_Child.py
│ └── mainwindow.ui
├── Start.py
├── Start.sh
└── WorkingProcess
│ ├── MainProcess.py
│ └── WorkingMode.py
├── Xception
├── Live.py
├── Train.py
├── Valid.py
└── tensorboard.png
├── images
├── FrontView.jpg
└── SideView.jpg
├── tools
├── Readme.md
├── Sample
│ ├── 1.jpg
│ ├── mask.png
│ └── preprocess.py
├── cameraTest
│ └── cameraTest.py
└── hasObject
│ └── hasObject.py
├── yolo-fastest
├── backup
│ └── yolo-fastest_best.weights
├── test.png
├── train.data
├── yolo-fastest.cfg
└── yolo-fastest.conv.109
└── 第七届全国大学生工程训练综合能力竞赛(重庆)命题与运行-终稿20210222.pdf
/Readme.md:
--------------------------------------------------------------------------------
1 | # 一个基于Xception图像识别的垃圾分类项目
2 |
3 | 正视图
4 | 
5 | 侧视图
6 | 
7 | UI图
8 |
9 |
10 | ## 硬件要求
11 | **请务必使用4G及以上的Linux硬件**
12 | **建议使用Jetson Nano(约26fps) 或树莓派4B (约0.3fps)**
13 |
14 | > 2022-05-08更新: 建议使用RKNN(RockChip)代替Jetson.
15 |
16 | ## 图像识别部分
17 | ### Xception 图像分类实现
18 | #### 模型训练
19 | 请务必使用自己的摄像头针对自己的设备添加足够训练集之后再进行训练。
20 | ```
21 | cd Xception
22 | python ./Train.py
23 | ```
24 | 注意根据实际路径修改以下内容:
25 | ```
26 | # Configure
27 | # 以下内容请和 Valid.py 中的匹配
28 | ## 源图片的总文件夹位置
29 | Base_Dir = "E:/TensorFlow/datasets/garbage_finally/"
30 | train_dir = Base_Dir + "Train"
31 | validation_dir = Base_Dir + "Valid"
32 | log_dir = "./log"
33 | ```
34 |
35 | #### 模型校验
36 | ```
37 | cd Xception
38 | python ./Valid.py
39 | ```
40 | 注意根据实际文件路径修改以下内容:
41 | ```
42 | # Configure
43 | ## 源图片的总文件夹位置, 尽量保证输入图片的长宽比为1:1即可, 程序会自动缩放。
44 | Base_Dir = '../../datasets/garbage_finally/'
45 | ## 权重文件的位置
46 | Weight_File_Path = "./weights/epoch-140-val_acc-0.9651-acc_top3-1.0000-acc_top5-1.0000.hdf5"
47 | ```
48 |
49 | #### 实时监测
50 | ```
51 | cd Xception
52 | python ./Live.py
53 | ```
54 | 至此, Xception图像分类部分完毕。但是仍然无法进行实际的图像识别流程, 原因如下文 `Xception具体操作流程`。
55 |
56 | #### TensorBoard绘图
57 | ```
58 | cd Xception
59 | tensorboard --logdir ./log
60 | ```
61 | 然后根据提示访问对应网址即可
62 | 
63 |
64 | ### Xception具体操作流程
65 | 由于图像分类无法对未知物体或无物体时的结果进行正确预测, 所以需要进行一些预处理。
66 |
67 |
68 |
69 | ### yolo-fastest 图像识别实现
70 | 由于RK3399, Jetson Nano等廉价Linux开发板算力较弱无法流畅运行yolov4, 外加yolov4训练对电脑需求过高, 故本项目不再使用yolov4实现。
71 | 本项目使用了基于华为垃圾分类竞赛数据集基础上的拓展数据集 (读起来真拗口。。)
72 |
73 | 本项目使用的源dataset (VOC格式): https://aistudio.baidu.com/aistudio/datasetdetail/70610
74 | 本项目使用的源dataset (图像分类格式):
75 |
76 | 我根据比赛要求改进的dataset:
77 | [Classification](./dataset/Classification)
78 | [yolo-mark](./dataset/yolo-mark)
79 |
80 | 需要配置[Darknet](https://github.com/AlexeyAB/darknet)环境。
81 |
82 | 由于竞赛需求, 本人只使用了上述数据集的部分种类
83 | ```
84 | classes = {"干电池" : 0, "陶瓷器皿" : 1, "易拉罐" : 2, "烟蒂" : 3, "果皮果肉" : 4, "菜帮菜叶" : 5, "饮料瓶" : 6}
85 | ```
86 |
87 | 本人的 yolo-fastest 实现:
88 | 使用方法:
89 | ```
90 | cd yolo-fastest
91 | darknet detector demo .\train.data .\yolo-fastest.cfg .\backup\yolo-fastest_best.weights -c 0
92 | ```
93 | 
94 |
95 | 但是实测效果一般, 故比赛中又改为了 Xception。
96 |
97 | ## STM32端具体实现
98 |
99 | ## 机械结构及设计思路
100 | 暂未整理
101 |
--------------------------------------------------------------------------------
/STM32/Driver/Baffle/Baffle.h:
--------------------------------------------------------------------------------
1 | #ifndef _BAFFLE_H_
2 | #define _BAFFLE_H_
3 |
4 | #define Left_Baffle_Open() TIM_SetCompare2(TIM4, 220)
5 | #define Left_Baffle_Close() TIM_SetCompare2(TIM4, 50)
6 |
7 |
8 | #define Right_Baffle_Open() TIM_SetCompare3(TIM4, 87)
9 | #define Right_Baffle_Close() TIM_SetCompare3(TIM4, 250)
10 |
11 | #define Middle_Baffle_Rotate(angle) TIM_SetCompare4(TIM4, angle)
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/STM32/Driver/CapacityDetector/CapacityDetector.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/CapacityDetector/CapacityDetector.c
--------------------------------------------------------------------------------
/STM32/Driver/CapacityDetector/CapacityDetector.h:
--------------------------------------------------------------------------------
1 | #ifndef _CAPACITYDETECTOR_H_
2 | #define _CAPACITYDETECTOR_H_
3 |
4 | void CapacityDetectorInit(void);
5 |
6 | inline void CapacityDetector_Handler(void);
7 |
8 | void CapacityDetector_getValue(double *rec, double *kit, double *oth, double *harm);
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/STM32/Driver/Conveyor/Conveyor.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/Conveyor/Conveyor.c
--------------------------------------------------------------------------------
/STM32/Driver/Conveyor/Conveyor.h:
--------------------------------------------------------------------------------
1 | #ifndef _CONVEYOR_H_
2 | #define _CONVEYOR_H_
3 |
4 | //Configs
5 | #define CONVEYOR_DIR_PORT GPIOA
6 | #define CONVEYOR_DIR_PIN GPIO_Pin_0
7 | #define CONVEYOR_STEP_PORT GPIOA
8 | #define CONVEYOR_STEP_PIN GPIO_Pin_1
9 | #define CONVEYOR_DELAY_PER_HALF_SETP 5000 //5ms 10ms 100hz 720 1000
10 |
11 |
12 | //APIs
13 |
14 | /**
15 | * @brief Init Conveyor.
16 | * @param None
17 | * @retval None
18 | * @note None
19 | */
20 | void ConveyorInit(void);
21 |
22 | void ConveyorForward(void);
23 |
24 | void ConveyorBackward(void);
25 |
26 | void ConveyorStop(void);
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/STM32/Driver/Readme.md:
--------------------------------------------------------------------------------
1 | 这里一般存放一些软件模拟的硬件协议
2 | 比如模拟I2C 模拟并行等等。
--------------------------------------------------------------------------------
/STM32/Driver/Slider/Slider.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/Slider/Slider.c
--------------------------------------------------------------------------------
/STM32/Driver/Slider/Slider.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/Slider/Slider.h
--------------------------------------------------------------------------------
/STM32/Driver/Stepper/Stepper.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/Stepper/Stepper.c
--------------------------------------------------------------------------------
/STM32/Driver/Stepper/Stepper.h:
--------------------------------------------------------------------------------
1 | #ifndef _STEPPER_H_
2 | #define _STEPPER_H_
3 |
4 | #include "stm32f10x.h"
5 |
6 | typedef struct
7 | {
8 | GPIO_TypeDef* DIR_Port;
9 | uint16_t DIR_Pin;
10 | GPIO_TypeDef* STEP_Port;
11 | uint16_t STEP_Pin;
12 | }Stepper_TypeDef;
13 |
14 | //Configs
15 | #define Stepper_ClockEnable() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE)
16 |
17 | /**
18 | * @brief: Init Stepper
19 | * @param: Port and Pin for Stepper.
20 | * @return: Stepper_TypeDef stepper.
21 | */
22 |
23 | Stepper_TypeDef Stepper_Init(GPIO_TypeDef* DIR_Port, uint16_t DIR_Pin, GPIO_TypeDef* STEP_Port, uint16_t STEP_Pin);
24 |
25 |
26 | /**********Automatic APIs***********/
27 |
28 | /**
29 | * @brief: Turn the stepper counterclockwise.
30 | * @param:
31 | * Stepper_TypeDef* stepper -> The stepper to be operated.
32 | * uint16_t steps -> The number of steps.
33 | * uint16_t delay -> The interval between each *half* step.
34 | * @note:
35 | */
36 | void Stepper_Forward(Stepper_TypeDef* stepper, uint16_t steps, uint16_t delayus);
37 |
38 | /**
39 | * @brief: Turn the stepper clockwise.
40 | * @param:
41 | * Stepper_TypeDef* stepper -> The stepper to be operated.
42 | * uint16_t steps -> The number of steps.
43 | * uint16_t delay -> The interval between each *half* step.
44 | * @note:
45 | */
46 | void Stepper_Backward(Stepper_TypeDef* stepper, uint16_t steps, uint16_t delayus);
47 |
48 |
49 | /**********Manual APIs***********/
50 |
51 | /**
52 | * @brief: Switch the stepper to counterclockwise Mode.
53 | * @param: Stepper_TypeDef* stepper -> The stepper to be operated.
54 | */
55 | void Stepper_ForwardMode(Stepper_TypeDef* stepper);
56 |
57 | /**
58 | * @brief: Switch the stepper to clockwise Mode.
59 | * @param: Stepper_TypeDef* stepper -> The stepper to be operated.
60 | */
61 | void Stepper_BackwardMode(Stepper_TypeDef* stepper);
62 |
63 | /**
64 | * @brief: Run Single Step(inline function).
65 | * @param:
66 | * Stepper_TypeDef* stepper -> The stepper to be operated.
67 | * delayus -> The interval between each *half* step.
68 | */
69 | void Stepper_SingleStep(Stepper_TypeDef* stepper, uint16_t delayus);
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/STM32/Driver/Ultrasonic_Ranging/Ultrasonic_Ranging.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/Ultrasonic_Ranging/Ultrasonic_Ranging.c
--------------------------------------------------------------------------------
/STM32/Driver/Ultrasonic_Ranging/Ultrasonic_Ranging.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Driver/Ultrasonic_Ranging/Ultrasonic_Ranging.h
--------------------------------------------------------------------------------
/STM32/Hardware/FreeIO/FreeIO.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Hardware/FreeIO/FreeIO.c
--------------------------------------------------------------------------------
/STM32/Hardware/FreeIO/FreeIO.h:
--------------------------------------------------------------------------------
1 | void FreeC13_15(void);
2 |
--------------------------------------------------------------------------------
/STM32/Hardware/TIM/TIM_Init.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Hardware/TIM/TIM_Init.c
--------------------------------------------------------------------------------
/STM32/Hardware/TIM/TIM_Init.h:
--------------------------------------------------------------------------------
1 | #ifndef _TIM_INIT_H_
2 | #define _TIM_INIT_H_
3 |
4 | #include "stm32f10x.h"
5 |
6 | void TIM2_PWM_Init(uint16_t arr,uint16_t psc);
7 |
8 | void TIM3_Timer_Init(uint16_t arr,uint16_t psc);
9 |
10 | void TIM3_PWM_Init(uint16_t arr,uint16_t psc);
11 |
12 | void TIM4_Timer_Init(uint16_t arr,uint16_t psc);
13 |
14 | void TIM4_PWM_Init(uint16_t arr,uint16_t psc);
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/STM32/Project/Commands.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/Commands.c
--------------------------------------------------------------------------------
/STM32/Project/Commands.c.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/Commands.c.orig
--------------------------------------------------------------------------------
/STM32/Project/Commands.h:
--------------------------------------------------------------------------------
1 | #ifndef _AT_COMMAND_H_
2 | #define _AT_COMMAND_H_
3 | #include "stm32f10x.h"
4 |
5 | uint8_t Command(uint8_t* Rec,uint8_t len);
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/STM32/Project/DebugConfig/Target_1_STM32F103C8_1.0.0.dbgconf:
--------------------------------------------------------------------------------
1 | // File: STM32F101_102_103_105_107.dbgconf
2 | // Version: 1.0.0
3 | // Note: refer to STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx Reference manual (RM0008)
4 | // STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx datasheets
5 |
6 | // <<< Use Configuration Wizard in Context Menu >>>
7 |
8 | // Debug MCU configuration register (DBGMCU_CR)
9 | // Reserved bits must be kept at reset value
10 | // DBG_TIM11_STOP TIM11 counter stopped when core is halted
11 | // DBG_TIM10_STOP TIM10 counter stopped when core is halted
12 | // DBG_TIM9_STOP TIM9 counter stopped when core is halted
13 | // DBG_TIM14_STOP TIM14 counter stopped when core is halted
14 | // DBG_TIM13_STOP TIM13 counter stopped when core is halted
15 | // DBG_TIM12_STOP TIM12 counter stopped when core is halted
16 | // DBG_CAN2_STOP Debug CAN2 stopped when core is halted
17 | // DBG_TIM7_STOP TIM7 counter stopped when core is halted
18 | // DBG_TIM6_STOP TIM6 counter stopped when core is halted
19 | // DBG_TIM5_STOP TIM5 counter stopped when core is halted
20 | // DBG_TIM8_STOP TIM8 counter stopped when core is halted
21 | // DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted
22 | // DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted
23 | // DBG_CAN1_STOP Debug CAN1 stopped when Core is halted
24 | // DBG_TIM4_STOP TIM4 counter stopped when core is halted
25 | // DBG_TIM3_STOP TIM3 counter stopped when core is halted
26 | // DBG_TIM2_STOP TIM2 counter stopped when core is halted
27 | // DBG_TIM1_STOP TIM1 counter stopped when core is halted
28 | // DBG_WWDG_STOP Debug window watchdog stopped when core is halted
29 | // DBG_IWDG_STOP Debug independent watchdog stopped when core is halted
30 | // DBG_STANDBY Debug standby mode
31 | // DBG_STOP Debug stop mode
32 | // DBG_SLEEP Debug sleep mode
33 | //
34 | DbgMCU_CR = 0x00000007;
35 |
36 | // <<< end of configuration section >>>
37 |
--------------------------------------------------------------------------------
/STM32/Project/EventRecorderStub.scvd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/STM32/Project/USART1_IRQ.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/USART1_IRQ.c
--------------------------------------------------------------------------------
/STM32/Project/USART1_IRQ.c.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/USART1_IRQ.c.orig
--------------------------------------------------------------------------------
/STM32/Project/USART1_IRQ.h:
--------------------------------------------------------------------------------
1 | #ifndef _USART1_IRQ_H_
2 | #define _USART1_IRQ_H_
3 |
4 | #include "stm32f10x.h"
5 |
6 | #define USART1_BUF_LEN 32
7 |
8 | #define USART1_READLINE 1
9 |
10 | void USART1_Handler(void);
11 |
12 | #if USART1_READLINE
13 | /**
14 | * @brief: Gets USART1 buffer data.
15 | * @param: uint8_t* buffer.
16 | * @return: length of
17 | */
18 | uint16_t USART1_ReadLine(uint8_t* buf);
19 | #endif
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/STM32/Project/USART1_IRQ.h.orig:
--------------------------------------------------------------------------------
1 | #ifndef _USART1_IRQ_H_
2 | #define _USART1_IRQ_H_
3 |
4 | #include "stm32f10x.h"
5 |
6 | #define USART1_BUF_LEN 32
7 |
8 | #define USART1_READLINE 1
9 |
10 | void USART1_Handler(void);
11 |
12 | #if USART1_READLINE
13 | /**
14 | * @brief: Gets USART1 buffer data.
15 | * @param: uint8_t* buffer.
16 | * @return: length of
17 | */
18 | uint16_t USART1_ReadLine(uint8_t* buf);
19 | #endif
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/STM32/Project/main.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/main.c
--------------------------------------------------------------------------------
/STM32/Project/main.c.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/main.c.orig
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/stm32f10x.h
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x.h.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/stm32f10x.h.orig
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x_conf.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 08-April-2011
7 | * @brief Library configuration file.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | *
© COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Define to prevent recursive inclusion -------------------------------------*/
23 | #ifndef __STM32F10x_CONF_H
24 | #define __STM32F10x_CONF_H
25 |
26 | /* Includes ------------------------------------------------------------------*/
27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
28 | #include "stm32f10x_adc.h"
29 | #include "stm32f10x_bkp.h"
30 | #include "stm32f10x_can.h"
31 | #include "stm32f10x_cec.h"
32 | #include "stm32f10x_crc.h"
33 | #include "stm32f10x_dac.h"
34 | #include "stm32f10x_dbgmcu.h"
35 | #include "stm32f10x_dma.h"
36 | #include "stm32f10x_exti.h"
37 | #include "stm32f10x_flash.h"
38 | #include "stm32f10x_fsmc.h"
39 | #include "stm32f10x_gpio.h"
40 | #include "stm32f10x_i2c.h"
41 | #include "stm32f10x_iwdg.h"
42 | #include "stm32f10x_pwr.h"
43 | #include "stm32f10x_rcc.h"
44 | #include "stm32f10x_rtc.h"
45 | #include "stm32f10x_sdio.h"
46 | #include "stm32f10x_spi.h"
47 | #include "stm32f10x_tim.h"
48 | #include "stm32f10x_usart.h"
49 | #include "stm32f10x_wwdg.h"
50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
51 |
52 | /* Exported types ------------------------------------------------------------*/
53 | /* Exported constants --------------------------------------------------------*/
54 | /* Uncomment the line below to expanse the "assert_param" macro in the
55 | Standard Peripheral Library drivers code */
56 | /* #define USE_FULL_ASSERT 1 */
57 |
58 | /* Exported macro ------------------------------------------------------------*/
59 | #ifdef USE_FULL_ASSERT
60 |
61 | /**
62 | * @brief The assert_param macro is used for function's parameters check.
63 | * @param expr: If expr is false, it calls assert_failed function which reports
64 | * the name of the source file and the source line number of the call
65 | * that failed. If expr is true, it returns no value.
66 | * @retval None
67 | */
68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
69 | /* Exported functions ------------------------------------------------------- */
70 | void assert_failed(uint8_t* file, uint32_t line);
71 | #else
72 | #define assert_param(expr) ((void)0)
73 | #endif /* USE_FULL_ASSERT */
74 |
75 | #endif /* __STM32F10x_CONF_H */
76 |
77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
78 |
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x_conf.h.orig:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 08-April-2011
7 | * @brief Library configuration file.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Define to prevent recursive inclusion -------------------------------------*/
23 | #ifndef __STM32F10x_CONF_H
24 | #define __STM32F10x_CONF_H
25 |
26 | /* Includes ------------------------------------------------------------------*/
27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
28 | #include "stm32f10x_adc.h"
29 | #include "stm32f10x_bkp.h"
30 | #include "stm32f10x_can.h"
31 | #include "stm32f10x_cec.h"
32 | #include "stm32f10x_crc.h"
33 | #include "stm32f10x_dac.h"
34 | #include "stm32f10x_dbgmcu.h"
35 | #include "stm32f10x_dma.h"
36 | #include "stm32f10x_exti.h"
37 | #include "stm32f10x_flash.h"
38 | #include "stm32f10x_fsmc.h"
39 | #include "stm32f10x_gpio.h"
40 | #include "stm32f10x_i2c.h"
41 | #include "stm32f10x_iwdg.h"
42 | #include "stm32f10x_pwr.h"
43 | #include "stm32f10x_rcc.h"
44 | #include "stm32f10x_rtc.h"
45 | #include "stm32f10x_sdio.h"
46 | #include "stm32f10x_spi.h"
47 | #include "stm32f10x_tim.h"
48 | #include "stm32f10x_usart.h"
49 | #include "stm32f10x_wwdg.h"
50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
51 |
52 | /* Exported types ------------------------------------------------------------*/
53 | /* Exported constants --------------------------------------------------------*/
54 | /* Uncomment the line below to expanse the "assert_param" macro in the
55 | Standard Peripheral Library drivers code */
56 | /* #define USE_FULL_ASSERT 1 */
57 |
58 | /* Exported macro ------------------------------------------------------------*/
59 | #ifdef USE_FULL_ASSERT
60 |
61 | /**
62 | * @brief The assert_param macro is used for function's parameters check.
63 | * @param expr: If expr is false, it calls assert_failed function which reports
64 | * the name of the source file and the source line number of the call
65 | * that failed. If expr is true, it returns no value.
66 | * @retval None
67 | */
68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
69 | /* Exported functions ------------------------------------------------------- */
70 | void assert_failed(uint8_t* file, uint32_t line);
71 | #else
72 | #define assert_param(expr) ((void)0)
73 | #endif /* USE_FULL_ASSERT */
74 |
75 | #endif /* __STM32F10x_CONF_H */
76 |
77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
78 |
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x_it.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/stm32f10x_it.c
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x_it.c.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Project/stm32f10x_it.c.orig
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x_it.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 08-April-2011
7 | * @brief This file contains the headers of the interrupt handlers.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Define to prevent recursive inclusion -------------------------------------*/
23 | #ifndef __STM32F10x_IT_H
24 | #define __STM32F10x_IT_H
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | #include "stm32f10x.h"
32 |
33 | /* Exported types ------------------------------------------------------------*/
34 | /* Exported constants --------------------------------------------------------*/
35 | /* Exported macro ------------------------------------------------------------*/
36 | /* Exported functions ------------------------------------------------------- */
37 |
38 | void NMI_Handler(void);
39 | void HardFault_Handler(void);
40 | void MemManage_Handler(void);
41 | void BusFault_Handler(void);
42 | void UsageFault_Handler(void);
43 | void SVC_Handler(void);
44 | void DebugMon_Handler(void);
45 | void PendSV_Handler(void);
46 | void SysTick_Handler(void);
47 |
48 | #ifdef __cplusplus
49 | }
50 | #endif
51 |
52 | #endif /* __STM32F10x_IT_H */
53 |
54 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
55 |
--------------------------------------------------------------------------------
/STM32/Project/stm32f10x_it.h.orig:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 08-April-2011
7 | * @brief This file contains the headers of the interrupt handlers.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Define to prevent recursive inclusion -------------------------------------*/
23 | #ifndef __STM32F10x_IT_H
24 | #define __STM32F10x_IT_H
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | #include "stm32f10x.h"
32 |
33 | /* Exported types ------------------------------------------------------------*/
34 | /* Exported constants --------------------------------------------------------*/
35 | /* Exported macro ------------------------------------------------------------*/
36 | /* Exported functions ------------------------------------------------------- */
37 |
38 | void NMI_Handler(void);
39 | void HardFault_Handler(void);
40 | void MemManage_Handler(void);
41 | void BusFault_Handler(void);
42 | void UsageFault_Handler(void);
43 | void SVC_Handler(void);
44 | void DebugMon_Handler(void);
45 | void PendSV_Handler(void);
46 | void SysTick_Handler(void);
47 |
48 | #ifdef __cplusplus
49 | }
50 | #endif
51 |
52 | #endif /* __STM32F10x_IT_H */
53 |
54 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
55 |
--------------------------------------------------------------------------------
/STM32/Project/system_stm32f10x.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file system_stm32f10x.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /** @addtogroup CMSIS
23 | * @{
24 | */
25 |
26 | /** @addtogroup stm32f10x_system
27 | * @{
28 | */
29 |
30 | /**
31 | * @brief Define to prevent recursive inclusion
32 | */
33 | #ifndef __SYSTEM_STM32F10X_H
34 | #define __SYSTEM_STM32F10X_H
35 |
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | /** @addtogroup STM32F10x_System_Includes
41 | * @{
42 | */
43 |
44 | /**
45 | * @}
46 | */
47 |
48 |
49 | /** @addtogroup STM32F10x_System_Exported_types
50 | * @{
51 | */
52 |
53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
54 |
55 | /**
56 | * @}
57 | */
58 |
59 | /** @addtogroup STM32F10x_System_Exported_Constants
60 | * @{
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /** @addtogroup STM32F10x_System_Exported_Macros
68 | * @{
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /** @addtogroup STM32F10x_System_Exported_Functions
76 | * @{
77 | */
78 |
79 | extern void SystemInit(void);
80 | extern void SystemCoreClockUpdate(void);
81 | /**
82 | * @}
83 | */
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
89 | #endif /*__SYSTEM_STM32F10X_H */
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /**
96 | * @}
97 | */
98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
99 |
--------------------------------------------------------------------------------
/STM32/Project/system_stm32f10x.h.orig:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file system_stm32f10x.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /** @addtogroup CMSIS
23 | * @{
24 | */
25 |
26 | /** @addtogroup stm32f10x_system
27 | * @{
28 | */
29 |
30 | /**
31 | * @brief Define to prevent recursive inclusion
32 | */
33 | #ifndef __SYSTEM_STM32F10X_H
34 | #define __SYSTEM_STM32F10X_H
35 |
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | /** @addtogroup STM32F10x_System_Includes
41 | * @{
42 | */
43 |
44 | /**
45 | * @}
46 | */
47 |
48 |
49 | /** @addtogroup STM32F10x_System_Exported_types
50 | * @{
51 | */
52 |
53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
54 |
55 | /**
56 | * @}
57 | */
58 |
59 | /** @addtogroup STM32F10x_System_Exported_Constants
60 | * @{
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /** @addtogroup STM32F10x_System_Exported_Macros
68 | * @{
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /** @addtogroup STM32F10x_System_Exported_Functions
76 | * @{
77 | */
78 |
79 | extern void SystemInit(void);
80 | extern void SystemCoreClockUpdate(void);
81 | /**
82 | * @}
83 | */
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
89 | #endif /*__SYSTEM_STM32F10X_H */
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /**
96 | * @}
97 | */
98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
99 |
--------------------------------------------------------------------------------
/STM32/Readme.md:
--------------------------------------------------------------------------------
1 | # STM32下位机端
2 |
3 | ## 串口通信格式
4 | ### 基础格式
5 | ```
6 | ${key}[:${class}]:${value}
7 | ```
8 |
9 | ### 垃圾桶容量信息
10 | ```
11 | Capacity:${class}:${value}
12 | ```
13 |
14 | class分别有: `Recycle` `Kitchen` `Harmful` `Other`, 分别对应四种垃圾
15 |
16 | value表示当前的容量, int, 取值0-100
17 |
18 | eg:
19 | ```
20 | Capacity:Recycle:50
21 | ```
22 | 表示可回收垃圾容量为50%
23 |
24 | ### 挡板信息
25 | ```
26 | Baffle:${class}:${msg}
27 | ```
28 |
29 | class分别有: `Left` `Right` `Middle`, 分别对应左、右挡板和终端挡板
30 |
31 | msg分别有:
32 | STM32端发送: `Opened` `Closed`, 分别表示成功开启/关闭
33 | Linux端发送: `Open` `Close`, 分别表示开启/关闭
34 |
35 | eg:
36 |
37 |
38 | ### 传送带信息
39 | ```
40 | Conveyor:${cmd}
41 | ```
42 |
43 | cmd分别有:
44 | Linux端发送: `Forward` `Backward` `Stop`
45 | STM32端不发送任何消息
46 |
47 |
48 |
49 | ### 滑台云台信息
50 | 此部分只负责把垃圾投送到对应垃圾桶
51 |
52 | Linux:
53 | ```
54 | Slider:${class}
55 | ```
56 | class即垃圾种类, `Recycle` `Kitchen` `Harmful` `Other`
57 |
58 |
59 | STM32:
60 | ```
61 | Slider:OK
62 | ```
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/STM32/Software/ANO_tc/ANO_tc.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/ANO_tc/ANO_tc.c
--------------------------------------------------------------------------------
/STM32/Software/ANO_tc/ANO_tc.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/ANO_tc/ANO_tc.h
--------------------------------------------------------------------------------
/STM32/Software/BLUEROCKER/BlueRocker.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/BLUEROCKER/BlueRocker.c
--------------------------------------------------------------------------------
/STM32/Software/BLUEROCKER/BlueRocker.c.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/BLUEROCKER/BlueRocker.c.orig
--------------------------------------------------------------------------------
/STM32/Software/BLUEROCKER/BlueRocker.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/BLUEROCKER/BlueRocker.h
--------------------------------------------------------------------------------
/STM32/Software/Bit_operation/Bit_operation.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/Bit_operation/Bit_operation.h
--------------------------------------------------------------------------------
/STM32/Software/PID/PID.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/PID/PID.c
--------------------------------------------------------------------------------
/STM32/Software/PID/PID.c.orig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/PID/PID.c.orig
--------------------------------------------------------------------------------
/STM32/Software/PID/PID.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/PID/PID.h
--------------------------------------------------------------------------------
/STM32/Software/SystemClock/SystemClock.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/SystemClock/SystemClock.c
--------------------------------------------------------------------------------
/STM32/Software/SystemClock/SystemClock.h:
--------------------------------------------------------------------------------
1 | #ifndef _SYSTEMCLOCK_H_
2 | #define _SYSTEMCLOCK_H_
3 | #include "stm32f10x.h"
4 |
5 | //Inital api
6 | /**
7 | * @brief Init Clock System
8 | * @param None
9 | * @retval None
10 | * @note Interrupt grouping is initialized here, and the Systick Interrupt has the *HIGHEST* priority!
11 | */
12 | void SystemClockInit(void);
13 |
14 | //Interrupt Handle (inline api)
15 | /**
16 | * @brief Init Clock System
17 | * @param None
18 | * @retval None
19 | * @note It MUST BE ADDED TO SysTick_Handler in stm32f10x_it.c !
20 | */
21 | void Systick_IQR(void);
22 |
23 | /**
24 | * @brief Get the number of milliseconds since SystemClockInit()
25 | * @param None
26 | * @retval uint64_t ms
27 | */
28 | uint64_t Get_ms(void);
29 |
30 | /**
31 | * @brief Gets the number of microseconds since SystemClockInit()
32 | * @param None
33 | * @retval uint64_t us
34 | */
35 | uint64_t Get_us(void);
36 |
37 | /**
38 | * @brief Delay n ms
39 | * @param None
40 | * @retval None
41 | */
42 | void delay_ms(uint32_t delaytime);
43 |
44 | /**
45 | * @brief Delay n us
46 | * @param None
47 | * @retval None
48 | */
49 | void delay_us(uint32_t delaytime);
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/STM32/Software/sys/sys.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/sys/sys.c
--------------------------------------------------------------------------------
/STM32/Software/sys/sys.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/sys/sys.h
--------------------------------------------------------------------------------
/STM32/Software/usart/usart.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/usart/usart.c
--------------------------------------------------------------------------------
/STM32/Software/usart/usart.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Software/usart/usart.h
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/misc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file misc.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the miscellaneous
8 | * firmware library functions (add-on to CMSIS functions).
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __MISC_H
25 | #define __MISC_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup MISC
39 | * @{
40 | */
41 |
42 | /** @defgroup MISC_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @brief NVIC Init Structure definition
48 | */
49 |
50 | typedef struct
51 | {
52 | uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled.
53 | This parameter can be a value of @ref IRQn_Type
54 | (For the complete STM32 Devices IRQ Channels list, please
55 | refer to stm32f10x.h file) */
56 |
57 | uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel
58 | specified in NVIC_IRQChannel. This parameter can be a value
59 | between 0 and 15 as described in the table @ref NVIC_Priority_Table */
60 |
61 | uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified
62 | in NVIC_IRQChannel. This parameter can be a value
63 | between 0 and 15 as described in the table @ref NVIC_Priority_Table */
64 |
65 | FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
66 | will be enabled or disabled.
67 | This parameter can be set either to ENABLE or DISABLE */
68 | } NVIC_InitTypeDef;
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /** @defgroup NVIC_Priority_Table
75 | * @{
76 | */
77 |
78 | /**
79 | @code
80 | The table below gives the allowed values of the pre-emption priority and subpriority according
81 | to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function
82 | ============================================================================================================================
83 | NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description
84 | ============================================================================================================================
85 | NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority
86 | | | | 4 bits for subpriority
87 | ----------------------------------------------------------------------------------------------------------------------------
88 | NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority
89 | | | | 3 bits for subpriority
90 | ----------------------------------------------------------------------------------------------------------------------------
91 | NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority
92 | | | | 2 bits for subpriority
93 | ----------------------------------------------------------------------------------------------------------------------------
94 | NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority
95 | | | | 1 bits for subpriority
96 | ----------------------------------------------------------------------------------------------------------------------------
97 | NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority
98 | | | | 0 bits for subpriority
99 | ============================================================================================================================
100 | @endcode
101 | */
102 |
103 | /**
104 | * @}
105 | */
106 |
107 | /** @defgroup MISC_Exported_Constants
108 | * @{
109 | */
110 |
111 | /** @defgroup Vector_Table_Base
112 | * @{
113 | */
114 |
115 | #define NVIC_VectTab_RAM ((uint32_t)0x20000000)
116 | #define NVIC_VectTab_FLASH ((uint32_t)0x08000000)
117 | #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \
118 | ((VECTTAB) == NVIC_VectTab_FLASH))
119 | /**
120 | * @}
121 | */
122 |
123 | /** @defgroup System_Low_Power
124 | * @{
125 | */
126 |
127 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10)
128 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04)
129 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02)
130 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \
131 | ((LP) == NVIC_LP_SLEEPDEEP) || \
132 | ((LP) == NVIC_LP_SLEEPONEXIT))
133 | /**
134 | * @}
135 | */
136 |
137 | /** @defgroup Preemption_Priority_Group
138 | * @{
139 | */
140 |
141 | #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority
142 | 4 bits for subpriority */
143 | #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority
144 | 3 bits for subpriority */
145 | #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority
146 | 2 bits for subpriority */
147 | #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority
148 | 1 bits for subpriority */
149 | #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority
150 | 0 bits for subpriority */
151 |
152 | #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \
153 | ((GROUP) == NVIC_PriorityGroup_1) || \
154 | ((GROUP) == NVIC_PriorityGroup_2) || \
155 | ((GROUP) == NVIC_PriorityGroup_3) || \
156 | ((GROUP) == NVIC_PriorityGroup_4))
157 |
158 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
159 |
160 | #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
161 |
162 | #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF)
163 |
164 | /**
165 | * @}
166 | */
167 |
168 | /** @defgroup SysTick_clock_source
169 | * @{
170 | */
171 |
172 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB)
173 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004)
174 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \
175 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8))
176 | /**
177 | * @}
178 | */
179 |
180 | /**
181 | * @}
182 | */
183 |
184 | /** @defgroup MISC_Exported_Macros
185 | * @{
186 | */
187 |
188 | /**
189 | * @}
190 | */
191 |
192 | /** @defgroup MISC_Exported_Functions
193 | * @{
194 | */
195 |
196 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);
197 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);
198 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset);
199 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState);
200 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource);
201 |
202 | #ifdef __cplusplus
203 | }
204 | #endif
205 |
206 | #endif /* __MISC_H */
207 |
208 | /**
209 | * @}
210 | */
211 |
212 | /**
213 | * @}
214 | */
215 |
216 | /**
217 | * @}
218 | */
219 |
220 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
221 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_bkp.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_bkp.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the BKP firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_BKP_H
25 | #define __STM32F10x_BKP_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup BKP
39 | * @{
40 | */
41 |
42 | /** @defgroup BKP_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup BKP_Exported_Constants
51 | * @{
52 | */
53 |
54 | /** @defgroup Tamper_Pin_active_level
55 | * @{
56 | */
57 |
58 | #define BKP_TamperPinLevel_High ((uint16_t)0x0000)
59 | #define BKP_TamperPinLevel_Low ((uint16_t)0x0001)
60 | #define IS_BKP_TAMPER_PIN_LEVEL(LEVEL) (((LEVEL) == BKP_TamperPinLevel_High) || \
61 | ((LEVEL) == BKP_TamperPinLevel_Low))
62 | /**
63 | * @}
64 | */
65 |
66 | /** @defgroup RTC_output_source_to_output_on_the_Tamper_pin
67 | * @{
68 | */
69 |
70 | #define BKP_RTCOutputSource_None ((uint16_t)0x0000)
71 | #define BKP_RTCOutputSource_CalibClock ((uint16_t)0x0080)
72 | #define BKP_RTCOutputSource_Alarm ((uint16_t)0x0100)
73 | #define BKP_RTCOutputSource_Second ((uint16_t)0x0300)
74 | #define IS_BKP_RTC_OUTPUT_SOURCE(SOURCE) (((SOURCE) == BKP_RTCOutputSource_None) || \
75 | ((SOURCE) == BKP_RTCOutputSource_CalibClock) || \
76 | ((SOURCE) == BKP_RTCOutputSource_Alarm) || \
77 | ((SOURCE) == BKP_RTCOutputSource_Second))
78 | /**
79 | * @}
80 | */
81 |
82 | /** @defgroup Data_Backup_Register
83 | * @{
84 | */
85 |
86 | #define BKP_DR1 ((uint16_t)0x0004)
87 | #define BKP_DR2 ((uint16_t)0x0008)
88 | #define BKP_DR3 ((uint16_t)0x000C)
89 | #define BKP_DR4 ((uint16_t)0x0010)
90 | #define BKP_DR5 ((uint16_t)0x0014)
91 | #define BKP_DR6 ((uint16_t)0x0018)
92 | #define BKP_DR7 ((uint16_t)0x001C)
93 | #define BKP_DR8 ((uint16_t)0x0020)
94 | #define BKP_DR9 ((uint16_t)0x0024)
95 | #define BKP_DR10 ((uint16_t)0x0028)
96 | #define BKP_DR11 ((uint16_t)0x0040)
97 | #define BKP_DR12 ((uint16_t)0x0044)
98 | #define BKP_DR13 ((uint16_t)0x0048)
99 | #define BKP_DR14 ((uint16_t)0x004C)
100 | #define BKP_DR15 ((uint16_t)0x0050)
101 | #define BKP_DR16 ((uint16_t)0x0054)
102 | #define BKP_DR17 ((uint16_t)0x0058)
103 | #define BKP_DR18 ((uint16_t)0x005C)
104 | #define BKP_DR19 ((uint16_t)0x0060)
105 | #define BKP_DR20 ((uint16_t)0x0064)
106 | #define BKP_DR21 ((uint16_t)0x0068)
107 | #define BKP_DR22 ((uint16_t)0x006C)
108 | #define BKP_DR23 ((uint16_t)0x0070)
109 | #define BKP_DR24 ((uint16_t)0x0074)
110 | #define BKP_DR25 ((uint16_t)0x0078)
111 | #define BKP_DR26 ((uint16_t)0x007C)
112 | #define BKP_DR27 ((uint16_t)0x0080)
113 | #define BKP_DR28 ((uint16_t)0x0084)
114 | #define BKP_DR29 ((uint16_t)0x0088)
115 | #define BKP_DR30 ((uint16_t)0x008C)
116 | #define BKP_DR31 ((uint16_t)0x0090)
117 | #define BKP_DR32 ((uint16_t)0x0094)
118 | #define BKP_DR33 ((uint16_t)0x0098)
119 | #define BKP_DR34 ((uint16_t)0x009C)
120 | #define BKP_DR35 ((uint16_t)0x00A0)
121 | #define BKP_DR36 ((uint16_t)0x00A4)
122 | #define BKP_DR37 ((uint16_t)0x00A8)
123 | #define BKP_DR38 ((uint16_t)0x00AC)
124 | #define BKP_DR39 ((uint16_t)0x00B0)
125 | #define BKP_DR40 ((uint16_t)0x00B4)
126 | #define BKP_DR41 ((uint16_t)0x00B8)
127 | #define BKP_DR42 ((uint16_t)0x00BC)
128 |
129 | #define IS_BKP_DR(DR) (((DR) == BKP_DR1) || ((DR) == BKP_DR2) || ((DR) == BKP_DR3) || \
130 | ((DR) == BKP_DR4) || ((DR) == BKP_DR5) || ((DR) == BKP_DR6) || \
131 | ((DR) == BKP_DR7) || ((DR) == BKP_DR8) || ((DR) == BKP_DR9) || \
132 | ((DR) == BKP_DR10) || ((DR) == BKP_DR11) || ((DR) == BKP_DR12) || \
133 | ((DR) == BKP_DR13) || ((DR) == BKP_DR14) || ((DR) == BKP_DR15) || \
134 | ((DR) == BKP_DR16) || ((DR) == BKP_DR17) || ((DR) == BKP_DR18) || \
135 | ((DR) == BKP_DR19) || ((DR) == BKP_DR20) || ((DR) == BKP_DR21) || \
136 | ((DR) == BKP_DR22) || ((DR) == BKP_DR23) || ((DR) == BKP_DR24) || \
137 | ((DR) == BKP_DR25) || ((DR) == BKP_DR26) || ((DR) == BKP_DR27) || \
138 | ((DR) == BKP_DR28) || ((DR) == BKP_DR29) || ((DR) == BKP_DR30) || \
139 | ((DR) == BKP_DR31) || ((DR) == BKP_DR32) || ((DR) == BKP_DR33) || \
140 | ((DR) == BKP_DR34) || ((DR) == BKP_DR35) || ((DR) == BKP_DR36) || \
141 | ((DR) == BKP_DR37) || ((DR) == BKP_DR38) || ((DR) == BKP_DR39) || \
142 | ((DR) == BKP_DR40) || ((DR) == BKP_DR41) || ((DR) == BKP_DR42))
143 |
144 | #define IS_BKP_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x7F)
145 | /**
146 | * @}
147 | */
148 |
149 | /**
150 | * @}
151 | */
152 |
153 | /** @defgroup BKP_Exported_Macros
154 | * @{
155 | */
156 |
157 | /**
158 | * @}
159 | */
160 |
161 | /** @defgroup BKP_Exported_Functions
162 | * @{
163 | */
164 |
165 | void BKP_DeInit(void);
166 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel);
167 | void BKP_TamperPinCmd(FunctionalState NewState);
168 | void BKP_ITConfig(FunctionalState NewState);
169 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource);
170 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue);
171 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data);
172 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR);
173 | FlagStatus BKP_GetFlagStatus(void);
174 | void BKP_ClearFlag(void);
175 | ITStatus BKP_GetITStatus(void);
176 | void BKP_ClearITPendingBit(void);
177 |
178 | #ifdef __cplusplus
179 | }
180 | #endif
181 |
182 | #endif /* __STM32F10x_BKP_H */
183 | /**
184 | * @}
185 | */
186 |
187 | /**
188 | * @}
189 | */
190 |
191 | /**
192 | * @}
193 | */
194 |
195 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
196 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_cec.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_cec.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the CEC firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_CEC_H
25 | #define __STM32F10x_CEC_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup CEC
39 | * @{
40 | */
41 |
42 |
43 | /** @defgroup CEC_Exported_Types
44 | * @{
45 | */
46 |
47 | /**
48 | * @brief CEC Init structure definition
49 | */
50 | typedef struct
51 | {
52 | uint16_t CEC_BitTimingMode; /*!< Configures the CEC Bit Timing Error Mode.
53 | This parameter can be a value of @ref CEC_BitTiming_Mode */
54 | uint16_t CEC_BitPeriodMode; /*!< Configures the CEC Bit Period Error Mode.
55 | This parameter can be a value of @ref CEC_BitPeriod_Mode */
56 | }CEC_InitTypeDef;
57 |
58 | /**
59 | * @}
60 | */
61 |
62 | /** @defgroup CEC_Exported_Constants
63 | * @{
64 | */
65 |
66 | /** @defgroup CEC_BitTiming_Mode
67 | * @{
68 | */
69 | #define CEC_BitTimingStdMode ((uint16_t)0x00) /*!< Bit timing error Standard Mode */
70 | #define CEC_BitTimingErrFreeMode CEC_CFGR_BTEM /*!< Bit timing error Free Mode */
71 |
72 | #define IS_CEC_BIT_TIMING_ERROR_MODE(MODE) (((MODE) == CEC_BitTimingStdMode) || \
73 | ((MODE) == CEC_BitTimingErrFreeMode))
74 | /**
75 | * @}
76 | */
77 |
78 | /** @defgroup CEC_BitPeriod_Mode
79 | * @{
80 | */
81 | #define CEC_BitPeriodStdMode ((uint16_t)0x00) /*!< Bit period error Standard Mode */
82 | #define CEC_BitPeriodFlexibleMode CEC_CFGR_BPEM /*!< Bit period error Flexible Mode */
83 |
84 | #define IS_CEC_BIT_PERIOD_ERROR_MODE(MODE) (((MODE) == CEC_BitPeriodStdMode) || \
85 | ((MODE) == CEC_BitPeriodFlexibleMode))
86 | /**
87 | * @}
88 | */
89 |
90 |
91 | /** @defgroup CEC_interrupts_definition
92 | * @{
93 | */
94 | #define CEC_IT_TERR CEC_CSR_TERR
95 | #define CEC_IT_TBTRF CEC_CSR_TBTRF
96 | #define CEC_IT_RERR CEC_CSR_RERR
97 | #define CEC_IT_RBTF CEC_CSR_RBTF
98 | #define IS_CEC_GET_IT(IT) (((IT) == CEC_IT_TERR) || ((IT) == CEC_IT_TBTRF) || \
99 | ((IT) == CEC_IT_RERR) || ((IT) == CEC_IT_RBTF))
100 | /**
101 | * @}
102 | */
103 |
104 |
105 | /** @defgroup CEC_Own_Address
106 | * @{
107 | */
108 | #define IS_CEC_ADDRESS(ADDRESS) ((ADDRESS) < 0x10)
109 | /**
110 | * @}
111 | */
112 |
113 | /** @defgroup CEC_Prescaler
114 | * @{
115 | */
116 | #define IS_CEC_PRESCALER(PRESCALER) ((PRESCALER) <= 0x3FFF)
117 |
118 | /**
119 | * @}
120 | */
121 |
122 | /** @defgroup CEC_flags_definition
123 | * @{
124 | */
125 |
126 | /**
127 | * @brief ESR register flags
128 | */
129 | #define CEC_FLAG_BTE ((uint32_t)0x10010000)
130 | #define CEC_FLAG_BPE ((uint32_t)0x10020000)
131 | #define CEC_FLAG_RBTFE ((uint32_t)0x10040000)
132 | #define CEC_FLAG_SBE ((uint32_t)0x10080000)
133 | #define CEC_FLAG_ACKE ((uint32_t)0x10100000)
134 | #define CEC_FLAG_LINE ((uint32_t)0x10200000)
135 | #define CEC_FLAG_TBTFE ((uint32_t)0x10400000)
136 |
137 | /**
138 | * @brief CSR register flags
139 | */
140 | #define CEC_FLAG_TEOM ((uint32_t)0x00000002)
141 | #define CEC_FLAG_TERR ((uint32_t)0x00000004)
142 | #define CEC_FLAG_TBTRF ((uint32_t)0x00000008)
143 | #define CEC_FLAG_RSOM ((uint32_t)0x00000010)
144 | #define CEC_FLAG_REOM ((uint32_t)0x00000020)
145 | #define CEC_FLAG_RERR ((uint32_t)0x00000040)
146 | #define CEC_FLAG_RBTF ((uint32_t)0x00000080)
147 |
148 | #define IS_CEC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF03) == 0x00) && ((FLAG) != 0x00))
149 |
150 | #define IS_CEC_GET_FLAG(FLAG) (((FLAG) == CEC_FLAG_BTE) || ((FLAG) == CEC_FLAG_BPE) || \
151 | ((FLAG) == CEC_FLAG_RBTFE) || ((FLAG)== CEC_FLAG_SBE) || \
152 | ((FLAG) == CEC_FLAG_ACKE) || ((FLAG) == CEC_FLAG_LINE) || \
153 | ((FLAG) == CEC_FLAG_TBTFE) || ((FLAG) == CEC_FLAG_TEOM) || \
154 | ((FLAG) == CEC_FLAG_TERR) || ((FLAG) == CEC_FLAG_TBTRF) || \
155 | ((FLAG) == CEC_FLAG_RSOM) || ((FLAG) == CEC_FLAG_REOM) || \
156 | ((FLAG) == CEC_FLAG_RERR) || ((FLAG) == CEC_FLAG_RBTF))
157 |
158 | /**
159 | * @}
160 | */
161 |
162 | /**
163 | * @}
164 | */
165 |
166 | /** @defgroup CEC_Exported_Macros
167 | * @{
168 | */
169 |
170 | /**
171 | * @}
172 | */
173 |
174 | /** @defgroup CEC_Exported_Functions
175 | * @{
176 | */
177 | void CEC_DeInit(void);
178 | void CEC_Init(CEC_InitTypeDef* CEC_InitStruct);
179 | void CEC_Cmd(FunctionalState NewState);
180 | void CEC_ITConfig(FunctionalState NewState);
181 | void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress);
182 | void CEC_SetPrescaler(uint16_t CEC_Prescaler);
183 | void CEC_SendDataByte(uint8_t Data);
184 | uint8_t CEC_ReceiveDataByte(void);
185 | void CEC_StartOfMessage(void);
186 | void CEC_EndOfMessageCmd(FunctionalState NewState);
187 | FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG);
188 | void CEC_ClearFlag(uint32_t CEC_FLAG);
189 | ITStatus CEC_GetITStatus(uint8_t CEC_IT);
190 | void CEC_ClearITPendingBit(uint16_t CEC_IT);
191 |
192 | #ifdef __cplusplus
193 | }
194 | #endif
195 |
196 | #endif /* __STM32F10x_CEC_H */
197 |
198 | /**
199 | * @}
200 | */
201 |
202 | /**
203 | * @}
204 | */
205 |
206 | /**
207 | * @}
208 | */
209 |
210 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
211 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_crc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_crc.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the CRC firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_CRC_H
25 | #define __STM32F10x_CRC_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup CRC
39 | * @{
40 | */
41 |
42 | /** @defgroup CRC_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup CRC_Exported_Constants
51 | * @{
52 | */
53 |
54 | /**
55 | * @}
56 | */
57 |
58 | /** @defgroup CRC_Exported_Macros
59 | * @{
60 | */
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | /** @defgroup CRC_Exported_Functions
67 | * @{
68 | */
69 |
70 | void CRC_ResetDR(void);
71 | uint32_t CRC_CalcCRC(uint32_t Data);
72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength);
73 | uint32_t CRC_GetCRC(void);
74 | void CRC_SetIDRegister(uint8_t IDValue);
75 | uint8_t CRC_GetIDRegister(void);
76 |
77 | #ifdef __cplusplus
78 | }
79 | #endif
80 |
81 | #endif /* __STM32F10x_CRC_H */
82 | /**
83 | * @}
84 | */
85 |
86 | /**
87 | * @}
88 | */
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
95 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_dbgmcu.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_dbgmcu.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the DBGMCU
8 | * firmware library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_DBGMCU_H
25 | #define __STM32F10x_DBGMCU_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup DBGMCU
39 | * @{
40 | */
41 |
42 | /** @defgroup DBGMCU_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup DBGMCU_Exported_Constants
51 | * @{
52 | */
53 |
54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001)
55 | #define DBGMCU_STOP ((uint32_t)0x00000002)
56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004)
57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100)
58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200)
59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400)
60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800)
61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000)
62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000)
63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000)
64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000)
65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000)
66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000)
67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000)
68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000)
69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000)
70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000)
71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000)
72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000)
73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000)
74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000)
75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000)
76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000)
77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000)
78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000)
79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000)
80 |
81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00))
82 | /**
83 | * @}
84 | */
85 |
86 | /** @defgroup DBGMCU_Exported_Macros
87 | * @{
88 | */
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | /** @defgroup DBGMCU_Exported_Functions
95 | * @{
96 | */
97 |
98 | uint32_t DBGMCU_GetREVID(void);
99 | uint32_t DBGMCU_GetDEVID(void);
100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState);
101 |
102 | #ifdef __cplusplus
103 | }
104 | #endif
105 |
106 | #endif /* __STM32F10x_DBGMCU_H */
107 | /**
108 | * @}
109 | */
110 |
111 | /**
112 | * @}
113 | */
114 |
115 | /**
116 | * @}
117 | */
118 |
119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
120 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_exti.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_exti.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the EXTI firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_EXTI_H
25 | #define __STM32F10x_EXTI_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup EXTI
39 | * @{
40 | */
41 |
42 | /** @defgroup EXTI_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @brief EXTI mode enumeration
48 | */
49 |
50 | typedef enum
51 | {
52 | EXTI_Mode_Interrupt = 0x00,
53 | EXTI_Mode_Event = 0x04
54 | }EXTIMode_TypeDef;
55 |
56 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event))
57 |
58 | /**
59 | * @brief EXTI Trigger enumeration
60 | */
61 |
62 | typedef enum
63 | {
64 | EXTI_Trigger_Rising = 0x08,
65 | EXTI_Trigger_Falling = 0x0C,
66 | EXTI_Trigger_Rising_Falling = 0x10
67 | }EXTITrigger_TypeDef;
68 |
69 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \
70 | ((TRIGGER) == EXTI_Trigger_Falling) || \
71 | ((TRIGGER) == EXTI_Trigger_Rising_Falling))
72 | /**
73 | * @brief EXTI Init Structure definition
74 | */
75 |
76 | typedef struct
77 | {
78 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled.
79 | This parameter can be any combination of @ref EXTI_Lines */
80 |
81 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines.
82 | This parameter can be a value of @ref EXTIMode_TypeDef */
83 |
84 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines.
85 | This parameter can be a value of @ref EXTIMode_TypeDef */
86 |
87 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines.
88 | This parameter can be set either to ENABLE or DISABLE */
89 | }EXTI_InitTypeDef;
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /** @defgroup EXTI_Exported_Constants
96 | * @{
97 | */
98 |
99 | /** @defgroup EXTI_Lines
100 | * @{
101 | */
102 |
103 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */
104 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */
105 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */
106 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */
107 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */
108 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */
109 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */
110 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */
111 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */
112 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */
113 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */
114 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */
115 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */
116 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */
117 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */
118 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */
119 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */
120 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */
121 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS
122 | Wakeup from suspend event */
123 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */
124 |
125 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00))
126 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \
127 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \
128 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \
129 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \
130 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \
131 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \
132 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \
133 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \
134 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \
135 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19))
136 |
137 |
138 | /**
139 | * @}
140 | */
141 |
142 | /**
143 | * @}
144 | */
145 |
146 | /** @defgroup EXTI_Exported_Macros
147 | * @{
148 | */
149 |
150 | /**
151 | * @}
152 | */
153 |
154 | /** @defgroup EXTI_Exported_Functions
155 | * @{
156 | */
157 |
158 | void EXTI_DeInit(void);
159 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct);
160 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct);
161 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line);
162 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line);
163 | void EXTI_ClearFlag(uint32_t EXTI_Line);
164 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line);
165 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line);
166 |
167 | #ifdef __cplusplus
168 | }
169 | #endif
170 |
171 | #endif /* __STM32F10x_EXTI_H */
172 | /**
173 | * @}
174 | */
175 |
176 | /**
177 | * @}
178 | */
179 |
180 | /**
181 | * @}
182 | */
183 |
184 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
185 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_iwdg.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_iwdg.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the IWDG
8 | * firmware library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_IWDG_H
25 | #define __STM32F10x_IWDG_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup IWDG
39 | * @{
40 | */
41 |
42 | /** @defgroup IWDG_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup IWDG_Exported_Constants
51 | * @{
52 | */
53 |
54 | /** @defgroup IWDG_WriteAccess
55 | * @{
56 | */
57 |
58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555)
59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000)
60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \
61 | ((ACCESS) == IWDG_WriteAccess_Disable))
62 | /**
63 | * @}
64 | */
65 |
66 | /** @defgroup IWDG_prescaler
67 | * @{
68 | */
69 |
70 | #define IWDG_Prescaler_4 ((uint8_t)0x00)
71 | #define IWDG_Prescaler_8 ((uint8_t)0x01)
72 | #define IWDG_Prescaler_16 ((uint8_t)0x02)
73 | #define IWDG_Prescaler_32 ((uint8_t)0x03)
74 | #define IWDG_Prescaler_64 ((uint8_t)0x04)
75 | #define IWDG_Prescaler_128 ((uint8_t)0x05)
76 | #define IWDG_Prescaler_256 ((uint8_t)0x06)
77 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \
78 | ((PRESCALER) == IWDG_Prescaler_8) || \
79 | ((PRESCALER) == IWDG_Prescaler_16) || \
80 | ((PRESCALER) == IWDG_Prescaler_32) || \
81 | ((PRESCALER) == IWDG_Prescaler_64) || \
82 | ((PRESCALER) == IWDG_Prescaler_128)|| \
83 | ((PRESCALER) == IWDG_Prescaler_256))
84 | /**
85 | * @}
86 | */
87 |
88 | /** @defgroup IWDG_Flag
89 | * @{
90 | */
91 |
92 | #define IWDG_FLAG_PVU ((uint16_t)0x0001)
93 | #define IWDG_FLAG_RVU ((uint16_t)0x0002)
94 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU))
95 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF)
96 | /**
97 | * @}
98 | */
99 |
100 | /**
101 | * @}
102 | */
103 |
104 | /** @defgroup IWDG_Exported_Macros
105 | * @{
106 | */
107 |
108 | /**
109 | * @}
110 | */
111 |
112 | /** @defgroup IWDG_Exported_Functions
113 | * @{
114 | */
115 |
116 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess);
117 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler);
118 | void IWDG_SetReload(uint16_t Reload);
119 | void IWDG_ReloadCounter(void);
120 | void IWDG_Enable(void);
121 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG);
122 |
123 | #ifdef __cplusplus
124 | }
125 | #endif
126 |
127 | #endif /* __STM32F10x_IWDG_H */
128 | /**
129 | * @}
130 | */
131 |
132 | /**
133 | * @}
134 | */
135 |
136 | /**
137 | * @}
138 | */
139 |
140 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
141 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_pwr.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_pwr.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the PWR firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_PWR_H
25 | #define __STM32F10x_PWR_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup PWR
39 | * @{
40 | */
41 |
42 | /** @defgroup PWR_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup PWR_Exported_Constants
51 | * @{
52 | */
53 |
54 | /** @defgroup PVD_detection_level
55 | * @{
56 | */
57 |
58 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000)
59 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020)
60 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040)
61 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060)
62 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080)
63 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0)
64 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0)
65 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0)
66 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \
67 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \
68 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \
69 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9))
70 | /**
71 | * @}
72 | */
73 |
74 | /** @defgroup Regulator_state_is_STOP_mode
75 | * @{
76 | */
77 |
78 | #define PWR_Regulator_ON ((uint32_t)0x00000000)
79 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001)
80 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \
81 | ((REGULATOR) == PWR_Regulator_LowPower))
82 | /**
83 | * @}
84 | */
85 |
86 | /** @defgroup STOP_mode_entry
87 | * @{
88 | */
89 |
90 | #define PWR_STOPEntry_WFI ((uint8_t)0x01)
91 | #define PWR_STOPEntry_WFE ((uint8_t)0x02)
92 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
93 |
94 | /**
95 | * @}
96 | */
97 |
98 | /** @defgroup PWR_Flag
99 | * @{
100 | */
101 |
102 | #define PWR_FLAG_WU ((uint32_t)0x00000001)
103 | #define PWR_FLAG_SB ((uint32_t)0x00000002)
104 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004)
105 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \
106 | ((FLAG) == PWR_FLAG_PVDO))
107 |
108 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB))
109 | /**
110 | * @}
111 | */
112 |
113 | /**
114 | * @}
115 | */
116 |
117 | /** @defgroup PWR_Exported_Macros
118 | * @{
119 | */
120 |
121 | /**
122 | * @}
123 | */
124 |
125 | /** @defgroup PWR_Exported_Functions
126 | * @{
127 | */
128 |
129 | void PWR_DeInit(void);
130 | void PWR_BackupAccessCmd(FunctionalState NewState);
131 | void PWR_PVDCmd(FunctionalState NewState);
132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);
133 | void PWR_WakeUpPinCmd(FunctionalState NewState);
134 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
135 | void PWR_EnterSTANDBYMode(void);
136 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
137 | void PWR_ClearFlag(uint32_t PWR_FLAG);
138 |
139 | #ifdef __cplusplus
140 | }
141 | #endif
142 |
143 | #endif /* __STM32F10x_PWR_H */
144 | /**
145 | * @}
146 | */
147 |
148 | /**
149 | * @}
150 | */
151 |
152 | /**
153 | * @}
154 | */
155 |
156 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
157 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_rtc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_rtc.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the RTC firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_RTC_H
25 | #define __STM32F10x_RTC_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup RTC
39 | * @{
40 | */
41 |
42 | /** @defgroup RTC_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup RTC_Exported_Constants
51 | * @{
52 | */
53 |
54 | /** @defgroup RTC_interrupts_define
55 | * @{
56 | */
57 |
58 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */
59 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */
60 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */
61 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00))
62 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \
63 | ((IT) == RTC_IT_SEC))
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup RTC_interrupts_flags
69 | * @{
70 | */
71 |
72 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */
73 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */
74 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */
75 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */
76 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */
77 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00))
78 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \
79 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \
80 | ((FLAG) == RTC_FLAG_SEC))
81 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF)
82 |
83 | /**
84 | * @}
85 | */
86 |
87 | /**
88 | * @}
89 | */
90 |
91 | /** @defgroup RTC_Exported_Macros
92 | * @{
93 | */
94 |
95 | /**
96 | * @}
97 | */
98 |
99 | /** @defgroup RTC_Exported_Functions
100 | * @{
101 | */
102 |
103 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState);
104 | void RTC_EnterConfigMode(void);
105 | void RTC_ExitConfigMode(void);
106 | uint32_t RTC_GetCounter(void);
107 | void RTC_SetCounter(uint32_t CounterValue);
108 | void RTC_SetPrescaler(uint32_t PrescalerValue);
109 | void RTC_SetAlarm(uint32_t AlarmValue);
110 | uint32_t RTC_GetDivider(void);
111 | void RTC_WaitForLastTask(void);
112 | void RTC_WaitForSynchro(void);
113 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG);
114 | void RTC_ClearFlag(uint16_t RTC_FLAG);
115 | ITStatus RTC_GetITStatus(uint16_t RTC_IT);
116 | void RTC_ClearITPendingBit(uint16_t RTC_IT);
117 |
118 | #ifdef __cplusplus
119 | }
120 | #endif
121 |
122 | #endif /* __STM32F10x_RTC_H */
123 | /**
124 | * @}
125 | */
126 |
127 | /**
128 | * @}
129 | */
130 |
131 | /**
132 | * @}
133 | */
134 |
135 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
136 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/inc/stm32f10x_wwdg.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_wwdg.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file contains all the functions prototypes for the WWDG firmware
8 | * library.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Define to prevent recursive inclusion -------------------------------------*/
24 | #ifndef __STM32F10x_WWDG_H
25 | #define __STM32F10x_WWDG_H
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "stm32f10x.h"
33 |
34 | /** @addtogroup STM32F10x_StdPeriph_Driver
35 | * @{
36 | */
37 |
38 | /** @addtogroup WWDG
39 | * @{
40 | */
41 |
42 | /** @defgroup WWDG_Exported_Types
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup WWDG_Exported_Constants
51 | * @{
52 | */
53 |
54 | /** @defgroup WWDG_Prescaler
55 | * @{
56 | */
57 |
58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000)
59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080)
60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100)
61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180)
62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \
63 | ((PRESCALER) == WWDG_Prescaler_2) || \
64 | ((PRESCALER) == WWDG_Prescaler_4) || \
65 | ((PRESCALER) == WWDG_Prescaler_8))
66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F)
67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F))
68 |
69 | /**
70 | * @}
71 | */
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | /** @defgroup WWDG_Exported_Macros
78 | * @{
79 | */
80 | /**
81 | * @}
82 | */
83 |
84 | /** @defgroup WWDG_Exported_Functions
85 | * @{
86 | */
87 |
88 | void WWDG_DeInit(void);
89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler);
90 | void WWDG_SetWindowValue(uint8_t WindowValue);
91 | void WWDG_EnableIT(void);
92 | void WWDG_SetCounter(uint8_t Counter);
93 | void WWDG_Enable(uint8_t Counter);
94 | FlagStatus WWDG_GetFlagStatus(void);
95 | void WWDG_ClearFlag(void);
96 |
97 | #ifdef __cplusplus
98 | }
99 | #endif
100 |
101 | #endif /* __STM32F10x_WWDG_H */
102 |
103 | /**
104 | * @}
105 | */
106 |
107 | /**
108 | * @}
109 | */
110 |
111 | /**
112 | * @}
113 | */
114 |
115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
116 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/misc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file misc.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the miscellaneous firmware functions (add-on
8 | * to CMSIS functions).
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 | *
19 | * © COPYRIGHT 2011 STMicroelectronics
20 | ******************************************************************************
21 | */
22 |
23 | /* Includes ------------------------------------------------------------------*/
24 | #include "misc.h"
25 |
26 | /** @addtogroup STM32F10x_StdPeriph_Driver
27 | * @{
28 | */
29 |
30 | /** @defgroup MISC
31 | * @brief MISC driver modules
32 | * @{
33 | */
34 |
35 | /** @defgroup MISC_Private_TypesDefinitions
36 | * @{
37 | */
38 |
39 | /**
40 | * @}
41 | */
42 |
43 | /** @defgroup MISC_Private_Defines
44 | * @{
45 | */
46 |
47 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
48 | /**
49 | * @}
50 | */
51 |
52 | /** @defgroup MISC_Private_Macros
53 | * @{
54 | */
55 |
56 | /**
57 | * @}
58 | */
59 |
60 | /** @defgroup MISC_Private_Variables
61 | * @{
62 | */
63 |
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup MISC_Private_FunctionPrototypes
69 | * @{
70 | */
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | /** @defgroup MISC_Private_Functions
77 | * @{
78 | */
79 |
80 | /**
81 | * @brief Configures the priority grouping: pre-emption priority and subpriority.
82 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
83 | * This parameter can be one of the following values:
84 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
85 | * 4 bits for subpriority
86 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
87 | * 3 bits for subpriority
88 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
89 | * 2 bits for subpriority
90 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
91 | * 1 bits for subpriority
92 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
93 | * 0 bits for subpriority
94 | * @retval None
95 | */
96 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
97 | {
98 | /* Check the parameters */
99 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
100 |
101 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
102 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
103 | }
104 |
105 | /**
106 | * @brief Initializes the NVIC peripheral according to the specified
107 | * parameters in the NVIC_InitStruct.
108 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
109 | * the configuration information for the specified NVIC peripheral.
110 | * @retval None
111 | */
112 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
113 | {
114 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
115 |
116 | /* Check the parameters */
117 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
118 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
119 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
120 |
121 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
122 | {
123 | /* Compute the Corresponding IRQ Priority --------------------------------*/
124 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
125 | tmppre = (0x4 - tmppriority);
126 | tmpsub = tmpsub >> tmppriority;
127 |
128 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
129 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
130 | tmppriority = tmppriority << 0x04;
131 |
132 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
133 |
134 | /* Enable the Selected IRQ Channels --------------------------------------*/
135 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
136 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
137 | }
138 | else
139 | {
140 | /* Disable the Selected IRQ Channels -------------------------------------*/
141 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
142 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
143 | }
144 | }
145 |
146 | /**
147 | * @brief Sets the vector table location and Offset.
148 | * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
149 | * This parameter can be one of the following values:
150 | * @arg NVIC_VectTab_RAM
151 | * @arg NVIC_VectTab_FLASH
152 | * @param Offset: Vector Table base offset field. This value must be a multiple
153 | * of 0x200.
154 | * @retval None
155 | */
156 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
157 | {
158 | /* Check the parameters */
159 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
160 | assert_param(IS_NVIC_OFFSET(Offset));
161 |
162 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
163 | }
164 |
165 | /**
166 | * @brief Selects the condition for the system to enter low power mode.
167 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
168 | * This parameter can be one of the following values:
169 | * @arg NVIC_LP_SEVONPEND
170 | * @arg NVIC_LP_SLEEPDEEP
171 | * @arg NVIC_LP_SLEEPONEXIT
172 | * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
173 | * @retval None
174 | */
175 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
176 | {
177 | /* Check the parameters */
178 | assert_param(IS_NVIC_LP(LowPowerMode));
179 | assert_param(IS_FUNCTIONAL_STATE(NewState));
180 |
181 | if (NewState != DISABLE)
182 | {
183 | SCB->SCR |= LowPowerMode;
184 | }
185 | else
186 | {
187 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
188 | }
189 | }
190 |
191 | /**
192 | * @brief Configures the SysTick clock source.
193 | * @param SysTick_CLKSource: specifies the SysTick clock source.
194 | * This parameter can be one of the following values:
195 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
196 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
197 | * @retval None
198 | */
199 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
200 | {
201 | /* Check the parameters */
202 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
203 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
204 | {
205 | SysTick->CTRL |= SysTick_CLKSource_HCLK;
206 | }
207 | else
208 | {
209 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
210 | }
211 | }
212 |
213 | /**
214 | * @}
215 | */
216 |
217 | /**
218 | * @}
219 | */
220 |
221 | /**
222 | * @}
223 | */
224 |
225 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
226 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_bkp.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_bkp.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the BKP firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_bkp.h"
24 | #include "stm32f10x_rcc.h"
25 |
26 | /** @addtogroup STM32F10x_StdPeriph_Driver
27 | * @{
28 | */
29 |
30 | /** @defgroup BKP
31 | * @brief BKP driver modules
32 | * @{
33 | */
34 |
35 | /** @defgroup BKP_Private_TypesDefinitions
36 | * @{
37 | */
38 |
39 | /**
40 | * @}
41 | */
42 |
43 | /** @defgroup BKP_Private_Defines
44 | * @{
45 | */
46 |
47 | /* ------------ BKP registers bit address in the alias region --------------- */
48 | #define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
49 |
50 | /* --- CR Register ----*/
51 |
52 | /* Alias word address of TPAL bit */
53 | #define CR_OFFSET (BKP_OFFSET + 0x30)
54 | #define TPAL_BitNumber 0x01
55 | #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
56 |
57 | /* Alias word address of TPE bit */
58 | #define TPE_BitNumber 0x00
59 | #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
60 |
61 | /* --- CSR Register ---*/
62 |
63 | /* Alias word address of TPIE bit */
64 | #define CSR_OFFSET (BKP_OFFSET + 0x34)
65 | #define TPIE_BitNumber 0x02
66 | #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
67 |
68 | /* Alias word address of TIF bit */
69 | #define TIF_BitNumber 0x09
70 | #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
71 |
72 | /* Alias word address of TEF bit */
73 | #define TEF_BitNumber 0x08
74 | #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
75 |
76 | /* ---------------------- BKP registers bit mask ------------------------ */
77 |
78 | /* RTCCR register bit mask */
79 | #define RTCCR_CAL_MASK ((uint16_t)0xFF80)
80 | #define RTCCR_MASK ((uint16_t)0xFC7F)
81 |
82 | /**
83 | * @}
84 | */
85 |
86 |
87 | /** @defgroup BKP_Private_Macros
88 | * @{
89 | */
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /** @defgroup BKP_Private_Variables
96 | * @{
97 | */
98 |
99 | /**
100 | * @}
101 | */
102 |
103 | /** @defgroup BKP_Private_FunctionPrototypes
104 | * @{
105 | */
106 |
107 | /**
108 | * @}
109 | */
110 |
111 | /** @defgroup BKP_Private_Functions
112 | * @{
113 | */
114 |
115 | /**
116 | * @brief Deinitializes the BKP peripheral registers to their default reset values.
117 | * @param None
118 | * @retval None
119 | */
120 | void BKP_DeInit(void)
121 | {
122 | RCC_BackupResetCmd(ENABLE);
123 | RCC_BackupResetCmd(DISABLE);
124 | }
125 |
126 | /**
127 | * @brief Configures the Tamper Pin active level.
128 | * @param BKP_TamperPinLevel: specifies the Tamper Pin active level.
129 | * This parameter can be one of the following values:
130 | * @arg BKP_TamperPinLevel_High: Tamper pin active on high level
131 | * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
132 | * @retval None
133 | */
134 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
135 | {
136 | /* Check the parameters */
137 | assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
138 | *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
139 | }
140 |
141 | /**
142 | * @brief Enables or disables the Tamper Pin activation.
143 | * @param NewState: new state of the Tamper Pin activation.
144 | * This parameter can be: ENABLE or DISABLE.
145 | * @retval None
146 | */
147 | void BKP_TamperPinCmd(FunctionalState NewState)
148 | {
149 | /* Check the parameters */
150 | assert_param(IS_FUNCTIONAL_STATE(NewState));
151 | *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
152 | }
153 |
154 | /**
155 | * @brief Enables or disables the Tamper Pin Interrupt.
156 | * @param NewState: new state of the Tamper Pin Interrupt.
157 | * This parameter can be: ENABLE or DISABLE.
158 | * @retval None
159 | */
160 | void BKP_ITConfig(FunctionalState NewState)
161 | {
162 | /* Check the parameters */
163 | assert_param(IS_FUNCTIONAL_STATE(NewState));
164 | *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
165 | }
166 |
167 | /**
168 | * @brief Select the RTC output source to output on the Tamper pin.
169 | * @param BKP_RTCOutputSource: specifies the RTC output source.
170 | * This parameter can be one of the following values:
171 | * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
172 | * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
173 | * divided by 64 on the Tamper pin.
174 | * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
175 | * the Tamper pin.
176 | * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
177 | * the Tamper pin.
178 | * @retval None
179 | */
180 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
181 | {
182 | uint16_t tmpreg = 0;
183 | /* Check the parameters */
184 | assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
185 | tmpreg = BKP->RTCCR;
186 | /* Clear CCO, ASOE and ASOS bits */
187 | tmpreg &= RTCCR_MASK;
188 |
189 | /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
190 | tmpreg |= BKP_RTCOutputSource;
191 | /* Store the new value */
192 | BKP->RTCCR = tmpreg;
193 | }
194 |
195 | /**
196 | * @brief Sets RTC Clock Calibration value.
197 | * @param CalibrationValue: specifies the RTC Clock Calibration value.
198 | * This parameter must be a number between 0 and 0x7F.
199 | * @retval None
200 | */
201 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
202 | {
203 | uint16_t tmpreg = 0;
204 | /* Check the parameters */
205 | assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
206 | tmpreg = BKP->RTCCR;
207 | /* Clear CAL[6:0] bits */
208 | tmpreg &= RTCCR_CAL_MASK;
209 | /* Set CAL[6:0] bits according to CalibrationValue value */
210 | tmpreg |= CalibrationValue;
211 | /* Store the new value */
212 | BKP->RTCCR = tmpreg;
213 | }
214 |
215 | /**
216 | * @brief Writes user data to the specified Data Backup Register.
217 | * @param BKP_DR: specifies the Data Backup Register.
218 | * This parameter can be BKP_DRx where x:[1, 42]
219 | * @param Data: data to write
220 | * @retval None
221 | */
222 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
223 | {
224 | __IO uint32_t tmp = 0;
225 |
226 | /* Check the parameters */
227 | assert_param(IS_BKP_DR(BKP_DR));
228 |
229 | tmp = (uint32_t)BKP_BASE;
230 | tmp += BKP_DR;
231 |
232 | *(__IO uint32_t *) tmp = Data;
233 | }
234 |
235 | /**
236 | * @brief Reads data from the specified Data Backup Register.
237 | * @param BKP_DR: specifies the Data Backup Register.
238 | * This parameter can be BKP_DRx where x:[1, 42]
239 | * @retval The content of the specified Data Backup Register
240 | */
241 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
242 | {
243 | __IO uint32_t tmp = 0;
244 |
245 | /* Check the parameters */
246 | assert_param(IS_BKP_DR(BKP_DR));
247 |
248 | tmp = (uint32_t)BKP_BASE;
249 | tmp += BKP_DR;
250 |
251 | return (*(__IO uint16_t *) tmp);
252 | }
253 |
254 | /**
255 | * @brief Checks whether the Tamper Pin Event flag is set or not.
256 | * @param None
257 | * @retval The new state of the Tamper Pin Event flag (SET or RESET).
258 | */
259 | FlagStatus BKP_GetFlagStatus(void)
260 | {
261 | return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
262 | }
263 |
264 | /**
265 | * @brief Clears Tamper Pin Event pending flag.
266 | * @param None
267 | * @retval None
268 | */
269 | void BKP_ClearFlag(void)
270 | {
271 | /* Set CTE bit to clear Tamper Pin Event flag */
272 | BKP->CSR |= BKP_CSR_CTE;
273 | }
274 |
275 | /**
276 | * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
277 | * @param None
278 | * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
279 | */
280 | ITStatus BKP_GetITStatus(void)
281 | {
282 | return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
283 | }
284 |
285 | /**
286 | * @brief Clears Tamper Pin Interrupt pending bit.
287 | * @param None
288 | * @retval None
289 | */
290 | void BKP_ClearITPendingBit(void)
291 | {
292 | /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
293 | BKP->CSR |= BKP_CSR_CTI;
294 | }
295 |
296 | /**
297 | * @}
298 | */
299 |
300 | /**
301 | * @}
302 | */
303 |
304 | /**
305 | * @}
306 | */
307 |
308 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
309 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_crc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_crc.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the CRC firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_crc.h"
24 |
25 | /** @addtogroup STM32F10x_StdPeriph_Driver
26 | * @{
27 | */
28 |
29 | /** @defgroup CRC
30 | * @brief CRC driver modules
31 | * @{
32 | */
33 |
34 | /** @defgroup CRC_Private_TypesDefinitions
35 | * @{
36 | */
37 |
38 | /**
39 | * @}
40 | */
41 |
42 | /** @defgroup CRC_Private_Defines
43 | * @{
44 | */
45 |
46 | /**
47 | * @}
48 | */
49 |
50 | /** @defgroup CRC_Private_Macros
51 | * @{
52 | */
53 |
54 | /**
55 | * @}
56 | */
57 |
58 | /** @defgroup CRC_Private_Variables
59 | * @{
60 | */
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | /** @defgroup CRC_Private_FunctionPrototypes
67 | * @{
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /** @defgroup CRC_Private_Functions
75 | * @{
76 | */
77 |
78 | /**
79 | * @brief Resets the CRC Data register (DR).
80 | * @param None
81 | * @retval None
82 | */
83 | void CRC_ResetDR(void)
84 | {
85 | /* Reset CRC generator */
86 | CRC->CR = CRC_CR_RESET;
87 | }
88 |
89 | /**
90 | * @brief Computes the 32-bit CRC of a given data word(32-bit).
91 | * @param Data: data word(32-bit) to compute its CRC
92 | * @retval 32-bit CRC
93 | */
94 | uint32_t CRC_CalcCRC(uint32_t Data)
95 | {
96 | CRC->DR = Data;
97 |
98 | return (CRC->DR);
99 | }
100 |
101 | /**
102 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
103 | * @param pBuffer: pointer to the buffer containing the data to be computed
104 | * @param BufferLength: length of the buffer to be computed
105 | * @retval 32-bit CRC
106 | */
107 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
108 | {
109 | uint32_t index = 0;
110 |
111 | for(index = 0; index < BufferLength; index++)
112 | {
113 | CRC->DR = pBuffer[index];
114 | }
115 | return (CRC->DR);
116 | }
117 |
118 | /**
119 | * @brief Returns the current CRC value.
120 | * @param None
121 | * @retval 32-bit CRC
122 | */
123 | uint32_t CRC_GetCRC(void)
124 | {
125 | return (CRC->DR);
126 | }
127 |
128 | /**
129 | * @brief Stores a 8-bit data in the Independent Data(ID) register.
130 | * @param IDValue: 8-bit value to be stored in the ID register
131 | * @retval None
132 | */
133 | void CRC_SetIDRegister(uint8_t IDValue)
134 | {
135 | CRC->IDR = IDValue;
136 | }
137 |
138 | /**
139 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register
140 | * @param None
141 | * @retval 8-bit value of the ID register
142 | */
143 | uint8_t CRC_GetIDRegister(void)
144 | {
145 | return (CRC->IDR);
146 | }
147 |
148 | /**
149 | * @}
150 | */
151 |
152 | /**
153 | * @}
154 | */
155 |
156 | /**
157 | * @}
158 | */
159 |
160 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
161 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_dbgmcu.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_dbgmcu.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the DBGMCU firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_dbgmcu.h"
24 |
25 | /** @addtogroup STM32F10x_StdPeriph_Driver
26 | * @{
27 | */
28 |
29 | /** @defgroup DBGMCU
30 | * @brief DBGMCU driver modules
31 | * @{
32 | */
33 |
34 | /** @defgroup DBGMCU_Private_TypesDefinitions
35 | * @{
36 | */
37 |
38 | /**
39 | * @}
40 | */
41 |
42 | /** @defgroup DBGMCU_Private_Defines
43 | * @{
44 | */
45 |
46 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
47 | /**
48 | * @}
49 | */
50 |
51 | /** @defgroup DBGMCU_Private_Macros
52 | * @{
53 | */
54 |
55 | /**
56 | * @}
57 | */
58 |
59 | /** @defgroup DBGMCU_Private_Variables
60 | * @{
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /** @defgroup DBGMCU_Private_FunctionPrototypes
68 | * @{
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /** @defgroup DBGMCU_Private_Functions
76 | * @{
77 | */
78 |
79 | /**
80 | * @brief Returns the device revision identifier.
81 | * @param None
82 | * @retval Device revision identifier
83 | */
84 | uint32_t DBGMCU_GetREVID(void)
85 | {
86 | return(DBGMCU->IDCODE >> 16);
87 | }
88 |
89 | /**
90 | * @brief Returns the device identifier.
91 | * @param None
92 | * @retval Device identifier
93 | */
94 | uint32_t DBGMCU_GetDEVID(void)
95 | {
96 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK);
97 | }
98 |
99 | /**
100 | * @brief Configures the specified peripheral and low power mode behavior
101 | * when the MCU under Debug mode.
102 | * @param DBGMCU_Periph: specifies the peripheral and low power mode.
103 | * This parameter can be any combination of the following values:
104 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode
105 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode
106 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode
107 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted
108 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted
109 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted
110 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted
111 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted
112 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted
113 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted
114 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted
115 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted
116 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted
117 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted
118 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted
119 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted
120 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted
121 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted
122 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted
123 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted
124 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted
125 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted
126 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted
127 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted
128 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted
129 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted
130 | * @param NewState: new state of the specified peripheral in Debug mode.
131 | * This parameter can be: ENABLE or DISABLE.
132 | * @retval None
133 | */
134 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState)
135 | {
136 | /* Check the parameters */
137 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph));
138 | assert_param(IS_FUNCTIONAL_STATE(NewState));
139 |
140 | if (NewState != DISABLE)
141 | {
142 | DBGMCU->CR |= DBGMCU_Periph;
143 | }
144 | else
145 | {
146 | DBGMCU->CR &= ~DBGMCU_Periph;
147 | }
148 | }
149 |
150 | /**
151 | * @}
152 | */
153 |
154 | /**
155 | * @}
156 | */
157 |
158 | /**
159 | * @}
160 | */
161 |
162 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
163 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_exti.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_exti.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the EXTI firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_exti.h"
24 |
25 | /** @addtogroup STM32F10x_StdPeriph_Driver
26 | * @{
27 | */
28 |
29 | /** @defgroup EXTI
30 | * @brief EXTI driver modules
31 | * @{
32 | */
33 |
34 | /** @defgroup EXTI_Private_TypesDefinitions
35 | * @{
36 | */
37 |
38 | /**
39 | * @}
40 | */
41 |
42 | /** @defgroup EXTI_Private_Defines
43 | * @{
44 | */
45 |
46 | #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
47 |
48 | /**
49 | * @}
50 | */
51 |
52 | /** @defgroup EXTI_Private_Macros
53 | * @{
54 | */
55 |
56 | /**
57 | * @}
58 | */
59 |
60 | /** @defgroup EXTI_Private_Variables
61 | * @{
62 | */
63 |
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup EXTI_Private_FunctionPrototypes
69 | * @{
70 | */
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | /** @defgroup EXTI_Private_Functions
77 | * @{
78 | */
79 |
80 | /**
81 | * @brief Deinitializes the EXTI peripheral registers to their default reset values.
82 | * @param None
83 | * @retval None
84 | */
85 | void EXTI_DeInit(void)
86 | {
87 | EXTI->IMR = 0x00000000;
88 | EXTI->EMR = 0x00000000;
89 | EXTI->RTSR = 0x00000000;
90 | EXTI->FTSR = 0x00000000;
91 | EXTI->PR = 0x000FFFFF;
92 | }
93 |
94 | /**
95 | * @brief Initializes the EXTI peripheral according to the specified
96 | * parameters in the EXTI_InitStruct.
97 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
98 | * that contains the configuration information for the EXTI peripheral.
99 | * @retval None
100 | */
101 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
102 | {
103 | uint32_t tmp = 0;
104 |
105 | /* Check the parameters */
106 | assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
107 | assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
108 | assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
109 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
110 |
111 | tmp = (uint32_t)EXTI_BASE;
112 |
113 | if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
114 | {
115 | /* Clear EXTI line configuration */
116 | EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
117 | EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
118 |
119 | tmp += EXTI_InitStruct->EXTI_Mode;
120 |
121 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
122 |
123 | /* Clear Rising Falling edge configuration */
124 | EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
125 | EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
126 |
127 | /* Select the trigger for the selected external interrupts */
128 | if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
129 | {
130 | /* Rising Falling edge */
131 | EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
132 | EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
133 | }
134 | else
135 | {
136 | tmp = (uint32_t)EXTI_BASE;
137 | tmp += EXTI_InitStruct->EXTI_Trigger;
138 |
139 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
140 | }
141 | }
142 | else
143 | {
144 | tmp += EXTI_InitStruct->EXTI_Mode;
145 |
146 | /* Disable the selected external lines */
147 | *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
148 | }
149 | }
150 |
151 | /**
152 | * @brief Fills each EXTI_InitStruct member with its reset value.
153 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
154 | * be initialized.
155 | * @retval None
156 | */
157 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
158 | {
159 | EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
160 | EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
161 | EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
162 | EXTI_InitStruct->EXTI_LineCmd = DISABLE;
163 | }
164 |
165 | /**
166 | * @brief Generates a Software interrupt.
167 | * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled.
168 | * This parameter can be any combination of EXTI_Linex where x can be (0..19).
169 | * @retval None
170 | */
171 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
172 | {
173 | /* Check the parameters */
174 | assert_param(IS_EXTI_LINE(EXTI_Line));
175 |
176 | EXTI->SWIER |= EXTI_Line;
177 | }
178 |
179 | /**
180 | * @brief Checks whether the specified EXTI line flag is set or not.
181 | * @param EXTI_Line: specifies the EXTI line flag to check.
182 | * This parameter can be:
183 | * @arg EXTI_Linex: External interrupt line x where x(0..19)
184 | * @retval The new state of EXTI_Line (SET or RESET).
185 | */
186 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
187 | {
188 | FlagStatus bitstatus = RESET;
189 | /* Check the parameters */
190 | assert_param(IS_GET_EXTI_LINE(EXTI_Line));
191 |
192 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
193 | {
194 | bitstatus = SET;
195 | }
196 | else
197 | {
198 | bitstatus = RESET;
199 | }
200 | return bitstatus;
201 | }
202 |
203 | /**
204 | * @brief Clears the EXTI's line pending flags.
205 | * @param EXTI_Line: specifies the EXTI lines flags to clear.
206 | * This parameter can be any combination of EXTI_Linex where x can be (0..19).
207 | * @retval None
208 | */
209 | void EXTI_ClearFlag(uint32_t EXTI_Line)
210 | {
211 | /* Check the parameters */
212 | assert_param(IS_EXTI_LINE(EXTI_Line));
213 |
214 | EXTI->PR = EXTI_Line;
215 | }
216 |
217 | /**
218 | * @brief Checks whether the specified EXTI line is asserted or not.
219 | * @param EXTI_Line: specifies the EXTI line to check.
220 | * This parameter can be:
221 | * @arg EXTI_Linex: External interrupt line x where x(0..19)
222 | * @retval The new state of EXTI_Line (SET or RESET).
223 | */
224 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
225 | {
226 | ITStatus bitstatus = RESET;
227 | uint32_t enablestatus = 0;
228 | /* Check the parameters */
229 | assert_param(IS_GET_EXTI_LINE(EXTI_Line));
230 |
231 | enablestatus = EXTI->IMR & EXTI_Line;
232 | if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
233 | {
234 | bitstatus = SET;
235 | }
236 | else
237 | {
238 | bitstatus = RESET;
239 | }
240 | return bitstatus;
241 | }
242 |
243 | /**
244 | * @brief Clears the EXTI's line pending bits.
245 | * @param EXTI_Line: specifies the EXTI lines to clear.
246 | * This parameter can be any combination of EXTI_Linex where x can be (0..19).
247 | * @retval None
248 | */
249 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
250 | {
251 | /* Check the parameters */
252 | assert_param(IS_EXTI_LINE(EXTI_Line));
253 |
254 | EXTI->PR = EXTI_Line;
255 | }
256 |
257 | /**
258 | * @}
259 | */
260 |
261 | /**
262 | * @}
263 | */
264 |
265 | /**
266 | * @}
267 | */
268 |
269 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
270 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_flash.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Stm32F10x_FWLIB/src/stm32f10x_flash.c
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_i2c.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Stm32F10x_FWLIB/src/stm32f10x_i2c.c
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_iwdg.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_iwdg.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the IWDG firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_iwdg.h"
24 |
25 | /** @addtogroup STM32F10x_StdPeriph_Driver
26 | * @{
27 | */
28 |
29 | /** @defgroup IWDG
30 | * @brief IWDG driver modules
31 | * @{
32 | */
33 |
34 | /** @defgroup IWDG_Private_TypesDefinitions
35 | * @{
36 | */
37 |
38 | /**
39 | * @}
40 | */
41 |
42 | /** @defgroup IWDG_Private_Defines
43 | * @{
44 | */
45 |
46 | /* ---------------------- IWDG registers bit mask ----------------------------*/
47 |
48 | /* KR register bit mask */
49 | #define KR_KEY_Reload ((uint16_t)0xAAAA)
50 | #define KR_KEY_Enable ((uint16_t)0xCCCC)
51 |
52 | /**
53 | * @}
54 | */
55 |
56 | /** @defgroup IWDG_Private_Macros
57 | * @{
58 | */
59 |
60 | /**
61 | * @}
62 | */
63 |
64 | /** @defgroup IWDG_Private_Variables
65 | * @{
66 | */
67 |
68 | /**
69 | * @}
70 | */
71 |
72 | /** @defgroup IWDG_Private_FunctionPrototypes
73 | * @{
74 | */
75 |
76 | /**
77 | * @}
78 | */
79 |
80 | /** @defgroup IWDG_Private_Functions
81 | * @{
82 | */
83 |
84 | /**
85 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
86 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
87 | * This parameter can be one of the following values:
88 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
89 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
90 | * @retval None
91 | */
92 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
93 | {
94 | /* Check the parameters */
95 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
96 | IWDG->KR = IWDG_WriteAccess;
97 | }
98 |
99 | /**
100 | * @brief Sets IWDG Prescaler value.
101 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
102 | * This parameter can be one of the following values:
103 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
104 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
105 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
106 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
107 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
108 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
109 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
110 | * @retval None
111 | */
112 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
113 | {
114 | /* Check the parameters */
115 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
116 | IWDG->PR = IWDG_Prescaler;
117 | }
118 |
119 | /**
120 | * @brief Sets IWDG Reload value.
121 | * @param Reload: specifies the IWDG Reload value.
122 | * This parameter must be a number between 0 and 0x0FFF.
123 | * @retval None
124 | */
125 | void IWDG_SetReload(uint16_t Reload)
126 | {
127 | /* Check the parameters */
128 | assert_param(IS_IWDG_RELOAD(Reload));
129 | IWDG->RLR = Reload;
130 | }
131 |
132 | /**
133 | * @brief Reloads IWDG counter with value defined in the reload register
134 | * (write access to IWDG_PR and IWDG_RLR registers disabled).
135 | * @param None
136 | * @retval None
137 | */
138 | void IWDG_ReloadCounter(void)
139 | {
140 | IWDG->KR = KR_KEY_Reload;
141 | }
142 |
143 | /**
144 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
145 | * @param None
146 | * @retval None
147 | */
148 | void IWDG_Enable(void)
149 | {
150 | IWDG->KR = KR_KEY_Enable;
151 | }
152 |
153 | /**
154 | * @brief Checks whether the specified IWDG flag is set or not.
155 | * @param IWDG_FLAG: specifies the flag to check.
156 | * This parameter can be one of the following values:
157 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
158 | * @arg IWDG_FLAG_RVU: Reload Value Update on going
159 | * @retval The new state of IWDG_FLAG (SET or RESET).
160 | */
161 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
162 | {
163 | FlagStatus bitstatus = RESET;
164 | /* Check the parameters */
165 | assert_param(IS_IWDG_FLAG(IWDG_FLAG));
166 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
167 | {
168 | bitstatus = SET;
169 | }
170 | else
171 | {
172 | bitstatus = RESET;
173 | }
174 | /* Return the flag status */
175 | return bitstatus;
176 | }
177 |
178 | /**
179 | * @}
180 | */
181 |
182 | /**
183 | * @}
184 | */
185 |
186 | /**
187 | * @}
188 | */
189 |
190 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
191 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_pwr.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_pwr.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the PWR firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_pwr.h"
24 | #include "stm32f10x_rcc.h"
25 |
26 | /** @addtogroup STM32F10x_StdPeriph_Driver
27 | * @{
28 | */
29 |
30 | /** @defgroup PWR
31 | * @brief PWR driver modules
32 | * @{
33 | */
34 |
35 | /** @defgroup PWR_Private_TypesDefinitions
36 | * @{
37 | */
38 |
39 | /**
40 | * @}
41 | */
42 |
43 | /** @defgroup PWR_Private_Defines
44 | * @{
45 | */
46 |
47 | /* --------- PWR registers bit address in the alias region ---------- */
48 | #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
49 |
50 | /* --- CR Register ---*/
51 |
52 | /* Alias word address of DBP bit */
53 | #define CR_OFFSET (PWR_OFFSET + 0x00)
54 | #define DBP_BitNumber 0x08
55 | #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
56 |
57 | /* Alias word address of PVDE bit */
58 | #define PVDE_BitNumber 0x04
59 | #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
60 |
61 | /* --- CSR Register ---*/
62 |
63 | /* Alias word address of EWUP bit */
64 | #define CSR_OFFSET (PWR_OFFSET + 0x04)
65 | #define EWUP_BitNumber 0x08
66 | #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
67 |
68 | /* ------------------ PWR registers bit mask ------------------------ */
69 |
70 | /* CR register bit mask */
71 | #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
72 | #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
73 |
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /** @defgroup PWR_Private_Macros
80 | * @{
81 | */
82 |
83 | /**
84 | * @}
85 | */
86 |
87 | /** @defgroup PWR_Private_Variables
88 | * @{
89 | */
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /** @defgroup PWR_Private_FunctionPrototypes
96 | * @{
97 | */
98 |
99 | /**
100 | * @}
101 | */
102 |
103 | /** @defgroup PWR_Private_Functions
104 | * @{
105 | */
106 |
107 | /**
108 | * @brief Deinitializes the PWR peripheral registers to their default reset values.
109 | * @param None
110 | * @retval None
111 | */
112 | void PWR_DeInit(void)
113 | {
114 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
115 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
116 | }
117 |
118 | /**
119 | * @brief Enables or disables access to the RTC and backup registers.
120 | * @param NewState: new state of the access to the RTC and backup registers.
121 | * This parameter can be: ENABLE or DISABLE.
122 | * @retval None
123 | */
124 | void PWR_BackupAccessCmd(FunctionalState NewState)
125 | {
126 | /* Check the parameters */
127 | assert_param(IS_FUNCTIONAL_STATE(NewState));
128 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
129 | }
130 |
131 | /**
132 | * @brief Enables or disables the Power Voltage Detector(PVD).
133 | * @param NewState: new state of the PVD.
134 | * This parameter can be: ENABLE or DISABLE.
135 | * @retval None
136 | */
137 | void PWR_PVDCmd(FunctionalState NewState)
138 | {
139 | /* Check the parameters */
140 | assert_param(IS_FUNCTIONAL_STATE(NewState));
141 | *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
142 | }
143 |
144 | /**
145 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
146 | * @param PWR_PVDLevel: specifies the PVD detection level
147 | * This parameter can be one of the following values:
148 | * @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V
149 | * @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V
150 | * @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V
151 | * @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V
152 | * @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V
153 | * @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V
154 | * @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V
155 | * @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V
156 | * @retval None
157 | */
158 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
159 | {
160 | uint32_t tmpreg = 0;
161 | /* Check the parameters */
162 | assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
163 | tmpreg = PWR->CR;
164 | /* Clear PLS[7:5] bits */
165 | tmpreg &= CR_PLS_MASK;
166 | /* Set PLS[7:5] bits according to PWR_PVDLevel value */
167 | tmpreg |= PWR_PVDLevel;
168 | /* Store the new value */
169 | PWR->CR = tmpreg;
170 | }
171 |
172 | /**
173 | * @brief Enables or disables the WakeUp Pin functionality.
174 | * @param NewState: new state of the WakeUp Pin functionality.
175 | * This parameter can be: ENABLE or DISABLE.
176 | * @retval None
177 | */
178 | void PWR_WakeUpPinCmd(FunctionalState NewState)
179 | {
180 | /* Check the parameters */
181 | assert_param(IS_FUNCTIONAL_STATE(NewState));
182 | *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
183 | }
184 |
185 | /**
186 | * @brief Enters STOP mode.
187 | * @param PWR_Regulator: specifies the regulator state in STOP mode.
188 | * This parameter can be one of the following values:
189 | * @arg PWR_Regulator_ON: STOP mode with regulator ON
190 | * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
191 | * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
192 | * This parameter can be one of the following values:
193 | * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
194 | * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
195 | * @retval None
196 | */
197 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
198 | {
199 | uint32_t tmpreg = 0;
200 | /* Check the parameters */
201 | assert_param(IS_PWR_REGULATOR(PWR_Regulator));
202 | assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
203 |
204 | /* Select the regulator state in STOP mode ---------------------------------*/
205 | tmpreg = PWR->CR;
206 | /* Clear PDDS and LPDS bits */
207 | tmpreg &= CR_DS_MASK;
208 | /* Set LPDS bit according to PWR_Regulator value */
209 | tmpreg |= PWR_Regulator;
210 | /* Store the new value */
211 | PWR->CR = tmpreg;
212 | /* Set SLEEPDEEP bit of Cortex System Control Register */
213 | SCB->SCR |= SCB_SCR_SLEEPDEEP;
214 |
215 | /* Select STOP mode entry --------------------------------------------------*/
216 | if(PWR_STOPEntry == PWR_STOPEntry_WFI)
217 | {
218 | /* Request Wait For Interrupt */
219 | __WFI();
220 | }
221 | else
222 | {
223 | /* Request Wait For Event */
224 | __WFE();
225 | }
226 |
227 | /* Reset SLEEPDEEP bit of Cortex System Control Register */
228 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
229 | }
230 |
231 | /**
232 | * @brief Enters STANDBY mode.
233 | * @param None
234 | * @retval None
235 | */
236 | void PWR_EnterSTANDBYMode(void)
237 | {
238 | /* Clear Wake-up flag */
239 | PWR->CR |= PWR_CR_CWUF;
240 | /* Select STANDBY mode */
241 | PWR->CR |= PWR_CR_PDDS;
242 | /* Set SLEEPDEEP bit of Cortex System Control Register */
243 | SCB->SCR |= SCB_SCR_SLEEPDEEP;
244 | /* This option is used to ensure that store operations are completed */
245 | #if defined ( __CC_ARM )
246 | __force_stores();
247 | #endif
248 | /* Request Wait For Interrupt */
249 | __WFI();
250 | }
251 |
252 | /**
253 | * @brief Checks whether the specified PWR flag is set or not.
254 | * @param PWR_FLAG: specifies the flag to check.
255 | * This parameter can be one of the following values:
256 | * @arg PWR_FLAG_WU: Wake Up flag
257 | * @arg PWR_FLAG_SB: StandBy flag
258 | * @arg PWR_FLAG_PVDO: PVD Output
259 | * @retval The new state of PWR_FLAG (SET or RESET).
260 | */
261 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
262 | {
263 | FlagStatus bitstatus = RESET;
264 | /* Check the parameters */
265 | assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
266 |
267 | if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
268 | {
269 | bitstatus = SET;
270 | }
271 | else
272 | {
273 | bitstatus = RESET;
274 | }
275 | /* Return the flag status */
276 | return bitstatus;
277 | }
278 |
279 | /**
280 | * @brief Clears the PWR's pending flags.
281 | * @param PWR_FLAG: specifies the flag to clear.
282 | * This parameter can be one of the following values:
283 | * @arg PWR_FLAG_WU: Wake Up flag
284 | * @arg PWR_FLAG_SB: StandBy flag
285 | * @retval None
286 | */
287 | void PWR_ClearFlag(uint32_t PWR_FLAG)
288 | {
289 | /* Check the parameters */
290 | assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
291 |
292 | PWR->CR |= PWR_FLAG << 2;
293 | }
294 |
295 | /**
296 | * @}
297 | */
298 |
299 | /**
300 | * @}
301 | */
302 |
303 | /**
304 | * @}
305 | */
306 |
307 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
308 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_rtc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_rtc.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the RTC firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_rtc.h"
24 |
25 | /** @addtogroup STM32F10x_StdPeriph_Driver
26 | * @{
27 | */
28 |
29 | /** @defgroup RTC
30 | * @brief RTC driver modules
31 | * @{
32 | */
33 |
34 | /** @defgroup RTC_Private_TypesDefinitions
35 | * @{
36 | */
37 | /**
38 | * @}
39 | */
40 |
41 | /** @defgroup RTC_Private_Defines
42 | * @{
43 | */
44 | #define RTC_LSB_MASK ((uint32_t)0x0000FFFF) /*!< RTC LSB Mask */
45 | #define PRLH_MSB_MASK ((uint32_t)0x000F0000) /*!< RTC Prescaler MSB Mask */
46 |
47 | /**
48 | * @}
49 | */
50 |
51 | /** @defgroup RTC_Private_Macros
52 | * @{
53 | */
54 |
55 | /**
56 | * @}
57 | */
58 |
59 | /** @defgroup RTC_Private_Variables
60 | * @{
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /** @defgroup RTC_Private_FunctionPrototypes
68 | * @{
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /** @defgroup RTC_Private_Functions
76 | * @{
77 | */
78 |
79 | /**
80 | * @brief Enables or disables the specified RTC interrupts.
81 | * @param RTC_IT: specifies the RTC interrupts sources to be enabled or disabled.
82 | * This parameter can be any combination of the following values:
83 | * @arg RTC_IT_OW: Overflow interrupt
84 | * @arg RTC_IT_ALR: Alarm interrupt
85 | * @arg RTC_IT_SEC: Second interrupt
86 | * @param NewState: new state of the specified RTC interrupts.
87 | * This parameter can be: ENABLE or DISABLE.
88 | * @retval None
89 | */
90 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)
91 | {
92 | /* Check the parameters */
93 | assert_param(IS_RTC_IT(RTC_IT));
94 | assert_param(IS_FUNCTIONAL_STATE(NewState));
95 |
96 | if (NewState != DISABLE)
97 | {
98 | RTC->CRH |= RTC_IT;
99 | }
100 | else
101 | {
102 | RTC->CRH &= (uint16_t)~RTC_IT;
103 | }
104 | }
105 |
106 | /**
107 | * @brief Enters the RTC configuration mode.
108 | * @param None
109 | * @retval None
110 | */
111 | void RTC_EnterConfigMode(void)
112 | {
113 | /* Set the CNF flag to enter in the Configuration Mode */
114 | RTC->CRL |= RTC_CRL_CNF;
115 | }
116 |
117 | /**
118 | * @brief Exits from the RTC configuration mode.
119 | * @param None
120 | * @retval None
121 | */
122 | void RTC_ExitConfigMode(void)
123 | {
124 | /* Reset the CNF flag to exit from the Configuration Mode */
125 | RTC->CRL &= (uint16_t)~((uint16_t)RTC_CRL_CNF);
126 | }
127 |
128 | /**
129 | * @brief Gets the RTC counter value.
130 | * @param None
131 | * @retval RTC counter value.
132 | */
133 | uint32_t RTC_GetCounter(void)
134 | {
135 | uint16_t tmp = 0;
136 | tmp = RTC->CNTL;
137 | return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
138 | }
139 |
140 | /**
141 | * @brief Sets the RTC counter value.
142 | * @param CounterValue: RTC counter new value.
143 | * @retval None
144 | */
145 | void RTC_SetCounter(uint32_t CounterValue)
146 | {
147 | RTC_EnterConfigMode();
148 | /* Set RTC COUNTER MSB word */
149 | RTC->CNTH = CounterValue >> 16;
150 | /* Set RTC COUNTER LSB word */
151 | RTC->CNTL = (CounterValue & RTC_LSB_MASK);
152 | RTC_ExitConfigMode();
153 | }
154 |
155 | /**
156 | * @brief Sets the RTC prescaler value.
157 | * @param PrescalerValue: RTC prescaler new value.
158 | * @retval None
159 | */
160 | void RTC_SetPrescaler(uint32_t PrescalerValue)
161 | {
162 | /* Check the parameters */
163 | assert_param(IS_RTC_PRESCALER(PrescalerValue));
164 |
165 | RTC_EnterConfigMode();
166 | /* Set RTC PRESCALER MSB word */
167 | RTC->PRLH = (PrescalerValue & PRLH_MSB_MASK) >> 16;
168 | /* Set RTC PRESCALER LSB word */
169 | RTC->PRLL = (PrescalerValue & RTC_LSB_MASK);
170 | RTC_ExitConfigMode();
171 | }
172 |
173 | /**
174 | * @brief Sets the RTC alarm value.
175 | * @param AlarmValue: RTC alarm new value.
176 | * @retval None
177 | */
178 | void RTC_SetAlarm(uint32_t AlarmValue)
179 | {
180 | RTC_EnterConfigMode();
181 | /* Set the ALARM MSB word */
182 | RTC->ALRH = AlarmValue >> 16;
183 | /* Set the ALARM LSB word */
184 | RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
185 | RTC_ExitConfigMode();
186 | }
187 |
188 | /**
189 | * @brief Gets the RTC divider value.
190 | * @param None
191 | * @retval RTC Divider value.
192 | */
193 | uint32_t RTC_GetDivider(void)
194 | {
195 | uint32_t tmp = 0x00;
196 | tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;
197 | tmp |= RTC->DIVL;
198 | return tmp;
199 | }
200 |
201 | /**
202 | * @brief Waits until last write operation on RTC registers has finished.
203 | * @note This function must be called before any write to RTC registers.
204 | * @param None
205 | * @retval None
206 | */
207 | void RTC_WaitForLastTask(void)
208 | {
209 | /* Loop until RTOFF flag is set */
210 | while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)
211 | {
212 | }
213 | }
214 |
215 | /**
216 | * @brief Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)
217 | * are synchronized with RTC APB clock.
218 | * @note This function must be called before any read operation after an APB reset
219 | * or an APB clock stop.
220 | * @param None
221 | * @retval None
222 | */
223 | void RTC_WaitForSynchro(void)
224 | {
225 | /* Clear RSF flag */
226 | RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;
227 | /* Loop until RSF flag is set */
228 | while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)
229 | {
230 | }
231 | }
232 |
233 | /**
234 | * @brief Checks whether the specified RTC flag is set or not.
235 | * @param RTC_FLAG: specifies the flag to check.
236 | * This parameter can be one the following values:
237 | * @arg RTC_FLAG_RTOFF: RTC Operation OFF flag
238 | * @arg RTC_FLAG_RSF: Registers Synchronized flag
239 | * @arg RTC_FLAG_OW: Overflow flag
240 | * @arg RTC_FLAG_ALR: Alarm flag
241 | * @arg RTC_FLAG_SEC: Second flag
242 | * @retval The new state of RTC_FLAG (SET or RESET).
243 | */
244 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
245 | {
246 | FlagStatus bitstatus = RESET;
247 |
248 | /* Check the parameters */
249 | assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
250 |
251 | if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)
252 | {
253 | bitstatus = SET;
254 | }
255 | else
256 | {
257 | bitstatus = RESET;
258 | }
259 | return bitstatus;
260 | }
261 |
262 | /**
263 | * @brief Clears the RTC's pending flags.
264 | * @param RTC_FLAG: specifies the flag to clear.
265 | * This parameter can be any combination of the following values:
266 | * @arg RTC_FLAG_RSF: Registers Synchronized flag. This flag is cleared only after
267 | * an APB reset or an APB Clock stop.
268 | * @arg RTC_FLAG_OW: Overflow flag
269 | * @arg RTC_FLAG_ALR: Alarm flag
270 | * @arg RTC_FLAG_SEC: Second flag
271 | * @retval None
272 | */
273 | void RTC_ClearFlag(uint16_t RTC_FLAG)
274 | {
275 | /* Check the parameters */
276 | assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
277 |
278 | /* Clear the corresponding RTC flag */
279 | RTC->CRL &= (uint16_t)~RTC_FLAG;
280 | }
281 |
282 | /**
283 | * @brief Checks whether the specified RTC interrupt has occurred or not.
284 | * @param RTC_IT: specifies the RTC interrupts sources to check.
285 | * This parameter can be one of the following values:
286 | * @arg RTC_IT_OW: Overflow interrupt
287 | * @arg RTC_IT_ALR: Alarm interrupt
288 | * @arg RTC_IT_SEC: Second interrupt
289 | * @retval The new state of the RTC_IT (SET or RESET).
290 | */
291 | ITStatus RTC_GetITStatus(uint16_t RTC_IT)
292 | {
293 | ITStatus bitstatus = RESET;
294 | /* Check the parameters */
295 | assert_param(IS_RTC_GET_IT(RTC_IT));
296 |
297 | bitstatus = (ITStatus)(RTC->CRL & RTC_IT);
298 | if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))
299 | {
300 | bitstatus = SET;
301 | }
302 | else
303 | {
304 | bitstatus = RESET;
305 | }
306 | return bitstatus;
307 | }
308 |
309 | /**
310 | * @brief Clears the RTC's interrupt pending bits.
311 | * @param RTC_IT: specifies the interrupt pending bit to clear.
312 | * This parameter can be any combination of the following values:
313 | * @arg RTC_IT_OW: Overflow interrupt
314 | * @arg RTC_IT_ALR: Alarm interrupt
315 | * @arg RTC_IT_SEC: Second interrupt
316 | * @retval None
317 | */
318 | void RTC_ClearITPendingBit(uint16_t RTC_IT)
319 | {
320 | /* Check the parameters */
321 | assert_param(IS_RTC_IT(RTC_IT));
322 |
323 | /* Clear the corresponding RTC pending bit */
324 | RTC->CRL &= (uint16_t)~RTC_IT;
325 | }
326 |
327 | /**
328 | * @}
329 | */
330 |
331 | /**
332 | * @}
333 | */
334 |
335 | /**
336 | * @}
337 | */
338 |
339 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
340 |
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_usart.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/Stm32F10x_FWLIB/src/stm32f10x_usart.c
--------------------------------------------------------------------------------
/STM32/Stm32F10x_FWLIB/src/stm32f10x_wwdg.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_wwdg.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 11-March-2011
7 | * @brief This file provides all the WWDG firmware functions.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "stm32f10x_wwdg.h"
24 | #include "stm32f10x_rcc.h"
25 |
26 | /** @addtogroup STM32F10x_StdPeriph_Driver
27 | * @{
28 | */
29 |
30 | /** @defgroup WWDG
31 | * @brief WWDG driver modules
32 | * @{
33 | */
34 |
35 | /** @defgroup WWDG_Private_TypesDefinitions
36 | * @{
37 | */
38 |
39 | /**
40 | * @}
41 | */
42 |
43 | /** @defgroup WWDG_Private_Defines
44 | * @{
45 | */
46 |
47 | /* ----------- WWDG registers bit address in the alias region ----------- */
48 | #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE)
49 |
50 | /* Alias word address of EWI bit */
51 | #define CFR_OFFSET (WWDG_OFFSET + 0x04)
52 | #define EWI_BitNumber 0x09
53 | #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
54 |
55 | /* --------------------- WWDG registers bit mask ------------------------ */
56 |
57 | /* CR register bit mask */
58 | #define CR_WDGA_Set ((uint32_t)0x00000080)
59 |
60 | /* CFR register bit mask */
61 | #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F)
62 | #define CFR_W_Mask ((uint32_t)0xFFFFFF80)
63 | #define BIT_Mask ((uint8_t)0x7F)
64 |
65 | /**
66 | * @}
67 | */
68 |
69 | /** @defgroup WWDG_Private_Macros
70 | * @{
71 | */
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | /** @defgroup WWDG_Private_Variables
78 | * @{
79 | */
80 |
81 | /**
82 | * @}
83 | */
84 |
85 | /** @defgroup WWDG_Private_FunctionPrototypes
86 | * @{
87 | */
88 |
89 | /**
90 | * @}
91 | */
92 |
93 | /** @defgroup WWDG_Private_Functions
94 | * @{
95 | */
96 |
97 | /**
98 | * @brief Deinitializes the WWDG peripheral registers to their default reset values.
99 | * @param None
100 | * @retval None
101 | */
102 | void WWDG_DeInit(void)
103 | {
104 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
105 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
106 | }
107 |
108 | /**
109 | * @brief Sets the WWDG Prescaler.
110 | * @param WWDG_Prescaler: specifies the WWDG Prescaler.
111 | * This parameter can be one of the following values:
112 | * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
113 | * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
114 | * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
115 | * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
116 | * @retval None
117 | */
118 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
119 | {
120 | uint32_t tmpreg = 0;
121 | /* Check the parameters */
122 | assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
123 | /* Clear WDGTB[1:0] bits */
124 | tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
125 | /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
126 | tmpreg |= WWDG_Prescaler;
127 | /* Store the new value */
128 | WWDG->CFR = tmpreg;
129 | }
130 |
131 | /**
132 | * @brief Sets the WWDG window value.
133 | * @param WindowValue: specifies the window value to be compared to the downcounter.
134 | * This parameter value must be lower than 0x80.
135 | * @retval None
136 | */
137 | void WWDG_SetWindowValue(uint8_t WindowValue)
138 | {
139 | __IO uint32_t tmpreg = 0;
140 |
141 | /* Check the parameters */
142 | assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
143 | /* Clear W[6:0] bits */
144 |
145 | tmpreg = WWDG->CFR & CFR_W_Mask;
146 |
147 | /* Set W[6:0] bits according to WindowValue value */
148 | tmpreg |= WindowValue & (uint32_t) BIT_Mask;
149 |
150 | /* Store the new value */
151 | WWDG->CFR = tmpreg;
152 | }
153 |
154 | /**
155 | * @brief Enables the WWDG Early Wakeup interrupt(EWI).
156 | * @param None
157 | * @retval None
158 | */
159 | void WWDG_EnableIT(void)
160 | {
161 | *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
162 | }
163 |
164 | /**
165 | * @brief Sets the WWDG counter value.
166 | * @param Counter: specifies the watchdog counter value.
167 | * This parameter must be a number between 0x40 and 0x7F.
168 | * @retval None
169 | */
170 | void WWDG_SetCounter(uint8_t Counter)
171 | {
172 | /* Check the parameters */
173 | assert_param(IS_WWDG_COUNTER(Counter));
174 | /* Write to T[6:0] bits to configure the counter value, no need to do
175 | a read-modify-write; writing a 0 to WDGA bit does nothing */
176 | WWDG->CR = Counter & BIT_Mask;
177 | }
178 |
179 | /**
180 | * @brief Enables WWDG and load the counter value.
181 | * @param Counter: specifies the watchdog counter value.
182 | * This parameter must be a number between 0x40 and 0x7F.
183 | * @retval None
184 | */
185 | void WWDG_Enable(uint8_t Counter)
186 | {
187 | /* Check the parameters */
188 | assert_param(IS_WWDG_COUNTER(Counter));
189 | WWDG->CR = CR_WDGA_Set | Counter;
190 | }
191 |
192 | /**
193 | * @brief Checks whether the Early Wakeup interrupt flag is set or not.
194 | * @param None
195 | * @retval The new state of the Early Wakeup interrupt flag (SET or RESET)
196 | */
197 | FlagStatus WWDG_GetFlagStatus(void)
198 | {
199 | return (FlagStatus)(WWDG->SR);
200 | }
201 |
202 | /**
203 | * @brief Clears Early Wakeup interrupt flag.
204 | * @param None
205 | * @retval None
206 | */
207 | void WWDG_ClearFlag(void)
208 | {
209 | WWDG->SR = (uint32_t)RESET;
210 | }
211 |
212 | /**
213 | * @}
214 | */
215 |
216 | /**
217 | * @}
218 | */
219 |
220 | /**
221 | * @}
222 | */
223 |
224 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
225 |
--------------------------------------------------------------------------------
/STM32/keilkill.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/STM32/keilkill.bat
--------------------------------------------------------------------------------
/Software/FunctionAreas/FunctionAreas.py:
--------------------------------------------------------------------------------
1 | # import Private Implementation
2 | ## Image Processing
3 | from ImageProcessing.VideoPlayer import VideoPlayer
4 | from ImageProcessing.Detector import Detector
5 |
6 | # import Working mode definition
7 | from WorkingProcess.WorkingMode import Mode
8 |
9 | class Functions():
10 | def __init__(self, ui, videoPlayer, detector):
11 | self.__ui__ = ui
12 | self.__videoPlayer__ = videoPlayer
13 | self.__detector__ = detector
14 |
15 | # 当前模式
16 | self.__mode__ = Mode['preMode']
17 |
18 | # 颜色设置
19 | self.__enableStyleSheet__ = "background-color: #FFFFFF;"
20 | self.__disableStyleSheet__ = "background-color: #E4E4E4;"
21 |
22 | # 模式切换
23 | self.__ui__.PreMode.clicked.connect(lambda:self.__preMode__())
24 | self.__ui__.FinalMode.clicked.connect(lambda:self.__finalMode__())
25 |
26 | # 图像功能区
27 | self.__ui__.PlayVideo.clicked.connect(lambda:self.__playVideo__())
28 | self.__ui__.PlayPhoto.clicked.connect(lambda:self.__playPhoto__())
29 | self.__ui__.TakeTurns.clicked.connect(lambda:self.__takeTurns__())
30 |
31 | # 背景阈值Slider
32 | self.__ui__.threSlider.valueChanged.connect(lambda:self.__threValueChanged__())
33 |
34 | # 录入新垃圾
35 | self.__ui__.ReadyToRecord.clicked.connect(lambda:self.__readyToRecord__())
36 | # 重新录入
37 | self.__ui__.ReRecord.clicked.connect(lambda:self.__reRecord__())
38 |
39 | ## 新的可回收垃圾
40 | self.__ui__.NewRecycle.clicked.connect(lambda:self.__newRecycle__())
41 |
42 | ## 新的厨余垃圾
43 | self.__ui__.NewKitchen.clicked.connect(lambda:self.__newKitchen__())
44 |
45 | ## 新的有害垃圾
46 | self.__ui__.NewHarmful.clicked.connect(lambda:self.__newHarmful__())
47 |
48 | ## 新的其他垃圾
49 | self.__ui__.NewOther.clicked.connect(lambda:self.__newOther__())
50 |
51 |
52 | # 获取当前模式
53 | def getCurrentMode(self):
54 | return self.__mode__
55 |
56 |
57 | # 切换为初赛模式
58 | def __preMode__(self):
59 | self.__ui__.PreMode.setStyleSheet(self.__enableStyleSheet__)
60 | self.__ui__.FinalMode.setStyleSheet(self.__disableStyleSheet__)
61 |
62 | self.__ui__.PreMode.setEnabled(False)
63 | self.__ui__.FinalMode.setEnabled(True)
64 |
65 | self.__mode__ = Mode['preMode']
66 |
67 |
68 | # 切换为决赛模式
69 | def __finalMode__(self):
70 | self.__ui__.PreMode.setStyleSheet(self.__disableStyleSheet__)
71 | self.__ui__.FinalMode.setStyleSheet(self.__enableStyleSheet__)
72 |
73 | self.__ui__.PreMode.setEnabled(True)
74 | self.__ui__.FinalMode.setEnabled(False)
75 |
76 | self.__mode__ = Mode['finalMode']
77 |
78 |
79 | # 切换为视频播放模式
80 | def __playVideo__(self):
81 | self.__ui__.PlayVideo.setStyleSheet(self.__enableStyleSheet__)
82 | self.__ui__.PlayPhoto.setStyleSheet(self.__disableStyleSheet__)
83 | self.__ui__.TakeTurns.setStyleSheet(self.__disableStyleSheet__)
84 |
85 | self.__ui__.PlayVideo.setEnabled(False)
86 | self.__ui__.PlayPhoto.setEnabled(True)
87 | self.__ui__.TakeTurns.setEnabled(True)
88 |
89 | self.__videoPlayer__.fromVideo()
90 |
91 |
92 | # 切换为图片播放模式
93 | def __playPhoto__(self):
94 | self.__ui__.PlayVideo.setStyleSheet(self.__disableStyleSheet__)
95 | self.__ui__.PlayPhoto.setStyleSheet(self.__enableStyleSheet__)
96 | self.__ui__.TakeTurns.setStyleSheet(self.__disableStyleSheet__)
97 |
98 | self.__ui__.PlayVideo.setEnabled(True)
99 | self.__ui__.PlayPhoto.setEnabled(False)
100 | self.__ui__.TakeTurns.setEnabled(True)
101 |
102 | self.__videoPlayer__.fromFloder()
103 |
104 |
105 | # 切换为轮流播放模式
106 | def __takeTurns__(self):
107 | self.__ui__.PlayVideo.setStyleSheet(self.__disableStyleSheet__)
108 | self.__ui__.PlayPhoto.setStyleSheet(self.__disableStyleSheet__)
109 | self.__ui__.TakeTurns.setStyleSheet(self.__enableStyleSheet__)
110 |
111 | self.__ui__.PlayVideo.setEnabled(True)
112 | self.__ui__.PlayPhoto.setEnabled(True)
113 | self.__ui__.TakeTurns.setEnabled(False)
114 |
115 | self.__videoPlayer__.takeTurns()
116 |
117 |
118 | # 设置阈值Slider当前值
119 | def setThreSliderValue(self, value):
120 | if((value >= 0) and (value <= 255)):
121 | self.__ui__.threSlider.setValue(value)
122 |
123 |
124 | # 阈值Slider触发函数
125 | def __threValueChanged__(self):
126 | self.__detector__.setThreValue(self.__ui__.threSlider.value())
127 |
128 |
129 | # 准备录入新垃圾
130 | def __readyToRecord__(self):
131 | self.__ui__.ReadyToRecord.setStyleSheet(self.__disableStyleSheet__)
132 | self.__enableAllKinds__()
133 |
134 |
135 | # 新垃圾录入完毕(或失败), 由其他对象调起
136 | def recordFinish(self):
137 | self.__ui__.ReadyToRecord.setStyleSheet(self.__enableStyleSheet__)
138 | self.__disableAllKinds__()
139 |
140 |
141 | # 重新录入, 删除所有模板
142 | def __reRecord__(self):
143 | pass
144 |
145 |
146 | # 录入新的可回收垃圾
147 | def __newRecycle__(self):
148 | self.__disableAllKinds__()
149 |
150 |
151 | # 录入新的厨余垃圾
152 | def __newKitchen__(self):
153 | self.__disableAllKinds__()
154 |
155 |
156 | # 录入新的有害垃圾
157 | def __newHarmful__(self):
158 | self.__disableAllKinds__()
159 |
160 |
161 | # 录入新的其他垃圾
162 | def __newOther__(self):
163 | self.__disableAllKinds__()
164 |
165 |
166 | # 准备录入, 使四种垃圾的按钮全部生效
167 | def __enableAllKinds__(self):
168 | self.__ui__.NewRecycle.setEnabled(True)
169 | self.__ui__.NewKitchen.setEnabled(True)
170 | self.__ui__.NewHarmful.setEnabled(True)
171 | self.__ui__.NewOther.setEnabled(True)
172 |
173 | self.__ui__.NewRecycle.setStyleSheet(self.__enableStyleSheet__)
174 | self.__ui__.NewKitchen.setStyleSheet(self.__enableStyleSheet__)
175 | self.__ui__.NewHarmful.setStyleSheet(self.__enableStyleSheet__)
176 | self.__ui__.NewOther.setStyleSheet(self.__enableStyleSheet__)
177 |
178 |
179 | # 录入完毕, 使四种垃圾的按钮全部失效
180 | def __disableAllKinds__(self):
181 | self.__ui__.NewRecycle.setEnabled(False)
182 | self.__ui__.NewKitchen.setEnabled(False)
183 | self.__ui__.NewHarmful.setEnabled(False)
184 | self.__ui__.NewOther.setEnabled(False)
185 |
186 | self.__ui__.NewRecycle.setStyleSheet(self.__disableStyleSheet__)
187 | self.__ui__.NewKitchen.setStyleSheet(self.__disableStyleSheet__)
188 | self.__ui__.NewHarmful.setStyleSheet(self.__disableStyleSheet__)
189 | self.__ui__.NewOther.setStyleSheet(self.__disableStyleSheet__)
190 |
--------------------------------------------------------------------------------
/Software/GarbageFunction/GarbageMessage.py:
--------------------------------------------------------------------------------
1 | # 主要负责管理UI左侧的垃圾桶信息及对应按钮
2 | # import PyQt5
3 | from PyQt5.QtCore import pyqtSignal
4 | from PyQt5.QtWidgets import QWidget
5 |
6 |
7 | # import Helper libs
8 | import threading
9 | import time
10 |
11 | class GarbageMessage(QWidget):
12 | __recycleNumberSignal__ = pyqtSignal([int])
13 | __kitchenNumberSignal__ = pyqtSignal([int])
14 | __harmfulNumberSignal__ = pyqtSignal([int])
15 | __otherNumberSignal__ = pyqtSignal([int])
16 |
17 | def __init__(self, ui):
18 | QWidget.__init__(self)
19 | self.__ui__ = ui
20 | self.__slave__ = None
21 | self.__slaveLock__ = threading.Lock()
22 |
23 | # 显示动画
24 | self.__ui__.processbar_other.parameterUpdate(100)
25 | self.__ui__.processbar_other.parameterUpdate(0)
26 |
27 | self.__ui__.processbar_harmful.parameterUpdate(100)
28 | self.__ui__.processbar_harmful.parameterUpdate(0)
29 |
30 | self.__ui__.processbar_recycle.parameterUpdate(100)
31 | self.__ui__.processbar_recycle.parameterUpdate(0)
32 |
33 | self.__ui__.processbar_kitchen.parameterUpdate(100)
34 | self.__ui__.processbar_kitchen.parameterUpdate(0)
35 |
36 |
37 | # 连接信号
38 | self.__recycleNumberSignal__.connect(self.__ui__.setRecycleNumber)
39 | self.__kitchenNumberSignal__.connect(self.__ui__.setKitchenNumber)
40 | self.__harmfulNumberSignal__.connect(self.__ui__.setHarmfulNumber)
41 | self.__otherNumberSignal__.connect(self.__ui__.setOtherNumber)
42 |
43 | self.__ui__.LoadTest.clicked.connect(lambda:self.__loadFlash__())
44 | self.__ui__.ClearNumbers.clicked.connect(lambda:self.clear())
45 |
46 | # 垃圾数量统计
47 | self.__recycleNumber__ = 0
48 | self.__kitchenNumber__ = 0
49 | self.__harmfulNumber__ = 0
50 | self.__otherNumber__ = 0
51 |
52 | # 归零
53 | self.clear()
54 |
55 | # UI刷新线程
56 | self.__loadFlashThread__ = threading.Thread(target=self.__loadFlash__)
57 | self.__loadFlashThread__.setDaemon(True)
58 | self.__loadFlashThread__.start()
59 |
60 |
61 | # 清零计数
62 | def clear(self):
63 | self.__recycleNumber__ = 0
64 | self.__kitchenNumber__ = 0
65 | self.__harmfulNumber__ = 0
66 | self.__otherNumber__ = 0
67 |
68 | self.__recycleNumberSignal__.emit(0)
69 | self.__kitchenNumberSignal__.emit(0)
70 | self.__harmfulNumberSignal__.emit(0)
71 | self.__otherNumberSignal__.emit(0)
72 |
73 |
74 | def sum(self):
75 | return self.__recycleNumber__ + self.__kitchenNumber__ + self.__harmfulNumber__ + self.__otherNumber__
76 |
77 |
78 | # 增加垃圾数量
79 | def newRecycle(self):
80 | self.__recycleNumber__ += 1
81 | self.__recycleNumberSignal__.emit(self.__recycleNumber__)
82 | return self.sum(), self.__recycleNumber__
83 |
84 |
85 | def newKitchen(self):
86 | self.__kitchenNumber__ += 1
87 | self.__kitchenNumberSignal__.emit(self.__kitchenNumber__)
88 | return self.sum(), self.__kitchenNumber__
89 |
90 |
91 | def newHarmful(self):
92 | self.__harmfulNumber__ += 1
93 | self.__harmfulNumberSignal__.emit(self.__harmfulNumber__)
94 | return self.sum(), self.__harmfulNumber__
95 |
96 |
97 | def newOther(self):
98 | self.__otherNumber__ += 1
99 | self.__otherNumberSignal__.emit(self.__otherNumber__)
100 | return self.sum(), self.__otherNumber__
101 |
102 |
103 | # 设置slave
104 | def setSlave(self, slave):
105 | with self.__slaveLock__:
106 | self.__slave__ = slave
107 |
108 | def __loadFlash__(self):
109 | while True:
110 | time.sleep(10)
111 | with self.__slaveLock__:
112 | if not self.__slave__ is None:
113 | rec, kit, har, oth = self.__slave__.getLoadTest()
114 |
115 | self.__ui__.processbar_recycle.parameterUpdate(rec)
116 | self.__ui__.processbar_kitchen.parameterUpdate(kit)
117 | self.__ui__.processbar_harmful.parameterUpdate(har)
118 | self.__ui__.processbar_other.parameterUpdate(oth)
119 |
120 |
121 |
--------------------------------------------------------------------------------
/Software/Hardware/Slave.py:
--------------------------------------------------------------------------------
1 | # import pyserial
2 | import serial
3 |
4 | # import Helper libs
5 | import threading
6 |
7 | # import Helper libs
8 | import time
9 |
10 | class Slave():
11 | def __init__(self, com):
12 | self.__usart__ = serial.Serial(com, 115200, timeout=None)
13 |
14 | # 垃圾桶容量信息
15 | self.__loadLock__ = threading.Lock()
16 | self.__recycleLoad__ = 0
17 | self.__kitchenLoad__ = 0
18 | self.__harmfulLoad__ = 0
19 | self.__otherLoad__ = 0
20 |
21 | self.__receiveThread__ = threading.Thread(target=self.__receive__)
22 | self.__receiveThread__.setDaemon(True)
23 | self.__receiveThread__.start()
24 |
25 | self.__isSliderOK__ = False
26 | self.__SliderOKLock__ = threading.Lock()
27 |
28 |
29 | def __receive__(self):
30 | while True:
31 | try:
32 | msg = self.__usart__.readline().decode(encoding = "utf-8")
33 | msg = msg.replace("\r","").replace("\n","")
34 | except Exception:
35 | msg = ""
36 |
37 | if(msg.find(":") > 1):
38 | sp = msg.split(":")
39 |
40 | try:
41 | # 垃圾桶容量信息
42 | if(sp[0] == 'Capacity'):
43 | # 校验
44 | if(len(sp) == 3):
45 | with self.__loadLock__:
46 |
47 | # 可回收垃圾
48 | if(sp[1] == "Recycle"):
49 | self.__recycleLoad__ = int(float(sp[2]))
50 |
51 | # 厨余垃圾
52 | elif(sp[1] == "Kitchen"):
53 | self.__kitchenLoad__ = int(float(sp[2]))
54 |
55 | # 有害垃圾
56 | elif(sp[1] == "Harmful"):
57 | self.__harmfulLoad__ = int(float(sp[2]))
58 |
59 | # 其他垃圾
60 | elif(sp[1] == "Other"):
61 | self.__otherLoad__ = int(float(sp[2]))
62 |
63 | # 滑块事件
64 | elif(sp[0] == 'Slider'):
65 | # 校验
66 | if(len(sp) == 2):
67 | if(sp[1] == 'OK'):
68 | # Do someThing
69 | with self.__SliderOKLock__:
70 | self.isSliderOK = True
71 | pass
72 |
73 | except Exception as e:
74 | pass
75 |
76 |
77 | # 返回容量信息
78 | def getLoadTest(self):
79 | return self.__recycleLoad__, self.__kitchenLoad__, self.__harmfulLoad__, self.__otherLoad__
80 |
81 |
82 | # 控制传送带运动
83 | ## 传送带向前
84 | def conveyorForward(self):
85 | self.__usart__.write(("Conveyor:" + "Forward\r\n").encode("utf-8"))
86 |
87 | ## 传送带向后
88 | def conveyorBackward(self):
89 | self.__usart__.write(("Conveyor:" + "Backward\r\n").encode("utf-8"))
90 |
91 | ## 传送带停止
92 | def conveyorStop(self):
93 | self.__usart__.write(("Conveyor:" + "Stop\r\n").encode("utf-8"))
94 |
95 | # 托盘运送垃圾
96 | ## 懒得用阻塞了 直接等待就行
97 | def sendRecycle(self, timeout = 5):
98 | return self.__sendGarbage__("Recycle", timeout)
99 |
100 |
101 | def sendKitchen(self, timeout = 5):
102 | return self.__sendGarbage__("Kitchen", timeout)
103 |
104 |
105 | def sendHarmful(self, timeout = 5):
106 | return self.__sendGarbage__("Harmful", timeout)
107 |
108 |
109 | def sendOther(self, timeout = 5):
110 | return self.__sendGarbage__("Other", timeout)
111 |
112 |
113 | def __sendGarbage__(self, classes, timeout):
114 | startTime = time.time()
115 | with self.__SliderOKLock__:
116 | self.isSliderOK = False
117 |
118 | self.__usart__.write(("Slider:" + classes + "\r\n").encode("utf-8"))
119 | while((time.time() - startTime < timeout*1000) and not self.isSliderOK):
120 | time.sleep(0.1)
121 |
122 | with self.__SliderOKLock__:
123 | return self.__isSliderOK__
124 |
125 |
126 | # 开挡板
127 | def openBaffle(self, target):
128 | self.__usart__.write(("Baffle:" + target + ":Open\r\n").encode("utf-8"))
129 |
130 |
131 | # 关挡板
132 | def closeBaffle(self, target):
133 | self.__usart__.write(("Baffle:" + target + ":Close\r\n").encode("utf-8"))
134 |
135 |
136 | # 开始摇动中置隔板
137 | def shakeMiddleBaffle(self):
138 | self.__usart__.write(("Baffle:Middle:Shake\r\n").encode("utf-8"))
139 |
140 |
141 | # 停止摇动中置隔板
142 | def stopShakeMiddleBaffle(self):
143 | self.__usart__.write(("Baffle:Middle:Stop\r\n").encode("utf-8"))
144 |
145 | def sliderSend(self, classes):
146 | self.__usart__.write(("Slider:" + classes + "\r\n").encode("utf-8"))
147 |
148 |
--------------------------------------------------------------------------------
/Software/ImageProcessing/Detector.py:
--------------------------------------------------------------------------------
1 | # import Tensorflow
2 | import tensorflow as tf
3 | from tensorflow.keras.preprocessing import image
4 |
5 | # import PyQt5
6 | from PyQt5.QtGui import QImage, QPixmap
7 | from PyQt5.QtCore import pyqtSignal
8 | from PyQt5.QtWidgets import QWidget
9 |
10 | # Helper libraries
11 | import cv2 as cv
12 | import numpy as np
13 | import threading, signal
14 | import os
15 | import time
16 |
17 | # import resize tool
18 | from ImageProcessing.ResizeTo import ResizeTo
19 |
20 | class Detector(threading.Thread, QWidget):
21 | def __init__(self, ui, cameraID, threValue, weigthFile, className):
22 | threading.Thread.__init__(self)
23 | QWidget.__init__(self)
24 |
25 | # UI和摄像头
26 | self.__qlabel__ = ui.frame_label
27 | self.cameraID = cameraID
28 |
29 | # 背景阈值相关参数
30 | self.threValue = threValue
31 | self.threValueLock = threading.Lock()
32 |
33 | # 目标物体所在Rect
34 | ## 选择是否绘出Rect, 共用一个锁即可
35 | self.__drawRect__ = False
36 |
37 | ## 目标所在方框
38 | self.__rect__ = None
39 | self.__rectLock__ = threading.Lock()
40 |
41 | # 目标的边缘
42 | ## 选择是否绘出Contour
43 | self.__drawContour__ = False
44 |
45 | ## 目标轮廓
46 | self.__contour__ = None
47 | self.__contourLock__ = threading.Lock()
48 |
49 | # label和种类信息
50 | self.__className__ = className
51 |
52 | # 输出结果, 共用一个锁即可
53 | ## 选择是否在图像中标出结果
54 | self.__drawResult__ = False
55 |
56 | ## 推演出的结果
57 | self.__nameResult__ = None
58 | self.__probabilityResult__ = None
59 | self.__resultLock__ = threading.Lock()
60 |
61 |
62 | # Camera
63 | self.__capLock__ = threading.Lock()
64 | self.__cap__ = cv.VideoCapture(self.cameraID)
65 | self.__cap__.set(cv.CAP_PROP_FRAME_WIDTH, 640)
66 | self.__cap__.set(cv.CAP_PROP_FRAME_HEIGHT, 480)
67 |
68 | if(not self.__cap__.isOpened):
69 | raise Exception("Could not open camera: " + str(self.cameraID))
70 |
71 | # 创建显示线程且立即阻塞
72 | self.__displayFlag__ = threading.Event()
73 | self.__displayFlag__.clear()
74 |
75 | self.__displayThread__ = threading.Thread(target=self.__display__, )
76 | self.__displayThread__.setDaemon(True)
77 | self.__displayThread__.start()
78 |
79 | # Build Model
80 | physical_devices = tf.config.experimental.list_physical_devices('GPU')
81 | for physical_device in physical_devices:
82 | tf.config.experimental.set_memory_growth(physical_device, True)
83 | self.__model__ = tf.keras.applications.Xception(include_top=True,weights=weigthFile,input_shape=(299,299,3),classes=len(className),pooling="avg")
84 |
85 |
86 | # 获取单帧图像
87 | def getFrame(self):
88 | with self.__capLock__:
89 | ret, frame = self.__cap__.read()
90 | return frame
91 |
92 |
93 | # 需要显示的时候才调用此方法
94 | def show(self):
95 | self.__displayFlag__.set()
96 |
97 |
98 | # 但是不释放摄像头(懒得写)
99 | def pause(self):
100 | self.__displayFlag__.clear()
101 |
102 |
103 | # 私有方法, 显示图像用
104 | def __display__(self):
105 | while True:
106 | self.__displayFlag__.wait()
107 | image = self.getFrame()
108 |
109 | # 获取是否需要画出方框
110 | ## TODO: 支持多方框
111 | ## TODO: 使用完一次后即销毁
112 | rect = None
113 | with self.__rectLock__:
114 | if(self.__drawRect__):
115 | rect = self.__rect__
116 |
117 | # 获取是否需要画出结果
118 | ## TODO: 支持多结果
119 | ## TODO: 使用完一次后即销毁
120 | nameResult = None
121 | probabilityResult = None
122 |
123 | with self.__resultLock__:
124 | if(self.__drawResult__):
125 | nameResult = self.__nameResult__
126 | probabilityResult = self.__probabilityResult__
127 |
128 | # 绘制方框
129 | if(not rect is None):
130 | image = cv.rectangle(image, self.__rect__, (0, 255, 0), 2)
131 |
132 | # 绘制结果
133 | if(not nameResult is None):
134 | image = cv.putText(image, nameResult + " " + probabilityResult, (rect[0], rect[1] - 4), cv.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 0), 2)
135 | pass
136 |
137 | image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
138 | qImage = QImage(image.data, 640, 480, 640 * 3, QImage.Format_RGB888)
139 | self.__qlabel__.setPixmap(QPixmap.fromImage(qImage))
140 | time.sleep(0.03)
141 |
142 |
143 | # 预处理图像, 用黑色方块覆盖机械部分
144 | def getPreprocessedFrame(self, mask):
145 | return cv.bitwise_and(self.getFrame(), mask)
146 |
147 |
148 | # 将Frame左右分割
149 | ## 可选数据源
150 | def getSplitedFrame(self, frame = None):
151 | if frame is None:
152 | frame = self.getFrame()
153 |
154 | frame = cv.resize(frame, (398, 299))
155 |
156 | if(frame.ndim == 2):
157 | # 单通道图
158 | # 黑色底图
159 | leftFrame = np.zeros((299, 299), dtype= np.uint8)
160 | rightFrame = np.zeros((299, 299), dtype= np.uint8)
161 |
162 | # 将frame左右分别拷贝到leftFrame和rightFrame的中间
163 | np.copyto(leftFrame[0:299, 49:248], frame[0:299, 0:199])
164 | np.copyto(rightFrame[0:299, 49:248], frame[0:299, 199:398])
165 |
166 | else:
167 | # 三通道
168 | # 黑色底图
169 | leftFrame = np.zeros((299, 299, 3), dtype= np.uint8)
170 | rightFrame = np.zeros((299, 299, 3), dtype= np.uint8)
171 |
172 | # 将frame左右分别拷贝到leftFrame和rightFrame的中间
173 | np.copyto(leftFrame[0:299, 49:248], frame[0:299, 0:199])
174 | np.copyto(rightFrame[0:299, 49:248], frame[0:299, 199:398])
175 |
176 | return leftFrame, rightFrame
177 |
178 |
179 | # 检测垃圾是否被放置
180 | def hasObject(self, frame):
181 | ret = False
182 | thre = None
183 | # threshold
184 | with self.threValueLock:
185 | ret, thre = cv.threshold(frame, self.threValue, 255, cv.THRESH_TOZERO)
186 |
187 | # erode
188 | kernel = np.ones((5,5),np.uint8)
189 | erosion = cv.erode(thre, kernel, iterations = 1)
190 |
191 | # BGR To Gray
192 | gray = cv.cvtColor(erosion, cv.COLOR_BGR2GRAY)
193 |
194 | # findContours
195 | Contours, Hierarchy = cv.findContours(gray, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
196 |
197 | # output maximum area
198 | maxArea = 0
199 | maxContour = None
200 | for contour in Contours:
201 | area = cv.contourArea(contour)
202 | if(area > maxArea):
203 | maxArea = area
204 | maxContour = contour
205 |
206 | # output Rect of Item
207 | with self.__rectLock__:
208 | self.__rect__ = cv.boundingRect(maxContour)
209 |
210 | return maxArea, self.__rect__
211 |
212 |
213 | # 选择是否需要画出方框
214 | def drawRect(self, value):
215 | with self.__rectLock__:
216 | self.__drawRect__ = value
217 |
218 |
219 | # 选择是否绘制出边缘
220 | ## 这样效果会和Yolo有很明显的区别
221 | def drawContour(self, value):
222 | with self.__contourLock__:
223 | self.drawRect = value
224 |
225 |
226 | # 选择是否在图像中标出结果
227 | def drawResult(self, value):
228 | with self.__resultLock__:
229 | self.__drawResult__ = value
230 |
231 |
232 | # 预测种类
233 | # return: Name, classes, probability
234 | def predict(self, frame):
235 | frame = ResizeTo(frame, 299)
236 | frame = frame.astype(np.float32) / 255.0
237 | frame = image.img_to_array(cv.cvtColor(frame, cv.COLOR_BGR2RGB))
238 | imgList = []
239 | imgList.append(frame)
240 | imgs = np.array(imgList)
241 |
242 | predictions = self.__model__.predict(imgs)
243 |
244 | with self.__resultLock__:
245 | self.__nameResult__ = self.__className__[np.argmax(predictions[0])][1]
246 | self.__probabilityResult__ = str(100*np.max(predictions[0])) + "%"
247 |
248 | return self.__className__[np.argmax(predictions[0])][0], self.__className__[np.argmax(predictions[0])][2], self.__probabilityResult__
249 |
250 |
251 | # 录入新的物体(模板匹配)
252 | ## 省赛不需要 暂时不写
253 | def newObject(self):
254 | pass
255 |
256 |
257 | # 设置背景阈值
258 | def setThreValue(self, value):
259 | with self.threValueLock:
260 | self.threValue = value
--------------------------------------------------------------------------------
/Software/ImageProcessing/ResizeTo.py:
--------------------------------------------------------------------------------
1 | import cv2 as cv
2 | import numpy as np
3 |
4 | def ResizeTo(src, size):
5 |
6 | input_height = src.shape[0]
7 | input_width = src.shape[1]
8 | input_channels = src.shape[2]
9 |
10 | if(input_height > input_width):
11 | # 如果高大于宽
12 | # resize到最大边为width
13 | output_width = int(input_width * size / input_height)
14 | src = cv.resize(src,(output_width,size))
15 |
16 | mask = np.zeros([size + 2, size + 2, 1], np.uint8)
17 | background = np.zeros((size, size, input_channels), np.uint8)
18 |
19 | cv.floodFill(background, mask, (0, 0), (100, 100, 100), cv.FLOODFILL_MASK_ONLY)
20 |
21 | delta = int((size - output_width) / 2)
22 | np.copyto(background[0:size, delta:delta + output_width], src)
23 | src = background
24 |
25 |
26 | elif(input_height < input_width):
27 | # 宽大于高
28 | output_height = int(input_height * size / input_width)
29 | src = cv.resize(src,(size, output_height))
30 |
31 | mask = np.zeros([size + 2, size + 2, 1], np.uint8)
32 | background = np.zeros((size, size, input_channels), np.uint8)
33 |
34 | cv.floodFill(background, mask, (0, 0), (100, 100, 100), cv.FLOODFILL_MASK_ONLY)
35 |
36 | delta = int((size - output_height) / 2)
37 | np.copyto(background[delta:delta + output_height, 0:size], src)
38 | src = background
39 |
40 | elif(input_height == input_width):
41 | # 宽高相等
42 | src = cv.resize(src,(size,size))
43 |
44 | return src
--------------------------------------------------------------------------------
/Software/ImageProcessing/StandardExample.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/Software/ImageProcessing/StandardExample.jpg
--------------------------------------------------------------------------------
/Software/ImageProcessing/VideoPlayer.py:
--------------------------------------------------------------------------------
1 | # import PyQt5
2 | from PyQt5.QtGui import QImage, QPixmap
3 | from PyQt5.QtCore import Qt
4 |
5 | # import cv2
6 | import cv2 as cv
7 | import numpy as np
8 |
9 | # import helper libs
10 | import threading
11 | import time
12 | import os
13 |
14 | imgType_list = {'.jpg','.bmp','.png','.jpeg'}
15 |
16 | class VideoPlayer(threading.Thread):
17 | def __init__(self,Qlabel):
18 | threading.Thread.__init__(self)
19 | super(VideoPlayer, self).__init__()
20 | self.__qlabel__ = Qlabel
21 |
22 | # 创建播放线程 但立即阻塞
23 | self.__playerFlag__ = threading.Event()
24 | self.__playerFlag__.clear() # 立即阻塞
25 |
26 | self.thread = threading.Thread(target=self.__player__)
27 | self.thread.setDaemon(True)
28 | self.thread.start()
29 |
30 | # status:
31 | ## notWorking: 未在播放, Qlabel已经被释放
32 | ## working: 正在工作, Qlabel正在被占用
33 | self.status = "notWorking"
34 |
35 | # mode:
36 | ## picture: 循环播放图片
37 | ## video: 循环播放视频
38 | ## takeTurns: 循环播放图片和视频
39 | self.mode = None
40 |
41 | self.__cap__ = None
42 |
43 |
44 | # 循环播放视频
45 | def fromVideo(self, file = "./video.mp4"):
46 | if(self.status == "working"):
47 | self.pause()
48 | time.sleep(0.1)
49 | self.mode = 'video'
50 | self.__file__ = file
51 | self.resume()
52 |
53 | else:
54 | self.pause()
55 | time.sleep(0.1)
56 | self.mode = 'video'
57 | self.__file__ = file
58 |
59 |
60 | # 循环播放文件夹下所有图片
61 | def fromFloder(self, floder = "./imgs"):
62 | if(self.status == "working"):
63 | self.pause()
64 | time.sleep(0.1)
65 | self.mode = 'picture'
66 |
67 | self.photoList = []
68 | self.numberOfPictures = 0
69 |
70 | # Read images from floders
71 | ## ToDo: Rename files
72 | for files in os.listdir(floder):
73 | for imgtype in imgType_list:
74 | if(files.endswith(imgtype) and os.path.isfile(os.path.join(floder, files))):
75 | self.photoList.append(os.path.join(floder, files))
76 | self.numberOfPictures += 1
77 | break
78 |
79 | self.resume()
80 |
81 | else:
82 | self.mode = 'picture'
83 | self.photoList = []
84 | self.numberOfPictures = 0
85 |
86 | # Read images from floders
87 | ## ToDo: Rename files
88 | for files in os.listdir(floder):
89 | for imgtype in imgType_list:
90 | if(files.endswith(imgtype) and os.path.isfile(os.path.join(floder, files))):
91 | self.photoList.append(os.path.join(floder, files))
92 | self.numberOfPictures += 1
93 | break
94 |
95 |
96 | # 视频图片轮流播放
97 | def takeTurns(self, file = "./video.mp4", floder = "./imgs"):
98 | if(self.status == "working"):
99 | self.pause()
100 | time.sleep(0.1)
101 | self.mode = "takeTurns"
102 | self.__file__ = file
103 |
104 | self.photoList = []
105 | self.numberOfPictures = 0
106 |
107 | # Read images from floders
108 | ## ToDo: Rename files
109 | for files in os.listdir(floder):
110 | for imgtype in imgType_list:
111 | if(files.endswith(imgtype) and os.path.isfile(os.path.join(floder, files))):
112 | self.photoList.append(os.path.join(floder, files))
113 | self.numberOfPictures += 1
114 | break
115 |
116 | self.resume()
117 |
118 | else:
119 | self.mode = "takeTurns"
120 | self.__file__ = file
121 | self.photoList = []
122 | self.numberOfPictures = 0
123 |
124 | # Read images from floders
125 | ## ToDo: Rename files
126 | for files in os.listdir(floder):
127 | for imgtype in imgType_list:
128 | if(files.endswith(imgtype) and os.path.isfile(os.path.join(floder, files))):
129 | self.photoList.append(os.path.join(floder, files))
130 | self.numberOfPictures += 1
131 | break
132 |
133 |
134 | # 从cv2的numpy转换到QPixmap的内部实现
135 | ## 自动缩放, 不拉伸
136 | def __loadImage__(self,image):
137 | image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
138 | width = image.shape[1]
139 | height = image.shape[0]
140 | q_image = QImage(image.data, width, height, width * 3, QImage.Format_RGB888)
141 | if width / 640 >= height / 480:
142 | ratio = width / 640
143 | else:
144 | ratio = height / 480
145 | new_width = width / ratio
146 | new_height = height / ratio
147 | new_img = q_image.scaled(int(new_width), int(new_height), Qt.KeepAspectRatio)
148 | return QPixmap.fromImage(new_img)
149 |
150 |
151 | # 播放器的内部实现
152 | def __player__(self):
153 | self.__playerFlag__.wait()
154 | while True:
155 | if(self.mode == 'picture'):
156 | # Play from images
157 | if(self.numberOfPictures < 1):
158 | raise Exception("No Image(s) in this floder.")
159 |
160 | for img in self.photoList:
161 | image = cv.imread(img)
162 | if(image is None):
163 | continue
164 |
165 | self.__playerFlag__.wait()
166 |
167 | self.__qlabel__.setPixmap(self.__loadImage__(image))
168 | if(not self.mode == 'picture'):
169 | break
170 |
171 | time.sleep(self.__delay__)
172 |
173 |
174 | elif(self.mode == 'video'):
175 | # Play from Video
176 | if(self.__cap__ is None):
177 | self.__cap__ = cv.VideoCapture(self.__file__)
178 | if(not self.__cap__.isOpened()):
179 | raise Exception("Could not open VideoCapture: " + str(self.__file__))
180 |
181 | ret, frame = self.__cap__.read()
182 |
183 | if(ret):
184 | self.__playerFlag__.wait()
185 |
186 | self.__qlabel__.setPixmap(self.__loadImage__(frame))
187 | else:
188 | break
189 |
190 | time.sleep(1 / self.__cap__.get(cv.CAP_PROP_FPS))
191 |
192 | elif(self.mode == 'takeTurns'):
193 | # TakeTurns
194 | if(self.__cap__ is None):
195 | self.__cap__ = cv.VideoCapture(self.__file__)
196 | if(not self.__cap__.isOpened()):
197 | raise Exception("Could not open VideoCapture: " + str(self.__file__))
198 |
199 | ret = True
200 | ret, frame = self.__cap__.read()
201 |
202 | if(ret):
203 | self.__playerFlag__.wait()
204 |
205 | self.__qlabel__.setPixmap(self.__loadImage__(frame))
206 |
207 | time.sleep(1 / self.__cap__.get(cv.CAP_PROP_FPS))
208 | else:
209 | if(self.numberOfPictures < 1):
210 | raise Exception("No Image(s) in this floder.")
211 |
212 | for img in self.photoList:
213 | image = cv.imread(img)
214 | if(image is None):
215 | continue
216 |
217 | self.__playerFlag__.wait()
218 |
219 | self.__qlabel__.setPixmap(self.__loadImage__(image))
220 |
221 | if(not self.mode == 'takeTurns'):
222 | break
223 |
224 | time.sleep(self.__delay__)
225 |
226 | self.__cap__ = cv.VideoCapture(self.__file__)
227 | if(not self.__cap__.isOpened()):
228 | raise Exception("Could not open VideoCapture: " + str(self.__file__))
229 |
230 |
231 | # 开始播放
232 | def start(self, delay=1.5):
233 | self.__delay__ = delay
234 | self.__playerFlag__.set()
235 | self.status = "working"
236 |
237 |
238 | # 暂停播放
239 | def pause(self):
240 | if(self.status == "working"):
241 | self.__playerFlag__.clear() # 设置为False, 让线程阻塞
242 | self.status = "notWorking"
243 |
244 |
245 | # 继续播放
246 | def resume(self):
247 | if(self.status == "notWorking"):
248 | self.__playerFlag__.set()
249 | self.status = "working"
250 |
251 |
252 | # 销毁对象
253 | ## 懒得测试 应该没有内存泄漏
254 | def __del__(self):
255 | self.__playerFlag__.clear()
256 | time.sleep(0.1)
257 | if(not self.__cap__ == None):
258 | self.__cap__.release()
259 |
--------------------------------------------------------------------------------
/Software/ImageProcessing/multiModeMask.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/Software/ImageProcessing/multiModeMask.jpg
--------------------------------------------------------------------------------
/Software/ImageProcessing/singleModeMask.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/Software/ImageProcessing/singleModeMask.jpg
--------------------------------------------------------------------------------
/Software/QtUI/ConvertUIToPy.bat:
--------------------------------------------------------------------------------
1 | pyuic5 -o ./UI.py ./mainwindow.ui
--------------------------------------------------------------------------------
/Software/QtUI/ProcessBar.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import threading
3 | import math
4 | import time
5 |
6 | from PyQt5 import QtCore, QtGui
7 | from PyQt5.QtCore import Qt
8 | from PyQt5.QtGui import QPainter, QBrush, QColor, QPen
9 | from PyQt5.QtWidgets import QApplication, QWidget
10 |
11 | lock = threading.Lock()
12 | class RoundProgress(QWidget):
13 |
14 | def __init__(self):
15 | super(RoundProgress, self).__init__()
16 | self.persent = 0
17 | self.color = "#20a53a"
18 | # self.t = Thread_Updata()
19 | # self.t.mysignal.connect(self.parameterUpdateReal)
20 |
21 |
22 |
23 | def __parameterUpdateReal(self, p):
24 | lock.acquire()
25 | distance = math.floor(p) - math.ceil(self.persent) if p >= self.persent else math.floor(self.persent) - math.ceil(p)
26 | for i in range(distance):
27 | if p >= self.persent:
28 | self.persent+=1
29 | else:
30 | self.persent-=1
31 | self.update()
32 | time.sleep(0.005)
33 | lock.release()
34 |
35 | def parameterUpdate(self,p):
36 | if(p > 100):
37 | p = 100
38 | elif(p < 0):
39 | p = 0
40 | updateThread = threading.Thread(target=lambda :self.__parameterUpdateReal(p))
41 | updateThread.setDaemon(True)
42 | updateThread.start()
43 |
44 |
45 | def paintEvent(self, event):
46 | rotateAngle = 360 * self.persent / 100
47 | # 绘制准备工作,启用反锯齿
48 | painter = QPainter(self)
49 | painter.setRenderHints(QtGui.QPainter.Antialiasing)
50 |
51 | painter.setPen(QtCore.Qt.NoPen)
52 |
53 | painter.setBrush(QBrush(QColor("#cccccc")))
54 | painter.drawEllipse(3, 3, 120, 120) # 画外圆
55 |
56 | painter.setBrush(QBrush(QColor("#FFFFFF")))
57 | painter.drawEllipse(17, 17, 92, 92) # 画内圆
58 | if self.persent>=0 and self.persent<=50:
59 | color = "#20a53a"
60 | elif self.persent>50 and self.persent<=75:
61 | color = "#ff9900"
62 | else:
63 | color = "#FF0033"
64 | self.pen = QPen()
65 | self.pen.setBrush(QBrush(QColor(color))) # 设置画刷渐变效果
66 | self.pen.setWidth(14)
67 | self.pen.setCapStyle(Qt.RoundCap)
68 | painter.setPen(self.pen)
69 | painter.drawArc(QtCore.QRectF(10,10 , 106, 106), (90 - 0) * 16, -rotateAngle * 16) # 画圆环
70 |
71 | font = QtGui.QFont()
72 | font.setFamily("微软雅黑")
73 | font.setPointSize(11)
74 | painter.setFont(font)
75 | painter.setPen(QColor("#5481FF"))
76 | painter.drawText(QtCore.QRectF(6, 6, 122, 110), Qt.AlignCenter, "%d%%" % self.persent) # 显示进度条当前进度
77 |
78 |
--------------------------------------------------------------------------------
/Software/QtUI/RoundProcessBar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/Software/QtUI/RoundProcessBar.png
--------------------------------------------------------------------------------
/Software/QtUI/UI_Child.py:
--------------------------------------------------------------------------------
1 | from QtUI import UI
2 | from QtUI.ProcessBar import RoundProgress
3 | from PyQt5.QtCore import pyqtSignal
4 | from PyQt5.QtWidgets import QWidget
5 | from PyQt5.QtGui import QTextCursor
6 |
7 |
8 | class Ui_Main(UI.Ui_MainWindow, QWidget):
9 | def setupUi(self, MainWindow):
10 | super().setupUi(MainWindow)
11 |
12 | self.stackedWidget_Other.addWidget(self.processbar_other)
13 | self.stackedWidget_Harmful.addWidget(self.processbar_harmful)
14 | self.stackedWidget_Recycle.addWidget(self.processbar_recycle)
15 | self.stackedWidget_Kitchen.addWidget(self.processbar_kitchen)
16 | self.processbar_kitchen.show()
17 | self.processbar_other.show()
18 | self.processbar_recycle.show()
19 | self.processbar_harmful.show()
20 |
21 |
22 | def __init__(self):
23 | UI.Ui_MainWindow.__init__(self)
24 | QWidget.__init__(self)
25 |
26 | self.processbar_recycle = RoundProgress()
27 | self.processbar_harmful = RoundProgress()
28 | self.processbar_other = RoundProgress()
29 | self.processbar_kitchen = RoundProgress()
30 |
31 |
32 | def outputResult(self, result):
33 | self.textEdit.setText(result)
34 | self.textEdit.moveCursor(QTextCursor.End)
35 |
36 |
37 | def setRecycleNumber(self, number):
38 | self.RecycleNumbers.setText("当前件数: " + str(number))
39 |
40 |
41 | def setKitchenNumber(self, number):
42 | self.KitchenNumbers.setText("当前件数: " + str(number))
43 |
44 |
45 | def setHarmfulNumber(self, number):
46 | self.HarmfulNumbers.setText("当前件数: " + str(number))
47 |
48 |
49 | def setOtherNumber(self, number):
50 | self.OtherNumbers.setText("当前件数: " + str(number))
51 |
--------------------------------------------------------------------------------
/Software/Start.py:
--------------------------------------------------------------------------------
1 | # import PyQt5
2 | from PyQt5.QtWidgets import QApplication, QMainWindow
3 |
4 | # import UI
5 | from QtUI.UI_Child import Ui_Main
6 |
7 | # import Helper libs
8 | import sys
9 | import os
10 | import platform
11 | import argparse
12 |
13 | ## WorkingProcess
14 | from WorkingProcess.MainProcess import Process
15 |
16 | def main():
17 | # 如果被部署到Linux上 首先清除系统缓存以获取更大的可用内存
18 | if(platform.system()=='Linux'):
19 | os.system("sync; echo 3 > /proc/sys/vm/drop_caches")
20 |
21 | # 初始化UI
22 | app = QApplication(sys.argv)
23 |
24 | Mainw = QMainWindow()
25 | ui = Ui_Main()
26 | ui.setupUi(Mainw)
27 | Mainw.show()
28 |
29 | # argparse
30 | parser = argparse.ArgumentParser()
31 | if(platform.system()=='Windows'):
32 | parser.add_argument('--serial', type=str, default="COM5", help="Serial port")
33 | elif(platform.system()=='Linux'):
34 | parser.add_argument('--serial', type=str, default="/dev/ttyTHS1", help="Serial port")
35 |
36 | parser.add_argument('--cam', type=int, default=0, help="Camrea ID")
37 |
38 | parser.add_argument('--thre', type=int, default=170, help="threshold Value")
39 |
40 | parser.add_argument('--minArea', type=int, default=20, help="Minimum Area Of Object")
41 |
42 | parser.add_argument('--retry', type=int, default=5, help="Maximum number of attempts")
43 |
44 | args = parser.parse_args()
45 |
46 |
47 | # process
48 | process = Process(ui, args.cam, args.serial, args.thre, args.minArea, args.retry)
49 |
50 | sys.exit(app.exec_())
51 |
52 |
53 | if __name__ == "__main__":
54 | main()
55 |
--------------------------------------------------------------------------------
/Software/Start.sh:
--------------------------------------------------------------------------------
1 | python3 ./Start.py > log
2 |
--------------------------------------------------------------------------------
/Software/WorkingProcess/WorkingMode.py:
--------------------------------------------------------------------------------
1 | from enum import Enum
2 |
3 | '''
4 | # PreMode 初赛模式 -> 即一次投入一个垃圾
5 | # FinalMode 决赛模式 -> 即一次投入两个垃圾
6 | '''
7 |
8 | class Mode(Enum):
9 | preMode = 1
10 | finalMode = 2
11 |
--------------------------------------------------------------------------------
/Xception/Live.py:
--------------------------------------------------------------------------------
1 | # import TensorFlow
2 | import tensorflow as tf
3 | from tensorflow.keras.preprocessing import image
4 |
5 | # Helper libraries
6 | import cv2 as cv
7 | import numpy as np
8 | import threading, signal
9 | import os
10 | import time
11 |
12 | # Configure
13 | Image_Shape = (299,299)
14 | ## 权重文件的位置
15 | Weight_File_Path = "./Result977/Result.hdf5"
16 | Class_name = ['Battery','Brokenceramics','Cans','Cigarettebutts','Fruit','Paper','Tile','Vegetables','Walterbottles']
17 |
18 | frame = np.zeros((1,1), np.uint8)
19 | framelock = threading.Lock()
20 |
21 | name = None
22 | namelock = threading.Lock()
23 |
24 | probability = None
25 | probabilitylock = threading.Lock()
26 |
27 | def GetFrame():
28 | global frame
29 | cap = cv.VideoCapture(0)
30 | if(not cap.isOpened()):
31 | raise Exception("Open Capture error!")
32 |
33 | # Build Model
34 | model = tf.keras.applications.Xception(include_top=True,weights=Weight_File_Path,input_shape=(299,299,3),classes=len(Class_name),pooling="avg")
35 |
36 |
37 | while(True):
38 | ret, getframe = cap.read()
39 | shape = getframe.shape
40 | size = min(shape[0],shape[1])
41 | getframe = getframe[int((shape[0]-size)/2):int((shape[0]-size)/2) + size, int((shape[1]-size)/2):int((shape[1]-size)/2) + size]
42 |
43 | with framelock:
44 | frame = getframe.copy()
45 |
46 |
47 | def show():
48 | global frame
49 | while(True):
50 | with framelock:
51 | frame_show = frame.copy()
52 |
53 | with namelock:
54 | if(not name is None):
55 | frame_show = cv.putText(frame_show,name,(0, 18), cv.FONT_HERSHEY_SIMPLEX, 0.75, (255, 0, 0), 2)
56 |
57 | with probabilitylock:
58 | if(not probability is None):
59 | frame_show = cv.putText(frame_show,str(probability) + "%",(0, 32), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
60 |
61 | cv.imshow("Live",frame_show)
62 | cv.waitKey(1)
63 |
64 |
65 | def main():
66 | global frame, name, probability
67 |
68 | th_get = threading.Thread(target=GetFrame,)
69 | th_get.setDaemon(True)
70 | th_get.start()
71 |
72 | th_show = threading.Thread(target=show,)
73 | th_show.setDaemon(True)
74 | th_show.start()
75 |
76 | # Build Model
77 | model = tf.keras.applications.Xception(include_top=True,weights=Weight_File_Path,input_shape=(299,299,3),classes=len(Class_name),pooling="avg")
78 |
79 | while(True):
80 | with framelock:
81 | if(frame.shape == (480, 480, 3)):
82 | break
83 | else:
84 | time.sleep(1)
85 |
86 | while(True):
87 | frame_main = None
88 | with framelock:
89 | frame_main = frame.copy()
90 |
91 | frame_main = cv.resize(frame_main,Image_Shape)
92 | frame_main = frame_main.astype(np.float32) / 255.0
93 |
94 | templist = []
95 | templist.append(frame_main)
96 | img = np.array(templist)
97 |
98 | prediction = model.predict(img)
99 |
100 | with namelock:
101 | name = Class_name[np.argmax(prediction)]
102 | #print(name)
103 |
104 | with probabilitylock:
105 | probability = 100*np.max(prediction)
106 | #print(probability)
107 |
108 |
109 |
110 |
111 |
112 |
113 | if(__name__ == '__main__'):
114 | main()
--------------------------------------------------------------------------------
/Xception/Train.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | from tensorflow import keras
3 | from tensorflow.keras import datasets, layers, models
4 | from tensorflow.keras.preprocessing.image import ImageDataGenerator
5 | from tensorflow.keras.preprocessing import image
6 | from tensorflow.keras.applications.imagenet_utils import preprocess_input
7 |
8 | # Helper libraries
9 | import cv2 as cv
10 | import numpy as np
11 | import matplotlib.pyplot as plt
12 | import pandas as pd
13 | import PIL
14 |
15 | # System API
16 | import os
17 |
18 | # Configure
19 | # 以下内容请和 Valid.py 中的匹配
20 | ## 源图片的总文件夹位置
21 | Base_Dir = "E:/TensorFlow/datasets/garbage_finally/"
22 | train_dir = Base_Dir + "Train"
23 | validation_dir = Base_Dir + "Valid"
24 | log_dir = "./log"
25 | ## 导入模型的图片大小, 没必要修改, 但是尽量和使用时设置的一致。
26 | Image_Shape = (299,299)
27 | batch_size = 4
28 | classes = 10
29 | epochs = 25
30 | save_dir='./weights'
31 | filepath="epoch-{epoch:02d}-val_acc-{val_accuracy:.4f}-acc_top3-{acc_top3:.4f}-acc_top5-{acc_top5:.4f}.hdf5"
32 | learning_rate = 0.0005 #0.0005
33 |
34 | physical_devices = tf.config.experimental.list_physical_devices('GPU')
35 | for physical_device in physical_devices:
36 | tf.config.experimental.set_memory_growth(physical_device, True)
37 |
38 | # 定义训练集图像生成器,并进行图像增强
39 | train_image_generator = ImageDataGenerator( rescale=1./255, # 归一化
40 | rotation_range=40, #旋转范围
41 | width_shift_range=0.2, #水平平移范围
42 | height_shift_range=0.2, #垂直平移范围
43 | shear_range=0.2, #剪切变换的程度
44 | zoom_range=0.2, #缩放范围
45 | horizontal_flip=True, #水平翻转
46 | fill_mode='nearest')
47 |
48 | # 使用图像生成器从文件夹train_dir中读取样本,对标签进行one-hot编码
49 | train_data_gen = train_image_generator.flow_from_directory(directory=train_dir,
50 | batch_size=batch_size,
51 | shuffle=True, #打乱数据
52 | target_size=Image_Shape,
53 | class_mode='categorical')
54 | # 训练集样本数
55 | total_train = train_data_gen.n
56 |
57 | # 定义验证集图像生成器,并对图像进行预处理
58 | validation_image_generator = ImageDataGenerator(rescale=1./255) #归一化
59 |
60 | # 使用图像生成器从验证集validation_dir中读取样本
61 | val_data_gen = validation_image_generator.flow_from_directory(directory=validation_dir,
62 | batch_size=batch_size,
63 | shuffle=False, #不打乱数据
64 | target_size=Image_Shape,
65 | class_mode='categorical')
66 | # 验证集样本数
67 | total_val = val_data_gen.n
68 |
69 | # Build Model
70 | base_model = tf.keras.applications.Xception(weights="imagenet",include_top=False,input_shape=(299, 299, 3),pooling="avg")
71 | outputs = layers.Dense(classes, activation='softmax')(base_model.output)
72 | model = keras.Model(base_model.inputs, outputs)
73 |
74 | # Callbacks
75 | ## Checkpoint
76 | checkpoint = keras.callbacks.ModelCheckpoint(os.path.join(save_dir, filepath),
77 | monitor='val_acc',verbose=1,
78 | save_best_only=False)
79 |
80 | ## Tensorboard Callback
81 | tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
82 |
83 | # acc
84 | def acc_top3(y_true, y_pred):
85 | return keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=3)
86 |
87 | def acc_top5(y_true, y_pred):
88 | return keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=5)
89 |
90 | # compile
91 | model.compile(optimizer=tf.keras.optimizers.Adam(lr=learning_rate),
92 | loss='categorical_crossentropy',
93 | metrics=['accuracy', acc_top3, acc_top5])
94 |
95 | # 模型训练
96 | model.fit(x=train_data_gen,
97 | steps_per_epoch=total_train // batch_size,
98 | epochs=epochs,
99 | shuffle=True,
100 | validation_data=val_data_gen,
101 | validation_steps=total_val // batch_size,
102 | callbacks=[checkpoint,tensorboard_callback])
103 |
--------------------------------------------------------------------------------
/Xception/Valid.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | from tensorflow.keras.preprocessing import image
3 |
4 | # Helper libraries
5 | import cv2 as cv
6 | import numpy as np
7 | import matplotlib.pyplot as plt
8 | from PIL import Image
9 | from datetime import datetime
10 |
11 | # System API
12 | import os
13 |
14 | # Configure
15 | ## 源图片的总文件夹位置, 尽量保证输入图片的长宽比为1:1即可, 程序会自动缩放。
16 | Base_Dir = '../../datasets/garbage_finally/'
17 | ## 权重文件的位置
18 | Weight_File_Path = "./weights/epoch-140-val_acc-0.9651-acc_top3-1.0000-acc_top5-1.0000.hdf5"
19 |
20 | Image_Shape = (299,299)
21 | Base_Dir = Base_Dir + "Test"
22 |
23 | # Load Images
24 | def LoadImages(Dir,label):
25 | Input_image_list = []
26 | Source_image_list = []
27 | Input_label_list = []
28 |
29 | for Files in os.listdir(Dir):
30 | if(os.path.isfile(Dir + "/" + Files)):
31 | print("Loading " + Dir + "/" + Files)
32 | cv_img = cv.imread(Dir + "/" + Files)
33 | cv_img = cv.resize(cv_img,(299,299))
34 | cv_img = cv_img.astype(np.float32) / 255.0
35 | img = image.img_to_array(cv.cvtColor(cv_img,cv.COLOR_BGR2RGB))
36 | Input_image_list.append(img)
37 | Input_label_list.append(label)
38 |
39 | return Input_image_list,Input_label_list
40 |
41 | def plot_image(i, predictions_array, true_label, img, Class_name):
42 | predictions_array, true_label, img = predictions_array, true_label[i], img[i]
43 | plt.grid(False)
44 | plt.xticks([])
45 | plt.yticks([])
46 |
47 | plt.imshow(img, cmap=plt.cm.binary)
48 |
49 | predicted_label = np.argmax(predictions_array)
50 | if predicted_label == true_label:
51 | color = 'blue'
52 | else:
53 | color = 'red'
54 |
55 | plt.xlabel("{} {:2.0f}% ({})".format(Class_name[predicted_label],
56 | 100*np.max(predictions_array),
57 | Class_name[true_label]),
58 | color=color)
59 |
60 |
61 | def plot_value_array(i, predictions_array, true_label, classes):
62 | predictions_array, true_label = predictions_array, true_label[i]
63 | plt.grid(False)
64 | plt.xticks(range(classes))
65 | plt.yticks([])
66 | thisplot = plt.bar(range(classes), predictions_array, color="#777777")
67 | plt.ylim([0, 1])
68 | predicted_label = np.argmax(predictions_array)
69 |
70 | thisplot[predicted_label].set_color('red')
71 | thisplot[true_label].set_color('blue')
72 |
73 |
74 | def main():
75 | image_list = []
76 | label_list = []
77 | Class_name = []
78 |
79 | index = 0
80 | for dirs in os.listdir(Base_Dir):
81 | if(os.path.isdir(Base_Dir + "/" + dirs)):
82 | temp_image_list,temp_label_list = LoadImages(Base_Dir + "/" + dirs,index)
83 | image_list = image_list + temp_image_list
84 | label_list = label_list + temp_label_list
85 | Class_name.append(dirs)
86 |
87 | index += 1
88 |
89 | test_images = np.array(image_list)
90 | test_labels = label_list
91 |
92 | # Build Model
93 | model = tf.keras.applications.Xception(include_top=True,weights=Weight_File_Path,input_shape=(299,299,3),classes=len(Class_name),pooling="avg")
94 |
95 | StartTime = datetime.now()
96 | predictions = model.predict(np.array(test_images))
97 | EndTime = datetime.now()
98 | print(predictions)
99 |
100 | print(str((EndTime - StartTime).microseconds / len(test_images)) + " us per picture.")
101 |
102 | Correct = 0
103 | for i in range(len(test_images)):
104 | if(np.argmax(predictions[i]) == test_labels[i]):
105 | Correct += 1
106 |
107 | print("Accuracy: " + str(Correct / len(test_images)))
108 |
109 | index = 0
110 | while(index < len(test_images)):
111 | num_rows = 5
112 | num_cols = 4
113 | num_images = num_rows*num_cols
114 | plt.figure(figsize=(2*2*num_cols, 2*num_rows))
115 | for i in range(num_images):
116 | if(i + index < len(test_images)):
117 | plt.subplot(num_rows, 2*num_cols, 2*i+1)
118 | plot_image(i + index, predictions[i + index], test_labels, test_images, Class_name)
119 | plt.subplot(num_rows, 2*num_cols, 2*i+2)
120 | plot_value_array(i + index, predictions[i + index], test_labels, len(Class_name))
121 | plt.tight_layout()
122 | plt.show()
123 |
124 | index += 20
125 |
126 |
127 | if __name__ == '__main__':
128 | main()
--------------------------------------------------------------------------------
/Xception/tensorboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/Xception/tensorboard.png
--------------------------------------------------------------------------------
/images/FrontView.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/images/FrontView.jpg
--------------------------------------------------------------------------------
/images/SideView.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/images/SideView.jpg
--------------------------------------------------------------------------------
/tools/Readme.md:
--------------------------------------------------------------------------------
1 | # 调参工具
2 | ## hasObject
3 | 用于调节 "检测是否有垃圾放入" 功能 (即 `Detector.hasObject()`)的参数。
4 | 主要为了适应各种环境光线等的变化
5 |
6 |
--------------------------------------------------------------------------------
/tools/Sample/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/tools/Sample/1.jpg
--------------------------------------------------------------------------------
/tools/Sample/mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/tools/Sample/mask.png
--------------------------------------------------------------------------------
/tools/Sample/preprocess.py:
--------------------------------------------------------------------------------
1 | import cv2 as cv
2 | import numpy as np
3 |
4 | input = cv.imread("./1.jpg")
5 | mask = cv.imread("./mask.png")
6 |
7 | end = cv.bitwise_and(input, mask)
8 |
9 | cv.imshow("end", end)
10 | cv.waitKey(0)
11 |
--------------------------------------------------------------------------------
/tools/cameraTest/cameraTest.py:
--------------------------------------------------------------------------------
1 | import cv2 as cv
2 |
3 | cap = cv.VideoCapture(0)
4 | cap.set(cv.CAP_PROP_FRAME_WIDTH, 640)
5 | cap.set(cv.CAP_PROP_FRAME_HEIGHT, 480)
6 |
7 | while True:
8 | ret, frame = cap.read()
9 |
10 | frame = cv.flip(frame, -1)
11 |
12 | cv.imshow("frame", frame)
13 |
14 | cv.waitKey(1)
--------------------------------------------------------------------------------
/tools/hasObject/hasObject.py:
--------------------------------------------------------------------------------
1 | import cv2 as cv
2 | import numpy as np
3 |
4 | cap = cv.VideoCapture(0)
5 |
6 | while True:
7 | ret, src = cap.read()
8 | cv.imshow("src", src)
9 |
10 | # threshold
11 | ret, thre = cv.threshold(src, 100, 255, cv.THRESH_TOZERO)
12 | #ret, thre = cv.threshold(src, 150, 255, cv.THRESH_TOZERO)
13 |
14 | cv.imshow("thre", thre)
15 |
16 | # Method 1
17 | ## erode
18 | kernel = np.ones((5,5),np.uint8)
19 | erosion = cv.erode(thre, kernel, iterations = 1)
20 |
21 | cv.imshow("erosion", erosion)
22 |
23 | # Method 2
24 | ## gray
25 | gray = cv.cvtColor(erosion, cv.COLOR_BGR2GRAY)
26 |
27 | ## findContours
28 | contours, hierarchy = cv.findContours(gray, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
29 |
30 | blank = np.zeros(gray.shape, dtype=np.uint8)
31 |
32 | ## output
33 | output = blank.copy()
34 | for contour in contours:
35 | if(cv.contourArea(contour) > 10):
36 | cv.drawContours(output, [contour], -1, (255, 255, 255), 2)
37 |
38 | cv.imshow("findContours", output)
39 |
40 | ## newObject
41 | maxId = -1
42 | maxArea = 0
43 | maxContour = None
44 |
45 | currentId = 0
46 | for contour in contours:
47 | area = cv.contourArea(contour)
48 | if(area > maxArea):
49 | maxArea = area
50 | maxId = currentId
51 | maxContour = contour
52 | currentId += 1
53 |
54 | max = blank.copy()
55 | cv.drawContours(max, contours, maxId, (255, 255, 255), 2)
56 | print(maxId)
57 |
58 | cv.imshow("max", max)
59 |
60 | ## draw
61 | x, y, w, h = cv.boundingRect(maxContour)
62 | drawed = cv.rectangle(src,(x,y),(x+w,y+h),(0,255,0),2)
63 | cv.imshow("draw", drawed)
64 |
65 | ## Cut
66 | if((w > 0) and (h > 0)):
67 | cv.imshow("cut",src[y:y+h,x:x+w])
68 |
69 | cv.waitKey(10)
70 |
--------------------------------------------------------------------------------
/yolo-fastest/backup/yolo-fastest_best.weights:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/yolo-fastest/backup/yolo-fastest_best.weights
--------------------------------------------------------------------------------
/yolo-fastest/test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/yolo-fastest/test.png
--------------------------------------------------------------------------------
/yolo-fastest/train.data:
--------------------------------------------------------------------------------
1 | classes=7
2 | train = E:/TensorFlow/datasets/Garbage_YOLO_1.25/train.txt
3 | valid = E:/TensorFlow/datasets/Garbage_YOLO_1.25/valid.txt
4 | names = E:/TensorFlow/datasets/Garbage_YOLO_1.25/Garbage.names
5 | backup = E:/TensorFlow/DarkNet_YOLOv4/Yolo-Fastest/Garbage_COCO_1.25/backup
--------------------------------------------------------------------------------
/yolo-fastest/yolo-fastest.conv.109:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/yolo-fastest/yolo-fastest.conv.109
--------------------------------------------------------------------------------
/第七届全国大学生工程训练综合能力竞赛(重庆)命题与运行-终稿20210222.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/h13-0/Garbage-Classification/fb8e71b431620e6cecc6664b820e13e4499f65ef/第七届全国大学生工程训练综合能力竞赛(重庆)命题与运行-终稿20210222.pdf
--------------------------------------------------------------------------------