├── .gitignore ├── CORE ├── core_cm3.c ├── core_cm3.h ├── startup_stm32f10x_hd.s └── startup_stm32f10x_md.s ├── HARDWARE ├── FLASH │ ├── flash.c │ └── flash.h ├── LED │ ├── led.c │ └── led.h └── SPI │ ├── spi.c │ └── spi.h ├── KEY ├── CompositeKey.cpp ├── CompositeKey.h ├── Const.cpp ├── Const.h ├── ContentKey.cpp ├── ContentKey.h ├── DefineKey.h ├── DefineKeyLayer.h ├── FunctionKey.cpp ├── FunctionKey.h ├── Key.cpp ├── Key.h ├── KeyCode.cpp ├── KeyCode.h ├── KeyCodeStanderd.h ├── KeyState.cpp ├── KeyState.h ├── tool.cpp └── tool.h ├── README.md ├── SCHDOC ├── cherry轴元件库.zip ├── keyboard_IO.pdf ├── keyboard_core.pdf ├── locating board.DXF ├── ourdev_692986N5FAHU.pdf └── shell.stl ├── STM32F10x_FWLib ├── inc │ ├── misc.h │ ├── stm32f10x_adc.h │ ├── stm32f10x_bkp.h │ ├── stm32f10x_can.h │ ├── stm32f10x_cec.h │ ├── stm32f10x_crc.h │ ├── stm32f10x_dac.h │ ├── stm32f10x_dbgmcu.h │ ├── stm32f10x_dma.h │ ├── stm32f10x_exti.h │ ├── stm32f10x_flash.h │ ├── stm32f10x_fsmc.h │ ├── stm32f10x_gpio.h │ ├── stm32f10x_i2c.h │ ├── stm32f10x_iwdg.h │ ├── stm32f10x_pwr.h │ ├── stm32f10x_rcc.h │ ├── stm32f10x_rtc.h │ ├── stm32f10x_sdio.h │ ├── stm32f10x_spi.h │ ├── stm32f10x_tim.h │ ├── stm32f10x_usart.h │ └── stm32f10x_wwdg.h └── src │ ├── misc.c │ ├── stm32f10x_adc.c │ ├── stm32f10x_bkp.c │ ├── stm32f10x_can.c │ ├── stm32f10x_cec.c │ ├── stm32f10x_crc.c │ ├── stm32f10x_dac.c │ ├── stm32f10x_dbgmcu.c │ ├── stm32f10x_dma.c │ ├── stm32f10x_exti.c │ ├── stm32f10x_flash.c │ ├── stm32f10x_fsmc.c │ ├── stm32f10x_gpio.c │ ├── stm32f10x_i2c.c │ ├── stm32f10x_iwdg.c │ ├── stm32f10x_pwr.c │ ├── stm32f10x_rcc.c │ ├── stm32f10x_rtc.c │ ├── stm32f10x_sdio.c │ ├── stm32f10x_spi.c │ ├── stm32f10x_tim.c │ ├── stm32f10x_usart.c │ └── stm32f10x_wwdg.c ├── SYSTEM ├── delay │ ├── delay.c │ └── delay.h ├── sys │ ├── sys.c │ └── sys.h └── usart │ ├── usart.c │ └── usart.h ├── USB ├── CONFIG │ ├── hw_config.c │ ├── hw_config.h │ ├── platform_config.h │ ├── usb_conf.h │ ├── usb_desc.c │ ├── usb_desc.h │ ├── usb_endp.c │ ├── usb_istr.c │ ├── usb_istr.h │ ├── usb_prop.c │ ├── usb_prop.h │ ├── usb_pwr.c │ └── usb_pwr.h └── STM32_USB-FS-Device_Driver │ ├── inc │ ├── usb_core.h │ ├── usb_def.h │ ├── usb_init.h │ ├── usb_int.h │ ├── usb_lib.h │ ├── usb_mem.h │ ├── usb_regs.h │ ├── usb_sil.h │ └── usb_type.h │ └── src │ ├── usb_core.c │ ├── usb_init.c │ ├── usb_int.c │ ├── usb_mem.c │ ├── usb_regs.c │ └── usb_sil.c ├── USER ├── CoopBoard.uvguix_chaofan.bak ├── CoopBoard_Target 1.dep ├── CoopBoard_uvoptx.bak ├── CoopBoard_uvprojx.bak ├── JLinkSettings.ini ├── main.cpp ├── stm32f10x.h ├── stm32f10x_conf.h ├── stm32f10x_it.c ├── stm32f10x_it.h ├── system_stm32f10x.c └── system_stm32f10x.h └── bootloader ├── CMSIS ├── CM3 │ ├── CORE │ │ ├── core_cm3.c │ │ └── core_cm3.h │ ├── STARTUP │ │ ├── startup_stm32f10x_cl.s │ │ ├── startup_stm32f10x_hd.s │ │ ├── startup_stm32f10x_hd_vl.s │ │ ├── startup_stm32f10x_ld.s │ │ ├── startup_stm32f10x_ld_vl.s │ │ ├── startup_stm32f10x_md.s │ │ ├── startup_stm32f10x_md_vl.s │ │ └── startup_stm32f10x_xl.s │ ├── stm32f10x.h │ ├── stm32f10x_conf.h │ ├── stm32f10x_it.c │ ├── stm32f10x_it.h │ ├── system_stm32f10x.c │ └── system_stm32f10x.h └── STM32LIB │ ├── inc │ ├── misc.h │ ├── stm32f10x_adc.h │ ├── stm32f10x_bkp.h │ ├── stm32f10x_can.h │ ├── stm32f10x_cec.h │ ├── stm32f10x_crc.h │ ├── stm32f10x_dac.h │ ├── stm32f10x_dbgmcu.h │ ├── stm32f10x_dma.h │ ├── stm32f10x_exti.h │ ├── stm32f10x_flash.h │ ├── stm32f10x_fsmc.h │ ├── stm32f10x_gpio.h │ ├── stm32f10x_i2c.h │ ├── stm32f10x_iwdg.h │ ├── stm32f10x_pwr.h │ ├── stm32f10x_rcc.h │ ├── stm32f10x_rtc.h │ ├── stm32f10x_sdio.h │ ├── stm32f10x_spi.h │ ├── stm32f10x_tim.h │ ├── stm32f10x_usart.h │ └── stm32f10x_wwdg.h │ └── src │ ├── misc.c │ ├── stm32f10x_adc.c │ ├── stm32f10x_bkp.c │ ├── stm32f10x_can.c │ ├── stm32f10x_cec.c │ ├── stm32f10x_crc.c │ ├── stm32f10x_dac.c │ ├── stm32f10x_dbgmcu.c │ ├── stm32f10x_dma.c │ ├── stm32f10x_exti.c │ ├── stm32f10x_flash.c │ ├── stm32f10x_fsmc.c │ ├── stm32f10x_gpio.c │ ├── stm32f10x_i2c.c │ ├── stm32f10x_iwdg.c │ ├── stm32f10x_pwr.c │ ├── stm32f10x_rcc.c │ ├── stm32f10x_rtc.c │ ├── stm32f10x_sdio.c │ ├── stm32f10x_spi.c │ ├── stm32f10x_tim.c │ ├── stm32f10x_usart.c │ └── stm32f10x_wwdg.c ├── HARDWARE ├── KEY │ ├── key.c │ └── key.h └── STM32_config.h ├── STM32 DFU升级APP程序移植笔记.pdf ├── STM32 USB DFU做的升级程序中利用到同样中断时的处理办法.pdf ├── SYSTEM ├── delay │ ├── delay.c │ └── delay.h ├── sys │ ├── sys.c │ └── sys.h └── usart │ ├── usart.c │ └── usart.h ├── USB ├── Mass_Storage │ ├── inc │ │ ├── dfu_mal.h │ │ ├── hw_config.h │ │ ├── platform_config.h │ │ ├── usb_conf.h │ │ ├── usb_desc.h │ │ ├── usb_istr.h │ │ ├── usb_prop.h │ │ └── usb_pwr.h │ └── src │ │ ├── dfu_mal.c │ │ ├── hw_config.c │ │ ├── usb_desc.c │ │ ├── usb_istr.c │ │ ├── usb_prop.c │ │ └── usb_pwr.c └── USBLIB │ ├── inc │ ├── usb_core.h │ ├── usb_def.h │ ├── usb_init.h │ ├── usb_int.h │ ├── usb_lib.h │ ├── usb_mem.h │ ├── usb_regs.h │ ├── usb_sil.h │ └── usb_type.h │ └── src │ ├── usb_core.c │ ├── usb_init.c │ ├── usb_int.c │ ├── usb_mem.c │ ├── usb_regs.c │ └── usb_sil.c ├── USER ├── IAP_USB.uvproj └── main.c └── keilkilll.bat /.gitignore: -------------------------------------------------------------------------------- 1 | OBJ/ 2 | OBJ/ 3 | *.uvoptx 4 | *.uvguix.* 5 | *.uvprojx 6 | *.map 7 | *.hex 8 | *.lst 9 | !USER/CoopBoard.uvprojx 10 | -------------------------------------------------------------------------------- /HARDWARE/FLASH/flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/HARDWARE/FLASH/flash.c -------------------------------------------------------------------------------- /HARDWARE/FLASH/flash.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/HARDWARE/FLASH/flash.h -------------------------------------------------------------------------------- /HARDWARE/LED/led.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/HARDWARE/LED/led.c -------------------------------------------------------------------------------- /HARDWARE/LED/led.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/HARDWARE/LED/led.h -------------------------------------------------------------------------------- /HARDWARE/SPI/spi.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/HARDWARE/SPI/spi.c -------------------------------------------------------------------------------- /HARDWARE/SPI/spi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/HARDWARE/SPI/spi.h -------------------------------------------------------------------------------- /KEY/CompositeKey.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #include "CompositeKey.h" 6 | 7 | void CompositeKey::beforeAllProcess(KeyState &ks) { 8 | Key::beforeAllProcess(ks); 9 | if(ks.isDown(rc_place.getRow(), rc_place.getCol())) { 10 | ks.composite_mark |= this->compositeByte; 11 | } 12 | } 13 | 14 | void CompositeKey::whenKeyDown(KeyState &ks) { 15 | // do nothing 16 | } 17 | 18 | void CompositeKey::afterAllProcess(KeyState &ks) { 19 | if( 20 | ks.isDown(rc_place.getRow(), rc_place.getCol()) 21 | && 22 | ks.code_to_send.size() == 0 23 | ) { 24 | ks.code_to_send.push_back(KeyCode(0, this->compositeByte)); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /KEY/CompositeKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_COMPOSITEKEY_H 6 | #define CPPTEST_COMPOSITEKEY_H 7 | 8 | #include "Key.h" 9 | #include "Const.h" 10 | 11 | /** 12 | * 此类表示 Ctrl,Alt,Shift 三键操作 13 | * 主要通过 14 | */ 15 | class CompositeKey : public Key { 16 | public: 17 | CompositeKey(const KeyPlace &rc_place, const ExactPlace &xy_place, const char composite_bit): 18 | Key(rc_place, xy_place), compositeByte(composite_bit) {} 19 | 20 | CompositeKey(const char r, const char c, const float x, const float y, const char composite_bit): 21 | Key(r,c,x,y), compositeByte(composite_bit) {} 22 | virtual void beforeAllProcess(KeyState &ks); 23 | 24 | /** 25 | * @brief 监测到该键按下时调用,修改ks中composite标志 26 | * @param ks 27 | */ 28 | virtual void whenKeyDown(KeyState &ks); 29 | /** 30 | * @brief 所有键按下之后的后处理 31 | * @details 用于将未确定的键自动降层到 大层(8小层的倍数) + 自身的组合键 32 | * 例如: 33 | * ctrl + shift + 左 34 | * 按下时 35 | * 情况1,应该在(ctrl | shift)的mini层上发送左键盘码。 36 | * 情况2,如果shift + 左 被定义为 a,则该发送 ctrl + a 键盘码。 37 | * 此函数操作为,对每个未确定的按键: 38 | * 1. 去掉this(假设为ctrl)键,是定义的键码(对应情况2)=> 相应键码加入发送队列 39 | * 2. 去掉this(假设为ctrl)键,还不是键码(对应情况1)=> 修改未确定队列中的元素 40 | * @param ks 41 | */ 42 | virtual void afterAllProcess(KeyState &ks); 43 | 44 | private: 45 | char compositeByte; ///> 组合位,设置成 1 2 4 之类 46 | }; 47 | 48 | 49 | #endif //CPPTEST_COMPOSITEKEY_H 50 | -------------------------------------------------------------------------------- /KEY/Const.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/30. 3 | // 4 | 5 | #include "Const.h" 6 | 7 | const char ROW_LENGTH[MAX_ROW] = {14, 13, 14, 12}; 8 | -------------------------------------------------------------------------------- /KEY/Const.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_CONST_H 6 | #define CPPTEST_CONST_H 7 | 8 | #define MAX_ROW 4 9 | #define MAX_COL 14 10 | extern const char ROW_LENGTH[MAX_ROW]; 11 | 12 | 13 | #define COMPOSITE_KEY_NUM 4 14 | 15 | #endif //CPPTEST_CONST_H 16 | -------------------------------------------------------------------------------- /KEY/ContentKey.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #include "ContentKey.h" 6 | 7 | void ContentKey::whenKeyDown(KeyState &ks) { 8 | unsigned int mini_layer = ks.getMiniLayer(); 9 | unsigned char raw = rc_place.getRow(); 10 | unsigned char col = rc_place.getCol(); 11 | // 查看是否可以直接生成传送键码,否则对降层,尝试其他键码 12 | if (codeMap->isSendable(mini_layer, raw, col)) { 13 | ks.code_to_send.push_back(codeMap->getKeyCode(mini_layer, raw, col)); 14 | } else if(mini_layer & 15) { // 如果是因为miniLayer中导致的没有键码,则自动判断 15 | // 尝试去掉一些composite键,查找键码 16 | static const unsigned char mark[] = {/*去掉一个*/1, 2, 4, 8, /*去掉两个*/3, 5, 6, 9, 10, 12, /*去掉三个*/7, 11, 13, 14, 15}; 17 | for (int j = 0; j < sizeof(mark); ++j) { 18 | unsigned char composite = (unsigned char)mini_layer & mark[j]; 19 | if (!composite) continue; // 没有按下该位的composite键 20 | if (codeMap->isSendable(mini_layer - composite, raw, col)) { 21 | KeyCode code = codeMap->getKeyCode(mini_layer - composite, raw, col); 22 | code.setComposite(code.getComposite() | composite); 23 | ks.code_to_send.push_back(code); 24 | return; 25 | } 26 | // 如果在mini层找不到,就不会做任何动作了 27 | } 28 | } 29 | } 30 | 31 | void ContentKey::keepDown(KeyState &ks) { // 按下时,在跳沿监测结束后 32 | Key::keepDown(ks); 33 | ContentKey::whenKeyDown(ks); 34 | } 35 | -------------------------------------------------------------------------------- /KEY/ContentKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_CONTENTKEY_H 6 | #define CPPTEST_CONTENTKEY_H 7 | 8 | #include "Key.h" 9 | 10 | class ContentKey : public Key { 11 | public: 12 | ContentKey(const KeyPlace &rc_place, const ExactPlace &xy_place) : Key(rc_place, xy_place) {} 13 | ContentKey(const char r, const char c, const float x, const float y) : Key(r,c,x,y) {} 14 | virtual void whenKeyDown(KeyState &ks); 15 | virtual void keepDown(KeyState &ks); 16 | }; 17 | 18 | 19 | #endif //CPPTEST_CONTENTKEY_H 20 | -------------------------------------------------------------------------------- /KEY/DefineKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/30. 3 | // 4 | 5 | #ifndef CPPTEST_DEFINEKEY_H 6 | #define CPPTEST_DEFINEKEY_H 7 | 8 | #include "Key.h" 9 | #include "CompositeKey.h" 10 | #include "ContentKey.h" 11 | #include "FunctionKey.h" 12 | 13 | typedef ContentKey KK; 14 | typedef CompositeKey CK; 15 | typedef FunctionKey FK; 16 | #define DefK(KT, r, c, x, y, args...) do { Key::setKey(r, c, new KT(r, c, x, y, ##args));} while(0) 17 | 18 | void define_key() { 19 | Key::keyboardClear(); 20 | DefK(CK, 2, 0, 0, 0, KB_SHIFT); // shift 21 | DefK(CK, 3, 0, 0, 0, KB_CTRL); // ctrl 22 | DefK(CK, 3, 2, 0, 0, KB_ALT); // alt 23 | DefK(CK, 3, 3, 0, 0, KB_WIN); // command 24 | DefK(FK, 2, 1, 0, 0, 1); // fn1 25 | DefK(FK, 3, 1, 0, 0, 2); // fn2 26 | DefK(FK, 3, 4, 0, 0, 3); // fn3 27 | DefK(FK, 3, 8, 0, 0, 4); // fn4 28 | //DefK(FK, 2, 13, 0, 0, 5); // fn5 29 | // define other keys as ContentKey 30 | for (char i = 0; i < MAX_ROW; ++i) { 31 | for (char j = 0; j < ROW_LENGTH[i]; ++j) { 32 | if (!Key::getKey(i, j)) { 33 | Key::setKey(i, j, new KK(i, j, 0, 0)); 34 | } 35 | } 36 | } 37 | } 38 | 39 | #endif //CPPTEST_DEFINEKEY_H 40 | -------------------------------------------------------------------------------- /KEY/DefineKeyLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/30. 3 | // 4 | 5 | #ifndef CPPTEST_DEFINEKEYLAYER_H 6 | #define CPPTEST_DEFINEKEYLAYER_H 7 | 8 | #include "Const.h" 9 | #include "KeyCodeStanderd.h" 10 | #include "KeyCode.h" 11 | 12 | ///??? 13 | typedef KeyCode C; 14 | KeyCode layer0[MAX_ROW][MAX_COL] = 15 | { // layer 0 default 16 | // row 1 17 | {C(KB_TAB), C(KB_Q), C(KB_W), C(KB_E), C(KB_R), C(KB_T), C(KB_Y), C(KB_U), C(KB_I), C(KB_O), C(KB_P), C(KB_LEFT_BRACKET), C(KB_RIGHT_BRACKET), C(KB_DEL)}, 18 | // row 2 19 | {C(KB_CAPSLOCK), C(KB_A), C(KB_S), C(KB_D), C(KB_F), C(KB_G), C(KB_H), C(KB_J), C(KB_K), C(KB_L), C(KB_SEMICOLON), C(KB_QUOTES), C(KB_RETURN)}, 20 | // row 3 21 | {C(), C(), C(KB_Z), C(KB_X), C(KB_C), C(KB_V), C(KB_B), C(KB_N), C(KB_M), C(KB_COMMA), C(KB_END_MARK), C(KB_SLASH), C(KB_UP_ARROW), C(KB_DELETE_FORWARD)}, 22 | // row 4 23 | {C(), C(), C(), C(), C(), C(KB_SPACE), C(KB_SPACE), C(KB_RIGHT_CLICK), C(), C(KB_LEFT_ARROW), C(KB_DOWN_ARROW), C(KB_RIGHT_ARROW)}, 24 | }; 25 | KeyCode minilayer1[MAX_ROW][MAX_COL] = 26 | { // layer 0 default ctrl 27 | // row 1 28 | {}, 29 | // row 2 30 | {}, 31 | // row 3 32 | {C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(KB_BACK_SLASH), C(), C()}, 33 | }; 34 | KeyCode layer1[MAX_ROW][MAX_COL] = 35 | { // layer 8 f1 number mini board implement 36 | // row 1 Q W E R T Y U I O P [ ] DEL 37 | {C(KB_BACK_QUOTES), C(KB_1), C(KB_2), C(KB_3), C(KB_4), C(KB_5), C(KB_6), C(KB_7), C(KB_8), C(KB_9), C(KB_0), C(KB_MINUS), C(KB_EQUAL), C(KB_DEL)}, 38 | // row 2 A S D F G H J K L ; ' ENTER 39 | {C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(KB_QUOTES), C(KB_RETURN)}, 40 | // row 3 SHIFTZ X C V B N M ,< .> /? ^ 41 | {C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(KB_BACK_SLASH), C(KB_PRT_SCR), C()}, 42 | // row 4 f3 f4 CTRL ALT SPACE1 SPACE2 f5 CTRL < v > 43 | {C(), C(), C(), C(), C(), C(KB_SPACE), C(KB_SPACE), C(), C(), C(KB_VOLUME_UP), C(KB_VOLUME_MUTE), C(KB_VOLUME_DOWN)}, 44 | }; 45 | KeyCode layer2[MAX_ROW][MAX_COL] = 46 | { // layer 2 f2 F1-F12 Layer [function keys] 47 | // row 1 Q W E R T Y U I O P [ ] DEL 48 | {C(KB_ESC), C(KB_F1), C(KB_F2), C(KB_F3), C(KB_F4), C(KB_F5), C(KB_F6), C(KB_F7), C(KB_F8), C(KB_F9), C(KB_F10), C(KB_F11), C(KB_F12), C(KB_DEL)}, 49 | // row 2 A S D F G H J K L ; ' ENTER 50 | {C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(KB_RETURN)}, 51 | // row 3 SHIFTZ X C V B N M ,< .> /? ^ f6 52 | {C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(KB_UP_ARROW), C()}, 53 | // row 4 f3 f4 CTRL ALT SPACE1 SPACE2 f5 CTRL < v > 54 | {C(), C(), C(), C(), C(), C(KB_0), C(KB_SPACE), C(), C(), C(KB_LEFT_ARROW), C(KB_DOWN_ARROW), C(KB_RIGHT_ARROW)}, 55 | }; 56 | KeyCode layer3[MAX_ROW][MAX_COL] = 57 | { // layer 3 f3 HOME END INSERT DELETE ... [control keys] 58 | // row 1 Q W E R T Y U I O P [ ] DEL 59 | {C(135), C(136), C(137), C(138), C(139), C(140), C(141), C(142), C(143), C(144), C(145), C(146), C(147), C(148)}, 60 | // row 2 A S D F G H J K L ; ' ENTER 61 | {C(149), C(150), C(151), C(152), C(153), C(154), C(155), C(156), C(157), C(158), C(159), C(160), C(161)}, 62 | // row 3 SHIFTZ X C V B N M ,< .> /? ^ f6 63 | {C(), C(), C(162), C(163), C(164), C(165), C(166), C(167), C(168), C(169), C(170), C(171), C(172), C(173)}, 64 | // row 4 f3 f4 CTRL ALT SPACE1 SPACE2 f5 CTRL < v > 65 | {C(), C(), C(), C(), C(), C(174), C(175), C(176), C(), C(177), C(178), C(179)}, 66 | }; 67 | KeyCode layer4[MAX_ROW][MAX_COL] = 68 | { // layer 4 f4 69 | // row 1 70 | // row 1 Q W E R T Y U I O P [ ] DEL 71 | {C(KB_BACK_QUOTES, KB_SHIFT), C(KB_1, KB_SHIFT), C(KB_2, KB_SHIFT), C(KB_3, KB_SHIFT), C(KB_4, KB_SHIFT), C(KB_5, KB_SHIFT), C(KB_6, KB_SHIFT), C(KB_7, KB_SHIFT), C(KB_8, KB_SHIFT), C(KB_9, KB_SHIFT), C(KB_0, KB_SHIFT), C(KB_MINUS, KB_SHIFT), C(KB_EQUAL, KB_SHIFT), C(KB_DEL)}, 72 | // row 2 A S D F G H J K L ; ' ENTER 73 | {C(KB_BACK_QUOTES), C(KB_1), C(KB_2), C(KB_3), C(KB_4), C(KB_5), C(KB_6), C(KB_7), C(KB_8), C(KB_9), C(KB_0), C(KB_MINUS), C(KB_EQUAL)}, 74 | // row 3 SHIFTZ X C V B N M ,< .> /? ^ f6 75 | {C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(), C(KB_UP_ARROW), C()}, 76 | // row 4 f3 f4 CTRL ALT SPACE1 SPACE2 f5 CTRL < v > 77 | {C(), C(), C(), C(), C(), C(KB_SPACE), C(KB_SPACE), C(), C(), C(KB_LEFT_ARROW), C(KB_DOWN_ARROW), C(KB_RIGHT_ARROW)}, 78 | }; 79 | 80 | /*KeyCode layer5[MAX_ROW][MAX_COL] = 81 | { // layer 5 f5 82 | // row 1 83 | {C(KB_TAB)} 84 | };*/ 85 | 86 | void define_key_layer(CodeMap* codeMap) { 87 | codeMap->setLayer(0, layer0); 88 | codeMap->setMiniLayer(0, KB_CTRL, minilayer1); 89 | codeMap->setLayer(1, layer1); 90 | codeMap->setLayer(2, layer2); 91 | codeMap->setLayer(3, layer3); 92 | codeMap->setLayer(4, layer4); 93 | //codeMap->setLayer(5, layer5); 94 | } 95 | 96 | #endif //CPPTEST_DEFINEKEYLAYER_H 97 | -------------------------------------------------------------------------------- /KEY/FunctionKey.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #include "FunctionKey.h" 6 | 7 | 8 | void FunctionKey::beforeAllProcess(KeyState &ks) { 9 | Key::beforeAllProcess(ks); 10 | if(ks.isDown(rc_place.getRow(), rc_place.getCol())) { 11 | ks.fn_layer = this->layer; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /KEY/FunctionKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_FUNCTIONKEY_H 6 | #define CPPTEST_FUNCTIONKEY_H 7 | 8 | #include "Key.h" 9 | 10 | class FunctionKey : public Key{ 11 | public: 12 | FunctionKey(const KeyPlace &rc_place, const ExactPlace &xy_place, const unsigned char layer): 13 | Key(rc_place ,xy_place), layer(layer) {} 14 | FunctionKey(const char r, const char c, const float x, const float y, const unsigned char layer) : Key(r,c,x,y), layer(layer) {} 15 | 16 | virtual void beforeAllProcess(KeyState &ks); 17 | 18 | private: 19 | unsigned char layer; 20 | }; 21 | 22 | 23 | #endif //CPPTEST_FUNCTIONKEY_H 24 | -------------------------------------------------------------------------------- /KEY/Key.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "delay.h" 9 | #include "sys.h" 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #include "Key.h" 16 | #include "tool.h" 17 | 18 | CodeMap* Key::codeMap; 19 | Key* Key::keyboard[MAX_ROW * MAX_COL]; 20 | 21 | void Key::KEY_Init(void) //初始化矩阵键盘要使用的GPIO口。 22 | { 23 | GPIO_InitTypeDef GPIO_InitStructure; 24 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 25 | 26 | GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); 27 | 28 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//ROW1\2\3\4\5\6 29 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //定义PC0到PC5为推挽输出、、。11110->11101->11011->10111->01111->11110 30 | GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; 31 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; 32 | GPIO_Init(GPIOC,&GPIO_InitStructure); 33 | 34 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//COL1\2\3\4\5\6\7\8\9\10\11 35 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //定义PB0\1\3\4\5\6\7\8\9\10\11上拉输入 36 | GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; 37 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11; 38 | GPIO_Init(GPIOB,&GPIO_InitStructure); 39 | 40 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//COL12\13\14 41 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //定义PC6\7\8为上拉输入 42 | GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; 43 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8; 44 | GPIO_Init(GPIOC,&GPIO_InitStructure); 45 | 46 | } 47 | 48 | 49 | void Key::updateCOL(bool* col) 50 | { 51 | col[0]=!COL1; 52 | col[1]=!COL2; 53 | col[2]=!COL3; 54 | col[3]=!COL4; 55 | col[4]=!COL5; 56 | col[5]=!COL6; 57 | col[6]=!COL7; 58 | col[7]=!COL8; 59 | col[8]=!COL9; 60 | col[9]=!COL10; 61 | col[10]=!COL11; 62 | col[11]=!COL12; 63 | col[12]=!COL13; 64 | col[13]=!COL14; 65 | } 66 | void disable(unsigned char* col) { 67 | for (int i = 0; i < MAX_COL; i++) { 68 | col[i] = 0; 69 | } 70 | } 71 | 72 | void Key::scanKeys(KeyState & ks) { 73 | 74 | // disable(ks.origin[0]); 75 | // disable(ks.origin[1]); 76 | // disable(ks.origin[2]); 77 | // disable(ks.origin[3]); 78 | //让row1到row6输出二进制的011111. 79 | ROW1=0; ROW2=1; ROW3=1; ROW4=1; ROW5=1; ROW6=1; 80 | delay_us(10); 81 | updateCOL(ks.origin[0]); 82 | ROW1=1; ROW2=0; ROW3=1; ROW4=1; ROW5=1; ROW6=1; 83 | delay_us(10); 84 | updateCOL(ks.origin[1]); 85 | ROW1=1; ROW2=1; ROW3=0; ROW4=1; ROW5=1; ROW6=1; 86 | delay_us(10); 87 | updateCOL(ks.origin[2]); 88 | ROW1=1; ROW2=1; ROW3=1; ROW4=0; ROW5=1; ROW6=1; 89 | delay_us(10); 90 | updateCOL(ks.origin[3]); 91 | } 92 | 93 | 94 | void Key::decodeKeyCode(KeyState & ks) { 95 | static bool pre_ks[MAX_ROW][MAX_COL]; 96 | static char pre_fn_layer; // 这是为了做一个fn层切换延迟,防止误触的。 97 | if (ks.sameOrigin(pre_ks)) { 98 | return; 99 | } 100 | 101 | for (int i = 0; i < MAX_ROW; ++i) { 102 | for (int j = 0; j < ROW_LENGTH[i]; ++j) { 103 | if (keyboard[i * MAX_COL + j]) keyboard[i * MAX_COL + j]->beforeAllProcess(ks); 104 | } 105 | } 106 | 107 | for (int i = 0; i < MAX_ROW; ++i) { 108 | for (int j = 0; j < ROW_LENGTH[i]; ++j) { 109 | if (keyboard[i * MAX_COL + j]) { 110 | if (ks.isDown(i, j) && pre_ks[i][j]) { 111 | keyboard[i * MAX_COL + j]->keepDown(ks); 112 | } else if (!ks.isDown(i, j) && !pre_ks[i][j]) { 113 | keyboard[i * MAX_COL + j]->keepUp(ks); 114 | } 115 | } 116 | } 117 | } 118 | // 挑檐信息更重要,放在之后处理。键码之后的更重要。 119 | for (int i = 0; i < MAX_ROW; ++i) { 120 | for (int j = 0; j < ROW_LENGTH[i]; ++j) { 121 | if (keyboard[i * MAX_COL + j]) { 122 | if (ks.isDown(i, j) && !pre_ks[i][j]) { 123 | keyboard[i * MAX_COL + j]->whenKeyDown(ks); 124 | } else if (!ks.isDown(i, j) && pre_ks[i][j]) { 125 | keyboard[i * MAX_COL + j]->whenKeyUp(ks); 126 | } 127 | } 128 | } 129 | } 130 | 131 | for (int i = 0; i < MAX_ROW; ++i) { 132 | for (int j = 0; j < ROW_LENGTH[i]; ++j) { 133 | if (keyboard[i * MAX_COL + j]) { 134 | keyboard[i * MAX_COL + j]->afterAllProcess(ks); 135 | } 136 | } 137 | } 138 | for (int i = 0; i < MAX_ROW; ++i) { 139 | for (int j = 0; j < ROW_LENGTH[i]; ++j) { 140 | if (keyboard[i * MAX_COL + j]) { 141 | keyboard[i * MAX_COL + j]->beforeKeyCodeSend(ks); 142 | } 143 | } 144 | } 145 | 146 | if (pre_fn_layer > ks.fn_layer) { 147 | // 逻辑是在fn下降层数之后(抬起按键)。总是等待一段时间再检测,防止其他被组合的按键没有抬起来。 148 | delay_ms(100); 149 | pre_fn_layer = ks.fn_layer; 150 | return; 151 | } 152 | tool::sent_key_code(ks.code_to_send); 153 | ks.copyOrigin(pre_ks); 154 | pre_fn_layer = ks.fn_layer; 155 | } 156 | -------------------------------------------------------------------------------- /KEY/Key.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_KEY_H 6 | #define CPPTEST_KEY_H 7 | 8 | #include "KeyState.h" 9 | #include "KeyCode.h" 10 | #include "KeyCodeStanderd.h" 11 | #include "Const.h" 12 | 13 | class Key { 14 | public: 15 | Key(const KeyPlace &rc_place, const ExactPlace &xy_place) : 16 | rc_place(rc_place), xy_place(xy_place) {} 17 | Key(const char * a, const float * b) : rc_place(a[0], a[1]), xy_place(b[0], b[1]) {} 18 | Key(const char r, const char c, const float x, const float y) : rc_place(r, c), xy_place(x, y) {} 19 | static void KEY_Init(void); 20 | static void updateCOL(bool* col); 21 | static void scanKeys(KeyState & ks); 22 | static void decodeKeyCode(KeyState & ks); 23 | virtual void whenKeyDown(KeyState & ks) {}; 24 | virtual void whenKeyUp(KeyState & ks) {}; 25 | virtual void keepDown(KeyState &ks) {}; 26 | virtual void keepUp(KeyState &ks) {}; 27 | virtual void beforeAllProcess(KeyState & ks) {}; 28 | virtual void afterAllProcess(KeyState & ks) {}; 29 | virtual void beforeKeyCodeSend(KeyState & ks) {}; 30 | 31 | // 此方法不传递所有权 32 | static void setCodeMap(CodeMap * codeMap) { Key::codeMap = codeMap; } 33 | static void setKey(char i, char j, Key * kp) { keyboard[i * MAX_COL + j] = kp;} 34 | static Key* getKey(char i, char j) { return keyboard[i * MAX_COL + j]; } 35 | static void keyboardClear() { for (int i = 0; i < MAX_ROW * MAX_COL; ++i) { delete keyboard[i]; keyboard[i] = NULL; }} 36 | protected: 37 | KeyPlace rc_place; 38 | ExactPlace xy_place; 39 | static CodeMap* codeMap; 40 | static Key* keyboard[MAX_ROW * MAX_COL]; 41 | }; 42 | 43 | 44 | #endif //CPPTEST_KEY_H 45 | -------------------------------------------------------------------------------- /KEY/KeyCode.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #include "KeyCode.h" 6 | #include "KeyCodeStanderd.h" 7 | #include "CompositeKey.h" 8 | #include "vector" 9 | void CodeLayer::setCodes(KeyCode layer[MAX_ROW][MAX_COL]) { 10 | codes = layer; 11 | // clear(); 12 | // codes[3].resize(1); 13 | // std::vector s; 14 | // s.resize(4); 15 | // codes[2].resize(1); 16 | // codes[1].resize(1); 17 | // codes[0].resize(1); 18 | // 19 | // for (char i = 1; i < MAX_ROW; i++) { 20 | // for (int j = MAX_COL - 10; j >=0 && j < MAX_COL; j--) { 21 | // if (layer[i][j].isSendable()) { 22 | //// if (codes[i].size() <= j) { 23 | //// codes[i].resize(j + 1); 24 | //// } 25 | // codes[i].operator[](j) = new KeyCode(layer[i][j].getCode(), layer[i][j].getComposite()); 26 | // } 27 | // } 28 | // } 29 | } 30 | 31 | KeyCode CodeLayer::getCode(unsigned char row, unsigned char col) const { 32 | if (row >= MAX_ROW || col >= MAX_COL || codes == NULL) { 33 | return KeyCode(); 34 | } else { 35 | return codes[row][col]; 36 | } 37 | } 38 | 39 | CodeMap * CodeMap::defaultCodeMap = new CodeMap(); 40 | 41 | bool CodeMap::isSendable(unsigned int mini_layer, unsigned char row, unsigned char col) { 42 | if (mini_layer >= layers.size()) { 43 | return false; 44 | } 45 | return layers[mini_layer]->getCode(row, col).isSendable(); 46 | } 47 | 48 | void CodeMap::setLayer(unsigned int big_layer_index, KeyCode layer[MAX_ROW][MAX_COL]) { 49 | setMiniLayer(big_layer_index, 0, layer); 50 | } 51 | 52 | void CodeMap::setMiniLayer(unsigned int big_layer_index, unsigned char layer_inner_index, KeyCode layer[MAX_ROW][MAX_COL]) { 53 | unsigned int layer_index = (big_layer_index << COMPOSITE_KEY_NUM) + layer_inner_index; 54 | if (layers.size() <= layer_index) resize(layer_index + 1); 55 | layers[layer_index]->setCodes(layer); 56 | } 57 | 58 | KeyCode CodeMap::getKeyCode(unsigned int mini_layer, unsigned char row, unsigned char col) { 59 | if (mini_layer >= layers.size()) { 60 | KeyCode empty_code; 61 | return empty_code; 62 | } else { 63 | return layers[mini_layer]->getCode(row, col); 64 | } 65 | 66 | } 67 | 68 | void CodeMap::resize(size_t n) { 69 | int old = layers.size(); 70 | layers.resize(n); 71 | for (int i = old; i < n; ++i) { 72 | layers[i] = new CodeLayer; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /KEY/KeyCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_KEYCODE_H 6 | #define CPPTEST_KEYCODE_H 7 | 8 | #include 9 | #include 10 | #include "Const.h" 11 | #include 12 | 13 | class KeyCode { 14 | public: 15 | KeyCode(unsigned char code = 0, unsigned char composite = 0) : composite(composite), code(code) {} 16 | KeyCode(const KeyCode& that) : composite(that.composite), code(that.code) {} 17 | bool isSendable()const { return (bool)(code | composite); } 18 | unsigned char getComposite() const { return composite; } 19 | void setComposite(unsigned char composite) { KeyCode::composite = composite; } 20 | unsigned char getCode() const { return code; } 21 | void setCode(unsigned char code) { KeyCode::code = code; } 22 | 23 | private: 24 | unsigned char composite; 25 | unsigned char code; 26 | }; 27 | 28 | class CodeLayer { 29 | public: 30 | CodeLayer() { // 这个函数保证不被设置的空layer中没有元素 31 | codes = NULL; 32 | } 33 | KeyCode getCode(unsigned char row, unsigned char col) const; 34 | void setCodes(KeyCode layer[MAX_ROW][MAX_COL]); 35 | void clear() {codes=NULL;} 36 | private: 37 | KeyCode (*codes)[MAX_COL]; 38 | 39 | }; 40 | 41 | class CodeMap { 42 | public: 43 | CodeMap() {} 44 | bool isSendable(unsigned int mini_layer, unsigned char row, unsigned char col); 45 | void setLayer(unsigned int big_layer_index, KeyCode layer[MAX_ROW][MAX_COL]); 46 | void setMiniLayer(unsigned int big_layer_index, unsigned char layer_inner_index, KeyCode layer[MAX_ROW][MAX_COL]); 47 | KeyCode getKeyCode(unsigned int mini_layer, unsigned char row, unsigned char col); 48 | const CodeLayer &getLayer(const unsigned int i) const { return *layers[i]; } 49 | void resize(size_t n); 50 | static CodeMap *defaultCodeMap; 51 | private: 52 | std::vector layers; 53 | 54 | }; 55 | 56 | #endif //CPPTEST_KEYCODE_H 57 | -------------------------------------------------------------------------------- /KEY/KeyCodeStanderd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_KEYCODESTANDERD_H_H 6 | #define CPPTEST_KEYCODESTANDERD_H_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "sys.h" 13 | #define ROW1 PCout(0) // PC0 14 | #define ROW2 PCout(1) // PC1 15 | #define ROW3 PCout(2) // PC2 16 | #define ROW4 PCout(3) // PC3 17 | #define ROW5 PCout(4) // PC4 18 | #define ROW6 PCout(5) // PC5 19 | 20 | #define COL1 PBin(0); 21 | #define COL2 PBin(1); 22 | #define COL3 PBin(3); 23 | #define COL4 PBin(4); 24 | #define COL5 PBin(5); 25 | #define COL6 PBin(6); 26 | #define COL7 PBin(7); 27 | #define COL8 PBin(8); 28 | #define COL9 PBin(9); 29 | #define COL10 PBin(10); 30 | #define COL11 PBin(11); 31 | #define COL12 PCin(6); 32 | #define COL13 PCin(7); 33 | #define COL14 PCin(8); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #define KB_NULL 0 40 | #define KB_RESERVED 0 41 | #define KB_ErrorRollOver 1 42 | #define KB_POSTFail 2 43 | #define KB_ErrorUndefined 3 44 | #define KB_A 4 45 | #define KB_B 5 46 | #define KB_C 6 47 | #define KB_D 7 48 | #define KB_E 8 49 | #define KB_F 9 50 | #define KB_G 10 51 | #define KB_H 11 52 | #define KB_I 12 53 | #define KB_J 13 54 | #define KB_K 14 55 | #define KB_L 15 56 | #define KB_M 16 57 | #define KB_N 17 58 | #define KB_O 18 59 | #define KB_P 19 60 | #define KB_Q 20 61 | #define KB_R 21 62 | #define KB_S 22 63 | #define KB_T 23 64 | #define KB_U 24 65 | #define KB_V 25 66 | #define KB_W 26 67 | #define KB_X 27 68 | #define KB_Y 28 69 | #define KB_Z 29 70 | #define KB_1 30 71 | #define KB_2 31 72 | #define KB_3 32 73 | #define KB_4 33 74 | #define KB_5 34 75 | #define KB_6 35 76 | #define KB_7 36 77 | #define KB_8 37 78 | #define KB_9 38 79 | #define KB_0 39 80 | #define KB_RETURN 40 81 | #define KB_ESC 41 82 | #define KB_DEL 42 83 | #define KB_TAB 43 84 | #define KB_SPACE 44 85 | #define KB_MINUS 45 86 | #define KB_EQUAL 46 87 | #define KB_LEFT_BRACKET 47 88 | #define KB_RIGHT_BRACKET 48 89 | #define KB_BACK_SLASH 49 90 | #define KB_SEMICOLON 51 // ; : 91 | #define KB_BACK_QUOTES 53//·~ 92 | #define KB_QUOTES 52 // " ' 93 | #define KB_COMMA 54 94 | #define KB_END_MARK 55 95 | #define KB_SLASH 56 96 | #define KB_CAPSLOCK 57 97 | #define KB_F1 58 98 | #define KB_F2 59 99 | #define KB_F3 60 100 | #define KB_F4 61 101 | #define KB_F5 62 102 | #define KB_F6 63 103 | #define KB_F7 64 104 | #define KB_F8 65 105 | #define KB_F9 66 106 | #define KB_F10 67 107 | #define KB_F11 68 108 | #define KB_F12 69 109 | #define KB_PRT_SCR 70 110 | #define KB_SCROLL_LOCK 71 111 | #define KB_PAUSE 72 112 | #define KB_INSERT 73 113 | #define KB_HOME 74 114 | #define KB_PAGE_UP 75 115 | #define KB_DELETE_FORWARD 76 116 | #define KB_END 77 117 | #define KB_PAGE_DOWN 78 118 | #define KB_RIGHT_ARROW 79 119 | #define KB_LEFT_ARROW 80 120 | #define KB_DOWN_ARROW 81 121 | #define KB_UP_ARROW 82 122 | #define KB_RIGHT_CLICK 101 123 | #define KB_VOLUME_MUTE 127 124 | #define KB_VOLUME_UP 128 125 | #define KB_VOLUME_DOWN 129 126 | //// 以下不属于标准键盘标准 127 | //#define KB_FN1 101 128 | //#define KB_FN2 102 129 | //#define KB_FN3 103 130 | //#define KB_FN4 104 131 | //#define KB_FN5 105 132 | 133 | // 以下三个按键在八字节的第一个字节的0123位 134 | #define KB_CTRL 1 //D0 135 | #define KB_SHIFT 2 //D1 136 | #define KB_ALT 4 //D2 137 | #define KB_WIN 8 //D4 138 | 139 | //第二个字节为0 140 | //第345678字节保存键值 141 | 142 | #endif //CPPTEST_KEYCODESTANDERD_H_H 143 | -------------------------------------------------------------------------------- /KEY/KeyState.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #include "KeyState.h" 6 | 7 | KeyState::KeyState() : fn_layer(0), composite_mark(0) { 8 | for (int i = 0; i < MAX_ROW; ++i) { 9 | for (int j = 0; j < MAX_COL; ++j) { 10 | origin[i][j] = false; 11 | } 12 | } 13 | } 14 | 15 | bool KeyState::isDown(const unsigned char row, const unsigned char col) { 16 | return origin[row][col]; 17 | } 18 | 19 | bool KeyState::sameOrigin(bool o[MAX_ROW][MAX_COL]) { 20 | for (int i = 0; i < MAX_ROW; ++i) { 21 | for (int j = 0; j < MAX_COL; ++j) { 22 | if (o[i][j] != origin[i][j]) return false; 23 | } 24 | } 25 | return true; 26 | } 27 | 28 | void KeyState::copyOrigin(bool (*o)[14]) { 29 | for (int i = 0; i < MAX_ROW; ++i) { 30 | for (int j = 0; j < MAX_COL; ++j) { 31 | o[i][j] = isDown(i, j); 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /KEY/KeyState.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_KEYSTATE_H 6 | #define CPPTEST_KEYSTATE_H 7 | 8 | #include "KeyCode.h" 9 | #include "Const.h" 10 | 11 | struct KeyPlace { 12 | public: 13 | KeyPlace(char row, char col) : row(row), col(col) {} 14 | KeyPlace(char * rc) : row(rc[0]), col(rc[1]) {} 15 | KeyPlace(const KeyPlace& that) : row(that.row), col(that.col) {} 16 | unsigned char getRow() const { return row; } 17 | unsigned char getCol() const { return col; } 18 | void setRow(unsigned char row) { KeyPlace::row = row; } 19 | void setCol(unsigned char col) { KeyPlace::col = col; } 20 | private: 21 | unsigned char row, col; 22 | }; 23 | 24 | struct ExactPlace { 25 | public: 26 | ExactPlace(float x, float y) : x(x), y(y) {} 27 | ExactPlace(float * xy) : x(xy[0]), y(xy[1]) {} 28 | ExactPlace(const ExactPlace & that) : x(that.x), y(that.y) {} 29 | float getX() const { return x; } 30 | void setX(float x) { ExactPlace::x = x; } 31 | float getY() const { return y; } 32 | void setY(float y) { ExactPlace::y = y; } 33 | private: 34 | float x,y; 35 | }; 36 | 37 | /** 38 | * \brief 此类用于存放按下键位的原始状态并在键之间传递,使得形成最终的键码。 39 | */ 40 | class KeyRemainDeloy { 41 | public: 42 | KeyRemainDeloy(unsigned int miniLayer, 43 | unsigned char raw, 44 | unsigned char col, 45 | unsigned char compositeMark = 0) 46 | : miniLayer(miniLayer), raw(raw), col(col), compositeMark(compositeMark) {} 47 | 48 | unsigned int miniLayer; 49 | unsigned char raw, col; 50 | unsigned char compositeMark; 51 | }; 52 | 53 | /** 54 | * \brief 此类用于保存状态,供Key之间处理并确定最终发送的键码 55 | * \details 56 | * 对象的声明周期为: 57 | * 键盘扫描完成后 58 | * 1. 生成 59 | * 2. 传入预处理程序 60 | * 3. 传入每个键盘处理 61 | * 4. 传入后处理程序 62 | * 5. 传入发送前循环处理程序 63 | * 6. 传入键码发送程序发送键码 64 | * 7. 销毁 65 | */ 66 | class KeyState { 67 | public: 68 | KeyState(); 69 | bool isDown(const unsigned char row, const unsigned char col); 70 | void setData(const unsigned char row, const unsigned char col, bool isDown) { 71 | origin[row][col] = isDown; 72 | } 73 | 74 | unsigned int getMiniLayer() { 75 | return (((unsigned int)fn_layer) << COMPOSITE_KEY_NUM) + composite_mark; 76 | } 77 | bool sameOrigin(bool origin[MAX_ROW][MAX_COL]); 78 | void copyOrigin(bool origin[MAX_ROW][MAX_COL]); 79 | 80 | std::vector code_to_send; // 这里的code都是处理好的,需要最终发送的键码 81 | std::vector key_holding; // 这里做的比较trick,是用于自动降层的 82 | unsigned char fn_layer; 83 | unsigned char composite_mark; 84 | bool origin[MAX_ROW][MAX_COL]; 85 | }; 86 | 87 | #endif //CPPTEST_KEYSTATE_H 88 | -------------------------------------------------------------------------------- /KEY/tool.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | #include "hw_config.h" 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | 13 | #include "tool.h" 14 | #include "delay.h" 15 | #include "vector" 16 | 17 | char isSameCom(const std::vector &keys_to_sent) { 18 | char num = keys_to_sent.size(); 19 | if (num <= 1) return 1; 20 | char co = keys_to_sent[0].getComposite(); 21 | for (int i = 1; i < num; ++i) { 22 | if (co != keys_to_sent[0].getComposite()) return 0; 23 | } 24 | return 1; 25 | } 26 | 27 | void tool::sent_key_code(const std::vector &keys_to_sent) { 28 | char num = keys_to_sent.size(); 29 | if (num == 0) { 30 | Joystick_Send(0, 0, 0, 0, 0, 0, 0, 0); 31 | } else if (num == 1) { 32 | char c = keys_to_sent[0].getComposite(); 33 | char co = keys_to_sent[0].getCode(); 34 | Joystick_Send(c, 0, co, 0, 0, 0, 0, 0); 35 | } else if (isSameCom(keys_to_sent)) { // 同一minilayer的可以 6 并行传送 36 | char c = keys_to_sent[0].getComposite(); 37 | char co[6]; 38 | for (int i = 0; i < 6; ++i) { 39 | co[i] = (i < num)? keys_to_sent[i].getCode(): 0; 40 | } 41 | Joystick_Send(c, 0, co[0], co[1], co[2], co[3], co[4], co[5]); 42 | } else { 43 | for (int i = 0; i < num; ++i) { 44 | char c = keys_to_sent[i].getComposite(); 45 | char co = keys_to_sent[i].getCode(); 46 | Joystick_Send(c, 0, co, 0, 0, 0, 0, 0); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /KEY/tool.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liu on 2017/11/28. 3 | // 4 | 5 | #ifndef CPPTEST_TOOL_H 6 | #define CPPTEST_TOOL_H 7 | 8 | 9 | #include "KeyCode.h" 10 | 11 | class tool { 12 | public: 13 | static void sent_key_code(const std::vector &keys_to_sent); 14 | }; 15 | 16 | 17 | #endif //CPPTEST_TOOL_H 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoopBoard 2 | Software for a Keyboard and LEDs on it. 3 | 4 | http://blog.csdn.net/BG2CRW/article/details/79475752 5 | -------------------------------------------------------------------------------- /SCHDOC/cherry轴元件库.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/SCHDOC/cherry轴元件库.zip -------------------------------------------------------------------------------- /SCHDOC/keyboard_IO.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/SCHDOC/keyboard_IO.pdf -------------------------------------------------------------------------------- /SCHDOC/keyboard_core.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/SCHDOC/keyboard_core.pdf -------------------------------------------------------------------------------- /SCHDOC/ourdev_692986N5FAHU.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/SCHDOC/ourdev_692986N5FAHU.pdf -------------------------------------------------------------------------------- /STM32F10x_FWLib/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CRC_H 25 | #define __STM32F10x_CRC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CRC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup CRC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | void CRC_ResetDR(void); 71 | uint32_t CRC_CalcCRC(uint32_t Data); 72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 73 | uint32_t CRC_GetCRC(void); 74 | void CRC_SetIDRegister(uint8_t IDValue); 75 | uint8_t CRC_GetIDRegister(void); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F10x_CRC_H */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_DBGMCU_H 25 | #define __STM32F10x_DBGMCU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup DBGMCU 39 | * @{ 40 | */ 41 | 42 | /** @defgroup DBGMCU_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 55 | #define DBGMCU_STOP ((uint32_t)0x00000002) 56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 80 | 81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup DBGMCU_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup DBGMCU_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | uint32_t DBGMCU_GetREVID(void); 99 | uint32_t DBGMCU_GetDEVID(void); 100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __STM32F10x_DBGMCU_H */ 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_IWDG_H 25 | #define __STM32F10x_IWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup IWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup IWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup IWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup IWDG_WriteAccess 55 | * @{ 56 | */ 57 | 58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 61 | ((ACCESS) == IWDG_WriteAccess_Disable)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup IWDG_prescaler 67 | * @{ 68 | */ 69 | 70 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 71 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 72 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 73 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 74 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 75 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 76 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 77 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 78 | ((PRESCALER) == IWDG_Prescaler_8) || \ 79 | ((PRESCALER) == IWDG_Prescaler_16) || \ 80 | ((PRESCALER) == IWDG_Prescaler_32) || \ 81 | ((PRESCALER) == IWDG_Prescaler_64) || \ 82 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 83 | ((PRESCALER) == IWDG_Prescaler_256)) 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup IWDG_Flag 89 | * @{ 90 | */ 91 | 92 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 93 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 94 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 95 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @defgroup IWDG_Exported_Macros 105 | * @{ 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** @defgroup IWDG_Exported_Functions 113 | * @{ 114 | */ 115 | 116 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 117 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 118 | void IWDG_SetReload(uint16_t Reload); 119 | void IWDG_ReloadCounter(void); 120 | void IWDG_Enable(void); 121 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __STM32F10x_IWDG_H */ 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 141 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_PWR_H 25 | #define __STM32F10x_PWR_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup PWR 39 | * @{ 40 | */ 41 | 42 | /** @defgroup PWR_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup PWR_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup PVD_detection_level 55 | * @{ 56 | */ 57 | 58 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 59 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 60 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 61 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 62 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 63 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 64 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 65 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 66 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 67 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 68 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup Regulator_state_is_STOP_mode 75 | * @{ 76 | */ 77 | 78 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 79 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 80 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 81 | ((REGULATOR) == PWR_Regulator_LowPower)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup STOP_mode_entry 87 | * @{ 88 | */ 89 | 90 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 91 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 92 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup PWR_Flag 99 | * @{ 100 | */ 101 | 102 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 103 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 104 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 105 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 106 | ((FLAG) == PWR_FLAG_PVDO)) 107 | 108 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup PWR_Exported_Macros 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup PWR_Exported_Functions 126 | * @{ 127 | */ 128 | 129 | void PWR_DeInit(void); 130 | void PWR_BackupAccessCmd(FunctionalState NewState); 131 | void PWR_PVDCmd(FunctionalState NewState); 132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 133 | void PWR_WakeUpPinCmd(FunctionalState NewState); 134 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 135 | void PWR_EnterSTANDBYMode(void); 136 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 137 | void PWR_ClearFlag(uint32_t PWR_FLAG); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __STM32F10x_PWR_H */ 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_RTC_H 25 | #define __STM32F10x_RTC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RTC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup RTC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup RTC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup RTC_interrupts_define 55 | * @{ 56 | */ 57 | 58 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 59 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 60 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 61 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 62 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 63 | ((IT) == RTC_IT_SEC)) 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup RTC_interrupts_flags 69 | * @{ 70 | */ 71 | 72 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 73 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 74 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 75 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 76 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 77 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 78 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 79 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 80 | ((FLAG) == RTC_FLAG_SEC)) 81 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @defgroup RTC_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup RTC_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 104 | void RTC_EnterConfigMode(void); 105 | void RTC_ExitConfigMode(void); 106 | uint32_t RTC_GetCounter(void); 107 | void RTC_SetCounter(uint32_t CounterValue); 108 | void RTC_SetPrescaler(uint32_t PrescalerValue); 109 | void RTC_SetAlarm(uint32_t AlarmValue); 110 | uint32_t RTC_GetDivider(void); 111 | void RTC_WaitForLastTask(void); 112 | void RTC_WaitForSynchro(void); 113 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 114 | void RTC_ClearFlag(uint16_t RTC_FLAG); 115 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 116 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* __STM32F10x_RTC_H */ 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 136 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_WWDG_H 25 | #define __STM32F10x_WWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup WWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup WWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Exported_Macros 78 | * @{ 79 | */ 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | void WWDG_DeInit(void); 89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 90 | void WWDG_SetWindowValue(uint8_t WindowValue); 91 | void WWDG_EnableIT(void); 92 | void WWDG_SetCounter(uint8_t Counter); 93 | void WWDG_Enable(uint8_t Counter); 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F10x_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_crc.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup CRC 30 | * @brief CRC driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup CRC_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup CRC_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup CRC_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Resets the CRC Data register (DR). 80 | * @param None 81 | * @retval None 82 | */ 83 | void CRC_ResetDR(void) 84 | { 85 | /* Reset CRC generator */ 86 | CRC->CR = CRC_CR_RESET; 87 | } 88 | 89 | /** 90 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 91 | * @param Data: data word(32-bit) to compute its CRC 92 | * @retval 32-bit CRC 93 | */ 94 | uint32_t CRC_CalcCRC(uint32_t Data) 95 | { 96 | CRC->DR = Data; 97 | 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 103 | * @param pBuffer: pointer to the buffer containing the data to be computed 104 | * @param BufferLength: length of the buffer to be computed 105 | * @retval 32-bit CRC 106 | */ 107 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 108 | { 109 | uint32_t index = 0; 110 | 111 | for(index = 0; index < BufferLength; index++) 112 | { 113 | CRC->DR = pBuffer[index]; 114 | } 115 | return (CRC->DR); 116 | } 117 | 118 | /** 119 | * @brief Returns the current CRC value. 120 | * @param None 121 | * @retval 32-bit CRC 122 | */ 123 | uint32_t CRC_GetCRC(void) 124 | { 125 | return (CRC->DR); 126 | } 127 | 128 | /** 129 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 130 | * @param IDValue: 8-bit value to be stored in the ID register 131 | * @retval None 132 | */ 133 | void CRC_SetIDRegister(uint8_t IDValue) 134 | { 135 | CRC->IDR = IDValue; 136 | } 137 | 138 | /** 139 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 140 | * @param None 141 | * @retval 8-bit value of the ID register 142 | */ 143 | uint8_t CRC_GetIDRegister(void) 144 | { 145 | return (CRC->IDR); 146 | } 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 161 | -------------------------------------------------------------------------------- /STM32F10x_FWLib/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/STM32F10x_FWLib/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /STM32F10x_FWLib/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/STM32F10x_FWLib/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /STM32F10x_FWLib/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/STM32F10x_FWLib/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /SYSTEM/delay/delay.h: -------------------------------------------------------------------------------- 1 | #ifndef __DELAY_H 2 | #define __DELAY_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "sys.h" 9 | ////////////////////////////////////////////////////////////////////////////////// 10 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 11 | //ALIENTEK STM32开发板 12 | //使用SysTick的普通计数模式对延迟进行管理(适合STM32F10x系列) 13 | //包括delay_us,delay_ms 14 | //正点原子@ALIENTEK 15 | //技术论坛:www.openedv.com 16 | //创建日期:2010/1/1 17 | //版本:V1.8 18 | //版权所有,盗版必究。 19 | //Copyright(C) 广州市星翼电子科技有限公司 2009-2019 20 | //All rights reserved 21 | //******************************************************************************** 22 | //V1.2修改说明 23 | //修正了中断中调用出现死循环的错误 24 | //防止延时不准确,采用do while结构! 25 | //V1.3修改说明 26 | //增加了对UCOSII延时的支持. 27 | //如果使用ucosII,delay_init会自动设置SYSTICK的值,使之与ucos的TICKS_PER_SEC对应. 28 | //delay_ms和delay_us也进行了针对ucos的改造. 29 | //delay_us可以在ucos下使用,而且准确度很高,更重要的是没有占用额外的定时器. 30 | //delay_ms在ucos下,可以当成OSTimeDly来用,在未启动ucos时,它采用delay_us实现,从而准确延时 31 | //可以用来初始化外设,在启动了ucos之后delay_ms根据延时的长短,选择OSTimeDly实现或者delay_us实现. 32 | //V1.4修改说明 20110929 33 | //修改了使用ucos,但是ucos未启动的时候,delay_ms中中断无法响应的bug. 34 | //V1.5修改说明 20120902 35 | //在delay_us加入ucos上锁,防止由于ucos打断delay_us的执行,可能导致的延时不准。 36 | //V1.6修改说明 20150109 37 | //在delay_ms加入OSLockNesting判断。 38 | //V1.7修改说明 20150319 39 | //修改OS支持方式,以支持任意OS(不限于UCOSII和UCOSIII,理论上任意OS都可以支持) 40 | //添加:delay_osrunning/delay_ostickspersec/delay_osintnesting三个宏定义 41 | //添加:delay_osschedlock/delay_osschedunlock/delay_ostimedly三个函数 42 | //V1.8修改说明 20150519 43 | //修正UCOSIII支持时的2个bug: 44 | //delay_tickspersec改为:delay_ostickspersec 45 | //delay_intnesting改为:delay_osintnesting 46 | ////////////////////////////////////////////////////////////////////////////////// 47 | 48 | void delay_init(void); 49 | void delay_ms(u16 nms); 50 | void delay_us(u32 nus); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /SYSTEM/sys/sys.c: -------------------------------------------------------------------------------- 1 | #include "sys.h" 2 | 3 | //******************************************************************************** 4 | //THUMB指令不支持汇编内联 5 | //采用如下方法实现执行汇编指令WFI 6 | void WFI_SET(void) 7 | { 8 | __ASM volatile("wfi"); 9 | } 10 | //关闭所有中断 11 | void INTX_DISABLE(void) 12 | { 13 | __ASM volatile("cpsid i"); 14 | } 15 | //开启所有中断 16 | void INTX_ENABLE(void) 17 | { 18 | __ASM volatile("cpsie i"); 19 | } 20 | //设置栈顶地址 21 | //addr:栈顶地址 22 | __asm void MSR_MSP(u32 addr) 23 | { 24 | MSR MSP, r0 //set Main Stack value 25 | BX r14 26 | } 27 | -------------------------------------------------------------------------------- /SYSTEM/sys/sys.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_H 2 | #define __SYS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "stm32f10x.h" 9 | ////////////////////////////////////////////////////////////////////////////////// 10 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 11 | //ALIENTEK STM32开发板 12 | //正点原子@ALIENTEK 13 | //技术论坛:www.openedv.com 14 | //修改日期:2012/8/18 15 | //版本:V1.7 16 | //版权所有,盗版必究。 17 | //Copyright(C) 广州市星翼电子科技有限公司 2009-2019 18 | //All rights reserved 19 | ////////////////////////////////////////////////////////////////////////////////// 20 | 21 | //0,不支持ucos 22 | //1,支持ucos 23 | #define SYSTEM_SUPPORT_OS 0 //定义系统文件夹是否支持UCOS 24 | 25 | 26 | //位带操作,实现51类似的GPIO控制功能 27 | //具体实现思想,参考<>第五章(87页~92页). 28 | //IO口操作宏定义 29 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 30 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 31 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 32 | //IO口地址映射 33 | #define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C 34 | #define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C 35 | #define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C 36 | #define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C 37 | #define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C 38 | #define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C 39 | #define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C 40 | 41 | #define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808 42 | #define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08 43 | #define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008 44 | #define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408 45 | #define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808 46 | #define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08 47 | #define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08 48 | 49 | //IO口操作,只对单一的IO口! 50 | //确保n的值小于16! 51 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 52 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 53 | 54 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 55 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 56 | 57 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 58 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 59 | 60 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 61 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 62 | 63 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 64 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 65 | 66 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 67 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 68 | 69 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 70 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 71 | 72 | //以下为汇编函数 73 | void WFI_SET(void); //执行WFI指令 74 | void INTX_DISABLE(void);//关闭所有中断 75 | void INTX_ENABLE(void); //开启所有中断 76 | void MSR_MSP(u32 addr); //设置堆栈地址 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /SYSTEM/usart/usart.c: -------------------------------------------------------------------------------- 1 | #include "sys.h" 2 | #include "usart.h" 3 | ////////////////////////////////////////////////////////////////////////////////// 4 | //如果使用ucos,则包括下面的头文件即可. 5 | #if SYSTEM_SUPPORT_OS 6 | #include "includes.h" //ucos 使用 7 | #endif 8 | 9 | 10 | ////////////////////////////////////////////////////////////////// 11 | //加入以下代码,支持printf函数,而不需要选择use MicroLIB 12 | #if 1 13 | #pragma import(__use_no_semihosting) 14 | //标准库需要的支持函数 15 | struct __FILE 16 | { 17 | int handle; 18 | 19 | }; 20 | 21 | FILE __stdout; 22 | //定义_sys_exit()以避免使用半主机模式 23 | _sys_exit(int x) 24 | { 25 | x = x; 26 | } 27 | //重定义fputc函数 28 | int fputc(int ch, FILE *f) 29 | { 30 | while((USART1->SR&0X40)==0);//循环发送,直到发送完毕 31 | USART1->DR = (u8) ch; 32 | return ch; 33 | } 34 | #endif 35 | 36 | 37 | 38 | #if EN_USART1_RX //如果使能了接收 39 | //串口1中断服务程序 40 | //注意,读取USARTx->SR能避免莫名其妙的错误 41 | u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节. 42 | //接收状态 43 | //bit15, 接收完成标志 44 | //bit14, 接收到0x0d 45 | //bit13~0, 接收到的有效字节数目 46 | u16 USART_RX_STA=0; //接收状态标记 47 | 48 | void uart_init(u32 bound){ 49 | //GPIO端口设置 50 | GPIO_InitTypeDef GPIO_InitStructure; 51 | USART_InitTypeDef USART_InitStructure; 52 | NVIC_InitTypeDef NVIC_InitStructure; 53 | 54 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能USART1,GPIOA时钟 55 | 56 | //USART1_TX GPIOA.9 57 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9 58 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 59 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出 60 | GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.9 61 | 62 | //USART1_RX GPIOA.10初始化 63 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10 64 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入 65 | GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.10 66 | 67 | //Usart1 NVIC 配置 68 | NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; 69 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3 70 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3 71 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 72 | NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器 73 | 74 | //USART 初始化设置 75 | 76 | USART_InitStructure.USART_BaudRate = bound;//串口波特率 77 | USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式 78 | USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位 79 | USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位 80 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制 81 | USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式 82 | 83 | USART_Init(USART1, &USART_InitStructure); //初始化串口1 84 | USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断 85 | USART_Cmd(USART1, ENABLE); //使能串口1 86 | 87 | } 88 | 89 | void USART1_IRQHandler(void) //串口1中断服务程序 90 | { 91 | u8 Res; 92 | #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS. 93 | OSIntEnter(); 94 | #endif 95 | if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾) 96 | { 97 | Res =USART_ReceiveData(USART1); //读取接收到的数据 98 | 99 | if((USART_RX_STA&0x8000)==0)//接收未完成 100 | { 101 | if(USART_RX_STA&0x4000)//接收到了0x0d 102 | { 103 | if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始 104 | else USART_RX_STA|=0x8000; //接收完成了 105 | } 106 | else //还没收到0X0D 107 | { 108 | if(Res==0x0d)USART_RX_STA|=0x4000; 109 | else 110 | { 111 | USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ; 112 | USART_RX_STA++; 113 | if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//接收数据错误,重新开始接收 114 | } 115 | } 116 | } 117 | } 118 | #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS. 119 | OSIntExit(); 120 | #endif 121 | } 122 | #endif 123 | 124 | -------------------------------------------------------------------------------- /SYSTEM/usart/usart.h: -------------------------------------------------------------------------------- 1 | #ifndef __USART_H 2 | #define __USART_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "stdio.h" 9 | #include "sys.h" 10 | ////////////////////////////////////////////////////////////////////////////////// 11 | //本程序只供学习使用,未经作者许可,不得用于其它任何用途 12 | //ALIENTEK STM32开发板 13 | //串口1初始化 14 | //正点原子@ALIENTEK 15 | //技术论坛:www.openedv.com 16 | //修改日期:2012/8/18 17 | //版本:V1.5 18 | //版权所有,盗版必究。 19 | //Copyright(C) 广州市星翼电子科技有限公司 2009-2019 20 | //All rights reserved 21 | //******************************************************************************** 22 | //V1.3修改说明 23 | //支持适应不同频率下的串口波特率设置. 24 | //加入了对printf的支持 25 | //增加了串口接收命令功能. 26 | //修正了printf第一个字符丢失的bug 27 | //V1.4修改说明 28 | //1,修改串口初始化IO的bug 29 | //2,修改了USART_RX_STA,使得串口最大接收字节数为2的14次方 30 | //3,增加了USART_REC_LEN,用于定义串口最大允许接收的字节数(不大于2的14次方) 31 | //4,修改了EN_USART1_RX的使能方式 32 | //V1.5修改说明 33 | //1,增加了对UCOSII的支持 34 | #define USART_REC_LEN 200 //定义最大接收字节数 200 35 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 36 | 37 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 38 | extern u16 USART_RX_STA; //接收状态标记 39 | //如果想串口中断接收,请不要注释以下宏定义 40 | void uart_init(u32 bound); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | 48 | 49 | -------------------------------------------------------------------------------- /USB/CONFIG/hw_config.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/USB/CONFIG/hw_config.c -------------------------------------------------------------------------------- /USB/CONFIG/hw_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hw_config.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Hardware Configuration & Setup 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __HW_CONFIG_H 31 | #define __HW_CONFIG_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "platform_config.h" 35 | #include "usb_type.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported constants --------------------------------------------------------*/ 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* Exported define -----------------------------------------------------------*/ 45 | #define CURSOR_STEP 20 46 | 47 | #define DOWN 2 48 | #define LEFT 3 49 | #define RIGHT 4 50 | #define UP 5 51 | 52 | /* Exported functions ------------------------------------------------------- */ 53 | void Set_System(void); 54 | void Set_USBClock(void); 55 | void GPIO_AINConfig(void); 56 | void Enter_LowPowerMode(void); 57 | void Leave_LowPowerMode(void); 58 | void USB_Interrupts_Config(void); 59 | void USB_Cable_Config (FunctionalState NewState); 60 | 61 | void USB_Port_Set(u8 enable); 62 | void Joystick_Send(u8 buf0,u8 buf1,u8 buf2,u8 buf3,u8 buf4,u8 buf5,u8 buf6,u8 buf7); 63 | 64 | 65 | uint8_t JoyState(void); 66 | void Get_SerialNum(void); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /*__HW_CONFIG_H*/ 73 | 74 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 75 | -------------------------------------------------------------------------------- /USB/CONFIG/usb_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_conf.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Joystick Mouse demo configuration file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_CONF_H 31 | #define __USB_CONF_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions ------------------------------------------------------- */ 42 | /* External variables --------------------------------------------------------*/ 43 | /*-------------------------------------------------------------*/ 44 | /* EP_NUM */ 45 | /* defines how many endpoints are used by the device */ 46 | /*-------------------------------------------------------------*/ 47 | #define EP_NUM (2) 48 | 49 | /*-------------------------------------------------------------*/ 50 | /* -------------- Buffer Description Table -----------------*/ 51 | /*-------------------------------------------------------------*/ 52 | /* buffer table base address */ 53 | /* buffer table base address */ 54 | #define BTABLE_ADDRESS (0x00) 55 | 56 | /* EP0 */ 57 | /* rx/tx buffer base address */ 58 | #define ENDP0_RXADDR (0x18) 59 | #define ENDP0_TXADDR (0x58) 60 | 61 | /* EP1 */ 62 | /* tx buffer base address */ 63 | #define ENDP1_TXADDR (0x100) 64 | #define ENDP1_RXADDR (0xD8) 65 | 66 | /*-------------------------------------------------------------*/ 67 | /* ------------------- ISTR events -------------------------*/ 68 | /*-------------------------------------------------------------*/ 69 | /* IMR_MSK */ 70 | /* mask defining which events has to be handled */ 71 | /* by the device application software */ 72 | #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \ 73 | | CNTR_ESOFM | CNTR_RESETM ) 74 | 75 | /* CTR service routines */ 76 | /* associated to defined endpoints */ 77 | /* #define EP1_IN_Callback NOP_Process*/ 78 | #define EP2_IN_Callback NOP_Process 79 | #define EP3_IN_Callback NOP_Process 80 | #define EP4_IN_Callback NOP_Process 81 | #define EP5_IN_Callback NOP_Process 82 | #define EP6_IN_Callback NOP_Process 83 | #define EP7_IN_Callback NOP_Process 84 | 85 | #define EP1_OUT_Callback NOP_Process 86 | #define EP2_OUT_Callback NOP_Process 87 | #define EP3_OUT_Callback NOP_Process 88 | #define EP4_OUT_Callback NOP_Process 89 | #define EP5_OUT_Callback NOP_Process 90 | #define EP6_OUT_Callback NOP_Process 91 | #define EP7_OUT_Callback NOP_Process 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /*__USB_CONF_H*/ 98 | 99 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 100 | -------------------------------------------------------------------------------- /USB/CONFIG/usb_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Descriptor Header for Joystick Mouse Demo 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_DESC_H 31 | #define __USB_DESC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported define -----------------------------------------------------------*/ 42 | #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 43 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 44 | #define USB_STRING_DESCRIPTOR_TYPE 0x03 45 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 46 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 47 | 48 | #define HID_DESCRIPTOR_TYPE 0x21 49 | #define JOYSTICK_SIZ_HID_DESC 0x09 50 | #define JOYSTICK_OFF_HID_DESC 0x12 51 | 52 | #define JOYSTICK_SIZ_DEVICE_DESC 18 53 | #define JOYSTICK_SIZ_CONFIG_DESC 41 54 | #define JOYSTICK_SIZ_REPORT_DESC 61 55 | #define JOYSTICK_SIZ_STRING_LANGID 4 56 | #define JOYSTICK_SIZ_STRING_VENDOR 38 57 | #define JOYSTICK_SIZ_STRING_PRODUCT 20 58 | #define JOYSTICK_SIZ_STRING_SERIAL 26 59 | 60 | #define STANDARD_ENDPOINT_DESC_SIZE 0x09 61 | 62 | /* Exported functions ------------------------------------------------------- */ 63 | extern const uint8_t Joystick_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC]; 64 | extern const uint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIG_DESC]; 65 | extern const uint8_t Joystick_ReportDescriptor[JOYSTICK_SIZ_REPORT_DESC]; 66 | extern const uint8_t Joystick_StringLangID[JOYSTICK_SIZ_STRING_LANGID]; 67 | extern const uint8_t Joystick_StringVendor[JOYSTICK_SIZ_STRING_VENDOR]; 68 | extern const uint8_t Joystick_StringProduct[JOYSTICK_SIZ_STRING_PRODUCT]; 69 | extern uint8_t Joystick_StringSerial[JOYSTICK_SIZ_STRING_SERIAL]; 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* __USB_DESC_H */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /USB/CONFIG/usb_endp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_endp.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Endpoint routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "hw_config.h" 31 | #include "usb_lib.h" 32 | #include "usb_istr.h" 33 | 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | extern __IO uint8_t PrevXferComplete; 39 | 40 | /* Private function prototypes -----------------------------------------------*/ 41 | /* Private functions ---------------------------------------------------------*/ 42 | /******************************************************************************* 43 | * Function Name : EP1_OUT_Callback. 44 | * Description : EP1 OUT Callback Routine. 45 | * Input : None. 46 | * Output : None. 47 | * Return : None. 48 | *******************************************************************************/ 49 | void EP1_IN_Callback(void) 50 | { 51 | /* Set the transfer complete token to inform upper layer that the current 52 | transfer has been complete */ 53 | PrevXferComplete = 1; 54 | } 55 | 56 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 57 | 58 | -------------------------------------------------------------------------------- /USB/CONFIG/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_ISTR_H 31 | #define __USB_ISTR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "usb_conf.h" 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | /* Exported constants --------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions ------------------------------------------------------- */ 44 | 45 | void USB_Istr(void); 46 | 47 | /* function prototypes Automatically built defining related macros */ 48 | 49 | void EP1_IN_Callback(void); 50 | void EP2_IN_Callback(void); 51 | void EP3_IN_Callback(void); 52 | void EP4_IN_Callback(void); 53 | void EP5_IN_Callback(void); 54 | void EP6_IN_Callback(void); 55 | void EP7_IN_Callback(void); 56 | 57 | void EP1_OUT_Callback(void); 58 | void EP2_OUT_Callback(void); 59 | void EP3_OUT_Callback(void); 60 | void EP4_OUT_Callback(void); 61 | void EP5_OUT_Callback(void); 62 | void EP6_OUT_Callback(void); 63 | void EP7_OUT_Callback(void); 64 | 65 | #ifdef CTR_CALLBACK 66 | void CTR_Callback(void); 67 | #endif 68 | 69 | #ifdef DOVR_CALLBACK 70 | void DOVR_Callback(void); 71 | #endif 72 | 73 | #ifdef ERR_CALLBACK 74 | void ERR_Callback(void); 75 | #endif 76 | 77 | #ifdef WKUP_CALLBACK 78 | void WKUP_Callback(void); 79 | #endif 80 | 81 | #ifdef SUSP_CALLBACK 82 | void SUSP_Callback(void); 83 | #endif 84 | 85 | #ifdef RESET_CALLBACK 86 | void RESET_Callback(void); 87 | #endif 88 | 89 | #ifdef SOF_CALLBACK 90 | void SOF_Callback(void); 91 | #endif 92 | 93 | #ifdef ESOF_CALLBACK 94 | void ESOF_Callback(void); 95 | #endif 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /*__USB_ISTR_H*/ 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /USB/CONFIG/usb_prop.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_prop.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief All processing related to Joystick Mouse demo 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_PROP_H 31 | #define __USB_PROP_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | typedef enum _HID_REQUESTS 40 | { 41 | GET_REPORT = 1, 42 | GET_IDLE, 43 | GET_PROTOCOL, 44 | 45 | SET_REPORT = 9, 46 | SET_IDLE, 47 | SET_PROTOCOL 48 | } HID_REQUESTS; 49 | 50 | /* Exported constants --------------------------------------------------------*/ 51 | /* Exported macro ------------------------------------------------------------*/ 52 | /* Exported functions ------------------------------------------------------- */ 53 | void Joystick_init(void); 54 | void Joystick_Reset(void); 55 | void Joystick_SetConfiguration(void); 56 | void Joystick_SetDeviceAddress (void); 57 | void Joystick_Status_In (void); 58 | void Joystick_Status_Out (void); 59 | RESULT Joystick_Data_Setup(uint8_t); 60 | RESULT Joystick_NoData_Setup(uint8_t); 61 | RESULT Joystick_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting); 62 | uint8_t *Joystick_GetDeviceDescriptor(uint16_t ); 63 | uint8_t *Joystick_GetConfigDescriptor(uint16_t); 64 | uint8_t *Joystick_GetStringDescriptor(uint16_t); 65 | RESULT Joystick_SetProtocol(void); 66 | uint8_t *Joystick_GetProtocolValue(uint16_t Length); 67 | RESULT Joystick_SetProtocol(void); 68 | uint8_t *Joystick_GetReportDescriptor(uint16_t Length); 69 | uint8_t *Joystick_GetHIDDescriptor(uint16_t Length); 70 | 71 | /* Exported define -----------------------------------------------------------*/ 72 | #define Joystick_GetConfiguration NOP_Process 73 | //#define Joystick_SetConfiguration NOP_Process 74 | #define Joystick_GetInterface NOP_Process 75 | #define Joystick_SetInterface NOP_Process 76 | #define Joystick_GetStatus NOP_Process 77 | #define Joystick_ClearFeature NOP_Process 78 | #define Joystick_SetEndPointFeature NOP_Process 79 | #define Joystick_SetDeviceFeature NOP_Process 80 | //#define Joystick_SetDeviceAddress NOP_Process 81 | 82 | #define REPORT_DESCRIPTOR 0x22 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* __USB_PROP_H */ 89 | 90 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 91 | -------------------------------------------------------------------------------- /USB/CONFIG/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_PWR_H 31 | #define __USB_PWR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | typedef enum _RESUME_STATE 40 | { 41 | RESUME_EXTERNAL, 42 | RESUME_INTERNAL, 43 | RESUME_LATER, 44 | RESUME_WAIT, 45 | RESUME_START, 46 | RESUME_ON, 47 | RESUME_OFF, 48 | RESUME_ESOF 49 | } RESUME_STATE; 50 | 51 | typedef enum _DEVICE_STATE 52 | { 53 | UNCONNECTED, 54 | ATTACHED, 55 | POWERED, 56 | SUSPENDED, 57 | ADDRESSED, 58 | CONFIGURED 59 | } DEVICE_STATE; 60 | 61 | /* Exported constants --------------------------------------------------------*/ 62 | /* Exported macro ------------------------------------------------------------*/ 63 | /* Exported functions ------------------------------------------------------- */ 64 | void Suspend(void); 65 | void Resume_Init(void); 66 | void Resume(RESUME_STATE eResumeSetVal); 67 | RESULT PowerOn(void); 68 | RESULT PowerOff(void); 69 | /* External variables --------------------------------------------------------*/ 70 | extern __IO uint32_t bDeviceState; /* USB device status */ 71 | extern __IO BOOL fSuspendEnabled; /* true when suspend is possible */ 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /*__USB_PWR_H*/ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_def.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Definitions related to USB Core 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_DEF_H 30 | #define __USB_DEF_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | /* Exported types ------------------------------------------------------------*/ 38 | typedef enum _RECIPIENT_TYPE 39 | { 40 | DEVICE_RECIPIENT, /* Recipient device */ 41 | INTERFACE_RECIPIENT, /* Recipient interface */ 42 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 43 | OTHER_RECIPIENT 44 | } RECIPIENT_TYPE; 45 | 46 | 47 | typedef enum _STANDARD_REQUESTS 48 | { 49 | GET_STATUS = 0, 50 | CLEAR_FEATURE, 51 | RESERVED1, 52 | SET_FEATURE, 53 | RESERVED2, 54 | SET_ADDRESS, 55 | GET_DESCRIPTOR, 56 | SET_DESCRIPTOR, 57 | GET_CONFIGURATION, 58 | SET_CONFIGURATION, 59 | GET_INTERFACE, 60 | SET_INTERFACE, 61 | TOTAL_sREQUEST, /* Total number of Standard request */ 62 | SYNCH_FRAME = 12 63 | } STANDARD_REQUESTS; 64 | 65 | /* Definition of "USBwValue" */ 66 | typedef enum _DESCRIPTOR_TYPE 67 | { 68 | DEVICE_DESCRIPTOR = 1, 69 | CONFIG_DESCRIPTOR, 70 | STRING_DESCRIPTOR, 71 | INTERFACE_DESCRIPTOR, 72 | ENDPOINT_DESCRIPTOR 73 | } DESCRIPTOR_TYPE; 74 | 75 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 76 | typedef enum _FEATURE_SELECTOR 77 | { 78 | ENDPOINT_STALL, 79 | DEVICE_REMOTE_WAKEUP 80 | } FEATURE_SELECTOR; 81 | 82 | /* Exported constants --------------------------------------------------------*/ 83 | /* Definition of "USBbmRequestType" */ 84 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 85 | #define STANDARD_REQUEST 0x00 /* Standard request */ 86 | #define CLASS_REQUEST 0x20 /* Class request */ 87 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 88 | 89 | #define RECIPIENT 0x1F /* Mask to get recipient */ 90 | 91 | /* Exported macro ------------------------------------------------------------*/ 92 | /* Exported functions ------------------------------------------------------- */ 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif /* __USB_DEF_H */ 99 | 100 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 101 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INIT_H 31 | #define __USB_INIT_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions ------------------------------------------------------- */ 42 | void USB_Init(void); 43 | 44 | /* External variables --------------------------------------------------------*/ 45 | /* The number of current endpoint, it will be used to specify an endpoint */ 46 | extern uint8_t EPindex; 47 | /* The number of current device, it is an index to the Device_Table */ 48 | /*extern uint8_t Device_no; */ 49 | /* Points to the DEVICE_INFO structure of current device */ 50 | /* The purpose of this register is to speed up the execution */ 51 | extern DEVICE_INFO* pInformation; 52 | /* Points to the DEVICE_PROP structure of current device */ 53 | /* The purpose of this register is to speed up the execution */ 54 | extern DEVICE_PROP* pProperty; 55 | /* Temporary save the state of Rx & Tx status. */ 56 | /* Whenever the Rx or Tx state is changed, its value is saved */ 57 | /* in this variable first and will be set to the EPRB or EPRA */ 58 | /* at the end of interrupt process */ 59 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 60 | 61 | extern uint16_t SaveState ; 62 | extern uint16_t wInterrupt_Mask; 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* __USB_INIT_H */ 69 | 70 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 71 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INT_H 31 | #define __USB_INT_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions ------------------------------------------------------- */ 42 | void CTR_LP(void); 43 | void CTR_HP(void); 44 | 45 | /* External variables --------------------------------------------------------*/ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* __USB_INT_H */ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_lib.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief USB library include files 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_LIB_H 31 | #define __USB_LIB_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "hw_config.h" 39 | #include "usb_type.h" 40 | #include "usb_regs.h" 41 | #include "usb_def.h" 42 | #include "usb_core.h" 43 | #include "usb_init.h" 44 | #include "usb_sil.h" 45 | #include "usb_mem.h" 46 | #include "usb_int.h" 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | /* Exported macro ------------------------------------------------------------*/ 51 | /* Exported functions ------------------------------------------------------- */ 52 | /* External variables --------------------------------------------------------*/ 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __USB_LIB_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility prototypes functions for memory/PMA transfers 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_MEM_H 31 | #define __USB_MEM_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions ------------------------------------------------------- */ 42 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 43 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 44 | 45 | /* External variables --------------------------------------------------------*/ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /*__USB_MEM_H*/ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer function prototypes. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_SIL_H 31 | #define __USB_SIL_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macro ------------------------------------------------------------*/ 41 | /* Exported functions ------------------------------------------------------- */ 42 | 43 | uint32_t USB_SIL_Init(void); 44 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize); 45 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer); 46 | 47 | /* External variables --------------------------------------------------------*/ 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __USB_SIL_H */ 54 | 55 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 56 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_type.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Type definitions used by the USB Library 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_TYPE_H 31 | #define __USB_TYPE_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "usb_conf.h" 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | /* Exported constants --------------------------------------------------------*/ 42 | #ifndef NULL 43 | #define NULL ((void *)0) 44 | #endif 45 | 46 | typedef enum 47 | { 48 | FALSE = 0, 49 | TRUE = !FALSE 50 | }BOOL; 51 | 52 | 53 | 54 | /* Exported macro ------------------------------------------------------------*/ 55 | /* Exported functions ------------------------------------------------------- */ 56 | /* External variables --------------------------------------------------------*/ 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __USB_TYPE_H */ 63 | 64 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 65 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* Private define ------------------------------------------------------------*/ 34 | /* Private macro -------------------------------------------------------------*/ 35 | /* Private variables ---------------------------------------------------------*/ 36 | /* The number of current endpoint, it will be used to specify an endpoint */ 37 | uint8_t EPindex; 38 | /* The number of current device, it is an index to the Device_Table */ 39 | /* uint8_t Device_no; */ 40 | /* Points to the DEVICE_INFO structure of current device */ 41 | /* The purpose of this register is to speed up the execution */ 42 | DEVICE_INFO *pInformation; 43 | /* Points to the DEVICE_PROP structure of current device */ 44 | /* The purpose of this register is to speed up the execution */ 45 | DEVICE_PROP *pProperty; 46 | /* Temporary save the state of Rx & Tx status. */ 47 | /* Whenever the Rx or Tx state is changed, its value is saved */ 48 | /* in this variable first and will be set to the EPRB or EPRA */ 49 | /* at the end of interrupt process */ 50 | uint16_t SaveState ; 51 | uint16_t wInterrupt_Mask; 52 | DEVICE_INFO Device_Info; 53 | USER_STANDARD_REQUESTS *pUser_Standard_Requests; 54 | 55 | /* Extern variables ----------------------------------------------------------*/ 56 | /* Private function prototypes -----------------------------------------------*/ 57 | /* Private functions ---------------------------------------------------------*/ 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_Init 61 | * Description : USB system initialization 62 | * Input : None. 63 | * Output : None. 64 | * Return : None. 65 | *******************************************************************************/ 66 | void USB_Init(void) 67 | { 68 | pInformation = &Device_Info; 69 | pInformation->ControlState = 2; 70 | pProperty = &Device_Property; 71 | pUser_Standard_Requests = &User_Standard_Requests; 72 | /* Initialize devices one by one */ 73 | pProperty->Init(); 74 | } 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/src/usb_mem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility functions for memory transfers to/from PMA 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Extern variables ----------------------------------------------------------*/ 36 | /* Private function prototypes -----------------------------------------------*/ 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /******************************************************************************* 40 | * Function Name : UserToPMABufferCopy 41 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 42 | * Input : - pbUsrBuf: pointer to user memory area. 43 | * - wPMABufAddr: address into PMA. 44 | * - wNBytes: no. of bytes to be copied. 45 | * Output : None. 46 | * Return : None . 47 | *******************************************************************************/ 48 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 49 | { 50 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 51 | uint32_t i, temp1, temp2; 52 | uint16_t *pdwVal; 53 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 54 | for (i = n; i != 0; i--) 55 | { 56 | temp1 = (uint16_t) * pbUsrBuf; 57 | pbUsrBuf++; 58 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; 59 | *pdwVal++ = temp2; 60 | pdwVal++; 61 | pbUsrBuf++; 62 | } 63 | } 64 | 65 | /******************************************************************************* 66 | * Function Name : PMAToUserBufferCopy 67 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 68 | * Input : - pbUsrBuf = pointer to user memory area. 69 | * - wPMABufAddr = address into PMA. 70 | * - wNBytes = no. of bytes to be copied. 71 | * Output : None. 72 | * Return : None. 73 | *******************************************************************************/ 74 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 75 | { 76 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 77 | uint32_t i; 78 | uint32_t *pdwVal; 79 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 80 | for (i = n; i != 0; i--) 81 | { 82 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; 83 | pbUsrBuf++; 84 | } 85 | } 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /USB/STM32_USB-FS-Device_Driver/src/usb_sil.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer for Global Initialization and Endpoint 8 | * Rea/Write operations. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usb_lib.h" 32 | 33 | /* Private typedef -----------------------------------------------------------*/ 34 | /* Private define ------------------------------------------------------------*/ 35 | /* Private macro -------------------------------------------------------------*/ 36 | /* Private variables ---------------------------------------------------------*/ 37 | /* Extern variables ----------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /******************************************************************************* 42 | * Function Name : USB_SIL_Init 43 | * Description : Initialize the USB Device IP and the Endpoint 0. 44 | * Input : None. 45 | * Output : None. 46 | * Return : Status. 47 | *******************************************************************************/ 48 | uint32_t USB_SIL_Init(void) 49 | { 50 | /* USB interrupts initialization */ 51 | /* clear pending interrupts */ 52 | _SetISTR(0); 53 | wInterrupt_Mask = IMR_MSK; 54 | /* set interrupts mask */ 55 | _SetCNTR(wInterrupt_Mask); 56 | return 0; 57 | } 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_SIL_Write 61 | * Description : Write a buffer of data to a selected endpoint. 62 | * Input : - bEpAddr: The address of the non control endpoint. 63 | * - pBufferPointer: The pointer to the buffer of data to be written 64 | * to the endpoint. 65 | * - wBufferSize: Number of data to be written (in bytes). 66 | * Output : None. 67 | * Return : Status. 68 | *******************************************************************************/ 69 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize) 70 | { 71 | /* Use the memory interface function to write to the selected endpoint */ 72 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); 73 | 74 | /* Update the data length in the control register */ 75 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize); 76 | 77 | return 0; 78 | } 79 | 80 | /******************************************************************************* 81 | * Function Name : USB_SIL_Read 82 | * Description : Write a buffer of data to a selected endpoint. 83 | * Input : - bEpAddr: The address of the non control endpoint. 84 | * - pBufferPointer: The pointer to which will be saved the 85 | * received data buffer. 86 | * Output : None. 87 | * Return : Number of received data (in Bytes). 88 | *******************************************************************************/ 89 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer) 90 | { 91 | uint32_t DataLength = 0; 92 | 93 | /* Get the number of received data on the selected Endpoint */ 94 | DataLength = GetEPRxCount(bEpAddr & 0x7F); 95 | 96 | /* Use the memory interface function to write to the selected endpoint */ 97 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); 98 | 99 | /* Return the number of received data */ 100 | return DataLength; 101 | } 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /USER/JLinkSettings.ini: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ShowInfoWin = 1 3 | EnableFlashBP = 2 4 | BPDuringExecution = 0 5 | [CFI] 6 | CFISize = 0x00 7 | CFIAddr = 0x00 8 | [CPU] 9 | OverrideMemMap = 0 10 | AllowSimulation = 1 11 | ScriptFile="" 12 | [FLASH] 13 | MinNumBytesFlashDL = 0 14 | SkipProgOnCRCMatch = 1 15 | VerifyDownload = 1 16 | AllowCaching = 1 17 | EnableFlashDL = 2 18 | Override = 0 19 | Device="UNSPECIFIED" 20 | [GENERAL] 21 | WorkRAMSize = 0x00 22 | WorkRAMAddr = 0x00 23 | [SWO] 24 | SWOLogFile="" 25 | [MEM] 26 | RdOverrideOrMask = 0x00 27 | RdOverrideAndMask = 0xFFFFFFFF 28 | RdOverrideAddr = 0xFFFFFFFF 29 | WrOverrideOrMask = 0x00 30 | WrOverrideAndMask = 0xFFFFFFFF 31 | WrOverrideAddr = 0xFFFFFFFF 32 | -------------------------------------------------------------------------------- /USER/main.cpp: -------------------------------------------------------------------------------- 1 | #include "delay.h" 2 | #include "sys.h" 3 | #include "usart.h" 4 | #include "Key.h" 5 | #include "ContentKey.h" 6 | #include "CompositeKey.h" 7 | #include "FunctionKey.h" 8 | #include "led.h" 9 | #include "usb_lib.h" 10 | #include "usb_pwr.h" 11 | #include 12 | #include "DefineKey.h" 13 | #include "DefineKeyLayer.h" 14 | unsigned char result; 15 | int main(void) 16 | { 17 | SCB->VTOR = FLASH_BASE | 0X30000; /* Vector Table Relocation in Internal FLASH. */ 18 | delay_init(); //延时函数初始化 19 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断分组设置 20 | uart_init(9600);//串口初始化为9600 21 | LED_Init(); //初始化与LED连接的硬件接口 22 | HC595SendData(0xff0000); 23 | Key::KEY_Init(); //按键初始化 24 | delay_ms(500); 25 | USB_Port_Set(0); //USB先断开 26 | delay_ms(300); 27 | USB_Port_Set(1); //USB再次连接 28 | //USB配置 29 | USB_Interrupts_Config(); 30 | Set_USBClock(); 31 | USB_Init(); 32 | delay_ms(500); 33 | define_key(); 34 | define_key_layer(CodeMap::defaultCodeMap); 35 | Key::setCodeMap(CodeMap::defaultCodeMap); 36 | while(1) 37 | { 38 | HC595SendData(0xff0000); 39 | KeyState ks; 40 | Key::scanKeys(ks); 41 | Key::decodeKeyCode(ks); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /USER/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CONF_H 24 | #define __STM32F10x_CONF_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ 28 | //#include "stm32f10x_adc.h" 29 | //#include "stm32f10x_bkp.h" 30 | //#include "stm32f10x_can.h" 31 | //#include "stm32f10x_cec.h" 32 | //#include "stm32f10x_crc.h" 33 | //#include "stm32f10x_dac.h" 34 | //#include "stm32f10x_dbgmcu.h" 35 | //#include "stm32f10x_dma.h" 36 | #include "stm32f10x_exti.h" 37 | //#include "stm32f10x_flash.h" 38 | //#include "stm32f10x_fsmc.h" 39 | #include "stm32f10x_gpio.h" 40 | //#include "stm32f10x_i2c.h" 41 | //#include "stm32f10x_iwdg.h" 42 | //#include "stm32f10x_pwr.h" 43 | #include "stm32f10x_rcc.h" 44 | //#include "stm32f10x_rtc.h" 45 | //#include "stm32f10x_sdio.h" 46 | #include "stm32f10x_spi.h" 47 | //#include "stm32f10x_tim.h" 48 | #include "stm32f10x_usart.h" 49 | //#include "stm32f10x_wwdg.h" 50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Uncomment the line below to expanse the "assert_param" macro in the 55 | Standard Peripheral Library drivers code */ 56 | /* #define USE_FULL_ASSERT 1 */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #ifdef USE_FULL_ASSERT 60 | 61 | /** 62 | * @brief The assert_param macro is used for function's parameters check. 63 | * @param expr: If expr is false, it calls assert_failed function which reports 64 | * the name of the source file and the source line number of the call 65 | * that failed. If expr is true, it returns no value. 66 | * @retval None 67 | */ 68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 69 | /* Exported functions ------------------------------------------------------- */ 70 | void assert_failed(uint8_t* file, uint32_t line); 71 | #else 72 | #define assert_param(expr) ((void)0) 73 | #endif /* USE_FULL_ASSERT */ 74 | 75 | #endif /* __STM32F10x_CONF_H */ 76 | 77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /USER/stm32f10x_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_it.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and peripherals 9 | * interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 14 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 15 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 16 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 17 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 18 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 19 | * 20 | *

