├── .gitignore ├── README.md ├── example ├── offchip │ ├── Ethernet │ │ └── stm32f103c8t6 │ │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── UserInterrupt.cpp │ │ │ ├── UserInterrupt.h │ │ │ └── main.cpp │ │ │ └── demo.uvprojx │ ├── MFRC522 │ │ └── stm32f103c8t6 │ │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── UserInterrupt.cpp │ │ │ ├── UserInterrupt.h │ │ │ └── main.cpp │ │ │ └── demo.uvprojx │ ├── PN53x │ │ └── stm32f103c8t6 │ │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── UserInterrupt.cpp │ │ │ ├── UserInterrupt.h │ │ │ └── main.cpp │ │ │ └── demo.uvprojx │ ├── SPIFlash │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── Main.cpp │ │ │ ├── UserInterrupt.cpp │ │ │ └── UserInterrupt.h │ │ └── demo.uvprojx │ ├── Si7021 │ │ └── stm32f103c8t6 │ │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── UserInterrupt.cpp │ │ │ ├── UserInterrupt.h │ │ │ └── main.cpp │ │ │ └── demo.uvprojx │ └── esp8266 │ │ └── stm32f103c8t6 │ │ ├── RTE │ │ ├── Device │ │ │ └── STM32F103C8 │ │ │ │ ├── RTE_Device.h │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ └── system_stm32f10x.c │ │ └── RTE_Components.h │ │ ├── demo.uvprojx │ │ └── system │ │ ├── Configuration.h │ │ ├── UserInterrupt.cpp │ │ ├── UserInterrupt.h │ │ └── main.cpp └── onchip │ ├── CAN │ └── stm32f103c8t6 │ │ ├── RTE │ │ ├── Device │ │ │ └── STM32F103C8 │ │ │ │ ├── RTE_Device.h │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ └── system_stm32f10x.c │ │ └── RTE_Components.h │ │ ├── app │ │ ├── Configuration.h │ │ ├── UserInterrupt.cpp │ │ ├── UserInterrupt.h │ │ └── main.cpp │ │ └── demo.uvprojx │ ├── Flash │ └── stm32f103c8t6 │ │ ├── RTE │ │ ├── Device │ │ │ └── STM32F103C8 │ │ │ │ ├── RTE_Device.h │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ └── system_stm32f10x.c │ │ └── RTE_Components.h │ │ ├── demo.uvprojx │ │ └── system │ │ ├── Configuration.h │ │ ├── UserInterrupt.cpp │ │ ├── UserInterrupt.h │ │ └── main.cpp │ ├── GPIO │ └── stm32f103c8t6 │ │ ├── RTE │ │ ├── Device │ │ │ └── STM32F103C8 │ │ │ │ ├── RTE_Device.h │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ └── system_stm32f10x.c │ │ └── RTE_Components.h │ │ ├── demo.uvprojx │ │ └── system │ │ ├── Configuration.h │ │ ├── Interrupt.cpp │ │ ├── Interrupt.h │ │ ├── UserInterrupt.cpp │ │ ├── UserInterrupt.h │ │ └── main.cpp │ ├── IAP │ ├── app │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── UserInterrupt.cpp │ │ │ ├── UserInterrupt.h │ │ │ └── main.cpp │ │ ├── demo.uvprojx │ │ └── runToApp.ini │ ├── bootloader │ │ ├── RTE │ │ │ ├── Device │ │ │ │ └── STM32F103C8 │ │ │ │ │ ├── RTE_Device.h │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ │ └── system_stm32f10x.c │ │ │ └── RTE_Components.h │ │ ├── app │ │ │ ├── Configuration.h │ │ │ ├── LED_Min.cpp │ │ │ ├── LED_Min.h │ │ │ ├── UserInterrupt.cpp │ │ │ ├── UserInterrupt.h │ │ │ └── main.cpp │ │ └── demo.uvprojx │ └── toolApp │ │ └── STM32_IAP.py │ ├── IWDG │ └── stm32f103c8t6 │ │ ├── RTE │ │ ├── Device │ │ │ └── STM32F103C8 │ │ │ │ ├── RTE_Device.h │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ └── system_stm32f10x.c │ │ └── RTE_Components.h │ │ ├── app │ │ ├── Configuration.h │ │ ├── UserInterrupt.cpp │ │ ├── UserInterrupt.h │ │ └── main.cpp │ │ └── demo.uvprojx │ ├── TIM │ └── stm32f103c8t6 │ │ ├── RTE │ │ ├── Device │ │ │ └── STM32F103C8 │ │ │ │ ├── RTE_Device.h │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ ├── stm32f10x_conf.h │ │ │ │ └── system_stm32f10x.c │ │ └── RTE_Components.h │ │ ├── demo.uvprojx │ │ └── system │ │ ├── Configuration.h │ │ ├── Interrupt.cpp │ │ ├── Interrupt.h │ │ ├── UserInterrupt.cpp │ │ ├── UserInterrupt.h │ │ └── main.cpp │ └── USART │ └── stm32f103c8t6 │ ├── RTE │ ├── Device │ │ └── STM32F103C8 │ │ │ ├── RTE_Device.h │ │ │ ├── startup_stm32f10x_md.s │ │ │ ├── stm32f10x_conf.h │ │ │ └── system_stm32f10x.c │ └── RTE_Components.h │ ├── app │ ├── Configuration.h │ ├── UserInterrupt.cpp │ ├── UserInterrupt.h │ └── main.cpp │ └── demo.uvprojx ├── lib ├── math │ ├── AHRS_DCM.h │ ├── FIFOBuffer.h │ ├── Matrix3.h │ ├── PIDController.h │ ├── Quaternion.h │ └── Vector3.h ├── offchip │ ├── BLDCMotor │ │ ├── BLDCMotor.cpp │ │ └── BLDCMotor.h │ ├── Door │ │ ├── door.cpp │ │ └── door.h │ ├── Ethernet │ │ ├── README.md │ │ ├── examples │ │ │ ├── AdvancedChatServer │ │ │ │ └── AdvancedChatServer.ino │ │ │ ├── BarometricPressureWebServer │ │ │ │ └── BarometricPressureWebServer.ino │ │ │ ├── ChatServer │ │ │ │ └── ChatServer.ino │ │ │ ├── DhcpAddressPrinter │ │ │ │ └── DhcpAddressPrinter.ino │ │ │ ├── DhcpChatServer │ │ │ │ └── DhcpChatServer.ino │ │ │ ├── TelnetClient │ │ │ │ └── TelnetClient.ino │ │ │ ├── Twitter_Serial_GW │ │ │ │ └── Twitter_Serial_GW.ino │ │ │ ├── Twitter_SimplePost │ │ │ │ └── Twitter_SimplePost.ino │ │ │ ├── UDPSendReceiveString │ │ │ │ └── UDPSendReceiveString.ino │ │ │ ├── UdpNtpClient │ │ │ │ └── UdpNtpClient.ino │ │ │ ├── WebClient │ │ │ │ └── WebClient.ino │ │ │ ├── WebClientRepeating │ │ │ │ └── WebClientRepeating.ino │ │ │ ├── WebServer │ │ │ │ └── WebServer.ino │ │ │ ├── XivelyClient │ │ │ │ └── XivelyClient.ino │ │ │ └── XivelyClientString │ │ │ │ └── XivelyClientString.ino │ │ ├── keywords.txt │ │ ├── library.properties │ │ └── src │ │ │ ├── Client.h │ │ │ ├── Dhcp.cpp │ │ │ ├── Dhcp.h │ │ │ ├── Dns.cpp │ │ │ ├── Dns.h │ │ │ ├── EthernetClient.cpp │ │ │ ├── EthernetClient.h │ │ │ ├── EthernetUdp.cpp │ │ │ ├── EthernetUdp.h │ │ │ ├── Ethernet_STM.cpp │ │ │ ├── Ethernet_STM.h │ │ │ ├── util.h │ │ │ └── utility │ │ │ ├── IPAddress.cpp │ │ │ ├── IPAddress.h │ │ │ ├── Stream.h │ │ │ ├── Udp.h │ │ │ ├── socket.cpp │ │ │ ├── socket.h │ │ │ ├── util.cpp │ │ │ ├── util.h │ │ │ ├── w5500.cpp │ │ │ └── w5500.h │ ├── GPS │ │ ├── GPS.cpp │ │ ├── GPS.h │ │ ├── main.cpp │ │ ├── stm32f10x.cpp │ │ └── stm32f10x_it.h │ ├── HCHO │ │ ├── HCHO.cpp │ │ ├── HCHO.h │ │ └── Senser.h │ ├── HMC5883L │ │ ├── HMC5883L.cpp │ │ └── HMC5883L.h │ ├── HMI │ │ ├── HMI.cpp │ │ └── HMI.h │ ├── Humidity │ │ └── Humidity.h │ ├── Joystick │ │ ├── Joystick.cpp │ │ └── Joystick.h │ ├── LED │ │ ├── LED.cpp │ │ └── LED.h │ ├── MFRC522 │ │ ├── MFRC522.cpp │ │ └── MFRC522.h │ ├── MG996R │ │ └── readme.md │ ├── MHZ14 │ │ ├── MHZ14.cpp │ │ └── MHZ14.h │ ├── MPU6050 │ │ ├── InertialSensor.h │ │ ├── mpu6050.cpp │ │ └── mpu6050.h │ ├── PN53x │ │ ├── PN53x.cpp │ │ └── PN53x.h │ ├── Relay │ │ ├── Relay.cpp │ │ └── Relay.h │ ├── Remote Control │ │ ├── RemoteControl.cpp │ │ └── RemoteControl.h │ ├── SHARP_1014_PM2_5 │ │ ├── SHARP_1014_PM2_5.cpp │ │ └── SHARP_1014_PM2_5.h │ ├── SHARP_1051_PM2_5 │ │ ├── SHARP_PM2_5.cpp │ │ └── SHARP_PM2_5.h │ ├── SPIFlash │ │ ├── SPIFlash.cpp │ │ └── SPIFlash.h │ ├── Si7021 │ │ ├── Si7021.cpp │ │ └── Si7021.h │ ├── Temperature │ │ └── Temperature.h │ ├── ZPH01 │ │ ├── Senser.h │ │ ├── ZPH01.cpp │ │ └── ZPH01.h │ ├── esp8266 │ │ ├── README.md │ │ ├── Socket_esp8266.cpp │ │ ├── Socket_esp8266.h │ │ ├── esp8266.cpp │ │ ├── esp8266.h │ │ └── socket.h │ └── yishan_PM2_5 │ │ ├── yishan_PM2_5.cpp │ │ └── yishan_PM2_5.h └── onchip │ ├── ADC │ ├── ADC.cpp │ └── ADC.h │ ├── CAN │ ├── can.cpp │ └── can.h │ ├── GPIO │ ├── GPIO.cpp │ └── GPIO.h │ ├── I2C │ ├── I2C.cpp │ ├── I2C.h │ └── Sensor.h │ ├── IAP │ ├── IAP.cpp │ ├── IAP.h │ ├── IAP_USART.cpp │ └── IAP_USART.h │ ├── IWDG │ ├── IWDG.cpp │ └── IWDG.h │ ├── PWM │ ├── PWM.cpp │ └── PWM.h │ ├── SPI │ ├── SPI.cpp │ └── SPI.h │ ├── USART │ ├── USART.cpp │ ├── USART.cpp.old │ └── USART.h │ ├── Util │ ├── Assert.cpp │ └── Assert.h │ ├── capture │ ├── InputCapture_EXIT.cpp │ ├── InputCapture_EXIT.h │ ├── InputCapture_TIM.cpp │ └── InputCapture_TIM.h │ ├── delay │ ├── Delay.cpp │ └── Delay.h │ ├── flash │ ├── Flash.cpp │ └── Flash.h │ ├── interrupt │ ├── Interrupt.cpp │ └── Interrupt.h │ ├── taskManager │ ├── TaskManager.cpp │ └── TaskManager.h │ └── timer │ ├── Timer.cpp │ └── Timer.h ├── template └── MDK │ └── stm32103c8t6 │ ├── RTE │ ├── Device │ │ └── STM32F103C8 │ │ │ ├── RTE_Device.h │ │ │ ├── startup_stm32f10x_md.s │ │ │ ├── stm32f10x_conf.h │ │ │ └── system_stm32f10x.c │ └── RTE_Components.h │ ├── app │ ├── Configuration.h │ ├── Main.cpp │ ├── UserInterrupt.cpp │ └── UserInterrupt.h │ └── demo.uvprojx └── tool └── clean_project_files.bat /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | #out folder 16 | out 17 | listing 18 | Objects 19 | listings 20 | Listings 21 | 22 | #MDK project file 23 | JLinkLog.txt 24 | JLinkSettings.ini 25 | *.guild_log.htm 26 | *.uvguix.* 27 | *_uvoptx.bak 28 | *_uvprojx.bak 29 | *.dep 30 | *.uvoptx 31 | *.*.bak 32 | 33 | *.dbgconf 34 | 35 | 36 | ProjectTemplate 37 | -------------------------------------------------------------------------------- /example/offchip/Ethernet/stm32f103c8t6/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | #define RTE_DEVICE_STDPERIPH_DMA 20 | #define RTE_DEVICE_STDPERIPH_EXTI 21 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 22 | #define RTE_DEVICE_STDPERIPH_GPIO 23 | #define RTE_DEVICE_STDPERIPH_I2C 24 | #define RTE_DEVICE_STDPERIPH_IWDG 25 | #define RTE_DEVICE_STDPERIPH_RCC 26 | #define RTE_DEVICE_STDPERIPH_SPI 27 | #define RTE_DEVICE_STDPERIPH_USART 28 | 29 | #endif /* RTE_COMPONENTS_H */ 30 | -------------------------------------------------------------------------------- /example/offchip/Ethernet/stm32f103c8t6/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | #ifdef USE_TIMER1 6 | void Timer1_IRQ() 7 | { 8 | 9 | } 10 | #endif 11 | 12 | #ifdef USE_TIMER2 13 | void Timer2_IRQ() 14 | { 15 | 16 | } 17 | #endif 18 | 19 | #ifdef USE_TIMER3 20 | void Timer3_IRQ() 21 | { 22 | 23 | } 24 | #endif 25 | 26 | #ifdef USE_TIMER4 27 | void Timer4_IRQ() 28 | { 29 | 30 | } 31 | #endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | #ifdef USE_EXTI0 36 | void EXTI0_IRQ() 37 | { 38 | } 39 | #endif 40 | #ifdef USE_EXTI1 41 | void EXTI1_IRQ() 42 | { 43 | } 44 | #endif 45 | #ifdef USE_EXTI2 46 | void EXTI2_IRQ() 47 | { 48 | } 49 | #endif 50 | #ifdef USE_EXTI3 51 | void EXTI3_IRQ() 52 | { 53 | } 54 | #endif 55 | #ifdef USE_EXTI4 56 | void EXTI4_IRQ() 57 | { 58 | } 59 | #endif 60 | #ifdef USE_EXTI5 61 | void EXTI5_IRQ() 62 | { 63 | } 64 | #endif 65 | #ifdef USE_EXTI6 66 | void EXTI6_IRQ() 67 | { 68 | } 69 | #endif 70 | #ifdef USE_EXTI7 71 | void EXTI7_IRQ() 72 | { 73 | } 74 | #endif 75 | #ifdef USE_EXTI8 76 | void EXTI8_IRQ() 77 | { 78 | } 79 | #endif 80 | #ifdef USE_EXTI9 81 | void EXTI9_IRQ() 82 | { 83 | } 84 | #endif 85 | #ifdef USE_EXTI10 86 | void EXTI10_IRQ() 87 | { 88 | } 89 | #endif 90 | #ifdef USE_EXTI11 91 | void EXTI11_IRQ() 92 | { 93 | } 94 | #endif 95 | #ifdef USE_EXTI12 96 | void EXTI12_IRQ() 97 | { 98 | } 99 | #endif 100 | #ifdef USE_EXTI13 101 | void EXTI13_IRQ() 102 | { 103 | } 104 | #endif 105 | #ifdef USE_EXTI14 106 | void EXTI14_IRQ() 107 | { 108 | } 109 | #endif 110 | #ifdef USE_EXTI15 111 | void EXTI15_IRQ() 112 | { 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /example/offchip/Ethernet/stm32f103c8t6/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /example/offchip/MFRC522/stm32f103c8t6/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | #define RTE_DEVICE_STDPERIPH_DMA 14 | #define RTE_DEVICE_STDPERIPH_EXTI 15 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 16 | #define RTE_DEVICE_STDPERIPH_GPIO 17 | #define RTE_DEVICE_STDPERIPH_RCC 18 | #define RTE_DEVICE_STDPERIPH_SPI 19 | #define RTE_DEVICE_STDPERIPH_USART 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /example/offchip/MFRC522/stm32f103c8t6/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | #ifdef USE_TIMER1 6 | void Timer1_IRQ() 7 | { 8 | 9 | } 10 | #endif 11 | 12 | #ifdef USE_TIMER2 13 | void Timer2_IRQ() 14 | { 15 | 16 | } 17 | #endif 18 | 19 | #ifdef USE_TIMER3 20 | void Timer3_IRQ() 21 | { 22 | 23 | } 24 | #endif 25 | 26 | #ifdef USE_TIMER4 27 | void Timer4_IRQ() 28 | { 29 | 30 | } 31 | #endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | #ifdef USE_EXTI0 36 | void EXTI0_IRQ() 37 | { 38 | } 39 | #endif 40 | #ifdef USE_EXTI1 41 | void EXTI1_IRQ() 42 | { 43 | } 44 | #endif 45 | #ifdef USE_EXTI2 46 | void EXTI2_IRQ() 47 | { 48 | } 49 | #endif 50 | #ifdef USE_EXTI3 51 | void EXTI3_IRQ() 52 | { 53 | } 54 | #endif 55 | #ifdef USE_EXTI4 56 | void EXTI4_IRQ() 57 | { 58 | } 59 | #endif 60 | #ifdef USE_EXTI5 61 | void EXTI5_IRQ() 62 | { 63 | } 64 | #endif 65 | #ifdef USE_EXTI6 66 | void EXTI6_IRQ() 67 | { 68 | } 69 | #endif 70 | #ifdef USE_EXTI7 71 | void EXTI7_IRQ() 72 | { 73 | } 74 | #endif 75 | #ifdef USE_EXTI8 76 | void EXTI8_IRQ() 77 | { 78 | } 79 | #endif 80 | #ifdef USE_EXTI9 81 | void EXTI9_IRQ() 82 | { 83 | } 84 | #endif 85 | #ifdef USE_EXTI10 86 | void EXTI10_IRQ() 87 | { 88 | } 89 | #endif 90 | #ifdef USE_EXTI11 91 | void EXTI11_IRQ() 92 | { 93 | } 94 | #endif 95 | #ifdef USE_EXTI12 96 | void EXTI12_IRQ() 97 | { 98 | } 99 | #endif 100 | #ifdef USE_EXTI13 101 | void EXTI13_IRQ() 102 | { 103 | } 104 | #endif 105 | #ifdef USE_EXTI14 106 | void EXTI14_IRQ() 107 | { 108 | } 109 | #endif 110 | #ifdef USE_EXTI15 111 | void EXTI15_IRQ() 112 | { 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /example/offchip/MFRC522/stm32f103c8t6/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /example/offchip/MFRC522/stm32f103c8t6/app/main.cpp: -------------------------------------------------------------------------------- 1 | ////////////////||spi1MOSI | PA7 ||////////////////////////// 2 | ////////////////||spi1MISO | PA6 ||////////////////////////// 3 | ////////////////||spi1SCK | PA5 ||////////////////////////// 4 | ////////////////||spi1NSS | PA4 ||////////////////////////// 5 | 6 | 7 | 8 | #include "TaskManager.h" 9 | #include "USART.h" 10 | #include "SPI.h" 11 | #include "MFRC522.h" 12 | 13 | 14 | USART com(1,115200); 15 | SPI spi1(SPI1); 16 | MFRC522 rfid(&spi1); 17 | 18 | unsigned char defaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 19 | uint8_t dataWrite[16]={1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,}; 20 | 21 | int main() 22 | { 23 | TaskManager::DelayS(2); 24 | rfid.PCDReset(); 25 | com<<"init complete\n"; 26 | while(1) 27 | { 28 | uint8_t mTagInfo[4]; 29 | if(rfid.PcdRequest(MFRC522_PICC_REQIDL,mTagInfo)) 30 | { 31 | com<<"find card\n"; 32 | if(((u16)mTagInfo[0]<<8|mTagInfo[1])==MFRC522_PICC_MIFARE_ONE_S50) 33 | { 34 | com<<"car type is MI1S50\n"; 35 | if(rfid.PcdAntiColl(mTagInfo)) 36 | { 37 | com<<"anticoll success!UID:"; 38 | com.PrintHex(mTagInfo,4," ")<<"\n"; 39 | if(rfid.PcdSelect(mTagInfo)) 40 | { 41 | com<<"select card success\n"; 42 | if(rfid.PcdAuthState(MFRC522_PICC_AUTHENT1A, 1, defaultKey, mTagInfo)) 43 | { 44 | com<<"auth success!\n"; 45 | if(rfid.PcdWrite(2,dataWrite)) 46 | { 47 | com<<"write success:"; 48 | com.PrintHex(dataWrite,16," ")<<"\n"; 49 | uint8_t cardValue[16] = {0}; 50 | if(rfid.PcdRead(2,cardValue)) 51 | { 52 | com<<"read success:"; 53 | com.PrintHex(cardValue,16," ")<<"\n"; 54 | } 55 | } 56 | } 57 | } 58 | } 59 | 60 | } 61 | } 62 | } 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /example/offchip/PN53x/stm32f103c8t6/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | #define RTE_DEVICE_STDPERIPH_DMA 14 | #define RTE_DEVICE_STDPERIPH_EXTI 15 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 16 | #define RTE_DEVICE_STDPERIPH_GPIO 17 | #define RTE_DEVICE_STDPERIPH_RCC 18 | #define RTE_DEVICE_STDPERIPH_USART 19 | 20 | #endif /* RTE_COMPONENTS_H */ 21 | -------------------------------------------------------------------------------- /example/offchip/PN53x/stm32f103c8t6/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | #ifdef USE_TIMER1 6 | void Timer1_IRQ() 7 | { 8 | 9 | } 10 | #endif 11 | 12 | #ifdef USE_TIMER2 13 | void Timer2_IRQ() 14 | { 15 | 16 | } 17 | #endif 18 | 19 | #ifdef USE_TIMER3 20 | void Timer3_IRQ() 21 | { 22 | 23 | } 24 | #endif 25 | 26 | #ifdef USE_TIMER4 27 | void Timer4_IRQ() 28 | { 29 | 30 | } 31 | #endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | #ifdef USE_EXTI0 36 | void EXTI0_IRQ() 37 | { 38 | } 39 | #endif 40 | #ifdef USE_EXTI1 41 | void EXTI1_IRQ() 42 | { 43 | } 44 | #endif 45 | #ifdef USE_EXTI2 46 | void EXTI2_IRQ() 47 | { 48 | } 49 | #endif 50 | #ifdef USE_EXTI3 51 | void EXTI3_IRQ() 52 | { 53 | } 54 | #endif 55 | #ifdef USE_EXTI4 56 | void EXTI4_IRQ() 57 | { 58 | } 59 | #endif 60 | #ifdef USE_EXTI5 61 | void EXTI5_IRQ() 62 | { 63 | } 64 | #endif 65 | #ifdef USE_EXTI6 66 | void EXTI6_IRQ() 67 | { 68 | } 69 | #endif 70 | #ifdef USE_EXTI7 71 | void EXTI7_IRQ() 72 | { 73 | } 74 | #endif 75 | #ifdef USE_EXTI8 76 | void EXTI8_IRQ() 77 | { 78 | } 79 | #endif 80 | #ifdef USE_EXTI9 81 | void EXTI9_IRQ() 82 | { 83 | } 84 | #endif 85 | #ifdef USE_EXTI10 86 | void EXTI10_IRQ() 87 | { 88 | } 89 | #endif 90 | #ifdef USE_EXTI11 91 | void EXTI11_IRQ() 92 | { 93 | } 94 | #endif 95 | #ifdef USE_EXTI12 96 | void EXTI12_IRQ() 97 | { 98 | } 99 | #endif 100 | #ifdef USE_EXTI13 101 | void EXTI13_IRQ() 102 | { 103 | } 104 | #endif 105 | #ifdef USE_EXTI14 106 | void EXTI14_IRQ() 107 | { 108 | } 109 | #endif 110 | #ifdef USE_EXTI15 111 | void EXTI15_IRQ() 112 | { 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /example/offchip/PN53x/stm32f103c8t6/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /example/offchip/PN53x/stm32f103c8t6/app/main.cpp: -------------------------------------------------------------------------------- 1 | #include "USART.h" 2 | #include "PN53x.h" 3 | #include "TaskManager.h" 4 | #include "LED.h" 5 | 6 | 7 | USART LOG(1,115200,false,0,3,7,1,3);// 8 | USART usart2(2,115200);// 9 | USART usart3(3,115200);// 10 | PN53x rfidReader(usart3); 11 | GPIO gpioLed(GPIOB,0,GPIO_Mode_Out_PP,GPIO_Speed_50MHz); 12 | LED led(gpioLed); 13 | 14 | uint8_t key[6]={0xff,0xff,0xff,0xff,0xff,0xff}; 15 | uint8_t dataRead[16] = {0}; 16 | uint8_t dataWrite[16] = {0,0,0,0,5,6,7,8,9,0,0,0,0,0,0,0}; 17 | 18 | int main() 19 | { 20 | led.On(); 21 | TaskManager::DelayS(2); 22 | if(!rfidReader.PcdWakeUp()) 23 | LOG<<"pcd wake up fail!!!\n"; 24 | LOG<<"init complete\n"; 25 | while(1) 26 | { 27 | uint16_t type; 28 | uint8_t uid[4]; 29 | if(rfidReader.PcdListPassiveTarget(&type,uid)) 30 | { 31 | LOG<<"find card,type:"<Irq(); 22 | #endif 23 | } 24 | void USART2_IRQHandler(void) //----USART2 IRQ----// 25 | { 26 | #ifdef USE_USART2 27 | pUSART2->Irq(); 28 | #endif 29 | } 30 | void USART3_IRQHandler(void) //----USART3 IRQ----// 31 | { 32 | #ifdef USE_USART3 33 | pUSART3->Irq(); 34 | #endif 35 | } 36 | 37 | 38 | 39 | 40 | /*TIM****************************************************************************/ 41 | #ifdef USE_CAPTURE_TIM1 42 | InputCapture_TIM *pICP1; 43 | #endif 44 | 45 | #ifdef USE_CAPTURE_TIM2 46 | InputCapture_TIM *pICP2; 47 | #endif 48 | 49 | #ifdef USE_CAPTURE_TIM3 50 | InputCapture_TIM *pICP3; 51 | #endif 52 | 53 | #ifdef USE_CAPTURE_TIM4 54 | InputCapture_TIM *pICP4; 55 | #endif 56 | 57 | void TIM1_UP_IRQHandler(void) //----TIM1 Up-------// 58 | { 59 | #ifdef USE_TIMER1 60 | TIM_ClearITPendingBit(TIM1, TIM_FLAG_Update); 61 | Timer1_IRQ(); 62 | #endif 63 | } 64 | 65 | #ifdef USE_CAPTURE_TIM1 66 | void TIM1_CC_IRQHandler(void) 67 | { 68 | pICP1->IRQ(); 69 | } 70 | #endif 71 | 72 | void TIM2_IRQHandler(void) //----TIM4 IRQ------// 73 | { 74 | #ifdef USE_TIMER2 75 | TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); 76 | Timer2_IRQ(); 77 | #endif 78 | 79 | #ifdef USE_CAPTURE_TIM2 80 | pICP2->IRQ(); 81 | #endif 82 | } 83 | 84 | void TIM3_IRQHandler(void) //----TIM4 IRQ------// 85 | { 86 | #ifdef USE_TIMER3 87 | TIM_ClearITPendingBit(TIM3, TIM_FLAG_Update); 88 | Timer3_IRQ(); 89 | #endif 90 | 91 | #ifdef USE_CAPTURE_TIM3 92 | pICP3->IRQ(); 93 | #endif 94 | } 95 | void TIM4_IRQHandler(void) //----TIM4 IRQ------// 96 | { 97 | #ifdef USE_TIMER4 98 | TIM_ClearITPendingBit(TIM4, TIM_FLAG_Update); 99 | Timer4_IRQ(); 100 | #endif 101 | 102 | #ifdef USE_CAPTURE_TIM4 103 | pICP4->IRQ(); 104 | #endif 105 | } 106 | /*END****************************************************************************/ 107 | 108 | -------------------------------------------------------------------------------- /example/onchip/GPIO/stm32f103c8t6/system/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | u8 cnt=0; 4 | 5 | /*************************TIM_USER_IRQ***********************************/ 6 | #ifdef USE_TIMER1 7 | void Timer1_IRQ() 8 | { 9 | 10 | } 11 | #endif 12 | 13 | 14 | #ifdef USE_TIMER2 15 | 16 | void Timer2_IRQ() 17 | { 18 | static bool flag = true; 19 | 20 | if(flag) 21 | { 22 | cnt++; 23 | if(cnt>100) 24 | flag=false; 25 | } 26 | else 27 | { 28 | cnt--; 29 | if(cnt<1) 30 | flag=true; 31 | } 32 | 33 | } 34 | #endif 35 | 36 | #ifdef USE_TIMER3 37 | void Timer3_IRQ() 38 | { 39 | 40 | } 41 | #endif 42 | 43 | #ifdef USE_TIMER4 44 | void Timer4_IRQ() 45 | { 46 | 47 | } 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /example/onchip/GPIO/stm32f103c8t6/system/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | extern u8 cnt; 7 | 8 | /*TIM***************************************************************************/ 9 | #ifdef USE_TIMER1 10 | void Timer1_IRQ(); 11 | #endif 12 | 13 | #ifdef USE_TIMER2 14 | void Timer2_IRQ(); 15 | #endif 16 | 17 | #ifdef USE_TIMER3 18 | void Timer3_IRQ(); 19 | #endif 20 | 21 | #ifdef USE_TIMER4 22 | void Timer4_IRQ(); 23 | #endif 24 | 25 | /*EDN***************************************************************************/ 26 | 27 | 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /example/onchip/GPIO/stm32f103c8t6/system/main.cpp: -------------------------------------------------------------------------------- 1 | #include "GPIO.h" 2 | #include "Delay.h" 3 | 4 | GPIO RedLed(GPIOB,3,GPIO_Mode_Out_PP,GPIO_Speed_50MHz); 5 | GPIO led(GPIOB,0,GPIO_Mode_Out_PP,GPIO_Speed_50MHz); 6 | GPIO led2(GPIOB,1,GPIO_Mode_Out_PP,GPIO_Speed_50MHz); 7 | 8 | int main() 9 | { 10 | bool Level = false; 11 | RedLed.DisableSWJTAG(false,true);//PB3要使用通用功能,需要先关闭JTAG功能 12 | RedLed.SetLevel(1);//设置管脚电平为高 13 | while(1) 14 | { 15 | RedLed.Toggle(); //翻转电平 16 | led.Toggle(); 17 | led2.Toggle(); 18 | Level=RedLed.GetLevel();//获取当前管脚电平 19 | Delay::Ms(100); 20 | 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /example/onchip/IAP/app/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | #define RTE_DEVICE_STDPERIPH_DMA 20 | #define RTE_DEVICE_STDPERIPH_EXTI 21 | #define RTE_DEVICE_STDPERIPH_FLASH 22 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 23 | #define RTE_DEVICE_STDPERIPH_GPIO 24 | #define RTE_DEVICE_STDPERIPH_RCC 25 | #define RTE_DEVICE_STDPERIPH_USART 26 | 27 | #endif /* RTE_COMPONENTS_H */ 28 | -------------------------------------------------------------------------------- /example/onchip/IAP/app/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | #ifdef USE_TIMER1 6 | void Timer1_IRQ() 7 | { 8 | 9 | } 10 | #endif 11 | 12 | #ifdef USE_TIMER2 13 | void Timer2_IRQ() 14 | { 15 | 16 | } 17 | #endif 18 | 19 | #ifdef USE_TIMER3 20 | void Timer3_IRQ() 21 | { 22 | 23 | } 24 | #endif 25 | 26 | #ifdef USE_TIMER4 27 | void Timer4_IRQ() 28 | { 29 | 30 | } 31 | #endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | #ifdef USE_EXTI0 36 | void EXTI0_IRQ() 37 | { 38 | } 39 | #endif 40 | #ifdef USE_EXTI1 41 | void EXTI1_IRQ() 42 | { 43 | } 44 | #endif 45 | #ifdef USE_EXTI2 46 | void EXTI2_IRQ() 47 | { 48 | } 49 | #endif 50 | #ifdef USE_EXTI3 51 | void EXTI3_IRQ() 52 | { 53 | } 54 | #endif 55 | #ifdef USE_EXTI4 56 | void EXTI4_IRQ() 57 | { 58 | } 59 | #endif 60 | #ifdef USE_EXTI5 61 | void EXTI5_IRQ() 62 | { 63 | } 64 | #endif 65 | #ifdef USE_EXTI6 66 | void EXTI6_IRQ() 67 | { 68 | } 69 | #endif 70 | #ifdef USE_EXTI7 71 | void EXTI7_IRQ() 72 | { 73 | } 74 | #endif 75 | #ifdef USE_EXTI8 76 | void EXTI8_IRQ() 77 | { 78 | } 79 | #endif 80 | #ifdef USE_EXTI9 81 | void EXTI9_IRQ() 82 | { 83 | } 84 | #endif 85 | #ifdef USE_EXTI10 86 | void EXTI10_IRQ() 87 | { 88 | } 89 | #endif 90 | #ifdef USE_EXTI11 91 | void EXTI11_IRQ() 92 | { 93 | } 94 | #endif 95 | #ifdef USE_EXTI12 96 | void EXTI12_IRQ() 97 | { 98 | } 99 | #endif 100 | #ifdef USE_EXTI13 101 | void EXTI13_IRQ() 102 | { 103 | } 104 | #endif 105 | #ifdef USE_EXTI14 106 | void EXTI14_IRQ() 107 | { 108 | } 109 | #endif 110 | #ifdef USE_EXTI15 111 | void EXTI15_IRQ() 112 | { 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /example/onchip/IAP/app/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /example/onchip/IAP/app/app/main.cpp: -------------------------------------------------------------------------------- 1 | #include "LED.h" 2 | #include "USART.h" 3 | #include "TaskManager.h" 4 | #include "IAP.h" 5 | 6 | 7 | const uint32_t appAddr = (0x08000000+10*MEMORY_PAGE_SIZE); 8 | 9 | 10 | GPIO ledPin(GPIOC,13); 11 | LED led(ledPin); 12 | USART usart(1,115200); 13 | IAP iap(NULL,appAddr); 14 | 15 | int main() 16 | { 17 | double logTimeRecord; 18 | int count = 0; 19 | 20 | iap.Init(appAddr); 21 | 22 | usart<<"App start...\n"; 23 | TaskManager::DelayMs(1000); 24 | while(1) 25 | { 26 | led.Blink(0,2000,false); 27 | if(TaskManager::TimeSlice(logTimeRecord,1)) 28 | { 29 | usart<<"hello "<<(++count)<<"\n"; 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /example/onchip/IAP/app/runToApp.ini: -------------------------------------------------------------------------------- 1 | SP = _RDWORD(0x8002800); 2 | PC = _RDWORD(0x8002804); -------------------------------------------------------------------------------- /example/onchip/IAP/bootloader/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | #define RTE_DEVICE_STDPERIPH_DMA 20 | #define RTE_DEVICE_STDPERIPH_EXTI 21 | #define RTE_DEVICE_STDPERIPH_FLASH 22 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 23 | #define RTE_DEVICE_STDPERIPH_GPIO 24 | #define RTE_DEVICE_STDPERIPH_RCC 25 | #define RTE_DEVICE_STDPERIPH_USART 26 | 27 | #endif /* RTE_COMPONENTS_H */ 28 | -------------------------------------------------------------------------------- /example/onchip/IAP/bootloader/app/LED_Min.cpp: -------------------------------------------------------------------------------- 1 | #include "LED_Min.h" 2 | 3 | 4 | ///构造函数 5 | ///@param gpio GPIO类对象,分配片上资源 6 | ///@param highLevelOn 是否输出高电平时为LED打开 7 | ///////////////////////// 8 | LED::LED(GPIO &gpio,bool highLevelOn) 9 | :mGPIO(gpio),times(0),time_old(0) 10 | { 11 | if(highLevelOn) 12 | mLevelOn=1; 13 | else 14 | mLevelOn=0; 15 | Off(); 16 | } 17 | 18 | 19 | //////////////////////// 20 | ///翻转(开-->关 , 关-->开) 21 | /////////////////////// 22 | void LED::Toggle() 23 | { 24 | if(mGPIO.GetLevel()) 25 | mGPIO.SetLevel(0); 26 | else 27 | mGPIO.SetLevel(1); 28 | } 29 | 30 | ////////////////////// 31 | ///打开LED 32 | ///////////////////// 33 | void LED::On() 34 | { 35 | mGPIO.SetLevel(mLevelOn); 36 | } 37 | 38 | ///////////////////// 39 | ///关闭LED 40 | //////////////////// 41 | void LED::Off() 42 | { 43 | mGPIO.SetLevel(mLevelOn^1); 44 | } 45 | 46 | //////////////////////// 47 | ///闪烁n次 48 | ///@param time 闪烁次数 49 | ///@param Interval 闪烁间隔 (ms) 50 | ///@param wait 是否等待闪烁完毕后再结束函数 51 | /////////////////////// 52 | void LED::Blink(uint16_t time,float interval,bool wait) 53 | { 54 | if(wait){ 55 | for(uint8_t i=0;i=time) 63 | { 64 | times = 0; 65 | return; 66 | } 67 | double timeNow = TaskManager::Time(); 68 | if(timeNow - time_old > interval/1000.0) 69 | { 70 | time_old = TaskManager::Time(); 71 | ++times; 72 | Toggle(); 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /example/onchip/IAP/bootloader/app/LED_Min.h: -------------------------------------------------------------------------------- 1 | #ifndef _LED_H 2 | #define _LED_H 3 | 4 | #include "GPIO.h" 5 | #include "TaskManager.h" 6 | class LED 7 | { 8 | public: 9 | //////////////////////// 10 | ///构造函数 11 | ///@param gpio GPIO类对象,分配片上资源 12 | ///@param highLevelOn 是否输出高电平时为LED打开 13 | ///////////////////////// 14 | LED(GPIO &gpio,bool highLevelOn=false); 15 | 16 | 17 | //////////////////////// 18 | ///翻转(开-->关 , 关-->开) 19 | /////////////////////// 20 | void Toggle(); 21 | 22 | ////////////////////// 23 | ///打开LED 24 | ///////////////////// 25 | void On(); 26 | 27 | ///////////////////// 28 | ///关闭LED 29 | //////////////////// 30 | void Off(); 31 | 32 | //////////////////////// 33 | ///闪烁n次 34 | ///@param time 闪烁次数,若为0,则为无线闪烁(只适用于非等待方式) 35 | ///@param Interval 闪烁间隔(ms) 36 | ///@param wait 是否等待闪烁完毕后再结束函数 37 | /////////////////////// 38 | void Blink(uint16_t time,float interval,bool wait); 39 | 40 | 41 | private: 42 | ////////////////////////// 43 | ///GPIO的类的实例对象引用 44 | ////////////////////////// 45 | GPIO & mGPIO; 46 | //////////////////////// 47 | ///标志开启LED时取的电平高低 48 | //////////////////////// 49 | unsigned char mLevelOn; 50 | 51 | uint16_t times; 52 | double time_old; 53 | 54 | 55 | 56 | }; 57 | 58 | 59 | #endif 60 | 61 | 62 | -------------------------------------------------------------------------------- /example/onchip/IAP/bootloader/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | //#ifdef USE_TIMER1 6 | //void Timer1_IRQ() 7 | //{ 8 | // 9 | //} 10 | //#endif 11 | 12 | //#ifdef USE_TIMER2 13 | //void Timer2_IRQ() 14 | //{ 15 | // 16 | //} 17 | //#endif 18 | 19 | //#ifdef USE_TIMER3 20 | //void Timer3_IRQ() 21 | //{ 22 | // 23 | //} 24 | //#endif 25 | 26 | //#ifdef USE_TIMER4 27 | //void Timer4_IRQ() 28 | //{ 29 | // 30 | //} 31 | //#endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | //#ifdef USE_EXTI0 36 | //void EXTI0_IRQ() 37 | //{ 38 | //} 39 | //#endif 40 | //#ifdef USE_EXTI1 41 | //void EXTI1_IRQ() 42 | //{ 43 | //} 44 | //#endif 45 | //#ifdef USE_EXTI2 46 | //void EXTI2_IRQ() 47 | //{ 48 | //} 49 | //#endif 50 | //#ifdef USE_EXTI3 51 | //void EXTI3_IRQ() 52 | //{ 53 | //} 54 | //#endif 55 | //#ifdef USE_EXTI4 56 | //void EXTI4_IRQ() 57 | //{ 58 | //} 59 | //#endif 60 | //#ifdef USE_EXTI5 61 | //void EXTI5_IRQ() 62 | //{ 63 | //} 64 | //#endif 65 | //#ifdef USE_EXTI6 66 | //void EXTI6_IRQ() 67 | //{ 68 | //} 69 | //#endif 70 | //#ifdef USE_EXTI7 71 | //void EXTI7_IRQ() 72 | //{ 73 | //} 74 | //#endif 75 | //#ifdef USE_EXTI8 76 | //void EXTI8_IRQ() 77 | //{ 78 | //} 79 | //#endif 80 | //#ifdef USE_EXTI9 81 | //void EXTI9_IRQ() 82 | //{ 83 | //} 84 | //#endif 85 | //#ifdef USE_EXTI10 86 | //void EXTI10_IRQ() 87 | //{ 88 | //} 89 | //#endif 90 | //#ifdef USE_EXTI11 91 | //void EXTI11_IRQ() 92 | //{ 93 | //} 94 | //#endif 95 | //#ifdef USE_EXTI12 96 | //void EXTI12_IRQ() 97 | //{ 98 | //} 99 | //#endif 100 | //#ifdef USE_EXTI13 101 | //void EXTI13_IRQ() 102 | //{ 103 | //} 104 | //#endif 105 | //#ifdef USE_EXTI14 106 | //void EXTI14_IRQ() 107 | //{ 108 | //} 109 | //#endif 110 | //#ifdef USE_EXTI15 111 | //void EXTI15_IRQ() 112 | //{ 113 | //} 114 | //#endif 115 | -------------------------------------------------------------------------------- /example/onchip/IAP/bootloader/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /example/onchip/IAP/bootloader/app/main.cpp: -------------------------------------------------------------------------------- 1 | #include "USART.h" 2 | #include "IAP_USART.h" 3 | #include "flash.h" 4 | #include "GPIO.h" 5 | #include "stdint.h" 6 | #include "LED_Min.h" 7 | 8 | const uint32_t iapAddr = (0x08000000); 9 | const uint32_t appAddr = (0x08000000+10*MEMORY_PAGE_SIZE); 10 | 11 | USART usart(1,115200); 12 | Flash flash(appAddr); 13 | IAP_USART iapUsart(usart,flash,appAddr); 14 | 15 | GPIO ledPin(GPIOC,13); 16 | LED led(ledPin); 17 | 18 | 19 | 20 | int main() 21 | { 22 | IAP_USART_Upgrade_Status_t status; 23 | 24 | iapUsart.Init(iapAddr); 25 | 26 | led.Blink(4,200,true); 27 | 28 | while(1) 29 | { 30 | status = iapUsart.Upgrade(); 31 | switch((int)status) 32 | { 33 | case IAP_USART_UPGRADE_STATUS_IDLE: 34 | led.Blink(0,1000,false); 35 | break; 36 | case IAP_USART_UPGRADE_STATUS_WORKING: 37 | led.Blink(0,100,false); 38 | break; 39 | case IAP_USART_UPGRADE_STATUS_COMPLETE: 40 | iapUsart.LoadApp(); 41 | led.Off(); 42 | break; 43 | case IAP_USART_UPGRADE_STATUS_ERROR: 44 | led.On(); 45 | break; 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /example/onchip/IWDG/stm32f103c8t6/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | #define RTE_DEVICE_STDPERIPH_DMA 14 | #define RTE_DEVICE_STDPERIPH_EXTI 15 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 16 | #define RTE_DEVICE_STDPERIPH_GPIO 17 | #define RTE_DEVICE_STDPERIPH_IWDG 18 | #define RTE_DEVICE_STDPERIPH_RCC 19 | #define RTE_DEVICE_STDPERIPH_USART 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /example/onchip/IWDG/stm32f103c8t6/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | #ifdef USE_TIMER1 6 | void Timer1_IRQ() 7 | { 8 | 9 | } 10 | #endif 11 | 12 | #ifdef USE_TIMER2 13 | void Timer2_IRQ() 14 | { 15 | 16 | } 17 | #endif 18 | 19 | #ifdef USE_TIMER3 20 | void Timer3_IRQ() 21 | { 22 | 23 | } 24 | #endif 25 | 26 | #ifdef USE_TIMER4 27 | void Timer4_IRQ() 28 | { 29 | 30 | } 31 | #endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | #ifdef USE_EXTI0 36 | void EXTI0_IRQ() 37 | { 38 | } 39 | #endif 40 | #ifdef USE_EXTI1 41 | void EXTI1_IRQ() 42 | { 43 | } 44 | #endif 45 | #ifdef USE_EXTI2 46 | void EXTI2_IRQ() 47 | { 48 | } 49 | #endif 50 | #ifdef USE_EXTI3 51 | void EXTI3_IRQ() 52 | { 53 | } 54 | #endif 55 | #ifdef USE_EXTI4 56 | void EXTI4_IRQ() 57 | { 58 | } 59 | #endif 60 | #ifdef USE_EXTI5 61 | void EXTI5_IRQ() 62 | { 63 | } 64 | #endif 65 | #ifdef USE_EXTI6 66 | void EXTI6_IRQ() 67 | { 68 | } 69 | #endif 70 | #ifdef USE_EXTI7 71 | void EXTI7_IRQ() 72 | { 73 | } 74 | #endif 75 | #ifdef USE_EXTI8 76 | void EXTI8_IRQ() 77 | { 78 | } 79 | #endif 80 | #ifdef USE_EXTI9 81 | void EXTI9_IRQ() 82 | { 83 | } 84 | #endif 85 | #ifdef USE_EXTI10 86 | void EXTI10_IRQ() 87 | { 88 | } 89 | #endif 90 | #ifdef USE_EXTI11 91 | void EXTI11_IRQ() 92 | { 93 | } 94 | #endif 95 | #ifdef USE_EXTI12 96 | void EXTI12_IRQ() 97 | { 98 | } 99 | #endif 100 | #ifdef USE_EXTI13 101 | void EXTI13_IRQ() 102 | { 103 | } 104 | #endif 105 | #ifdef USE_EXTI14 106 | void EXTI14_IRQ() 107 | { 108 | } 109 | #endif 110 | #ifdef USE_EXTI15 111 | void EXTI15_IRQ() 112 | { 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /example/onchip/IWDG/stm32f103c8t6/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /example/onchip/IWDG/stm32f103c8t6/app/main.cpp: -------------------------------------------------------------------------------- 1 | #include "USART.h" 2 | #include "IWDG.h" 3 | 4 | USART usart(1,115200,false,0,3,7,1,3);// 5 | IWDG_ iwdg(2);//2s 6 | 7 | int main() 8 | { 9 | usart<<"init complete\n"; 10 | while(1) 11 | { 12 | iwdg.Feed(); 13 | usart<<"."; 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /example/onchip/TIM/stm32f103c8t6/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'demo' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | #define RTE_DEVICE_STDPERIPH_DMA 14 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 15 | #define RTE_DEVICE_STDPERIPH_GPIO 16 | #define RTE_DEVICE_STDPERIPH_RCC 17 | #define RTE_DEVICE_STDPERIPH_TIM 18 | #define RTE_DEVICE_STDPERIPH_USART 19 | 20 | #endif /* RTE_COMPONENTS_H */ 21 | -------------------------------------------------------------------------------- /example/onchip/TIM/stm32f103c8t6/system/Configuration.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIGURATION_H_ 2 | #define _CONFIGURATION_H_ 3 | 4 | #include "stm32f10x.h" 5 | #include "USART.h" 6 | 7 | 8 | //~~~~~~~~~~~~~~~USART Congfigure~~~~~~~~~~~// 9 | #define USE_USART //---USART---// 10 | #define USE_USART1 //---USART1--// 11 | //#define USE_USART2 //---USART2--// 12 | //#define USE_USART3 //---USART3--// 13 | 14 | //~~~~~~~~~~~~~~~Timer Congfigure~~~~~~~~~~~// 15 | #define USE_TIMER //---Timer---// 16 | //#define USE_TIMER1 //---Timer1--// 17 | #define USE_TIMER2 //---Timer2--// 18 | //#define USE_TIMER3 //---Timer3--// 19 | //#define USE_TIMER4 //---Timer4--// 20 | 21 | 22 | 23 | 24 | #ifdef USE_TIMER 25 | #include "Timer.h" 26 | #endif 27 | 28 | #ifdef USE_USART 29 | #include "USART.h" 30 | #endif 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /example/onchip/TIM/stm32f103c8t6/system/Interrupt.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Interrupt.h" 3 | 4 | 5 | /*USART*************************************************************************/ 6 | #ifdef USE_USART1 7 | USART *pUSART1 = 0; 8 | #endif 9 | 10 | #ifdef USE_USART2 11 | USART *pUSART2 = 0; 12 | #endif 13 | 14 | #ifdef USE_USART3 15 | USART *pUSART3 = 0; 16 | #endif 17 | 18 | void USART1_IRQHandler(void) //----USART1 IRQ----// 19 | { 20 | #ifdef USE_USART1 21 | pUSART1->Irq(); 22 | #endif 23 | } 24 | void USART2_IRQHandler(void) //----USART2 IRQ----// 25 | { 26 | #ifdef USE_USART2 27 | pUSART2->Irq(); 28 | #endif 29 | } 30 | void USART3_IRQHandler(void) //----USART3 IRQ----// 31 | { 32 | #ifdef USE_USART3 33 | pUSART3->Irq(); 34 | #endif 35 | } 36 | 37 | 38 | 39 | 40 | /*TIM****************************************************************************/ 41 | #ifdef USE_CAPTURE_TIM1 42 | InputCapture_TIM *pICP1; 43 | #endif 44 | 45 | #ifdef USE_CAPTURE_TIM2 46 | InputCapture_TIM *pICP2; 47 | #endif 48 | 49 | #ifdef USE_CAPTURE_TIM3 50 | InputCapture_TIM *pICP3; 51 | #endif 52 | 53 | #ifdef USE_CAPTURE_TIM4 54 | InputCapture_TIM *pICP4; 55 | #endif 56 | 57 | void TIM1_UP_IRQHandler(void) //----TIM1 Up-------// 58 | { 59 | #ifdef USE_TIMER1 60 | TIM_ClearITPendingBit(TIM1, TIM_FLAG_Update); 61 | Timer1_IRQ(); 62 | #endif 63 | } 64 | 65 | #ifdef USE_CAPTURE_TIM1 66 | void TIM1_CC_IRQHandler(void) 67 | { 68 | pICP1->IRQ(); 69 | } 70 | #endif 71 | 72 | void TIM2_IRQHandler(void) //----TIM4 IRQ------// 73 | { 74 | #ifdef USE_TIMER2 75 | TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); 76 | Timer2_IRQ(); 77 | #endif 78 | 79 | #ifdef USE_CAPTURE_TIM2 80 | pICP2->IRQ(); 81 | #endif 82 | } 83 | 84 | void TIM3_IRQHandler(void) //----TIM4 IRQ------// 85 | { 86 | #ifdef USE_TIMER3 87 | TIM_ClearITPendingBit(TIM3, TIM_FLAG_Update); 88 | Timer3_IRQ(); 89 | #endif 90 | 91 | #ifdef USE_CAPTURE_TIM3 92 | pICP3->IRQ(); 93 | #endif 94 | } 95 | void TIM4_IRQHandler(void) //----TIM4 IRQ------// 96 | { 97 | #ifdef USE_TIMER4 98 | TIM_ClearITPendingBit(TIM4, TIM_FLAG_Update); 99 | Timer4_IRQ(); 100 | #endif 101 | 102 | #ifdef USE_CAPTURE_TIM4 103 | pICP4->IRQ(); 104 | #endif 105 | } 106 | /*END****************************************************************************/ 107 | 108 | -------------------------------------------------------------------------------- /example/onchip/TIM/stm32f103c8t6/system/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | u8 cnt=0; 4 | 5 | /*************************TIM_USER_IRQ***********************************/ 6 | #ifdef USE_TIMER1 7 | void Timer1_IRQ() 8 | { 9 | 10 | } 11 | #endif 12 | 13 | 14 | #ifdef USE_TIMER2 15 | 16 | void Timer2_IRQ() 17 | { 18 | static bool flag = true; 19 | 20 | if(flag) 21 | { 22 | cnt++; 23 | if(cnt>100) 24 | flag=false; 25 | } 26 | else 27 | { 28 | cnt--; 29 | if(cnt<1) 30 | flag=true; 31 | } 32 | 33 | } 34 | #endif 35 | 36 | #ifdef USE_TIMER3 37 | void Timer3_IRQ() 38 | { 39 | 40 | } 41 | #endif 42 | 43 | #ifdef USE_TIMER4 44 | void Timer4_IRQ() 45 | { 46 | 47 | } 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /example/onchip/TIM/stm32f103c8t6/system/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | extern u8 cnt; 7 | 8 | /*TIM***************************************************************************/ 9 | #ifdef USE_TIMER1 10 | void Timer1_IRQ(); 11 | #endif 12 | 13 | #ifdef USE_TIMER2 14 | void Timer2_IRQ(); 15 | #endif 16 | 17 | #ifdef USE_TIMER3 18 | void Timer3_IRQ(); 19 | #endif 20 | 21 | #ifdef USE_TIMER4 22 | void Timer4_IRQ(); 23 | #endif 24 | 25 | /*EDN***************************************************************************/ 26 | 27 | 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /example/onchip/TIM/stm32f103c8t6/system/main.cpp: -------------------------------------------------------------------------------- 1 | #include "USART.h" 2 | #include "Timer.h" 3 | #include "Delay.h" 4 | #include "UserInterrupt.h" 5 | 6 | USART usart(1,115200,false); 7 | Timer tim(TIM2,1,0,0); 8 | 9 | int main() 10 | { 11 | tim.OnOrOffIrq(true); 12 | tim.Start(); 13 | 14 | while(1) 15 | { 16 | usart<0) 25 | { 26 | int receivedDataNum=usart.ReceiveBufferSize(); 27 | usart.GetReceivedData(dataReceived,receivedDataNum); 28 | usart.SendData(dataReceived,receivedDataNum); 29 | } 30 | 31 | usart2.SendData(dataSend,8); 32 | usart2<<"aaaaaa"; 33 | for(uint32_t i=0;i<100000;++i); 34 | if(usart2.ReceiveBufferSize()>0) 35 | { 36 | int receivedDataNum=usart2.ReceiveBufferSize(); 37 | usart2.GetReceivedData(dataReceived,receivedDataNum); 38 | usart2.SendData(dataReceived,receivedDataNum); 39 | } 40 | usart3.SendData(dataSend,8); 41 | for(uint32_t i=0;i<100000;++i); 42 | if(usart3.ReceiveBufferSize()>0) 43 | { 44 | int receivedDataNum=usart3.ReceiveBufferSize(); 45 | usart3.GetReceivedData(dataReceived,receivedDataNum); 46 | usart3.SendData(dataReceived,receivedDataNum); 47 | } 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /lib/math/AHRS_DCM.h: -------------------------------------------------------------------------------- 1 | #ifndef __AHRS_DCM_H__ 2 | #define __AHRS_DCM_H__ 3 | 4 | #include "Matrix3.h" 5 | class AHRS_DCM 6 | { 7 | public: 8 | AHRS_DCM() 9 | { 10 | mDCMVector.x = 0; 11 | mDCMVector.y = 0; 12 | mDCMVector.z = 9.7935f; 13 | } 14 | Vector3f GetAngle_InertialSensor(Vector3 acc,Vector3f gyro,float updateInterval) 15 | { 16 | // Vector3f acc ; 17 | // acc.x = acc_.x; 18 | // acc.y = acc_.y; 19 | // acc.z = acc_.z; 20 | // com<0.36f && acclen<1.96f) 32 | { 33 | float accFilter = 0.002; 34 | mDCMVector.x = mDCMVector.x*(1-accFilter) + acc.y*accFilter; 35 | mDCMVector.y = mDCMVector.y*(1-accFilter) + acc.x*accFilter; 36 | mDCMVector.z = mDCMVector.z*(1-accFilter) - acc.z*accFilter; 37 | } 38 | 39 | mAngle.x = atan2f(mDCMVector.x, sqrtf(mDCMVector.y*mDCMVector.y+mDCMVector.z*mDCMVector.z))*57.29f; 40 | mAngle.y = atan2f(mDCMVector.y,mDCMVector.z)*57.29f; 41 | return mAngle; 42 | } 43 | Vector3f GetAngle_InertialSensor_Mag() 44 | { 45 | return mDCMVector; 46 | } 47 | private: 48 | Matrix3 mDCMMatrix; 49 | Vector3f mDCMVector; 50 | 51 | Vector3f mAngle; //算出来的角度 52 | }; 53 | 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lib/math/PIDController.h: -------------------------------------------------------------------------------- 1 | #ifndef __PIDCONTROLLER_H 2 | #define __PIDCONTROLLER_H 3 | 4 | class PIDController 5 | { 6 | private: 7 | float mKp; 8 | float mKi; 9 | float mKd; 10 | 11 | float _Perr; 12 | float _Ierr; 13 | float _Derr; 14 | 15 | public: 16 | PIDController(float kp=0, float ki=0, float kd=0) 17 | { 18 | mKp = kp; 19 | mKi = ki; 20 | mKd = kd; 21 | } 22 | void operator()(float kp, float ki, float kd) 23 | { 24 | mKp = kp; 25 | mKi = ki; 26 | mKd = kd; 27 | } 28 | float Controll(float target, float now) 29 | { 30 | float err = target - now; 31 | 32 | float detaI = err*mKi*2; 33 | 34 | if(detaI>10) detaI = 10; 35 | if(detaI<-10) detaI = -10; 36 | 37 | _Ierr += detaI; 38 | _Derr = (err -_Perr)*500; 39 | _Perr = err; 40 | return mKp*_Perr + _Ierr + mKd*_Derr; 41 | } 42 | void AddKp(float value) 43 | { 44 | mKp+=value; 45 | } 46 | void AddKi(float value) 47 | { 48 | mKi+=value; 49 | } 50 | void AddKd(float value) 51 | { 52 | mKd+=value; 53 | } 54 | float GetKp() 55 | { 56 | return mKp; 57 | } 58 | float GetKi() 59 | { 60 | return mKi; 61 | } 62 | float GetKd() 63 | { 64 | return mKd; 65 | } 66 | }; 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /lib/math/Quaternion.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUATERNION_H_ 2 | #define _QUATERNION_H_ 3 | 4 | #include "math.h" 5 | 6 | class Quaternion 7 | { 8 | public: 9 | float q1, q2, q3, q4; 10 | public: 11 | // constructor creates a quaternion equivalent to roll=0, pitch=0, yaw=0 12 | Quaternion() { q1 = 1; q2 = q3 = q4 = 0; } 13 | // setting constructor 14 | Quaternion(float _q1, float _q2, float _q3, float _q4):q1(_q1), q2(_q2), q3(_q3), q4(_q4) {} 15 | // function call operator 16 | void operator()(float _q1, float _q2, float _q3, float _q4) {q1 = _q1; q2 = _q2; q3 = _q3; q4 = _q4; } 17 | // check if any elements are NAN 18 | bool IsNan(void) { return isnan(q1) || isnan(q2) || isnan(q3) || isnan(q4); } 19 | // create eulers from a quaternion 20 | void ToEuler(float &roll, float &pitch, float &yaw) 21 | { 22 | roll = atan2(2.0*(q1*q2 + q3*q4), 1 - 2.0*(q2*q2 + q3*q3)); 23 | pitch = asin(2.0*(q1*q3 - q4*q2)); 24 | yaw = atan2(2.0*(q1*q4 + q2*q3), 1 - 2.0*(q3*q3 + q4*q4)); 25 | } 26 | }; 27 | #endif // QUATERNION_H 28 | -------------------------------------------------------------------------------- /lib/math/Vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef _VECTOR3_H_ 2 | #define _VECTOR3_H_ 3 | 4 | #include "math.h" 5 | 6 | template 7 | class Vector3 8 | { 9 | public: 10 | T x,y,z; 11 | public: 12 | //defualt constructor 13 | Vector3() { x = 0; y = 0; z = 0; } 14 | // setting ctor 15 | Vector3(T x0, T y0, T z0) : x(x0), y(y0), z(z0) {} 16 | //"()" overload 17 | void operator()(T x0, T y0, T z0){x= x0; y= y0; z= z0;} 18 | //"==" overload 19 | bool operator==(const Vector3 &v){return (x==v.x && y==v.y && z==v.z); } 20 | //"!=" overload 21 | bool operator!=(const Vector3 &v){return (x!=v.x || y!=v.y || z!=v.z); } 22 | // "-" negation overload 23 | Vector3 operator-(void) const { return Vector3(-x,-y,-z);} 24 | //"+" addition overload 25 | Vector3 operator+(const Vector3 &v) const { return Vector3(x+v.x, y+v.y, z+v.z); } 26 | //"-" subtraction overload 27 | Vector3 operator-(const Vector3 &v) const { return Vector3(x-v.x, y-v.y, z-v.z); } 28 | //"*" multiply overload 29 | Vector3 operator*(const T n)const { return Vector3(x*n, y*n, z*n); } 30 | //"/" divsion overload 31 | Vector3 operator/(const T n)const { return Vector3(x/n, y/n, z/n); } 32 | //"=" 33 | Vector3 &operator=(const Vector3 &v){x=v.x; y=v.y; z=v.z; return *this;} 34 | //"+=" overload 35 | Vector3 &operator+=(const Vector3 &v) { x+=v.x; y+=v.y; z+=v.z; return *this; } 36 | //"-=" overload 37 | Vector3 &operator-=(const Vector3 &v) { x-=v.x; y-=v.y; z-=v.z; return *this; } 38 | //"*=" overload 39 | Vector3 &operator*=(const T n) { x*=n; y*=n; z*=n; return *this; } 40 | // uniform scaling 41 | Vector3 &operator/=(const T n) { x/=n; y/=n; z/=n; return *this; } 42 | //dot product 43 | T operator*(const Vector3 &v) const { return x*v.x + y*v.y + z*v.z; } 44 | //cross product 45 | Vector3 operator %(const Vector3 &v)const { return Vector3(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);} 46 | // gets the length of this vector squared 47 | T LengthSquared() const { return (T)(*this * *this); } 48 | // gets the length of this vector 49 | float Length(void) const { return (T)sqrt(*this * *this); } 50 | // normalizes this vector 51 | void Normalize() { *this/=Length(); } 52 | // zero the vector 53 | void Zero() { x = y = z = 0.0; } 54 | // returns the normalized version of this vector 55 | Vector3 Normalized() const { return *this/Length(); } 56 | // check if any elements are NAN 57 | bool IsNan(void) { return isnan(x) || isnan(y) || isnan(z); } 58 | // check if any elements are infinity 59 | bool IsInf(void) { return isinf(x) || isinf(y) || isinf(z); } 60 | 61 | }; 62 | typedef Vector3 Vector3f; 63 | #endif // VECTOR3_H 64 | -------------------------------------------------------------------------------- /lib/offchip/BLDCMotor/BLDCMotor.cpp: -------------------------------------------------------------------------------- 1 | #include "BLDCMotor.h" 2 | 3 | bool BLDCMotor::bInitSPWM = false; 4 | float BLDCMotor::SPWM[256] = {0}; 5 | 6 | 7 | void BLDCMotor::InitSPWM() 8 | { 9 | for(int i=0;i<256;i++) 10 | { 11 | SPWM[i] = sin(i*2.0*3.1415926/256.0); 12 | } 13 | } 14 | 15 | BLDCMotor::BLDCMotor(PWM *pwma, u8 cha, PWM *pwmb, u8 chb, PWM *pwmc, u8 chc, float power) 16 | { 17 | _pwm_a = pwma; 18 | _pwm_b = pwmb; 19 | _pwm_c = pwmc; 20 | _ch_a = cha; 21 | _ch_b = chb; 22 | _ch_c = chc; 23 | _maxPower = power; 24 | _armed = false; 25 | if(bInitSPWM) return; 26 | bInitSPWM = true; 27 | InitSPWM(); 28 | } 29 | 30 | void BLDCMotor::Initialize(PWM *pwma, u8 cha, PWM *pwmb, u8 chb, PWM *pwmc, u8 chc, float power) 31 | { 32 | _pwm_a = pwma; 33 | _pwm_b = pwmb; 34 | _pwm_c = pwmc; 35 | _ch_a = cha; 36 | _ch_b = chb; 37 | _ch_c = chc; 38 | _maxPower = power; 39 | 40 | } 41 | 42 | 43 | void BLDCMotor::SetPosition(int position) 44 | { 45 | if(!_armed) return; 46 | float a,b,c; 47 | 48 | u16 pos = position & 0xFF; 49 | 50 | a = SPWM[pos%256]; 51 | b = SPWM[(pos+85)%256]; 52 | c = SPWM[(pos+170)%256]; 53 | 54 | a = (_maxPower*a + 1.0)/2.0; 55 | b = (_maxPower*b + 1.0)/2.0; 56 | c = (_maxPower*c + 1.0)/2.0; 57 | 58 | _pwm_a->SetDuty(_ch_a,a*100); 59 | _pwm_b->SetDuty(_ch_b,b*100); 60 | _pwm_c->SetDuty(_ch_c,c*100); 61 | } 62 | void BLDCMotor::Enable() 63 | { 64 | _armed = true; 65 | } 66 | void BLDCMotor::Disable() 67 | { 68 | _armed = false; 69 | _pwm_a->SetDuty(_ch_a,0); 70 | _pwm_b->SetDuty(_ch_b,0); 71 | _pwm_c->SetDuty(_ch_c,0); 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /lib/offchip/BLDCMotor/BLDCMotor.h: -------------------------------------------------------------------------------- 1 | #ifndef __BLDCMOTOR_H 2 | #define __BLDCMOTOR_H 3 | #include "PWM.h" 4 | #include "math.h" 5 | 6 | class BLDCMotor 7 | { 8 | private: 9 | static bool bInitSPWM; 10 | static float SPWM[256]; 11 | PWM *_pwm_a; 12 | PWM *_pwm_b; 13 | PWM *_pwm_c; 14 | u8 _ch_a; 15 | u8 _ch_b; 16 | u8 _ch_c; 17 | float _maxPower; 18 | bool _armed; 19 | private: 20 | static void InitSPWM(); 21 | public: 22 | BLDCMotor(PWM *pwma, u8 cha, PWM *pwmb, u8 chb, PWM *pwmc, u8 chc, float power); 23 | void Initialize(PWM *pwma, u8 cha, PWM *pwmb, u8 chb, PWM *pwmc, u8 chc, float power); 24 | void SetPosition(int pos); 25 | void Enable(); 26 | void Disable(); 27 | }; 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /lib/offchip/Door/door.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "door.h" 4 | #include "Assert.h" 5 | 6 | 7 | Door::Door(GPIO* in, bool normalOpen , GPIO* out) 8 | { 9 | assert(in != NULL); 10 | mNormalOpen = normalOpen; 11 | mIsOpen = false; 12 | mGPIOIn = in; 13 | mGPIOOut = out; 14 | } 15 | 16 | 17 | bool Door::Init() 18 | { 19 | if(mGPIOOut) 20 | { 21 | mGPIOOut->SetLevel(1); 22 | } 23 | return true; 24 | } 25 | 26 | bool Door::Update() 27 | { 28 | uint8_t status = mGPIOIn->GetLevel(); 29 | if(mNormalOpen) 30 | { 31 | mIsOpen = (status==1)?false:true; 32 | } 33 | else 34 | { 35 | mIsOpen = (status==1)?true:false; 36 | } 37 | return true; 38 | } 39 | 40 | 41 | bool Door::IsOpen() 42 | { 43 | return mIsOpen; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /lib/offchip/Door/door.h: -------------------------------------------------------------------------------- 1 | #ifndef __DOOR_H 2 | #define __DOOR_H 3 | 4 | #include "GPIO.h" 5 | #include "stdbool.h" 6 | #include "stdio.h" 7 | #include "stdint.h" 8 | 9 | 10 | class Door{ 11 | 12 | public: 13 | Door(GPIO* in, bool normalOpen, GPIO* out = NULL); 14 | bool Init(); 15 | bool IsOpen(); 16 | bool Update(); 17 | 18 | private: 19 | bool mNormalOpen; 20 | bool mIsOpen; 21 | GPIO* mGPIOIn; 22 | GPIO* mGPIOOut; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Advanced Chat Server 3 | 4 | A more advanced server that distributes any incoming messages 5 | to all connected clients but the client the message comes from. 6 | To use telnet to your device's IP address and type. 7 | You can see the client's input in the serial monitor as well. 8 | Using an Arduino Wiznet Ethernet shield. 9 | 10 | Circuit: 11 | * Ethernet shield attached to pins 10, 11, 12, 13 12 | * Analog inputs attached to pins A0 through A5 (optional) 13 | 14 | created 18 Dec 2009 15 | by David A. Mellis 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | redesigned to make use of operator== 25 Nov 2013 19 | by Norbert Truchsess 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #define PORT 23 // telnet defaults to port 23 27 | 28 | // Enter a MAC address and IP address for your controller below. 29 | // The IP address will be dependent on your local network. 30 | // gateway and subnet are optional: 31 | byte mac[] = { 32 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 33 | IPAddress ip(192,168,1, 177); 34 | IPAddress gateway(192,168,1, 1); 35 | IPAddress subnet(255, 255, 255, 0); 36 | 37 | 38 | EthernetServer server(PORT); 39 | 40 | EthernetClient clients[4]; 41 | 42 | void setup() { 43 | // initialize the ethernet device 44 | Ethernet.begin(mac, ip, gateway, subnet); 45 | // start listening for clients 46 | server.begin(); 47 | // Open serial communications and wait for port to open: 48 | Serial.begin(9600); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo only 51 | } 52 | 53 | 54 | 55 | Serial.print("Chat server address: "); 56 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 57 | // print the value of each byte of the IP address: 58 | Serial.print(Ethernet.localIP()[thisByte], DEC); 59 | Serial.print("."); 60 | } 61 | Serial.print("\nPort: "); 62 | Serial.print(PORT); 63 | } 64 | 65 | void loop() { 66 | // wait for a new client: 67 | EthernetClient client = server.available(); 68 | 69 | // when the client sends the first byte, say hello: 70 | if (client) { 71 | 72 | boolean newClient = true; 73 | for (byte i=0;i<4;i++) { 74 | //check whether this client refers to the same socket as one of the existing instances: 75 | if (clients[i]==client) { 76 | newClient = false; 77 | break; 78 | } 79 | } 80 | 81 | if (newClient) { 82 | //check which of the existing clients can be overridden: 83 | for (byte i=0;i<4;i++) { 84 | if (!clients[i] && clients[i]!=client) { 85 | clients[i] = client; 86 | // clead out the input buffer: 87 | client.flush(); 88 | Serial.println("We have a new client"); 89 | client.print("Hello, client number: "); 90 | client.print(i); 91 | client.println(); 92 | break; 93 | } 94 | } 95 | } 96 | 97 | if (client.available() > 0) { 98 | // read the bytes incoming from the client: 99 | char thisChar = client.read(); 100 | // echo the bytes back to all other connected clients: 101 | for (byte i=0;i<4;i++) { 102 | if (clients[i] && (clients[i]!=client)) { 103 | clients[i].write(thisChar); 104 | } 105 | } 106 | // echo the bytes to the server as well: 107 | Serial.write(thisChar); 108 | } 109 | } 110 | for (byte i=0;i<4;i++) { 111 | if (!(clients[i].connected())) { 112 | // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false; 113 | clients[i].stop(); 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /lib/offchip/Ethernet/examples/ChatServer/ChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | Using an Arduino Wiznet Ethernet shield. 8 | 9 | Circuit: 10 | * Ethernet shield attached to pins 10, 11, 12, 13 11 | * Analog inputs attached to pins A0 through A5 (optional) 12 | 13 | created 18 Dec 2009 14 | by David A. Mellis 15 | modified 9 Apr 2012 16 | by Tom Igoe 17 | modified 12 Aug 2013 18 | by Soohwan Kim 19 | Modified 18 Aug 2015 20 | by Vassilis Serasidis 21 | 22 | ========================================================= 23 | Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis 24 | 25 | <---- Pinout ----> 26 | W5x00 <--> STM32F103 27 | SS <--> PA4 <--> BOARD_SPI1_NSS_PIN 28 | SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN 29 | MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN 30 | MOSI <--> PA7 <--> BOARD_SPI1_MOSI_PIN 31 | ========================================================= 32 | 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | // Enter a MAC address and IP address for your controller below. 39 | // The IP address will be dependent on your local network. 40 | // gateway and subnet are optional: 41 | #if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io 42 | ; 43 | #else 44 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 45 | #endif 46 | 47 | IPAddress ip(192,168,1, 177); 48 | IPAddress gateway(192,168,1, 1); 49 | IPAddress subnet(255, 255, 255, 0); 50 | 51 | 52 | // telnet defaults to port 23 53 | EthernetServer server(23); 54 | boolean alreadyConnected = false; // whether or not the client was connected previously 55 | 56 | void setup() { 57 | // initialize the ethernet device 58 | #if defined(WIZ550io_WITH_MACADDRESS) 59 | Ethernet.begin(ip, gateway, subnet); 60 | #else 61 | Ethernet.begin(mac, ip, gateway, subnet); 62 | #endif 63 | // start listening for clients 64 | server.begin(); 65 | // Open serial communications and wait for port to open: 66 | Serial.begin(9600); 67 | while (!Serial) { 68 | ; // wait for serial port to connect. Needed for Leonardo only 69 | } 70 | 71 | 72 | Serial.print("Chat server address:"); 73 | Serial.println(Ethernet.localIP()); 74 | } 75 | 76 | void loop() { 77 | // wait for a new client: 78 | EthernetClient client = server.available(); 79 | 80 | // when the client sends the first byte, say hello: 81 | if (client) { 82 | if (!alreadyConnected) { 83 | // clead out the input buffer: 84 | client.flush(); 85 | Serial.println("We have a new client"); 86 | client.println("Hello, client!"); 87 | alreadyConnected = true; 88 | } 89 | 90 | if (client.available() > 0) { 91 | // read the bytes incoming from the client: 92 | char thisChar = client.read(); 93 | // echo the bytes back to the client: 94 | server.write(thisChar); 95 | // echo the bytes to the server as well: 96 | Serial.write(thisChar); 97 | } 98 | } 99 | } 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHCP-based IP printer 3 | 4 | This sketch uses the DHCP extensions to the Ethernet library 5 | to get an IP address via DHCP and print the address obtained. 6 | using an Arduino Wiznet Ethernet shield. 7 | 8 | Circuit: 9 | * Ethernet shield attached to pins 10, 11, 12, 13 10 | 11 | created 12 April 2011 12 | modified 9 Apr 2012 13 | by Tom Igoe 14 | modified 12 Aug 2013 15 | by Soohwan Kim 16 | Modified 18 Aug 2015 17 | by Vassilis Serasidis 18 | 19 | ========================================================= 20 | Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis 21 | 22 | <---- Pinout ----> 23 | W5x00 <--> STM32F103 24 | SS <--> PA4 <--> BOARD_SPI1_NSS_PIN 25 | SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN 26 | MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN 27 | MOSI <--> PA7 <--> BOARD_SPI1_MOSI_PIN 28 | ========================================================= 29 | 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | // Enter a MAC address for your controller below. 36 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 37 | #if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io 38 | ; 39 | #else 40 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 41 | #endif 42 | 43 | IPAddress ip(192,168,1,177); 44 | 45 | // Initialize the Ethernet client library 46 | // with the IP address and port of the server 47 | // that you want to connect to (port 80 is default for HTTP): 48 | EthernetClient client; 49 | 50 | void setup() { 51 | // Open serial communications and wait for port to open: 52 | Serial.begin(9600); 53 | 54 | // start the Ethernet connection: 55 | //Ethernet.begin(mac, ip); //Static IP 56 | Ethernet.begin(mac); //It Gets the IP from the DHCP Server 57 | 58 | // print your local IP address: 59 | Serial.print("My IP address: "); 60 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 61 | // print the value of each byte of the IP address: 62 | Serial.print(Ethernet.localIP()[thisByte], DEC); 63 | Serial.print("."); 64 | } 65 | Serial.println(); 66 | } 67 | 68 | void loop() { 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHCP Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | Using an Arduino Wiznet Ethernet shield. 8 | 9 | THis version attempts to get an IP address using DHCP 10 | 11 | Circuit: 12 | * Ethernet shield attached to pins 10, 11, 12, 13 13 | 14 | Based on ChatServer example by David A. Mellis 15 | created 21 May 2011 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified 12 Aug 2013 19 | by Soohwan Kim 20 | Modified 18 Aug 2015 21 | by Vassilis Serasidis 22 | 23 | ========================================================= 24 | Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis 25 | 26 | <---- Pinout ----> 27 | W5x00 <--> STM32F103 28 | SS <--> PA4 <--> BOARD_SPI1_NSS_PIN 29 | SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN 30 | MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN 31 | MOSI <--> PA7 <--> BOARD_SPI1_MOSI_PIN 32 | ========================================================= 33 | 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | // Enter a MAC address and IP address for your controller below. 40 | // The IP address will be dependent on your local network. 41 | // gateway and subnet are optional: 42 | #if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io 43 | ; 44 | #else 45 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 46 | #endif 47 | IPAddress ip(192,168,1, 177); 48 | IPAddress gateway(192,168,1, 1); 49 | IPAddress subnet(255, 255, 0, 0); 50 | 51 | // telnet defaults to port 23 52 | EthernetServer server(23); 53 | boolean gotAMessage = false; // whether or not you got a message from the client yet 54 | 55 | void setup() { 56 | 57 | // Open serial communications and wait for port to open: 58 | Serial.begin(9600); 59 | // this check is only needed on the Leonardo: 60 | while (!Serial) { 61 | ; // wait for serial port to connect. Needed for Leonardo only 62 | } 63 | 64 | 65 | // start the Ethernet connection: 66 | Serial.println("Trying to get an IP address using DHCP"); 67 | #if defined(WIZ550io_WITH_MACADDRESS) 68 | if (Ethernet.begin() == 0) { 69 | #else 70 | if (Ethernet.begin(mac) == 0) { 71 | #endif 72 | Serial.println("Failed to configure Ethernet using DHCP"); 73 | // initialize the ethernet device not using DHCP: 74 | #if defined(WIZ550io_WITH_MACADDRESS) 75 | Ethernet.begin(ip, gateway, subnet); 76 | #else 77 | Ethernet.begin(mac, ip, gateway, subnet); 78 | #endif 79 | } 80 | // print your local IP address: 81 | Serial.print("My IP address: "); 82 | ip = Ethernet.localIP(); 83 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 84 | // print the value of each byte of the IP address: 85 | Serial.print(ip[thisByte], DEC); 86 | Serial.print("."); 87 | } 88 | Serial.println(); 89 | // start listening for clients 90 | server.begin(); 91 | 92 | } 93 | 94 | void loop() { 95 | // wait for a new client: 96 | EthernetClient client = server.available(); 97 | 98 | // when the client sends the first byte, say hello: 99 | if (client) { 100 | if (!gotAMessage) { 101 | Serial.println("We have a new client"); 102 | client.println("Hello, client!"); 103 | gotAMessage = true; 104 | } 105 | 106 | // read the bytes incoming from the client: 107 | char thisChar = client.read(); 108 | // echo the bytes back to the client: 109 | server.write(thisChar); 110 | // echo the bytes to the server as well: 111 | Serial.print(thisChar); 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/examples/TelnetClient/TelnetClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Telnet client 3 | 4 | This sketch connects to a a telnet server (http://www.google.com) 5 | using an Arduino Wiznet Ethernet shield. You'll need a telnet server 6 | to test this with. 7 | Processing's ChatServer example (part of the network library) works well, 8 | running on port 10002. It can be found as part of the examples 9 | in the Processing application, available at 10 | http://processing.org/ 11 | 12 | Circuit: 13 | * Ethernet shield attached to pins 10, 11, 12, 13 14 | 15 | created 14 Sep 2010 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified 12 Aug 2013 19 | by Soohwan Kim 20 | Modified 18 Aug 2015 21 | by Vassilis Serasidis 22 | 23 | ========================================================= 24 | Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis 25 | 26 | <---- Pinout ----> 27 | W5x00 <--> STM32F103 28 | SS <--> PA4 <--> BOARD_SPI1_NSS_PIN 29 | SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN 30 | MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN 31 | MOSI <--> PA7 <--> BOARD_SPI1_MOSI_PIN 32 | ========================================================= 33 | 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | // Enter a MAC address and IP address for your controller below. 40 | // The IP address will be dependent on your local network: 41 | #if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io 42 | ; 43 | #else 44 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 45 | #endif 46 | 47 | IPAddress ip(192,168,1,177); 48 | 49 | // Enter the IP address of the server you're connecting to: 50 | IPAddress server(1,1,1,1); 51 | 52 | // Initialize the Ethernet client library 53 | // with the IP address and port of the server 54 | // that you want to connect to (port 23 is default for telnet; 55 | // if you're using Processing's ChatServer, use port 10002): 56 | EthernetClient client; 57 | 58 | void setup() { 59 | // start the Ethernet connection: 60 | #if defined(WIZ550io_WITH_MACADDRESS) 61 | Ethernet.begin(ip); 62 | #else 63 | Ethernet.begin(mac, ip); 64 | #endif 65 | // Open serial communications and wait for port to open: 66 | Serial.begin(9600); 67 | while (!Serial) { 68 | ; // wait for serial port to connect. Needed for Leonardo only 69 | } 70 | 71 | 72 | // give the Ethernet shield a second to initialize: 73 | delay(1000); 74 | Serial.println("connecting..."); 75 | 76 | // if you get a connection, report back via serial: 77 | if (client.connect(server, 10002)) { 78 | Serial.println("connected"); 79 | } 80 | else { 81 | // if you didn't get a connection to the server: 82 | Serial.println("connection failed"); 83 | } 84 | } 85 | 86 | void loop() 87 | { 88 | // if there are incoming bytes available 89 | // from the server, read them and print them: 90 | if (client.available()) { 91 | char c = client.read(); 92 | Serial.print(c); 93 | } 94 | 95 | // as long as there are bytes in the serial queue, 96 | // read them and send them out the socket if it's open: 97 | while (Serial.available() > 0) { 98 | char inChar = Serial.read(); 99 | if (client.connected()) { 100 | client.print(inChar); 101 | } 102 | } 103 | 104 | // if the server's disconnected, stop the client: 105 | if (!client.connected()) { 106 | Serial.println(); 107 | Serial.println("disconnecting."); 108 | client.stop(); 109 | // do nothing: 110 | while(true); 111 | } 112 | } 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/examples/Twitter_SimplePost/Twitter_SimplePost.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Twitter SimplePost 3 | 4 | SimplePost messages to Twitter (tweet) from Aruduino with Ethernet Shield! 5 | 6 | Notice 7 | -The library uses this site as a proxy server for OAuth stuff. Your tweet may not be applied during maintenance of this site. 8 | -Please avoid sending more than 1 request per minute not to overload the server. 9 | -Twitter seems to reject repeated tweets with the same contenet (returns error 403). 10 | 11 | Reference & Lincense 12 | URL : http://arduino-tweet.appspot.com/ 13 | 14 | Circuit: 15 | * Ethernet shield attached to pins 10, 11, 12, 13 16 | 17 | created 2011 18 | by NeoCat - (ver1.3 - Support IDE 1.0) 19 | tested & 20 | modified 13 Aug 2013 21 | by Soohwan Kim - (ver1.3 - Support IDE 1.0.5) 22 | Modified 18 Aug 2015 23 | by Vassilis Serasidis 24 | 25 | ========================================================= 26 | Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis 27 | 28 | <---- Pinout ----> 29 | W5x00 <--> STM32F103 30 | SS <--> PA4 <--> BOARD_SPI1_NSS_PIN 31 | SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN 32 | MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN 33 | MOSI <--> PA7 <--> BOARD_SPI1_MOSI_PIN 34 | ========================================================= 35 | 36 | */ 37 | 38 | #include // needed in Arduino 0019 or later 39 | #include 40 | #include "./Twitter.h" // Twitter.h in library/Ethernet folder. @diffinsight 2013-08-19 41 | 42 | // The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later. 43 | // Please uncomment below in Arduino IDE 0022 or earlier. 44 | //#include 45 | 46 | 47 | // Ethernet Shield Settings 48 | #if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io 49 | ; 50 | #else 51 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 52 | #endif 53 | 54 | // If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later). 55 | // fill in an available IP address on your network here, 56 | IPAddress ip(1,1,1,1); 57 | IPAddress gw(1,1,1,1); 58 | IPAddress snip(1,1,1,1); 59 | IPAddress dnsip(1,1,1,1); 60 | 61 | // Your Token to Tweet (get it from http://arduino-tweet.appspot.com/) 62 | Twitter twitter("YOUR-TOKEN-HERE"); 63 | 64 | // Message to post 65 | char msg[] = "Hello! Tweet! Tweet! Tweet! This message is written from Arduino Pro Mini!"; 66 | 67 | void setup() 68 | { 69 | delay(1000); 70 | // start the Ethernet connection: 71 | #if defined(WIZ550io_WITH_MACADDRESS) 72 | Ethernet.begin(ip, dnsip, gw,snip); 73 | #else 74 | Ethernet.begin(mac, ip, dnsip, gw,snip); 75 | #endif 76 | // or you can use DHCP for autoomatic IP address configuration. 77 | // Ethernet.begin(mac); 78 | Serial.begin(9600); 79 | 80 | Serial.println("connecting ..."); 81 | if (twitter.post(msg)) { 82 | // Specify &Serial to output received response to Serial. 83 | // If no output is required, you can just omit the argument, e.g. 84 | // int status = twitter.wait(); 85 | int status = twitter.wait(&Serial); 86 | if (status == 200) { 87 | Serial.println("OK."); 88 | } else { 89 | Serial.print("failed : code "); 90 | Serial.println(status); 91 | } 92 | } else { 93 | Serial.println("connection failed."); 94 | } 95 | } 96 | 97 | void loop() 98 | { 99 | } 100 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ethernet 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Ethernet KEYWORD1 Ethernet 10 | EthernetClient KEYWORD1 EthernetClient 11 | EthernetServer KEYWORD1 EthernetServer 12 | IPAddress KEYWORD1 EthernetIPAddress 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | status KEYWORD2 19 | connect KEYWORD2 20 | write KEYWORD2 21 | available KEYWORD2 22 | read KEYWORD2 23 | peek KEYWORD2 24 | flush KEYWORD2 25 | stop KEYWORD2 26 | connected KEYWORD2 27 | begin KEYWORD2 28 | beginPacket KEYWORD2 29 | endPacket KEYWORD2 30 | parsePacket KEYWORD2 31 | remoteIP KEYWORD2 32 | remotePort KEYWORD2 33 | 34 | ####################################### 35 | # Constants (LITERAL1) 36 | ####################################### 37 | 38 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/library.properties: -------------------------------------------------------------------------------- 1 | name=Ethernet_STM 2 | version=1.0.3 3 | author=WIZnet :: Ported to STM32 by Vassilis Serasidis. 4 | maintainer=WIZnet and Vassilis Serasidis (for porting to STM32) 5 | sentence=Enables network connection (local and Internet) using the Arduino Ethernet board or shield. For all Arduino boards. 6 | paragraph=With this library you can use the Arduino Ethernet (shield or board) to connect to Internet. The library provides both Client and server functionalities. The library permits you to connect to a local network also with DHCP and to resolve DNS. 7 | category=Communication 8 | url=http://arduino.cc/en/Reference/Ethernet 9 | architectures=* -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | // #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/Dns.h: -------------------------------------------------------------------------------- 1 | // Arduino DNS client for WizNet5100-based Ethernet shield 2 | // (c) Copyright 2009-2010 MCQN Ltd. 3 | // Released under Apache License, version 2.0 4 | 5 | #ifndef DNSClient_h 6 | #define DNSClient_h 7 | 8 | #include 9 | #include "util.h" 10 | 11 | class DNSClient 12 | { 13 | public: 14 | // ctor 15 | void begin(const IPAddress& aDNSServer); 16 | 17 | /** Convert a numeric IP address string into a four-byte IP address. 18 | @param aIPAddrString IP address to convert 19 | @param aResult IPAddress structure to store the returned IP address 20 | @result 1 if aIPAddrString was successfully converted to an IP address, 21 | else error code 22 | */ 23 | int inet_aton(const char *aIPAddrString, IPAddress& aResult); 24 | 25 | /** Resolve the given hostname to an IP address. 26 | @param aHostname Name to be resolved 27 | @param aResult IPAddress structure to store the returned IP address 28 | @result 1 if aIPAddrString was successfully converted to an IP address, 29 | else error code 30 | */ 31 | int getHostByName(const char* aHostname, IPAddress& aResult); 32 | 33 | protected: 34 | uint16_t BuildRequest(const char* aName); 35 | int16_t ProcessResponse(uint16_t aTimeout, IPAddress& aAddress); 36 | 37 | IPAddress iDNSServer; 38 | uint16_t iRequestId; 39 | EthernetUDP iUdp; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/EthernetClient.h: -------------------------------------------------------------------------------- 1 | #ifndef ethernetclient_h 2 | #define ethernetclient_h 3 | // #include "Arduino.h" 4 | // #include "Print.h" 5 | #include "Client.h" 6 | #include "IPAddress.h" 7 | 8 | class EthernetClient : public Client { 9 | 10 | public: 11 | EthernetClient(); 12 | EthernetClient(uint8_t sock); 13 | 14 | uint8_t status(); 15 | virtual int connect(IPAddress ip, uint16_t port); 16 | virtual int connect(const char *host, uint16_t port); 17 | virtual size_t write(uint8_t); 18 | virtual size_t write(const uint8_t *buf, size_t size); 19 | virtual int available(); 20 | virtual int read(); 21 | virtual int read(uint8_t *buf, size_t size); 22 | virtual int peek(); 23 | virtual void flush(); 24 | virtual void stop(); 25 | virtual uint8_t connected(); 26 | virtual operator bool(); 27 | virtual bool operator==(const EthernetClient&); 28 | virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); }; 29 | 30 | friend class EthernetServer; 31 | 32 | // using Print::write; 33 | int println(const char* str); 34 | int println(); 35 | int print(const char* str); 36 | int getWriteError() { return write_error; } 37 | 38 | protected: 39 | void setWriteError(int err = 1) { write_error = err; } 40 | 41 | private: 42 | static uint16_t _srcport; 43 | uint8_t _sock; 44 | int write_error; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/Ethernet_STM.h: -------------------------------------------------------------------------------- 1 | /* 2 | modified 12 Aug 2013 3 | by Soohwan Kim (suhwan@wiznet.co.kr) 4 | */ 5 | #ifndef ethernet_h 6 | #define ethernet_h 7 | 8 | #include 9 | #include "utility/w5500.h" 10 | #include "IPAddress.h" 11 | #include "EthernetClient.h" 12 | //#include "EthernetServer.h" 13 | #include "Dhcp.h" 14 | 15 | 16 | 17 | class EthernetClass { 18 | private: 19 | IPAddress _dnsServerAddress; 20 | //DhcpClass* _dhcp; 21 | GPIO* mResetPin; 22 | public: 23 | static uint8_t _state[MAX_SOCK_NUM]; 24 | static uint16_t _server_port[MAX_SOCK_NUM]; 25 | 26 | void setResetPin(GPIO* gpio); 27 | 28 | #if defined(WIZ550io_WITH_MACADDRESS) 29 | // Initialize function when use the ioShield serise (included WIZ550io) 30 | // WIZ550io has a MAC address which is written after reset. 31 | // Default IP, Gateway and subnet address are also writen. 32 | // so, It needs some initial time. please refer WIZ550io Datasheet in details. 33 | int begin(void); 34 | void begin(IPAddress local_ip); 35 | void begin(IPAddress local_ip, IPAddress dns_server); 36 | void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway); 37 | void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); 38 | #else 39 | // Initialize the Ethernet shield to use the provided MAC address and gain the rest of the 40 | // configuration through DHCP. 41 | // Returns 0 if the DHCP configuration failed, and 1 if it succeeded 42 | int begin(uint8_t *mac_address); 43 | void begin(uint8_t *mac_address, IPAddress local_ip); 44 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server); 45 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway); 46 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); 47 | 48 | #endif 49 | 50 | int maintain(); 51 | 52 | IPAddress localIP(); 53 | IPAddress subnetMask(); 54 | IPAddress gatewayIP(); 55 | IPAddress dnsServerIP(); 56 | 57 | friend class EthernetClient; 58 | // friend class EthernetServer; 59 | }; 60 | 61 | extern EthernetClass Ethernet; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #define htons(x) ( ((x)<<8) | (((x)>>8)&0xFF) ) 5 | #define ntohs(x) htons(x) 6 | 7 | #define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \ 8 | ((x)<< 8 & 0x00FF0000UL) | \ 9 | ((x)>> 8 & 0x0000FF00UL) | \ 10 | ((x)>>24 & 0x000000FFUL) ) 11 | #define ntohl(x) htonl(x) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/utility/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.h - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef IPAddress_h 21 | #define IPAddress_h 22 | 23 | #include 24 | #include 25 | 26 | // A class to make it easier to handle and pass around IP addresses 27 | typedef uint8_t byte; 28 | 29 | 30 | class IPAddress { 31 | private: 32 | union { 33 | uint8_t bytes[4]; // IPv4 address 34 | uint32_t dword; 35 | } _address; 36 | 37 | 38 | 39 | public: 40 | // Constructors 41 | IPAddress(); 42 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 43 | IPAddress(uint32_t address); 44 | IPAddress(const uint8_t *address); 45 | 46 | bool fromString(const char *address); 47 | // bool fromString(const String &address) { return fromString(address.c_str()); } 48 | 49 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 50 | // to a four-byte uint8_t array is expected 51 | operator uint32_t() const { return _address.dword; }; 52 | bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; 53 | bool operator==(const uint8_t* addr) const; 54 | 55 | // Overloaded index operator to allow getting and setting individual octets of the address 56 | uint8_t operator[](int index) const { return _address.bytes[index]; }; 57 | uint8_t& operator[](int index) { return _address.bytes[index]; }; 58 | 59 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 60 | IPAddress& operator=(const uint8_t *address); 61 | IPAddress& operator=(uint32_t address); 62 | 63 | // virtual size_t printTo(Print& p) const; 64 | // String toString(); 65 | // Access the raw byte array containing the address. Because this returns a pointer 66 | // to the internal structure rather than a copy of the address this function should only 67 | // be used when you know that the usage of the returned uint8_t* will be transient and not 68 | // stored. 69 | uint8_t* raw_address() { return _address.bytes; }; 70 | }; 71 | 72 | const IPAddress INADDR_NONE(0,0,0,0); 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/utility/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOCKET_H_ 2 | #define _SOCKET_H_ 3 | 4 | #include "utility/w5500.h" 5 | 6 | extern uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag); // Opens a socket(TCP or UDP or IP_RAW mode) 7 | extern void close(SOCKET s); // Close socket 8 | extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TCP connection (Active connection) 9 | extern void disconnect(SOCKET s); // disconnect the connection 10 | extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection) 11 | extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP) 12 | extern int16_t recv(SOCKET s, uint8_t * buf, int16_t len); // Receive data (TCP) 13 | extern uint16_t peek(SOCKET s, uint8_t *buf); 14 | extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW) 15 | extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW) 16 | extern void flush(SOCKET s); // Wait for transmission to complete 17 | 18 | extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len); 19 | 20 | // Functions to allow buffered UDP send (i.e. where the UDP datagram is built up over a 21 | // number of calls before being sent 22 | /* 23 | @brief This function sets up a UDP datagram, the data for which will be provided by one 24 | or more calls to bufferData and then finally sent with sendUDP. 25 | @return 1 if the datagram was successfully set up, or 0 if there was an error 26 | */ 27 | extern int startUDP(SOCKET s, uint8_t* addr, uint16_t port); 28 | /* 29 | @brief This function copies up to len bytes of data from buf into a UDP datagram to be 30 | sent later by sendUDP. Allows datagrams to be built up from a series of bufferData calls. 31 | @return Number of bytes successfully buffered 32 | */ 33 | uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len); 34 | /* 35 | @brief Send a UDP datagram built up from a sequence of startUDP followed by one or more 36 | calls to bufferData. 37 | @return 1 if the datagram was successfully sent, or 0 if there was an error 38 | */ 39 | int sendUDP(SOCKET s); 40 | uint8_t socketStatus(SOCKET s); 41 | 42 | #endif 43 | /* _SOCKET_H_ */ 44 | -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/utility/util.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neutree/STM32f103DriverLib/28dfb70b6b0aa8e0de940ae8aa417a3989dbe3a5/lib/offchip/Ethernet/src/utility/util.cpp -------------------------------------------------------------------------------- /lib/offchip/Ethernet/src/utility/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #include "TaskManager.h" 5 | #include "stdlib.h" 6 | 7 | inline int millis() 8 | { 9 | int s = (int)TaskManager::Time(); 10 | return s*1000; 11 | } 12 | 13 | inline void delay(int ms) 14 | { 15 | TaskManager::DelayMs(ms); 16 | } 17 | 18 | inline int random(int min, int max) 19 | { 20 | return rand()%(max-min+1)+min; 21 | } 22 | 23 | #define htons(x) ( ((x)<< 8 & 0xFF00) | \ 24 | ((x)>> 8 & 0x00FF) ) 25 | #define ntohs(x) htons(x) 26 | 27 | #define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \ 28 | ((x)<< 8 & 0x00FF0000UL) | \ 29 | ((x)>> 8 & 0x0000FF00UL) | \ 30 | ((x)>>24 & 0x000000FFUL) ) 31 | #define ntohl(x) htonl(x) 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/offchip/GPS/main.cpp: -------------------------------------------------------------------------------- 1 | #include "GPS.h" 2 | //#include "USART.h" 3 | void USART_Config(void){ 4 | USART_InitTypeDef USART_InitStructure; 5 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); 6 | 7 | USART_InitStructure.USART_BaudRate = 9600; 8 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 9 | USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; 10 | USART_InitStructure.USART_Parity = USART_Parity_No; 11 | USART_InitStructure.USART_StopBits = USART_StopBits_1; 12 | USART_InitStructure.USART_WordLength = USART_WordLength_8b; 13 | 14 | USART_Init(USART1,&USART_InitStructure); 15 | USART_Cmd(USART1,ENABLE); 16 | 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 20 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; 21 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 22 | GPIO_Init(GPIOA,&GPIO_InitStructure); 23 | 24 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 25 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; 26 | GPIO_Init(GPIOA,&GPIO_InitStructure); 27 | } 28 | 29 | void RCC_HSE_Configuration(void){ 30 | RCC_DeInit(); 31 | RCC_HSEConfig(RCC_HSE_ON); 32 | if(RCC_WaitForHSEStartUp() == SUCCESS){ 33 | RCC_HCLKConfig(RCC_SYSCLK_Div1); 34 | RCC_PCLK1Config(RCC_HCLK_Div2); 35 | RCC_PCLK2Config(RCC_HCLK_Div1); 36 | RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); 37 | RCC_PLLCmd(ENABLE); 38 | while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); 39 | RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); 40 | while(RCC_GetSYSCLKSource() != 0x08); 41 | } 42 | } 43 | 44 | int main(void){ 45 | // USART com2(2,115200); 46 | u8 i = 0,j=0; 47 | SystemInit(); 48 | GPS GPS1(USART2, 9600, false, 0x00, 1, 0, 1); 49 | GPS1.EnabledRealProcess(); 50 | // GPS1.SETGPSUpdateTime(500); 51 | USART_Config(); 52 | while(1){ 53 | for(i = 0;i<255;i++) 54 | for(j = 0;j<255;j++) 55 | ; 56 | GPS1.Update(); 57 | printf("Longitude=%lf\r\n", GPS1.getLongitude()); 58 | printf("Latitude=%lf\r\n", GPS1.getLatitude()); 59 | printf("Speed=%lf\r\n", GPS1.getSpeed()); 60 | printf("Course=%lf\r\n", GPS1.getCourse()); 61 | printf("MSL_Al=%lf\r\n", GPS1.getMSL_Altitude()); 62 | printf("PDOP=%lf\r\n", GPS1.getPDOP()); 63 | printf("HDOP=%lf\r\n", GPS1.getHDOP()); 64 | printf("VDOP=%lf\r\n", GPS1.getVDOP()); 65 | printf("NS_Ind=%c\r\n", GPS1.getNS_Indicator()); 66 | printf("EW_Ind=%c\r\n", GPS1.getEW_Indicator()); 67 | } 68 | } 69 | extern "C"{ 70 | int fputc(int ch,FILE *f) 71 | { 72 | USART_SendData(USART1,(u8)ch); 73 | while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET); 74 | return ch; 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /lib/offchip/GPS/stm32f10x.cpp: -------------------------------------------------------------------------------- 1 | #include "stm32f10x_it.h" 2 | 3 | GPS *pGPS1 = 0; 4 | GPS *pGPS2 = 0; 5 | GPS *pGPS3 = 0; 6 | void USART1_IRQHandler(void){ 7 | if(pGPS1) 8 | pGPS1->GPS_IRQHandler(); 9 | } 10 | 11 | void USART2_IRQHandler(void){ 12 | if(pGPS2) 13 | pGPS2->GPS_IRQHandler(); 14 | } 15 | 16 | void USART3_IRQHandler(void){ 17 | if(pGPS3) 18 | pGPS3->GPS_IRQHandler(); 19 | } 20 | 21 | void DMA1_Channel1_IRQHandler(void){ 22 | 23 | } 24 | 25 | void DMA1_Channel2_IRQHandler(void){ 26 | 27 | } 28 | 29 | void DMA1_Channel3_IRQHandler(void){ 30 | 31 | } 32 | 33 | void DMA1_Channel4_IRQHandler(void){ 34 | 35 | } 36 | 37 | void DMA1_Channel5_IRQHandler(void){ 38 | 39 | } 40 | 41 | void DMA1_Channel6_IRQHandler(void){ 42 | 43 | } 44 | 45 | void DMA1_Channel7_IRQHandler(void){ 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lib/offchip/HCHO/HCHO.cpp: -------------------------------------------------------------------------------- 1 | #include "HCHO.h" 2 | 3 | HCHO::HCHO(USART &usart):mUsart(usart) 4 | { 5 | 6 | } 7 | 8 | HCHO::~HCHO() 9 | { 10 | 11 | } 12 | 13 | //和校验生成函数 14 | unsigned short HCHO::LRC(unsigned char *data,unsigned char len) 15 | { 16 | unsigned short lrc = 0; 17 | for(int i = 0;i=10) 31 | { 32 | while(mUsart.ReceiveBufferSize()>=10) 33 | { 34 | mUsart.GetReceivedData(&ch,1); 35 | if(ch == 0x42) 36 | { 37 | mUsart.GetReceivedData(&ch,1); 38 | if(ch==0x4d) 39 | { 40 | mUsart.GetReceivedData(mData,8); 41 | datatemp = (mData[4]<<8) + mData[5]; //返回数据 42 | switch (mData[3]) //数据当量 43 | { 44 | case 0x01:{data = datatemp/1.0;break;} 45 | case 0x02:{data = datatemp/10.0;break;} 46 | case 0x03:{data = datatemp/100.0;break;} 47 | case 0x04:{data = datatemp/1000.0;break;} 48 | } 49 | data_h = (u8)data; 50 | data_l = (u8) ( (data - data_h)*100 ); 51 | mUsart.ClearReceiveBuffer(); 52 | return true; 53 | 54 | } 55 | } 56 | } 57 | } 58 | return false; 59 | } 60 | 61 | float HCHO::GetFloatData() 62 | { 63 | return data; 64 | } 65 | 66 | //正常情况下不得超过0.10mg/m3 67 | 68 | unsigned char HCHO::Data_Hight_8() 69 | { 70 | return data_h; 71 | } 72 | unsigned char HCHO::Data_Low_8() 73 | { 74 | return data_l; 75 | } 76 | -------------------------------------------------------------------------------- /lib/offchip/HCHO/HCHO.h: -------------------------------------------------------------------------------- 1 | /******************************************************************* 2 | * filename:HCHO.h 3 | * brief: 这是一个甲烷传感器的驱动,传感器的型号是DS-HCHO.可以直接得到一个float的数据值 4 | * 单位是mg/m3,也可以得到两个8位数据,高位+低位/100=浓度,方便数据成帧传输 5 | * version:1.2 6 | * author: lissettecarlr 7 | * data: 2016/5/27 8 | * note: 一共三个文件 .H .CPP 和一个抽象类:Senser.h组成 9 | ******************************************************************/ 10 | 11 | #ifndef _HCHO_H 12 | #define _HCHO_H 13 | 14 | #include 15 | #include "USART.h" 16 | #include "Senser.h" 17 | 18 | #define HCHO_DATASIZE 20 19 | 20 | #define _HCHO 0x14 21 | 22 | #define PPM 0x01 23 | #define VOL 0x02 24 | #define LEL 0x03 25 | #define PPB 0x04 26 | #define MGM3 0x05 27 | 28 | 29 | 30 | class HCHO:public Senser 31 | { 32 | private: 33 | 34 | USART &mUsart; 35 | float data; 36 | unsigned char mData[HCHO_DATASIZE]; //数据区 37 | /** 38 | *@brief 和校验函数(只是简单的将数据求和) 39 | *@param data :要生成和校验的数据的首地址 40 | */ 41 | unsigned short LRC(unsigned char *data,unsigned char len); 42 | 43 | public: 44 | 45 | u8 data_h; 46 | u8 data_l; 47 | 48 | HCHO(USART &usart); 49 | ~HCHO(); 50 | 51 | virtual bool Updata(); 52 | 53 | /** 54 | *@brief 得到甲醛浓度的数据 55 | *@retval 甲醛浓度的高低字节数据 56 | */ 57 | virtual float GetFloatData(); 58 | virtual unsigned char Data_Hight_8(); 59 | virtual unsigned char Data_Low_8(); 60 | }; 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lib/offchip/HCHO/Senser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __SENSER_H 3 | #define __SENSER_H 4 | 5 | class Senser{ 6 | public: 7 | Senser(){}; 8 | virtual bool Updata()=0; 9 | // virtual unsigned short int GetU16Data()=0; 10 | virtual float GetFloatData()=0; 11 | virtual unsigned char Data_Hight_8() =0; 12 | virtual unsigned char Data_Low_8() =0; 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/offchip/HMI/HMI.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neutree/STM32f103DriverLib/28dfb70b6b0aa8e0de940ae8aa417a3989dbe3a5/lib/offchip/HMI/HMI.cpp -------------------------------------------------------------------------------- /lib/offchip/HMI/HMI.h: -------------------------------------------------------------------------------- 1 | /**@file HMI.h 2 | *@brief HMI串口屏驱动,使其更加方便的使用串口屏来显示数据 3 | * 使用: 4 | * 5 | * 6 | * 7 | * 8 | *@author lissettecarlr 9 | * 10 | */ 11 | 12 | #ifndef __HMI_H 13 | #define __HMI_H 14 | 15 | #include "stm32f10x.h" 16 | #include "USART.h" 17 | #include "TaskManager.h" 18 | #include "stdio.h" 19 | 20 | class HMI 21 | { 22 | private: 23 | USART &COM; 24 | 25 | 26 | public: 27 | 28 | HMI(USART &HMI_com); 29 | 30 | bool setTextBox(char *ControlsName,char *Content); 31 | bool setTextBox(char *ControlsName,float val,u8 decimals); 32 | bool setTextBox(char *ControlsName,int val); 33 | 34 | bool flushPage(char *Page); 35 | bool vis(char *ControlsName,bool state); //1显示 0隐藏 36 | // bool SetTextBox(char *name,char *txt);//设置文本框 37 | // bool SetProgressBar(char *name,char val);//设置进度条 38 | 39 | // bool SetTextBox(USART &com,char *name,char *txt);//设置文本框 40 | // bool SetProgressBar(USART &com,char *name,char *val);//设置进度条 41 | 42 | 43 | /**********************************Personal function**************************************/ 44 | bool outputDirection(char *ControlsName,u8 direction); //九宫格表示 45 | 46 | }; 47 | 48 | #endif 49 | 50 | /**********************************Personal define**************************************/ 51 | #define UI_PITCH "t6" 52 | #define UI_ROOL "t7" 53 | #define UI_YAW "t8" 54 | #define UI_THR "t9" 55 | #define UI_RcPower "t21" 56 | #define UI_CopterPower "t22" 57 | #define UI_DirectionL "t19" 58 | #define UI_DirectionR "t20" 59 | #define UI_CoefficientL "t14" 60 | #define UI_CoefficientR "t15" 61 | #define UI_Hight "t11" 62 | #define UI_AliveTime "t13" 63 | #define UI_FlyClock "p0" 64 | 65 | 66 | -------------------------------------------------------------------------------- /lib/offchip/Humidity/Humidity.h: -------------------------------------------------------------------------------- 1 | #ifndef __HUMIDITY_H 2 | #define __HUMIDITY_H 3 | 4 | class Humidity{ 5 | 6 | public: 7 | virtual float GetHumidity() = 0; 8 | virtual int Update() = 0; 9 | }; 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lib/offchip/Joystick/Joystick.cpp: -------------------------------------------------------------------------------- 1 | #include "Joystick.h" 2 | 3 | 4 | 5 | Joystick::Joystick(ADC &adc,u8 LX,u8 LY,u8 NX,u8 NY):mAdc(adc) 6 | { 7 | mCH_LX=LX; 8 | mCH_LY=LY; 9 | mCH_NX=NX; 10 | mCH_NY=NY; 11 | } 12 | 13 | 14 | bool Joystick::Updata() 15 | { 16 | 17 | mLX_Val=mAdc[mCH_LX]; 18 | mLY_Val=mAdc[mCH_LY]; 19 | mNX_Val=mAdc[mCH_NX]; 20 | mNY_Val=mAdc[mCH_NY]; 21 | 22 | return true; 23 | 24 | } 25 | 26 | 27 | u8 Joystick::getLeftState() //左上向右数的九宫格 28 | { 29 | u8 Xtemp,Ytemp; 30 | 31 | //左右判断 32 | if(mLX_Val ==0) 33 | return 0; 34 | else if(mLX_ValLX_LEFT_THRESHOLDS) //向左搬动了 37 | Xtemp=4; 38 | else 39 | Xtemp=5; 40 | 41 | //上下判断 42 | if(mLY_Val ==0) 43 | return 0; 44 | else if(mLY_Val>LX_UP_THRESHOLDS)//向上搬动了 45 | Ytemp=2; 46 | else if(mLY_ValNX_NIGHT_THRESHOLDS) //向右搬动了 86 | Xtemp=6; 87 | else if(mNX_ValNX_DOWN_THRESHOLDS)//向下搬动了 98 | Ytemp=8; 99 | else 100 | Ytemp=5; 101 | 102 | //综合返回 103 | if(Xtemp==4 && Ytemp==2) //左上 104 | return 1; 105 | if(Xtemp==5 && Ytemp==2) //上 106 | return 2; 107 | if(Xtemp==6 && Ytemp==2) //右上 108 | return 3; 109 | if(Xtemp==4 && Ytemp==5) //左 110 | return 4; 111 | if(Xtemp==5 && Ytemp==5) //中 112 | return 5; 113 | if(Xtemp==6 && Ytemp==5) //右 114 | return 6; 115 | if(Xtemp==4 && Ytemp==8) //左下 116 | return 7; 117 | if(Xtemp==5 && Ytemp==8) //下 118 | return 8; 119 | if(Xtemp==6 && Ytemp==8) //右下 120 | return 9; 121 | 122 | return 0;//错误退出 123 | } 124 | -------------------------------------------------------------------------------- /lib/offchip/Joystick/Joystick.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYSTICK_H 2 | #define _JOYSTICK_H 3 | 4 | #include "stm32f10x.h" 5 | #include "ADC.h" 6 | 7 | 8 | 9 | 10 | //左摇杆X 在小于2的时候判定为向右搬动了,在大于3的时候判定为左搬动 11 | //左摇杆Y 在大于1的时候判定为向上搬动了, 在小于0.5的时候判定为向下搬动了 12 | 13 | //右摇杆X 在小于0.7的时候判定为向左搬动了,在大于1的时候判定为向右搬动了 14 | //右摇杆Y 在小于2的时候判定为向上搬动了,在大于3的时候判定为向下搬动了 15 | #define LX_NIGHT_THRESHOLDS 2 16 | #define LX_LEFT_THRESHOLDS 3 17 | #define LX_UP_THRESHOLDS 1 18 | #define LX_DOWN_THRESHOLDS 0.5 19 | 20 | 21 | #define NX_NIGHT_THRESHOLDS 1 22 | #define NX_LEFT_THRESHOLDS 0.7 23 | #define NX_UP_THRESHOLDS 2 24 | #define NX_DOWN_THRESHOLDS 3 25 | 26 | 27 | class Joystick{ 28 | 29 | private: 30 | ADC &mAdc; 31 | u8 mCH_LX,mCH_LY,mCH_NX,mCH_NY; 32 | float mLX_Val; 33 | float mLY_Val; 34 | float mNX_Val; 35 | float mNY_Val; 36 | 37 | public: 38 | Joystick(ADC &adc,u8 LX,u8 LY,u8 NX,u8 NY); 39 | bool Updata(); 40 | u8 getLeftState(); //左上向右数的九宫格 41 | u8 getNightState(); 42 | 43 | }; 44 | 45 | 46 | #endif 47 | 48 | 49 | //X1(5): 中间值:2.56 最小:(右移)0.008 最大(左移) 3.299 50 | //Y1(6): 0.87 (下移)0.005 (上移) 2.98 51 | //X2(8): 0.83 (左移)0.002 (右移) 2.89 52 | //Y2(9): 2.27 (上移)0.010 (下移) 3.299 53 | 54 | //左摇杆X 在小于2的时候判定为向右搬动了,在大于3的时候判定为左搬动 55 | //左摇杆Y 在大于1的时候判定为向上搬动了, 在小于0.5的时候判定为向下搬动了 56 | 57 | //右摇杆X 在小于0.7的时候判定为向左搬动了,在大于1的时候判定为向右搬动了 58 | //右摇杆Y 在小于2的时候判定为向上搬动了,在大于3的时候判定为向下搬动了 59 | 60 | -------------------------------------------------------------------------------- /lib/offchip/LED/LED.cpp: -------------------------------------------------------------------------------- 1 | #include "LED.h" 2 | 3 | 4 | ///构造函数 5 | ///@param gpio GPIO类对象,分配片上资源 6 | ///@param highLevelOn 是否输出高电平时为LED打开 7 | ///////////////////////// 8 | LED::LED(GPIO &gpio,bool highLevelOn) 9 | :mGPIO(gpio),times(0),time_old(0) 10 | { 11 | if(highLevelOn) 12 | mLevelOn=1; 13 | else 14 | mLevelOn=0; 15 | Off(); 16 | } 17 | 18 | 19 | //////////////////////// 20 | ///翻转(开-->关 , 关-->开) 21 | /////////////////////// 22 | void LED::Toggle() 23 | { 24 | if(mGPIO.GetLevel()) 25 | mGPIO.SetLevel(0); 26 | else 27 | mGPIO.SetLevel(1); 28 | } 29 | 30 | ////////////////////// 31 | ///打开LED 32 | ///////////////////// 33 | void LED::On() 34 | { 35 | mGPIO.SetLevel(mLevelOn); 36 | } 37 | 38 | ///////////////////// 39 | ///关闭LED 40 | //////////////////// 41 | void LED::Off() 42 | { 43 | mGPIO.SetLevel(mLevelOn^1); 44 | } 45 | 46 | //////////////////////// 47 | ///闪烁n次 48 | ///@param time 闪烁次数 49 | ///@param Interval 闪烁间隔 (ms) 50 | ///@param wait 是否等待闪烁完毕后再结束函数 51 | /////////////////////// 52 | void LED::Blink(uint16_t time,float interval,bool wait) 53 | { 54 | if(wait){ 55 | for(uint8_t i=0;i=time) 63 | { 64 | times = 0; 65 | return; 66 | } 67 | if(TaskManager::Time() - time_old > interval/1000.0) 68 | { 69 | time_old = TaskManager::Time(); 70 | ++times; 71 | Toggle(); 72 | } 73 | } 74 | //////////////////////// 75 | ///两个灯一起闪烁n次 76 | ///@param 另一个灯的引用 77 | ///@param time 闪烁次数 78 | ///@param Interval 闪烁间隔(ms) 79 | /////////////////////// 80 | void LED::Blink2(LED &led,uint8_t time,uint16_t interval) 81 | { 82 | for(uint8_t i=0;i关 , 关-->开) 19 | /////////////////////// 20 | void Toggle(); 21 | 22 | ////////////////////// 23 | ///打开LED 24 | ///////////////////// 25 | void On(); 26 | 27 | ///////////////////// 28 | ///关闭LED 29 | //////////////////// 30 | void Off(); 31 | 32 | //////////////////////// 33 | ///闪烁n次 34 | ///@param time 闪烁次数,若为0,则为无线闪烁(只适用于非等待方式) 35 | ///@param Interval 闪烁间隔(ms) 36 | ///@param wait 是否等待闪烁完毕后再结束函数 37 | /////////////////////// 38 | void Blink(uint16_t time,float interval,bool wait); 39 | 40 | 41 | //////////////////////// 42 | ///两个灯一起闪烁n次,闪烁完后结束 43 | ///@param 另一个灯的引用 44 | ///@param time 闪烁次数 45 | ///@param Interval 闪烁间隔(ms) 46 | /////////////////////// 47 | void Blink2(LED &led,uint8_t time,uint16_t interval); 48 | 49 | 50 | //////////////////////// 51 | ///两个灯交替闪烁n次,闪烁完后结束 52 | ///@param 另一个灯的引用 53 | ///@param time 闪烁次数 54 | ///@param Interval 闪烁间隔(ms) 55 | /////////////////////// 56 | void Blink3(LED &led,uint8_t time,uint16_t interval); 57 | 58 | 59 | private: 60 | ////////////////////////// 61 | ///GPIO的类的实例对象引用 62 | ////////////////////////// 63 | GPIO & mGPIO; 64 | //////////////////////// 65 | ///标志开启LED时取的电平高低 66 | //////////////////////// 67 | unsigned char mLevelOn; 68 | 69 | uint16_t times; 70 | double time_old; 71 | 72 | 73 | 74 | }; 75 | 76 | 77 | #endif 78 | 79 | 80 | -------------------------------------------------------------------------------- /lib/offchip/MG996R/readme.md: -------------------------------------------------------------------------------- 1 | # 介绍 2 | MG996R 是一款 55G[舵机](https://www.google.com/search?source=hp&ei=eYCeWrP7Kqu1ggey1a-IAQ&q=%E8%88%B5%E6%9C%BA&oq=%E8%88%B5%E6%9C%BA&gs_l=psy-ab.3..0l5j0i203k1j0l4.1970.2877.0.3068.8.7.0.0.0.0.488.488.4-1.2.0....0...1c.4.64.psy-ab..6.2.760.6..35i39k1.274.2dwrP4egcIc) 3 | 这个lib有以下作用 4 | 1. 操控舵机,使之旋转确定角度 5 | 2. 多个舵机组合在一起之后能完成一些基本动作 6 | 3. 用按键操控 7 | --- 8 | _创建这个lib的初衷就是为了好玩儿_ 9 | -------------------------------------------------------------------------------- /lib/offchip/MHZ14/MHZ14.cpp: -------------------------------------------------------------------------------- 1 | #include "MHZ14.h" 2 | 3 | MHZ14::MHZ14(USART &com) 4 | :COM(com) 5 | { 6 | //一帧数据读取指令 7 | Command_getvalue[0]=0xff; 8 | Command_getvalue[1]=0x01; 9 | Command_getvalue[2]=0x86; 10 | Command_getvalue[3]=0; 11 | Command_getvalue[4]=0; 12 | Command_getvalue[5]=0; 13 | Command_getvalue[6]=0; 14 | Command_getvalue[7]=0; 15 | Command_getvalue[8]=0x79; 16 | 17 | DATA_H=0; 18 | DATA_L=0; 19 | } 20 | 21 | 22 | bool MHZ14::SumCheck(u8 data[9]) 23 | { 24 | u8 sum=0,check=0; 25 | for(u8 i=1;i<8;i++) 26 | { 27 | sum+=data[i]; 28 | } 29 | check=0xff-sum+0x01; 30 | if(data[8]==check) 31 | return true ; 32 | else 33 | return false; 34 | } 35 | 36 | u16 MHZ14::GetValue() 37 | { 38 | return CO2_Concentration; 39 | } 40 | 41 | 42 | bool MHZ14::Updata() 43 | { 44 | //向模块发送获取数据 45 | COM.SendData(Command_getvalue,9); 46 | 47 | //判断是否有数据返回 48 | if(COM.ReceiveBufferSize()<9) 49 | { 50 | COM.ClearReceiveBuffer(); //清空接收缓存 51 | return false; 52 | } 53 | else 54 | { 55 | COM.GetReceivedData(rev_buffer,9); //取出一帧数据 56 | COM.ClearReceiveBuffer(); //清空接收缓存 57 | 58 | if(SumCheck(rev_buffer)==false) //校验和 59 | return false; 60 | else 61 | { 62 | DATA_H=rev_buffer[2]; 63 | DATA_L=rev_buffer[3]; 64 | CO2_Concentration=rev_buffer[2]*256+rev_buffer[3]; //计算浓度 65 | return true; 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /lib/offchip/MHZ14/MHZ14.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | */ 4 | 5 | 6 | 7 | #include "USART.h" 8 | #include "TaskManager.h" 9 | 10 | class MHZ14 { 11 | 12 | private: 13 | USART &COM; 14 | u8 Command_getvalue[9]; //发送命令 15 | u8 rev_buffer[9]; 16 | u16 CO2_Concentration; 17 | bool SumCheck(u8 data[9]); 18 | public: 19 | u8 DATA_H; 20 | u8 DATA_L; 21 | MHZ14(USART &com); 22 | bool Updata();//更新数据,返回是否更新成功 true false 23 | u16 GetValue(); //得到一个浓度数据 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /lib/offchip/MPU6050/InertialSensor.h: -------------------------------------------------------------------------------- 1 | #ifndef _INERTIAL_SENSOR_H_ 2 | #define _INERTIAL_SENSOR_H_ 3 | #include "Sensor.h" 4 | #include "Vector3.h" 5 | 6 | class InertialSensor 7 | { 8 | public: 9 | 10 | ////////////////////////// 11 | ///IMU初始化函数 12 | ///@param wait if wait until the command in queue execute complete 13 | ///@retval -1:检测到硬件 -2:检测到部分硬件 -3:正在检测 -0:未检测到硬件 14 | ////////////////////////// 15 | virtual u8 Init(bool wait=false) =0 ;//初始化IMU 16 | 17 | 18 | //////////////////////////////// 19 | ///获取加速度原始值 20 | ///@retval 返回三轴的加速度值 21 | /////////////////////////////// 22 | virtual Vector3 GetAccRaw() =0 ;//获取加速度原始值 23 | 24 | 25 | //////////////////////////////// 26 | ///获取角速度原始值 27 | ///@retval 返回三轴的角速度值 28 | /////////////////////////////// 29 | virtual Vector3 GetGyrRaw() =0 ;//获取角速度原始值 30 | 31 | //////////////////////////////// 32 | ///获取角速度值 33 | ///@retval 返回三轴的角速度值 单位:rad/s 34 | /////////////////////////////// 35 | virtual Vector3f GetGyr() =0 ;//获取角速度值 36 | 37 | //////////////////////////////// 38 | ///获取加速度值 39 | ///@retval 返回三轴的加速度值 单位:g 40 | /////////////////////////////// 41 | virtual Vector3f GetAcc() =0 ;//获取加速度值 42 | 43 | /////////////////////////// 44 | ///角速度校准值 45 | ////////////////////////// 46 | virtual Vector3 GetGyrOffset() =0 ; 47 | 48 | ///////////////////////////// 49 | ///角速度校准是否完毕 50 | ////////////////////////////// 51 | virtual bool IsGyroCalibrated() =0 ; 52 | 53 | ////////////////////////////// 54 | ///从硬件更新加速度、角速度值到内存 55 | ///@param wait if wait until the command in queue execute complete 56 | ///@param acc The address of raw accelerator data save to 57 | ///@param gyro The address of raw gyro data save to 58 | ///@return if wait set to true,MOD_READY:update succed MOD_ERROR:update fail MOD_BUSY:Update interval is too short 59 | /// if wait set to false,MOD_ERROR:发送更新数据失败 MOD_READY:命令将会发送(具体的发送时间取决于队列中的排队的命令的数量)MOD_BUSY:Update interval is too short 60 | ////////////////////////////// 61 | virtual u8 Update(bool wait=false,Vector3 *acc=0, Vector3 *gyro=0) =0 ; 62 | 63 | //////////////////////// 64 | ///开始角速度校准 65 | ///@attention 校准时不要移动传感器 66 | ///////////////////////// 67 | virtual void StartGyroCalibrate() =0 ; 68 | 69 | //////////////////////// 70 | ///停止角速度校准 71 | ///@attention 校准时不要移动传感器 72 | ///////////////////////// 73 | virtual void StopGyroCalibrate() =0 ; 74 | 75 | 76 | //////////////////// 77 | ///是否正在校准角速度 78 | /////////////////////// 79 | virtual bool IsGyroCalibrating() =0 ; 80 | 81 | ////////////////////////////////////// 82 | ///获得两次数据采集的间隔 83 | ////////////////////////////////////// 84 | virtual double GetUpdateInterval() =0 ; 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /lib/offchip/PN53x/PN53x.h: -------------------------------------------------------------------------------- 1 | /** 2 | *@file PN53x.h 3 | *@author Neucrack 4 | *@version v0.1 5 | *@brief RFID reader PN53x driver 6 | *@date create:2017.5.29 7 | * update:2017.5.29 8 | * 9 | */ 10 | 11 | 12 | #include "USART.h" 13 | //extern USART LOG; 14 | 15 | #define MAX_WAIT_TIME_OUT 0.8 //s 16 | 17 | class PN53x{ 18 | 19 | private: 20 | USART& mUsart; 21 | 22 | public: 23 | PN53x(USART& com); 24 | bool PcdWakeUp(); 25 | bool PcdListPassiveTarget(uint16_t* type, uint8_t* uid,uint8_t* sak=0,uint8_t* ats=0); 26 | bool PcdVerifyKeyA(uint8_t* uid,uint8_t* key); 27 | bool PcdRead(uint8_t* dataRead,uint8_t blockNumber = 2); 28 | bool PcdWrite(uint8_t* dataWrite,uint8_t blockNumber = 2); 29 | }; 30 | -------------------------------------------------------------------------------- /lib/offchip/Relay/Relay.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "Relay.h" 4 | #include "Assert.h" 5 | 6 | 7 | Relay::Relay(bool highLevelOn) 8 | { 9 | mHighLevelOn = highLevelOn; 10 | } 11 | 12 | bool Relay::Init(GPIO* gpio) 13 | { 14 | mGPIO = gpio; 15 | assert(mGPIO != NULL); 16 | return true; 17 | } 18 | 19 | bool Relay::IsOn() 20 | { 21 | assert(mGPIO != NULL); 22 | uint8_t status; 23 | status = mGPIO->GetLevel(); 24 | if(mHighLevelOn) 25 | return status; 26 | else 27 | return status?0:1; 28 | } 29 | 30 | 31 | void Relay::Set(bool isOn) 32 | { 33 | assert(mGPIO != NULL); 34 | uint8_t out; 35 | if(mHighLevelOn) 36 | out = isOn?1:0; 37 | else 38 | out = isOn?0:1; 39 | mGPIO->SetLevel(out); 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /lib/offchip/Relay/Relay.h: -------------------------------------------------------------------------------- 1 | #ifndef __RELAY_H 2 | #define __RELAY_H 3 | 4 | #include "GPIO.h" 5 | #include "stdint.h" 6 | #include "stdbool.h" 7 | #include "stdio.h" 8 | 9 | class Relay{ 10 | 11 | public: 12 | Relay(bool HighLevelOn = true); 13 | bool Init(GPIO* gpio); 14 | bool IsOn(); 15 | void Set(bool isOn); 16 | 17 | private: 18 | bool mHighLevelOn; 19 | GPIO* mGPIO; 20 | }; 21 | 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /lib/offchip/SHARP_1014_PM2_5/SHARP_1014_PM2_5.cpp: -------------------------------------------------------------------------------- 1 | #include "SHARP_1014_PM2_5.h" 2 | 3 | /*---------------------------TEST----------------------------------*/ 4 | sharp_1014_pm2_5::sharp_1014_pm2_5(GPIO &LED):mLed(LED) 5 | { 6 | OriginalVol=0; 7 | AdcOriginalVol=0; 8 | ADC_init(); 9 | 10 | } 11 | 12 | float sharp_1014_pm2_5::testGetVol() 13 | { 14 | //延时测试方案: 管脚拉低,延时280us,读取AD,延时40us,拉高管脚,再延时9680 us。 15 | mLed.SetLevel(0); 16 | tskmgr.DelayUs(280); 17 | tskmgr.DelayUs(40); 18 | mLed.SetLevel(1); 19 | tskmgr.DelayUs(9680); 20 | 21 | return OriginalVol; 22 | } 23 | 24 | 25 | 26 | //sharp_1014_pm2_5::sharp_1014_pm2_5(PWM &Led,ADC &Adc,u8 AdcCh):mLED(Led),mAdc(Adc) 27 | //{ 28 | // OriginalVol=0; 29 | // AdcChannel = AdcCh; 30 | //} 31 | 32 | 33 | bool sharp_1014_pm2_5::updata()//数据更新,最快更新时间:10ms一次 34 | { 35 | mLed.SetLevel(0); 36 | tskmgr.DelayUs(280); 37 | AdcOriginalVol = Get_ADC(); 38 | tskmgr.DelayUs(40); 39 | mLed.SetLevel(1); 40 | tskmgr.DelayUs(9680); 41 | return true; 42 | } 43 | 44 | float sharp_1014_pm2_5::getOriginalVol(float NearVccR,float OtherR)//读取原始电压值,该值根据分压电阻决定 45 | { 46 | 47 | OriginalVol= (float)AdcOriginalVol*0.0008056640625; //将原始值转化为电压 48 | OriginalVol=OriginalVol*(NearVccR/OtherR+1);//由于使用了8.61:14.84的电阻分压,所以要转化为原始电压 49 | return OriginalVol; 50 | } 51 | 52 | 53 | float sharp_1014_pm2_5::InVolOutDensity(float Vol) 54 | { 55 | float a = 0.17; 56 | float b = -0.1; 57 | //由图得出一个一元二次方程 58 | return (a*Vol+b); 59 | 60 | } 61 | 62 | bool sharp_1014_pm2_5::ADC_init() 63 | { 64 | //时钟初始化 65 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1,ENABLE); 66 | RCC_ADCCLKConfig(RCC_PCLK2_Div6); 67 | 68 | //管脚初始化 69 | GPIO_InitTypeDef GPIO_InitStructure; 70 | GPIO_InitStructure.GPIO_Pin = ADC_PIN; 71 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; 72 | GPIO_Init(ADC_GPIO,&GPIO_InitStructure); 73 | //ADC初始化 74 | ADC_DeInit(ADC1); 75 | ADC_InitTypeDef ADC_init; 76 | ADC_init.ADC_Mode = ADC_Mode_Independent; //独立工作模式 77 | ADC_init.ADC_ScanConvMode = DISABLE; //单通道模式 78 | ADC_init.ADC_ContinuousConvMode = DISABLE; //单次转换模式 79 | ADC_init.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None ;//软件触发 80 | ADC_init.ADC_DataAlign = ADC_DataAlign_Right; //右对齐 81 | ADC_init.ADC_NbrOfChannel = 1;//1个通道 82 | ADC_Init(ADC1,&ADC_init); 83 | //设置ADC的一些通道规则 84 | ADC_Cmd(ADC1,ENABLE); 85 | 86 | // 87 | ADC_ResetCalibration(ADC1); 88 | while(ADC_GetResetCalibrationStatus(ADC1)); 89 | ADC_StartCalibration(ADC1); 90 | while(ADC_GetCalibrationStatus(ADC1)); 91 | return true; 92 | 93 | } 94 | 95 | uint16_t sharp_1014_pm2_5::Get_ADC() 96 | { 97 | ADC_RegularChannelConfig(ADC1,ADC_Channel_2,1,ADC_SampleTime_55Cycles5); 98 | ADC_SoftwareStartConvCmd(ADC1,ENABLE);//启动转换等待转换完成 99 | while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)); 100 | return (uint16_t)ADC_GetConversionValue(ADC1); 101 | } 102 | 103 | -------------------------------------------------------------------------------- /lib/offchip/SHARP_1014_PM2_5/SHARP_1014_PM2_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | 夏普GP2Y1014 6823 PM2.5粉尘传感器,驱动方式主要用一路PWM(周期10ms,启动时间0.32ms)来控制LED灯 3 | 然后才能从AD角读出电压值。 4 | 有传感器结构图可以看出控制LED的是一个PNP三极管,所以当电平为低的时候导通,开启。 5 | 原定计划是用PWM,然后再中断时间中启动ADC读取,但先使用延时的方式测试传感器 6 | 7 | */ 8 | 9 | 10 | 11 | #ifndef _SHARP_1014_PM2_5_H 12 | #define _SHARP_1014_PM2_5_H 13 | 14 | #include "stm32f10x.h" 15 | #include "GPIO.h" 16 | #include "TaskManager.h" 17 | 18 | //暂时先用宏定义 19 | #define ADC_PIN GPIO_Pin_2 20 | #define ADC_GPIO GPIOA 21 | #define ADC_CHANNEL ADC_Channel_2 22 | 23 | class sharp_1014_pm2_5{ 24 | private: 25 | 26 | uint16_t AdcOriginalVol;//保存ADC寄存器的原始值 27 | float OriginalVol;//保存计算出的电压值 28 | GPIO &mLed; 29 | 30 | bool ADC_init(); 31 | uint16_t Get_ADC(); 32 | float InVolOutDensity(float Vol); 33 | 34 | public: 35 | sharp_1014_pm2_5(GPIO &LED); 36 | float testGetVol(); 37 | bool updata();//数据更新,最快更新时间:10ms一次 38 | float getOriginalVol(float NearVccR,float OtherR);//读取原始电压值,该值根据分压电阻决定 39 | 40 | }; 41 | 42 | 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /lib/offchip/SHARP_1051_PM2_5/SHARP_PM2_5.cpp: -------------------------------------------------------------------------------- 1 | #include "SHARP_PM2_5.h" 2 | 3 | 4 | Sharp_PM_2_5::Sharp_PM_2_5(USART &com):mCom(com) 5 | {} 6 | 7 | bool Sharp_PM_2_5::Update() 8 | { 9 | //u8 buffer[70]; //buffer 最大70 10 | u8 data[5]; 11 | float temp; 12 | u8 ch; 13 | int num=mCom.ReceiveBufferSize(); 14 | if(num > 7) 15 | { 16 | mCom.GetReceivedData(&ch,1); 17 | if(ch!=0xaa) 18 | return false; 19 | else 20 | mCom.GetReceivedData(data,5); 21 | if(Check(data,4,data[4]))//校验 22 | { 23 | temp=(float)(data[0]*256+data[1])/1024*5; 24 | UD=temp * COEFFICIENT_A; 25 | mCom.ClearReceiveBuffer(); 26 | return true; 27 | } 28 | else 29 | return false; 30 | } 31 | else 32 | return false; 33 | } 34 | 35 | float Sharp_PM_2_5::GetConcentration() 36 | { 37 | return UD; 38 | } 39 | 40 | bool Sharp_PM_2_5::Check(u8 *Data,int Lenth,u8 CheckSum) 41 | { 42 | u8 temp =0; 43 | for(int i=0;iInit(); 32 | } 33 | 34 | 35 | 36 | float Si7021::GetTemperature() 37 | { 38 | assert(mI2C != NULL); 39 | return mTemperature; 40 | } 41 | 42 | int8_t Si7021::GetChipID() 43 | { 44 | //read chip id 45 | // compound commands 46 | // uint8_t SI7021_SERIAL1_READ[2] ={ 0xFA, 0x0F }; 47 | uint8_t SI7021_SERIAL2_READ[2] ={ 0xFC, 0xC9 }; 48 | uint8_t temp[6]; 49 | if(!mI2C->AddCommandRead(SI7021_ADDR,SI7021_SERIAL2_READ,2,temp,6)) 50 | return -1; 51 | uint8_t ret = mI2C->StartCMDQueue(); 52 | if(ret != 1) 53 | return -2; 54 | if(!mI2C->WaitTransmitComplete(true,true,false)) 55 | return -3; 56 | return temp[0]; 57 | } 58 | 59 | bool Si7021::Kick() 60 | { 61 | int8_t id = GetChipID(); 62 | if(id != SI7021_CHIP_ID_SI7021) 63 | return false; 64 | return true; 65 | } 66 | 67 | 68 | float Si7021::GetHumidity() 69 | { 70 | assert(mI2C != NULL); 71 | return mHumidity; 72 | } 73 | 74 | 75 | int Si7021::Update() 76 | { 77 | assert(mI2C != NULL); 78 | 79 | uint8_t cmd = SI7021_TEMP_READ; 80 | uint8_t temp[2]; 81 | uint16_t tempInteger; 82 | uint8_t ret ; 83 | 84 | //read temperature 85 | if(!mI2C->AddCommandRead(SI7021_ADDR,&cmd,1,temp,2)) 86 | return -1; 87 | ret = mI2C->StartCMDQueue(); 88 | if(ret != 1) 89 | return -2; 90 | if(!mI2C->WaitTransmitComplete(true,true,false)) 91 | return -3; 92 | tempInteger = (uint16_t)temp[0] << 8 | temp[1]; 93 | mTemperature = (((17572 * tempInteger) >> 16) - 4685)/100.0; 94 | 95 | //read humidity 96 | cmd = SI7021_RH_READ; 97 | if(!mI2C->AddCommandRead(SI7021_ADDR,&cmd,1,temp,2)) 98 | return -1; 99 | ret = mI2C->StartCMDQueue(); 100 | if(ret != 1) 101 | return -2; 102 | if(!mI2C->WaitTransmitComplete(true,true,false)) 103 | return -3; 104 | tempInteger = (uint16_t)temp[0] << 8 | temp[1]; 105 | mHumidity = ((125* tempInteger) >> 16) - 6; 106 | 107 | return 0; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /lib/offchip/Si7021/Si7021.h: -------------------------------------------------------------------------------- 1 | #ifndef __SI7021_H 2 | #define __SI7021_H 3 | 4 | #include "Temperature.h" 5 | #include "I2C.h" 6 | #include "Humidity.h" 7 | 8 | 9 | #define SI7021_CHIP_ID_SI7013 0x0D 10 | #define SI7021_CHIP_ID_SI7020 0x14 11 | #define SI7021_CHIP_ID_SI7021 0x15 12 | 13 | class Si7021 :public Temperature,public Humidity{ 14 | 15 | public: 16 | Si7021(); 17 | bool Init(I2C* i2c); 18 | virtual float GetTemperature(); 19 | virtual float GetHumidity(); 20 | virtual int Update(); 21 | int8_t GetChipID(); 22 | bool Kick(); 23 | 24 | private: 25 | I2C* mI2C; 26 | float mTemperature; 27 | float mHumidity; 28 | }; 29 | 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /lib/offchip/Temperature/Temperature.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEMPERATURE_H 2 | #define __TEMPERATURE_H 3 | 4 | #include "stdbool.h" 5 | #include "stdint.h" 6 | 7 | class Temperature{ 8 | 9 | public: 10 | virtual float GetTemperature() = 0; 11 | virtual int Update() = 0; 12 | }; 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/offchip/ZPH01/Senser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __SENSER_H 3 | #define __SENSER_H 4 | 5 | class Senser{ 6 | public: 7 | Senser(){}; 8 | virtual bool Updata()=0; 9 | // virtual unsigned short int GetU16Data()=0; 10 | virtual float GetFloatData()=0; 11 | virtual unsigned char Data_Hight_8() =0; 12 | virtual unsigned char Data_Low_8() =0; 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/offchip/ZPH01/ZPH01.cpp: -------------------------------------------------------------------------------- 1 | #include "ZPH01.h" 2 | 3 | ZPH01::ZPH01(USART &usart):mUsart(usart) 4 | { 5 | 6 | } 7 | 8 | ZPH01::~ZPH01() 9 | { 10 | } 11 | 12 | 13 | bool ZPH01::Updata() 14 | { 15 | int num=mUsart.ReceiveBufferSize(); 16 | if(num%9!=0 || num>=90 ||num<9) 17 | { 18 | mUsart.ClearReceiveBuffer(); 19 | return false; 20 | } 21 | else 22 | { 23 | for(int i=0;i 17 | #include "USART.h" 18 | #include "Senser.h" 19 | 20 | class ZPH01:Senser 21 | { 22 | private: 23 | 24 | USART& mUsart; 25 | 26 | unsigned char mData[9]; //一帧数据大小 27 | 28 | float Concentration;//保存浓度值 29 | 30 | unsigned char FucCheckSum(unsigned char *i,unsigned char ln);//校验 31 | public: 32 | 33 | ZPH01(USART &usart); 34 | 35 | ~ZPH01(); 36 | 37 | u8 data_h;//保存浓度半分比的整数部分 38 | u8 data_l;//保存小数部分 39 | 40 | virtual bool Updata(); //更新 41 | virtual float GetFloatData(); //返回浓度值 单位ug/m3 42 | virtual unsigned char Data_Hight_8(); 43 | virtual unsigned char Data_Low_8(); 44 | 45 | }; 46 | 47 | 48 | #endif 49 | 50 | 51 | -------------------------------------------------------------------------------- /lib/offchip/esp8266/README.md: -------------------------------------------------------------------------------- 1 | esp8266 stm32 驱动封装 2 | ==== 3 | 4 | # 简介 5 | 使用stm32驱动使用AT指令驱动的esp8266模块 6 | 并封装了socket类,让使用更加简单 7 | 8 | # 环境 9 | C、C++、基于[stm32外设库](https://github.com/Neutree/STM32f103DriverLib) 10 | 11 | # 使用 12 | * 将文件夹内的5个文件复制并引入工程 13 | * 引入头文件、定义变量、资源装配、wifi初始化设置、wifi使用(socket接口(socket.h中)) 14 | * 代码 [(例程)](../../../example/offchip/esp8266/stm32f103c8t6) 15 | ```cpp 16 | #include "USART.h" 17 | #include "TaskManager.h" 18 | #include "Socket_esp8266.h" 19 | 20 | USART com(1,115200,false); 21 | Socket_esp8266 wifi(com); 22 | 23 | /*******************configuration****************/ 24 | char* mApJoinName ="lalala"; 25 | char* mApJoinPasswd="dd199511"; 26 | char* mServerIP = "192.168.1.104"; 27 | uint16_t mServerPort = 8989; 28 | /***********************************************/ 29 | 30 | char dataToSend[10]={1,2,3,4,5,6,7,8,9,10}; 31 | 32 | bool WiFiInit(void); 33 | 34 | int main() 35 | { 36 | TaskManager::DelayS(3); 37 | if(!WiFiInit()) 38 | { 39 | while(1); 40 | } 41 | wifi.Write(dataToSend,10); 42 | while(1); 43 | } 44 | 45 | bool WiFiInit() 46 | { 47 | wifi.Init();//初始化时一定要清除串口缓冲区,因为WiFi上电后回显很多调试信息,可能会造成串口缓冲区溢出,上电大于2秒后调用 48 | if(!wifi.Kick()) 49 | return false; 50 | wifi.SetEcho(false);//关闭回响 51 | wifi.SetMode(esp8266::esp8266_MODE_STATION,esp8266::esp8266_PATTERN_DEF);//设置为station模式 52 | wifi.SetMUX(false);//单连接模式 53 | wifi.JoinAP(mApJoinName,mApJoinPasswd,esp8266::esp8266_PATTERN_DEF);//加入AP 54 | TaskManager::DelayS(2); 55 | //连接服务器 56 | if(!wifi.Connect(mServerIP,mServerPort,Socket_Type_Stream,Socket_Protocol_IPV4)) 57 | return false; 58 | return true; 59 | } 60 | 61 | ``` -------------------------------------------------------------------------------- /lib/offchip/esp8266/Socket_esp8266.cpp: -------------------------------------------------------------------------------- 1 | #include "Socket_esp8266.h" 2 | 3 | Socket_esp8266::Socket_esp8266(USART& usart) 4 | :esp8266(usart),mUsart(usart),mIsConnected(false) 5 | { 6 | mTimeOut = 3; 7 | 8 | } 9 | bool Socket_esp8266::Init() 10 | { 11 | mUsart.ClearReceiveBuffer();//wifi上电后会有一串调试信息,为了避免缓冲区溢出,所以需要在wifi模块上电后几秒钟后清除缓冲区 12 | //建议上电大于2秒后调用 13 | return true; 14 | } 15 | bool Socket_esp8266::Connect(char* ipAddr,short port,Socket_Type socketType,Socket_Protocol socketProtocol) 16 | { 17 | if(CreateConnectMutipleMode(ipAddr,port,socketType)) 18 | mIsConnected = true; 19 | else 20 | mIsConnected = false; 21 | return mIsConnected; 22 | } 23 | bool Socket_esp8266::Write(char* data,unsigned int num) 24 | { 25 | return SendMultipleMode(data,num); 26 | } 27 | unsigned int Socket_esp8266::Read(char* data) 28 | { 29 | float starttime = TaskManager::Time(); 30 | if(!mIsConnected) 31 | return 0; 32 | unsigned char temp[13]; 33 | unsigned short bufferSize=0; 34 | unsigned short dataLength=0; 35 | short count=0; 36 | uint8_t headFlag=0; 37 | //读出数据长度 38 | while(TaskManager::Time()-starttime0) 41 | { 42 | mUsart.GetReceivedData(temp,1); 43 | if(temp[0] == '+') 44 | headFlag = 1; 45 | else if(temp[0] == 'I' && headFlag == 1) 46 | headFlag = 2; 47 | else if(temp[0] == 'P' && headFlag == 2) 48 | headFlag = 3; 49 | else if(temp[0] == 'D' && headFlag == 3) 50 | headFlag = 4; 51 | else if(temp[0] == ',' && headFlag == 4) 52 | { 53 | if(mIsEnableMUX) 54 | mUsart.GetReceivedData(temp,2); 55 | headFlag = 5; 56 | } 57 | else if(headFlag == 5) 58 | { 59 | if(temp[0] == ':') 60 | { 61 | break; 62 | } 63 | else 64 | dataLength = dataLength*10+(temp[0]-'0'); 65 | } 66 | } 67 | } 68 | count=0; 69 | //读取数据 70 | while(TaskManager::Time()-starttime0) 72 | { 73 | mUsart.GetReceivedData((unsigned char*)(data+count),1); 74 | ++count; 75 | if(count==dataLength || count==ESP8266_RECEIVE_BUFFER_SIZE) 76 | break; 77 | } 78 | } 79 | return count; 80 | } 81 | unsigned int Socket_esp8266::Read(char* data,unsigned int num) 82 | { 83 | float starttime = TaskManager::Time(); 84 | if(!mIsConnected) 85 | return 0; 86 | unsigned int count=0; 87 | while(TaskManager::Time()-starttime0) 89 | { 90 | mUsart.GetReceivedData((unsigned char*)(data+count),1); 91 | ++count; 92 | } 93 | } 94 | return count; 95 | } 96 | bool Socket_esp8266::IsAlive() 97 | { 98 | if(!mIsConnected) 99 | return false; 100 | if(GetStatus()==3) 101 | return true; 102 | return false; 103 | } 104 | bool Socket_esp8266::Close() 105 | { 106 | if(mIsConnected) 107 | { 108 | esp8266::Close(); 109 | } 110 | return true; 111 | } 112 | 113 | void Socket_esp8266::SetTimeOut(float timetOut) 114 | { 115 | mTimeOut = timetOut; 116 | } 117 | 118 | bool Socket_esp8266::SetMUX(bool isEnableMUX) 119 | { 120 | mIsEnableMUX = isEnableMUX; 121 | return esp8266::SetMUX(isEnableMUX); 122 | } 123 | 124 | -------------------------------------------------------------------------------- /lib/offchip/esp8266/Socket_esp8266.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOCKET_ESP8266_H 2 | #define __SOCKET_ESP8266_H 3 | #include "socket.h" 4 | #include "esp8266.h" 5 | #include "string.h" 6 | #include "stdlib.h" 7 | #include "USART.h" 8 | 9 | class Socket_esp8266 :public esp8266,public Socket 10 | { 11 | public: 12 | Socket_esp8266(USART& usart); 13 | virtual bool Init(); 14 | virtual bool Connect(char* ipAddr,short port,Socket_Type socketType,Socket_Protocol socketProtocol=Socket_Protocol_IPV4); 15 | virtual bool Write(char* data,unsigned int num); 16 | virtual unsigned int Read(char* data); 17 | virtual unsigned int Read(char* data,unsigned int num); 18 | virtual bool IsAlive(); 19 | virtual bool Close(); 20 | virtual void SetTimeOut(float timetOut); 21 | 22 | bool SetMUX(bool isEnableMUX); 23 | private: 24 | USART& mUsart; 25 | float mTimeOut; 26 | bool mIsConnected; 27 | bool mIsEnableMUX; 28 | }; 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /lib/offchip/esp8266/esp8266.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESP8266_H 2 | #define __ESP8266_H 3 | 4 | 5 | /** 6 | *@file esp8266.h 7 | *@brief The definition of class esp8266 and related operation of esp8266 module 8 | *@author neucrack(neucrack.com) CQUT IOT lib 9 | *@date 2015-11 10 | *@copyright CQUT IOT lib all right reserved 11 | */ 12 | 13 | 14 | 15 | #include "USART.h" 16 | #include "string.h" 17 | #include "TaskManager.h" 18 | #include "socket.h" 19 | /*********************configuration****************************/ 20 | #define ESP8266_RECEIVE_BUFFER_SIZE 50 21 | #define ESP8266_DEFAULT_PATTERN esp8266_PATTERN_DEF 22 | #define ESP8266_DEFAULT_TIMEOUT 5 //单位:s 23 | 24 | /**************************************************************/ 25 | 26 | 27 | class esp8266 28 | { 29 | public: 30 | enum esp8266_pattern{esp8266_PATTERN_NULL=0,esp8266_PATTERN_CUR=1,esp8266_PATTERN_DEF=2}; 31 | enum esp8266_MODE{esp8266_MODE_STATION=1,esp8266_MODE_AP=2,esp8266_MODE_STATION_AP=3}; 32 | enum esp8266_ENCRYPTION{esp8266_ENCRYPTION_OPEN=0,esp8266_ENCRYPTION_WEP=1, 33 | esp8266_ENCRYPTION_WPA_PSK=2,esp8266_ENCRYPTION_WPA2_PSK=3,esp8266_ENCRYPTION_WPA_WPA2_PSK=4}; 34 | enum esp8266_ROLE{esp8266_ROLE_SERVER=1,esp8266_ROLE_CLIENT=2}; 35 | /** 36 | * Constuctor. 37 | * 38 | * @param uart - an reference of HardwareSerial object. 39 | * @param baudRate - the baud rate to communicate with ESP8266 when first power on (default:the same as usart's baud rate). 40 | * if the value is not the same as usart's baud rate, it will change usart's baud rate to the same as thid parameter's value 41 | * @warning parameter baud depends on the AT firmware. 9600 is an common value. 42 | */ 43 | esp8266(USART &usart, uint32_t baudRate = 0 ); 44 | 45 | bool Kick(void); 46 | bool Restart(void); 47 | bool GetVersion(char*); 48 | bool SetEcho(bool echo); 49 | bool Restore(void); 50 | bool SetUart(uint32_t baudrate,esp8266_pattern pattern); 51 | 52 | bool SetMode(esp8266_MODE,esp8266_pattern = esp8266_PATTERN_DEF);//设置为station+ap模式 53 | bool SetMUX(bool isEnableMUX); 54 | bool SetApParam(char* apSetSsid,char* apSetPasswd,unsigned char channel=1,esp8266_ENCRYPTION encryption=esp8266_ENCRYPTION_WPA2_PSK,esp8266_pattern = esp8266_PATTERN_DEF); 55 | bool JoinAP(char* apJoinSsid,char* apJoinPasswd,esp8266_pattern = esp8266_PATTERN_DEF);//加入AP 56 | 57 | bool CreateConnectMutipleMode(char* ipAddr,short port,Socket_Type socketType, signed char muxID = -1); 58 | bool SendMultipleMode(char* data, unsigned int num,signed char muxID=-1); 59 | bool Close(signed char muxID=-1); 60 | char GetStatus(char* muxID=0,char* type=0,char* ipAddr=0,short remotePort=0,short localPort=0,esp8266_ROLE role=esp8266_ROLE_CLIENT); 61 | 62 | private: 63 | 64 | USART &mUsart; 65 | unsigned int mReceiveBufferIndex; 66 | void ClearBuffer(); 67 | bool ReceiveAndWait(char const* targetString,unsigned char timeOut=ESP8266_DEFAULT_TIMEOUT); 68 | bool ReceiveAndWait(char const* targetString,char const* targetString2,unsigned char timeOut=ESP8266_DEFAULT_TIMEOUT); 69 | bool ReceiveAndWait(char const* targetString,char const* targetString2,char const* targetString3,unsigned char timeOut=ESP8266_DEFAULT_TIMEOUT); 70 | 71 | protected: 72 | char mReceiveBuffer[ESP8266_RECEIVE_BUFFER_SIZE]; 73 | public: 74 | bool RecvFind(char const *target, unsigned char timeout=ESP8266_DEFAULT_TIMEOUT); 75 | bool RecvFind(char const *target,char const *target2, unsigned char timeout=ESP8266_DEFAULT_TIMEOUT); 76 | bool RecvFind(char const *target,char const *target2,char const *target3, unsigned char timeout=ESP8266_DEFAULT_TIMEOUT); 77 | bool RecvFindAndFilter(char const *target, char const * begin, char const * end, char* Data, float timeout=ESP8266_DEFAULT_TIMEOUT); 78 | 79 | 80 | }; 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /lib/offchip/esp8266/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOCKET_H 2 | #define __SOCKET_H 3 | #include "stdbool.h" 4 | 5 | enum Socket_Type{Socket_Type_Stream,Socket_Type_Dgram};//TCP & UDP 6 | enum Socket_Protocol{Socket_Protocol_IPV4,Socket_Protocol_IPV6}; 7 | 8 | class Socket 9 | { 10 | public : 11 | Socket(){} 12 | virtual bool Init() = 0; 13 | virtual bool Connect(char* ipAddr,short int port,Socket_Type socketType,Socket_Protocol socketProtocol=Socket_Protocol_IPV4) = 0; 14 | virtual bool Write(char* data,unsigned int num) = 0; 15 | virtual unsigned int Read(char* data) = 0; 16 | virtual unsigned int Read(char* data,unsigned int num) = 0; 17 | virtual bool IsAlive() = 0; 18 | virtual bool Close() = 0; 19 | virtual void SetTimeOut(float timetOut) = 0; 20 | private: 21 | long int mIPAddr; 22 | short int mPort; 23 | 24 | }; 25 | 26 | #endif 27 | 28 | 29 | -------------------------------------------------------------------------------- /lib/offchip/yishan_PM2_5/yishan_PM2_5.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "yishan_PM2_5.h" 3 | 4 | yishan_PM_2_5::yishan_PM_2_5(USART &com):mCom(com) 5 | { 6 | PM1_0_UD=0; 7 | PM2_5_UD = 0; 8 | PM10_UD = 0; 9 | } 10 | 11 | bool yishan_PM_2_5::Check(u8 *Data,int Lenth,int CheckSum) 12 | { 13 | int temp=0; 14 | for(int i=0;i 31) 46 | { 47 | mCom.GetReceivedData(ch,2); 48 | if(ch[0] != 0x32 || ch[1] != 0x3d) 49 | { 50 | mCom.ClearReceiveBuffer(); 51 | return false; 52 | } 53 | // if(ch!=0x32) 54 | // return false; 55 | // else 56 | // { 57 | // mCom.GetReceivedData(&ch,1); 58 | // if(ch!=0x3D) 59 | // return false; 60 | // } 61 | mCom.GetReceivedData(data+2,30); 62 | data[0] = 0x32; 63 | data[1]= 0x3d; 64 | 65 | if(Check(data,30,(int)data[30]*256+data[31]))//校验 66 | { 67 | //数据处理 68 | PM1_0_UD = (int)data[4]*256 + data[5]; 69 | PM2_5_UD = (int)data[6]*256 + data[7]; 70 | PM10_UD = (int)data[8]*256 + data[9]; 71 | mCom.ClearReceiveBuffer(); 72 | return true; 73 | } 74 | else 75 | return false; 76 | } 77 | else 78 | return false; 79 | 80 | } 81 | -------------------------------------------------------------------------------- /lib/offchip/yishan_PM2_5/yishan_PM2_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | 每秒发送一次,波特率9600 一个包长度为32个字节 3 | */ 4 | 5 | #ifndef __YISHAN_PM2_5_H__ 6 | #define __YISHAN_PM2_5_H__ 7 | 8 | #include "stm32f10x.h" 9 | #include "USART.h" 10 | 11 | class yishan_PM_2_5{ 12 | 13 | private: 14 | USART &mCom; 15 | int PM1_0_UD; 16 | int PM2_5_UD;//PM2.5浓度 单位 ug/m^3 17 | int PM10_UD; 18 | 19 | bool Check(u8 *Data,int Lenth,int CheckSum); 20 | 21 | public: 22 | yishan_PM_2_5(USART &com); 23 | 24 | bool Update(); 25 | int GetConcentration_2_5(); 26 | int GetConcentration_1_0(); 27 | int GetConcentration_10(); 28 | 29 | }; 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /lib/onchip/ADC/ADC.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADC_H_ 2 | #define _ADC_H_ 3 | 4 | #include "stm32f10x.h" 5 | 6 | 7 | /** 8 | * 9 | * ADC端口 和 STM32f103c8t6板子的对应引脚 10 | * (stm32f10x系列板若有以下引脚也可兼容使用) 11 | * PA0---ADC12_IN0 PB0---ADC12_IN8 12 | * PA1---ADC12_IN1 PB1---ADC12_IN9 13 | * PA2---ADC12_IN2 PC0---ADC12_IN10 14 | * PA3---ADC12_IN3 PC1---ADC12_IN11 15 | * PA4---ADC12_IN4 PC2---ADC12_IN12 16 | * PA5---ADC12_IN5 PC3---ADC12_IN13 17 | * PA6---ADC12_IN6 PC4---ADC12_IN14 18 | * PA7---ADC12_IN7 PC5---ADC12_IN15 19 | * 20 | */ 21 | 22 | 23 | #define MAX_ADC_CHANNEL 10 24 | 25 | class ADC 26 | { 27 | private: 28 | static u16 _pin[MAX_ADC_CHANNEL]; //gpio pin for adc channel 29 | static bool _enCh[MAX_ADC_CHANNEL]; //enable flag for adc channel 30 | static u8 _chMap[MAX_ADC_CHANNEL]; //map channel number to the index of _adcValue 31 | static u16 _adcValue[MAX_ADC_CHANNEL]; //adc value for each channel 32 | public: 33 | ADC(u8 ch0Num, u8 ch1Num=0xFF, u8 ch2Num=0xFF, u8 ch3Num=0xFF, u8 ch4Num=0xFF, u8 ch5Num=0xFF, u8 ch6Num=0xFF, u8 ch7Num=0xFF, u8 ch8Num=0xFF, u8 ch9Num=0xFF); 34 | double operator[](u8 chNum); 35 | float Voltage_I(uint8_t channelNumber, float resister_a,float resister_b,float fullRange); 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /lib/onchip/CAN/can.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neutree/STM32f103DriverLib/28dfb70b6b0aa8e0de940ae8aa417a3989dbe3a5/lib/onchip/CAN/can.cpp -------------------------------------------------------------------------------- /lib/onchip/CAN/can.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neutree/STM32f103DriverLib/28dfb70b6b0aa8e0de940ae8aa417a3989dbe3a5/lib/onchip/CAN/can.h -------------------------------------------------------------------------------- /lib/onchip/GPIO/GPIO.cpp: -------------------------------------------------------------------------------- 1 | 2 | //include the header file containing the class declaration. 3 | #include "GPIO.h" 4 | 5 | 6 | //Initialize the static member constants 7 | const uint16_t GPIO::mPin[16]={GPIO_Pin_0,GPIO_Pin_1,GPIO_Pin_2,GPIO_Pin_3,GPIO_Pin_4,GPIO_Pin_5,GPIO_Pin_6,GPIO_Pin_7, 8 | GPIO_Pin_8,GPIO_Pin_9,GPIO_Pin_10,GPIO_Pin_11,GPIO_Pin_12,GPIO_Pin_13,GPIO_Pin_14,GPIO_Pin_15}; 9 | 10 | 11 | //The Constructor of the Class 12 | GPIO::GPIO(GPIO_TypeDef *port,uint16_t pin,GPIOMode_TypeDef mode,GPIOSpeed_TypeDef speed):mMode(mode),mSpeed(speed),mPort(port),mSelectPin(pin) 13 | { 14 | GPIO_InitTypeDef GPIO_InitStructure; 15 | RCC_Configuration(); 16 | 17 | GPIO_InitStructure.GPIO_Pin=mPin[pin]; 18 | GPIO_InitStructure.GPIO_Speed=speed; 19 | GPIO_InitStructure.GPIO_Mode=mode; 20 | GPIO_Init(mPort,&GPIO_InitStructure); 21 | } 22 | 23 | void GPIO::DisableSWJTAG(bool disableSW,bool disableJtag) 24 | { 25 | uint8_t temp=0; 26 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 27 | if(disableSW && disableJtag) 28 | temp = 4; 29 | else if(!disableSW && disableJtag) 30 | temp = 2; 31 | else 32 | temp = 4; 33 | GPIO_PinRemapConfig(0x00300000|(temp<<8),ENABLE); 34 | // GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); 35 | 36 | } 37 | 38 | //The function to configure the RCC of GPIO 39 | void GPIO::RCC_Configuration() 40 | { 41 | if(mPort==GPIOA) 42 | { 43 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); 44 | } 45 | else if(mPort==GPIOB) 46 | { 47 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); 48 | } 49 | else if(mPort==GPIOC) 50 | { 51 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); 52 | } 53 | else if(mPort==GPIOD) 54 | { 55 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); 56 | } 57 | else if(mPort==GPIOE) 58 | { 59 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE); 60 | } 61 | else if(mPort==GPIOF) 62 | { 63 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE); 64 | } 65 | else if(mPort==GPIOG) 66 | { 67 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG,ENABLE); 68 | } 69 | } 70 | 71 | /** 72 | * @brief Set the level of the pin 73 | * @param level:The level you wan to set,value:0 or 1 74 | */ 75 | void GPIO::SetLevel(u8 level) 76 | { 77 | if(level>0) 78 | GPIO_SetBits(mPort,mPin[mSelectPin]); 79 | else 80 | GPIO_ResetBits(mPort,mPin[mSelectPin]); 81 | } 82 | 83 | /** 84 | * @brief Get the level of the pin 85 | * @retval level:Return the pin's level,value:true(1),false(0) 86 | */ 87 | bool GPIO::GetLevel() 88 | { 89 | if(!GPIO_ReadInputDataBit(mPort,mPin[mSelectPin])) 90 | return false; 91 | else 92 | return true; 93 | } 94 | 95 | /*** Invert the level of the pin ***/ 96 | void GPIO::Toggle() 97 | { 98 | if(GPIO_ReadInputDataBit(mPort,mPin[mSelectPin])) 99 | GPIO_ResetBits(mPort,mPin[mSelectPin]); 100 | else 101 | GPIO_SetBits(mPort,mPin[mSelectPin]); 102 | } 103 | 104 | void GPIO::ChangeMode(GPIOMode_TypeDef mode) 105 | { 106 | GPIO_InitTypeDef GPIO_InitStructure; 107 | 108 | GPIO_InitStructure.GPIO_Pin = mPin[mSelectPin]; 109 | GPIO_InitStructure.GPIO_Speed = mSpeed; 110 | GPIO_InitStructure.GPIO_Mode = mode; 111 | GPIO_Init(mPort,&GPIO_InitStructure); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /lib/onchip/GPIO/GPIO.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * 4 | * GPIO CALSS HEADER FILE 5 | * 6 | * Filename : GPIO.h 7 | * Version : V1.0 8 | * Programmer(s) : Jason Xie 9 | * 10 | ********************************************************************************************************* 11 | */ 12 | #ifndef _GPIO_H 13 | #define _GPIO_H 14 | 15 | /** include header files **/ 16 | 17 | #include 18 | #include "stm32f10x_gpio.h" 19 | #include "stm32f10x_rcc.h" 20 | //#include 21 | //#include 22 | 23 | 24 | /** 25 | * @brief The class of GPIO. 26 | * @param mPin[16]: The array of GPIO_Pin_x. 27 | * @param mPort:The port of GPIO,such as GPIOA,etc. 28 | * @param mSelectPin:The pin you want to use. 29 | * @param mMode:The GPIO's mode,such as "GPIO_Mode_Out_PP",etc 30 | * @param mSpeed:The output's speed of GPIO,such as "GPIO_Speed_10MHz",etc 31 | */ 32 | class GPIO 33 | { 34 | private: 35 | static const uint16_t mPin[16]; 36 | GPIOMode_TypeDef mMode; 37 | GPIOSpeed_TypeDef mSpeed; 38 | 39 | /* The function to configure the RCC of GPIO */ 40 | void RCC_Configuration(); 41 | 42 | public: 43 | GPIO_TypeDef *mPort; 44 | uint16_t mSelectPin; 45 | 46 | /* The Constructor of the Class */ 47 | GPIO(GPIO_TypeDef *port=GPIOA,uint16_t pin=1,GPIOMode_TypeDef mode=GPIO_Mode_Out_PP,GPIOSpeed_TypeDef speed=GPIO_Speed_50MHz); 48 | 49 | /** 50 | * @brief disable jtag or sw if you want to use the io below: 51 | * PB3:JTDO, PB4:JNTRST, PA15:JTDI, PA14:JTCK/SWCLK, PA13:JTMS/SWDIO 52 | */ 53 | void DisableSWJTAG(bool disableSW,bool disableJtag); 54 | /** 55 | * @brief Set the pin as high level or low level. 56 | * @param level: The level you wan to set,type:unsigned char ,value:0 or 1 57 | */ 58 | void SetLevel(u8 level); 59 | 60 | /** 61 | * @brief Get the level of the pin. 62 | * @retval level:Return the pin's level,value:true(1),false(0) 63 | */ 64 | bool GetLevel(); 65 | 66 | /** 67 | * @brief Invert the level of the pin. 68 | */ 69 | void Toggle(); 70 | 71 | /** 72 | * @brief Change the GPIO's mode. 73 | * @param the GPIO's mode 74 | */ 75 | void ChangeMode(GPIOMode_TypeDef mode); 76 | }; 77 | 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /lib/onchip/I2C/Sensor.h: -------------------------------------------------------------------------------- 1 | #ifndef _SENSOR_H_ 2 | #define _SENSOR_H_ 3 | 4 | #include "TaskManager.h" 5 | 6 | class Sensor 7 | { 8 | protected: 9 | bool mHealthy; 10 | bool mIsUpdated; //I2C task complete falg 11 | double mUpdatedTime; //I2C task completed time (second) 12 | double mInterval; //time interval since last update (second) 13 | public: 14 | Sensor() 15 | { 16 | mHealthy = false; 17 | mIsUpdated = true; 18 | mUpdatedTime = 0; 19 | mInterval = 0; 20 | } 21 | void Updated() 22 | { 23 | mIsUpdated = true; 24 | double curTime = tskmgr.Time(); 25 | mInterval = curTime - mUpdatedTime; 26 | mUpdatedTime = curTime; 27 | } 28 | float Interval() { return mInterval; } //return interval between two update 29 | bool IsHealthy() { return mHealthy; } //return healthy state of device 30 | }; 31 | 32 | 33 | #endif 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /lib/onchip/IAP/IAP.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "IAP.h" 3 | #include "stm32f10x.h" 4 | 5 | IAP::IAP(Flash* flash,uint32_t appAddr ) 6 | :mFlash(flash) 7 | { 8 | mAppAddr = appAddr; 9 | __enable_irq(); 10 | } 11 | 12 | bool IAP::LoadApp() 13 | { 14 | void (*pFun)(void); 15 | 16 | RCC_DeInit(); //关闭外设时钟 17 | //NVIC_DeInit(); //恢复NVIC为复位状态.使中断不再发生. 18 | __disable_irq(); 19 | 20 | if(((*(uint32_t*)mAppAddr)&0x2FFE0000)==0x20000000) //检查栈顶地址是否合法. 21 | { 22 | pFun=(void(*)(void))*(vu32*)(mAppAddr+4); //用户代码区第二个字为程序开始地址(复位地址) 23 | // MSR_MSP(*(vu32*)mAppAddr); //初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址) 24 | __set_MSP(*(uint32_t*)mAppAddr); //设置SP.,堆栈栈顶地址 25 | pFun(); //跳转到APP. 26 | return true; 27 | 28 | }else{ 29 | return false; 30 | } 31 | } 32 | 33 | /** 34 | * 35 | *@param appAdress App adress, this value **must** be a multiple 36 | * of 0x200. 37 | */ 38 | void IAP::Init(uint32_t currAppAdress) 39 | { 40 | NVIC_SetVectorTable(NVIC_VectTab_FLASH, currAppAdress); 41 | __enable_irq(); 42 | } 43 | 44 | 45 | bool IAP::CheckPack(IAP_Pack_t* pack) 46 | { 47 | uint16_t i; 48 | uint16_t packLen = sizeof(IAP_Pack_t)-1; 49 | uint8_t sum = *((uint8_t*)pack); 50 | for(i=1; icheckSum; 55 | } 56 | 57 | bool IAP::WritePack(IAP_Pack_t* pack, bool checkPack) 58 | { 59 | if(checkPack && !CheckPack(pack)) 60 | return false; 61 | if(mFlash->IsHalfWord()) 62 | { 63 | if(pack->len % 2) 64 | return false; 65 | uint16_t packLen = pack->len/2; 66 | if(!mFlash->Write(pack->id,0,(uint16_t*)(pack->data),packLen)) 67 | return false; 68 | } 69 | else 70 | { 71 | if(pack->len % 4) 72 | return false; 73 | uint16_t packLen = pack->len/4; 74 | if(!mFlash->Write(pack->id,(uint32_t*)(pack->data),packLen)) 75 | return false; 76 | } 77 | return true; 78 | } 79 | 80 | // extern "C" 81 | // { 82 | 83 | // __asm void MSR_MSP(u32 addr) 84 | // { 85 | // MSR MSP, r0 //set Main Stack value 86 | // BX r14 87 | // } 88 | 89 | // } 90 | 91 | -------------------------------------------------------------------------------- /lib/onchip/IAP/IAP.h: -------------------------------------------------------------------------------- 1 | #ifndef __IAP_H 2 | #define __IAP_H 3 | 4 | #include "Flash.h" 5 | #include "stdint.h" 6 | #include "stdbool.h" 7 | 8 | typedef struct{ 9 | uint16_t id; // packet ID (current packet ), start from 0 10 | uint16_t len; // data length of this packet, must MEMORY_PAGE_SIZE except the last one packet 11 | uint8_t data[MEMORY_PAGE_SIZE]; //data 12 | uint8_t checkSum; // ^ every bytes before 13 | }IAP_Pack_t; 14 | 15 | class IAP{ 16 | 17 | public: 18 | /** 19 | * 20 | *@param flash Flash object, can be NULL if you are in APP program but IAP program 21 | */ 22 | IAP(Flash* flash,uint32_t appAddr); 23 | bool CheckPack(IAP_Pack_t* pack); // for IAP 24 | bool WritePack(IAP_Pack_t* pack, bool checkPack = false); // for IAP 25 | /** 26 | * IAP program load(and run) App program 27 | */ 28 | bool LoadApp(); // for IAP 29 | /** 30 | * Initilize app(IAP program or App program), you must call this function 31 | * in on the start of IAP program **and** APP program 32 | * 33 | *@param currAppAdress current App adress, must be the start address of current application(IAP or user APP) 34 | * this value **must** be a multiple of 0x200. 35 | */ 36 | void Init(uint32_t currAppAdress); // for IAP and App 37 | 38 | private: 39 | Flash* mFlash; 40 | uint32_t mAppAddr; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /lib/onchip/IAP/IAP_USART.h: -------------------------------------------------------------------------------- 1 | #ifndef __IAP_USART_H 2 | #define __IAP_USART_H 3 | 4 | #include "IAP.h" 5 | #include "USART.h" 6 | 7 | 8 | ///////////////////////////////////////////////////// 9 | /// Attention, the buffer length of USART MUST more than `sizeof(IAP_USART_Pack_t)` (1k+12) 10 | /// setting in Configuration.h 11 | ///////////////////////////////////////////////////// 12 | 13 | 14 | #define IAP_USART_PACK_START_FLAG 0xAE003D72 //little edian 15 | #define IAP_USART_PACK_ACK_START_FLAG 0xAE003E78 //little edian 16 | 17 | typedef struct{ 18 | uint32_t packStart; 19 | uint16_t packTotal; 20 | uint16_t packID; // start from 0 21 | uint16_t len; 22 | uint8_t data[MEMORY_PAGE_SIZE]; //fixed length MEMORY_PAGE_SIZE, if less than MEMORY_PAGE_SIZE, padding with 0 23 | uint16_t checkSum; //^ all bytes before 24 | }IAP_USART_Pack_t; //little edian 25 | 26 | typedef enum{ 27 | IAP_USART_UPGRADE_STATUS_ERROR = -1, 28 | IAP_USART_UPGRADE_STATUS_IDLE = 0, 29 | IAP_USART_UPGRADE_STATUS_WORKING = 1, 30 | IAP_USART_UPGRADE_STATUS_COMPLETE = 2, 31 | 32 | IAP_USART_UPGRADE_STATUS_MAX 33 | }IAP_USART_Upgrade_Status_t; 34 | 35 | #pragma pack(1) 36 | typedef struct 37 | { 38 | uint32_t packStart; 39 | uint16_t packTotal; 40 | uint16_t packID; 41 | bool success; 42 | uint16_t checkSum; 43 | }IAP_USART_Pack_Ack_t; 44 | #pragma pack() 45 | 46 | 47 | 48 | 49 | class IAP_USART:public IAP{ 50 | 51 | public: 52 | IAP_USART(USART& usart,Flash& flash,uint32_t appAddr); 53 | IAP_USART_Upgrade_Status_t Upgrade(); 54 | 55 | private: 56 | USART& mUsart; 57 | uint16_t mPackIdLast; 58 | IAP_USART_Pack_t mPack; 59 | IAP_USART_Pack_Ack_t mPackAck; 60 | bool CheckPack(IAP_USART_Pack_t* pack); 61 | bool PackAck(uint16_t packID, uint16_t packTotal, bool success); 62 | bool AckCheckSum(IAP_USART_Pack_Ack_t* pack); 63 | 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/onchip/IWDG/IWDG.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *@file IWDG.cpp 3 | *@author Neucrack 4 | *@version v0.1 5 | *@brief independent watch dog 6 | * 7 | */ 8 | #include "IWDG.h" 9 | 10 | IWDG_::IWDG_(float timeoutS) 11 | { 12 | #ifdef WATCHDOG 13 | uint8_t prer = 4; 14 | uint16_t rlr = (uint16_t)timeoutS * 625; 15 | IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); /* 使能对寄存器IWDG_PR和IWDG_RLR的写操作*/ 16 | IWDG_SetPrescaler(prer); /*设置IWDG预分频值:设置IWDG预分频值*/ 17 | IWDG_SetReload(rlr); /*设置IWDG重装载值*/ 18 | IWDG_ReloadCounter(); /*按照IWDG重装载寄存器的值重装载IWDG计数器*/ 19 | IWDG_Enable(); /*使能IWDG*/ 20 | #endif 21 | } 22 | 23 | void IWDG_::Feed() 24 | { 25 | IWDG_ReloadCounter(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lib/onchip/IWDG/IWDG.h: -------------------------------------------------------------------------------- 1 | /** 2 | *@file IWDG.h 3 | *@author Neucrack 4 | *@version v0.1 5 | *@brief independent watch dog 6 | * 7 | */ 8 | #include "stm32f10x.h" 9 | 10 | class IWDG_ 11 | { 12 | public: 13 | IWDG_(float timeoutS); 14 | void Feed(); 15 | }; 16 | -------------------------------------------------------------------------------- /lib/onchip/PWM/PWM.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neutree/STM32f103DriverLib/28dfb70b6b0aa8e0de940ae8aa417a3989dbe3a5/lib/onchip/PWM/PWM.cpp -------------------------------------------------------------------------------- /lib/onchip/PWM/PWM.h: -------------------------------------------------------------------------------- 1 | #ifndef _F103_PWM_H_ 2 | #define _F103_PWM_H_ 3 | 4 | #include "stm32f10x.h" 5 | 6 | class PWM 7 | { 8 | private: 9 | u32 _timx_rcc; //timer rcc 10 | u32 _gpio_rcc; //gpio rcc 11 | TIM_TypeDef *_timx; //timer 12 | GPIO_TypeDef *_port; //gpio 13 | u16 _pin1; //ch1 gpio pin 14 | u16 _pin2; //ch2 gpio pin 15 | u16 _pin3; //ch3 gpio pin 16 | u16 _pin4; //ch4 gpio pin 17 | bool _enCh1; //ch1 enable flag 18 | bool _enCh2; //ch2 enable flag 19 | bool _enCh3; //ch3 enable falg 20 | bool _enCh4; //ch4 enable falg 21 | u16 _frqence; //freqence 22 | u32 _period; //period 23 | u16 _prescaler; //prescaler 24 | public: 25 | PWM(TIM_TypeDef *timx,bool enCh1,bool enCh2,bool enCh3, bool enCh4, u16 frq); 26 | void Initialize(TIM_TypeDef *timx,bool enCh1,bool enCh2,bool enCh3, bool enCh4, u16 frq); 27 | void SetDuty(float ch1,float ch2, float ch3, float ch4=0); 28 | void SetDuty(u8 chNum,float ch2); 29 | }; 30 | 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/onchip/SPI/SPI.h: -------------------------------------------------------------------------------- 1 | /** 2 | *@file SPI.h 3 | *@frief SPI driver lib for stm32f10x 4 | *@author Neucrack(Neutree) 5 | *@version v0.1 6 | *@date create on 2016-01-06 7 | * last update on 2017-05-27 8 | *@copyright CQUT IOT LIB all right reserved 9 | *@bug only for master mode now 10 | */ 11 | 12 | #ifndef __SPI_H_ 13 | #define __SPI_H_ 14 | 15 | #include "stm32f10x.h" 16 | #include "TaskManager.h" 17 | 18 | 19 | class SPI{ 20 | 21 | public: 22 | /////////////////////////// 23 | ///Constructor for SPI 24 | ///@param SPI choose which SPI to use SPI1 or SPI2 25 | ///@param if remap pin 26 | ///@param speed speed of SPI default:SPI_SPEED_256(281.25kHz) @see SPI_Speed 27 | ///@param firstBit the first bit of transfer LSB or MSB @see SPI_FirstBit default:SPI_FirstBit_MSB_ 28 | ////////////////////////// 29 | SPI(SPI_TypeDef* spi,bool remap=false); 30 | 31 | 32 | 33 | /////////////////////////////// 34 | ///read a byte from slave or write a byte to slave 35 | ///@param dataToSend if write: the data will send to slave 36 | /// if read : the slave register address to read 37 | ///@dataReturn allow empty if write: the same data with send data 38 | /// if read : the slave register's data 39 | ///@retval if read or write succeed 40 | /////////////////////////////// 41 | bool ReadOrWriteByte(u8 dataTosend,u8 *dataReturn=0); 42 | 43 | 44 | 45 | ////////////////////////// 46 | ///使能SPI(使能NSS) 47 | ////////////////////////// 48 | void EnableSPI(void); 49 | 50 | ////////////////////////// 51 | ///失能SPI(使能NSS) 52 | ////////////////////////// 53 | void DisableSPI(void); 54 | 55 | private: 56 | 57 | // 58 | SPI_TypeDef* mSPI; 59 | GPIO_TypeDef* mNSS_GPIO; 60 | uint16_t mNSS_Pin; 61 | 62 | 63 | /////////////////////////// 64 | ///Constructor for SPI 65 | ///@param SPI choose which SPI to use SPI1(default) or SPI2 66 | ///@param if remap pin 67 | ///@param speed speed of SPI @see SPI_Speed default:SPI_SPEED_16 68 | ///@param firstBit the first bit of transfer LSB or MSB @see SPI_FirstBit default:SPI_FirstBit_MSB_ 69 | ////////////////////////// 70 | void Init(SPI_TypeDef* spi,bool remap=false); 71 | 72 | 73 | }; 74 | /** @defgroup USART_Pin_Table 75 | * @{ 76 | */ 77 | /** 78 | =========================================================================== 79 | | remap value | 80 | spiName | 0x00 | 0x01 | 0x11| 81 | spi1MOSI | PA7 | PB5 | | 82 | spi1MISO | PA6 | PB4 | | 83 | spi1SCK | PA5 | PB3 | | 84 | spi1NSS | PA4 | PA15 | | 85 | spi2MOSI | PB15 | | | 86 | spi2MISO | PB14 | | | 87 | spi2SCK | PB13 | | | 88 | spi2NSS | PB12 | | | 89 | spi3MOSI | PB5 | PC12 | | 90 | spi3MISO | PB4 | PC11 | | 91 | spi3SCK | PB3 | PC10 | | 92 | spi3NSS | PA15 | PA4 | | 93 | =========================================================================== 94 | */ 95 | /** 96 | * @} 97 | */ 98 | 99 | #endif 100 | 101 | 102 | -------------------------------------------------------------------------------- /lib/onchip/Util/Assert.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Assert.h" 3 | 4 | //#define DEBUG_USE_USART 5 | 6 | #ifdef DEBUG_USE_USART 7 | #include "USART.h" 8 | extern USART log; 9 | #define LOG(str) log<LOAD = 9000*nms; 21 | SysTick->VAL=0X00;//清空计数器 22 | SysTick->CTRL=0X01;//使能,减到零是无动作,采用外部时钟源 23 | do 24 | { 25 | temp=SysTick->CTRL;//读取当前倒计数值 26 | }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达 27 | SysTick->CTRL=0x00; //关闭计数器 28 | SysTick->VAL =0X00; //清空计数器 29 | #else 30 | u16 i=0; 31 | while(nms--) 32 | { 33 | i=8000; //自己定义 34 | while(i--) ; 35 | } 36 | #endif 37 | } 38 | 39 | 40 | void Delay::Us(uint32_t usec) 41 | { 42 | u32 temp; 43 | #ifdef DELAY_USE_SYSTICK 44 | if(nus==0) 45 | return; 46 | SysTick->LOAD = 9*usec; 47 | SysTick->VAL=0X00;//清空计数器 48 | SysTick->CTRL=0X01;//使能,减到零是无动作,采用外部时钟源 49 | do 50 | { 51 | temp=SysTick->CTRL;//读取当前倒计数值 52 | }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达 53 | 54 | SysTick->CTRL=0x00; //关闭计数器 55 | SysTick->VAL =0X00; //清空计数器 56 | 57 | #else 58 | u16 i=0; 59 | while(temp--) 60 | { 61 | i=10; //自己定义 62 | while(i--) ; 63 | } 64 | #endif 65 | } 66 | 67 | 68 | 69 | void Delay::S(uint32_t ns) 70 | { 71 | u32 temp; 72 | #ifdef DELAY_USE_SYSTICK 73 | u32 i; 74 | if(ns==0) 75 | return; 76 | SysTick->LOAD = 9000000;//1S 77 | SysTick->VAL=0X00;//清空计数器 78 | SysTick->CTRL=0X01;//使能,减到零是无动作,采用外部时钟源 79 | for(i=0;iCTRL;//读取当前倒计数值 84 | }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达 85 | SysTick->LOAD = 9000000;//1S 86 | } 87 | SysTick->CTRL=0x00; //关闭计数器 88 | SysTick->VAL =0X00; //清空计数器 89 | #else 90 | while(temp--) 91 | { 92 | Ms(1000); 93 | } 94 | #endif 95 | } 96 | 97 | -------------------------------------------------------------------------------- /lib/onchip/delay/Delay.h: -------------------------------------------------------------------------------- 1 | /** 2 | *@file Delay.h 3 | *@author Neutree 4 | *@breif Delay Class 5 | *@copyright CQUT IOT Lib all rights reserved 6 | */ 7 | 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | 12 | /*************************configuration******************************/ 13 | // #define DELAY_USE_SYSTICK 14 | #define DELAY_USE_SOFTDELAY 15 | 16 | /********************************************************************/ 17 | 18 | #include "stm32f10x.h" 19 | 20 | class Delay 21 | { 22 | public: 23 | ///////////////////////// 24 | ///delay static function 25 | ///use Delay::Ms() or use object to invoke 26 | ///@param nMs the time will delay Unit:ms 27 | ///////////////////////// 28 | static void Ms(uint16_t nMs); 29 | 30 | ///////////////////////// 31 | ///delay static function 32 | ///use Delay::Us() or use object to invoke 33 | ///@param nUs the time will delay Unit:us 34 | ///////////////////////// 35 | static void Us(uint32_t nUs); 36 | ///////////////////////// 37 | ///delay static function 38 | ///use Delay::nS() or use object to invoke 39 | ///@param nS the time will delay Unit:nS 40 | ///////////////////////// 41 | static void S(uint32_t nS); 42 | }; 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /lib/onchip/flash/Flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLASH_H 2 | #define __FLASH_H 3 | /**@file Memory.h 4 | *@brief stm32 flash的读写操作 5 | * 使用: 6 | * * 引入文件到工程中,Memory.cpp Memory.h 7 | * * 建立一个Memory对象(注意构造函数,默认是从63K Byte处开始存数,使用半字储存) 8 | * * 使用Read和Write函数进行读写,具体参数和返回值见函数说明 9 | * 10 | *@author neucrack CQUT IOT lib 11 | * 12 | */ 13 | 14 | #include "stm32f10x.h" 15 | #include "stm32f10x_flash.h" 16 | 17 | 18 | /* Define the STM32F10Xxx Flash page size depending on the used STM32 device */ 19 | #if defined (STM32F10X_LD) || defined (STM32F10X_MD) 20 | #define MEMORY_PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */ 21 | #elif defined (STM32F10X_HD) || defined (STM32F10X_CL) 22 | #define MEMORY_PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */ 23 | #endif 24 | 25 | 26 | /* Page status definitions */ 27 | #define MEMORY_STATUS_ERASED ((uint16_t)0xFFFF) /* PAGE is empty */ 28 | #define MEMORY_STATUS_RECEIVE_DATA ((uint16_t)0xEEEE) /* PAGE is marked to receive data */ 29 | #define MEMORY_STATUS_VALID_PAGE ((uint16_t)0x0000) /* PAGE containing valid data */ 30 | 31 | 32 | 33 | 34 | 35 | class Flash 36 | { 37 | private: 38 | 39 | bool mUseHalfWord;//储存字长 16/32 默认16位 40 | uint32_t mStartAddress;//开始储存的地址 41 | public: 42 | /////////////////// 43 | ///构造函数 44 | ///@param startAddress 存储数据的开始位置 默认:0x08010000 即63k byte 处 45 | ///@param useHalfWord 单个数据储存的长度 true:16位 false:32位 默认:16位 46 | /////////////////// 47 | Flash(uint32_t startAddress=(0x08000000+63*MEMORY_PAGE_SIZE),bool useHalfWord=true); 48 | 49 | 50 | /////////////////////// 51 | ///读取储存器中特定位置的值 52 | ///@param -relativeAddress 相对于开始地址的地址 53 | ///@param -Data 读出的数据存放的地址 54 | ///@retval -1 : 读取成功 -0:读取失败 55 | /////////////////////// 56 | bool Read(uint16_t relativeAddress, uint8_t* Data,u16 length); 57 | 58 | //position为一页中的位置,只能是偶数或者0 59 | bool Read(u16 pageNumber,u16 position,u16* data,u16 length); 60 | 61 | 62 | bool Read(uint16_t relativeAddress, uint32_t* Data,u16 length); 63 | 64 | /////////////////////// 65 | ///向储存器中特定位置写值 66 | ///@param -pageNumber 相对于开始地址的页地址 67 | ///@param -Data 将要写入的数据 68 | ///@attention 如果构造构造函数的参数useHalfWord为true时,会现将其转换为u16再储存,否则会转换成u32再储存 69 | ///@retval -1 : 写入成功 -0:写入失败 70 | /////////////////////// 71 | bool Write(uint16_t pageNumber, uint8_t* Data,u16 length); 72 | 73 | //position为一页中的位置,只能是偶数或者0 74 | bool Write(uint16_t pageNumber,u16 position,uint16_t* data,u16 length); 75 | 76 | 77 | bool Write(uint16_t pageNumber, uint32_t* Data,u16 length); 78 | 79 | 80 | //字符串的存储于读取,参数:页码,页码中位置,字符串 81 | bool Write(uint16_t pageNumber,u16 position,char* str); 82 | bool Read(uint16_t pageNumber,u16 position,char *str); 83 | bool Clear(uint16_t pageNumber); 84 | 85 | bool IsHalfWord(); 86 | 87 | }; 88 | 89 | 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /lib/onchip/taskManager/TaskManager.cpp: -------------------------------------------------------------------------------- 1 | #include "TaskManager.h" 2 | 3 | TaskManager tskmgr; 4 | 5 | double TaskManager::_it_time = 0; 6 | double TaskManager::_new_time = 0; 7 | double TaskManager::_old_time = 0; 8 | 9 | //Constructor 10 | TaskManager::TaskManager() 11 | { 12 | SysTick->CTRL &= 0xFFFFFFFB; //Clock div 8 = 9M 13 | SysTick->LOAD = 16200000; //1.8s 14 | SysTick->CTRL |= 0x00000003; //INT +ENABLE 15 | } 16 | //get current time since power on 17 | double TaskManager::Time(void) 18 | { 19 | _new_time = _it_time + 1.8 - SysTick->VAL/9000000.0; //update current time 20 | 21 | if(_new_time - _old_time > 1.799) //check if breaked by SysTick interrupt 22 | { 23 | _new_time -= 1.8; //calibrate current time 24 | } 25 | _old_time = _new_time; //update old time 26 | return _new_time; 27 | } 28 | 29 | //微秒延时 30 | void TaskManager::DelayUs(u16 nus) 31 | { 32 | double OldT=Time(); 33 | while((Time()-OldT)=timeout) 53 | { 54 | record = Time(); //更新记录 55 | return true; 56 | } 57 | return false; 58 | } 59 | 60 | 61 | //SysTick interrupt IRQ handler 62 | extern "C" 63 | { 64 | void SysTick_Handler(void) 65 | { 66 | TaskManager::_it_time += 1.8; 67 | } 68 | } 69 | 70 | 71 | -------------------------------------------------------------------------------- /lib/onchip/taskManager/TaskManager.h: -------------------------------------------------------------------------------- 1 | #ifndef _TASK_MANAGER_H_ 2 | #define _TASK_MANAGER_H_ 3 | #include "stm32f10x.h" 4 | 5 | class TaskManager 6 | { 7 | private: 8 | static double _new_time; //current updated time 9 | static double _old_time; //last updated time 10 | public: 11 | static double _it_time; //time = SysTick interrupt counter*1.8s 12 | public: 13 | TaskManager(); //constructor 14 | static double Time(void); //get current time 15 | static void DelayUs(u16 nus); 16 | static void DelayMs(u16 nms); 17 | static void DelayS(u16 ns); 18 | static bool TimeSlice(double &record,double timeout); //传入一个时间记录值和一个超时时间 记录达到了超时时间返回tree 19 | }; 20 | extern TaskManager tskmgr; 21 | 22 | #define MOD_ERROR 0x00 23 | #define MOD_READY 0x01 24 | #define MOD_BUSY 0x02 25 | #define MOD_LOCK 0x04 26 | #define MOD_UNLOCK 0x08 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/onchip/timer/Timer.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Timer.h 4 | * @author lissettecarlr 5 | * @version V1.0 6 | V1.1 增加开关中断功能 7 | V1.2 增加清除CNT计数器的值的功能 8 | V1.3 增加了最大计数限制 9 | 增加错误标识ErrorMassage 10 | 修复了使用了宏定义却没有引入配置文的BUG 11 | 12 | * @date 10/25/2015(create) 13 | 10/28/2015(Debug) 14 | 11/02/2015(add) 15 | 08/25/2016(add Dubug) 16 | * @brief 必须配套Interrupt文件使用,用户如需需要编写中断函数,直接编写 17 | TIMX CH1 CH2 CH3 CH4 18 | 1 PA8 PA9 PA10 PA11 19 | 2 PA0 PA1 PA2 PA3 20 | 3 PA6 PA7 PB0 PB1 21 | 4 PB6 PB7 PB8 PB9 22 | ****************************************************************************** 23 | */ 24 | 25 | #ifndef __TIMER_H 26 | #define __TIMER_H 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | extern "C"{ 30 | #include "stm32f10x.h" 31 | } 32 | #include "Interrupt.h" 33 | 34 | 35 | /* define -------------------------------------------------------------------*/ 36 | #define INPUTMAX 59702385 //911*65535 最大计数 37 | #define COEFFICIENT 911 //72M下不分频最大计时us 38 | // 65535/72 39 | /* class----------------------------------------------------------------------*/ 40 | 41 | class Timer{ 42 | private: 43 | u16 mArr;//计数器初值 44 | u16 mPsc;//计数器预分频 45 | TIM_TypeDef *mTempTimer;//时钟选择 46 | u8 ErrorMassage;//错误信息标识 0标识没有出错 1:输出时间超出最大值 47 | bool Conversion(u16 s,u16 ms,u16 us);//将时分秒转换为初值和预分频 48 | 49 | public: 50 | 51 | //////////////////////////////////////// 52 | ///定时器初始化,默认定时器1,定时1ms 53 | ///@param timer 选择使用的定时器 54 | ///@param Prioritygroup 中断分组 55 | ///@param preemprionPriority 抢占优先级 56 | ///@param subPriority 响应优先级 57 | ///@param second 秒 58 | ///@param millisecond 毫秒 59 | ///@param microsecond 微秒 60 | //////////////////////////////////////// 61 | Timer(TIM_TypeDef *timer=TIM1,u16 second=0,u16 millisecond=1,u16 microsecond=0,u8 Prioritygroup=2,u8 preemprionPriority=2,u8 subPriority=2); 62 | 63 | //////////////////// 64 | ///开启定时器 65 | /////////////////// 66 | void Start(); 67 | 68 | /////////////////// 69 | ///关闭定时器 70 | ////////////////// 71 | void Stop(); 72 | 73 | ///////////////////////////////////////// 74 | ///中断开关 75 | ///@param bool true 开启中断 false 关闭中断 76 | ////////////////////////////////////////// 77 | void OnOrOffIrq(bool Switch); 78 | 79 | /////////////////// 80 | ///清空计数器的值 81 | ////////////////// 82 | void ClearCNT(void); 83 | 84 | 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /template/MDK/stm32103c8t6/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'demo' 7 | * Target: 'template' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | #define RTE_DEVICE_STDPERIPH_ADC 14 | #define RTE_DEVICE_STDPERIPH_DMA 15 | #define RTE_DEVICE_STDPERIPH_EXTI 16 | #define RTE_DEVICE_STDPERIPH_FLASH 17 | #define RTE_DEVICE_STDPERIPH_FRAMEWORK 18 | #define RTE_DEVICE_STDPERIPH_GPIO 19 | #define RTE_DEVICE_STDPERIPH_I2C 20 | #define RTE_DEVICE_STDPERIPH_RCC 21 | #define RTE_DEVICE_STDPERIPH_TIM 22 | #define RTE_DEVICE_STDPERIPH_USART 23 | 24 | #endif /* RTE_COMPONENTS_H */ 25 | -------------------------------------------------------------------------------- /template/MDK/stm32103c8t6/app/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "stm32f10x.h" 2 | #include "Configuration.h" 3 | #include "TaskManager.h" 4 | #include "USART.h" 5 | #include "I2C.h" 6 | #include "Timer.h" 7 | #include "ADC.h" 8 | #include "PWM.h" 9 | #include "flash.h" 10 | #include "InputCapture_TIM.h" 11 | #include "InputCapture_EXIT.h" 12 | #include "LED.h" 13 | 14 | //Timer T1(TIM1,1,2,3); //使用定时器计,溢出时间:1S+2毫秒+3微秒 15 | USART com(1,115200,false); 16 | I2C abc(2); 17 | PWM pwm2(TIM2,1,1,1,1,20000); //开启时钟2的4个通道,频率2Whz 18 | PWM pwm3(TIM3,1,1,0,0,20000); //开启时钟3的2个通道,频率2Whz 19 | PWM pwm4(TIM4,1,1,1,0,20000); //开启时钟4的3个通道,频率2Whz 20 | //InputCapture_TIM t4(TIM4, 400, true, true, true, true); 21 | InputCapture_EXIT ch1(GPIOB,6); 22 | ADC pressure(1); //PA1读取AD值 23 | flash InfoStore(0x08000000+100*MEMORY_PAGE_SIZE,true); //flash 24 | 25 | GPIO ledRedGPIO(GPIOB,0,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);//LED GPIO 26 | GPIO ledBlueGPIO(GPIOB,1,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);//LED GPIO 27 | LED ledRed(ledRedGPIO);//LED red 28 | LED ledBlue(ledBlueGPIO);//LED blue 29 | 30 | int main() 31 | { 32 | ledBlue.On(); 33 | ledRed.Off(); 34 | double record_tmgTest=0; //taskmanager时间 测试 35 | while(1) 36 | { 37 | if(tskmgr.TimeSlice(record_tmgTest,0.2)) //每0.2秒执行一次 38 | { 39 | ledRed.Toggle(); 40 | // ledBlue.Toggle(); 41 | } 42 | ledBlue.Blink(0,0.5,false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /template/MDK/stm32103c8t6/app/UserInterrupt.cpp: -------------------------------------------------------------------------------- 1 | #include "UserInterrupt.h" 2 | 3 | 4 | /*************************TIM_USER_IRQ***********************************/ 5 | #ifdef USE_TIMER1 6 | void Timer1_IRQ() 7 | { 8 | 9 | } 10 | #endif 11 | 12 | #ifdef USE_TIMER2 13 | void Timer2_IRQ() 14 | { 15 | 16 | } 17 | #endif 18 | 19 | #ifdef USE_TIMER3 20 | void Timer3_IRQ() 21 | { 22 | 23 | } 24 | #endif 25 | 26 | #ifdef USE_TIMER4 27 | void Timer4_IRQ() 28 | { 29 | 30 | } 31 | #endif 32 | 33 | 34 | /*************************EXIT_USER_IRQ***************************************/ 35 | #ifdef USE_EXTI0 36 | void EXTI0_IRQ() 37 | { 38 | } 39 | #endif 40 | #ifdef USE_EXTI1 41 | void EXTI1_IRQ() 42 | { 43 | } 44 | #endif 45 | #ifdef USE_EXTI2 46 | void EXTI2_IRQ() 47 | { 48 | } 49 | #endif 50 | #ifdef USE_EXTI3 51 | void EXTI3_IRQ() 52 | { 53 | } 54 | #endif 55 | #ifdef USE_EXTI4 56 | void EXTI4_IRQ() 57 | { 58 | } 59 | #endif 60 | #ifdef USE_EXTI5 61 | void EXTI5_IRQ() 62 | { 63 | } 64 | #endif 65 | #ifdef USE_EXTI6 66 | void EXTI6_IRQ() 67 | { 68 | } 69 | #endif 70 | #ifdef USE_EXTI7 71 | void EXTI7_IRQ() 72 | { 73 | } 74 | #endif 75 | #ifdef USE_EXTI8 76 | void EXTI8_IRQ() 77 | { 78 | } 79 | #endif 80 | #ifdef USE_EXTI9 81 | void EXTI9_IRQ() 82 | { 83 | } 84 | #endif 85 | #ifdef USE_EXTI10 86 | void EXTI10_IRQ() 87 | { 88 | } 89 | #endif 90 | #ifdef USE_EXTI11 91 | void EXTI11_IRQ() 92 | { 93 | } 94 | #endif 95 | #ifdef USE_EXTI12 96 | void EXTI12_IRQ() 97 | { 98 | } 99 | #endif 100 | #ifdef USE_EXTI13 101 | void EXTI13_IRQ() 102 | { 103 | } 104 | #endif 105 | #ifdef USE_EXTI14 106 | void EXTI14_IRQ() 107 | { 108 | } 109 | #endif 110 | #ifdef USE_EXTI15 111 | void EXTI15_IRQ() 112 | { 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /template/MDK/stm32103c8t6/app/UserInterrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USERINTERRUPT_H 2 | #define __USERINTERRUPT_H 3 | #include "Configuration.h" 4 | 5 | 6 | /*TIM***************************************************************************/ 7 | #ifdef USE_TIMER1 8 | void Timer1_IRQ(); 9 | #endif 10 | 11 | #ifdef USE_TIMER2 12 | void Timer2_IRQ(); 13 | #endif 14 | 15 | #ifdef USE_TIMER3 16 | void Timer3_IRQ(); 17 | #endif 18 | 19 | #ifdef USE_TIMER4 20 | void Timer4_IRQ(); 21 | #endif 22 | 23 | /*EDN***************************************************************************/ 24 | 25 | /*EXIT***************************************************************************/ 26 | #ifdef USE_EXTI0 27 | extern void EXTI0_IRQ(); 28 | #endif 29 | #ifdef USE_EXTI1 30 | extern void EXTI1_IRQ(); 31 | #endif 32 | #ifdef USE_EXTI2 33 | extern void EXTI2_IRQ(); 34 | #endif 35 | #ifdef USE_EXTI3 36 | extern void EXTI3_IRQ(); 37 | #endif 38 | #ifdef USE_EXTI4 39 | extern void EXTI4_IRQ(); 40 | #endif 41 | #ifdef USE_EXTI5 42 | extern void EXTI5_IRQ(); 43 | #endif 44 | #ifdef USE_EXTI6 45 | extern void EXTI6_IRQ(); 46 | #endif 47 | #ifdef USE_EXTI7 48 | extern void EXTI7_IRQ(); 49 | #endif 50 | #ifdef USE_EXTI8 51 | extern void EXTI8_IRQ(); 52 | #endif 53 | #ifdef USE_EXTI9 54 | extern void EXTI9_IRQ(); 55 | #endif 56 | #ifdef USE_EXTI10 57 | extern void EXTI10_IRQ(); 58 | #endif 59 | #ifdef USE_EXTI11 60 | extern void EXTI11_IRQ(); 61 | #endif 62 | #ifdef USE_EXTI12 63 | extern void EXTI12_IRQ(); 64 | #endif 65 | #ifdef USE_EXTI13 66 | extern void EXTI13_IRQ(); 67 | #endif 68 | #ifdef USE_EXTI14 69 | extern void EXTI14_IRQ(); 70 | #endif 71 | #ifdef USE_EXTI15 72 | extern void EXTI15_IRQ(); 73 | #endif 74 | /*END****************************************************************************/ 75 | 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /tool/clean_project_files.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Neutree/STM32f103DriverLib/28dfb70b6b0aa8e0de940ae8aa417a3989dbe3a5/tool/clean_project_files.bat --------------------------------------------------------------------------------