© COPYRIGHT 2011 STMicroelectronics

21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include "stm32f10x_it.h" 26 | 27 | 28 | 29 | void NMI_Handler(void) 30 | { 31 | } 32 | 33 | void HardFault_Handler(void) 34 | { 35 | /* Go to infinite loop when Hard Fault exception occurs */ 36 | while (1) 37 | { 38 | } 39 | } 40 | 41 | void MemManage_Handler(void) 42 | { 43 | /* Go to infinite loop when Memory Manage exception occurs */ 44 | while (1) 45 | { 46 | } 47 | } 48 | 49 | 50 | void BusFault_Handler(void) 51 | { 52 | /* Go to infinite loop when Bus Fault exception occurs */ 53 | while (1) 54 | { 55 | } 56 | } 57 | 58 | void UsageFault_Handler(void) 59 | { 60 | /* Go to infinite loop when Usage Fault exception occurs */ 61 | while (1) 62 | { 63 | } 64 | } 65 | 66 | void SVC_Handler(void) 67 | { 68 | } 69 | 70 | void DebugMon_Handler(void) 71 | { 72 | } 73 | 74 | void PendSV_Handler(void) 75 | { 76 | } 77 | 78 | void SysTick_Handler(void) 79 | { 80 | } 81 | 82 | /******************************************************************************/ 83 | /* STM32F10x Peripherals Interrupt Handlers */ 84 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 85 | /* available peripheral interrupt handler's name please refer to the startup */ 86 | /* file (startup_stm32f10x_xx.s). */ 87 | /******************************************************************************/ 88 | -------------------------------------------------------------------------------- /USER/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_it.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_IT_H 24 | #define __STM32F10x_IT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | 38 | void NMI_Handler(void); 39 | void HardFault_Handler(void); 40 | void MemManage_Handler(void); 41 | void BusFault_Handler(void); 42 | void UsageFault_Handler(void); 43 | void SVC_Handler(void); 44 | void DebugMon_Handler(void); 45 | void PendSV_Handler(void); 46 | void SysTick_Handler(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __STM32F10x_IT_H */ 53 | 54 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /USER/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /bootloader/CMSIS/CM3/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/CMSIS/CM3/stm32f10x.h -------------------------------------------------------------------------------- /bootloader/CMSIS/CM3/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CONF_H 24 | #define __STM32F10x_CONF_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ 28 | #include "stm32f10x_adc.h" 29 | #include "stm32f10x_bkp.h" 30 | #include "stm32f10x_can.h" 31 | #include "stm32f10x_cec.h" 32 | #include "stm32f10x_crc.h" 33 | #include "stm32f10x_dac.h" 34 | #include "stm32f10x_dbgmcu.h" 35 | #include "stm32f10x_dma.h" 36 | #include "stm32f10x_exti.h" 37 | #include "stm32f10x_flash.h" 38 | #include "stm32f10x_fsmc.h" 39 | #include "stm32f10x_gpio.h" 40 | #include "stm32f10x_i2c.h" 41 | #include "stm32f10x_iwdg.h" 42 | #include "stm32f10x_pwr.h" 43 | #include "stm32f10x_rcc.h" 44 | #include "stm32f10x_rtc.h" 45 | #include "stm32f10x_sdio.h" 46 | #include "stm32f10x_spi.h" 47 | #include "stm32f10x_tim.h" 48 | #include "stm32f10x_usart.h" 49 | #include "stm32f10x_wwdg.h" 50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Uncomment the line below to expanse the "assert_param" macro in the 55 | Standard Peripheral Library drivers code */ 56 | /* #define USE_FULL_ASSERT 1 */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #ifdef USE_FULL_ASSERT 60 | 61 | /** 62 | * @brief The assert_param macro is used for function's parameters check. 63 | * @param expr: If expr is false, it calls assert_failed function which reports 64 | * the name of the source file and the source line number of the call 65 | * that failed. If expr is true, it returns no value. 66 | * @retval None 67 | */ 68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 69 | /* Exported functions ------------------------------------------------------- */ 70 | void assert_failed(uint8_t* file, uint32_t line); 71 | #else 72 | #define assert_param(expr) ((void)0) 73 | #endif /* USE_FULL_ASSERT */ 74 | 75 | #endif /* __STM32F10x_CONF_H */ 76 | 77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /bootloader/CMSIS/CM3/stm32f10x_it.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/CMSIS/CM3/stm32f10x_it.c -------------------------------------------------------------------------------- /bootloader/CMSIS/CM3/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_IT_H 24 | #define __STM32F10x_IT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | 38 | void NMI_Handler(void); 39 | void HardFault_Handler(void); 40 | void MemManage_Handler(void); 41 | void BusFault_Handler(void); 42 | void UsageFault_Handler(void); 43 | void SVC_Handler(void); 44 | void DebugMon_Handler(void); 45 | void PendSV_Handler(void); 46 | void SysTick_Handler(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __STM32F10x_IT_H */ 53 | 54 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /bootloader/CMSIS/CM3/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CRC_H 25 | #define __STM32F10x_CRC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CRC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup CRC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | void CRC_ResetDR(void); 71 | uint32_t CRC_CalcCRC(uint32_t Data); 72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 73 | uint32_t CRC_GetCRC(void); 74 | void CRC_SetIDRegister(uint8_t IDValue); 75 | uint8_t CRC_GetIDRegister(void); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F10x_CRC_H */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_DBGMCU_H 25 | #define __STM32F10x_DBGMCU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup DBGMCU 39 | * @{ 40 | */ 41 | 42 | /** @defgroup DBGMCU_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 55 | #define DBGMCU_STOP ((uint32_t)0x00000002) 56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 80 | 81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup DBGMCU_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup DBGMCU_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | uint32_t DBGMCU_GetREVID(void); 99 | uint32_t DBGMCU_GetDEVID(void); 100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __STM32F10x_DBGMCU_H */ 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_IWDG_H 25 | #define __STM32F10x_IWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup IWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup IWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup IWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup IWDG_WriteAccess 55 | * @{ 56 | */ 57 | 58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 61 | ((ACCESS) == IWDG_WriteAccess_Disable)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup IWDG_prescaler 67 | * @{ 68 | */ 69 | 70 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 71 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 72 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 73 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 74 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 75 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 76 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 77 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 78 | ((PRESCALER) == IWDG_Prescaler_8) || \ 79 | ((PRESCALER) == IWDG_Prescaler_16) || \ 80 | ((PRESCALER) == IWDG_Prescaler_32) || \ 81 | ((PRESCALER) == IWDG_Prescaler_64) || \ 82 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 83 | ((PRESCALER) == IWDG_Prescaler_256)) 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup IWDG_Flag 89 | * @{ 90 | */ 91 | 92 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 93 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 94 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 95 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @defgroup IWDG_Exported_Macros 105 | * @{ 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** @defgroup IWDG_Exported_Functions 113 | * @{ 114 | */ 115 | 116 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 117 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 118 | void IWDG_SetReload(uint16_t Reload); 119 | void IWDG_ReloadCounter(void); 120 | void IWDG_Enable(void); 121 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __STM32F10x_IWDG_H */ 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 141 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_PWR_H 25 | #define __STM32F10x_PWR_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup PWR 39 | * @{ 40 | */ 41 | 42 | /** @defgroup PWR_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup PWR_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup PVD_detection_level 55 | * @{ 56 | */ 57 | 58 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 59 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 60 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 61 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 62 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 63 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 64 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 65 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 66 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 67 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 68 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup Regulator_state_is_STOP_mode 75 | * @{ 76 | */ 77 | 78 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 79 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 80 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 81 | ((REGULATOR) == PWR_Regulator_LowPower)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup STOP_mode_entry 87 | * @{ 88 | */ 89 | 90 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 91 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 92 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup PWR_Flag 99 | * @{ 100 | */ 101 | 102 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 103 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 104 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 105 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 106 | ((FLAG) == PWR_FLAG_PVDO)) 107 | 108 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup PWR_Exported_Macros 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup PWR_Exported_Functions 126 | * @{ 127 | */ 128 | 129 | void PWR_DeInit(void); 130 | void PWR_BackupAccessCmd(FunctionalState NewState); 131 | void PWR_PVDCmd(FunctionalState NewState); 132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 133 | void PWR_WakeUpPinCmd(FunctionalState NewState); 134 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 135 | void PWR_EnterSTANDBYMode(void); 136 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 137 | void PWR_ClearFlag(uint32_t PWR_FLAG); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __STM32F10x_PWR_H */ 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_RTC_H 25 | #define __STM32F10x_RTC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RTC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup RTC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup RTC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup RTC_interrupts_define 55 | * @{ 56 | */ 57 | 58 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 59 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 60 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 61 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 62 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 63 | ((IT) == RTC_IT_SEC)) 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup RTC_interrupts_flags 69 | * @{ 70 | */ 71 | 72 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 73 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 74 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 75 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 76 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 77 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 78 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 79 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 80 | ((FLAG) == RTC_FLAG_SEC)) 81 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @defgroup RTC_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup RTC_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 104 | void RTC_EnterConfigMode(void); 105 | void RTC_ExitConfigMode(void); 106 | uint32_t RTC_GetCounter(void); 107 | void RTC_SetCounter(uint32_t CounterValue); 108 | void RTC_SetPrescaler(uint32_t PrescalerValue); 109 | void RTC_SetAlarm(uint32_t AlarmValue); 110 | uint32_t RTC_GetDivider(void); 111 | void RTC_WaitForLastTask(void); 112 | void RTC_WaitForSynchro(void); 113 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 114 | void RTC_ClearFlag(uint16_t RTC_FLAG); 115 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 116 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* __STM32F10x_RTC_H */ 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 136 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_WWDG_H 25 | #define __STM32F10x_WWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup WWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup WWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Exported_Macros 78 | * @{ 79 | */ 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | void WWDG_DeInit(void); 89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 90 | void WWDG_SetWindowValue(uint8_t WindowValue); 91 | void WWDG_EnableIT(void); 92 | void WWDG_SetCounter(uint8_t Counter); 93 | void WWDG_Enable(uint8_t Counter); 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F10x_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_crc.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup CRC 30 | * @brief CRC driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup CRC_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup CRC_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup CRC_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Resets the CRC Data register (DR). 80 | * @param None 81 | * @retval None 82 | */ 83 | void CRC_ResetDR(void) 84 | { 85 | /* Reset CRC generator */ 86 | CRC->CR = CRC_CR_RESET; 87 | } 88 | 89 | /** 90 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 91 | * @param Data: data word(32-bit) to compute its CRC 92 | * @retval 32-bit CRC 93 | */ 94 | uint32_t CRC_CalcCRC(uint32_t Data) 95 | { 96 | CRC->DR = Data; 97 | 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 103 | * @param pBuffer: pointer to the buffer containing the data to be computed 104 | * @param BufferLength: length of the buffer to be computed 105 | * @retval 32-bit CRC 106 | */ 107 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 108 | { 109 | uint32_t index = 0; 110 | 111 | for(index = 0; index < BufferLength; index++) 112 | { 113 | CRC->DR = pBuffer[index]; 114 | } 115 | return (CRC->DR); 116 | } 117 | 118 | /** 119 | * @brief Returns the current CRC value. 120 | * @param None 121 | * @retval 32-bit CRC 122 | */ 123 | uint32_t CRC_GetCRC(void) 124 | { 125 | return (CRC->DR); 126 | } 127 | 128 | /** 129 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 130 | * @param IDValue: 8-bit value to be stored in the ID register 131 | * @retval None 132 | */ 133 | void CRC_SetIDRegister(uint8_t IDValue) 134 | { 135 | CRC->IDR = IDValue; 136 | } 137 | 138 | /** 139 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 140 | * @param None 141 | * @retval 8-bit value of the ID register 142 | */ 143 | uint8_t CRC_GetIDRegister(void) 144 | { 145 | return (CRC->IDR); 146 | } 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 161 | -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/CMSIS/STM32LIB/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/CMSIS/STM32LIB/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /bootloader/CMSIS/STM32LIB/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/CMSIS/STM32LIB/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /bootloader/HARDWARE/KEY/key.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/HARDWARE/KEY/key.c -------------------------------------------------------------------------------- /bootloader/HARDWARE/KEY/key.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/HARDWARE/KEY/key.h -------------------------------------------------------------------------------- /bootloader/HARDWARE/STM32_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/HARDWARE/STM32_config.h -------------------------------------------------------------------------------- /bootloader/STM32 DFU升级APP程序移植笔记.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/STM32 DFU升级APP程序移植笔记.pdf -------------------------------------------------------------------------------- /bootloader/STM32 USB DFU做的升级程序中利用到同样中断时的处理办法.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/STM32 USB DFU做的升级程序中利用到同样中断时的处理办法.pdf -------------------------------------------------------------------------------- /bootloader/SYSTEM/delay/delay.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/SYSTEM/delay/delay.c -------------------------------------------------------------------------------- /bootloader/SYSTEM/delay/delay.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/SYSTEM/delay/delay.h -------------------------------------------------------------------------------- /bootloader/SYSTEM/sys/sys.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/SYSTEM/sys/sys.c -------------------------------------------------------------------------------- /bootloader/SYSTEM/sys/sys.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/SYSTEM/sys/sys.h -------------------------------------------------------------------------------- /bootloader/SYSTEM/usart/usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/SYSTEM/usart/usart.c -------------------------------------------------------------------------------- /bootloader/SYSTEM/usart/usart.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/SYSTEM/usart/usart.h -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/dfu_mal.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/inc/dfu_mal.h -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/hw_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/inc/hw_config.h -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/platform_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/inc/platform_config.h -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/usb_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_conf.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Device Firmware Upgrade (DFU) configuration file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_CONF_H 31 | #define __USB_CONF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | 37 | /* These timings will be returned to the host when it checks the device 38 | status during a write or erase operation to know how much time the host 39 | should wait before issuing the next get status request. 40 | These defines are set in usb_conf.h file. 41 | The values of this table should be extracted from relative memories 42 | datasheet (Typical or Maximum timming value for Sector Erase and for 43 | 1024 bytes Write). All timings are expressed in millisecond unit (ms). 44 | Note that "Sector" refers here to the memory unit used for Erase/Write 45 | operations. It could be a sector, a page, a block, a word ... 46 | If the erase operation is not supported, it is advised to set the erase 47 | timing to 1 (which means 1ms: one USB frame). */ 48 | #define SPI_FLASH_SECTOR_ERASE_TIME 3000 49 | #define SPI_FLASH_SECTOR_WRITE_TIME 20 50 | 51 | #if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS) 52 | #define INTERN_FLASH_SECTOR_ERASE_TIME 100 53 | #define INTERN_FLASH_SECTOR_WRITE_TIME 104 54 | #else 55 | #define INTERN_FLASH_SECTOR_ERASE_TIME 50 56 | #define INTERN_FLASH_SECTOR_WRITE_TIME 50 57 | #endif /* STM32L1XX_XD */ 58 | 59 | #define M29W128F_SECTOR_ERASE_TIME 1000 60 | #define M29W128F_SECTOR_WRITE_TIME 25 61 | 62 | #define M29W128G_SECTOR_ERASE_TIME 1000 63 | #define M29W128G_SECTOR_WRITE_TIME 25 64 | 65 | #define S29GL128_SECTOR_ERASE_TIME 1000 66 | #define S29GL128_SECTOR_WRITE_TIME 45 67 | 68 | /* Exported macro ------------------------------------------------------------*/ 69 | /* Exported functions ------------------------------------------------------- */ 70 | /* External variables --------------------------------------------------------*/ 71 | /*-------------------------------------------------------------*/ 72 | /* EP_NUM */ 73 | /* defines how many endpoints are used by the device */ 74 | /*-------------------------------------------------------------*/ 75 | #define EP_NUM (1) 76 | 77 | /*-------------------------------------------------------------*/ 78 | /* -------------- Buffer Description Table -----------------*/ 79 | /*-------------------------------------------------------------*/ 80 | /* buffer table base address */ 81 | /* buffer table base address */ 82 | #define BTABLE_ADDRESS (0x00) 83 | 84 | /* EP0 */ 85 | /* rx/tx buffer base address */ 86 | #define ENDP0_RXADDR (0x10) 87 | #define ENDP0_TXADDR (0x50) 88 | 89 | 90 | /*-------------------------------------------------------------*/ 91 | /* ------------------- ISTR events -------------------------*/ 92 | /*-------------------------------------------------------------*/ 93 | /* IMR_MSK */ 94 | /* mask defining which events has to be handled */ 95 | /* by the device application software */ 96 | #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \ 97 | | CNTR_ESOFM | CNTR_RESETM ) 98 | 99 | /* CTR service routines */ 100 | /* associated to defined endpoints */ 101 | #define EP1_IN_Callback NOP_Process 102 | #define EP2_IN_Callback NOP_Process 103 | #define EP3_IN_Callback NOP_Process 104 | #define EP4_IN_Callback NOP_Process 105 | #define EP5_IN_Callback NOP_Process 106 | #define EP6_IN_Callback NOP_Process 107 | #define EP7_IN_Callback NOP_Process 108 | 109 | 110 | #define EP1_OUT_Callback NOP_Process 111 | #define EP2_OUT_Callback NOP_Process 112 | #define EP3_OUT_Callback NOP_Process 113 | #define EP4_OUT_Callback NOP_Process 114 | #define EP5_OUT_Callback NOP_Process 115 | #define EP6_OUT_Callback NOP_Process 116 | #define EP7_OUT_Callback NOP_Process 117 | 118 | #endif /*__USB_CONF_H*/ 119 | 120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 121 | 122 | -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/usb_desc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/inc/usb_desc.h -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_ISTR_H 31 | #define __USB_ISTR_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usb_conf.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | /* Exported macro ------------------------------------------------------------*/ 39 | /* Exported functions ------------------------------------------------------- */ 40 | 41 | void USB_Istr(void); 42 | 43 | /* function prototypes Automatically built defining related macros */ 44 | 45 | void EP1_IN_Callback(void); 46 | void EP2_IN_Callback(void); 47 | void EP3_IN_Callback(void); 48 | void EP4_IN_Callback(void); 49 | void EP5_IN_Callback(void); 50 | void EP6_IN_Callback(void); 51 | void EP7_IN_Callback(void); 52 | 53 | void EP1_OUT_Callback(void); 54 | void EP2_OUT_Callback(void); 55 | void EP3_OUT_Callback(void); 56 | void EP4_OUT_Callback(void); 57 | void EP5_OUT_Callback(void); 58 | void EP6_OUT_Callback(void); 59 | void EP7_OUT_Callback(void); 60 | 61 | #ifdef CTR_CALLBACK 62 | void CTR_Callback(void); 63 | #endif 64 | 65 | #ifdef DOVR_CALLBACK 66 | void DOVR_Callback(void); 67 | #endif 68 | 69 | #ifdef ERR_CALLBACK 70 | void ERR_Callback(void); 71 | #endif 72 | 73 | #ifdef WKUP_CALLBACK 74 | void WKUP_Callback(void); 75 | #endif 76 | 77 | #ifdef SUSP_CALLBACK 78 | void SUSP_Callback(void); 79 | #endif 80 | 81 | #ifdef RESET_CALLBACK 82 | void RESET_Callback(void); 83 | #endif 84 | 85 | #ifdef SOF_CALLBACK 86 | void SOF_Callback(void); 87 | #endif 88 | 89 | #ifdef ESOF_CALLBACK 90 | void ESOF_Callback(void); 91 | #endif 92 | 93 | #endif /*__USB_ISTR_H*/ 94 | 95 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 96 | -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/inc/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_PWR_H 30 | #define __USB_PWR_H 31 | /* Includes ------------------------------------------------------------------*/ 32 | /* Exported types ------------------------------------------------------------*/ 33 | typedef enum _RESUME_STATE 34 | { 35 | RESUME_EXTERNAL, 36 | RESUME_INTERNAL, 37 | RESUME_LATER, 38 | RESUME_WAIT, 39 | RESUME_START, 40 | RESUME_ON, 41 | RESUME_OFF, 42 | RESUME_ESOF 43 | } RESUME_STATE; 44 | 45 | typedef enum _DEVICE_STATE 46 | { 47 | UNCONNECTED, 48 | ATTACHED, 49 | POWERED, 50 | SUSPENDED, 51 | ADDRESSED, 52 | CONFIGURED 53 | } DEVICE_STATE; 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* Exported macro ------------------------------------------------------------*/ 56 | /* Exported functions ------------------------------------------------------- */ 57 | void Suspend(void); 58 | void Resume_Init(void); 59 | void Resume(RESUME_STATE eResumeSetVal); 60 | RESULT PowerOn(void); 61 | RESULT PowerOff(void); 62 | /* External variables --------------------------------------------------------*/ 63 | extern __IO uint32_t bDeviceState; /* USB device status */ 64 | extern __IO bool fSuspendEnabled; /* true when suspend is possible */ 65 | 66 | #endif /*__USB_PWR_H*/ 67 | 68 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 69 | -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/src/dfu_mal.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/src/dfu_mal.c -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/src/hw_config.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/src/hw_config.c -------------------------------------------------------------------------------- /bootloader/USB/Mass_Storage/src/usb_desc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USB/Mass_Storage/src/usb_desc.c -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_def.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Definitions related to USB Core 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_DEF_H 30 | #define __USB_DEF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported types ------------------------------------------------------------*/ 34 | typedef enum _RECIPIENT_TYPE 35 | { 36 | DEVICE_RECIPIENT, /* Recipient device */ 37 | INTERFACE_RECIPIENT, /* Recipient interface */ 38 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 39 | OTHER_RECIPIENT 40 | } RECIPIENT_TYPE; 41 | 42 | 43 | typedef enum _STANDARD_REQUESTS 44 | { 45 | GET_STATUS = 0, 46 | CLEAR_FEATURE, 47 | RESERVED1, 48 | SET_FEATURE, 49 | RESERVED2, 50 | SET_ADDRESS, 51 | GET_DESCRIPTOR, 52 | SET_DESCRIPTOR, 53 | GET_CONFIGURATION, 54 | SET_CONFIGURATION, 55 | GET_INTERFACE, 56 | SET_INTERFACE, 57 | TOTAL_sREQUEST, /* Total number of Standard request */ 58 | SYNCH_FRAME = 12 59 | } STANDARD_REQUESTS; 60 | 61 | /* Definition of "USBwValue" */ 62 | typedef enum _DESCRIPTOR_TYPE 63 | { 64 | DEVICE_DESCRIPTOR = 1, 65 | CONFIG_DESCRIPTOR, 66 | STRING_DESCRIPTOR, 67 | INTERFACE_DESCRIPTOR, 68 | ENDPOINT_DESCRIPTOR 69 | } DESCRIPTOR_TYPE; 70 | 71 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 72 | typedef enum _FEATURE_SELECTOR 73 | { 74 | ENDPOINT_STALL, 75 | DEVICE_REMOTE_WAKEUP 76 | } FEATURE_SELECTOR; 77 | 78 | /* Exported constants --------------------------------------------------------*/ 79 | /* Definition of "USBbmRequestType" */ 80 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 81 | #define STANDARD_REQUEST 0x00 /* Standard request */ 82 | #define CLASS_REQUEST 0x20 /* Class request */ 83 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 84 | 85 | #define RECIPIENT 0x1F /* Mask to get recipient */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions ------------------------------------------------------- */ 89 | 90 | #endif /* __USB_DEF_H */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INIT_H 31 | #define __USB_INIT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void USB_Init(void); 39 | 40 | /* External variables --------------------------------------------------------*/ 41 | /* The number of current endpoint, it will be used to specify an endpoint */ 42 | extern uint8_t EPindex; 43 | /* The number of current device, it is an index to the Device_Table */ 44 | /*extern uint8_t Device_no; */ 45 | /* Points to the DEVICE_INFO structure of current device */ 46 | /* The purpose of this register is to speed up the execution */ 47 | extern DEVICE_INFO* pInformation; 48 | /* Points to the DEVICE_PROP structure of current device */ 49 | /* The purpose of this register is to speed up the execution */ 50 | extern DEVICE_PROP* pProperty; 51 | /* Temporary save the state of Rx & Tx status. */ 52 | /* Whenever the Rx or Tx state is changed, its value is saved */ 53 | /* in this variable first and will be set to the EPRB or EPRA */ 54 | /* at the end of interrupt process */ 55 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 56 | 57 | extern uint16_t SaveState ; 58 | extern uint16_t wInterrupt_Mask; 59 | 60 | #endif /* __USB_INIT_H */ 61 | 62 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 63 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INT_H 31 | #define __USB_INT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void CTR_LP(void); 39 | void CTR_HP(void); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /* __USB_INT_H */ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_lib.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief USB library include files 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_LIB_H 31 | #define __USB_LIB_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "hw_config.h" 35 | #include "usb_type.h" 36 | #include "usb_regs.h" 37 | #include "usb_def.h" 38 | #include "usb_core.h" 39 | #include "usb_init.h" 40 | #include "usb_sil.h" 41 | #include "usb_mem.h" 42 | #include "usb_int.h" 43 | 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | /* Exported macro ------------------------------------------------------------*/ 47 | /* Exported functions ------------------------------------------------------- */ 48 | /* External variables --------------------------------------------------------*/ 49 | 50 | #endif /* __USB_LIB_H */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility prototypes functions for memory/PMA transfers 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_MEM_H 31 | #define __USB_MEM_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 39 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /*__USB_MEM_H*/ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer function prototypes. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_SIL_H 31 | #define __USB_SIL_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | 39 | uint32_t USB_SIL_Init(void); 40 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize); 41 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer); 42 | 43 | /* External variables --------------------------------------------------------*/ 44 | 45 | #endif /* __USB_SIL_H */ 46 | 47 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 48 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_type.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Type definitions used by the USB Library 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_TYPE_H 31 | #define __USB_TYPE_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usb_conf.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | #ifndef NULL 39 | #define NULL ((void *)0) 40 | #endif 41 | 42 | typedef enum 43 | { 44 | FALSE = 0, TRUE = !FALSE 45 | } 46 | bool; 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* Exported functions ------------------------------------------------------- */ 50 | /* External variables --------------------------------------------------------*/ 51 | 52 | #endif /* __USB_TYPE_H */ 53 | 54 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* Private define ------------------------------------------------------------*/ 34 | /* Private macro -------------------------------------------------------------*/ 35 | /* Private variables ---------------------------------------------------------*/ 36 | /* The number of current endpoint, it will be used to specify an endpoint */ 37 | uint8_t EPindex; 38 | /* The number of current device, it is an index to the Device_Table */ 39 | /* uint8_t Device_no; */ 40 | /* Points to the DEVICE_INFO structure of current device */ 41 | /* The purpose of this register is to speed up the execution */ 42 | DEVICE_INFO *pInformation; 43 | /* Points to the DEVICE_PROP structure of current device */ 44 | /* The purpose of this register is to speed up the execution */ 45 | DEVICE_PROP *pProperty; 46 | /* Temporary save the state of Rx & Tx status. */ 47 | /* Whenever the Rx or Tx state is changed, its value is saved */ 48 | /* in this variable first and will be set to the EPRB or EPRA */ 49 | /* at the end of interrupt process */ 50 | uint16_t SaveState ; 51 | uint16_t wInterrupt_Mask; 52 | DEVICE_INFO Device_Info; 53 | USER_STANDARD_REQUESTS *pUser_Standard_Requests; 54 | 55 | /* Extern variables ----------------------------------------------------------*/ 56 | /* Private function prototypes -----------------------------------------------*/ 57 | /* Private functions ---------------------------------------------------------*/ 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_Init 61 | * Description : USB system initialization 62 | * Input : None. 63 | * Output : None. 64 | * Return : None. 65 | *******************************************************************************/ 66 | void USB_Init(void) 67 | { 68 | pInformation = &Device_Info; 69 | pInformation->ControlState = 2; 70 | pProperty = &Device_Property; 71 | pUser_Standard_Requests = &User_Standard_Requests; 72 | /* Initialize devices one by one */ 73 | pProperty->Init(); 74 | } 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/src/usb_mem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility functions for memory transfers to/from PMA 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Extern variables ----------------------------------------------------------*/ 36 | /* Private function prototypes -----------------------------------------------*/ 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /******************************************************************************* 40 | * Function Name : UserToPMABufferCopy 41 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 42 | * Input : - pbUsrBuf: pointer to user memory area. 43 | * - wPMABufAddr: address into PMA. 44 | * - wNBytes: no. of bytes to be copied. 45 | * Output : None. 46 | * Return : None . 47 | *******************************************************************************/ 48 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 49 | { 50 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 51 | uint32_t i, temp1, temp2; 52 | uint16_t *pdwVal; 53 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 54 | for (i = n; i != 0; i--) 55 | { 56 | temp1 = (uint16_t) * pbUsrBuf; 57 | pbUsrBuf++; 58 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; 59 | *pdwVal++ = temp2; 60 | pdwVal++; 61 | pbUsrBuf++; 62 | } 63 | } 64 | 65 | /******************************************************************************* 66 | * Function Name : PMAToUserBufferCopy 67 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 68 | * Input : - pbUsrBuf = pointer to user memory area. 69 | * - wPMABufAddr = address into PMA. 70 | * - wNBytes = no. of bytes to be copied. 71 | * Output : None. 72 | * Return : None. 73 | *******************************************************************************/ 74 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 75 | { 76 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 77 | uint32_t i; 78 | uint32_t *pdwVal; 79 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 80 | for (i = n; i != 0; i--) 81 | { 82 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; 83 | pbUsrBuf++; 84 | } 85 | } 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /bootloader/USB/USBLIB/src/usb_sil.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer for Global Initialization and Endpoint 8 | * Rea/Write operations. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usb_lib.h" 32 | 33 | /* Private typedef -----------------------------------------------------------*/ 34 | /* Private define ------------------------------------------------------------*/ 35 | /* Private macro -------------------------------------------------------------*/ 36 | /* Private variables ---------------------------------------------------------*/ 37 | /* Extern variables ----------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /******************************************************************************* 42 | * Function Name : USB_SIL_Init 43 | * Description : Initialize the USB Device IP and the Endpoint 0. 44 | * Input : None. 45 | * Output : None. 46 | * Return : Status. 47 | *******************************************************************************/ 48 | uint32_t USB_SIL_Init(void) 49 | { 50 | /* USB interrupts initialization */ 51 | /* clear pending interrupts */ 52 | _SetISTR(0); 53 | wInterrupt_Mask = IMR_MSK; 54 | /* set interrupts mask */ 55 | _SetCNTR(wInterrupt_Mask); 56 | return 0; 57 | } 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_SIL_Write 61 | * Description : Write a buffer of data to a selected endpoint. 62 | * Input : - bEpAddr: The address of the non control endpoint. 63 | * - pBufferPointer: The pointer to the buffer of data to be written 64 | * to the endpoint. 65 | * - wBufferSize: Number of data to be written (in bytes). 66 | * Output : None. 67 | * Return : Status. 68 | *******************************************************************************/ 69 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize) 70 | { 71 | /* Use the memory interface function to write to the selected endpoint */ 72 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); 73 | 74 | /* Update the data length in the control register */ 75 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize); 76 | 77 | return 0; 78 | } 79 | 80 | /******************************************************************************* 81 | * Function Name : USB_SIL_Read 82 | * Description : Write a buffer of data to a selected endpoint. 83 | * Input : - bEpAddr: The address of the non control endpoint. 84 | * - pBufferPointer: The pointer to which will be saved the 85 | * received data buffer. 86 | * Output : None. 87 | * Return : Number of received data (in Bytes). 88 | *******************************************************************************/ 89 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer) 90 | { 91 | uint32_t DataLength = 0; 92 | 93 | /* Get the number of received data on the selected Endpoint */ 94 | DataLength = GetEPRxCount(bEpAddr & 0x7F); 95 | 96 | /* Use the memory interface function to write to the selected endpoint */ 97 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); 98 | 99 | /* Return the number of received data */ 100 | return DataLength; 101 | } 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /bootloader/USER/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/USER/main.c -------------------------------------------------------------------------------- /bootloader/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG2CRW/CoopBoard/f1b4446a9dec2bbec4efbfe5019d8ac6441fa9ca/bootloader/keilkilll.bat --------------------------------------------------------------------------------